Browse Source

removed send messages to get if we are connected to thread
[SAB]


git-svn-id: svn://svn.code.sf.net/p/ditto-cp/code/trunk@200 595ec19a-5cb4-439b-94a8-42fb3063c22c

sabrogden 20 years ago
parent
commit
9ab39f14e1
6 changed files with 46 additions and 78 deletions
  1. 4 4
      CP_Main.rc
  2. 1 16
      Clip.cpp
  3. 30 41
      ClipboardViewer.cpp
  4. 5 7
      ClipboardViewer.h
  5. 3 8
      CopyThread.cpp
  6. 3 2
      Misc.cpp

+ 4 - 4
CP_Main.rc

@@ -769,8 +769,8 @@ END
 //
 //
 
 
 VS_VERSION_INFO VERSIONINFO
 VS_VERSION_INFO VERSIONINFO
- FILEVERSION 2,6,0,0
- PRODUCTVERSION 2,6,0,0
+ FILEVERSION 2,6,1,0
+ PRODUCTVERSION 2,6,1,0
  FILEFLAGSMASK 0x3fL
  FILEFLAGSMASK 0x3fL
 #ifdef _DEBUG
 #ifdef _DEBUG
  FILEFLAGS 0x1L
  FILEFLAGS 0x1L
@@ -788,14 +788,14 @@ BEGIN
             VALUE "Comments", "\0"
             VALUE "Comments", "\0"
             VALUE "CompanyName", "\0"
             VALUE "CompanyName", "\0"
             VALUE "FileDescription", "Ditto\0"
             VALUE "FileDescription", "Ditto\0"
-            VALUE "FileVersion", "2, 6, 0, 0\0"
+            VALUE "FileVersion", "2, 6, 1, 0\0"
             VALUE "InternalName", "CP_Main\0"
             VALUE "InternalName", "CP_Main\0"
             VALUE "LegalCopyright", "Copyright (C) 2003\0"
             VALUE "LegalCopyright", "Copyright (C) 2003\0"
             VALUE "LegalTrademarks", "\0"
             VALUE "LegalTrademarks", "\0"
             VALUE "OriginalFilename", "Ditto\0"
             VALUE "OriginalFilename", "Ditto\0"
             VALUE "PrivateBuild", "\0"
             VALUE "PrivateBuild", "\0"
             VALUE "ProductName", "Ditto\0"
             VALUE "ProductName", "Ditto\0"
-            VALUE "ProductVersion", "2, 6, 0, 0\0"
+            VALUE "ProductVersion", "2, 6, 1, 0\0"
             VALUE "SpecialBuild", "\0"
             VALUE "SpecialBuild", "\0"
         END
         END
     END
     END

+ 1 - 16
Clip.cpp

@@ -240,8 +240,6 @@ bool CClip::AddFormat(CLIPFORMAT cfType, void* pData, UINT nLen)
 	return true;
 	return true;
 }
 }
 
 
-bool g_bCopyingClipboard = false; // for debugging reentrance
-
 // Fills this CClip with the contents of the clipboard.
 // Fills this CClip with the contents of the clipboard.
 bool CClip::LoadFromClipboard(CClipTypes* pClipTypes)
 bool CClip::LoadFromClipboard(CClipTypes* pClipTypes)
 {
 {
@@ -249,28 +247,18 @@ bool CClip::LoadFromClipboard(CClipTypes* pClipTypes)
 	CClipTypes defaultTypes;
 	CClipTypes defaultTypes;
 	CClipTypes* pTypes = pClipTypes;
 	CClipTypes* pTypes = pClipTypes;
 
 
-	if( g_bCopyingClipboard )
-		return false;
-	
-	g_bCopyingClipboard = true;
-	
 	// m_Formats should be empty when this is called.
 	// m_Formats should be empty when this is called.
 	ASSERT(m_Formats.GetSize() == 0);
 	ASSERT(m_Formats.GetSize() == 0);
 	
 	
 	// If the data is supposed to be private, then return
 	// If the data is supposed to be private, then return
 	if(::IsClipboardFormatAvailable(theApp.m_cfIgnoreClipboard))
 	if(::IsClipboardFormatAvailable(theApp.m_cfIgnoreClipboard))
 	{
 	{
-		g_bCopyingClipboard = false;
-
 		return false;
 		return false;
 	}
 	}
-
-	Sleep(2000);
 	
 	
 	//Attach to the clipboard
 	//Attach to the clipboard
 	if(!oleData.AttachClipboard())
 	if(!oleData.AttachClipboard())
 	{
 	{
-		g_bCopyingClipboard = false;
 		ASSERT(0); // does this ever happen?
 		ASSERT(0); // does this ever happen?
 		return false;
 		return false;
 	}
 	}
@@ -342,7 +330,6 @@ bool CClip::LoadFromClipboard(CClipTypes* pClipTypes)
 					Log(cs);
 					Log(cs);
 
 
 					oleData.Release();
 					oleData.Release();
-					g_bCopyingClipboard = false;
 					return false;
 					return false;
 				}
 				}
 
 
@@ -378,11 +365,9 @@ bool CClip::LoadFromClipboard(CClipTypes* pClipTypes)
 	
 	
 	if(m_Formats.GetSize() == 0)
 	if(m_Formats.GetSize() == 0)
 	{
 	{
-		g_bCopyingClipboard = false;
 		return false;
 		return false;
 	}
 	}
-	
-	g_bCopyingClipboard = false;
+
 	return true;
 	return true;
 }
 }
 
 

+ 30 - 41
ClipboardViewer.cpp

@@ -14,17 +14,18 @@ static char THIS_FILE[] = __FILE__;
 /////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////////////
 // CClipboardViewer
 // CClipboardViewer
 
 
-CClipboardViewer::CClipboardViewer(CCopyThread* pHandler)
+CClipboardViewer::CClipboardViewer(CCopyThread* pHandler) :
+	m_hNextClipboardViewer(0),
+	m_bCalling_SetClipboardViewer(false),
+	m_lReconectCount(0),
+	m_bIsConnected(false),
+	m_bConnect(false),
+	m_pHandler(pHandler),
+	m_bPinging(false),
+	m_bPingSuccess(false),
+	m_bHandlingClipChange(false)
 {
 {
-	m_hNextClipboardViewer = 0;
-	m_bCalling_SetClipboardViewer = false;
-	m_lReconectCount = 0;
-	m_bIsConnected = false;
-	m_bConnect = false;
-	m_pHandler = pHandler;
-	ASSERT(m_pHandler);
-	m_bPinging = false;
-	m_bPingSuccess = false;
+
 }
 }
 
 
 CClipboardViewer::~CClipboardViewer()
 CClipboardViewer::~CClipboardViewer()
@@ -40,9 +41,6 @@ BEGIN_MESSAGE_MAP(CClipboardViewer, CWnd)
 	ON_WM_TIMER()
 	ON_WM_TIMER()
 	ON_WM_DESTROY()
 	ON_WM_DESTROY()
 	//}}AFX_MSG_MAP
 	//}}AFX_MSG_MAP
-	ON_MESSAGE(WM_CV_GETCONNECT, OnCVGetConnect)
-	ON_MESSAGE(WM_CV_SETCONNECT, OnCVSetConnect)
-	ON_MESSAGE(WM_CV_IS_CONNECTED, OnCVIsConnected)
 END_MESSAGE_MAP()
 END_MESSAGE_MAP()
 
 
 
 
@@ -118,7 +116,7 @@ void CClipboardViewer::SetCVIgnore()
 	}
 	}
 }
 }
 
 
-void CClipboardViewer::SetConnect( bool bConnect )
+void CClipboardViewer::SetConnect(bool bConnect)
 {
 {
 	m_bConnect = bConnect;
 	m_bConnect = bConnect;
 	if(m_bConnect)
 	if(m_bConnect)
@@ -149,8 +147,6 @@ void CClipboardViewer::OnDestroy()
 
 
 void CClipboardViewer::OnChangeCbChain(HWND hWndRemove, HWND hWndAfter) 
 void CClipboardViewer::OnChangeCbChain(HWND hWndRemove, HWND hWndAfter) 
 {
 {
-	Log(StrF("OnChangeCbChain Removed = %d After = %d", hWndAfter, hWndAfter));
-
 	// If the next window is closing, repair the chain. 
 	// If the next window is closing, repair the chain. 
 	if(m_hNextClipboardViewer == hWndRemove)
 	if(m_hNextClipboardViewer == hWndRemove)
     {
     {
@@ -161,8 +157,6 @@ void CClipboardViewer::OnChangeCbChain(HWND hWndRemove, HWND hWndAfter)
     {
     {
 		if(m_hNextClipboardViewer != m_hWnd)
 		if(m_hNextClipboardViewer != m_hWnd)
 		{
 		{
-			Log(StrF("OnChangeCbChain Sending WM_CHANGECBCHAIN to %d", m_hNextClipboardViewer));
-
 			::SendMessage(m_hNextClipboardViewer, WM_CHANGECBCHAIN, (WPARAM) hWndRemove, (LPARAM) hWndAfter);
 			::SendMessage(m_hNextClipboardViewer, WM_CHANGECBCHAIN, (WPARAM) hWndRemove, (LPARAM) hWndAfter);
 		}
 		}
 		else
 		else
@@ -186,7 +180,7 @@ void CClipboardViewer::OnDrawClipboard()
 	{
 	{
 		if(!::IsClipboardFormatAvailable(theApp.m_cfIgnoreClipboard))
 		if(!::IsClipboardFormatAvailable(theApp.m_cfIgnoreClipboard))
 		{
 		{
-			Log(StrF("OnDrawClipboard::SetTimer %d", GetTickCount()));
+			Log(StrF("OnDrawClipboard:: *** SetTimer *** %d", GetTickCount()));
 			
 			
 			KillTimer(TIMER_DRAW_CLIPBOARD);
 			KillTimer(TIMER_DRAW_CLIPBOARD);
 			SetTimer(TIMER_DRAW_CLIPBOARD, g_Opt.m_lProcessDrawClipboardDelay, NULL);		
 			SetTimer(TIMER_DRAW_CLIPBOARD, g_Opt.m_lProcessDrawClipboardDelay, NULL);		
@@ -218,20 +212,31 @@ void CClipboardViewer::OnTimer(UINT nIDEvent)
 	case TIMER_DRAW_CLIPBOARD:
 	case TIMER_DRAW_CLIPBOARD:
 		KillTimer(nIDEvent);
 		KillTimer(nIDEvent);
 
 
-		if((GetTickCount() - m_lLastCopy) > g_Opt.m_lSaveClipDelay)
+		if(m_bHandlingClipChange == false)
 		{
 		{
-			if(!::IsClipboardFormatAvailable(theApp.m_cfIgnoreClipboard))
+			m_bHandlingClipChange = true;
+
+			if((GetTickCount() - m_lLastCopy) > g_Opt.m_lSaveClipDelay)
 			{
 			{
-				Log(StrF("OnDrawClipboard::OnTimer %d", GetTickCount()));
+				if(!::IsClipboardFormatAvailable(theApp.m_cfIgnoreClipboard))
+				{
+					Log(StrF("OnDrawClipboard::OnTimer %d", GetTickCount()));
 
 
-				m_pHandler->OnClipboardChange();
+					m_pHandler->OnClipboardChange();
 
 
-				m_lLastCopy = GetTickCount();
+					m_lLastCopy = GetTickCount();
+				}
+			}
+			else
+			{
+				Log(StrF("Clip copy to fast difference from last copy = %d", (GetTickCount() - m_lLastCopy)));
 			}
 			}
+
+			m_bHandlingClipChange = false;
 		}
 		}
 		else
 		else
 		{
 		{
-			Log(StrF("Clip copy to fast difference from last copy = %d", (GetTickCount() - m_lLastCopy)));
+			Log("HandlingClipChange is Set, ERROR");
 		}
 		}
 
 
 		break;
 		break;
@@ -239,19 +244,3 @@ void CClipboardViewer::OnTimer(UINT nIDEvent)
 	
 	
 	CWnd::OnTimer(nIDEvent);
 	CWnd::OnTimer(nIDEvent);
 }
 }
-
-LRESULT CClipboardViewer::OnCVGetConnect(WPARAM wParam, LPARAM lParam)
-{
-	return GetConnect();
-}
-
-LRESULT CClipboardViewer::OnCVSetConnect(WPARAM wParam, LPARAM lParam)
-{
-	SetConnect(wParam != FALSE); // convert to bool
-	return TRUE;
-}
-
-LRESULT CClipboardViewer::OnCVIsConnected(WPARAM wParam, LPARAM lParam)
-{
-	return SendPing();
-}

+ 5 - 7
ClipboardViewer.h

@@ -39,16 +39,17 @@ public:
 	void Connect();    // connects as a clipboard viewer
 	void Connect();    // connects as a clipboard viewer
 	void Disconnect(); // disconnects as a clipboard viewer
 	void Disconnect(); // disconnects as a clipboard viewer
 
 
-	bool	m_bPinging;
-	bool	m_bPingSuccess;
+	bool m_bPinging;
+	bool m_bPingSuccess;
 	bool SendPing(); // returns true if we are in the chain
 	bool SendPing(); // returns true if we are in the chain
 	bool EnsureConnected(); // pings and connects if ping fails
 	bool EnsureConnected(); // pings and connects if ping fails
 	void SetCVIgnore(); // puts format "Clipboard Viewer Ignore" on the clipboard
 	void SetCVIgnore(); // puts format "Clipboard Viewer Ignore" on the clipboard
 
 
-	bool GetConnect() { return m_bConnect; }
-	void SetConnect( bool bConnect );
+	bool GetConnect()				{ return m_bConnect; }
+	void SetConnect(bool bConnect);
 
 
 	long m_lLastCopy;
 	long m_lLastCopy;
+	bool m_bHandlingClipChange;
 
 
 	// Generated message map functions
 	// Generated message map functions
 protected:
 protected:
@@ -59,9 +60,6 @@ protected:
 	afx_msg void OnDrawClipboard();
 	afx_msg void OnDrawClipboard();
 	afx_msg void OnTimer(UINT nIDEvent);
 	afx_msg void OnTimer(UINT nIDEvent);
 	//}}AFX_MSG
 	//}}AFX_MSG
-	afx_msg LRESULT OnCVGetConnect(WPARAM wParam, LPARAM lParam);
-	afx_msg LRESULT OnCVSetConnect(WPARAM wParam, LPARAM lParam);
-	afx_msg LRESULT OnCVIsConnected(WPARAM wParam, LPARAM lParam);
 	DECLARE_MESSAGE_MAP()
 	DECLARE_MESSAGE_MAP()
 };
 };
 
 

+ 3 - 8
CopyThread.cpp

@@ -132,24 +132,19 @@ void CCopyThread::AddToClips(CClip* pClip)
 	Release();
 	Release();
 }
 }
 
 
-// Shared (use thread-safe access functions below)
-// Called within Main thread:
 bool CCopyThread::IsClipboardViewerConnected()
 bool CCopyThread::IsClipboardViewerConnected()
 {
 {
-	ASSERT(m_pClipboardViewer && m_pClipboardViewer->m_hWnd);
-	return ::SendMessage(m_pClipboardViewer->m_hWnd, WM_CV_IS_CONNECTED, 0, 0) != FALSE;
+	return m_pClipboardViewer->SendPing();
 }
 }
 
 
 bool CCopyThread::GetConnectCV()
 bool CCopyThread::GetConnectCV()
 {
 {
-	ASSERT(m_pClipboardViewer && m_pClipboardViewer->m_hWnd);
-	return ::SendMessage(m_pClipboardViewer->m_hWnd, WM_CV_GETCONNECT, 0, 0) != FALSE;
+	return m_pClipboardViewer->GetConnect();
 }
 }
 
 
 void CCopyThread::SetConnectCV(bool bConnect)
 void CCopyThread::SetConnectCV(bool bConnect)
 {
 {
-	ASSERT(m_pClipboardViewer && m_pClipboardViewer->m_hWnd);
-	::SendMessage( m_pClipboardViewer->m_hWnd, WM_CV_SETCONNECT, bConnect, 0);
+	m_pClipboardViewer->SetConnect(bConnect);
 }
 }
 
 
 CClipList* CCopyThread::GetClips()
 CClipList* CCopyThread::GetClips()

+ 3 - 2
Misc.cpp

@@ -63,7 +63,8 @@ void Log(const char* msg, bool bFromSendRecieve)
 	
 	
 	csText += msg;
 	csText += msg;
 	csText += "\n";
 	csText += "\n";
-	TRACE(csText);
+	//TRACE(csText);
+	OutputDebugString(csText);
 
 
 #ifndef _DEBUG
 #ifndef _DEBUG
 	if(!bFromSendRecieve)
 	if(!bFromSendRecieve)
@@ -1386,7 +1387,7 @@ void CGetSetOptions::SetSaveClipDelay(long lDelay)
 
 
 long CGetSetOptions::GetProcessDrawClipboardDelay()
 long CGetSetOptions::GetProcessDrawClipboardDelay()
 {
 {
-	return GetProfileLong("ProcessDrawClipboardDelay", 50);
+	return GetProfileLong("ProcessDrawClipboardDelay", 100);
 }
 }
 
 
 void CGetSetOptions::SetProcessDrawClipboardDelay(long lDelay)
 void CGetSetOptions::SetProcessDrawClipboardDelay(long lDelay)