]> git.saurik.com Git - wxWidgets.git/blame - src/msw/taskbar.cpp
Dialog Editor corrections for latest wxWin changes; removed wxProp files
[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)
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)
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
147// Overridables
56194595 148void wxTaskBarIcon::OnMouseMove(wxEvent&)
2bda0e17
KB
149{
150}
151
56194595 152void wxTaskBarIcon::OnLButtonDown(wxEvent&)
2bda0e17
KB
153{
154}
155
56194595 156void wxTaskBarIcon::OnLButtonUp(wxEvent&)
2bda0e17
KB
157{
158}
159
56194595 160void wxTaskBarIcon::OnRButtonDown(wxEvent&)
2bda0e17
KB
161{
162}
163
56194595 164void wxTaskBarIcon::OnRButtonUp(wxEvent&)
2bda0e17
KB
165{
166}
167
56194595 168void wxTaskBarIcon::OnLButtonDClick(wxEvent&)
2bda0e17
KB
169{
170}
171
56194595 172void wxTaskBarIcon::OnRButtonDClick(wxEvent&)
2bda0e17
KB
173{
174}
175
176wxTaskBarIcon* wxTaskBarIcon::FindObjectForHWND(WXHWND hWnd)
177{
178 wxNode*node = sm_taskBarIcons.First();
179 while (node)
180 {
181 wxTaskBarIcon* obj = (wxTaskBarIcon*) node->Data();
182 if (obj->GetHWND() == hWnd)
183 return obj;
184 node = node->Next();
185 }
186 return NULL;
187}
188
189void wxTaskBarIcon::AddObject(wxTaskBarIcon* obj)
190{
191 sm_taskBarIcons.Append(obj);
192}
193
194void wxTaskBarIcon::RemoveObject(wxTaskBarIcon* obj)
195{
196 sm_taskBarIcons.DeleteObject(obj);
197}
198
199bool wxTaskBarIcon::RegisterWindowClass()
200{
201 if (sm_registeredClass)
202 return TRUE;
203
204 // Also register the taskbar message here
205 sm_taskbarMsg = ::RegisterWindowMessage("wxTaskBarIconMessage");
206
207 WNDCLASS wc;
208 bool rc;
209
210 HINSTANCE hInstance = GetModuleHandle(NULL);
211
212 /*
213 * set up and register window class
214 */
215 wc.style = CS_HREDRAW | CS_VREDRAW;
216 wc.lpfnWndProc = (WNDPROC) wxTaskBarIconWindowProc;
217 wc.cbClsExtra = 0;
218 wc.cbWndExtra = 0;
219 wc.hInstance = hInstance;
220 wc.hIcon = 0;
221 wc.hCursor = 0;
222 wc.hbrBackground = 0;
223 wc.lpszMenuName = NULL;
224 wc.lpszClassName = wxTaskBarWindowClass ;
225 rc = (::RegisterClass( &wc ) != 0);
226
227 sm_registeredClass = (rc != 0);
228
229 return( (rc != 0) );
230}
231
232WXHWND wxTaskBarIcon::CreateTaskBarWindow()
233{
234 HINSTANCE hInstance = GetModuleHandle(NULL);
235
236 HWND hWnd = CreateWindowEx (0, wxTaskBarWindowClass,
237 "wxTaskBarWindow",
238 WS_OVERLAPPED,
239 0,
240 0,
241 10,
242 10,
243 NULL,
244 (HMENU) 0,
245 hInstance,
246 NULL);
247
248 return (WXHWND) hWnd;
249}
250
251long wxTaskBarIcon::WindowProc( WXHWND hWnd, unsigned int msg, unsigned int wParam, long lParam )
252{
56194595
RD
253 wxEventType eventType = 0;
254
2bda0e17
KB
255 if (msg != sm_taskbarMsg)
256 return DefWindowProc((HWND) hWnd, msg, wParam, lParam);
257
258 switch (lParam)
259 {
260 case WM_LBUTTONDOWN:
56194595
RD
261 eventType = wxEVT_TASKBAR_LEFT_DOWN;
262 break;
2bda0e17
KB
263
264 case WM_LBUTTONUP:
56194595
RD
265 eventType = wxEVT_TASKBAR_LEFT_UP;
266 break;
2bda0e17
KB
267
268 case WM_RBUTTONDOWN:
56194595
RD
269 eventType = wxEVT_TASKBAR_RIGHT_DOWN;
270 break;
2bda0e17
KB
271
272 case WM_RBUTTONUP:
56194595
RD
273 eventType = wxEVT_TASKBAR_RIGHT_UP;
274 break;
2bda0e17
KB
275
276 case WM_LBUTTONDBLCLK:
56194595
RD
277 eventType = wxEVT_TASKBAR_LEFT_DCLICK;
278 break;
2bda0e17
KB
279
280 case WM_RBUTTONDBLCLK:
56194595
RD
281 eventType = wxEVT_TASKBAR_RIGHT_DCLICK;
282 break;
2bda0e17
KB
283
284 case WM_MOUSEMOVE:
56194595
RD
285 eventType = wxEVT_TASKBAR_MOVE;
286 break;
2bda0e17
KB
287
288 default:
56194595 289 break;
2bda0e17 290 }
56194595
RD
291
292 if (eventType) {
293 wxEvent event;
294 event.SetEventType(eventType);
295 event.SetEventObject(this);
296
297 ProcessEvent(event);
298 }
2bda0e17
KB
299 return 0;
300}
301
302LRESULT APIENTRY _EXPORT wxTaskBarIconWindowProc( HWND hWnd, unsigned msg,
303 UINT wParam, LONG lParam )
304{
305 wxTaskBarIcon* obj = wxTaskBarIcon::FindObjectForHWND((WXHWND) hWnd);
306 if (obj)
307 return obj->WindowProc((WXHWND) hWnd, msg, wParam, lParam);
308 else
309 return DefWindowProc(hWnd, msg, wParam, lParam);
310}
311
312#endif
313 // __WIN95__