]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/tooltip.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: msw/tooltip.cpp
3 // Purpose: wxToolTip class implementation for MSW
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1999 Vadim Zeitlin
9 // Licence: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #include "wx/wxprec.h"
32 #include "wx/tooltip.h"
33 #include "wx/msw/private.h"
35 #if (defined(__WIN95__) && !defined(__GNUWIN32__)) || defined(__TWIN32__) || defined(wxUSE_NORLANDER_HEADERS)
39 // ----------------------------------------------------------------------------
41 // ----------------------------------------------------------------------------
43 // the tooltip parent window
44 WXHWND
wxToolTip::hwndTT
= (WXHWND
)NULL
;
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
50 // a simple wrapper around TOOLINFO Win32 structure
52 #pragma warning( disable : 4097 ) // we inherit from a typedef - so what?
54 class wxToolInfo
: public TOOLINFO
57 wxToolInfo(wxWindow
*win
)
59 // initialize all members
60 ::ZeroMemory(this, sizeof(TOOLINFO
));
62 cbSize
= sizeof(TOOLINFO
);
63 uFlags
= TTF_IDISHWND
;
64 uId
= (UINT
)win
->GetHWND();
68 #pragma warning( default : 4097 )
71 // ----------------------------------------------------------------------------
73 // ----------------------------------------------------------------------------
75 // send a message to the tooltip control
76 inline LRESULT
SendTooltipMessage(WXHWND hwnd
,
81 return hwnd
? ::SendMessage((HWND
)hwnd
, msg
, wParam
, (LPARAM
)lParam
)
85 // send a message to all existing tooltip controls
86 static void SendTooltipMessageToAll(WXHWND hwnd
,
92 (void)SendTooltipMessage((WXHWND
)hwnd
, msg
, wParam
, (void *)lParam
);
95 // ============================================================================
97 // ============================================================================
99 // ----------------------------------------------------------------------------
101 // ----------------------------------------------------------------------------
105 void wxToolTip::Enable(bool flag
)
107 SendTooltipMessageToAll((WXHWND
)hwndTT
,TTM_ACTIVATE
, flag
, 0);
110 void wxToolTip::SetDelay(long milliseconds
)
112 SendTooltipMessageToAll((WXHWND
)hwndTT
,TTM_SETDELAYTIME
, TTDT_INITIAL
, milliseconds
);
115 // ---------------------------------------------------------------------------
116 // implementation helpers
117 // ---------------------------------------------------------------------------
119 // create the tooltip ctrl for our parent frame if it doesn't exist yet
120 WXHWND
wxToolTip::GetToolTipCtrl()
124 hwndTT
= (WXHWND
)::CreateWindow(TOOLTIPS_CLASS
,
127 CW_USEDEFAULT
, CW_USEDEFAULT
,
128 CW_USEDEFAULT
, CW_USEDEFAULT
,
134 SetWindowPos((HWND
)hwndTT
, HWND_TOPMOST
, 0, 0, 0, 0,
135 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
140 return (WXHWND
)hwndTT
;
143 void wxToolTip::RelayEvent(WXMSG
*msg
)
145 (void)SendTooltipMessage(GetToolTipCtrl(), TTM_RELAYEVENT
, 0, msg
);
148 // ----------------------------------------------------------------------------
150 // ----------------------------------------------------------------------------
152 wxToolTip::wxToolTip(const wxString
&tip
)
158 wxToolTip::~wxToolTip()
160 // there is no need to Remove() this tool - it will be done automatically
164 // ----------------------------------------------------------------------------
166 // ----------------------------------------------------------------------------
168 void wxToolTip::Remove()
170 // remove this tool from the tooltip control
173 wxToolInfo
ti(m_window
);
174 (void)SendTooltipMessage(GetToolTipCtrl(), TTM_DELTOOL
, 0, &ti
);
178 void wxToolTip::SetWindow(wxWindow
*win
)
186 wxToolInfo
ti(m_window
);
188 // as we store our text anyhow, it seems useless to waste system memory
189 // by asking the tooltip ctrl to remember it too - instead it will send
190 // us TTN_NEEDTEXT (via WM_NOTIFY) when it is about to be shown
191 ti
.hwnd
= (HWND
)m_window
->GetHWND();
192 ti
.lpszText
= LPSTR_TEXTCALLBACK
;
193 // instead of: ti.lpszText = (char *)m_text.c_str();
195 if ( !SendTooltipMessage(GetToolTipCtrl(), TTM_ADDTOOL
, 0, &ti
) )
197 wxLogSysError(_("Failed to create the tooltip '%s'"),
203 void wxToolTip::SetTip(const wxString
& tip
)
209 // update it immediately
210 wxToolInfo
ti(m_window
);
211 ti
.lpszText
= (wxChar
*)m_text
.c_str();
213 (void)SendTooltipMessage(GetToolTipCtrl(), TTM_UPDATETIPTEXT
, 0, &ti
);
217 #endif // wxUSE_TOOLTIPS