]>
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"
30 #include "wx/tooltip.h"
31 #include "wx/msw/private.h"
35 // ----------------------------------------------------------------------------
37 // ----------------------------------------------------------------------------
39 // a simple wrapper around TOOLINFO Win32 structure
40 class wxToolInfo
: public TOOLINFO
43 wxToolInfo(wxWindow
*win
)
45 // initialize all members
46 ::ZeroMemory(this, sizeof(TOOLINFO
));
48 cbSize
= sizeof(TOOLINFO
);
49 uFlags
= TTF_IDISHWND
;
50 uId
= (UINT
)win
->GetHWND();
54 // ----------------------------------------------------------------------------
56 // ----------------------------------------------------------------------------
58 // send a message to the tooltip control
59 inline LRESULT
SendTooltipMessage(WXHWND hwnd
,
64 return hwnd
? ::SendMessage((HWND
)hwnd
, msg
, wParam
, (LPARAM
)lParam
)
68 // ============================================================================
70 // ============================================================================
72 // ----------------------------------------------------------------------------
73 // "semiglobal" functions - these methods work with the tooltip control which
74 // is shared among all the wxToolTips of the same frame
75 // ----------------------------------------------------------------------------
77 // create the tooltip ctrl for our parent frame if it doesn't exist yet
78 WXHWND
wxToolTip::GetToolTipCtrl()
80 wxWindow
*parent
= m_window
;
81 while ( parent
&& !parent
->IsKindOf(CLASSINFO(wxFrame
)) )
83 parent
= parent
->GetParent();
86 wxCHECK_MSG( parent
, 0, "can't create tooltip control outside a frame" );
88 wxFrame
*frame
= (wxFrame
*)parent
;
89 HWND hwndTT
= (HWND
)frame
->GetToolTipCtrl();
92 hwndTT
= ::CreateWindow(TOOLTIPS_CLASS
,
95 CW_USEDEFAULT
, CW_USEDEFAULT
,
96 CW_USEDEFAULT
, CW_USEDEFAULT
,
97 (HWND
)frame
->GetHWND(), (HMENU
)NULL
,
98 wxGetInstance(), NULL
);
102 frame
->SetToolTipCtrl((WXHWND
)hwndTT
);
106 wxLogSysError(_("Can not create tooltip control"));
110 return (WXHWND
)hwndTT
;
113 void wxToolTip::Enable(bool flag
)
115 (void)SendTooltipMessage(GetToolTipCtrl(), TTM_ACTIVATE
, flag
, 0);
118 void wxToolTip::RelayEvent(WXMSG
*msg
)
120 (void)SendTooltipMessage(GetToolTipCtrl(), TTM_RELAYEVENT
, 0, msg
);
123 void wxToolTip::SetDelay(long milliseconds
)
125 (void)SendTooltipMessage(GetToolTipCtrl(), TTM_SETDELAYTIME
,
126 TTDT_INITIAL
, (void *)milliseconds
);
129 // ----------------------------------------------------------------------------
131 // ----------------------------------------------------------------------------
133 wxToolTip::wxToolTip(const wxString
&tip
)
139 wxToolTip::~wxToolTip()
141 // there is no need to Remove() this tool - it will be done automatically
145 // ----------------------------------------------------------------------------
147 // ----------------------------------------------------------------------------
149 void wxToolTip::Remove()
151 // remove this tool from the tooltip control
154 wxToolInfo
ti(m_window
);
155 (void)SendTooltipMessage(GetToolTipCtrl(), TTM_DELTOOL
, 0, &ti
);
159 void wxToolTip::SetWindow(wxWindow
*win
)
167 wxToolInfo
ti(m_window
);
169 // as we store our text anyhow, it seems useless to waste system memory
170 // by asking the tooltip ctrl to remember it too - instead it will send
171 // us TTN_NEEDTEXT (via WM_NOTIFY) when it is about to be shown
172 ti
.hwnd
= (HWND
)m_window
->GetHWND();
173 ti
.lpszText
= LPSTR_TEXTCALLBACK
;
174 // instead of: ti.lpszText = (char *)m_text.c_str();
176 if ( !SendTooltipMessage(GetToolTipCtrl(), TTM_ADDTOOL
, 0, &ti
) )
178 wxLogSysError(_("Failed to create the tooltip '%s'"),
184 void wxToolTip::SetTip(const wxString
& tip
)
190 // update it immediately
191 wxToolInfo
ti(m_window
);
192 ti
.lpszText
= (char *)m_text
.c_str();
194 (void)SendTooltipMessage(GetToolTipCtrl(), TTM_UPDATETIPTEXT
, 0, &ti
);