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