OSDN Git Service

[ 780827 ] Tooltips for DirView
authorLaurent Ganier <laoran@users.sourceforge.net>
Sun, 3 Aug 2003 08:30:09 +0000 (08:30 +0000)
committerLaurent Ganier <laoran@users.sourceforge.net>
Sun, 3 Aug 2003 08:30:09 +0000 (08:30 +0000)
Src/DirView.cpp
Src/DirView.h
Src/readme.txt

index 19bddcd..2bb1d74 100644 (file)
@@ -48,12 +48,12 @@ IMPLEMENT_DYNCREATE(CDirView, CListViewEx)
 CDirView::CDirView()
 : m_numcols(-1)
 {
-       m_pList=NULL;
+       m_pList = NULL;
 }
 
 CDirView::~CDirView()
 {
-        m_imageList.DeleteImageList();
+       m_imageList.DeleteImageList();
 }
 
 
@@ -100,8 +100,10 @@ BEGIN_MESSAGE_MAP(CDirView, CListViewEx)
        ON_COMMAND(ID_REFRESH, OnRefresh)
        ON_UPDATE_COMMAND_UI(ID_REFRESH, OnUpdateRefresh)
        ON_WM_TIMER()
+       ON_WM_MOUSEMOVE()
        //}}AFX_MSG_MAP
        ON_NOTIFY_REFLECT(LVN_COLUMNCLICK, OnColumnClick)
+       ON_NOTIFY_REFLECT(LVN_GETINFOTIP, OnInfoTip)
 END_MESSAGE_MAP()
 
 /////////////////////////////////////////////////////////////////////////////
@@ -194,7 +196,12 @@ void CDirView::OnInitialUpdate()
 
        // Allow user to rearrange columns via drag&drop of headers
        // if they have a new enough common controls
-       m_pList->SetExtendedStyle(LVS_EX_HEADERDRAGDROP);
+       // Also enable infotips & full row selection
+       m_pList->SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP | LVS_EX_INFOTIP);
+
+       // Disable CListViewEx's full row selection which only causes problems
+       // (tooltips and custom draw do not work!)
+       SetFullRowSel(FALSE);
 }
 
 void CDirView::OnLButtonDblClk(UINT nFlags, CPoint point) 
@@ -1313,3 +1320,33 @@ void CDirView::OnTimer(UINT nIDEvent)
        
        CListViewEx::OnTimer(nIDEvent);
 }
+
+/// Called before infotip is shown to get infotip text
+void CDirView::OnInfoTip(NMHDR * pNMHDR, LRESULT * pResult)
+{
+       LVHITTESTINFO lvhti = {0};
+       NMLVGETINFOTIP * pInfoTip = reinterpret_cast<NMLVGETINFOTIP*>(pNMHDR);
+       ASSERT(pInfoTip);
+       
+       // Get subitem under mouse cursor
+       lvhti.pt = m_ptLastMousePos;
+       m_pList->SubItemHitTest(&lvhti);
+
+       // Values >= 0 are subitem indexes
+       if (lvhti.iSubItem >= 0)
+       {
+               // Check that we are over icon or label
+               if ((lvhti.flags & LVHT_ONITEMICON) || (lvhti.flags & LVHT_ONITEMLABEL))
+               {
+                       // Set item text to tooltip
+                       CString strText = m_pList->GetItemText(lvhti.iItem, lvhti.iSubItem);
+                       _tcscpy(pInfoTip->pszText, strText);
+               }
+       }
+}
+
+void CDirView::OnMouseMove(UINT nFlags, CPoint point) 
+{
+       m_ptLastMousePos = point;
+       CListViewEx::OnMouseMove(nFlags, point);
+}
index 3a65fb4..6bd81bf 100644 (file)
@@ -165,7 +165,7 @@ protected:
        int m_numcols;
        CArray<int, int> m_colorder;
        CArray<int, int> m_invcolorder;
-
+       CPoint m_ptLastMousePos;
        
        // Generated message map functions
        afx_msg void OnColumnClick(NMHDR* pNMHDR, LRESULT* pResult);
@@ -211,10 +211,12 @@ protected:
        afx_msg void OnRefresh();
        afx_msg void OnUpdateRefresh(CCmdUI* pCmdUI);
        afx_msg void OnTimer(UINT nIDEvent);
+       afx_msg void OnMouseMove(UINT nFlags, CPoint point);
        //}}AFX_MSG
        DECLARE_MESSAGE_MAP()
        BOOL OnHeaderBeginDrag(LPNMHEADER hdr, LRESULT* pResult);
        BOOL OnHeaderEndDrag(LPNMHEADER hdr, LRESULT* pResult);
+       afx_msg void OnInfoTip(NMHDR * pNMHDR, LRESULT * pResult);
 
 private:
        void OpenSelection();
index 0ef25fb..a46d565 100644 (file)
@@ -1,3 +1,7 @@
+2003-07-31 Kimmo
+ PATCH: [ 780827 ] Tooltips for DirView
+  WinMerge: DirView.cpp DirView.h
+
 2003-07-31 Laoran
  PATCH: [ 780508 ] Convert Line Length array to CArray
   WinMerge: ccrystaltextview.cpp ccrystaltextview.h