Browse Source

Hide horizontal and vertical scroll bars unless you mouse over the right or bottom

git-svn-id: svn://svn.code.sf.net/p/ditto-cp/code/trunk@634 595ec19a-5cb4-439b-94a8-42fb3063c22c
sabrogden 14 years ago
parent
commit
e913282710
4 changed files with 121 additions and 17 deletions
  1. 73 7
      QListCtrl.cpp
  2. 2 0
      QListCtrl.h
  3. 43 8
      QPasteWnd.cpp
  4. 3 2
      QPasteWnd.h

+ 73 - 7
QListCtrl.cpp

@@ -21,6 +21,9 @@ static char THIS_FILE[] = __FILE__;
 #define COLOR_SHADOW			RGB(245, 245, 245)
 #define DUMMY_COL_WIDTH			1
 
+#define TIMER_SHOW_PROPERTIES	1
+#define TIMER_SHOW_HIDE_VSCROL	2
+
 /////////////////////////////////////////////////////////////////////////////
 // CQListCtrl
 
@@ -118,6 +121,7 @@ BEGIN_MESSAGE_MAP(CQListCtrl, CListCtrl)
 	ON_NOTIFY_REFLECT(LVN_KEYDOWN, OnKeydown)
 	ON_NOTIFY_REFLECT(NM_DBLCLK, OnDblclk)
 	ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnCustomdrawList)
+	ON_WM_MOUSEMOVE()
 	ON_WM_SYSKEYDOWN()
 	ON_WM_ERASEBKGND()
 	ON_WM_CREATE()
@@ -1221,8 +1225,6 @@ BOOL CQListCtrl::SetItemCountEx(int iCount, DWORD dwFlags /* = 0 */)
 	return CListCtrl::SetItemCountEx(iCount, dwFlags);
 }
 
-#define TIMER_SHOW_PROPERTIES	1
-
 void CQListCtrl::OnSelectionChange(NMHDR* pNMHDR, LRESULT* pResult)
 {
 	NMLISTVIEW *pnmv = (NMLISTVIEW *) pNMHDR;
@@ -1258,14 +1260,53 @@ void CQListCtrl::OnSelectionChange(NMHDR* pNMHDR, LRESULT* pResult)
 
 void CQListCtrl::OnTimer(UINT_PTR nIDEvent) 
 {
-	if(nIDEvent == TIMER_SHOW_PROPERTIES)
+	//http://support.microsoft.com/kb/200054
+	//OnTimer() Is Not Called Repeatedly for a List Control
+	bool callBase = true;
+
+	switch(nIDEvent)
 	{
-		if( theApp.m_bShowingQuickPaste )
-			ShowFullDescription(true);
-		KillTimer(TIMER_SHOW_PROPERTIES);
+		case TIMER_SHOW_PROPERTIES:
+			{
+				if( theApp.m_bShowingQuickPaste )
+					ShowFullDescription(true);
+				KillTimer(TIMER_SHOW_PROPERTIES);
+
+				callBase = false;
+			}
+			break;
+
+		case TIMER_SHOW_HIDE_VSCROL:
+			{
+				CPoint cursorPos;
+				GetCursorPos(&cursorPos);
+
+				CRect crRight;
+				this->GetWindowRect(&crRight);
+
+				crRight.left = crRight.right - 30;
+
+				CRect crBottom;
+				this->GetWindowRect(&crBottom);
+
+				crBottom.top = crBottom.bottom - 30;
+
+				if(crRight.PtInRect(cursorPos) == false && crBottom.PtInRect(cursorPos) == false)
+				{
+					GetParent()->SendMessage(NM_SHOW_HIDE_SCROLLBARS, 0, 0);
+
+					KillTimer(TIMER_SHOW_HIDE_VSCROL);
+				}
+
+				callBase = false;
+			}
+			break;
 	}
 	
-	CListCtrl::OnTimer(nIDEvent);
+	if(callBase)
+	{
+		CListCtrl::OnTimer(nIDEvent);
+	}
 }
 
 void CQListCtrl::SetLogFont(LOGFONT &font)
@@ -1313,4 +1354,29 @@ BOOL CQListCtrl::OnItemDeleted(long lID)
 	BOOL bRet2 = m_RTFData.RemoveKey(lID);
 
 	return (bRet2);
+}
+
+void CQListCtrl::OnMouseMove(UINT nFlags, CPoint point)
+{
+	CRect crRight;
+	this->GetWindowRect(&crRight);
+	ScreenToClient(&crRight);
+
+	crRight.left = crRight.right - 30;
+
+	CRect crBottom;
+	this->GetWindowRect(&crBottom);
+	ScreenToClient(&crBottom);
+
+	crBottom.top = crBottom.bottom - 30;
+
+	if(crRight.PtInRect(point) || crBottom.PtInRect(point))
+	{
+		GetParent()->SendMessage(NM_SHOW_HIDE_SCROLLBARS, 1, 0);
+		SetTimer(TIMER_SHOW_HIDE_VSCROL, 1000, NULL);
+	}
+	else
+	{
+		GetParent()->SendMessage(NM_SHOW_HIDE_SCROLLBARS, 0, 0);
+	}
 }

+ 2 - 0
QListCtrl.h

@@ -34,6 +34,7 @@
 #define NM_ALL_SELECTED				WM_USER+0x119
 #define NM_REFRESH_ROW				WM_USER+0x120
 #define NM_REFRESH_ROW_EXTRA_DATA	WM_USER+0x121
+#define NM_SHOW_HIDE_SCROLLBARS		WM_USER+0x122
 
 #define COPY_BUFFER_HOT_KEY_1_ID	-100
 #define COPY_BUFFER_HOT_KEY_2_ID	-101
@@ -169,6 +170,7 @@ protected:
 	//}}AFX_MSG
 	afx_msg BOOL OnToolTipText(UINT id, NMHDR * pNMHDR, LRESULT * pResult);
 	afx_msg void MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct);
+	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
 	DECLARE_MESSAGE_MAP()
 public:
 	afx_msg void OnKillFocus(CWnd* pNewWnd);

+ 43 - 8
QPasteWnd.cpp

@@ -186,6 +186,7 @@ ON_UPDATE_COMMAND_UI(ID_MENU_NEWCLIP, OnUpdateMenuNewclip)
 ON_WM_CTLCOLOR_REFLECT()
 ON_COMMAND_RANGE(3000, 4000, OnAddinSelect)
 ON_MESSAGE(NM_ALL_SELECTED, OnSelectAll)
+ON_MESSAGE(NM_SHOW_HIDE_SCROLLBARS, OnShowHideScrollBar)
 END_MESSAGE_MAP()
 
 
@@ -296,10 +297,10 @@ void CQPasteWnd::OnSize(UINT nType, int cx, int cy)
         return ;
     }
 
-    MoveControls();
+    MoveControls(false);
 }
 
-void CQPasteWnd::MoveControls()
+void CQPasteWnd::MoveControls(bool showVScroll)
 {
     CRect crRect;
     GetClientRect(crRect);
@@ -341,9 +342,17 @@ void CQPasteWnd::MoveControls()
 		m_btCancel.ShowWindow(SW_HIDE);
     }
 
-	m_lstHeader.MoveWindow(0, topOfListBox, cx, cy - listBoxBottomOffset-topOfListBox);
+	//If not showing the v-scroll bar then move it off of the screen
+	int scrollBarWidth = GetSystemMetrics (SM_CXVSCROLL);
+	if(showVScroll)
+	{
+		scrollBarWidth = 0;
+	}
+
+	m_lstHeader.MoveWindow(0, topOfListBox, cx+scrollBarWidth, cy - listBoxBottomOffset-topOfListBox);
     m_Search.MoveWindow(18, cy - 20, nWidth - 20, 19);
 
+
     m_ShowGroupsFolderBottom.MoveWindow(0, cy - 19, 18, 16);
 
     // Set the column widths
@@ -517,7 +526,7 @@ BOOL CQPasteWnd::ShowQPasteWindow(BOOL bFillList)
     }
     else
     {
-        MoveControls();
+        MoveControls(false);
     }
 
     // always on top... for persistent showing (g_Opt.m_bShowPersistent)
@@ -1011,7 +1020,7 @@ BOOL CQPasteWnd::FillList(CString csSQLSearch /*=""*/)
 	m_loadItems.push_back(loadItem);
 	m_thread.FireLoadItems(true);
 
-	MoveControls();
+	MoveControls(false);
 
 	m_CountSQL.Replace(_T("%"), _T("%%"));
 	m_SQL.Replace(_T("%"), _T("%%"));
@@ -1355,7 +1364,7 @@ LRESULT CQPasteWnd::OnSearch(WPARAM wParam, LPARAM lParam)
 
 	m_lstHeader.SetFocus();
 
-	MoveControls();
+	MoveControls(false);
 
 	m_Search.SetSel(-1, 0);
 
@@ -2523,7 +2532,7 @@ void CQPasteWnd::OnCancelFilter()
     m_Search.SetWindowText(_T(""));
     m_bHandleSearchTextChange = true;
 
-    MoveControls();
+    MoveControls(false);
 
     m_lstHeader.SetFocus();
 }
@@ -2988,7 +2997,7 @@ LRESULT CQPasteWnd::OnGroupTreeMessage(WPARAM wParam, LPARAM lParam)
     m_Search.SetWindowText(_T(""));
     m_bHandleSearchTextChange = true;
 
-    MoveControls();
+    MoveControls(false);
 
     if(id >= -1)
     {
@@ -3317,6 +3326,8 @@ void CQPasteWnd::OnTimer(UINT_PTR nIDEvent)
 {
     if(nIDEvent == TIMER_DO_SEARCH)
     {
+		Log(_T("TIMER_DO_SEARCH timer\n"));
+
 		KillTimer(TIMER_DO_SEARCH);
 
         CString csText;
@@ -3392,3 +3403,27 @@ LRESULT CQPasteWnd::OnSelectAll(WPARAM wParam, LPARAM lParam)
 
     return ret;
 }
+
+LRESULT CQPasteWnd::OnShowHideScrollBar(WPARAM wParam, LPARAM lParam)
+{
+	if(wParam == 1)
+	{
+		Log(_T("OnShowHideScrollBar Showing ScrollBars"));
+	
+		//For the virtical scroll hide the scrollbar by moving it off of the screen
+		//If you hide it using ShowScrollBar the scroll wheel is disabled
+		MoveControls(true);
+
+		//Horizontal scroll bar can be hidden this way, doesn't seem to affect things
+		m_lstHeader.ShowScrollBar(SB_HORZ, 1);
+	}
+	else
+	{
+		Log(_T("OnShowHideScrollBar Hiding ScrollBars"));
+			
+		MoveControls(false);
+		m_lstHeader.ShowScrollBar(SB_HORZ, 0);
+	}
+
+	return 1;
+}

+ 3 - 2
QPasteWnd.h

@@ -107,6 +107,7 @@ public:
     CBitmapButton m_ShowGroupsFolderTop;
     CBitmapButton m_BackButton;
 
+
     CString m_SQL;
     CString m_CountSQL;
     long m_lRecordCount;
@@ -122,7 +123,6 @@ public:
     CF_DibTypeMap m_cf_dibCache;
     CF_DibTypeMap m_cf_rtfCache;
     CCriticalSection m_CritSection;
-
     CAccels m_MainAccels;
 
     void RefreshNc();
@@ -130,7 +130,7 @@ public:
     BOOL FillList(CString csSQLSearch = "");
     BOOL HideQPasteWindow(bool releaseFocus);
     BOOL ShowQPasteWindow(BOOL bFillList = TRUE);
-    void MoveControls();
+    void MoveControls(bool showVScroll);
 
     void DeleteSelectedRows();
 
@@ -291,5 +291,6 @@ protected:
     afx_msg void OnUpdateMenuNewclip(CCmdUI *pCmdUI);
     afx_msg void CQPasteWnd::OnAddinSelect(UINT id);
     afx_msg LRESULT OnSelectAll(WPARAM wParam, LPARAM lParam);
+	afx_msg LRESULT OnShowHideScrollBar(WPARAM wParam, LPARAM lParam);
     //}}AFX_MSG
 };