X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/cb1a1dc963683ea42f9573b23024473f7543c9d9..3f1c6a14cb362d5a9cf56f1a4bd0f47f417c193e:/src/msw/tooltip.cpp diff --git a/src/msw/tooltip.cpp b/src/msw/tooltip.cpp index 281f8e45cb..cbe06c1711 100644 --- a/src/msw/tooltip.cpp +++ b/src/msw/tooltip.cpp @@ -32,28 +32,42 @@ #include "wx/tooltip.h" #include "wx/msw/private.h" -#if (defined(__WIN95__) && !defined(__GNUWIN32__)) || defined(__TWIN32__) +#if (defined(__WIN95__) && !defined(__GNUWIN32__)) || defined(__TWIN32__) || defined(wxUSE_NORLANDER_HEADERS) #include #endif +// ---------------------------------------------------------------------------- +// global variables +// ---------------------------------------------------------------------------- + +// the tooltip parent window +WXHWND wxToolTip::hwndTT = (WXHWND)NULL; + // ---------------------------------------------------------------------------- // private classes // ---------------------------------------------------------------------------- + // a simple wrapper around TOOLINFO Win32 structure +#pragma warning( disable : 4097 ) class wxToolInfo : public TOOLINFO { public: wxToolInfo(wxWindow *win) { // initialize all members +#if __GNUWIN32__ && !defined(wxUSE_NORLANDER_HEADERS) + memset(this, 0, sizeof(TOOLINFO)); +#else ::ZeroMemory(this, sizeof(TOOLINFO)); +#endif cbSize = sizeof(TOOLINFO); uFlags = TTF_IDISHWND; uId = (UINT)win->GetHWND(); } }; +#pragma warning( default : 4097 ) // ---------------------------------------------------------------------------- // private functions @@ -69,67 +83,69 @@ inline LRESULT SendTooltipMessage(WXHWND hwnd, : 0; } +// send a message to all existing tooltip controls +static void SendTooltipMessageToAll(WXHWND hwnd, + UINT msg, + WPARAM wParam, + LPARAM lParam) +{ + if ( hwnd ) + (void)SendTooltipMessage((WXHWND)hwnd, msg, wParam, (void *)lParam); +} + // ============================================================================ // implementation // ============================================================================ // ---------------------------------------------------------------------------- -// "semiglobal" functions - these methods work with the tooltip control which -// is shared among all the wxToolTips of the same frame +// static functions // ---------------------------------------------------------------------------- -// create the tooltip ctrl for our parent frame if it doesn't exist yet -WXHWND wxToolTip::GetToolTipCtrl() + + +void wxToolTip::Enable(bool flag) { - wxWindow *parent = m_window; - while ( parent && !parent->IsKindOf(CLASSINFO(wxFrame)) ) - { - parent = parent->GetParent(); - } + SendTooltipMessageToAll((WXHWND)hwndTT,TTM_ACTIVATE, flag, 0); +} + +void wxToolTip::SetDelay(long milliseconds) +{ + SendTooltipMessageToAll((WXHWND)hwndTT,TTM_SETDELAYTIME, TTDT_INITIAL, milliseconds); +} - wxCHECK_MSG( parent, 0, "can't create tooltip control outside a frame" ); +// --------------------------------------------------------------------------- +// implementation helpers +// --------------------------------------------------------------------------- - wxFrame *frame = (wxFrame *)parent; - HWND hwndTT = (HWND)frame->GetToolTipCtrl(); +// create the tooltip ctrl for our parent frame if it doesn't exist yet +WXHWND wxToolTip::GetToolTipCtrl() +{ if ( !hwndTT ) { - hwndTT = ::CreateWindow(TOOLTIPS_CLASS, + hwndTT = (WXHWND)::CreateWindow(TOOLTIPS_CLASS, (LPSTR)NULL, TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, - (HWND)frame->GetHWND(), (HMENU)NULL, - wxGetInstance(), NULL); + NULL, (HMENU)NULL, + wxGetInstance(), + NULL); + if ( hwndTT ) + { + SetWindowPos((HWND)hwndTT, HWND_TOPMOST, 0, 0, 0, 0, + SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); + } - if ( hwndTT ) - { - frame->SetToolTipCtrl((WXHWND)hwndTT); - } - else - { - wxLogSysError(_("Can not create tooltip control")); - } } return (WXHWND)hwndTT; } -void wxToolTip::Enable(bool flag) -{ - (void)SendTooltipMessage(GetToolTipCtrl(), TTM_ACTIVATE, flag, 0); -} - void wxToolTip::RelayEvent(WXMSG *msg) { (void)SendTooltipMessage(GetToolTipCtrl(), TTM_RELAYEVENT, 0, msg); } -void wxToolTip::SetDelay(long milliseconds) -{ - (void)SendTooltipMessage(GetToolTipCtrl(), TTM_SETDELAYTIME, - TTDT_INITIAL, (void *)milliseconds); -} - // ---------------------------------------------------------------------------- // ctor & dtor // ---------------------------------------------------------------------------- @@ -193,7 +209,7 @@ void wxToolTip::SetTip(const wxString& tip) { // update it immediately wxToolInfo ti(m_window); - ti.lpszText = (char *)m_text.c_str(); + ti.lpszText = (wxChar *)m_text.c_str(); (void)SendTooltipMessage(GetToolTipCtrl(), TTM_UPDATETIPTEXT, 0, &ti); }