]>
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__)
39 // ----------------------------------------------------------------------------
41 // ----------------------------------------------------------------------------
43 // a simple wrapper around TOOLINFO Win32 structure
44 class wxToolInfo
: public TOOLINFO
47 wxToolInfo(wxWindow
*win
)
49 // initialize all members
50 ::ZeroMemory(this, sizeof(TOOLINFO
));
52 cbSize
= sizeof(TOOLINFO
);
53 uFlags
= TTF_IDISHWND
;
54 uId
= (UINT
)win
->GetHWND();
58 // ----------------------------------------------------------------------------
60 // ----------------------------------------------------------------------------
62 // send a message to the tooltip control
63 inline LRESULT
SendTooltipMessage(WXHWND hwnd
,
68 return hwnd
? ::SendMessage((HWND
)hwnd
, msg
, wParam
, (LPARAM
)lParam
)
72 // ============================================================================
74 // ============================================================================
76 // ----------------------------------------------------------------------------
77 // "semiglobal" functions - these methods work with the tooltip control which
78 // is shared among all the wxToolTips of the same frame
79 // ----------------------------------------------------------------------------
81 // create the tooltip ctrl for our parent frame if it doesn't exist yet
82 WXHWND
wxToolTip::GetToolTipCtrl()
84 wxWindow
*parent
= m_window
;
85 while ( parent
&& !parent
->IsKindOf(CLASSINFO(wxFrame
)) )
87 parent
= parent
->GetParent();
90 wxCHECK_MSG( parent
, 0, "can't create tooltip control outside a frame" );
92 wxFrame
*frame
= (wxFrame
*)parent
;
93 HWND hwndTT
= (HWND
)frame
->GetToolTipCtrl();
96 hwndTT
= ::CreateWindow(TOOLTIPS_CLASS
,
99 CW_USEDEFAULT
, CW_USEDEFAULT
,
100 CW_USEDEFAULT
, CW_USEDEFAULT
,
101 (HWND
)frame
->GetHWND(), (HMENU
)NULL
,
102 wxGetInstance(), NULL
);
106 frame
->SetToolTipCtrl((WXHWND
)hwndTT
);
110 wxLogSysError(_("Can not create tooltip control"));
114 return (WXHWND
)hwndTT
;
117 void wxToolTip::Enable(bool flag
)
119 (void)SendTooltipMessage(GetToolTipCtrl(), TTM_ACTIVATE
, flag
, 0);
122 void wxToolTip::RelayEvent(WXMSG
*msg
)
124 (void)SendTooltipMessage(GetToolTipCtrl(), TTM_RELAYEVENT
, 0, msg
);
127 void wxToolTip::SetDelay(long milliseconds
)
129 (void)SendTooltipMessage(GetToolTipCtrl(), TTM_SETDELAYTIME
,
130 TTDT_INITIAL
, (void *)milliseconds
);
133 // ----------------------------------------------------------------------------
135 // ----------------------------------------------------------------------------
137 wxToolTip::wxToolTip(const wxString
&tip
)
143 wxToolTip::~wxToolTip()
145 // there is no need to Remove() this tool - it will be done automatically
149 // ----------------------------------------------------------------------------
151 // ----------------------------------------------------------------------------
153 void wxToolTip::Remove()
155 // remove this tool from the tooltip control
158 wxToolInfo
ti(m_window
);
159 (void)SendTooltipMessage(GetToolTipCtrl(), TTM_DELTOOL
, 0, &ti
);
163 void wxToolTip::SetWindow(wxWindow
*win
)
171 wxToolInfo
ti(m_window
);
173 // as we store our text anyhow, it seems useless to waste system memory
174 // by asking the tooltip ctrl to remember it too - instead it will send
175 // us TTN_NEEDTEXT (via WM_NOTIFY) when it is about to be shown
176 ti
.hwnd
= (HWND
)m_window
->GetHWND();
177 ti
.lpszText
= LPSTR_TEXTCALLBACK
;
178 // instead of: ti.lpszText = (char *)m_text.c_str();
180 if ( !SendTooltipMessage(GetToolTipCtrl(), TTM_ADDTOOL
, 0, &ti
) )
182 wxLogSysError(_("Failed to create the tooltip '%s'"),
188 void wxToolTip::SetTip(const wxString
& tip
)
194 // update it immediately
195 wxToolInfo
ti(m_window
);
196 ti
.lpszText
= (char *)m_text
.c_str();
198 (void)SendTooltipMessage(GetToolTipCtrl(), TTM_UPDATETIPTEXT
, 0, &ti
);
202 #endif // wxUSE_TOOLTIPS