comctl32: Implementation of tooltips for the treeview controls without TVS_NOTOOLTIPS...
authorIlya Shpigor <shpigor@etersoft.ru>
Tue, 5 May 2009 14:01:18 +0000 (18:01 +0400)
committerVitaly Lipatov <lav@etersoft.ru>
Fri, 8 May 2009 18:26:47 +0000 (22:26 +0400)
dlls/comctl32/treeview.c

index fcb6ae4dafba285d0590643a17bc84061d44369a..9769867541b455924b32457fe7f0831d6b0e0227 100644 (file)
@@ -5007,10 +5007,20 @@ TREEVIEW_Create(HWND hwnd, const CREATESTRUCTW *lpcs)
     TREEVIEW_NotifyFormat(infoPtr, infoPtr->hwndNotify, NF_REQUERY);
 
     if (!(infoPtr->dwStyle & TVS_NOTOOLTIPS))
+    {
+        TTTOOLINFOW ti = { 0 };
+
         infoPtr->hwndToolTip = CreateWindowExW(0, TOOLTIPS_CLASSW, NULL, WS_POPUP,
             CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
             hwnd, 0, 0, 0);
 
+        ti.cbSize = sizeof(TTTOOLINFOW);
+        ti.uFlags = TTF_SUBCLASS;
+        ti.hwnd = infoPtr->hwnd;
+        GetClientRect(infoPtr->hwnd, &ti.rect);
+        SendMessageW(infoPtr->hwndToolTip, TTM_ADDTOOLW, 0, (LPARAM)(LPTOOLINFOW)&ti);
+    }
+
     if (infoPtr->dwStyle & TVS_CHECKBOXES)
         initialize_checkboxes(infoPtr);
 
@@ -5233,6 +5243,60 @@ TREEVIEW_MouseLeave (TREEVIEW_INFO * infoPtr)
     return 0;
 }
 
+static LRESULT
+TREEVIEW_ShowTip (TREEVIEW_INFO * infoPtr, LPARAM lParam)
+{
+    POINT pt;
+    TRACKMOUSEEVENT trackinfo;
+    TREEVIEW_ITEM * item;
+    TTTOOLINFOW ti = { 0 };
+    RECT itemrc;
+
+    /* fill in the TRACKMOUSEEVENT struct */
+    trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
+    trackinfo.dwFlags = TME_QUERY;
+    trackinfo.hwndTrack = infoPtr->hwnd;
+    trackinfo.dwHoverTime = HOVER_DEFAULT;
+
+    /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
+    _TrackMouseEvent(&trackinfo);
+
+    /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
+    if(!(trackinfo.dwFlags & TME_LEAVE))
+    {
+        trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
+
+        /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
+        /* and can properly deactivate the hot item */
+        _TrackMouseEvent(&trackinfo);
+    }
+
+    pt.x = (short)LOWORD(lParam);
+    pt.y = (short)HIWORD(lParam);
+
+    item = TREEVIEW_HitTestPoint(infoPtr, pt);
+
+    if (!item) return 0;
+
+    *(HTREEITEM*)&itemrc = item;
+
+    if (!TREEVIEW_GetItemRect(infoPtr, TRUE, &itemrc)) return 0;
+    if (itemrc.right < infoPtr->clientWidth) return 0;
+    if ((item->pszText == LPSTR_TEXTCALLBACKW)
+        || (item->pszText == NULL)) return 0;
+
+    SendMessageW(infoPtr->hwndToolTip, TTM_GETTOOLINFOW, 0, (LPARAM)(LPTOOLINFOW)&ti);
+    ti.cbSize = sizeof(TTTOOLINFOW);
+    ti.uFlags = TTF_SUBCLASS | TTF_CENTERTIP;
+    ti.hwnd = infoPtr->hwnd;
+    ti.lpszText = item->pszText;
+    ti.uId = 0;
+    CopyRect(&ti.rect, &itemrc);
+    SendMessageW(infoPtr->hwndToolTip, TTM_SETTOOLINFOW, 0, (LPARAM)(LPTOOLINFOW) &ti);
+
+    return 0;
+}
+
 static LRESULT
 TREEVIEW_MouseMove (TREEVIEW_INFO * infoPtr, LPARAM lParam)
 {
@@ -5679,6 +5743,8 @@ TREEVIEW_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
        return TREEVIEW_MouseLeave(infoPtr);
 
     case WM_MOUSEMOVE:
+        if (!(infoPtr->dwStyle & TVS_NOTOOLTIPS))
+            TREEVIEW_ShowTip(infoPtr, lParam);
         if (infoPtr->dwStyle & TVS_TRACKSELECT)
             return TREEVIEW_MouseMove(infoPtr, lParam);
         else