]>
Commit | Line | Data |
---|---|---|
bbf1f0e5 KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: tbtest.cpp | |
3 | // Purpose: wxTaskBarIcon demo | |
4 | // Author: Julian Smart | |
329fa151 | 5 | // Modified by: |
bbf1f0e5 KB |
6 | // Created: 01/02/97 |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) | |
2f6c54eb | 9 | // Licence: wxWindows licence |
bbf1f0e5 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | // For compilers that support precompilation, includes "wx.h". | |
13 | #include "wx/wxprec.h" | |
14 | ||
15 | #ifdef __BORLANDC__ | |
16 | #pragma hdrstop | |
17 | #endif | |
18 | ||
19 | #ifndef WX_PRECOMP | |
788233da | 20 | #include "wx/wx.h" |
bbf1f0e5 KB |
21 | #endif |
22 | ||
4bc64712 VS |
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__) | |
1e6d9c20 | 25 | #include "../sample.xpm" |
4bc64712 VS |
26 | #endif |
27 | ||
0dc6da2d VS |
28 | #include "smile.xpm" |
29 | ||
e015d1f7 | 30 | #include "wx/taskbar.h" |
bbf1f0e5 KB |
31 | #include "tbtest.h" |
32 | ||
329fa151 | 33 | // Declare two frames |
bbf1f0e5 KB |
34 | MyDialog *dialog = NULL; |
35 | ||
36 | IMPLEMENT_APP(MyApp) | |
37 | ||
38 | bool MyApp::OnInit(void) | |
39 | { | |
45e6e6f8 VZ |
40 | if ( !wxApp::OnInit() ) |
41 | return false; | |
42 | ||
bbf1f0e5 | 43 | // Create the main frame window |
2a21ac15 | 44 | dialog = new MyDialog(NULL, wxID_ANY, wxT("wxTaskBarIcon Test Dialog"), wxDefaultPosition, wxSize(365, 290)); |
bbf1f0e5 | 45 | |
27301f26 | 46 | dialog->Show(true); |
bbf1f0e5 | 47 | |
27301f26 | 48 | return true; |
bbf1f0e5 KB |
49 | } |
50 | ||
69ecd30f | 51 | |
bbf1f0e5 KB |
52 | BEGIN_EVENT_TABLE(MyDialog, wxDialog) |
53 | EVT_BUTTON(wxID_OK, MyDialog::OnOK) | |
54 | EVT_BUTTON(wxID_EXIT, MyDialog::OnExit) | |
d66d9d5b | 55 | EVT_CLOSE(MyDialog::OnCloseWindow) |
bbf1f0e5 KB |
56 | END_EVENT_TABLE() |
57 | ||
69ecd30f | 58 | |
bbf1f0e5 KB |
59 | MyDialog::MyDialog(wxWindow* parent, const wxWindowID id, const wxString& title, |
60 | const wxPoint& pos, const wxSize& size, const long windowStyle): | |
61 | wxDialog(parent, id, title, pos, size, windowStyle) | |
62 | { | |
63 | Init(); | |
64 | } | |
65 | ||
1e6d9c20 VS |
66 | MyDialog::~MyDialog() |
67 | { | |
68 | delete m_taskBarIcon; | |
a5593369 DE |
69 | #if defined(__WXCOCOA__) |
70 | delete m_dockIcon; | |
71 | #endif | |
1e6d9c20 VS |
72 | } |
73 | ||
256b8649 | 74 | void MyDialog::OnOK(wxCommandEvent& WXUNUSED(event)) |
bbf1f0e5 | 75 | { |
27301f26 | 76 | Show(false); |
bbf1f0e5 KB |
77 | } |
78 | ||
256b8649 | 79 | void MyDialog::OnExit(wxCommandEvent& WXUNUSED(event)) |
bbf1f0e5 | 80 | { |
27301f26 | 81 | Close(true); |
bbf1f0e5 KB |
82 | } |
83 | ||
256b8649 | 84 | void MyDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event)) |
bbf1f0e5 KB |
85 | { |
86 | Destroy(); | |
87 | } | |
88 | ||
89 | void MyDialog::Init(void) | |
90 | { | |
0063a4dc | 91 | (void)new wxStaticText(this, wxID_ANY, _T("Press 'Hide me' to hide me, Exit to quit."), |
e0221ef7 | 92 | wxPoint(10, 20)); |
bbf1f0e5 | 93 | |
27301f26 | 94 | (void)new wxStaticText(this, wxID_ANY, _T("Double-click on the taskbar icon to show me again."), |
e0221ef7 | 95 | wxPoint(10, 40)); |
69ecd30f | 96 | |
ab1ca7b3 | 97 | (void)new wxButton(this, wxID_EXIT, _T("Exit"), wxPoint(185, 230), wxSize(80, 25)); |
0063a4dc | 98 | (new wxButton(this, wxID_OK, _T("Hide me"), wxPoint(100, 230), wxSize(80, 25)))->SetDefault(); |
e0221ef7 | 99 | Centre(wxBOTH); |
1e6d9c20 | 100 | |
329fa151 | 101 | m_taskBarIcon = new MyTaskBarIcon(); |
a5593369 DE |
102 | #if defined(__WXCOCOA__) |
103 | m_dockIcon = new MyTaskBarIcon(wxTaskBarIcon::DOCK); | |
104 | #endif | |
329fa151 | 105 | if (!m_taskBarIcon->SetIcon(wxICON(sample), wxT("wxTaskBarIcon Sample"))) |
1e6d9c20 | 106 | wxMessageBox(wxT("Could not set icon.")); |
bbf1f0e5 KB |
107 | } |
108 | ||
69ecd30f RD |
109 | |
110 | enum { | |
111 | PU_RESTORE = 10001, | |
ab85e6cd | 112 | PU_NEW_ICON, |
d806d30a | 113 | PU_OLD_ICON, |
69ecd30f | 114 | PU_EXIT, |
d806d30a DS |
115 | PU_CHECKMARK, |
116 | PU_SUB1, | |
117 | PU_SUB2, | |
118 | PU_SUBMAIN | |
69ecd30f RD |
119 | }; |
120 | ||
121 | ||
122 | BEGIN_EVENT_TABLE(MyTaskBarIcon, wxTaskBarIcon) | |
123 | EVT_MENU(PU_RESTORE, MyTaskBarIcon::OnMenuRestore) | |
124 | EVT_MENU(PU_EXIT, MyTaskBarIcon::OnMenuExit) | |
ab85e6cd | 125 | EVT_MENU(PU_NEW_ICON,MyTaskBarIcon::OnMenuSetNewIcon) |
d806d30a | 126 | EVT_MENU(PU_OLD_ICON,MyTaskBarIcon::OnMenuSetOldIcon) |
2afa9fa7 RR |
127 | EVT_MENU(PU_CHECKMARK,MyTaskBarIcon::OnMenuCheckmark) |
128 | EVT_UPDATE_UI(PU_CHECKMARK,MyTaskBarIcon::OnMenuUICheckmark) | |
329fa151 | 129 | EVT_TASKBAR_LEFT_DCLICK (MyTaskBarIcon::OnLeftButtonDClick) |
d806d30a DS |
130 | EVT_MENU(PU_SUB1, MyTaskBarIcon::OnMenuSub) |
131 | EVT_MENU(PU_SUB2, MyTaskBarIcon::OnMenuSub) | |
69ecd30f RD |
132 | END_EVENT_TABLE() |
133 | ||
a42b93aa | 134 | void MyTaskBarIcon::OnMenuRestore(wxCommandEvent& ) |
69ecd30f | 135 | { |
27301f26 | 136 | dialog->Show(true); |
69ecd30f RD |
137 | } |
138 | ||
a42b93aa | 139 | void MyTaskBarIcon::OnMenuExit(wxCommandEvent& ) |
69ecd30f | 140 | { |
27301f26 | 141 | dialog->Close(true); |
69ecd30f RD |
142 | } |
143 | ||
2afa9fa7 RR |
144 | static bool check = true; |
145 | ||
146 | void MyTaskBarIcon::OnMenuCheckmark(wxCommandEvent& ) | |
147 | { | |
148 | check =!check; | |
149 | } | |
d806d30a | 150 | |
2afa9fa7 RR |
151 | void MyTaskBarIcon::OnMenuUICheckmark(wxUpdateUIEvent &event) |
152 | { | |
153 | event.Check( check ); | |
154 | } | |
155 | ||
ab85e6cd JS |
156 | void MyTaskBarIcon::OnMenuSetNewIcon(wxCommandEvent&) |
157 | { | |
0dc6da2d | 158 | wxIcon icon(smile_xpm); |
ab85e6cd | 159 | |
0dc6da2d | 160 | if (!SetIcon(icon, wxT("wxTaskBarIcon Sample - a different icon"))) |
ab85e6cd | 161 | wxMessageBox(wxT("Could not set new icon.")); |
ab85e6cd | 162 | } |
69ecd30f | 163 | |
d806d30a DS |
164 | void MyTaskBarIcon::OnMenuSetOldIcon(wxCommandEvent&) |
165 | { | |
166 | if (IsIconInstalled()) | |
167 | { | |
168 | RemoveIcon(); | |
169 | } | |
170 | else | |
171 | { | |
172 | wxMessageBox(wxT("wxTaskBarIcon Sample - icon already is the old version")); | |
173 | } | |
174 | } | |
175 | ||
176 | void MyTaskBarIcon::OnMenuSub(wxCommandEvent&) | |
177 | { | |
178 | wxMessageBox(wxT("You clicked on a submenu!")); | |
179 | } | |
180 | ||
bbf1f0e5 | 181 | // Overridables |
dae73d74 | 182 | wxMenu *MyTaskBarIcon::CreatePopupMenu() |
bbf1f0e5 | 183 | { |
d806d30a DS |
184 | // Try creating menus different ways |
185 | // TODO: Probably try calling SetBitmap with some XPMs here | |
dae73d74 | 186 | wxMenu *menu = new wxMenu; |
dae73d74 | 187 | menu->Append(PU_RESTORE, _T("&Restore TBTest")); |
d806d30a DS |
188 | menu->AppendSeparator(); |
189 | menu->Append(PU_OLD_ICON, _T("&Restore Old Icon")); | |
190 | menu->Append(PU_NEW_ICON, _T("&Set New Icon")); | |
191 | menu->AppendSeparator(); | |
192 | menu->Append(PU_CHECKMARK, _T("Checkmark"),wxT(""), wxITEM_CHECK); | |
193 | menu->AppendSeparator(); | |
194 | wxMenu *submenu = new wxMenu; | |
195 | submenu->Append(PU_SUB1, _T("One submenu")); | |
196 | submenu->AppendSeparator(); | |
197 | submenu->Append(PU_SUB2, _T("Another submenu")); | |
198 | menu->Append(PU_SUBMAIN, _T("Submenu"), submenu); | |
199 | #ifndef __WXMAC_OSX__ /*Mac has built-in quit menu*/ | |
200 | menu->AppendSeparator(); | |
dae73d74 | 201 | menu->Append(PU_EXIT, _T("E&xit")); |
d806d30a | 202 | #endif |
dae73d74 | 203 | return menu; |
bbf1f0e5 KB |
204 | } |
205 | ||
329fa151 | 206 | void MyTaskBarIcon::OnLeftButtonDClick(wxTaskBarIconEvent&) |
bbf1f0e5 | 207 | { |
27301f26 | 208 | dialog->Show(true); |
bbf1f0e5 | 209 | } |