Browse Source

copy buffer changes

git-svn-id: svn://svn.code.sf.net/p/ditto-cp/code/trunk@375 595ec19a-5cb4-439b-94a8-42fb3063c22c
sabrogden 19 years ago
parent
commit
720897129e
3 changed files with 16 additions and 14 deletions
  1. 4 6
      ClipboardSaveRestore.cpp
  2. 11 7
      DittoCopyBuffer.cpp
  3. 1 1
      DittoCopyBuffer.h

+ 4 - 6
ClipboardSaveRestore.cpp

@@ -30,13 +30,11 @@ bool CClipboardSaveRestore::Save()
 				ULONG Size = GlobalSize(hGlobal);
 				ULONG Size = GlobalSize(hGlobal);
 				if(Size > 0)
 				if(Size > 0)
 				{
 				{
-					LPVOID pvData = GlobalLock(hGlobal);
-					cf.m_hgData = NewGlobalP(pvData, Size);
-					
+					//Copy the data locally
+					cf.m_hgData = NewGlobalP(pvData, Size);	
 					cf.m_cfType = nFormat;
 					cf.m_cfType = nFormat;
 
 
 					m_Clipboard.Add(cf);
 					m_Clipboard.Add(cf);
-					bRet = true;
 				}
 				}
 
 
 				GlobalUnlock(hGlobal);
 				GlobalUnlock(hGlobal);
@@ -46,6 +44,7 @@ bool CClipboardSaveRestore::Save()
 		}
 		}
 
 
 		::CloseClipboard();
 		::CloseClipboard();
+		bRet = true;
 	}
 	}
 
 
 	return bRet;
 	return bRet;
@@ -69,11 +68,10 @@ bool CClipboardSaveRestore::Restore()
 			{
 			{
 				::SetClipboardData(pCF->m_cfType, pCF->m_hgData);
 				::SetClipboardData(pCF->m_cfType, pCF->m_hgData);
 				pCF->m_hgData = NULL;//clipboard now owns the data
 				pCF->m_hgData = NULL;//clipboard now owns the data
-
-				bRet = TRUE;
 			}
 			}
 		}
 		}
 
 
+		bRet = TRUE;
 		::CloseClipboard();
 		::CloseClipboard();
 	}
 	}
 
 

+ 11 - 7
DittoCopyBuffer.cpp

@@ -7,7 +7,7 @@
 CDittoCopyBuffer::CDittoCopyBuffer() :
 CDittoCopyBuffer::CDittoCopyBuffer() :
 	m_ActiveTimer(TRUE, TRUE),
 	m_ActiveTimer(TRUE, TRUE),
 	m_RestoreTimer(TRUE, TRUE),
 	m_RestoreTimer(TRUE, TRUE),
-	m_RestoreActive(TRUE, TRUE)
+	m_Pasting(TRUE, TRUE)
 {
 {
 	m_bActive = false;
 	m_bActive = false;
 	m_dwLastPaste = 0;
 	m_dwLastPaste = 0;
@@ -63,6 +63,7 @@ UINT CDittoCopyBuffer::StartCopyTimer(LPVOID pParam)
 		DWORD dRes = WaitForSingleObject(pBuffer->m_ActiveTimer, 1500);
 		DWORD dRes = WaitForSingleObject(pBuffer->m_ActiveTimer, 1500);
 		if(dRes == WAIT_TIMEOUT)
 		if(dRes == WAIT_TIMEOUT)
 		{
 		{
+			pBuffer->m_SavedClipboard.Clear();
 			pBuffer->m_bActive = false;
 			pBuffer->m_bActive = false;
 		}
 		}
 	}
 	}
@@ -140,12 +141,14 @@ bool CDittoCopyBuffer::PutClipOnDittoCopyBuffer(long lClipId, long lBuffer)
 bool CDittoCopyBuffer::PastCopyBuffer(long lCopyBuffer)
 bool CDittoCopyBuffer::PastCopyBuffer(long lCopyBuffer)
 {
 {
 	//Can't paste while another is still active
 	//Can't paste while another is still active
-	if(WaitForSingleObject(m_RestoreActive, 1) == WAIT_TIMEOUT)
+	if(WaitForSingleObject(m_Pasting, 1) == WAIT_TIMEOUT)
 	{
 	{
 		Log(_T("Copy Buffer pasted to fast"));
 		Log(_T("Copy Buffer pasted to fast"));
 		return false;
 		return false;
 	}
 	}
 
 
+	m_RestoreTimer.ResetEvent();
+	m_Pasting.ResetEvent();
 	bool bRet = false;
 	bool bRet = false;
 
 
 	Log(StrF(_T("Start - PastCopyBuffer buffer = %d"), m_lCurrentDittoBuffer));
 	Log(StrF(_T("Start - PastCopyBuffer buffer = %d"), m_lCurrentDittoBuffer));
@@ -190,6 +193,9 @@ bool CDittoCopyBuffer::PastCopyBuffer(long lCopyBuffer)
 	}
 	}
 	CATCH_SQLITE_EXCEPTION
 	CATCH_SQLITE_EXCEPTION
 
 
+	if(bRet == false)
+		m_Pasting.SetEvent();
+
 	return bRet;
 	return bRet;
 }
 }
 
 
@@ -197,8 +203,9 @@ void CDittoCopyBuffer::EndRestoreThread()
 {
 {
 	//Tell the thread to stop waiting and restore the clipboard
 	//Tell the thread to stop waiting and restore the clipboard
 	m_RestoreTimer.SetEvent();
 	m_RestoreTimer.SetEvent();
+
 	//make sure it's ended
 	//make sure it's ended
-	WaitForSingleObject(m_RestoreActive, 5000);
+	WaitForSingleObject(m_Pasting, 5000);
 }
 }
 
 
 UINT CDittoCopyBuffer::DelayRestoreClipboard(LPVOID pParam)
 UINT CDittoCopyBuffer::DelayRestoreClipboard(LPVOID pParam)
@@ -206,9 +213,6 @@ UINT CDittoCopyBuffer::DelayRestoreClipboard(LPVOID pParam)
 	CDittoCopyBuffer *pBuffer = (CDittoCopyBuffer*)pParam;
 	CDittoCopyBuffer *pBuffer = (CDittoCopyBuffer*)pParam;
 	if(pBuffer)
 	if(pBuffer)
 	{
 	{
-		pBuffer->m_RestoreTimer.ResetEvent();
-		pBuffer->m_RestoreActive.ResetEvent();
-
 		CClipboardSaveRestoreCopyBuffer *pLocalClipboard = pBuffer->m_pClipboard;
 		CClipboardSaveRestoreCopyBuffer *pLocalClipboard = pBuffer->m_pClipboard;
 
 
 		DWORD dRes = WaitForSingleObject(pBuffer->m_RestoreTimer, pLocalClipboard->m_lRestoreDelay);
 		DWORD dRes = WaitForSingleObject(pBuffer->m_RestoreTimer, pLocalClipboard->m_lRestoreDelay);
@@ -232,7 +236,7 @@ UINT CDittoCopyBuffer::DelayRestoreClipboard(LPVOID pParam)
 		delete pLocalClipboard;
 		delete pLocalClipboard;
 		pLocalClipboard = NULL;
 		pLocalClipboard = NULL;
 
 
-		pBuffer->m_RestoreActive.SetEvent();
+		pBuffer->m_Pasting.SetEvent();
 	}
 	}
 
 
 	return TRUE;
 	return TRUE;

+ 1 - 1
DittoCopyBuffer.h

@@ -38,6 +38,6 @@ protected:
 	DWORD m_dwLastPaste;
 	DWORD m_dwLastPaste;
 	CEvent m_ActiveTimer;
 	CEvent m_ActiveTimer;
 	CEvent m_RestoreTimer;
 	CEvent m_RestoreTimer;
-	CEvent m_RestoreActive;
+	CEvent m_Pasting;
 	CClipboardSaveRestoreCopyBuffer *m_pClipboard;
 	CClipboardSaveRestoreCopyBuffer *m_pClipboard;
 };
 };