]>
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 WXHWND
wxToolTip::hwndTT
= NULL
;
41 // ----------------------------------------------------------------------------
43 // ----------------------------------------------------------------------------
46 // a simple wrapper around TOOLINFO Win32 structure
47 #pragma warning( disable : 4097 )
48 class wxToolInfo
: public TOOLINFO
51 wxToolInfo(wxWindow
*win
)
53 // initialize all members
54 #if __GNUWIN32__ && !defined(wxUSE_NORLANDER_HEADERS)
55 memset(this, 0, sizeof(TOOLINFO
));
57 ::ZeroMemory(this, sizeof(TOOLINFO
));
60 cbSize
= sizeof(TOOLINFO
);
61 uFlags
= TTF_IDISHWND
;
62 uId
= (UINT
)win
->GetHWND();
65 #pragma warning( default : 4097 )
67 // ----------------------------------------------------------------------------
69 // ----------------------------------------------------------------------------
71 // send a message to the tooltip control
72 inline LRESULT
SendTooltipMessage(WXHWND hwnd
,
77 return hwnd
? ::SendMessage((HWND
)hwnd
, msg
, wParam
, (LPARAM
)lParam
)
81 // send a message to all existing tooltip controls
82 static void SendTooltipMessageToAll(WXHWND hwnd
,
88 (void)SendTooltipMessage((WXHWND
)hwnd
, msg
, wParam
, (void *)lParam
);
91 // ============================================================================
93 // ============================================================================
95 // ----------------------------------------------------------------------------
97 // ----------------------------------------------------------------------------
101 void wxToolTip::Enable(bool flag
)
103 SendTooltipMessageToAll((WXHWND
)hwndTT
,TTM_ACTIVATE
, flag
, 0);
106 void wxToolTip::SetDelay(long milliseconds
)
108 SendTooltipMessageToAll((WXHWND
)hwndTT
,TTM_SETDELAYTIME
, TTDT_INITIAL
, milliseconds
);
111 // ---------------------------------------------------------------------------
112 // implementation helpers
113 // ---------------------------------------------------------------------------
115 // create the tooltip ctrl for our parent frame if it doesn't exist yet
116 WXHWND
wxToolTip::GetToolTipCtrl()
120 hwndTT
= (WXHWND
)::CreateWindow(TOOLTIPS_CLASS
,
123 CW_USEDEFAULT
, CW_USEDEFAULT
,
124 CW_USEDEFAULT
, CW_USEDEFAULT
,
130 return (WXHWND
)hwndTT
;
133 void wxToolTip::RelayEvent(WXMSG
*msg
)
135 (void)SendTooltipMessage(GetToolTipCtrl(), TTM_RELAYEVENT
, 0, msg
);
138 // ----------------------------------------------------------------------------
140 // ----------------------------------------------------------------------------
142 wxToolTip::wxToolTip(const wxString
&tip
)
148 wxToolTip::~wxToolTip()
150 // there is no need to Remove() this tool - it will be done automatically
154 // ----------------------------------------------------------------------------
156 // ----------------------------------------------------------------------------
158 void wxToolTip::Remove()
160 // remove this tool from the tooltip control
163 wxToolInfo
ti(m_window
);
164 (void)SendTooltipMessage(GetToolTipCtrl(), TTM_DELTOOL
, 0, &ti
);
168 void wxToolTip::SetWindow(wxWindow
*win
)
176 wxToolInfo
ti(m_window
);
178 // as we store our text anyhow, it seems useless to waste system memory
179 // by asking the tooltip ctrl to remember it too - instead it will send
180 // us TTN_NEEDTEXT (via WM_NOTIFY) when it is about to be shown
181 ti
.hwnd
= (HWND
)m_window
->GetHWND();
182 ti
.lpszText
= LPSTR_TEXTCALLBACK
;
183 // instead of: ti.lpszText = (char *)m_text.c_str();
185 if ( !SendTooltipMessage(GetToolTipCtrl(), TTM_ADDTOOL
, 0, &ti
) )
187 wxLogSysError(_("Failed to create the tooltip '%s'"),
193 void wxToolTip::SetTip(const wxString
& tip
)
199 // update it immediately
200 wxToolInfo
ti(m_window
);
201 ti
.lpszText
= (wxChar
*)m_text
.c_str();
203 (void)SendTooltipMessage(GetToolTipCtrl(), TTM_UPDATETIPTEXT
, 0, &ti
);
207 #endif // wxUSE_TOOLTIPS