Browse Source

- added more checks to ensure we skip focus changes on toolbar/tasktray.
- updated refresh when always on top and items are pasted, window is refreshed correctly

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

sabrogden 14 years ago
parent
commit
5d3965bd46
7 changed files with 68 additions and 35 deletions
  1. 1 5
      CP_Main.cpp
  2. 34 3
      ExternalWindowTracker.cpp
  3. 2 0
      ExternalWindowTracker.h
  4. 7 7
      MainFrm.cpp
  5. 6 6
      ProcessPaste.cpp
  6. 18 12
      QPasteWnd.cpp
  7. 0 2
      QPasteWndThread.cpp

+ 1 - 5
CP_Main.cpp

@@ -125,6 +125,7 @@ BOOL CCP_MainApp::InitInstance()
 	AfxEnableControlContainer();
 	AfxOleInit();
 	AfxInitRichEditEx();
+	afxAmbientActCtx = FALSE; 
 
 	DittoCommandLineInfo cmdInfo;
 	ParseCommandLine(cmdInfo);
@@ -476,11 +477,6 @@ void CCP_MainApp::RefreshView()
 
 void CCP_MainApp::OnPasteCompleted()
 {
-	// the list only changes if UpdateTimeOnPaste is true (updated time)
-	if(g_Opt.m_bUpdateTimeOnPaste)
-	{
-		RefreshView();
-	}
 }
 
 void CCP_MainApp::OnCopyCompleted(long lLastID, int count)

+ 34 - 3
ExternalWindowTracker.cpp

@@ -57,9 +57,7 @@ bool ExternalWindowTracker::TrackActiveWnd(HWND focus)
 		return false;
 	}
 
-	TCHAR className[100];
-	GetClassName(newActive, className, (sizeof(className) / sizeof(TCHAR)));
-	if(STRCMP(className, _T("Shell_TrayWnd")) == 0)
+	if(NotifyTrayhWnd(newActive) || NotifyTrayhWnd(newFocus))
 	{
 		Log(_T("TargetActiveWindow shell tray icon has active"));
 		return false;
@@ -123,6 +121,39 @@ void ExternalWindowTracker::ActivateFocus(const HWND activeHwnd, const HWND focu
 	}
 }
 
+bool ExternalWindowTracker::NotifyTrayhWnd(HWND hWnd)
+{
+	HWND hParent = hWnd;
+
+	int nCount = 0;
+
+	while(hParent != NULL)
+	{
+		TCHAR className[100];
+		GetClassName(hParent, className, (sizeof(className) / sizeof(TCHAR)));
+
+		if((STRCMP(className, _T("Shell_TrayWnd")) == 0) || 
+			(STRCMP(className, _T("NotifyIconOverflowWindow")) == 0) ||
+			(STRCMP(className, _T("TrayNotifyWnd")) == 0))
+		{
+			return true;
+		}
+
+		hParent = ::GetParent(hParent);
+		if(hParent == NULL)
+			break;
+
+		nCount++;
+		if(nCount > 100)
+		{
+			Log(_T("GetTargetName reached maximum search depth of 100"));
+			break;
+		}
+	}
+
+	return false;
+}
+
 bool ExternalWindowTracker::ActivateTarget()
 {
 	Log(StrF(_T("Activate Target - Active: %d, Focus: %d"), m_activeWnd, m_focusWnd));

+ 2 - 0
ExternalWindowTracker.h

@@ -21,6 +21,8 @@ public:
 	void SendCut();
 	void SendCopy();
 
+	bool NotifyTrayhWnd(HWND hWnd);
+
 protected:
 	HWND m_activeWnd;
 	HWND m_focusWnd;

+ 7 - 7
MainFrm.cpp

@@ -520,16 +520,16 @@ void CMainFrame::OnTimer(UINT nIDEvent)
 
         case ACTIVE_WINDOW_TIMER:
 			{
-	            if(m_quickPaste.IsWindowVisibleEx())
-	            {
-	                theApp.m_activeWnd.TrackActiveWnd(NULL);
-	            }
+				if(m_TrayIcon.Visible())
+				{
+					theApp.m_activeWnd.TrackActiveWnd(NULL);
+				}
 			}
-            break;
+			break;
 
-        case FOCUS_CHANGED_TIMER:
+		case FOCUS_CHANGED_TIMER:
 			{
-	            KillTimer(FOCUS_CHANGED_TIMER);
+				KillTimer(FOCUS_CHANGED_TIMER);
 	            //Log(StrF(_T("Focus Timer %d"), m_tempFocusWnd));
 	            theApp.m_activeWnd.TrackActiveWnd(m_tempFocusWnd);
 			}

+ 6 - 6
ProcessPaste.cpp

@@ -122,15 +122,12 @@ UINT CProcessPaste::MarkAsPastedThread(LPVOID pParam)
 
 	try
 	{
-		CppSQLite3DB Local_db;
-		Local_db.open(CGetSetOptions::GetDBPath());
-
 		//Update the time it was copied so that it appears at the top of the
 		//paste list. Items are sorted by this time.
 		CTime now = CTime::GetCurrentTime();
 		try
 		{
-			CppSQLite3Query q = Local_db.execQuery(_T("SELECT lDate FROM Main ORDER BY lDate DESC LIMIT 1"));
+			CppSQLite3Query q = theApp.m_db.execQuery(_T("SELECT lDate FROM Main ORDER BY lDate DESC LIMIT 1"));
 
 			if(q.eof() == false)
 			{
@@ -145,8 +142,11 @@ UINT CProcessPaste::MarkAsPastedThread(LPVOID pParam)
 
 		Log(StrF(_T("Setting clipId: %d, time: %d"), lID, now.GetTime()));
 
-		Local_db.execDMLEx(_T("UPDATE Main SET lDate = %d where lID = %d;"), (long)now.GetTime(), lID);
-		Local_db.close();
+		theApp.m_db.execDMLEx(_T("UPDATE Main SET lDate = %d where lID = %d;"), (long)now.GetTime(), lID);
+		if(g_Opt.m_bShowPersistent)
+		{
+			theApp.RefreshView();
+		}
 		bRet = TRUE;
 	}
 	CATCH_SQLITE_EXCEPTION

+ 18 - 12
QPasteWnd.cpp

@@ -754,7 +754,7 @@ LRESULT CQPasteWnd::OnRefreshView(WPARAM wParam, LPARAM lParam)
 	theApp.m_FocusID = -1;
 
 	if(theApp.m_bShowingQuickPaste)
-	{
+	{		
 		FillList();
 		action = _T("Filled List");
 	}
@@ -986,7 +986,13 @@ BOOL CQPasteWnd::FillList(CString csSQLSearch /*=""*/)
 	    m_lItemsPerPage = m_lstHeader.GetCountPerPage();
 	}
 
-	OnSetListCount(m_lstHeader.GetCountPerPage() + 2, 0);
+	{
+		ATL::CCritSecLock csLock(m_CritSection.m_sect);
+		m_mapCache.clear();
+	}
+	
+	m_lstHeader.Invalidate();
+	m_lstHeader.RedrawWindow();
 	CPoint loadItem(-1, m_lstHeader.GetCountPerPage() + 2);
 	m_loadItems.push_back(loadItem);
 	m_thread.FireLoadItems(true);
@@ -3181,8 +3187,6 @@ LRESULT CQPasteWnd::OnSetListCount(WPARAM wParam, LPARAM lParam)
     m_lstHeader.SetItemCountEx(wParam);
     UpdateStatus(false);
 
-	//m_lstHeader.ShowWindow(SW_SHOW);
-
     return TRUE;
 }
 
@@ -3209,18 +3213,20 @@ LRESULT CQPasteWnd::OnRefeshRow(WPARAM wParam, LPARAM lParam)
         }
     }
 
-    int topIndex = m_lstHeader.GetTopIndex();
-    int lastIndex = topIndex + m_lstHeader.GetCountPerPage();
+	int topIndex = m_lstHeader.GetTopIndex();
+	int lastIndex = topIndex + m_lstHeader.GetCountPerPage();
 
-    if(listPos >= topIndex && listPos <= lastIndex)
-    {
-        m_lstHeader.RefreshRow(listPos);
-    }
+	if(listPos >= topIndex && listPos <= lastIndex)
+	{
+		m_lstHeader.RefreshRow(listPos);
+	}
 
 	if(clipId == -2)
 	{
-		Log(_T("End of first load, showing listbox and loading actual count, then accelerators"));
-		m_lstHeader.ShowWindow(SW_SHOW);
+		m_lstHeader.Invalidate();
+		m_lstHeader.RedrawWindow();
+		
+		//Log(_T("End of first load, showing listbox and loading actual count, then accelerators"));
 		m_thread.FireDoQuery();
 		m_thread.FireLoadAccelerators();
 	}

+ 0 - 2
QPasteWndThread.cpp

@@ -71,8 +71,6 @@ void CQPasteWndThread::OnDoQuery(void *param)
 
 	    pasteWnd->m_bFoundClipToSetFocusTo = false;
 	    CountSQL = pasteWnd->m_CountSQL;
-	    pasteWnd->m_mapCache.clear();
-	    pasteWnd->m_loadItems.clear();
 	    pasteWnd->m_bStopQuery = false;
 	}