]> git.saurik.com Git - wxWidgets.git/commitdiff
Tooltip udpates
authorDavid Webster <Dave.Webster@bhmi.com>
Tue, 9 Jul 2002 22:02:07 +0000 (22:02 +0000)
committerDavid Webster <Dave.Webster@bhmi.com>
Tue, 9 Jul 2002 22:02:07 +0000 (22:02 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@16122 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/os2/timer.h
include/wx/os2/toolbar.h
include/wx/os2/tooltip.h
src/os2/app.cpp
src/os2/toolbar.cpp
src/os2/tooltip.cpp
src/os2/window.cpp
src/os2/wx23.def

index c1324430edfe767cf0248a14cf9f208a9da694fe..3c9ff0267d047473080c3ec902a7c0af15999499 100644 (file)
@@ -36,6 +36,7 @@ public:
     virtual void Stop(void);
 
     inline virtual bool IsRunning(void) const { return m_ulId != 0L; }
+    inline        ULONG GetTimerId(void) const { return m_ulId; }
 
 protected:
     void Init(void);
index c428072b28d746115c90e13fe8d8d802656653f0..608d65311a0e7603fa10907e70dfdb43f7870e89 100644 (file)
@@ -200,8 +200,9 @@ private:
 
     wxTimer                         m_vToolTimer;
     wxTimer                         m_vToolExpTimer;
-    ULONG                           m_ulToolTimer;
-    ULONG                           m_ulToolExpTimer;
+    wxToolTip*                      m_pToolTip;
+    wxCoord                         m_vXMouse;
+    wxCoord                         m_vYMouse;
 
     DECLARE_EVENT_TABLE()
     DECLARE_DYNAMIC_CLASS(wxToolBar)
index 493225f84fd9985d990400fe1542f66e81f71abf..709cd325c9683af4b71e5aed59e44c252d7b75dd 100644 (file)
@@ -13,37 +13,29 @@ class wxToolTip : public wxObject
 {
 public:
     // ctor & dtor
-    wxToolTip(const wxString &tip);
+    wxToolTip(const wxString &rsTip);
     virtual ~wxToolTip();
 
-    // accessors
-        // tip text
-    void SetTip(const wxString& tip);
-    const wxString& GetTip() const { return m_text; }
+    //
+    // Accessors
+    //
+    inline const wxString& GetTip(void) const { return m_sText; }
+    inline wxWindow*       GetWindow(void) const { return m_pWindow; }
 
-        // the window we're associated with
-    void SetWindow(wxWindow *win);
-    wxWindow *GetWindow() const { return m_window; }
+           void            SetTip(const wxString& rsTip);
+    inline void            SetWindow(wxWindow* pWin) { m_pWindow = pWin; }
 
-    // controlling tooltip behaviour: globally change tooltip parameters
-        // enable or disable the tooltips globally
-    static void Enable(bool flag);
-        // set the delay after which the tooltip appears
-    static void SetDelay(long milliseconds);
-
-    // implementation
-    void RelayEvent(WXMSG *msg);
+    //
+    // Implementation
+    //
+    void DisplayToolTipWindow(const wxPoint& rPos);
+    void HideToolTipWindow(void);
 
 private:
-    static WXHWND hwndTT;
-    // create the tooltip ctrl for our parent frame if it doesn't exist yet
-    // and return its window handle
-    WXHWND GetToolTipCtrl();
-
-    // remove this tooltip from the tooltip control
-    void Remove();
+    void Create(const wxString &rsTip);
 
-    wxString  m_text;           // tooltip text
-    wxWindow *m_window;         // window we're associated with
-};
+    HWND                            m_hWnd;
+    wxString                        m_sText;           // tooltip text
+    wxWindow*                       m_pWindow;         // window we're associated with
+}; // end of CLASS wxToolTip
 
index 909a3ce1327fe8be95179961a40bead528d0bdeb..39eeae0c8b6bb8ad8bc90d05f963e93c8f464661 100644 (file)
@@ -876,21 +876,6 @@ bool wxApp::ProcessMessage(
     wxWindow*                       pWndThis = wxFindWinFromHandle((WXHWND)hWnd);
     wxWindow*                       pWnd;
 
-#if wxUSE_TOOLTIPS
-    //
-    // We must relay WM_MOUSEMOVE events to the tooltip ctrl if we want it to
-    // popup the tooltip bubbles
-    //
-    if (pWndThis && (pMsg->msg == WM_MOUSEMOVE))
-    {
-        wxToolTip*                  pToolTip = pWndThis->GetToolTip();
-        if (pToolTip)
-        {
-            pToolTip->RelayEvent(pWxmsg);
-        }
-    }
-#endif // wxUSE_TOOLTIPS
-
     //
     // Pass non-system timer messages to the wxTimerProc
     //
index bc1e7b972305d051396307e953e99d0254e5d0be..0d2812a206cb67c7246330d07fe8283a192e4908 100644 (file)
@@ -21,6 +21,7 @@
     #include "wx/dcmemory.h"
 #endif
 
+#include "wx/tooltip.h"
 #include "wx/toolbar.h"
 
 bool                                wxToolBar::m_bInitialized = FALSE;
@@ -366,6 +367,8 @@ void wxToolBar::Init()
 
     m_defaultWidth = 16;
     m_defaultHeight = 15;
+
+    m_pToolTip = NULL;
 } // end of wxToolBar::Init
 
 wxToolBarToolBase* wxToolBar::DoAddTool(
@@ -635,6 +638,11 @@ bool wxToolBar::Create(
 
 wxToolBar::~wxToolBar()
 {
+    if (m_pToolTip)
+    {
+        delete m_pToolTip;
+        m_pToolTip = NULL;
+    }
 } // end of wxToolBar::~wxToolBar
 
 bool wxToolBar::Realize()
@@ -887,11 +895,21 @@ void wxToolBar::OnMouseEvent(
   wxMouseEvent&                     rEvent
 )
 {
+    POINTL                          vPoint;
+    HWND                            hWnd;
     wxCoord                         vX;
     wxCoord                         vY;
     HPOINTER                        hPtr = ::WinQuerySysPointer(HWND_DESKTOP, SPTR_ARROW, FALSE);
 
     ::WinSetPointer(HWND_DESKTOP, hPtr);
+    ::WinQueryPointerPos(HWND_DESKTOP, &vPoint);
+    hWnd = ::WinWindowFromPoint(HWND_DESKTOP, &vPoint, TRUE);
+    if (hWnd != (HWND)GetHwnd())
+    {
+        m_vToolTimer.Stop();
+        return;
+    }
+
     rEvent.GetPosition(&vX, &vY);
 
     wxToolBarTool*            pTool = (wxToolBarTool *)FindToolForPosition( vX
@@ -907,10 +925,14 @@ void wxToolBar::OnMouseEvent(
         ReleaseMouse();
     }
 
-    m_vToolTimer.Stop();
-    m_vToolTimer.Start(3000L, FALSE);
     if (!pTool)
     {
+        m_vToolTimer.Stop();
+        if (m_pToolTip)
+        {
+            delete m_pToolTip;
+            m_pToolTip = NULL;
+        }
         if (m_nCurrentTool > -1)
         {
             if (rEvent.LeftIsDown())
@@ -952,6 +974,13 @@ void wxToolBar::OnMouseEvent(
                          );
             m_nCurrentTool = pTool->GetId();
             OnMouseEnter(m_nCurrentTool);
+            if (!pTool->GetShortHelp().IsEmpty())
+            {
+                m_pToolTip = new wxToolTip(pTool->GetShortHelp());
+                m_vXMouse = (wxCoord)vPoint.x;
+                m_vYMouse = (wxCoord)vPoint.y;
+                m_vToolTimer.Start(3000L, TRUE);
+            }
             if (!pTool->IsToggled())
                 RaiseTool(pTool);
         }
@@ -1413,13 +1442,18 @@ void wxToolBar::OnTimer (
   wxTimerEvent&                     rEvent
 )
 {
-    if (rEvent.GetId() == (int)m_ulToolTimer)
+    if (rEvent.GetId() == (int)m_vToolTimer.GetTimerId())
     {
-        (void)wxMessageBox("wxWindows toolbar timer", "ToolTimer");
+        wxPoint                     vPos( m_vXMouse
+                                         ,m_vYMouse
+                                        );
+
+        m_pToolTip->DisplayToolTipWindow(vPos);
+        m_vToolExpTimer.Start(3000L, TRUE);
     }
-    else if (rEvent.GetId() == (int)m_ulToolExpTimer)
+    else if (rEvent.GetId() == (int)m_vToolExpTimer.GetTimerId())
     {
-        (void)wxMessageBox("wxWindows toolbar timer", "ToolExpTimer");
+        m_pToolTip->HideToolTipWindow();
     }
 } // end of wxToolBar::OnTimer
 
index 224f1b3f0c8395e3ab3255c464f9d1d5fe0494fa..90254e24821cff9377068628fc8a545aff173fef 100644 (file)
 // global variables
 // ----------------------------------------------------------------------------
 
-// the tooltip parent window
-WXHWND wxToolTip::hwndTT = (WXHWND)NULL;
-
-// ----------------------------------------------------------------------------
-// private classes
-// ----------------------------------------------------------------------------
-
-
-// a simple wrapper around TOOLINFO Win32 structure
-class wxToolInfo // define a TOOLINFO for OS/2 here : public TOOLINFO
-{
-public:
-    wxToolInfo(wxWindow *win)
-    {
-        // initialize all members
-//        ::ZeroMemory(this, sizeof(TOOLINFO));
-
-        cbSize = sizeof(this);
-        uFlags = 0; // TTF_IDISHWND;
-        uId = (UINT)win->GetHWND();
-    }
-    size_t        cbSize;
-    ULONG         uFlags;
-    UINT          uId;
-    HWND          hwnd;
-    char*         lpszText;
-};
-
-// ----------------------------------------------------------------------------
-// private functions
-// ----------------------------------------------------------------------------
-
-// send a message to the tooltip control
-inline MRESULT SendTooltipMessage(WXHWND hwnd,
-                                  UINT msg,
-                                  MPARAM wParam,
-                                  MPARAM lParam)
-{
-//    return hwnd ? ::SendMessage((HWND)hwnd, msg, wParam, (MPARAM)lParam)
-//                : 0;
-    return (MRESULT)0;
-}
-
-// send a message to all existing tooltip controls
-static void SendTooltipMessageToAll(WXHWND hwnd,
-                                    UINT msg,
-                                    MPARAM wParam,
-                                    MPARAM lParam)
-{
-   if ( hwnd )
-     (void)SendTooltipMessage((WXHWND)hwnd, msg, wParam, lParam);
-}
-
-// ============================================================================
-// implementation
-// ============================================================================
-
-// ----------------------------------------------------------------------------
-// static functions
-// ----------------------------------------------------------------------------
-
-void wxToolTip::Enable(bool flag)
-{
-//    SendTooltipMessageToAll((WXHWND)hwndTT,TTM_ACTIVATE, flag, 0);
-}
-
-void wxToolTip::SetDelay(long milliseconds)
-{
-//    SendTooltipMessageToAll((WXHWND)hwndTT,TTM_SETDELAYTIME, TTDT_INITIAL, milliseconds);
-}
-
-// ---------------------------------------------------------------------------
-// implementation helpers
-// ---------------------------------------------------------------------------
-
-// create the tooltip ctrl for our parent frame if it doesn't exist yet
-WXHWND wxToolTip::GetToolTipCtrl()
-{
-// TODO:
-/*
-    if ( !hwndTT )
-    {
-        hwndTT = (WXHWND)::CreateWindow(TOOLTIPS_CLASS,
-                                (LPSTR)NULL,
-                                TTS_ALWAYSTIP,
-                                CW_USEDEFAULT, CW_USEDEFAULT,
-                                CW_USEDEFAULT, CW_USEDEFAULT,
-                                NULL, (HMENU)NULL,
-                                wxGetInstance(),
-                                NULL);
-       if ( hwndTT )
-       {
-           SetWindowPos((HWND)hwndTT, HWND_TOPMOST, 0, 0, 0, 0,
-                        SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
-       }
-
-    }
-    return (WXHWND)hwndTT;
-*/
-    return (WXHWND)0;
-}
-
-void wxToolTip::RelayEvent(WXMSG *msg)
-{
-//  (void)SendTooltipMessage(GetToolTipCtrl(), TTM_RELAYEVENT, 0, msg);
-}
-
 // ----------------------------------------------------------------------------
 // ctor & dtor
 // ----------------------------------------------------------------------------
 
-wxToolTip::wxToolTip(const wxString &tip)
-         : m_text(tip)
+wxToolTip::wxToolTip(
+  const wxString&                   rsTip
+)
+: m_sText(rsTip)
+, m_pWindow(NULL)
 {
-    m_window = NULL;
-}
+    Create(rsTip);
+} // end of wxToolTip::wxToolTip
 
 wxToolTip::~wxToolTip()
 {
-    // there is no need to Remove() this tool - it will be done automatically
-    // anyhow
-}
-
-// ----------------------------------------------------------------------------
-// others
-// ----------------------------------------------------------------------------
+    if (m_hWnd)
+        ::WinDestroyWindow(m_hWnd);
+} // end of wxToolTip::~wxToolTip
 
-void wxToolTip::Remove()
+void wxToolTip::Create(
+  const wxString&                   rsTip
+)
 {
-    // remove this tool from the tooltip control
-    if ( m_window )
-    {
-        wxToolInfo ti(m_window);
-//      (void)SendTooltipMessage(GetToolTipCtrl(), TTM_DELTOOL, 0, &ti);
-    }
-}
-
-void wxToolTip::SetWindow(wxWindow *win)
+    ULONG                           lStyle = ES_READONLY | ES_MARGIN | ES_CENTER;
+    wxColour                        vColor;
+    LONG                            lColor;
+    char                            zFont[128];
+
+    m_hWnd = ::WinCreateWindow( HWND_DESKTOP
+                               ,WC_ENTRYFIELD
+                               ,rsTip.c_str()
+                               ,lStyle
+                               ,0, 0, 0, 0
+                               ,NULLHANDLE
+                               ,HWND_TOP
+                               ,1
+                               ,NULL
+                               ,NULL
+                              );
+    if (!m_hWnd)
+        wxLogError("Unable to create tooltip window");
+
+    vColor.InitFromName("YELLOW");
+    lColor = (LONG)vColor.GetPixel();
+    ::WinSetPresParam( m_hWnd
+                      ,PP_BACKGROUNDCOLOR
+                      ,sizeof(LONG)
+                      ,(PVOID)&lColor
+                     );
+    strcpy(zFont, "10.Helv");
+    ::WinSetPresParam( m_hWnd
+                      ,PP_FONTNAMESIZE
+                      ,strlen(zFont) + 1
+                      ,(PVOID)zFont
+                     );
+} // end of wxToolTip::Create
+
+void wxToolTip::DisplayToolTipWindow(
+  const wxPoint&                    rPoint
+)
 {
-    Remove();
-
-    m_window = win;
-
-    if ( m_window )
-    {
-        wxToolInfo ti(m_window);
-
-        // as we store our text anyhow, it seems useless to waste system memory
-        // by asking the tooltip ctrl to remember it too - instead it will send
-        // us TTN_NEEDTEXT (via WM_NOTIFY) when it is about to be shown
-        ti.hwnd = (HWND)m_window->GetHWND();
-//        ti.lpszText = LPSTR_TEXTCALLBACK;
-        // instead of: ti.lpszText = (char *)m_text.c_str();
-
-// TODO:
-/*
-        if ( !SendTooltipMessage(GetToolTipCtrl(), TTM_ADDTOOL, 0, &ti) )
-        {
-            wxLogSysError(_("Failed to create the tooltip '%s'"),
-                          m_text.c_str());
-        }
-*/
-    }
-}
-
-void wxToolTip::SetTip(const wxString& tip)
+    LONG                            lX = rPoint.x;
+    LONG                            lY = rPoint.y - 30;
+    LONG                            lWidth = 0L;
+    LONG                            lHeight = 0L;
+
+    lWidth = m_sText.Length() * 13;
+    lHeight = 15;
+    ::WinSetWindowPos( m_hWnd
+                      ,HWND_TOP
+                      ,lX
+                      ,lY
+                      ,lWidth
+                      ,lHeight
+                      ,SWP_MOVE | SWP_SIZE | SWP_SHOW
+                     );
+} // end of wxToolTip::DisplayToolTipWindow
+
+void wxToolTip::HideToolTipWindow()
 {
-    m_text = tip;
+    ::WinShowWindow(m_hWnd, FALSE);
+} // end of wxToolTip::HideToolTipWindow
 
-    if ( m_window )
-    {
-        // update it immediately
-        wxToolInfo ti(m_window);
-        ti.lpszText = (wxChar *)m_text.c_str();
-
-//      (void)SendTooltipMessage(GetToolTipCtrl(), TTM_UPDATETIPTEXT, 0, &ti);
-    }
-}
+void wxToolTip::SetTip(
+  const wxString&                   rsTip
+)
+{
+    SWP                             vSwp;
+    LONG                            lWidth = 0L;
+    LONG                            lHeight = 0L;
+
+    ::WinQueryWindowPos(m_hWnd, &vSwp);
+    m_sText = rsTip;
+    lWidth = rsTip.Length() * 13;
+    lHeight = 15;
+    ::WinSetWindowPos( m_hWnd
+                      ,HWND_TOP
+                      ,vSwp.cx
+                      ,vSwp.cy
+                      ,lWidth
+                      ,lHeight
+                      ,SWP_MOVE | SWP_SIZE | SWP_SHOW
+                     );
+} // end of wxToolTip::SetTip
 
 #endif // wxUSE_TOOLTIPS
index 52a983498a0940591749a505b324dec09d193847..e41f21f386436e7e7542559bb6586bb8ea5b5d47 100644 (file)
@@ -2330,17 +2330,6 @@ bool wxWindowOS2::OS2ProcessMessage(
     pMsg = pMsg; // just shut up the compiler
 #endif // __WXUNIVERSAL__
 
-#if wxUSE_TOOLTIPS
-    if ( m_tooltip )
-    {
-        // relay mouse move events to the tooltip control
-        QMSG*                       pQMsg = (QMSG*)pMsg;
-
-        if (pQMsg->msg == WM_MOUSEMOVE )
-            m_tooltip->RelayEvent(pMsg);
-    }
-#endif // wxUSE_TOOLTIPS
-
     return FALSE;
 } // end of wxWindowOS2::OS2ProcessMessage
 
index 386e0800346ee6f7bb2f3c57b01fb4aec402d72f..92f700571afa14b471598a8f896890561d086197 100644 (file)
@@ -4,7 +4,7 @@ DATA MULTIPLE NONSHARED READWRITE LOADONCALL
 CODE LOADONCALL
 
 EXPORTS
-;From library:  F:\DEV\WX2\WXWINDOWS\LIB\wx.lib
+;From library:  H:\Dev\Wx2\WxWindows\Lib\wx.lib
   ;From object file:  dummy.cpp
     ;PUBDEFs (Symbols available from object file):
       wxDummyChar
@@ -1946,7 +1946,7 @@ EXPORTS
       wxEVT_NC_LEFT_DCLICK
       wxEVT_INIT_DIALOG
       wxEVT_COMMAND_SET_FOCUS
-  ;From object file:  F:\DEV\WX2\WXWINDOWS\src\common\extended.c
+  ;From object file:  H:\DEV\WX2\WXWINDOWS\src\common\extended.c
     ;PUBDEFs (Symbols available from object file):
       ConvertToIeeeExtended
       ConvertFromIeeeExtended
@@ -6150,7 +6150,7 @@ EXPORTS
       Read32__17wxTextInputStreamFv
       ;wxTextInputStream::SkipIfEndOfLine(char)
       SkipIfEndOfLine__17wxTextInputStreamFc
-  ;From object file:  F:\DEV\WX2\WXWINDOWS\src\common\unzip.c
+  ;From object file:  H:\DEV\WX2\WXWINDOWS\src\common\unzip.c
     ;PUBDEFs (Symbols available from object file):
       unzReadCurrentFile
       unzGetCurrentFileInfo
@@ -14746,25 +14746,17 @@ EXPORTS
     ;PUBDEFs (Symbols available from object file):
       ;wxToolTip::wxToolTip(const wxString&)
       __ct__9wxToolTipFRC8wxString
-      ;wxToolTip::SetWindow(wxWindow*)
-      SetWindow__9wxToolTipFP8wxWindow
       __vft9wxToolTip8wxObject
-      ;wxToolTip::RelayEvent(void**)
-      RelayEvent__9wxToolTipFPPv
       ;wxToolTip::~wxToolTip()
       __dt__9wxToolTipFv
-      ;wxToolTip::Enable(unsigned long)
-      Enable__9wxToolTipFUl
-      ;wxToolTip::SetDelay(long)
-      SetDelay__9wxToolTipFl
+      ;wxToolTip::HideToolTipWindow()
+      HideToolTipWindow__9wxToolTipFv
       ;wxToolTip::SetTip(const wxString&)
       SetTip__9wxToolTipFRC8wxString
-      ;wxToolTip::GetToolTipCtrl()
-      GetToolTipCtrl__9wxToolTipFv
-      ;wxToolTip::Remove()
-      Remove__9wxToolTipFv
-      ;wxToolTip::hwndTT
-      hwndTT__9wxToolTip
+      ;wxToolTip::DisplayToolTipWindow(const wxPoint&)
+      DisplayToolTipWindow__9wxToolTipFRC7wxPoint
+      ;wxToolTip::Create(const wxString&)
+      Create__9wxToolTipFRC8wxString
   ;From object file:  ..\os2\toplevel.cpp
     ;PUBDEFs (Symbols available from object file):
       ;wxTopLevelWindowOS2::OS2GetStyle(long,unsigned long*) const