1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxTaskBarIcon demo
4 // Author: Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
23 // the application icon (under Windows and OS/2 it is in resources)
24 #if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) || defined(__WXX11__)
25 #include "../sample.xpm"
30 #include "wx/taskbar.h"
34 MyDialog
*dialog
= NULL
;
38 bool MyApp
::OnInit(void)
40 // Create the main frame window
41 dialog
= new MyDialog(NULL
, wxID_ANY
, wxT("wxTaskBarIcon Test Dialog"), wxDefaultPosition
, wxSize(365, 290));
49 BEGIN_EVENT_TABLE(MyDialog
, wxDialog
)
50 EVT_BUTTON(wxID_OK
, MyDialog
::OnOK
)
51 EVT_BUTTON(wxID_EXIT
, MyDialog
::OnExit
)
52 EVT_CLOSE(MyDialog
::OnCloseWindow
)
56 MyDialog
::MyDialog(wxWindow
* parent
, const wxWindowID id
, const wxString
& title
,
57 const wxPoint
& pos
, const wxSize
& size
, const long windowStyle
):
58 wxDialog(parent
, id
, title
, pos
, size
, windowStyle
)
66 #if defined(__WXCOCOA__)
71 void MyDialog
::OnOK(wxCommandEvent
& WXUNUSED(event
))
76 void MyDialog
::OnExit(wxCommandEvent
& WXUNUSED(event
))
81 void MyDialog
::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
86 void MyDialog
::Init(void)
88 (void)new wxStaticText(this, wxID_ANY
, _T("Press 'Hide me' to hide me, Exit to quit."),
91 (void)new wxStaticText(this, wxID_ANY
, _T("Double-click on the taskbar icon to show me again."),
94 (void)new wxButton(this, wxID_EXIT
, _T("Exit"), wxPoint(185, 230), wxSize(80, 25));
95 (new wxButton(this, wxID_OK
, _T("Hide me"), wxPoint(100, 230), wxSize(80, 25)))->SetDefault();
98 m_taskBarIcon
= new MyTaskBarIcon();
99 #if defined(__WXCOCOA__)
100 m_dockIcon
= new MyTaskBarIcon(wxTaskBarIcon
::DOCK
);
102 if (!m_taskBarIcon
->SetIcon(wxICON(sample
), wxT("wxTaskBarIcon Sample")))
103 wxMessageBox(wxT("Could not set icon."));
119 BEGIN_EVENT_TABLE(MyTaskBarIcon
, wxTaskBarIcon
)
120 EVT_MENU(PU_RESTORE
, MyTaskBarIcon
::OnMenuRestore
)
121 EVT_MENU(PU_EXIT
, MyTaskBarIcon
::OnMenuExit
)
122 EVT_MENU(PU_NEW_ICON
,MyTaskBarIcon
::OnMenuSetNewIcon
)
123 EVT_MENU(PU_OLD_ICON
,MyTaskBarIcon
::OnMenuSetOldIcon
)
124 EVT_MENU(PU_CHECKMARK
,MyTaskBarIcon
::OnMenuCheckmark
)
125 EVT_UPDATE_UI(PU_CHECKMARK
,MyTaskBarIcon
::OnMenuUICheckmark
)
126 EVT_TASKBAR_LEFT_DCLICK (MyTaskBarIcon
::OnLeftButtonDClick
)
127 EVT_MENU(PU_SUB1
, MyTaskBarIcon
::OnMenuSub
)
128 EVT_MENU(PU_SUB2
, MyTaskBarIcon
::OnMenuSub
)
131 void MyTaskBarIcon
::OnMenuRestore(wxCommandEvent
& )
136 void MyTaskBarIcon
::OnMenuExit(wxCommandEvent
& )
141 static bool check
= true;
143 void MyTaskBarIcon
::OnMenuCheckmark(wxCommandEvent
& )
148 void MyTaskBarIcon
::OnMenuUICheckmark(wxUpdateUIEvent
&event
)
150 event
.Check( check
);
153 void MyTaskBarIcon
::OnMenuSetNewIcon(wxCommandEvent
&)
155 wxIcon
icon(smile_xpm
);
157 if (!SetIcon(icon
, wxT("wxTaskBarIcon Sample - a different icon")))
158 wxMessageBox(wxT("Could not set new icon."));
161 void MyTaskBarIcon
::OnMenuSetOldIcon(wxCommandEvent
&)
163 if (IsIconInstalled())
169 wxMessageBox(wxT("wxTaskBarIcon Sample - icon already is the old version"));
173 void MyTaskBarIcon
::OnMenuSub(wxCommandEvent
&)
175 wxMessageBox(wxT("You clicked on a submenu!"));
179 wxMenu
*MyTaskBarIcon
::CreatePopupMenu()
181 // Try creating menus different ways
182 // TODO: Probably try calling SetBitmap with some XPMs here
183 wxMenu
*menu
= new wxMenu
;
184 menu
->Append(PU_RESTORE
, _T("&Restore TBTest"));
185 menu
->AppendSeparator();
186 menu
->Append(PU_OLD_ICON
, _T("&Restore Old Icon"));
187 menu
->Append(PU_NEW_ICON
, _T("&Set New Icon"));
188 menu
->AppendSeparator();
189 menu
->Append(PU_CHECKMARK
, _T("Checkmark"),wxT(""), wxITEM_CHECK
);
190 menu
->AppendSeparator();
191 wxMenu
*submenu
= new wxMenu
;
192 submenu
->Append(PU_SUB1
, _T("One submenu"));
193 submenu
->AppendSeparator();
194 submenu
->Append(PU_SUB2
, _T("Another submenu"));
195 menu
->Append(PU_SUBMAIN
, _T("Submenu"), submenu
);
196 #ifndef __WXMAC_OSX__ /*Mac has built-in quit menu*/
197 menu
->AppendSeparator();
198 menu
->Append(PU_EXIT
, _T("E&xit"));
203 void MyTaskBarIcon
::OnLeftButtonDClick(wxTaskBarIconEvent
&)