*** empty log message ***
[wxWidgets.git] / src / os2 / tooltip.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: msw/tooltip.cpp
3 // Purpose: wxToolTip class implementation for MSW
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/17/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #include "wx/wxprec.h"
21
22 #ifndef WX_PRECOMP
23 #include "wx/wx.h"
24 #endif
25
26 #if wxUSE_TOOLTIPS
27
28 #include "wx/tooltip.h"
29 #include "wx/os2/private.h"
30
31 // ----------------------------------------------------------------------------
32 // global variables
33 // ----------------------------------------------------------------------------
34
35 // the tooltip parent window
36 WXHWND wxToolTip::hwndTT = (WXHWND)NULL;
37
38 // ----------------------------------------------------------------------------
39 // private classes
40 // ----------------------------------------------------------------------------
41
42
43 // a simple wrapper around TOOLINFO Win32 structure
44 class wxToolInfo // define a TOOLINFO for OS/2 here : public TOOLINFO
45 {
46 public:
47 wxToolInfo(wxWindow *win)
48 {
49 // initialize all members
50 // ::ZeroMemory(this, sizeof(TOOLINFO));
51
52 cbSize = sizeof(this);
53 uFlags = 0; // TTF_IDISHWND;
54 uId = (UINT)win->GetHWND();
55 }
56 size_t cbSize;
57 ULONG uFlags;
58 UINT uId;
59 HWND hwnd;
60 char* lpszText;
61 };
62
63 // ----------------------------------------------------------------------------
64 // private functions
65 // ----------------------------------------------------------------------------
66
67 // send a message to the tooltip control
68 inline MRESULT SendTooltipMessage(WXHWND hwnd,
69 UINT msg,
70 MPARAM wParam,
71 MPARAM lParam)
72 {
73 // return hwnd ? ::SendMessage((HWND)hwnd, msg, wParam, (MPARAM)lParam)
74 // : 0;
75 return (MRESULT)0;
76 }
77
78 // send a message to all existing tooltip controls
79 static void SendTooltipMessageToAll(WXHWND hwnd,
80 UINT msg,
81 MPARAM wParam,
82 MPARAM lParam)
83 {
84 if ( hwnd )
85 (void)SendTooltipMessage((WXHWND)hwnd, msg, wParam, lParam);
86 }
87
88 // ============================================================================
89 // implementation
90 // ============================================================================
91
92 // ----------------------------------------------------------------------------
93 // static functions
94 // ----------------------------------------------------------------------------
95
96 void wxToolTip::Enable(bool flag)
97 {
98 // SendTooltipMessageToAll((WXHWND)hwndTT,TTM_ACTIVATE, flag, 0);
99 }
100
101 void wxToolTip::SetDelay(long milliseconds)
102 {
103 // SendTooltipMessageToAll((WXHWND)hwndTT,TTM_SETDELAYTIME, TTDT_INITIAL, milliseconds);
104 }
105
106 // ---------------------------------------------------------------------------
107 // implementation helpers
108 // ---------------------------------------------------------------------------
109
110 // create the tooltip ctrl for our parent frame if it doesn't exist yet
111 WXHWND wxToolTip::GetToolTipCtrl()
112 {
113 // TODO:
114 /*
115 if ( !hwndTT )
116 {
117 hwndTT = (WXHWND)::CreateWindow(TOOLTIPS_CLASS,
118 (LPSTR)NULL,
119 TTS_ALWAYSTIP,
120 CW_USEDEFAULT, CW_USEDEFAULT,
121 CW_USEDEFAULT, CW_USEDEFAULT,
122 NULL, (HMENU)NULL,
123 wxGetInstance(),
124 NULL);
125 if ( hwndTT )
126 {
127 SetWindowPos((HWND)hwndTT, HWND_TOPMOST, 0, 0, 0, 0,
128 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
129 }
130
131 }
132 return (WXHWND)hwndTT;
133 */
134 return (WXHWND)0;
135 }
136
137 void wxToolTip::RelayEvent(WXMSG *msg)
138 {
139 // (void)SendTooltipMessage(GetToolTipCtrl(), TTM_RELAYEVENT, 0, msg);
140 }
141
142 // ----------------------------------------------------------------------------
143 // ctor & dtor
144 // ----------------------------------------------------------------------------
145
146 wxToolTip::wxToolTip(const wxString &tip)
147 : m_text(tip)
148 {
149 m_window = NULL;
150 }
151
152 wxToolTip::~wxToolTip()
153 {
154 // there is no need to Remove() this tool - it will be done automatically
155 // anyhow
156 }
157
158 // ----------------------------------------------------------------------------
159 // others
160 // ----------------------------------------------------------------------------
161
162 void wxToolTip::Remove()
163 {
164 // remove this tool from the tooltip control
165 if ( m_window )
166 {
167 wxToolInfo ti(m_window);
168 // (void)SendTooltipMessage(GetToolTipCtrl(), TTM_DELTOOL, 0, &ti);
169 }
170 }
171
172 void wxToolTip::SetWindow(wxWindow *win)
173 {
174 Remove();
175
176 m_window = win;
177
178 if ( m_window )
179 {
180 wxToolInfo ti(m_window);
181
182 // as we store our text anyhow, it seems useless to waste system memory
183 // by asking the tooltip ctrl to remember it too - instead it will send
184 // us TTN_NEEDTEXT (via WM_NOTIFY) when it is about to be shown
185 ti.hwnd = (HWND)m_window->GetHWND();
186 // ti.lpszText = LPSTR_TEXTCALLBACK;
187 // instead of: ti.lpszText = (char *)m_text.c_str();
188
189 // TODO:
190 /*
191 if ( !SendTooltipMessage(GetToolTipCtrl(), TTM_ADDTOOL, 0, &ti) )
192 {
193 wxLogSysError(_("Failed to create the tooltip '%s'"),
194 m_text.c_str());
195 }
196 */
197 }
198 }
199
200 void wxToolTip::SetTip(const wxString& tip)
201 {
202 m_text = tip;
203
204 if ( m_window )
205 {
206 // update it immediately
207 wxToolInfo ti(m_window);
208 ti.lpszText = (wxChar *)m_text.c_str();
209
210 // (void)SendTooltipMessage(GetToolTipCtrl(), TTM_UPDATETIPTEXT, 0, &ti);
211 }
212 }
213
214 #endif // wxUSE_TOOLTIPS