]> git.saurik.com Git - wxWidgets.git/blob - src/msw/taskbar.cpp
no message
[wxWidgets.git] / src / msw / taskbar.cpp
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
39 LRESULT APIENTRY _EXPORT wxTaskBarIconWindowProc( HWND hWnd, unsigned msg,
40 UINT wParam, LONG lParam );
41
42 char *wxTaskBarWindowClass = "wxTaskBarWindowClass";
43
44 wxList wxTaskBarIcon::sm_taskBarIcons;
45 bool wxTaskBarIcon::sm_registeredClass = FALSE;
46 UINT wxTaskBarIcon::sm_taskbarMsg = 0;
47
48 wxTaskBarIcon::wxTaskBarIcon(void)
49 {
50 m_hWnd = 0;
51 m_iconAdded = FALSE;
52
53 AddObject(this);
54
55 if (RegisterWindowClass())
56 m_hWnd = CreateTaskBarWindow();
57 }
58
59 wxTaskBarIcon::~wxTaskBarIcon(void)
60 {
61 RemoveObject(this);
62
63 if (m_iconAdded)
64 {
65 RemoveIcon();
66 }
67
68 if (m_hWnd)
69 {
70 ::DestroyWindow((HWND) m_hWnd);
71 m_hWnd = 0;
72 }
73 }
74
75 // Operations
76 bool wxTaskBarIcon::SetIcon(const wxIcon& icon, const wxString& tooltip)
77 {
78 if (!IsOK())
79 return FALSE;
80
81 NOTIFYICONDATA notifyData;
82
83 memset(&notifyData, 0, sizeof(notifyData));
84 notifyData.cbSize = sizeof(notifyData);
85 notifyData.hWnd = (HWND) m_hWnd;
86 notifyData.uCallbackMessage = sm_taskbarMsg;
87 notifyData.uFlags = NIF_MESSAGE ;
88 if (icon.Ok())
89 {
90 notifyData.uFlags |= NIF_ICON;
91 notifyData.hIcon = (HICON) icon.GetHICON();
92 }
93
94 if (((const char*) tooltip != NULL) && (tooltip != ""))
95 {
96 notifyData.uFlags |= NIF_TIP ;
97 lstrcpyn(notifyData.szTip, (char*) (const char*) tooltip, sizeof(notifyData.szTip));
98 }
99
100 notifyData.uID = 99;
101
102 if (m_iconAdded)
103 return (Shell_NotifyIcon(NIM_MODIFY, & notifyData) != 0);
104 else
105 {
106 m_iconAdded = (Shell_NotifyIcon(NIM_ADD, & notifyData) != 0);
107 return m_iconAdded;
108 }
109 }
110
111 bool wxTaskBarIcon::RemoveIcon(void)
112 {
113 if (!m_iconAdded)
114 return FALSE;
115
116 NOTIFYICONDATA notifyData;
117
118 memset(&notifyData, 0, sizeof(notifyData));
119 notifyData.cbSize = sizeof(notifyData);
120 notifyData.hWnd = (HWND) m_hWnd;
121 notifyData.uCallbackMessage = sm_taskbarMsg;
122 notifyData.uFlags = NIF_MESSAGE;
123 notifyData.hIcon = 0 ; // hIcon;
124 notifyData.uID = 99;
125 m_iconAdded = FALSE;
126
127 return (Shell_NotifyIcon(NIM_DELETE, & notifyData) != 0);
128 }
129
130 // Overridables
131 void wxTaskBarIcon::OnMouseMove(void)
132 {
133 }
134
135 void wxTaskBarIcon::OnLButtonDown(void)
136 {
137 }
138
139 void wxTaskBarIcon::OnLButtonUp(void)
140 {
141 }
142
143 void wxTaskBarIcon::OnRButtonDown(void)
144 {
145 }
146
147 void wxTaskBarIcon::OnRButtonUp(void)
148 {
149 }
150
151 void wxTaskBarIcon::OnLButtonDClick(void)
152 {
153 }
154
155 void wxTaskBarIcon::OnRButtonDClick(void)
156 {
157 }
158
159 wxTaskBarIcon* wxTaskBarIcon::FindObjectForHWND(WXHWND hWnd)
160 {
161 wxNode*node = sm_taskBarIcons.First();
162 while (node)
163 {
164 wxTaskBarIcon* obj = (wxTaskBarIcon*) node->Data();
165 if (obj->GetHWND() == hWnd)
166 return obj;
167 node = node->Next();
168 }
169 return NULL;
170 }
171
172 void wxTaskBarIcon::AddObject(wxTaskBarIcon* obj)
173 {
174 sm_taskBarIcons.Append(obj);
175 }
176
177 void wxTaskBarIcon::RemoveObject(wxTaskBarIcon* obj)
178 {
179 sm_taskBarIcons.DeleteObject(obj);
180 }
181
182 bool wxTaskBarIcon::RegisterWindowClass()
183 {
184 if (sm_registeredClass)
185 return TRUE;
186
187 // Also register the taskbar message here
188 sm_taskbarMsg = ::RegisterWindowMessage("wxTaskBarIconMessage");
189
190 WNDCLASS wc;
191 bool rc;
192
193 HINSTANCE hInstance = GetModuleHandle(NULL);
194
195 /*
196 * set up and register window class
197 */
198 wc.style = CS_HREDRAW | CS_VREDRAW;
199 wc.lpfnWndProc = (WNDPROC) wxTaskBarIconWindowProc;
200 wc.cbClsExtra = 0;
201 wc.cbWndExtra = 0;
202 wc.hInstance = hInstance;
203 wc.hIcon = 0;
204 wc.hCursor = 0;
205 wc.hbrBackground = 0;
206 wc.lpszMenuName = NULL;
207 wc.lpszClassName = wxTaskBarWindowClass ;
208 rc = (::RegisterClass( &wc ) != 0);
209
210 sm_registeredClass = (rc != 0);
211
212 return( (rc != 0) );
213 }
214
215 WXHWND wxTaskBarIcon::CreateTaskBarWindow()
216 {
217 HINSTANCE hInstance = GetModuleHandle(NULL);
218
219 HWND hWnd = CreateWindowEx (0, wxTaskBarWindowClass,
220 "wxTaskBarWindow",
221 WS_OVERLAPPED,
222 0,
223 0,
224 10,
225 10,
226 NULL,
227 (HMENU) 0,
228 hInstance,
229 NULL);
230
231 return (WXHWND) hWnd;
232 }
233
234 long wxTaskBarIcon::WindowProc( WXHWND hWnd, unsigned int msg, unsigned int wParam, long lParam )
235 {
236 if (msg != sm_taskbarMsg)
237 return DefWindowProc((HWND) hWnd, msg, wParam, lParam);
238
239 switch (lParam)
240 {
241 case WM_LBUTTONDOWN:
242 OnLButtonDown();
243 break;
244
245 case WM_LBUTTONUP:
246 OnLButtonUp();
247 break;
248
249 case WM_RBUTTONDOWN:
250 OnRButtonDown();
251 break;
252
253 case WM_RBUTTONUP:
254 OnRButtonUp();
255 break;
256
257 case WM_LBUTTONDBLCLK:
258 OnLButtonDClick();
259 break;
260
261 case WM_RBUTTONDBLCLK:
262 OnRButtonDClick();
263 break;
264
265 case WM_MOUSEMOVE:
266 OnMouseMove();
267 break;
268
269 default:
270 break;
271 }
272 return 0;
273 }
274
275 LRESULT APIENTRY _EXPORT wxTaskBarIconWindowProc( HWND hWnd, unsigned msg,
276 UINT wParam, LONG lParam )
277 {
278 wxTaskBarIcon* obj = wxTaskBarIcon::FindObjectForHWND((WXHWND) hWnd);
279 if (obj)
280 return obj->WindowProc((WXHWND) hWnd, msg, wParam, lParam);
281 else
282 return DefWindowProc(hWnd, msg, wParam, lParam);
283 }
284
285 #endif
286 // __WIN95__