]>
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
52 #pragma warning( disable : 4097 )
53 class wxToolInfo
: public TOOLINFO
56 wxToolInfo(wxWindow
*win
)
58 // initialize all members
59 #if __GNUWIN32__ && !defined(wxUSE_NORLANDER_HEADERS)
60 memset(this, 0, sizeof(TOOLINFO
));
62 ::ZeroMemory(this, sizeof(TOOLINFO
));
65 cbSize
= sizeof(TOOLINFO
);
66 uFlags
= TTF_IDISHWND
;
67 uId
= (UINT
)win
->GetHWND();
70 #pragma warning( default : 4097 )
72 // ----------------------------------------------------------------------------
74 // ----------------------------------------------------------------------------
76 // send a message to the tooltip control
77 inline LRESULT
SendTooltipMessage(WXHWND hwnd
,
82 return hwnd
? ::SendMessage((HWND
)hwnd
, msg
, wParam
, (LPARAM
)lParam
)
86 // send a message to all existing tooltip controls
87 static void SendTooltipMessageToAll(WXHWND hwnd
,
93 (void)SendTooltipMessage((WXHWND
)hwnd
, msg
, wParam
, (void *)lParam
);
96 // ============================================================================
98 // ============================================================================
100 // ----------------------------------------------------------------------------
102 // ----------------------------------------------------------------------------
106 void wxToolTip::Enable(bool flag
)
108 SendTooltipMessageToAll((WXHWND
)hwndTT
,TTM_ACTIVATE
, flag
, 0);
111 void wxToolTip::SetDelay(long milliseconds
)
113 SendTooltipMessageToAll((WXHWND
)hwndTT
,TTM_SETDELAYTIME
, TTDT_INITIAL
, milliseconds
);
116 // ---------------------------------------------------------------------------
117 // implementation helpers
118 // ---------------------------------------------------------------------------
120 // create the tooltip ctrl for our parent frame if it doesn't exist yet
121 WXHWND
wxToolTip::GetToolTipCtrl()
125 hwndTT
= (WXHWND
)::CreateWindow(TOOLTIPS_CLASS
,
128 CW_USEDEFAULT
, CW_USEDEFAULT
,
129 CW_USEDEFAULT
, CW_USEDEFAULT
,
135 SetWindowPos((HWND
)hwndTT
, HWND_TOPMOST
, 0, 0, 0, 0,
136 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
141 return (WXHWND
)hwndTT
;
144 void wxToolTip::RelayEvent(WXMSG
*msg
)
146 (void)SendTooltipMessage(GetToolTipCtrl(), TTM_RELAYEVENT
, 0, msg
);
149 // ----------------------------------------------------------------------------
151 // ----------------------------------------------------------------------------
153 wxToolTip::wxToolTip(const wxString
&tip
)
159 wxToolTip::~wxToolTip()
161 // there is no need to Remove() this tool - it will be done automatically
165 // ----------------------------------------------------------------------------
167 // ----------------------------------------------------------------------------
169 void wxToolTip::Remove()
171 // remove this tool from the tooltip control
174 wxToolInfo
ti(m_window
);
175 (void)SendTooltipMessage(GetToolTipCtrl(), TTM_DELTOOL
, 0, &ti
);
179 void wxToolTip::SetWindow(wxWindow
*win
)
187 wxToolInfo
ti(m_window
);
189 // as we store our text anyhow, it seems useless to waste system memory
190 // by asking the tooltip ctrl to remember it too - instead it will send
191 // us TTN_NEEDTEXT (via WM_NOTIFY) when it is about to be shown
192 ti
.hwnd
= (HWND
)m_window
->GetHWND();
193 ti
.lpszText
= LPSTR_TEXTCALLBACK
;
194 // instead of: ti.lpszText = (char *)m_text.c_str();
196 if ( !SendTooltipMessage(GetToolTipCtrl(), TTM_ADDTOOL
, 0, &ti
) )
198 wxLogSysError(_("Failed to create the tooltip '%s'"),
204 void wxToolTip::SetTip(const wxString
& tip
)
210 // update it immediately
211 wxToolInfo
ti(m_window
);
212 ti
.lpszText
= (wxChar
*)m_text
.c_str();
214 (void)SendTooltipMessage(GetToolTipCtrl(), TTM_UPDATETIPTEXT
, 0, &ti
);
218 #endif // wxUSE_TOOLTIPS