Пример #1
0
void COleClipSource::DoUpperLowerCase(CClip &clip, bool upper)
{
	IClipFormat *unicodeTextFormat = clip.m_Formats.FindFormatEx(CF_UNICODETEXT);
	if (unicodeTextFormat != NULL)
	{
		HGLOBAL data = unicodeTextFormat->Data();
		wchar_t * stringData = (wchar_t *) GlobalLock(data);
		int size = (int) GlobalSize(data);
		CString cs(stringData);
		GlobalUnlock(data);

		//free the old text we are going to replace it below with an upper case version
		unicodeTextFormat->Free();

		CString val;
		if (upper)
		{
			val = cs.MakeUpper();
		}
		else
		{
			val = cs.MakeLower();
		}
		
		long lLen = val.GetLength();
		HGLOBAL hGlobal = NewGlobalP(val.GetBuffer(), ((lLen+1) * sizeof(wchar_t)));
		val.ReleaseBuffer();

		unicodeTextFormat->Data(hGlobal);		
	}

	IClipFormat *asciiTextFormat = clip.m_Formats.FindFormatEx(CF_TEXT);
	if (asciiTextFormat != NULL)
	{
		HGLOBAL data = asciiTextFormat->Data();
		char * stringData = (char *) GlobalLock(data);
		int size = (int) GlobalSize(data);
		CStringA cs(stringData);
		GlobalUnlock(data);

		//free the old text we are going to replace it below with an upper case version
		asciiTextFormat->Free();
		
		CString val;
		if (upper)
		{
			val = cs.MakeUpper();
		}
		else
		{
			val = cs.MakeLower();
		}

		long lLen = val.GetLength();
		HGLOBAL hGlobal = NewGlobalP(val.GetBuffer(lLen), lLen + sizeof(char));
		val.ReleaseBuffer();

		asciiTextFormat->Data(hGlobal);
	}
}
LRESULT CMainFrame::OnLoadClipOnClipboard(WPARAM wParam, LPARAM lParam)
{
	CClip *pClip = (CClip*)wParam;
    if(pClip == NULL)
    {
        LogSendRecieveInfo("---------ERROR OnLoadClipOnClipboard pClip == NULL");
        return FALSE;
    }

    if(pClip)
    {
		CProcessPaste paste;
		paste.m_bSendPaste = false;
		paste.m_bActivateTarget = false;

		LogSendRecieveInfo("---------OnLoadClipOnClipboard - Before PutFormats on clipboard");

		paste.m_pOle->PutFormatOnClipboard(&pClip->m_Formats);
		paste.m_pOle->CacheGlobalData(theApp.m_cfIgnoreClipboard, NewGlobalP("Ignore", sizeof("Ignore")));

		LogSendRecieveInfo("---------OnLoadClipOnClipboard - After PutFormats on clipboard");

		LogSendRecieveInfo(StrF(_T("---------OnLoadClipOnClipboard - Setting clip id: %d on ole clipboard"), pClip->m_id));
		paste.GetClipIDs().Add(pClip->m_id);
		paste.DoPaste();

		LogSendRecieveInfo(StrF(_T("---------OnLoadClipOnClipboard - After paste clip id: %d on ole clipboard"), pClip->m_id));
	}

	delete pClip;

	return TRUE;
}
BOOL CProcessPaste::DoPaste()
{
	m_pOle->m_pasteOptions = m_pasteOptions;

	if(m_pOle->DoImmediateRender())
	{
		// MarkAsPasted() must be done first since it makes use of
		//  m_pOle->m_ClipIDs and m_pOle is inaccessible after
		//  SetClipboard is called.
		MarkAsPasted();
		
		// Ignore the clipboard change that we will cause IF:
		// 1) we are pasting a single element, since the element is already
		//    in the db and its lDate was updated by MarkAsPasted().
		// OR
		// 2) we are pasting multiple, but g_Opt.m_bSaveMultiPaste is false
		if(GetClipIDs().GetSize() == 1 || !g_Opt.m_bSaveMultiPaste)
		{
			m_pOle->CacheGlobalData(theApp.m_cfIgnoreClipboard, NewGlobalP("Ignore", sizeof("Ignore")));
		}
		else
		{
			m_pOle->CacheGlobalData(theApp.m_cfDelaySavingData, NewGlobalP("Delay", sizeof("Delay")));
		}
		
		m_pOle->SetClipboard(); // m_pOle is now managed by the OLE clipboard

		// The Clipboard now owns the allocated memory
		// and will delete this data object
		// when new data is put on the Clipboard
		m_pOle = NULL; // m_pOle should not be accessed past this point

		if(m_bSendPaste)
		{
			Log(_T("Sending Paste to active window"));
			theApp.m_activeWnd.SendPaste(m_bActivateTarget);
		}
		else if(m_bActivateTarget)
		{
			Log(_T("Activating active window"));
			theApp.m_activeWnd.ActivateTarget();
		}
		
		return TRUE;
	}
	return FALSE;
}
HGLOBAL CCF_UnicodeTextAggregator::GetHGlobal()
{
	long lLen = m_csNewText.GetLength() * sizeof(wchar_t);
	HGLOBAL hGlobal = NewGlobalP(m_csNewText.GetBuffer(lLen), lLen+sizeof(wchar_t));
	m_csNewText.ReleaseBuffer();

	return hGlobal;
}
Пример #5
0
HGLOBAL NewGlobalH(HGLOBAL hSource, SIZE_T nLen)
{
	ASSERT(hSource && nLen);
	LPVOID pvData = GlobalLock(hSource);
	HGLOBAL hDest = NewGlobalP(pvData, nLen);
	GlobalUnlock(hSource);
	return hDest;
}
Пример #6
0
//##ModelId=474D3076034C
bool CClip_ImportExport::PlaceCF_TEXT_AND_CF_UNICODETEXT_OnClipboard(CStringA &csCF_TEXT, CStringW &csCF_UNICODETEXT)
{
	bool bRet = false;

	if(OpenClipboard(theApp.m_MainhWnd))
	{
		EmptyClipboard();

		if(csCF_TEXT.IsEmpty() == FALSE)
		{
			long lLen = csCF_TEXT.GetLength();
			HGLOBAL hGlobal = NewGlobalP(csCF_TEXT.GetBuffer(lLen), lLen+1);
			csCF_TEXT.ReleaseBuffer();
			SetClipboardData(CF_TEXT, hGlobal);

			bRet = true;
		}
		if(csCF_UNICODETEXT.IsEmpty() == FALSE)
		{
			long lLen = csCF_UNICODETEXT.GetLength() * sizeof(wchar_t);
			HGLOBAL hGlobal = NewGlobalP(csCF_UNICODETEXT.GetBuffer(lLen), lLen+1);
			csCF_UNICODETEXT.ReleaseBuffer();
			SetClipboardData(CF_UNICODETEXT, hGlobal);

			bRet = true;
		}

		CloseClipboard();
	}
	else
	{
		Log(_T("Error opening clipboard"));
	}

	return bRet;
}
Пример #7
0
//##ModelId=474D3064004F
HGLOBAL CHTMLFormatAggregator::GetHGlobal()
{
	CHTMFormatStruct HtmlData;
	HtmlData.SetFragment(m_csNewText);
	HtmlData.SetURL(m_csSourceURL);
	HtmlData.SetVersion(m_csVersion);

	CStringA csHtmlFormat;
	HtmlData.Serialize(csHtmlFormat);

	long lLen = csHtmlFormat.GetLength();
	HGLOBAL hGlobal = NewGlobalP(csHtmlFormat.GetBuffer(lLen), lLen+sizeof(char));
	csHtmlFormat.ReleaseBuffer();

	return hGlobal;
}
Пример #8
0
//##ModelId=474D307E0032
HGLOBAL CFileRecieve::CreateCF_HDROPBuffer()
{
	int nFileArraySize = m_RecievedFiles.GetSize();
	if(nFileArraySize <= 0)
		return NULL;

	TCHAR *pBuff = NULL;
	int	 nBuffSize = 0;

	for(int i = 0; i < nFileArraySize; i++)
	{
		nBuffSize += m_RecievedFiles[i].GetLength()*sizeof(TCHAR)+1;
	}

	nBuffSize += sizeof(DROPFILES)+2;
	nBuffSize = (nBuffSize/32 + 1)*32;

	pBuff = new TCHAR[nBuffSize];

	ZeroMemory(pBuff, nBuffSize);
	((DROPFILES*)pBuff)->pFiles = sizeof(DROPFILES);

#ifdef _UNICODE
	((DROPFILES*)pBuff)->fWide = TRUE;
#endif

	TCHAR* pCurrent = (TCHAR*)(((char*)pBuff) + sizeof(DROPFILES));

	for(int n = 0; n < nFileArraySize; n++)
	{
		STRCPY(pCurrent, (LPCTSTR)m_RecievedFiles[n]);

		pCurrent += m_RecievedFiles[n].GetLength(); 
		*pCurrent = 0;
		pCurrent++;
	}

	HGLOBAL hReturn = NewGlobalP(pBuff, nBuffSize);

	delete []pBuff;
	pBuff = NULL;

	return hReturn;
}
bool CDittoRulerRichEditCtrl::LoadRTFData(CClip &Clip)
{
	CString csRTFOriginal = GetRTF();
	if(csRTFOriginal.IsEmpty())
	{
		Log(_T("Rtf is empty, returning"));
		return false;
	}

	CStringA csRTF = CTextConvert::ConvertToChar(csRTFOriginal);
	CClipFormat format;
	format.m_cfType = RegisterClipboardFormat(_T("Rich Text Format"));
	int nLength = csRTF.GetLength() + 1;
	format.m_hgData = NewGlobalP(csRTF.GetBuffer(nLength), nLength);
	Clip.m_Formats.Add(format);
	format.m_hgData = NULL; //Clip.m_formats owns data now

	return true;
}
Пример #10
0
bool CDittoRulerRichEditCtrl::LoadTextData(CClip &Clip)
{
	CString csText = GetText();
	if(csText.IsEmpty())
	{
		for(int i = 0; i < 20; i++)
		{
			Sleep(100);
			csText = GetText();
			if(csText.IsEmpty() == FALSE)
				break;

			Log(StrF(_T("Get Text still empty pass = %d"), i));
		}
		if(csText.IsEmpty())
		{
			Log(_T("Get Text still empty pass returning"));
			return false;
		}
	}

	CClipFormat format;

#ifdef _UNICODE
	format.m_cfType = CF_UNICODETEXT;
#else
	format.m_cfType = CF_TEXT;
#endif

	int nLength = csText.GetLength() * sizeof(TCHAR) + sizeof(TCHAR);
	format.m_hgData = NewGlobalP(csText.GetBuffer(nLength), nLength);

	Clip.SetDescFromText(format.m_hgData, true);
	m_csDescription = Clip.m_Desc;
	m_csDescription = m_csDescription.Left(15);

	Clip.m_Formats.Add(format);
	format.m_hgData = NULL; //Clip.m_formats owns data now

	return true;
}
Пример #11
0
//##ModelId=474D3076033E
bool CClip_ImportExport::PlaceFormatsOnclipboard()
{
	bool bRet = false;

	if(OpenClipboard(theApp.m_MainhWnd))
	{
		EmptyClipboard();

		int nFormatCount = m_Formats.GetSize();
		for(int i = 0; i < nFormatCount; i++)
		{
			CClipFormat *pCF;
			pCF = &m_Formats.ElementAt(i);
			LPVOID Data = (LPVOID)GlobalLock(pCF->m_hgData);
			if(Data)
			{
				HGLOBAL hGlobal = NewGlobalP(Data, GlobalSize(pCF->m_hgData));			
				if(hGlobal)
				{
					SetClipboardData(pCF->m_cfType, hGlobal);
				}

				GlobalUnlock(pCF->m_hgData);
			}
		}

		CloseClipboard();

		bRet = true;
	}
	else
	{
		Log(_T("PlaceFormatsOnclipboard::Error opening clipboard"));
	}

	return bRet;
}
Пример #12
0
void COleClipSource::Typoglycemia(CClip &clip)
{
	IClipFormat *unicodeTextFormat = clip.m_Formats.FindFormatEx(CF_UNICODETEXT);
	if (unicodeTextFormat != NULL)
	{
		HGLOBAL data = unicodeTextFormat->Data();
		wchar_t * stringData = (wchar_t *) GlobalLock(data);
		int size = (int) GlobalSize(data);
		CString cs(stringData);
		GlobalUnlock(data);

		//free the old text we are going to replace it below with an upper case version
		unicodeTextFormat->Free();

		CString newString;
		
		
		CTokenizer token(cs, _T(' '));
		CString word;

		while (token.Next(word))
		{
			if(word.GetLength() > 3)
			{
				int end = word.GetLength();
				
				for (int i = end-1; i >= 0; i--)
				{
					if(word[i] == _T('.') ||
						word[i] == _T('!') ||
						word[i] == _T('?'))
					{
						end--;
					}
					else
					{
						break;
					}
				}

				if (end > 3)
				{
					std::uniform_int_distribution<int> dist(1, end - 2);
					std::random_device rd;

					for (int i = 1; i < end - 1; i++)
					{
						int newPos = dist(rd);

						CString cs;
						cs.Format(_T("pos: %d, rnd: %d\r\n"), i, newPos);
						OutputDebugString(cs);

						TCHAR temp = word.GetAt(i);
						word.SetAt(i, word.GetAt(newPos));
						word.SetAt(newPos, temp);
					}
				}

				newString += word;
			}
			else
			{
				newString += word;
			}

			newString += _T(' ');
		}

		
		long len = newString.GetLength();
		HGLOBAL hGlobal = NewGlobalP(newString.GetBuffer(), ((len + 1) * sizeof(wchar_t)));

		unicodeTextFormat->Data(hGlobal);
	}

	
}
Пример #13
0
void COleClipSource::AddLineFeeds(CClip &clip, int count)
{
	IClipFormat *pUnicodeText = clip.m_Formats.FindFormatEx(CF_UNICODETEXT);
	if (pUnicodeText != NULL)
	{
		wchar_t *stringData = (wchar_t *) GlobalLock(pUnicodeText->Data());
		if (stringData != NULL)
		{
			CStringW string(stringData);

			GlobalUnlock(pUnicodeText->Data());
			pUnicodeText->Free();

			for(int i = 0; i < count; i++)
			{
				string += _T("\r\n");
			}

			HGLOBAL hGlobal = NewGlobalP(string.GetBuffer(), ((string.GetLength() + 1) * sizeof(wchar_t)));

			pUnicodeText->Data(hGlobal);
		}
	}

	IClipFormat *pAsciiText = clip.m_Formats.FindFormatEx(CF_TEXT);
	if (pAsciiText != NULL)
	{
		char *stringData = (char *) GlobalLock(pAsciiText->Data());
		if (stringData != NULL)
		{
			CStringA string(stringData);

			GlobalUnlock(pAsciiText->Data());
			pAsciiText->Free();

			for (int i = 0; i < count; i++)
			{
				string += _T("\r\n");
			}

			HGLOBAL hGlobal = NewGlobalP(string.GetBuffer(), ((string.GetLength() + 1)));

			pAsciiText->Data(hGlobal);
		}
	}

	IClipFormat *pRTFFormat = clip.m_Formats.FindFormatEx(theApp.m_RTFFormat);
	if (pRTFFormat != NULL)
	{
		char *stringData = (char *) GlobalLock(pRTFFormat->Data());
		if (stringData != NULL)
		{
			CStringA string(stringData);

			GlobalUnlock(pRTFFormat->Data());
			pRTFFormat->Free();

			for (int i = 0; i < count; i++)
			{
				int pos = string.ReverseFind('}');
				if (pos >= 0)
				{
					int count = string.Insert(pos, "\\par\r\n");
				}
			}

			HGLOBAL hGlobal = NewGlobalP(string.GetBuffer(), ((string.GetLength() + 1)));

			pRTFFormat->Data(hGlobal);
		}
	}
}
Пример #14
0
void COleClipSource::RemoveLineFeeds(CClip &clip)
{
	IClipFormat *pUnicodeText = clip.m_Formats.FindFormatEx(CF_UNICODETEXT);
	if (pUnicodeText != NULL)
	{
		wchar_t *stringData = (wchar_t *) GlobalLock(pUnicodeText->Data());
		if (stringData != NULL)
		{
			CStringW string(stringData);

			GlobalUnlock(pUnicodeText->Data());
			pUnicodeText->Free();

			int count = string.Replace(_T("\r\n"), _T(" "));
			count = string.Replace(_T("\r"), _T(" "));
			count = string.Replace(_T("\n"), _T(" "));
			
			HGLOBAL hGlobal = NewGlobalP(string.GetBuffer(), ((string.GetLength() + 1) * sizeof(wchar_t)));

			pUnicodeText->Data(hGlobal);
		}
	}

	IClipFormat *pAsciiText = clip.m_Formats.FindFormatEx(CF_TEXT);
	if (pAsciiText != NULL)
	{
		char *stringData = (char *) GlobalLock(pAsciiText->Data());
		if (stringData != NULL)
		{
			CStringA string(stringData);

			GlobalUnlock(pAsciiText->Data());
			pAsciiText->Free();

			int count = string.Replace("\r\n", " ");
			count = string.Replace("\r", " ");
			count = string.Replace("\n", " ");

			HGLOBAL hGlobal = NewGlobalP(string.GetBuffer(), ((string.GetLength() + 1)));

			pAsciiText->Data(hGlobal);
		}
	}

	IClipFormat *pRTFFormat = clip.m_Formats.FindFormatEx(theApp.m_RTFFormat);
	if (pRTFFormat != NULL)
	{
		char *stringData = (char *) GlobalLock(pRTFFormat->Data());
		if (stringData != NULL)
		{
			CStringA string(stringData);

			GlobalUnlock(pRTFFormat->Data());
			pRTFFormat->Free();

			int count = string.Replace("\\par\r\n", " ");
			int count2 = string.Replace("\\par ", " ");
			int count3 = string.Replace("\\line ", " ");
			
			HGLOBAL hGlobal = NewGlobalP(string.GetBuffer(), ((string.GetLength() + 1)));

			pRTFFormat->Data(hGlobal);
		}
	}
}
Пример #15
0
void COleClipSource::SentenceCase(CClip &clip)
{
	IClipFormat *unicodeTextFormat = clip.m_Formats.FindFormatEx(CF_UNICODETEXT);
	if (unicodeTextFormat != NULL)
	{
		HGLOBAL data = unicodeTextFormat->Data();
		wchar_t * stringData = (wchar_t *) GlobalLock(data);
		int size = (int) GlobalSize(data);
		CString cs(stringData);
		GlobalUnlock(data);

		//free the old text we are going to replace it below with an upper case version
		unicodeTextFormat->Free();

		CString val = cs.MakeLower();
		long len = val.GetLength();

		if (len > 0)
		{
			wchar_t * pText = val.GetBuffer();

			pText[0] = toupper(pText[0]);
			bool capitalize = false;

			for (int i = 1; i < len; i++)
			{
				wchar_t item = pText[i];
				if (item == '.' ||
					item == '!' ||
					item == '?')
				{
					capitalize = true;
				}
				else if (capitalize && item != ' ')
				{
					pText[i] = toupper(item);
					capitalize = false;
				}
			}
		}


		val.ReleaseBuffer();

		HGLOBAL hGlobal = NewGlobalP(val.GetBuffer(), ((len + 1) * sizeof(wchar_t)));

		unicodeTextFormat->Data(hGlobal);
	}

	IClipFormat *asciiTextFormat = clip.m_Formats.FindFormatEx(CF_TEXT);
	if (asciiTextFormat != NULL)
	{
		HGLOBAL data = asciiTextFormat->Data();
		char * stringData = (char *) GlobalLock(data);
		int size = (int) GlobalSize(data);
		CStringA cs(stringData);
		GlobalUnlock(data);

		//free the old text we are going to replace it below with an upper case version
		asciiTextFormat->Free();

		CStringA val = cs.MakeLower();
		long len = val.GetLength();

		if (len > 0)
		{
			char * pText = val.GetBuffer();

			pText[0] = toupper(pText[0]);
			bool capitalize = false;

			for (int i = 1; i < len; i++)
			{
				wchar_t item = pText[i];
				if (item == '.' ||
					item == '!' ||
					item == '?')
				{
					capitalize = true;
				}
				else if (capitalize && item != ' ')
				{
					pText[i] = toupper(item);
					capitalize = false;
				}
			}
		}

		val.ReleaseBuffer();

		HGLOBAL hGlobal = NewGlobalP(val.GetBuffer(), (len + 1));

		asciiTextFormat->Data(hGlobal);
	}
}
Пример #16
0
//##ModelId=474D307602FF
bool CClip_ImportExport::ImportFromSqliteV1(CppSQLite3DB &db, CppSQLite3Query &qMain)
{
	try
	{
		//Load the Main Table
		m_Desc = qMain.getStringField(_T("mText"));
		long lID = qMain.getIntField(_T("lID"));

		//Load the data Table
		CClipFormat cf;
		HGLOBAL hGlobal = 0;
		m_Formats.RemoveAll();

		CString csSQL;
		csSQL.Format(
			_T("SELECT Data.* FROM Data ")
			_T("INNER JOIN Main ON Main.lID = Data.lParentID ")
			_T("WHERE Main.lID = %d ORDER BY Data.lID desc"), lID);

		CppSQLite3Query qData = db.execQuery(csSQL);
		while(qData.eof() == false)
		{
			cf.m_cfType = GetFormatID(qData.getStringField(_T("strClipBoardFormat")));
			long lOriginalSize = qData.getIntField(_T("lOriginalSize"));

			int nDataLen = 0;
			const unsigned char *cData = qData.getBlobField(_T("ooData"), nDataLen);
			if(cData != NULL)
			{
				Bytef *pUnZippedData = new Bytef[lOriginalSize];
				if(pUnZippedData)
				{
					//the data in the exported file is compressed so uncompress it now
					int nRet = uncompress(pUnZippedData, (uLongf *)&lOriginalSize, (Bytef *)cData, nDataLen);
					if(nRet == Z_OK)
					{
						cf.m_hgData = NewGlobalP(pUnZippedData, lOriginalSize);
						if(cf.m_hgData)
						{
							m_Formats.Add(cf);
							cf.m_hgData = NULL; //m_format owns m_hgData now
						}
						else
						{
							Log(StrF(_T("Error allocating NewGlobalP size = %d"), lOriginalSize));
							ASSERT(FALSE);
						}
					}
					else
					{
						Log(_T("Error uncompressing data from zlib"));
						ASSERT(FALSE);
					}

					delete []pUnZippedData;
					pUnZippedData = NULL;
				}
				else
				{
					Log(StrF(_T("Error allocating memory to unzip size = %d"), lOriginalSize));
					ASSERT(FALSE);
				}
			}

			qData.nextRow();
		}
	}
	CATCH_SQLITE_EXCEPTION_AND_RETURN(false)

	return m_Formats.GetSize() > 0;
}