]>
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 // ----------------------------------------------------------------------------
51 // a simple wrapper around TOOLINFO Win32 structure
53 #pragma warning( disable : 4097 )
55 class wxToolInfo
: public TOOLINFO
58 wxToolInfo(wxWindow
*win
)
60 // initialize all members
61 #if __GNUWIN32__ && !defined(wxUSE_NORLANDER_HEADERS)
62 memset(this, 0, sizeof(TOOLINFO
));
64 ::ZeroMemory(this, sizeof(TOOLINFO
));
67 cbSize
= sizeof(TOOLINFO
);
68 uFlags
= TTF_IDISHWND
;
69 uId
= (UINT
)win
->GetHWND();
73 #pragma warning( default : 4097 )
76 // ----------------------------------------------------------------------------
78 // ----------------------------------------------------------------------------
80 // send a message to the tooltip control
81 inline LRESULT
SendTooltipMessage(WXHWND hwnd
,
86 return hwnd
? ::SendMessage((HWND
)hwnd
, msg
, wParam
, (LPARAM
)lParam
)
90 // send a message to all existing tooltip controls
91 static void SendTooltipMessageToAll(WXHWND hwnd
,
97 (void)SendTooltipMessage((WXHWND
)hwnd
, msg
, wParam
, (void *)lParam
);
100 // ============================================================================
102 // ============================================================================
104 // ----------------------------------------------------------------------------
106 // ----------------------------------------------------------------------------
110 void wxToolTip::Enable(bool flag
)
112 SendTooltipMessageToAll((WXHWND
)hwndTT
,TTM_ACTIVATE
, flag
, 0);
115 void wxToolTip::SetDelay(long milliseconds
)
117 SendTooltipMessageToAll((WXHWND
)hwndTT
,TTM_SETDELAYTIME
, TTDT_INITIAL
, milliseconds
);
120 // ---------------------------------------------------------------------------
121 // implementation helpers
122 // ---------------------------------------------------------------------------
124 // create the tooltip ctrl for our parent frame if it doesn't exist yet
125 WXHWND
wxToolTip::GetToolTipCtrl()
129 hwndTT
= (WXHWND
)::CreateWindow(TOOLTIPS_CLASS
,
132 CW_USEDEFAULT
, CW_USEDEFAULT
,
133 CW_USEDEFAULT
, CW_USEDEFAULT
,
139 SetWindowPos((HWND
)hwndTT
, HWND_TOPMOST
, 0, 0, 0, 0,
140 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
145 return (WXHWND
)hwndTT
;
148 void wxToolTip::RelayEvent(WXMSG
*msg
)
150 (void)SendTooltipMessage(GetToolTipCtrl(), TTM_RELAYEVENT
, 0, msg
);
153 // ----------------------------------------------------------------------------
155 // ----------------------------------------------------------------------------
157 wxToolTip::wxToolTip(const wxString
&tip
)
163 wxToolTip::~wxToolTip()
165 // there is no need to Remove() this tool - it will be done automatically
169 // ----------------------------------------------------------------------------
171 // ----------------------------------------------------------------------------
173 void wxToolTip::Remove()
175 // remove this tool from the tooltip control
178 wxToolInfo
ti(m_window
);
179 (void)SendTooltipMessage(GetToolTipCtrl(), TTM_DELTOOL
, 0, &ti
);
183 void wxToolTip::SetWindow(wxWindow
*win
)
191 wxToolInfo
ti(m_window
);
193 // as we store our text anyhow, it seems useless to waste system memory
194 // by asking the tooltip ctrl to remember it too - instead it will send
195 // us TTN_NEEDTEXT (via WM_NOTIFY) when it is about to be shown
196 ti
.hwnd
= (HWND
)m_window
->GetHWND();
197 ti
.lpszText
= LPSTR_TEXTCALLBACK
;
198 // instead of: ti.lpszText = (char *)m_text.c_str();
200 if ( !SendTooltipMessage(GetToolTipCtrl(), TTM_ADDTOOL
, 0, &ti
) )
202 wxLogSysError(_("Failed to create the tooltip '%s'"),
208 void wxToolTip::SetTip(const wxString
& tip
)
214 // update it immediately
215 wxToolInfo
ti(m_window
);
216 ti
.lpszText
= (wxChar
*)m_text
.c_str();
218 (void)SendTooltipMessage(GetToolTipCtrl(), TTM_UPDATETIPTEXT
, 0, &ti
);
222 #endif // wxUSE_TOOLTIPS