]> git.saurik.com Git - wxWidgets.git/commitdiff
fixed setting tooltips for slider by moving the code working around comctl32.dll...
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 20 Jun 2002 14:49:19 +0000 (14:49 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 20 Jun 2002 14:49:19 +0000 (14:49 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15890 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
include/wx/msw/window.h
src/msw/tbar95.cpp
src/msw/window.cpp

index 975226a840e9f764de997d8c216971c59790eab6..f114502ec83a76d2c084df2d1b04e6967611c3be 100644 (file)
@@ -234,6 +234,7 @@ wxMSW:
   has the capture before release it.
 - fixed bugs in multiple selection wxCheckListBox
 - default button handling is now closer to expected
   has the capture before release it.
 - fixed bugs in multiple selection wxCheckListBox
 - default button handling is now closer to expected
+- setting tooltips for wxSlider now works
 
 wxGTK:
 
 
 wxGTK:
 
index cbe843dd7b02a6d0805bd1f18269f166b34b95ca..28045117b73efebb22dce95d3fbe821cb250f68b 100644 (file)
@@ -464,6 +464,12 @@ protected:
 
 #if wxUSE_TOOLTIPS
     virtual void DoSetToolTip( wxToolTip *tip );
 
 #if wxUSE_TOOLTIPS
     virtual void DoSetToolTip( wxToolTip *tip );
+
+    // process TTN_NEEDTEXT message properly (i.e. fixing the bugs in
+    // comctl32.dll in our code -- see the function body for more info)
+    bool HandleTooltipNotify(WXUINT code,
+                             WXLPARAM lParam,
+                             const wxString& ttip);
 #endif // wxUSE_TOOLTIPS
 
     // the helper functions used by HandleChar/KeyXXX methods
 #endif // wxUSE_TOOLTIPS
 
     // the helper functions used by HandleChar/KeyXXX methods
index c160e85885de4d19a17afdcffae224ad17cba91e..3748168d9e6021a9728299f9dcb84708b2ee9bef 100644 (file)
@@ -863,7 +863,7 @@ bool wxToolBar::MSWOnNotify(int WXUNUSED(idCtrl),
 
     // the tooltips control created by the toolbar is sometimes Unicode, even
     // in an ANSI application - this seems to be a bug in comctl32.dll v5
 
     // the tooltips control created by the toolbar is sometimes Unicode, even
     // in an ANSI application - this seems to be a bug in comctl32.dll v5
-    int code = (int)hdr->code;
+    UINT code = hdr->code;
     if ( (code != TTN_NEEDTEXTA) && (code != TTN_NEEDTEXTW) )
         return FALSE;
 
     if ( (code != TTN_NEEDTEXTA) && (code != TTN_NEEDTEXTW) )
         return FALSE;
 
@@ -878,51 +878,7 @@ bool wxToolBar::MSWOnNotify(int WXUNUSED(idCtrl),
     if ( !tool )
         return FALSE;
 
     if ( !tool )
         return FALSE;
 
-    const wxString& help = tool->GetShortHelp();
-
-    if ( !help.IsEmpty() )
-    {
-        if ( code == TTN_NEEDTEXTA )
-        {
-            ttText->lpszText = (wxChar *)help.c_str();
-        }
-        else
-        {
-#if wxUSE_UNICODE
-            ttText->lpszText = (wxChar *)help.c_str();
-#else
-            // VZ: I don't know why it happens, but the versions of
-            //     comctl32.dll starting from 4.70 sometimes send TTN_NEEDTEXTW
-            //     even to ANSI programs (normally, this message is supposed
-            //     to be sent to Unicode programs only) - hence we need to
-            //     handle it as well, otherwise no tooltips will be shown in
-            //     this case
-
-            size_t lenAnsi = help.Len();
-            #if defined( __MWERKS__ ) || defined( __CYGWIN__ )
-                // MetroWerks doesn't like calling mbstowcs with NULL argument
-                // neither Cygwin does
-                size_t lenUnicode = 2*lenAnsi;
-            #else
-                size_t lenUnicode = mbstowcs(NULL, help, lenAnsi);
-            #endif
-
-            // using the pointer of right type avoids us doing all sorts of
-            // pointer arithmetics ourselves
-            wchar_t *dst = (wchar_t *)ttText->szText,
-                    *pwz = new wchar_t[lenUnicode + 1];
-            mbstowcs(pwz, help, lenAnsi + 1);
-            memcpy(dst, pwz, lenUnicode*sizeof(wchar_t));
-
-            // put the terminating _wide_ NUL
-            dst[lenUnicode] = 0;
-
-            delete [] pwz;
-#endif
-        }
-    }
-
-    return TRUE;
+    return HandleTooltipNotify(code, lParam, tool->GetShortHelp());
 }
 
 // ----------------------------------------------------------------------------
 }
 
 // ----------------------------------------------------------------------------
index d1638dcda51053e6bb621cf8918cb694b5b6a487..20df0dd866a0c29e79c28333fda5b90259b5171e 100644 (file)
@@ -3055,19 +3055,77 @@ bool wxWindowMSW::HandleNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
 #endif
 }
 
 #endif
 }
 
+#if wxUSE_TOOLTIPS
+
+bool wxWindowMSW::HandleTooltipNotify(WXUINT code,
+                                      WXLPARAM lParam,
+                                      const wxString& ttip)
+{
+    // I don't know why it happens, but the versions of comctl32.dll starting
+    // from 4.70 sometimes send TTN_NEEDTEXTW even to ANSI programs (normally,
+    // this message is supposed to be sent to Unicode programs only) -- hence
+    // we need to handle it as well, otherwise no tooltips will be shown in
+    // this case
+
+    if ( !(code == TTN_NEEDTEXTA || code == TTN_NEEDTEXTW) || ttip.empty() )
+    {
+        // not a tooltip message or no tooltip to show anyhow
+        return FALSE;
+    }
+
+    LPTOOLTIPTEXT ttText = (LPTOOLTIPTEXT)lParam;
+
+    if ( code == TTN_NEEDTEXTA )
+    {
+        ttText->lpszText = (wxChar *)ttip.c_str();
+    }
+    else
+    {
+#if wxUSE_UNICODE
+        ttText->lpszText = (wxChar *)ttip.c_str();
+#else // !Unicode
+        size_t lenAnsi = ttip.length();
+
+        // some compilers (MetroWerks and Cygwin) don't like calling mbstowcs
+        // with NULL argument
+        #if defined( __MWERKS__ ) || defined( __CYGWIN__ )
+            size_t lenUnicode = 2*lenAnsi;
+        #else
+            size_t lenUnicode = mbstowcs(NULL, ttip, lenAnsi);
+        #endif
+
+        // using the pointer of right type avoids us doing all sorts of
+        // pointer arithmetics ourselves
+        wchar_t *dst = (wchar_t *)ttText->szText,
+                *pwz = new wchar_t[lenUnicode + 1];
+        mbstowcs(pwz, ttip, lenAnsi + 1);
+        memcpy(dst, pwz, lenUnicode*sizeof(wchar_t));
+
+        // put the terminating wide NUL
+        dst[lenUnicode] = L'\0';
+
+        delete [] pwz;
+#endif // Unicode/!Unicode
+    }
+
+    return TRUE;
+}
+
+#endif // wxUSE_TOOLTIPS
+
 bool wxWindowMSW::MSWOnNotify(int WXUNUSED(idCtrl),
 bool wxWindowMSW::MSWOnNotify(int WXUNUSED(idCtrl),
-                           WXLPARAM lParam,
-                           WXLPARAM* WXUNUSED(result))
+                              WXLPARAM lParam,
+                              WXLPARAM* WXUNUSED(result))
 {
 #if wxUSE_TOOLTIPS
 {
 #if wxUSE_TOOLTIPS
-    NMHDR* hdr = (NMHDR *)lParam;
-    if ( (int)hdr->code == TTN_NEEDTEXT && m_tooltip )
+    if ( m_tooltip )
     {
     {
-        TOOLTIPTEXT *ttt = (TOOLTIPTEXT *)lParam;
-        ttt->lpszText = (wxChar *)m_tooltip->GetTip().c_str();
-
-        // processed
-        return TRUE;
+        NMHDR* hdr = (NMHDR *)lParam;
+        if ( HandleTooltipNotify(hdr->code, lParam, m_tooltip->GetTip()))
+        {
+            // processed
+            return TRUE;
+        }
     }
 #endif // wxUSE_TOOLTIPS
 
     }
 #endif // wxUSE_TOOLTIPS