]> git.saurik.com Git - wxWidgets.git/blob - samples/taskbar/tbtest.cpp
remove unneeded dependencies from bakefiles and regenerate the make/project files...
[wxWidgets.git] / samples / taskbar / tbtest.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: tbtest.cpp
3 // Purpose: wxTaskBarIcon demo
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c)
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #ifndef WX_PRECOMP
28 #include "wx/wx.h"
29 #endif
30
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"
34 #endif
35
36 #include "smile.xpm"
37
38 #include "wx/taskbar.h"
39
40 #include "tbtest.h"
41
42 // ----------------------------------------------------------------------------
43 // global variables
44 // ----------------------------------------------------------------------------
45
46 static MyDialog *gs_dialog = NULL;
47
48 // ============================================================================
49 // implementation
50 // ============================================================================
51
52 // ----------------------------------------------------------------------------
53 // MyApp
54 // ----------------------------------------------------------------------------
55
56 IMPLEMENT_APP(MyApp)
57
58 bool MyApp::OnInit()
59 {
60 if ( !wxApp::OnInit() )
61 return false;
62
63 // Create the main window
64 gs_dialog = new MyDialog(wxT("wxTaskBarIcon Test Dialog"));
65
66 gs_dialog->Show(true);
67
68 return true;
69 }
70
71
72 // ----------------------------------------------------------------------------
73 // MyDialog implementation
74 // ----------------------------------------------------------------------------
75
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)
81 END_EVENT_TABLE()
82
83
84 MyDialog::MyDialog(const wxString& title)
85 : wxDialog(NULL, wxID_ANY, title)
86 {
87 wxSizer * const sizerTop = new wxBoxSizer(wxVERTICAL);
88
89 wxSizerFlags flags;
90 flags.Border(wxALL, 10);
91
92 sizerTop->Add(new wxStaticText
93 (
94 this,
95 wxID_ANY,
96 _T("Press 'Hide me' to hide this window, Exit to quit.")
97 ), flags);
98
99 sizerTop->Add(new wxStaticText
100 (
101 this,
102 wxID_ANY,
103 _T("Double-click on the taskbar icon to show me again.")
104 ), flags);
105
106 sizerTop->AddStretchSpacer()->SetMinSize(200, 50);
107
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);
112
113 sizerTop->Add(sizerBtns, flags.Align(wxALIGN_CENTER_HORIZONTAL));
114 SetSizerAndFit(sizerTop);
115 Centre();
116
117 m_taskBarIcon = new MyTaskBarIcon();
118 #if defined(__WXCOCOA__)
119 m_dockIcon = new MyTaskBarIcon(wxTaskBarIcon::DOCK);
120 #endif
121
122 // we should be able to show up to 128 characters on recent Windows versions
123 // (and 64 on Win9x)
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.") )
129 {
130 wxLogError(wxT("Could not set icon."));
131 }
132 }
133
134 MyDialog::~MyDialog()
135 {
136 delete m_taskBarIcon;
137 #if defined(__WXCOCOA__)
138 delete m_dockIcon;
139 #endif
140 }
141
142 void MyDialog::OnAbout(wxCommandEvent& WXUNUSED(event))
143 {
144 static const char * const title = "About wxWidgets Taskbar Sample";
145 static const char * const message
146 = "wxWidgets sample showing wxTaskBarIcon class\n"
147 "\n"
148 "(C) 1997 Julian Smart\n"
149 "(C) 2007 Vadim Zeitlin";
150
151 #if defined(__WXMSW__) && wxUSE_TASKBARICON_BALLOONS
152 m_taskBarIcon->ShowBalloon(title, message, 15000, wxICON_INFORMATION);
153 #else // !__WXMSW__
154 wxMessageBox(message, title, wxICON_INFORMATION, this);
155 #endif // __WXMSW__/!__WXMSW__
156 }
157
158 void MyDialog::OnOK(wxCommandEvent& WXUNUSED(event))
159 {
160 Show(false);
161 }
162
163 void MyDialog::OnExit(wxCommandEvent& WXUNUSED(event))
164 {
165 Close(true);
166 }
167
168 void MyDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
169 {
170 Destroy();
171 }
172
173
174 // ----------------------------------------------------------------------------
175 // MyTaskBarIcon implementation
176 // ----------------------------------------------------------------------------
177
178 enum
179 {
180 PU_RESTORE = 10001,
181 PU_NEW_ICON,
182 PU_EXIT,
183 PU_CHECKMARK,
184 PU_SUB1,
185 PU_SUB2,
186 PU_SUBMAIN
187 };
188
189
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)
199 END_EVENT_TABLE()
200
201 void MyTaskBarIcon::OnMenuRestore(wxCommandEvent& )
202 {
203 gs_dialog->Show(true);
204 }
205
206 void MyTaskBarIcon::OnMenuExit(wxCommandEvent& )
207 {
208 gs_dialog->Close(true);
209 }
210
211 static bool check = true;
212
213 void MyTaskBarIcon::OnMenuCheckmark(wxCommandEvent& )
214 {
215 check = !check;
216 }
217
218 void MyTaskBarIcon::OnMenuUICheckmark(wxUpdateUIEvent &event)
219 {
220 event.Check(check);
221 }
222
223 void MyTaskBarIcon::OnMenuSetNewIcon(wxCommandEvent&)
224 {
225 wxIcon icon(smile_xpm);
226
227 if (!SetIcon(icon, wxT("wxTaskBarIcon Sample - a different icon")))
228 wxMessageBox(wxT("Could not set new icon."));
229 }
230
231 void MyTaskBarIcon::OnMenuSub(wxCommandEvent&)
232 {
233 wxMessageBox(wxT("You clicked on a submenu!"));
234 }
235
236 // Overridables
237 wxMenu *MyTaskBarIcon::CreatePopupMenu()
238 {
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"));
254 #endif
255 return menu;
256 }
257
258 void MyTaskBarIcon::OnLeftButtonDClick(wxTaskBarIconEvent&)
259 {
260 gs_dialog->Show(true);
261 }