]> git.saurik.com Git - wxWidgets.git/blame - src/os2/taskbar.cpp
Rotated text patch from Hans-Joachim Baader (with some corrections)
[wxWidgets.git] / src / os2 / taskbar.cpp
CommitLineData
0e320a79
DW
1/////////////////////////////////////////////////////////////////////////
2// File: taskbar.cpp
3// Purpose: Implements wxTaskBarIcon class for manipulating icons on
4// the task bar. Optional.
d90895ac 5// Author: David Webster
0e320a79 6// Modified by:
d90895ac 7// Created: 10/17/99
0e320a79 8// RCS-ID: $Id$
d90895ac
DW
9// Copyright: (c) David Webster
10// Licence: wxWindows licence
0e320a79
DW
11/////////////////////////////////////////////////////////////////////////
12
d90895ac
DW
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
30MRESULT wxTaskBarIconWindowProc( HWND hWnd, UINT msg, MPARAM wParam, MPARAM lParam );
31
32wxChar *wxTaskBarWindowClass = wxT("wxTaskBarWindowClass");
33
34wxList wxTaskBarIcon::sm_taskBarIcons;
35bool wxTaskBarIcon::sm_registeredClass = FALSE;
36UINT wxTaskBarIcon::sm_taskbarMsg = 0;
37
38
39#if !USE_SHARED_LIBRARY
40BEGIN_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)
48END_EVENT_TABLE()
49
50IMPLEMENT_DYNAMIC_CLASS(wxTaskBarIcon, wxEvtHandler)
0e320a79
DW
51#endif
52
0e320a79 53
d90895ac 54wxTaskBarIcon::wxTaskBarIcon(void)
0e320a79 55{
d90895ac
DW
56 m_hWnd = 0;
57 m_iconAdded = FALSE;
58
59 AddObject(this);
60// TODO:
61/*
62 if (RegisterWindowClass())
63 m_hWnd = CreateTaskBarWindow();
64*/
0e320a79
DW
65}
66
d90895ac 67wxTaskBarIcon::~wxTaskBarIcon(void)
0e320a79 68{
d90895ac
DW
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*/
0e320a79
DW
84}
85
86// Operations
87bool wxTaskBarIcon::SetIcon(const wxIcon& icon, const wxString& tooltip)
88{
d90895ac
DW
89 if (!IsOK())
90 return FALSE;
91// TODO:
92/*
93 NOTIFYICONDATA notifyData;
94
95 memset(&notifyData, 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*/
0e320a79
DW
122 return FALSE;
123}
124
d90895ac 125bool wxTaskBarIcon::RemoveIcon(void)
0e320a79 126{
d90895ac
DW
127 if (!m_iconAdded)
128 return FALSE;
129//TODO:
130/*
131 NOTIFYICONDATA notifyData;
132
133 memset(&notifyData, 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*/
0e320a79
DW
144 return FALSE;
145}
146
d90895ac
DW
147bool 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
0e320a79 185// Overridables
d90895ac 186void wxTaskBarIcon::OnMouseMove(wxEvent&)
0e320a79
DW
187{
188}
189
d90895ac 190void wxTaskBarIcon::OnLButtonDown(wxEvent&)
0e320a79
DW
191{
192}
193
d90895ac 194void wxTaskBarIcon::OnLButtonUp(wxEvent&)
0e320a79
DW
195{
196}
197
d90895ac 198void wxTaskBarIcon::OnRButtonDown(wxEvent&)
0e320a79
DW
199{
200}
201
d90895ac 202void wxTaskBarIcon::OnRButtonUp(wxEvent&)
0e320a79
DW
203{
204}
205
d90895ac 206void wxTaskBarIcon::OnLButtonDClick(wxEvent&)
0e320a79
DW
207{
208}
209
d90895ac
DW
210void wxTaskBarIcon::OnRButtonDClick(wxEvent&)
211{
212}
213
214void wxTaskBarIcon::_OnMouseMove(wxEvent& e) { OnMouseMove(e); }
215void wxTaskBarIcon::_OnLButtonDown(wxEvent& e) { OnLButtonDown(e); }
216void wxTaskBarIcon::_OnLButtonUp(wxEvent& e) { OnLButtonUp(e); }
217void wxTaskBarIcon::_OnRButtonDown(wxEvent& e) { OnRButtonDown(e); }
218void wxTaskBarIcon::_OnRButtonUp(wxEvent& e) { OnRButtonUp(e); }
219void wxTaskBarIcon::_OnLButtonDClick(wxEvent& e) { OnLButtonDClick(e); }
220void wxTaskBarIcon::_OnRButtonDClick(wxEvent& e) { OnRButtonDClick(e); }
221
222
223wxTaskBarIcon* 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
236void wxTaskBarIcon::AddObject(wxTaskBarIcon* obj)
237{
238 sm_taskBarIcons.Append(obj);
239}
240
241void wxTaskBarIcon::RemoveObject(wxTaskBarIcon* obj)
242{
243 sm_taskBarIcons.DeleteObject(obj);
244}
245
246bool 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
283WXHWND 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
306MRESULT 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
359MRESULT wxTaskBarIconWindowProc(
360 HWND hWnd
361, UINT msg
362, MPARAM wParam
363, MPARAM lParam
364)
0e320a79 365{
d90895ac
DW
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);
0e320a79
DW
372}
373