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