FarString PasteFromClipboard()
{
	OSVERSIONINFO WinVer;
	WinVer.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
	GetVersionEx (&WinVer);

	HANDLE hClipData;
	if (!OpenClipboard(NULL))
		return(NULL);
	int Unicode=FALSE;
	int Format=0;
	int ReadType=CF_OEMTEXT;
	while ((Format=EnumClipboardFormats(Format))!=0)
	{
		if (Format==CF_UNICODETEXT && WinVer.dwPlatformId==VER_PLATFORM_WIN32_NT)
		{
			Unicode=TRUE;
			break;
		}
		if (Format==CF_TEXT)
		{
			ReadType=CF_TEXT;
			break;
		}
		if (Format==CF_OEMTEXT)
			break;
	}
	FarString ClipText;
	if ((hClipData=GetClipboardData(Unicode ? CF_UNICODETEXT:ReadType))!=NULL)
	{
		int BufferSize;
		char *ClipAddr=(char *)GlobalLock(hClipData);
		if (Unicode)
			BufferSize=lstrlenW((LPCWSTR)ClipAddr)+1;
		else
			BufferSize=strlen(ClipAddr)+1;

		if (Unicode)
		{
			ClipText.SetLength (BufferSize);
			WideCharToMultiByte(CP_OEMCP,0,(LPCWSTR)ClipAddr,-1,ClipText.GetBuffer(),BufferSize,NULL,FALSE);
		}
		else
		{
			ClipText.SetText (ClipAddr, BufferSize);
			if (ReadType==CF_TEXT)
				ClipText = ClipText.ToOEM();
		}
		GlobalUnlock(hClipData);
	}
	CloseClipboard();
	return ClipText;
}
Exemple #2
0
  FarXMLNode *ParseFile (const char *FileName, IFarXMLErrorSink *errorSink)
  {
    FarFile f;
    if (!f.OpenForRead (FileName))
      return NULL;

    int fileSize = f.GetSize();
    FarString xmlBuf;
    xmlBuf.SetLength (fileSize);
    f.Read (xmlBuf.GetBuffer(), fileSize);

    return ParseBuffer (xmlBuf, errorSink);
  }
FarString CMailViewPlugins::MakeKeyName( LPCSTR Root, LPCSTR FileName )
{
  FarString Key = ExtractRelativePath( Root, FileName );
  Key.Insert( 0, "Mailbox_" );
  Key.SetLength( Key.Length() - 4 );
  Key += "_Masks";

  int nIdx = Key.IndexOf( '\\' );
  while ( nIdx != -1 )
  {
    Key[ nIdx ] = '_';
    nIdx = Key.IndexOf( '\\' );
  }

  return Key;
}
void CMailViewTpl::processText( int len, IWriteSink & f )
{
  // TODO: check File
  FarFileName bodyFile = FarFileName::MakeTemp( "mvb" );

  File::mkdirs( bodyFile.GetPath() );

  PMsgPart TextPart = m_origMsg->GetTextPart();
  if ( TextPart )
  {
    long Encoding = GetMsgEncoding( m_origMsg, TextPart, m_defaultEncoding );

    if ( len > 20 )
    {
      FarStringArray Src;
      StrPtr sp = { NULL, 0, (LPSTR)TextPart->GetContentData() };
      LPCSTR Last = sp.Nxt + TextPart->GetContentSize();
      while ( sp.Nxt )
      {
        GetStrPtr( sp.Nxt, &sp, Last );
        Src.Add( ToOEMString( FarString( sp.Str, sp.Len ), Encoding ) );
      }
      FarStringArray * Dst = WordWrapLines( Src, len, true );
      for ( int i = 0; i < Dst->Count(); i ++ )
      {
        f.write( Dst->At( i ), strlen( Dst->At( i ) ) );
        f.write( "\r\n", 2 );
      }
      delete Dst;
    }
    else
    {
      FarString s = (LPCSTR)TextPart->GetContentData();

      s.SetLength( TextPart->GetContentSize() );

      s = ToOEMString( s, Encoding );

      f.write( s.c_str(), s.Length() );
    }

    File::deleteit( bodyFile );
  }
}