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