]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////// | |
2 | // File: taskbar.cpp | |
3 | // Purpose: Implements wxTaskBarIcon class for manipulating icons on | |
4 | // the task bar. Optional. | |
5 | // Author: David Webster | |
6 | // Modified by: | |
7 | // Created: 10/17/99 | |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) David Webster | |
10 | // Licence: wxWindows licence | |
11 | ///////////////////////////////////////////////////////////////////////// | |
12 | ||
13 | // For compilers that support precompilation, includes "wx.h". | |
14 | #include "wx/wxprec.h" | |
15 | ||
16 | #ifndef WX_PRECOMP | |
17 | #include "wx/defs.h" | |
18 | #include "wx/window.h" | |
19 | #include "wx/frame.h" | |
20 | #include "wx/utils.h" | |
21 | #include "wx/menu.h" | |
22 | #endif | |
23 | ||
24 | #define INCL_PM | |
25 | #include <os2.h> | |
26 | #include <string.h> | |
27 | #include <wx/os2/taskbar.h> | |
28 | #include <wx/os2/private.h> | |
29 | ||
30 | MRESULT wxTaskBarIconWindowProc( HWND hWnd, UINT msg, MPARAM wParam, MPARAM lParam ); | |
31 | ||
32 | wxChar *wxTaskBarWindowClass = wxT("wxTaskBarWindowClass"); | |
33 | ||
34 | wxList wxTaskBarIcon::sm_taskBarIcons; | |
35 | bool wxTaskBarIcon::sm_registeredClass = FALSE; | |
36 | UINT wxTaskBarIcon::sm_taskbarMsg = 0; | |
37 | ||
38 | ||
39 | #if !USE_SHARED_LIBRARY | |
40 | BEGIN_EVENT_TABLE(wxTaskBarIcon, wxEvtHandler) | |
41 | EVT_TASKBAR_MOVE (wxTaskBarIcon::_OnMouseMove) | |
42 | EVT_TASKBAR_LEFT_DOWN (wxTaskBarIcon::_OnLButtonDown) | |
43 | EVT_TASKBAR_LEFT_UP (wxTaskBarIcon::_OnLButtonUp) | |
44 | EVT_TASKBAR_RIGHT_DOWN (wxTaskBarIcon::_OnRButtonDown) | |
45 | EVT_TASKBAR_RIGHT_UP (wxTaskBarIcon::_OnRButtonUp) | |
46 | EVT_TASKBAR_LEFT_DCLICK (wxTaskBarIcon::_OnLButtonDClick) | |
47 | EVT_TASKBAR_RIGHT_DCLICK (wxTaskBarIcon::_OnRButtonDClick) | |
48 | END_EVENT_TABLE() | |
49 | ||
50 | IMPLEMENT_DYNAMIC_CLASS(wxTaskBarIcon, wxEvtHandler) | |
51 | #endif | |
52 | ||
53 | ||
54 | wxTaskBarIcon::wxTaskBarIcon(void) | |
55 | { | |
56 | m_hWnd = 0; | |
57 | m_iconAdded = FALSE; | |
58 | ||
59 | AddObject(this); | |
60 | // TODO: | |
61 | /* | |
62 | if (RegisterWindowClass()) | |
63 | m_hWnd = CreateTaskBarWindow(); | |
64 | */ | |
65 | } | |
66 | ||
67 | wxTaskBarIcon::~wxTaskBarIcon(void) | |
68 | { | |
69 | // TODO: | |
70 | /* | |
71 | RemoveObject(this); | |
72 | ||
73 | if (m_iconAdded) | |
74 | { | |
75 | RemoveIcon(); | |
76 | } | |
77 | ||
78 | if (m_hWnd) | |
79 | { | |
80 | ::DestroyWindow((HWND) m_hWnd); | |
81 | m_hWnd = 0; | |
82 | } | |
83 | */ | |
84 | } | |
85 | ||
86 | // Operations | |
87 | bool wxTaskBarIcon::SetIcon(const wxIcon& icon, const wxString& tooltip) | |
88 | { | |
89 | if (!IsOK()) | |
90 | return FALSE; | |
91 | // TODO: | |
92 | /* | |
93 | NOTIFYICONDATA notifyData; | |
94 | ||
95 | memset(¬ifyData, 0, sizeof(notifyData)); | |
96 | notifyData.cbSize = sizeof(notifyData); | |
97 | notifyData.hWnd = (HWND) m_hWnd; | |
98 | notifyData.uCallbackMessage = sm_taskbarMsg; | |
99 | notifyData.uFlags = NIF_MESSAGE ; | |
100 | if (icon.Ok()) | |
101 | { | |
102 | notifyData.uFlags |= NIF_ICON; | |
103 | notifyData.hIcon = (HICON) icon.GetHICON(); | |
104 | } | |
105 | ||
106 | if (((const wxChar*) tooltip != NULL) && (tooltip != wxT(""))) | |
107 | { | |
108 | notifyData.uFlags |= NIF_TIP ; | |
109 | lstrcpyn(notifyData.szTip, WXSTRINGCAST tooltip, sizeof(notifyData.szTip)); | |
110 | } | |
111 | ||
112 | notifyData.uID = 99; | |
113 | ||
114 | if (m_iconAdded) | |
115 | return (Shell_NotifyIcon(NIM_MODIFY, & notifyData) != 0); | |
116 | else | |
117 | { | |
118 | m_iconAdded = (Shell_NotifyIcon(NIM_ADD, & notifyData) != 0); | |
119 | return m_iconAdded; | |
120 | } | |
121 | */ | |
122 | return FALSE; | |
123 | } | |
124 | ||
125 | bool wxTaskBarIcon::RemoveIcon(void) | |
126 | { | |
127 | if (!m_iconAdded) | |
128 | return FALSE; | |
129 | //TODO: | |
130 | /* | |
131 | NOTIFYICONDATA notifyData; | |
132 | ||
133 | memset(¬ifyData, 0, sizeof(notifyData)); | |
134 | notifyData.cbSize = sizeof(notifyData); | |
135 | notifyData.hWnd = (HWND) m_hWnd; | |
136 | notifyData.uCallbackMessage = sm_taskbarMsg; | |
137 | notifyData.uFlags = NIF_MESSAGE; | |
138 | notifyData.hIcon = 0 ; // hIcon; | |
139 | notifyData.uID = 99; | |
140 | m_iconAdded = FALSE; | |
141 | ||
142 | return (Shell_NotifyIcon(NIM_DELETE, & notifyData) != 0); | |
143 | */ | |
144 | return FALSE; | |
145 | } | |
146 | ||
147 | bool wxTaskBarIcon::PopupMenu(wxMenu *menu) //, int x, int y); | |
148 | { | |
149 | // OK, so I know this isn't thread-friendly, but | |
150 | // what to do? We need this check. | |
151 | ||
152 | static bool s_inPopup = FALSE; | |
153 | ||
154 | if (s_inPopup) | |
155 | return FALSE; | |
156 | ||
157 | s_inPopup = TRUE; | |
158 | ||
159 | bool rval = FALSE; | |
160 | wxWindow* win; | |
161 | int x, y; | |
162 | wxGetMousePosition(&x, &y); | |
163 | ||
164 | // is wxFrame the best window type to use??? | |
165 | win = new wxFrame(NULL, -1, "", wxPoint(x,y), wxSize(-1,-1), 0); | |
166 | win->PushEventHandler(this); | |
167 | ||
168 | // Remove from record of top-level windows, or will confuse wxWindows | |
169 | // if we try to exit right now. | |
170 | wxTopLevelWindows.DeleteObject(win); | |
171 | ||
172 | menu->UpdateUI(); | |
173 | ||
174 | rval = win->PopupMenu(menu, 0, 0); | |
175 | ||
176 | win->PopEventHandler(FALSE); | |
177 | win->Destroy(); | |
178 | delete win; | |
179 | ||
180 | s_inPopup = FALSE; | |
181 | ||
182 | return rval; | |
183 | } | |
184 | ||
185 | // Overridables | |
186 | void wxTaskBarIcon::OnMouseMove(wxEvent&) | |
187 | { | |
188 | } | |
189 | ||
190 | void wxTaskBarIcon::OnLButtonDown(wxEvent&) | |
191 | { | |
192 | } | |
193 | ||
194 | void wxTaskBarIcon::OnLButtonUp(wxEvent&) | |
195 | { | |
196 | } | |
197 | ||
198 | void wxTaskBarIcon::OnRButtonDown(wxEvent&) | |
199 | { | |
200 | } | |
201 | ||
202 | void wxTaskBarIcon::OnRButtonUp(wxEvent&) | |
203 | { | |
204 | } | |
205 | ||
206 | void wxTaskBarIcon::OnLButtonDClick(wxEvent&) | |
207 | { | |
208 | } | |
209 | ||
210 | void wxTaskBarIcon::OnRButtonDClick(wxEvent&) | |
211 | { | |
212 | } | |
213 | ||
214 | void wxTaskBarIcon::_OnMouseMove(wxEvent& e) { OnMouseMove(e); } | |
215 | void wxTaskBarIcon::_OnLButtonDown(wxEvent& e) { OnLButtonDown(e); } | |
216 | void wxTaskBarIcon::_OnLButtonUp(wxEvent& e) { OnLButtonUp(e); } | |
217 | void wxTaskBarIcon::_OnRButtonDown(wxEvent& e) { OnRButtonDown(e); } | |
218 | void wxTaskBarIcon::_OnRButtonUp(wxEvent& e) { OnRButtonUp(e); } | |
219 | void wxTaskBarIcon::_OnLButtonDClick(wxEvent& e) { OnLButtonDClick(e); } | |
220 | void wxTaskBarIcon::_OnRButtonDClick(wxEvent& e) { OnRButtonDClick(e); } | |
221 | ||
222 | ||
223 | wxTaskBarIcon* wxTaskBarIcon::FindObjectForHWND(WXHWND hWnd) | |
224 | { | |
225 | wxNode*node = sm_taskBarIcons.First(); | |
226 | while (node) | |
227 | { | |
228 | wxTaskBarIcon* obj = (wxTaskBarIcon*) node->Data(); | |
229 | if (obj->GetHWND() == hWnd) | |
230 | return obj; | |
231 | node = node->Next(); | |
232 | } | |
233 | return NULL; | |
234 | } | |
235 | ||
236 | void wxTaskBarIcon::AddObject(wxTaskBarIcon* obj) | |
237 | { | |
238 | sm_taskBarIcons.Append(obj); | |
239 | } | |
240 | ||
241 | void wxTaskBarIcon::RemoveObject(wxTaskBarIcon* obj) | |
242 | { | |
243 | sm_taskBarIcons.DeleteObject(obj); | |
244 | } | |
245 | ||
246 | bool wxTaskBarIcon::RegisterWindowClass() | |
247 | { | |
248 | if (sm_registeredClass) | |
249 | return TRUE; | |
250 | ||
251 | // Also register the taskbar message here | |
252 | // TODO: | |
253 | /* | |
254 | sm_taskbarMsg = ::RegisterWindowMessage(wxT("wxTaskBarIconMessage")); | |
255 | ||
256 | WNDCLASS wc; | |
257 | bool rc; | |
258 | ||
259 | HINSTANCE hInstance = GetModuleHandle(NULL); | |
260 | ||
261 | // | |
262 | // set up and register window class | |
263 | // | |
264 | wc.style = CS_HREDRAW | CS_VREDRAW; | |
265 | wc.lpfnWndProc = (WNDPROC) wxTaskBarIconWindowProc; | |
266 | wc.cbClsExtra = 0; | |
267 | wc.cbWndExtra = 0; | |
268 | wc.hInstance = hInstance; | |
269 | wc.hIcon = 0; | |
270 | wc.hCursor = 0; | |
271 | wc.hbrBackground = 0; | |
272 | wc.lpszMenuName = NULL; | |
273 | wc.lpszClassName = wxTaskBarWindowClass ; | |
274 | rc = (::RegisterClass( &wc ) != 0); | |
275 | ||
276 | sm_registeredClass = (rc != 0); | |
277 | ||
278 | return( (rc != 0) ); | |
279 | */ | |
280 | return FALSE; | |
281 | } | |
282 | ||
283 | WXHWND wxTaskBarIcon::CreateTaskBarWindow() | |
284 | { | |
285 | // TODO: | |
286 | /* | |
287 | HINSTANCE hInstance = GetModuleHandle(NULL); | |
288 | ||
289 | HWND hWnd = CreateWindowEx (0, wxTaskBarWindowClass, | |
290 | wxT("wxTaskBarWindow"), | |
291 | WS_OVERLAPPED, | |
292 | 0, | |
293 | 0, | |
294 | 10, | |
295 | 10, | |
296 | NULL, | |
297 | (HMENU) 0, | |
298 | hInstance, | |
299 | NULL); | |
300 | ||
301 | return (WXHWND) hWnd; | |
302 | */ | |
303 | return (WXHWND)0; | |
304 | } | |
305 | ||
306 | MRESULT wxTaskBarIcon::WindowProc( WXHWND hWnd, UINT msg, MPARAM wParam, MPARAM lParam ) | |
307 | { | |
308 | wxEventType eventType = 0; | |
309 | // TODO: | |
310 | /* | |
311 | if (msg != sm_taskbarMsg) | |
312 | return DefWindowProc((HWND) hWnd, msg, wParam, lParam); | |
313 | ||
314 | switch (lParam) | |
315 | { | |
316 | case WM_LBUTTONDOWN: | |
317 | eventType = wxEVT_TASKBAR_LEFT_DOWN; | |
318 | break; | |
319 | ||
320 | case WM_LBUTTONUP: | |
321 | eventType = wxEVT_TASKBAR_LEFT_UP; | |
322 | break; | |
323 | ||
324 | case WM_RBUTTONDOWN: | |
325 | eventType = wxEVT_TASKBAR_RIGHT_DOWN; | |
326 | break; | |
327 | ||
328 | case WM_RBUTTONUP: | |
329 | eventType = wxEVT_TASKBAR_RIGHT_UP; | |
330 | break; | |
331 | ||
332 | case WM_LBUTTONDBLCLK: | |
333 | eventType = wxEVT_TASKBAR_LEFT_DCLICK; | |
334 | break; | |
335 | ||
336 | case WM_RBUTTONDBLCLK: | |
337 | eventType = wxEVT_TASKBAR_RIGHT_DCLICK; | |
338 | break; | |
339 | ||
340 | case WM_MOUSEMOVE: | |
341 | eventType = wxEVT_TASKBAR_MOVE; | |
342 | break; | |
343 | ||
344 | default: | |
345 | break; | |
346 | } | |
347 | */ | |
348 | if (eventType) | |
349 | { | |
350 | wxEvent event; | |
351 | event.SetEventType(eventType); | |
352 | event.SetEventObject(this); | |
353 | ||
354 | ProcessEvent(event); | |
355 | } | |
356 | return 0; | |
357 | } | |
358 | ||
359 | MRESULT wxTaskBarIconWindowProc( | |
360 | HWND hWnd | |
361 | , UINT msg | |
362 | , MPARAM wParam | |
363 | , MPARAM lParam | |
364 | ) | |
365 | { | |
366 | wxTaskBarIcon* obj = wxTaskBarIcon::FindObjectForHWND((WXHWND) hWnd); | |
367 | if (obj) | |
368 | return obj->WindowProc((WXHWND) hWnd, msg, wParam, lParam); | |
369 | else | |
370 | return (MRESULT)0; | |
371 | // return DefWindowProc(hWnd, msg, wParam, lParam); | |
372 | } | |
373 |