]>
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 BEGIN_EVENT_TABLE(wxTaskBarIcon
, wxEvtHandler
)
40 EVT_TASKBAR_MOVE (wxTaskBarIcon::_OnMouseMove
)
41 EVT_TASKBAR_LEFT_DOWN (wxTaskBarIcon::_OnLButtonDown
)
42 EVT_TASKBAR_LEFT_UP (wxTaskBarIcon::_OnLButtonUp
)
43 EVT_TASKBAR_RIGHT_DOWN (wxTaskBarIcon::_OnRButtonDown
)
44 EVT_TASKBAR_RIGHT_UP (wxTaskBarIcon::_OnRButtonUp
)
45 EVT_TASKBAR_LEFT_DCLICK (wxTaskBarIcon::_OnLButtonDClick
)
46 EVT_TASKBAR_RIGHT_DCLICK (wxTaskBarIcon::_OnRButtonDClick
)
49 IMPLEMENT_DYNAMIC_CLASS(wxTaskBarIcon
, wxEvtHandler
)
52 wxTaskBarIcon::wxTaskBarIcon(void)
60 if (RegisterWindowClass())
61 m_hWnd = CreateTaskBarWindow();
65 wxTaskBarIcon::~wxTaskBarIcon(void)
78 ::DestroyWindow((HWND) m_hWnd);
85 bool wxTaskBarIcon::SetIcon(const wxIcon
& icon
, const wxString
& tooltip
)
91 NOTIFYICONDATA notifyData;
93 memset(¬ifyData, 0, sizeof(notifyData));
94 notifyData.cbSize = sizeof(notifyData);
95 notifyData.hWnd = (HWND) m_hWnd;
96 notifyData.uCallbackMessage = sm_taskbarMsg;
97 notifyData.uFlags = NIF_MESSAGE ;
100 notifyData.uFlags |= NIF_ICON;
101 notifyData.hIcon = (HICON) icon.GetHICON();
104 if (((const wxChar*) tooltip != NULL) && (tooltip != wxT("")))
106 notifyData.uFlags |= NIF_TIP ;
107 lstrcpyn(notifyData.szTip, WXSTRINGCAST tooltip, sizeof(notifyData.szTip));
113 return (Shell_NotifyIcon(NIM_MODIFY, & notifyData) != 0);
116 m_iconAdded = (Shell_NotifyIcon(NIM_ADD, & notifyData) != 0);
123 bool wxTaskBarIcon::RemoveIcon(void)
129 NOTIFYICONDATA notifyData;
131 memset(¬ifyData, 0, sizeof(notifyData));
132 notifyData.cbSize = sizeof(notifyData);
133 notifyData.hWnd = (HWND) m_hWnd;
134 notifyData.uCallbackMessage = sm_taskbarMsg;
135 notifyData.uFlags = NIF_MESSAGE;
136 notifyData.hIcon = 0 ; // hIcon;
140 return (Shell_NotifyIcon(NIM_DELETE, & notifyData) != 0);
145 bool wxTaskBarIcon::PopupMenu(wxMenu
*menu
) //, int x, int y);
147 // OK, so I know this isn't thread-friendly, but
148 // what to do? We need this check.
150 static bool s_inPopup
= FALSE
;
160 wxGetMousePosition(&x
, &y
);
162 // is wxFrame the best window type to use???
163 win
= new wxFrame(NULL
, -1, "", wxPoint(x
,y
), wxSize(-1,-1), 0);
164 win
->PushEventHandler(this);
166 // Remove from record of top-level windows, or will confuse wxWindows
167 // if we try to exit right now.
168 wxTopLevelWindows
.DeleteObject(win
);
172 rval
= win
->PopupMenu(menu
, 0, 0);
174 win
->PopEventHandler(FALSE
);
184 void wxTaskBarIcon::OnMouseMove(wxEvent
&)
188 void wxTaskBarIcon::OnLButtonDown(wxEvent
&)
192 void wxTaskBarIcon::OnLButtonUp(wxEvent
&)
196 void wxTaskBarIcon::OnRButtonDown(wxEvent
&)
200 void wxTaskBarIcon::OnRButtonUp(wxEvent
&)
204 void wxTaskBarIcon::OnLButtonDClick(wxEvent
&)
208 void wxTaskBarIcon::OnRButtonDClick(wxEvent
&)
212 void wxTaskBarIcon::_OnMouseMove(wxEvent
& e
) { OnMouseMove(e
); }
213 void wxTaskBarIcon::_OnLButtonDown(wxEvent
& e
) { OnLButtonDown(e
); }
214 void wxTaskBarIcon::_OnLButtonUp(wxEvent
& e
) { OnLButtonUp(e
); }
215 void wxTaskBarIcon::_OnRButtonDown(wxEvent
& e
) { OnRButtonDown(e
); }
216 void wxTaskBarIcon::_OnRButtonUp(wxEvent
& e
) { OnRButtonUp(e
); }
217 void wxTaskBarIcon::_OnLButtonDClick(wxEvent
& e
) { OnLButtonDClick(e
); }
218 void wxTaskBarIcon::_OnRButtonDClick(wxEvent
& e
) { OnRButtonDClick(e
); }
221 wxTaskBarIcon
* wxTaskBarIcon::FindObjectForHWND(WXHWND hWnd
)
223 wxNode
*node
= sm_taskBarIcons
.First();
226 wxTaskBarIcon
* obj
= (wxTaskBarIcon
*) node
->Data();
227 if (obj
->GetHWND() == hWnd
)
234 void wxTaskBarIcon::AddObject(wxTaskBarIcon
* obj
)
236 sm_taskBarIcons
.Append(obj
);
239 void wxTaskBarIcon::RemoveObject(wxTaskBarIcon
* obj
)
241 sm_taskBarIcons
.DeleteObject(obj
);
244 bool wxTaskBarIcon::RegisterWindowClass()
246 if (sm_registeredClass
)
249 // Also register the taskbar message here
252 sm_taskbarMsg = ::RegisterWindowMessage(wxT("wxTaskBarIconMessage"));
257 HINSTANCE hInstance = GetModuleHandle(NULL);
260 // set up and register window class
262 wc.style = CS_HREDRAW | CS_VREDRAW;
263 wc.lpfnWndProc = (WNDPROC) wxTaskBarIconWindowProc;
266 wc.hInstance = hInstance;
269 wc.hbrBackground = 0;
270 wc.lpszMenuName = NULL;
271 wc.lpszClassName = wxTaskBarWindowClass ;
272 rc = (::RegisterClass( &wc ) != 0);
274 sm_registeredClass = (rc != 0);
281 WXHWND
wxTaskBarIcon::CreateTaskBarWindow()
285 HINSTANCE hInstance = GetModuleHandle(NULL);
287 HWND hWnd = CreateWindowEx (0, wxTaskBarWindowClass,
288 wxT("wxTaskBarWindow"),
299 return (WXHWND) hWnd;
304 MRESULT
wxTaskBarIcon::WindowProc( WXHWND hWnd
, UINT msg
, MPARAM wParam
, MPARAM lParam
)
306 wxEventType eventType
= 0;
309 if (msg != sm_taskbarMsg)
310 return DefWindowProc((HWND) hWnd, msg, wParam, lParam);
315 eventType = wxEVT_TASKBAR_LEFT_DOWN;
319 eventType = wxEVT_TASKBAR_LEFT_UP;
323 eventType = wxEVT_TASKBAR_RIGHT_DOWN;
327 eventType = wxEVT_TASKBAR_RIGHT_UP;
330 case WM_LBUTTONDBLCLK:
331 eventType = wxEVT_TASKBAR_LEFT_DCLICK;
334 case WM_RBUTTONDBLCLK:
335 eventType = wxEVT_TASKBAR_RIGHT_DCLICK;
339 eventType = wxEVT_TASKBAR_MOVE;
348 event.SetEventType(eventType);
349 event.SetEventObject(this);
357 MRESULT
wxTaskBarIconWindowProc(
364 wxTaskBarIcon
* obj
= wxTaskBarIcon::FindObjectForHWND((WXHWND
) hWnd
);
366 return obj
->WindowProc((WXHWND
) hWnd
, msg
, wParam
, lParam
);
369 // return DefWindowProc(hWnd, msg, wParam, lParam);