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