]>
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"
33 #if (defined(__WIN95__) && !defined(__GNUWIN32__)) || defined(__TWIN32__)
37 // ----------------------------------------------------------------------------
39 // ----------------------------------------------------------------------------
41 // a simple wrapper around TOOLINFO Win32 structure
42 class wxToolInfo
: public TOOLINFO
45 wxToolInfo(wxWindow
*win
)
47 // initialize all members
48 ::ZeroMemory(this, sizeof(TOOLINFO
));
50 cbSize
= sizeof(TOOLINFO
);
51 uFlags
= TTF_IDISHWND
;
52 uId
= (UINT
)win
->GetHWND();
56 // ----------------------------------------------------------------------------
58 // ----------------------------------------------------------------------------
60 // send a message to the tooltip control
61 inline LRESULT
SendTooltipMessage(WXHWND hwnd
,
66 return hwnd
? ::SendMessage((HWND
)hwnd
, msg
, wParam
, (LPARAM
)lParam
)
70 // ============================================================================
72 // ============================================================================
74 // ----------------------------------------------------------------------------
75 // "semiglobal" functions - these methods work with the tooltip control which
76 // is shared among all the wxToolTips of the same frame
77 // ----------------------------------------------------------------------------
79 // create the tooltip ctrl for our parent frame if it doesn't exist yet
80 WXHWND
wxToolTip::GetToolTipCtrl()
82 wxWindow
*parent
= m_window
;
83 while ( parent
&& !parent
->IsKindOf(CLASSINFO(wxFrame
)) )
85 parent
= parent
->GetParent();
88 wxCHECK_MSG( parent
, 0, "can't create tooltip control outside a frame" );
90 wxFrame
*frame
= (wxFrame
*)parent
;
91 HWND hwndTT
= (HWND
)frame
->GetToolTipCtrl();
94 hwndTT
= ::CreateWindow(TOOLTIPS_CLASS
,
97 CW_USEDEFAULT
, CW_USEDEFAULT
,
98 CW_USEDEFAULT
, CW_USEDEFAULT
,
99 (HWND
)frame
->GetHWND(), (HMENU
)NULL
,
100 wxGetInstance(), NULL
);
104 frame
->SetToolTipCtrl((WXHWND
)hwndTT
);
108 wxLogSysError(_("Can not create tooltip control"));
112 return (WXHWND
)hwndTT
;
115 void wxToolTip::Enable(bool flag
)
117 (void)SendTooltipMessage(GetToolTipCtrl(), TTM_ACTIVATE
, flag
, 0);
120 void wxToolTip::RelayEvent(WXMSG
*msg
)
122 (void)SendTooltipMessage(GetToolTipCtrl(), TTM_RELAYEVENT
, 0, msg
);
125 void wxToolTip::SetDelay(long milliseconds
)
127 (void)SendTooltipMessage(GetToolTipCtrl(), TTM_SETDELAYTIME
,
128 TTDT_INITIAL
, (void *)milliseconds
);
131 // ----------------------------------------------------------------------------
133 // ----------------------------------------------------------------------------
135 wxToolTip::wxToolTip(const wxString
&tip
)
141 wxToolTip::~wxToolTip()
143 // there is no need to Remove() this tool - it will be done automatically
147 // ----------------------------------------------------------------------------
149 // ----------------------------------------------------------------------------
151 void wxToolTip::Remove()
153 // remove this tool from the tooltip control
156 wxToolInfo
ti(m_window
);
157 (void)SendTooltipMessage(GetToolTipCtrl(), TTM_DELTOOL
, 0, &ti
);
161 void wxToolTip::SetWindow(wxWindow
*win
)
169 wxToolInfo
ti(m_window
);
171 // as we store our text anyhow, it seems useless to waste system memory
172 // by asking the tooltip ctrl to remember it too - instead it will send
173 // us TTN_NEEDTEXT (via WM_NOTIFY) when it is about to be shown
174 ti
.hwnd
= (HWND
)m_window
->GetHWND();
175 ti
.lpszText
= LPSTR_TEXTCALLBACK
;
176 // instead of: ti.lpszText = (char *)m_text.c_str();
178 if ( !SendTooltipMessage(GetToolTipCtrl(), TTM_ADDTOOL
, 0, &ti
) )
180 wxLogSysError(_("Failed to create the tooltip '%s'"),
186 void wxToolTip::SetTip(const wxString
& tip
)
192 // update it immediately
193 wxToolInfo
ti(m_window
);
194 ti
.lpszText
= (char *)m_text
.c_str();
196 (void)SendTooltipMessage(GetToolTipCtrl(), TTM_UPDATETIPTEXT
, 0, &ti
);