From: David Webster Date: Tue, 9 Jul 2002 22:02:07 +0000 (+0000) Subject: Tooltip udpates X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/05facebb89314f458099e0297abaa9a1b152c3a9?ds=inline Tooltip udpates git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@16122 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/os2/timer.h b/include/wx/os2/timer.h index c1324430ed..3c9ff0267d 100644 --- a/include/wx/os2/timer.h +++ b/include/wx/os2/timer.h @@ -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); diff --git a/include/wx/os2/toolbar.h b/include/wx/os2/toolbar.h index c428072b28..608d65311a 100644 --- a/include/wx/os2/toolbar.h +++ b/include/wx/os2/toolbar.h @@ -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) diff --git a/include/wx/os2/tooltip.h b/include/wx/os2/tooltip.h index 493225f84f..709cd325c9 100644 --- a/include/wx/os2/tooltip.h +++ b/include/wx/os2/tooltip.h @@ -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 diff --git a/src/os2/app.cpp b/src/os2/app.cpp index 909a3ce132..39eeae0c8b 100644 --- a/src/os2/app.cpp +++ b/src/os2/app.cpp @@ -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 // diff --git a/src/os2/toolbar.cpp b/src/os2/toolbar.cpp index bc1e7b9723..0d2812a206 100644 --- a/src/os2/toolbar.cpp +++ b/src/os2/toolbar.cpp @@ -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 diff --git a/src/os2/tooltip.cpp b/src/os2/tooltip.cpp index 224f1b3f0c..90254e2482 100644 --- a/src/os2/tooltip.cpp +++ b/src/os2/tooltip.cpp @@ -32,183 +32,109 @@ // 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 diff --git a/src/os2/window.cpp b/src/os2/window.cpp index 52a983498a..e41f21f386 100644 --- a/src/os2/window.cpp +++ b/src/os2/window.cpp @@ -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 diff --git a/src/os2/wx23.def b/src/os2/wx23.def index 386e080034..92f700571a 100644 --- a/src/os2/wx23.def +++ b/src/os2/wx23.def @@ -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