]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/taskbar.cpp
1 /////////////////////////////////////////////////////////////////////////
3 // Purpose: Implements wxTaskBarIcon class for manipulating icons on
4 // the task bar. Optional.
5 // Author: David Webster
9 // Copyright: (c) David Webster
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////
13 // For compilers that support precompilation, includes "wx.h".
14 #include "wx/wxprec.h"
18 #include "wx/window.h"
27 #include <wx/os2/taskbar.h>
28 #include <wx/os2/private.h>
30 MRESULT
wxTaskBarIconWindowProc( HWND hWnd
, UINT msg
, MPARAM wParam
, MPARAM lParam
);
32 wxChar
*wxTaskBarWindowClass
= wxT("wxTaskBarWindowClass");
34 wxList
wxTaskBarIcon::sm_taskBarIcons
;
35 bool wxTaskBarIcon::sm_registeredClass
= FALSE
;
36 UINT
wxTaskBarIcon::sm_taskbarMsg
= 0;
39 #if !USE_SHARED_LIBRARY
40 BEGIN_EVENT_TABLE(wxTaskBarIcon
, wxEvtHandler
)
41 EVT_TASKBAR_MOVE (wxTaskBarIcon::_OnMouseMove
)
42 EVT_TASKBAR_LEFT_DOWN (wxTaskBarIcon::_OnLButtonDown
)
43 EVT_TASKBAR_LEFT_UP (wxTaskBarIcon::_OnLButtonUp
)
44 EVT_TASKBAR_RIGHT_DOWN (wxTaskBarIcon::_OnRButtonDown
)
45 EVT_TASKBAR_RIGHT_UP (wxTaskBarIcon::_OnRButtonUp
)
46 EVT_TASKBAR_LEFT_DCLICK (wxTaskBarIcon::_OnLButtonDClick
)
47 EVT_TASKBAR_RIGHT_DCLICK (wxTaskBarIcon::_OnRButtonDClick
)
50 IMPLEMENT_DYNAMIC_CLASS(wxTaskBarIcon
, wxEvtHandler
)
54 wxTaskBarIcon::wxTaskBarIcon(void)
62 if (RegisterWindowClass())
63 m_hWnd = CreateTaskBarWindow();
67 wxTaskBarIcon::~wxTaskBarIcon(void)
80 ::DestroyWindow((HWND) m_hWnd);
87 bool wxTaskBarIcon::SetIcon(const wxIcon
& icon
, const wxString
& tooltip
)
93 NOTIFYICONDATA notifyData;
95 memset(¬ifyData, 0, sizeof(notifyData));
96 notifyData.cbSize = sizeof(notifyData);
97 notifyData.hWnd = (HWND) m_hWnd;
98 notifyData.uCallbackMessage = sm_taskbarMsg;
99 notifyData.uFlags = NIF_MESSAGE ;
102 notifyData.uFlags |= NIF_ICON;
103 notifyData.hIcon = (HICON) icon.GetHICON();
106 if (((const wxChar*) tooltip != NULL) && (tooltip != wxT("")))
108 notifyData.uFlags |= NIF_TIP ;
109 lstrcpyn(notifyData.szTip, WXSTRINGCAST tooltip, sizeof(notifyData.szTip));
115 return (Shell_NotifyIcon(NIM_MODIFY, & notifyData) != 0);
118 m_iconAdded = (Shell_NotifyIcon(NIM_ADD, & notifyData) != 0);
125 bool wxTaskBarIcon::RemoveIcon(void)
131 NOTIFYICONDATA notifyData;
133 memset(¬ifyData, 0, sizeof(notifyData));
134 notifyData.cbSize = sizeof(notifyData);
135 notifyData.hWnd = (HWND) m_hWnd;
136 notifyData.uCallbackMessage = sm_taskbarMsg;
137 notifyData.uFlags = NIF_MESSAGE;
138 notifyData.hIcon = 0 ; // hIcon;
142 return (Shell_NotifyIcon(NIM_DELETE, & notifyData) != 0);
147 bool wxTaskBarIcon::PopupMenu(wxMenu
*menu
) //, int x, int y);
149 // OK, so I know this isn't thread-friendly, but
150 // what to do? We need this check.
152 static bool s_inPopup
= FALSE
;
162 wxGetMousePosition(&x
, &y
);
164 // is wxFrame the best window type to use???
165 win
= new wxFrame(NULL
, -1, "", wxPoint(x
,y
), wxSize(-1,-1), 0);
166 win
->PushEventHandler(this);
168 // Remove from record of top-level windows, or will confuse wxWindows
169 // if we try to exit right now.
170 wxTopLevelWindows
.DeleteObject(win
);
174 rval
= win
->PopupMenu(menu
, 0, 0);
176 win
->PopEventHandler(FALSE
);
186 void wxTaskBarIcon::OnMouseMove(wxEvent
&)
190 void wxTaskBarIcon::OnLButtonDown(wxEvent
&)
194 void wxTaskBarIcon::OnLButtonUp(wxEvent
&)
198 void wxTaskBarIcon::OnRButtonDown(wxEvent
&)
202 void wxTaskBarIcon::OnRButtonUp(wxEvent
&)
206 void wxTaskBarIcon::OnLButtonDClick(wxEvent
&)
210 void wxTaskBarIcon::OnRButtonDClick(wxEvent
&)
214 void wxTaskBarIcon::_OnMouseMove(wxEvent
& e
) { OnMouseMove(e
); }
215 void wxTaskBarIcon::_OnLButtonDown(wxEvent
& e
) { OnLButtonDown(e
); }
216 void wxTaskBarIcon::_OnLButtonUp(wxEvent
& e
) { OnLButtonUp(e
); }
217 void wxTaskBarIcon::_OnRButtonDown(wxEvent
& e
) { OnRButtonDown(e
); }
218 void wxTaskBarIcon::_OnRButtonUp(wxEvent
& e
) { OnRButtonUp(e
); }
219 void wxTaskBarIcon::_OnLButtonDClick(wxEvent
& e
) { OnLButtonDClick(e
); }
220 void wxTaskBarIcon::_OnRButtonDClick(wxEvent
& e
) { OnRButtonDClick(e
); }
223 wxTaskBarIcon
* wxTaskBarIcon::FindObjectForHWND(WXHWND hWnd
)
225 wxNode
*node
= sm_taskBarIcons
.First();
228 wxTaskBarIcon
* obj
= (wxTaskBarIcon
*) node
->Data();
229 if (obj
->GetHWND() == hWnd
)
236 void wxTaskBarIcon::AddObject(wxTaskBarIcon
* obj
)
238 sm_taskBarIcons
.Append(obj
);
241 void wxTaskBarIcon::RemoveObject(wxTaskBarIcon
* obj
)
243 sm_taskBarIcons
.DeleteObject(obj
);
246 bool wxTaskBarIcon::RegisterWindowClass()
248 if (sm_registeredClass
)
251 // Also register the taskbar message here
254 sm_taskbarMsg = ::RegisterWindowMessage(wxT("wxTaskBarIconMessage"));
259 HINSTANCE hInstance = GetModuleHandle(NULL);
262 // set up and register window class
264 wc.style = CS_HREDRAW | CS_VREDRAW;
265 wc.lpfnWndProc = (WNDPROC) wxTaskBarIconWindowProc;
268 wc.hInstance = hInstance;
271 wc.hbrBackground = 0;
272 wc.lpszMenuName = NULL;
273 wc.lpszClassName = wxTaskBarWindowClass ;
274 rc = (::RegisterClass( &wc ) != 0);
276 sm_registeredClass = (rc != 0);
283 WXHWND
wxTaskBarIcon::CreateTaskBarWindow()
287 HINSTANCE hInstance = GetModuleHandle(NULL);
289 HWND hWnd = CreateWindowEx (0, wxTaskBarWindowClass,
290 wxT("wxTaskBarWindow"),
301 return (WXHWND) hWnd;
306 MRESULT
wxTaskBarIcon::WindowProc( WXHWND hWnd
, UINT msg
, MPARAM wParam
, MPARAM lParam
)
308 wxEventType eventType
= 0;
311 if (msg != sm_taskbarMsg)
312 return DefWindowProc((HWND) hWnd, msg, wParam, lParam);
317 eventType = wxEVT_TASKBAR_LEFT_DOWN;
321 eventType = wxEVT_TASKBAR_LEFT_UP;
325 eventType = wxEVT_TASKBAR_RIGHT_DOWN;
329 eventType = wxEVT_TASKBAR_RIGHT_UP;
332 case WM_LBUTTONDBLCLK:
333 eventType = wxEVT_TASKBAR_LEFT_DCLICK;
336 case WM_RBUTTONDBLCLK:
337 eventType = wxEVT_TASKBAR_RIGHT_DCLICK;
341 eventType = wxEVT_TASKBAR_MOVE;
351 event
.SetEventType(eventType
);
352 event
.SetEventObject(this);
359 MRESULT
wxTaskBarIconWindowProc(
366 wxTaskBarIcon
* obj
= wxTaskBarIcon::FindObjectForHWND((WXHWND
) hWnd
);
368 return obj
->WindowProc((WXHWND
) hWnd
, msg
, wParam
, lParam
);
371 // return DefWindowProc(hWnd, msg, wParam, lParam);