1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxTaskBarIcon demo
4 // Author: Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
31 // the application icon (under Windows and OS/2 it is in resources)
32 #if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) || defined(__WXX11__)
33 #include "../sample.xpm"
38 #include "wx/taskbar.h"
42 // ----------------------------------------------------------------------------
44 // ----------------------------------------------------------------------------
46 static MyDialog
*gs_dialog
= NULL
;
48 // ============================================================================
50 // ============================================================================
52 // ----------------------------------------------------------------------------
54 // ----------------------------------------------------------------------------
60 if ( !wxApp::OnInit() )
63 // Create the main window
64 gs_dialog
= new MyDialog(wxT("wxTaskBarIcon Test Dialog"));
66 gs_dialog
->Show(true);
72 // ----------------------------------------------------------------------------
73 // MyDialog implementation
74 // ----------------------------------------------------------------------------
76 BEGIN_EVENT_TABLE(MyDialog
, wxDialog
)
77 EVT_BUTTON(wxID_ABOUT
, MyDialog::OnAbout
)
78 EVT_BUTTON(wxID_OK
, MyDialog::OnOK
)
79 EVT_BUTTON(wxID_EXIT
, MyDialog::OnExit
)
80 EVT_CLOSE(MyDialog::OnCloseWindow
)
84 MyDialog::MyDialog(const wxString
& title
)
85 : wxDialog(NULL
, wxID_ANY
, title
)
87 wxSizer
* const sizerTop
= new wxBoxSizer(wxVERTICAL
);
90 flags
.Border(wxALL
, 10);
92 sizerTop
->Add(new wxStaticText
96 _T("Press 'Hide me' to hide this window, Exit to quit.")
99 sizerTop
->Add(new wxStaticText
103 _T("Double-click on the taskbar icon to show me again.")
106 sizerTop
->AddStretchSpacer()->SetMinSize(200, 50);
108 wxSizer
* const sizerBtns
= new wxBoxSizer(wxHORIZONTAL
);
109 sizerBtns
->Add(new wxButton(this, wxID_ABOUT
, _T("&About")), flags
);
110 sizerBtns
->Add(new wxButton(this, wxID_OK
, _T("&Hide")), flags
);
111 sizerBtns
->Add(new wxButton(this, wxID_EXIT
, _T("E&xit")), flags
);
113 sizerTop
->Add(sizerBtns
, flags
.Align(wxALIGN_CENTER_HORIZONTAL
));
114 SetSizerAndFit(sizerTop
);
117 m_taskBarIcon
= new MyTaskBarIcon();
118 #if defined(__WXCOCOA__)
119 m_dockIcon
= new MyTaskBarIcon(wxTaskBarIcon::DOCK
);
122 // we should be able to show up to 128 characters on recent Windows versions
124 if ( !m_taskBarIcon
->SetIcon(wxICON(sample
),
125 "wxTaskBarIcon Sample\n"
126 "With a very, very, very, very\n"
127 "long tooltip whose length is\n"
128 "greater than 64 characters.") )
130 wxLogError(wxT("Could not set icon."));
134 MyDialog::~MyDialog()
136 delete m_taskBarIcon
;
137 #if defined(__WXCOCOA__)
142 void MyDialog::OnAbout(wxCommandEvent
& WXUNUSED(event
))
144 static const char * const title
= "About wxWidgets Taskbar Sample";
145 static const char * const message
146 = "wxWidgets sample showing wxTaskBarIcon class\n"
148 "(C) 1997 Julian Smart\n"
149 "(C) 2007 Vadim Zeitlin";
151 #if defined(__WXMSW__) && wxUSE_TASKBARICON_BALLOONS
152 m_taskBarIcon
->ShowBalloon(title
, message
, 15000, wxICON_INFORMATION
);
154 wxMessageBox(message
, title
, wxICON_INFORMATION
, this);
155 #endif // __WXMSW__/!__WXMSW__
158 void MyDialog::OnOK(wxCommandEvent
& WXUNUSED(event
))
163 void MyDialog::OnExit(wxCommandEvent
& WXUNUSED(event
))
168 void MyDialog::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
174 // ----------------------------------------------------------------------------
175 // MyTaskBarIcon implementation
176 // ----------------------------------------------------------------------------
190 BEGIN_EVENT_TABLE(MyTaskBarIcon
, wxTaskBarIcon
)
191 EVT_MENU(PU_RESTORE
, MyTaskBarIcon::OnMenuRestore
)
192 EVT_MENU(PU_EXIT
, MyTaskBarIcon::OnMenuExit
)
193 EVT_MENU(PU_NEW_ICON
,MyTaskBarIcon::OnMenuSetNewIcon
)
194 EVT_MENU(PU_CHECKMARK
,MyTaskBarIcon::OnMenuCheckmark
)
195 EVT_UPDATE_UI(PU_CHECKMARK
,MyTaskBarIcon::OnMenuUICheckmark
)
196 EVT_TASKBAR_LEFT_DCLICK (MyTaskBarIcon::OnLeftButtonDClick
)
197 EVT_MENU(PU_SUB1
, MyTaskBarIcon::OnMenuSub
)
198 EVT_MENU(PU_SUB2
, MyTaskBarIcon::OnMenuSub
)
201 void MyTaskBarIcon::OnMenuRestore(wxCommandEvent
& )
203 gs_dialog
->Show(true);
206 void MyTaskBarIcon::OnMenuExit(wxCommandEvent
& )
208 gs_dialog
->Close(true);
211 static bool check
= true;
213 void MyTaskBarIcon::OnMenuCheckmark(wxCommandEvent
& )
218 void MyTaskBarIcon::OnMenuUICheckmark(wxUpdateUIEvent
&event
)
223 void MyTaskBarIcon::OnMenuSetNewIcon(wxCommandEvent
&)
225 wxIcon
icon(smile_xpm
);
227 if (!SetIcon(icon
, wxT("wxTaskBarIcon Sample - a different icon")))
228 wxMessageBox(wxT("Could not set new icon."));
231 void MyTaskBarIcon::OnMenuSub(wxCommandEvent
&)
233 wxMessageBox(wxT("You clicked on a submenu!"));
237 wxMenu
*MyTaskBarIcon::CreatePopupMenu()
239 wxMenu
*menu
= new wxMenu
;
240 menu
->Append(PU_RESTORE
, _T("&Restore main window"));
241 menu
->AppendSeparator();
242 menu
->Append(PU_NEW_ICON
, _T("&Set New Icon"));
243 menu
->AppendSeparator();
244 menu
->AppendCheckItem(PU_CHECKMARK
, _T("Test &check mark"));
245 menu
->AppendSeparator();
246 wxMenu
*submenu
= new wxMenu
;
247 submenu
->Append(PU_SUB1
, _T("One submenu"));
248 submenu
->AppendSeparator();
249 submenu
->Append(PU_SUB2
, _T("Another submenu"));
250 menu
->Append(PU_SUBMAIN
, _T("Submenu"), submenu
);
251 #ifndef __WXMAC_OSX__ /*Mac has built-in quit menu*/
252 menu
->AppendSeparator();
253 menu
->Append(PU_EXIT
, _T("E&xit"));
258 void MyTaskBarIcon::OnLeftButtonDClick(wxTaskBarIconEvent
&)
260 gs_dialog
->Show(true);