]>
Commit | Line | Data |
---|---|---|
2286341c VZ |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: statbar.cpp | |
3 | // Purpose: wxStatusBar sample | |
4 | // Author: Vadim Zeitlin | |
2286341c | 5 | // Created: 04.02.00 |
2286341c VZ |
6 | // Copyright: (c) Vadim Zeitlin |
7 | // Licence: wxWindows licence | |
8 | ///////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | // ============================================================================ | |
11 | // declarations | |
12 | // ============================================================================ | |
13 | ||
14 | // ---------------------------------------------------------------------------- | |
15 | // headers | |
16 | // ---------------------------------------------------------------------------- | |
17 | ||
2286341c VZ |
18 | // For compilers that support precompilation, includes "wx/wx.h". |
19 | #include "wx/wxprec.h" | |
20 | ||
21 | #ifdef __BORLANDC__ | |
22 | #pragma hdrstop | |
23 | #endif | |
24 | ||
25 | #if !wxUSE_STATUSBAR | |
26 | #error "You need to set wxUSE_STATUSBAR to 1 to compile this sample" | |
27 | #endif // wxUSE_STATUSBAR | |
28 | ||
cbc66a27 | 29 | // for all others, include the necessary headers |
2286341c VZ |
30 | #ifndef WX_PRECOMP |
31 | #include "wx/app.h" | |
ee38a8cf | 32 | #include "wx/dcclient.h" |
788233da | 33 | #include "wx/log.h" |
2286341c VZ |
34 | #include "wx/frame.h" |
35 | #include "wx/statusbr.h" | |
2286341c VZ |
36 | #include "wx/timer.h" |
37 | #include "wx/checkbox.h" | |
38 | #include "wx/statbmp.h" | |
39 | #include "wx/menu.h" | |
40 | #include "wx/msgdlg.h" | |
633d67bb | 41 | #include "wx/textdlg.h" |
cbc66a27 | 42 | #include "wx/sizer.h" |
f6c881b4 | 43 | #include "wx/stattext.h" |
f6bcfd97 BP |
44 | #include "wx/bmpbuttn.h" |
45 | #include "wx/dcmemory.h" | |
2286341c VZ |
46 | #endif |
47 | ||
85401ffe | 48 | #include "wx/datetime.h" |
e4f3eb42 | 49 | #include "wx/numdlg.h" |
2a90b100 | 50 | #include "wx/fontdlg.h" |
85401ffe | 51 | |
e7092398 | 52 | #ifndef wxHAS_IMAGES_IN_RESOURCES |
41f02b9a FM |
53 | #include "../sample.xpm" |
54 | #endif | |
55 | ||
ffd0623c | 56 | //#define USE_MDI_PARENT_FRAME 1 |
ffd0623c JS |
57 | #ifdef USE_MDI_PARENT_FRAME |
58 | #include "wx/mdi.h" | |
59 | #endif // USE_MDI_PARENT_FRAME | |
54e18afc | 60 | |
dac831bb | 61 | static const char *SAMPLE_DIALOGS_TITLE = "wxWidgets statbar sample"; |
f6bcfd97 | 62 | |
2286341c VZ |
63 | // ---------------------------------------------------------------------------- |
64 | // resources | |
65 | // ---------------------------------------------------------------------------- | |
66 | ||
5eb65a3b VZ |
67 | #include "green.xpm" |
68 | #include "red.xpm" | |
2286341c VZ |
69 | |
70 | // ---------------------------------------------------------------------------- | |
71 | // private classes | |
72 | // ---------------------------------------------------------------------------- | |
73 | ||
74 | // Define a new application type, each program should derive a class from wxApp | |
75 | class MyApp : public wxApp | |
76 | { | |
77 | public: | |
78 | // override base class virtuals | |
79 | // ---------------------------- | |
80 | ||
81 | // this one is called on application startup and is a good place for the app | |
82 | // initialization (doing it here and not in the ctor allows to have an error | |
83 | // return: if OnInit() returns false, the application terminates) | |
84 | virtual bool OnInit(); | |
85 | }; | |
86 | ||
87 | // A custom status bar which contains controls, icons &c | |
88 | class MyStatusBar : public wxStatusBar | |
89 | { | |
90 | public: | |
c4c178c1 | 91 | MyStatusBar(wxWindow *parent, long style = wxSTB_DEFAULT_STYLE); |
2286341c VZ |
92 | virtual ~MyStatusBar(); |
93 | ||
94 | void UpdateClock(); | |
95 | ||
96 | // event handlers | |
a6ebd559 | 97 | #if wxUSE_TIMER |
d1f47235 | 98 | void OnTimer(wxTimerEvent& WXUNUSED(event)) { UpdateClock(); } |
a6ebd559 | 99 | #endif |
2286341c VZ |
100 | void OnSize(wxSizeEvent& event); |
101 | void OnToggleClock(wxCommandEvent& event); | |
bced985e | 102 | void OnIdle(wxIdleEvent& event); |
2286341c VZ |
103 | |
104 | private: | |
f6bcfd97 BP |
105 | // toggle the state of the status bar controls |
106 | void DoToggle(); | |
107 | ||
2286341c VZ |
108 | enum |
109 | { | |
110 | Field_Text, | |
111 | Field_Checkbox, | |
112 | Field_Bitmap, | |
bced985e | 113 | Field_NumLockIndicator, |
2286341c | 114 | Field_Clock, |
bced985e | 115 | Field_CapsLockIndicator, |
2286341c VZ |
116 | Field_Max |
117 | }; | |
118 | ||
a6ebd559 | 119 | #if wxUSE_TIMER |
633d67bb | 120 | wxTimer m_timer; |
a6ebd559 | 121 | #endif |
2286341c | 122 | |
a6ebd559 | 123 | #if wxUSE_CHECKBOX |
2286341c | 124 | wxCheckBox *m_checkbox; |
a6ebd559 | 125 | #endif |
2286341c VZ |
126 | wxStaticBitmap *m_statbmp; |
127 | ||
128 | DECLARE_EVENT_TABLE() | |
129 | }; | |
130 | ||
131 | // Define a new frame type: this is going to be our main frame | |
06a0d3ea VZ |
132 | #ifdef USE_MDI_PARENT_FRAME |
133 | class MyFrame : public wxMDIParentFrame | |
134 | #else | |
2286341c | 135 | class MyFrame : public wxFrame |
06a0d3ea | 136 | #endif |
2286341c VZ |
137 | { |
138 | public: | |
139 | // ctor(s) | |
140 | MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size); | |
2286341c VZ |
141 | |
142 | // event handlers (these functions should _not_ be virtual) | |
143 | void OnQuit(wxCommandEvent& event); | |
144 | void OnAbout(wxCommandEvent& event); | |
633d67bb | 145 | |
dac831bb VZ |
146 | void OnSetStatusField(wxCommandEvent& event); |
147 | void OnSetStatusText(wxCommandEvent& event); | |
1454b442 VZ |
148 | void OnPushStatusText(wxCommandEvent& event); |
149 | void OnPopStatusText(wxCommandEvent& event); | |
dac831bb | 150 | |
fd3ece57 | 151 | void OnResetFieldsWidth(wxCommandEvent& event); |
ee38a8cf | 152 | void OnShowFieldsRect(wxCommandEvent& event); |
633d67bb | 153 | void OnSetStatusFields(wxCommandEvent& event); |
2a90b100 | 154 | void OnSetStatusFont(wxCommandEvent& event); |
2286341c | 155 | void OnRecreateStatusBar(wxCommandEvent& event); |
41d6e8b6 | 156 | |
c4c178c1 FM |
157 | void OnSetPaneStyle(wxCommandEvent& event); |
158 | void OnSetStyle(wxCommandEvent& event); | |
2286341c VZ |
159 | |
160 | private: | |
c4c178c1 | 161 | enum StatusBarKind |
2286341c VZ |
162 | { |
163 | StatBar_Default, | |
164 | StatBar_Custom, | |
165 | StatBar_Max | |
166 | } m_statbarKind; | |
fd3ece57 | 167 | |
9df6b3b0 | 168 | |
ea6e41e4 | 169 | void OnUpdateForDefaultStatusbar(wxUpdateUIEvent& event); |
ffd0623c | 170 | void OnUpdateStatusBarToggle(wxUpdateUIEvent& event); |
c4c178c1 FM |
171 | void OnUpdateSetPaneStyle(wxUpdateUIEvent& event); |
172 | void OnUpdateSetStyle(wxUpdateUIEvent& event); | |
ffd0623c | 173 | void OnStatusBarToggle(wxCommandEvent& event); |
c4c178c1 FM |
174 | void DoCreateStatusBar(StatusBarKind kind, long style); |
175 | void ApplyPaneStyle(); | |
2286341c | 176 | |
c4c178c1 | 177 | int m_statbarPaneStyle; |
c2919ab3 | 178 | |
dac831bb VZ |
179 | // the index of the field used by some commands |
180 | int m_field; | |
181 | ||
be5a51fb | 182 | // any class wishing to process wxWidgets events must use this macro |
2286341c VZ |
183 | DECLARE_EVENT_TABLE() |
184 | }; | |
185 | ||
cbc66a27 VZ |
186 | // Our about dialog ith its status bar |
187 | class MyAboutDialog : public wxDialog | |
188 | { | |
189 | public: | |
190 | MyAboutDialog(wxWindow *parent); | |
191 | }; | |
192 | ||
2286341c VZ |
193 | // ---------------------------------------------------------------------------- |
194 | // constants | |
195 | // ---------------------------------------------------------------------------- | |
196 | ||
197 | // IDs for the controls and the menu commands | |
198 | enum | |
199 | { | |
200 | // menu items | |
c4c178c1 FM |
201 | StatusBar_Quit = wxID_EXIT, |
202 | StatusBar_About = wxID_ABOUT, | |
41d6e8b6 | 203 | |
c4c178c1 | 204 | StatusBar_SetFields = wxID_HIGHEST+1, |
dac831bb VZ |
205 | StatusBar_SetField, |
206 | StatusBar_SetText, | |
1454b442 VZ |
207 | StatusBar_PushText, |
208 | StatusBar_PopText, | |
2a90b100 | 209 | StatusBar_SetFont, |
fd3ece57 | 210 | StatusBar_ResetFieldsWidth, |
ee38a8cf | 211 | StatusBar_ShowFieldsRect, |
ea6e41e4 | 212 | |
2286341c | 213 | StatusBar_Recreate, |
ffd0623c | 214 | StatusBar_Toggle, |
c4c178c1 FM |
215 | StatusBar_Checkbox, |
216 | StatusBar_SetPaneStyle, | |
217 | StatusBar_SetPaneStyleNormal, | |
218 | StatusBar_SetPaneStyleFlat, | |
219 | StatusBar_SetPaneStyleRaised, | |
98eb2e84 | 220 | StatusBar_SetPaneStyleSunken, |
41d6e8b6 | 221 | |
c4c178c1 FM |
222 | StatusBar_SetStyleSizeGrip, |
223 | StatusBar_SetStyleEllipsizeStart, | |
224 | StatusBar_SetStyleEllipsizeMiddle, | |
225 | StatusBar_SetStyleEllipsizeEnd, | |
226 | StatusBar_SetStyleShowTips | |
2286341c VZ |
227 | }; |
228 | ||
229 | static const int BITMAP_SIZE_X = 32; | |
230 | static const int BITMAP_SIZE_Y = 15; | |
231 | ||
232 | // ---------------------------------------------------------------------------- | |
be5a51fb | 233 | // event tables and other macros for wxWidgets |
2286341c VZ |
234 | // ---------------------------------------------------------------------------- |
235 | ||
be5a51fb | 236 | // the event tables connect the wxWidgets events with the functions (event |
2286341c VZ |
237 | // handlers) which process them. It can be also done at run-time, but for the |
238 | // simple menu events like this the static method is much simpler. | |
ffd0623c JS |
239 | #ifdef USE_MDI_PARENT_FRAME |
240 | BEGIN_EVENT_TABLE(MyFrame, wxMDIParentFrame) | |
241 | #else | |
2286341c | 242 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) |
ffd0623c | 243 | #endif |
2286341c | 244 | EVT_MENU(StatusBar_Quit, MyFrame::OnQuit) |
633d67bb | 245 | EVT_MENU(StatusBar_SetFields, MyFrame::OnSetStatusFields) |
dac831bb VZ |
246 | EVT_MENU(StatusBar_SetField, MyFrame::OnSetStatusField) |
247 | EVT_MENU(StatusBar_SetText, MyFrame::OnSetStatusText) | |
1454b442 VZ |
248 | EVT_MENU(StatusBar_PushText, MyFrame::OnPushStatusText) |
249 | EVT_MENU(StatusBar_PopText, MyFrame::OnPopStatusText) | |
2a90b100 | 250 | EVT_MENU(StatusBar_SetFont, MyFrame::OnSetStatusFont) |
54e18afc | 251 | EVT_MENU(StatusBar_ResetFieldsWidth, MyFrame::OnResetFieldsWidth) |
ee38a8cf | 252 | EVT_MENU(StatusBar_ShowFieldsRect, MyFrame::OnShowFieldsRect) |
2286341c VZ |
253 | EVT_MENU(StatusBar_Recreate, MyFrame::OnRecreateStatusBar) |
254 | EVT_MENU(StatusBar_About, MyFrame::OnAbout) | |
ffd0623c | 255 | EVT_MENU(StatusBar_Toggle, MyFrame::OnStatusBarToggle) |
c4c178c1 FM |
256 | EVT_MENU(StatusBar_SetPaneStyleNormal, MyFrame::OnSetPaneStyle) |
257 | EVT_MENU(StatusBar_SetPaneStyleFlat, MyFrame::OnSetPaneStyle) | |
258 | EVT_MENU(StatusBar_SetPaneStyleRaised, MyFrame::OnSetPaneStyle) | |
98eb2e84 | 259 | EVT_MENU(StatusBar_SetPaneStyleSunken, MyFrame::OnSetPaneStyle) |
41d6e8b6 | 260 | |
c4c178c1 FM |
261 | EVT_MENU(StatusBar_SetStyleSizeGrip, MyFrame::OnSetStyle) |
262 | EVT_MENU(StatusBar_SetStyleEllipsizeStart, MyFrame::OnSetStyle) | |
263 | EVT_MENU(StatusBar_SetStyleEllipsizeMiddle, MyFrame::OnSetStyle) | |
264 | EVT_MENU(StatusBar_SetStyleEllipsizeEnd, MyFrame::OnSetStyle) | |
265 | EVT_MENU(StatusBar_SetStyleShowTips, MyFrame::OnSetStyle) | |
fd3ece57 | 266 | |
ea6e41e4 FM |
267 | EVT_UPDATE_UI_RANGE(StatusBar_SetFields, StatusBar_ResetFieldsWidth, |
268 | MyFrame::OnUpdateForDefaultStatusbar) | |
ffd0623c | 269 | EVT_UPDATE_UI(StatusBar_Toggle, MyFrame::OnUpdateStatusBarToggle) |
06a0d3ea | 270 | EVT_UPDATE_UI_RANGE(StatusBar_SetPaneStyleNormal, |
98eb2e84 | 271 | StatusBar_SetPaneStyleSunken, |
c4c178c1 FM |
272 | MyFrame::OnUpdateSetPaneStyle) |
273 | EVT_UPDATE_UI_RANGE(StatusBar_SetStyleSizeGrip, StatusBar_SetStyleShowTips, | |
274 | MyFrame::OnUpdateSetStyle) | |
2286341c VZ |
275 | END_EVENT_TABLE() |
276 | ||
277 | BEGIN_EVENT_TABLE(MyStatusBar, wxStatusBar) | |
278 | EVT_SIZE(MyStatusBar::OnSize) | |
a6ebd559 | 279 | #if wxUSE_CHECKBOX |
2286341c | 280 | EVT_CHECKBOX(StatusBar_Checkbox, MyStatusBar::OnToggleClock) |
a6ebd559 | 281 | #endif |
a6ebd559 | 282 | #if wxUSE_TIMER |
ee1a622d | 283 | EVT_TIMER(wxID_ANY, MyStatusBar::OnTimer) |
a6ebd559 | 284 | #endif |
bced985e | 285 | EVT_IDLE(MyStatusBar::OnIdle) |
2286341c VZ |
286 | END_EVENT_TABLE() |
287 | ||
be5a51fb | 288 | // Create a new application object: this macro will allow wxWidgets to create |
2286341c VZ |
289 | // the application object during program execution (it's better than using a |
290 | // static object for many reasons) and also declares the accessor function | |
291 | // wxGetApp() which will return the reference of the right type (i.e. MyApp and | |
292 | // not wxApp) | |
293 | IMPLEMENT_APP(MyApp) | |
294 | ||
295 | // ============================================================================ | |
296 | // implementation | |
297 | // ============================================================================ | |
298 | ||
299 | // ---------------------------------------------------------------------------- | |
300 | // the application class | |
301 | // ---------------------------------------------------------------------------- | |
302 | ||
303 | // `Main program' equivalent: the program execution "starts" here | |
304 | bool MyApp::OnInit() | |
305 | { | |
45e6e6f8 VZ |
306 | if ( !wxApp::OnInit() ) |
307 | return false; | |
308 | ||
2286341c | 309 | // create the main application window |
9a83f860 | 310 | MyFrame *frame = new MyFrame(wxT("wxStatusBar sample"), |
06a0d3ea | 311 | wxPoint(50, 50), wxSize(450, 340)); |
2286341c VZ |
312 | |
313 | // and show it (the frames, unlike simple controls, are not shown when | |
314 | // created initially) | |
ee1a622d | 315 | frame->Show(true); |
2286341c VZ |
316 | |
317 | // success: wxApp::OnRun() will be called which will enter the main message | |
ee1a622d | 318 | // loop and the application will run. If we returned 'false' here, the |
2286341c | 319 | // application would exit immediately. |
ee1a622d | 320 | return true; |
2286341c VZ |
321 | } |
322 | ||
323 | // ---------------------------------------------------------------------------- | |
324 | // main frame | |
325 | // ---------------------------------------------------------------------------- | |
326 | ||
327 | // frame constructor | |
328 | MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) | |
ffd0623c | 329 | #ifdef USE_MDI_PARENT_FRAME |
06a0d3ea | 330 | : wxMDIParentFrame(NULL, wxID_ANY, title, pos, size) |
ffd0623c | 331 | #else |
06a0d3ea | 332 | : wxFrame(NULL, wxID_ANY, title, pos, size) |
ffd0623c | 333 | #endif |
2286341c | 334 | { |
41f02b9a FM |
335 | SetIcon(wxICON(sample)); |
336 | ||
c4c178c1 | 337 | m_statbarPaneStyle = wxSB_NORMAL; |
dac831bb | 338 | m_field = 1; |
c2919ab3 | 339 | |
2286341c VZ |
340 | // create a menu bar |
341 | wxMenu *menuFile = new wxMenu; | |
06a0d3ea VZ |
342 | menuFile->Append(StatusBar_Quit, wxT("E&xit\tAlt-X"), |
343 | wxT("Quit this program")); | |
2286341c VZ |
344 | |
345 | wxMenu *statbarMenu = new wxMenu; | |
41d6e8b6 | 346 | |
c4c178c1 | 347 | wxMenu *statbarStyleMenu = new wxMenu; |
06a0d3ea VZ |
348 | statbarStyleMenu->Append(StatusBar_SetStyleSizeGrip, wxT("wxSTB_SIZE_GRIP"), |
349 | wxT("Toggles the wxSTB_SIZE_GRIP style"), true); | |
350 | statbarStyleMenu->Append(StatusBar_SetStyleShowTips, wxT("wxSTB_SHOW_TIPS"), | |
351 | wxT("Toggles the wxSTB_SHOW_TIPS style"), true); | |
c4c178c1 | 352 | statbarStyleMenu->AppendSeparator(); |
06a0d3ea VZ |
353 | statbarStyleMenu->AppendCheckItem(StatusBar_SetStyleEllipsizeStart, |
354 | wxT("wxSTB_ELLIPSIZE_START"), | |
355 | wxT("Toggle wxSTB_ELLIPSIZE_START style")); | |
356 | statbarStyleMenu->AppendCheckItem(StatusBar_SetStyleEllipsizeMiddle, | |
357 | wxT("wxSTB_ELLIPSIZE_MIDDLE"), | |
358 | wxT("Toggle wxSTB_ELLIPSIZE_MIDDLE style")); | |
359 | statbarStyleMenu->AppendCheckItem(StatusBar_SetStyleEllipsizeEnd, | |
360 | wxT("wxSTB_ELLIPSIZE_END"), | |
361 | wxT("Toggle wxSTB_ELLIPSIZE_END style")); | |
362 | statbarMenu->Append(StatusBar_SetPaneStyle, wxT("Status bar style"), | |
363 | statbarStyleMenu); | |
c4c178c1 FM |
364 | statbarMenu->AppendSeparator(); |
365 | ||
dac831bb VZ |
366 | statbarMenu->Append(StatusBar_SetField, "Set active field &number\tCtrl-N", |
367 | "Set the number of field used by the next commands."); | |
368 | statbarMenu->Append(StatusBar_SetText, wxT("Set field &text\tCtrl-T"), | |
369 | wxT("Set the text of the selected field.")); | |
1454b442 VZ |
370 | statbarMenu->Append(StatusBar_PushText, "P&ush field text\tCtrl-P", |
371 | "Push a message on top the selected field."); | |
372 | statbarMenu->Append(StatusBar_PopText, "&Pop field text\tShift-Ctrl-P", | |
373 | "Restore the previous contents of the selected field."); | |
dac831bb VZ |
374 | statbarMenu->AppendSeparator(); |
375 | ||
9a83f860 VZ |
376 | statbarMenu->Append(StatusBar_SetFields, wxT("&Set field count\tCtrl-C"), |
377 | wxT("Set the number of status bar fields")); | |
9a83f860 | 378 | statbarMenu->Append(StatusBar_SetFont, wxT("&Set field font\tCtrl-F"), |
06a0d3ea | 379 | wxT("Set the font to use for status bar fields")); |
2286341c | 380 | |
c4c178c1 | 381 | wxMenu *statbarPaneStyleMenu = new wxMenu; |
06a0d3ea VZ |
382 | statbarPaneStyleMenu->AppendCheckItem |
383 | ( | |
384 | StatusBar_SetPaneStyleNormal, | |
385 | wxT("&Normal"), | |
386 | wxT("Sets the style of the first field to normal (sunken) look") | |
387 | ); | |
388 | statbarPaneStyleMenu->AppendCheckItem | |
389 | ( | |
390 | StatusBar_SetPaneStyleFlat, | |
391 | wxT("&Flat"), | |
392 | wxT("Sets the style of the first field to flat look") | |
393 | ); | |
394 | statbarPaneStyleMenu->AppendCheckItem | |
395 | ( | |
396 | StatusBar_SetPaneStyleRaised, | |
397 | wxT("&Raised"), | |
398 | wxT("Sets the style of the first field to raised look") | |
399 | ); | |
98eb2e84 VZ |
400 | statbarPaneStyleMenu->AppendCheckItem |
401 | ( | |
402 | StatusBar_SetPaneStyleSunken, | |
403 | wxT("&Sunken"), | |
404 | wxT("Sets the style of the first field to sunken look") | |
405 | ); | |
06a0d3ea VZ |
406 | statbarMenu->Append(StatusBar_SetPaneStyle, wxT("Field style"), |
407 | statbarPaneStyleMenu); | |
c2919ab3 | 408 | |
9a83f860 VZ |
409 | statbarMenu->Append(StatusBar_ResetFieldsWidth, wxT("Reset field widths"), |
410 | wxT("Sets all fields to the same width")); | |
ee38a8cf VZ |
411 | statbarMenu->Append(StatusBar_ShowFieldsRect, |
412 | wxT("Sho&w field rectangles\tCtrl-W"), | |
413 | wxT("Visually show field rectangles")); | |
fd3ece57 | 414 | statbarMenu->AppendSeparator(); |
54e18afc | 415 | |
06a0d3ea VZ |
416 | statbarMenu->AppendCheckItem(StatusBar_Toggle, wxT("&Toggle Status Bar"), |
417 | wxT("Toggle the status bar display")); | |
9a83f860 VZ |
418 | statbarMenu->Append(StatusBar_Recreate, wxT("&Recreate\tCtrl-R"), |
419 | wxT("Toggle status bar format")); | |
54e18afc | 420 | |
2286341c | 421 | wxMenu *helpMenu = new wxMenu; |
2d143b66 | 422 | helpMenu->Append(StatusBar_About, wxT("&About\tCtrl-A"), |
06a0d3ea | 423 | wxT("Show about dialog")); |
2286341c VZ |
424 | |
425 | // now append the freshly created menu to the menu bar... | |
426 | wxMenuBar *menuBar = new wxMenuBar(); | |
9a83f860 VZ |
427 | menuBar->Append(menuFile, wxT("&File")); |
428 | menuBar->Append(statbarMenu, wxT("&Status bar")); | |
429 | menuBar->Append(helpMenu, wxT("&Help")); | |
2286341c VZ |
430 | |
431 | // ... and attach this menu bar to the frame | |
432 | SetMenuBar(menuBar); | |
433 | ||
434 | // create default status bar to start with | |
c4c178c1 | 435 | DoCreateStatusBar(StatBar_Default, wxSTB_DEFAULT_STYLE); |
9a83f860 | 436 | SetStatusText(wxT("Welcome to wxWidgets!")); |
2286341c VZ |
437 | } |
438 | ||
c4c178c1 | 439 | void MyFrame::DoCreateStatusBar(MyFrame::StatusBarKind kind, long style) |
2286341c VZ |
440 | { |
441 | wxStatusBar *statbarOld = GetStatusBar(); | |
442 | if ( statbarOld ) | |
443 | { | |
c4c178c1 FM |
444 | SetStatusBar(NULL); |
445 | delete statbarOld; | |
2286341c VZ |
446 | } |
447 | ||
c4c178c1 | 448 | wxStatusBar *statbarNew = NULL; |
2286341c VZ |
449 | switch ( kind ) |
450 | { | |
451 | case StatBar_Default: | |
c4c178c1 FM |
452 | statbarNew = new wxStatusBar(this, wxID_ANY, style, "wxStatusBar"); |
453 | statbarNew->SetFieldsCount(2); | |
2286341c | 454 | break; |
41d6e8b6 | 455 | |
2286341c | 456 | case StatBar_Custom: |
c4c178c1 | 457 | statbarNew = new MyStatusBar(this, style); |
2286341c VZ |
458 | break; |
459 | ||
460 | default: | |
c4c178c1 | 461 | wxFAIL_MSG(wxT("unknown status bar kind")); |
2286341c VZ |
462 | } |
463 | ||
c4c178c1 FM |
464 | SetStatusBar(statbarNew); |
465 | ApplyPaneStyle(); | |
f6bcfd97 | 466 | PositionStatusBar(); |
2286341c VZ |
467 | |
468 | m_statbarKind = kind; | |
469 | } | |
470 | ||
9df6b3b0 FM |
471 | |
472 | // ---------------------------------------------------------------------------- | |
473 | // main frame - event handlers | |
474 | // ---------------------------------------------------------------------------- | |
475 | ||
ea6e41e4 | 476 | void MyFrame::OnUpdateForDefaultStatusbar(wxUpdateUIEvent& event) |
9df6b3b0 | 477 | { |
ea6e41e4 | 478 | // only allow this feature for the default status bar |
9df6b3b0 | 479 | wxStatusBar *sb = GetStatusBar(); |
c4c178c1 FM |
480 | if (!sb) |
481 | return; | |
41d6e8b6 | 482 | |
c4c178c1 | 483 | event.Enable(sb->GetName() == "wxStatusBar"); |
9df6b3b0 FM |
484 | } |
485 | ||
dac831bb | 486 | void MyFrame::OnSetStatusField(wxCommandEvent& WXUNUSED(event)) |
9df6b3b0 FM |
487 | { |
488 | wxStatusBar *sb = GetStatusBar(); | |
c4c178c1 FM |
489 | if (!sb) |
490 | return; | |
9df6b3b0 | 491 | |
dac831bb VZ |
492 | long rc = wxGetNumberFromUser |
493 | ( | |
494 | "Configure the field index to be used by the set, push " | |
495 | "and pop text commands in the menu.\n" | |
496 | "\n" | |
497 | "0 corresponds to the first field, 1 to the second one " | |
498 | "and so on.", | |
499 | "Field &index:", | |
500 | SAMPLE_DIALOGS_TITLE, | |
501 | m_field, | |
502 | 0, | |
503 | sb->GetFieldsCount() - 1, | |
504 | NULL | |
505 | ); | |
506 | ||
507 | if ( rc == -1 ) | |
508 | return; | |
9df6b3b0 | 509 | |
dac831bb VZ |
510 | m_field = rc; |
511 | ||
512 | wxLogStatus("Status bar text will be set for field #%d", m_field); | |
513 | } | |
514 | ||
515 | void MyFrame::OnSetStatusText(wxCommandEvent& WXUNUSED(event)) | |
516 | { | |
517 | wxStatusBar *sb = GetStatusBar(); | |
518 | if (!sb) | |
519 | return; | |
520 | ||
521 | wxString txt = wxGetTextFromUser | |
522 | ( | |
523 | wxString::Format | |
524 | ( | |
525 | "Enter the text from for the field #%d", | |
526 | m_field | |
527 | ), | |
528 | SAMPLE_DIALOGS_TITLE, | |
529 | sb->GetStatusText(m_field), | |
530 | this | |
531 | ); | |
532 | ||
533 | if ( txt.empty() ) | |
534 | return; | |
535 | ||
536 | sb->SetStatusText(txt, m_field); | |
9df6b3b0 FM |
537 | } |
538 | ||
1454b442 VZ |
539 | // the current depth of the stack used by Push/PopStatusText() |
540 | static int gs_depth = 0; | |
541 | ||
542 | void MyFrame::OnPushStatusText(wxCommandEvent& WXUNUSED(event)) | |
543 | { | |
544 | wxStatusBar *sb = GetStatusBar(); | |
545 | if (!sb) | |
546 | return; | |
547 | ||
548 | static int s_countPush = 0; | |
549 | sb->PushStatusText(wxString::Format | |
550 | ( | |
551 | "Pushed message #%d (depth = %d)", | |
552 | ++s_countPush, ++gs_depth | |
553 | ), m_field); | |
554 | } | |
555 | ||
556 | void MyFrame::OnPopStatusText(wxCommandEvent& WXUNUSED(event)) | |
557 | { | |
558 | wxStatusBar *sb = GetStatusBar(); | |
559 | if (!sb) | |
560 | return; | |
561 | ||
562 | if ( !gs_depth ) | |
563 | { | |
564 | wxLogStatus("No message to pop."); | |
565 | return; | |
566 | } | |
567 | ||
568 | gs_depth--; | |
569 | sb->PopStatusText(m_field); | |
570 | } | |
571 | ||
2a90b100 FM |
572 | void MyFrame::OnSetStatusFont(wxCommandEvent& WXUNUSED(event)) |
573 | { | |
574 | wxStatusBar *sb = GetStatusBar(); | |
c4c178c1 FM |
575 | if (!sb) |
576 | return; | |
2a90b100 | 577 | |
06a0d3ea VZ |
578 | wxFont |
579 | fnt = wxGetFontFromUser(this, sb->GetFont(), "Choose status bar font"); | |
2a90b100 FM |
580 | if (fnt.IsOk()) |
581 | { | |
582 | sb->SetFont(fnt); | |
583 | sb->SetSize(sb->GetBestSize()); | |
584 | } | |
585 | } | |
586 | ||
633d67bb VZ |
587 | void MyFrame::OnSetStatusFields(wxCommandEvent& WXUNUSED(event)) |
588 | { | |
589 | wxStatusBar *sb = GetStatusBar(); | |
c4c178c1 FM |
590 | if (!sb) |
591 | return; | |
633d67bb VZ |
592 | |
593 | long nFields = wxGetNumberFromUser | |
fd3ece57 | 594 | ( |
9a83f860 VZ |
595 | wxT("Select the number of fields in the status bar"), |
596 | wxT("Fields:"), | |
dac831bb | 597 | SAMPLE_DIALOGS_TITLE, |
633d67bb VZ |
598 | sb->GetFieldsCount(), |
599 | 1, 5, | |
600 | this | |
fd3ece57 | 601 | ); |
633d67bb VZ |
602 | |
603 | // we don't check if the number changed at all on purpose: calling | |
604 | // SetFieldsCount() with the same number of fields should be ok | |
605 | if ( nFields != -1 ) | |
606 | { | |
71e03035 VZ |
607 | static const int widthsFor2Fields[] = { 200, -1 }; |
608 | static const int widthsFor3Fields[] = { -1, -2, -1 }; | |
609 | static const int widthsFor4Fields[] = { 100, -1, 100, -2, 100 }; | |
610 | ||
bf69498a | 611 | static const int *widthsAll[] = |
633d67bb | 612 | { |
71e03035 VZ |
613 | NULL, // 1 field: default |
614 | widthsFor2Fields, // 2 fields: 1 fixed, 1 var | |
615 | widthsFor3Fields, // 3 fields: 3 var | |
616 | widthsFor4Fields, // 4 fields: 3 fixed, 2 vars | |
617 | NULL // 5 fields: default (all have same width) | |
618 | }; | |
633d67bb | 619 | |
bf69498a VZ |
620 | const int * const widths = widthsAll[nFields - 1]; |
621 | sb->SetFieldsCount(nFields, widths); | |
633d67bb | 622 | |
bf69498a VZ |
623 | wxString s; |
624 | for ( long n = 0; n < nFields; n++ ) | |
625 | { | |
626 | if ( widths ) | |
627 | { | |
628 | if ( widths[n] > 0 ) | |
9a83f860 | 629 | s.Printf(wxT("fixed (%d)"), widths[n]); |
bf69498a | 630 | else |
9a83f860 | 631 | s.Printf(wxT("variable (*%d)"), -widths[n]); |
bf69498a VZ |
632 | } |
633 | else | |
634 | { | |
9a83f860 | 635 | s = wxT("default"); |
bf69498a VZ |
636 | } |
637 | ||
638 | SetStatusText(s, n); | |
639 | } | |
dac831bb VZ |
640 | |
641 | if ( m_field >= nFields ) | |
642 | m_field = nFields - 1; | |
633d67bb VZ |
643 | } |
644 | else | |
645 | { | |
4693b20c | 646 | wxLogStatus(this, wxT("Cancelled")); |
633d67bb VZ |
647 | } |
648 | } | |
649 | ||
54e18afc FM |
650 | void MyFrame::OnResetFieldsWidth(wxCommandEvent& WXUNUSED(event)) |
651 | { | |
fd3ece57 | 652 | wxStatusBar *pStat = GetStatusBar(); |
06a0d3ea | 653 | if ( !pStat ) |
c4c178c1 | 654 | return; |
41d6e8b6 | 655 | |
06a0d3ea | 656 | const int n = pStat->GetFieldsCount(); |
c4c178c1 | 657 | pStat->SetStatusWidths(n, NULL); |
06a0d3ea | 658 | for ( int i = 0; i < n; i++ ) |
c4c178c1 | 659 | pStat->SetStatusText("same size", i); |
54e18afc FM |
660 | } |
661 | ||
ee38a8cf VZ |
662 | void MyFrame::OnShowFieldsRect(wxCommandEvent& WXUNUSED(event)) |
663 | { | |
664 | wxStatusBar *pStat = GetStatusBar(); | |
665 | if ( !pStat ) | |
666 | return; | |
667 | ||
668 | wxClientDC dc(pStat); | |
669 | dc.SetPen(*wxRED_PEN); | |
670 | dc.SetBrush(*wxTRANSPARENT_BRUSH); | |
671 | ||
672 | const int n = pStat->GetFieldsCount(); | |
673 | for ( int i = 0; i < n; i++ ) | |
674 | { | |
675 | wxRect r; | |
676 | if ( pStat->GetFieldRect(i, r) ) | |
677 | dc.DrawRectangle(r); | |
678 | } | |
679 | } | |
680 | ||
ffd0623c JS |
681 | void MyFrame::OnUpdateStatusBarToggle(wxUpdateUIEvent& event) |
682 | { | |
2dcd83af | 683 | event.Check(GetStatusBar() != NULL); |
ffd0623c JS |
684 | } |
685 | ||
686 | void MyFrame::OnStatusBarToggle(wxCommandEvent& WXUNUSED(event)) | |
687 | { | |
688 | wxStatusBar *statbarOld = GetStatusBar(); | |
689 | if ( statbarOld ) | |
690 | { | |
2dcd83af | 691 | SetStatusBar(NULL); |
c4c178c1 | 692 | delete statbarOld; |
ffd0623c JS |
693 | } |
694 | else | |
695 | { | |
c4c178c1 | 696 | DoCreateStatusBar(m_statbarKind, wxSTB_DEFAULT_STYLE); |
ffd0623c | 697 | } |
ffd0623c JS |
698 | } |
699 | ||
2286341c VZ |
700 | void MyFrame::OnRecreateStatusBar(wxCommandEvent& WXUNUSED(event)) |
701 | { | |
702 | DoCreateStatusBar(m_statbarKind == StatBar_Custom ? StatBar_Default | |
c4c178c1 FM |
703 | : StatBar_Custom, |
704 | wxSTB_DEFAULT_STYLE); | |
2286341c VZ |
705 | } |
706 | ||
707 | void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) | |
708 | { | |
ee1a622d WS |
709 | // true is to force the frame to close |
710 | Close(true); | |
2286341c VZ |
711 | } |
712 | ||
713 | void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) | |
714 | { | |
cbc66a27 VZ |
715 | MyAboutDialog dlg(this); |
716 | dlg.ShowModal(); | |
717 | } | |
718 | ||
c4c178c1 | 719 | void MyFrame::OnUpdateSetPaneStyle(wxUpdateUIEvent& event) |
c2919ab3 | 720 | { |
c4c178c1 FM |
721 | switch (event.GetId()) |
722 | { | |
723 | case StatusBar_SetPaneStyleNormal: | |
724 | event.Check(m_statbarPaneStyle == wxSB_NORMAL); | |
725 | break; | |
726 | case StatusBar_SetPaneStyleFlat: | |
727 | event.Check(m_statbarPaneStyle == wxSB_FLAT); | |
728 | break; | |
729 | case StatusBar_SetPaneStyleRaised: | |
730 | event.Check(m_statbarPaneStyle == wxSB_RAISED); | |
731 | break; | |
98eb2e84 VZ |
732 | case StatusBar_SetPaneStyleSunken: |
733 | event.Check(m_statbarPaneStyle == wxSB_SUNKEN); | |
734 | break; | |
c4c178c1 | 735 | } |
c2919ab3 VZ |
736 | } |
737 | ||
c4c178c1 | 738 | void MyFrame::OnSetPaneStyle(wxCommandEvent& event) |
c2919ab3 | 739 | { |
c4c178c1 FM |
740 | switch (event.GetId()) |
741 | { | |
742 | case StatusBar_SetPaneStyleNormal: | |
743 | m_statbarPaneStyle = wxSB_NORMAL; | |
744 | break; | |
745 | case StatusBar_SetPaneStyleFlat: | |
746 | m_statbarPaneStyle = wxSB_FLAT; | |
747 | break; | |
748 | case StatusBar_SetPaneStyleRaised: | |
749 | m_statbarPaneStyle = wxSB_RAISED; | |
750 | break; | |
98eb2e84 VZ |
751 | case StatusBar_SetPaneStyleSunken: |
752 | m_statbarPaneStyle = wxSB_SUNKEN; | |
753 | break; | |
c4c178c1 | 754 | } |
41d6e8b6 | 755 | |
c4c178c1 | 756 | ApplyPaneStyle(); |
c2919ab3 VZ |
757 | } |
758 | ||
c4c178c1 | 759 | void MyFrame::ApplyPaneStyle() |
c2919ab3 VZ |
760 | { |
761 | wxStatusBar *sb = GetStatusBar(); | |
c4c178c1 FM |
762 | if (!sb) |
763 | return; | |
41d6e8b6 | 764 | |
c2919ab3 VZ |
765 | int fields = sb->GetFieldsCount(); |
766 | int *styles = new int[fields]; | |
767 | ||
768 | for (int i = 1; i < fields; i++) | |
769 | styles[i] = wxSB_NORMAL; | |
770 | ||
c4c178c1 | 771 | styles[0] = m_statbarPaneStyle; |
c2919ab3 VZ |
772 | |
773 | sb->SetStatusStyles(fields, styles); | |
774 | ||
775 | delete [] styles; | |
776 | } | |
777 | ||
c4c178c1 FM |
778 | void MyFrame::OnUpdateSetStyle(wxUpdateUIEvent& event) |
779 | { | |
780 | long currentStyle = wxSTB_DEFAULT_STYLE; | |
781 | if (GetStatusBar()) | |
782 | currentStyle = GetStatusBar()->GetWindowStyle(); | |
783 | ||
784 | switch (event.GetId()) | |
785 | { | |
786 | case StatusBar_SetStyleSizeGrip: | |
787 | event.Check((currentStyle & wxSTB_SIZEGRIP) != 0); | |
788 | break; | |
789 | case StatusBar_SetStyleShowTips: | |
790 | event.Check((currentStyle & wxSTB_SHOW_TIPS) != 0); | |
791 | break; | |
792 | ||
793 | case StatusBar_SetStyleEllipsizeStart: | |
794 | event.Check((currentStyle & wxSTB_ELLIPSIZE_START) != 0); | |
795 | break; | |
796 | case StatusBar_SetStyleEllipsizeMiddle: | |
797 | event.Check((currentStyle & wxSTB_ELLIPSIZE_MIDDLE) != 0); | |
798 | break; | |
799 | case StatusBar_SetStyleEllipsizeEnd: | |
800 | event.Check((currentStyle & wxSTB_ELLIPSIZE_END) != 0); | |
801 | break; | |
802 | } | |
803 | } | |
804 | ||
805 | void MyFrame::OnSetStyle(wxCommandEvent& event) | |
806 | { | |
807 | long oldStyle = wxSTB_DEFAULT_STYLE; | |
808 | if (GetStatusBar()) | |
809 | oldStyle = GetStatusBar()->GetWindowStyle(); | |
810 | ||
06a0d3ea VZ |
811 | #define STB_ELLIPSIZE_MASK \ |
812 | (wxSTB_ELLIPSIZE_START|wxSTB_ELLIPSIZE_MIDDLE|wxSTB_ELLIPSIZE_END) | |
41d6e8b6 | 813 | |
c4c178c1 FM |
814 | long newStyle = oldStyle; |
815 | long newStyleBit = 0; | |
816 | switch (event.GetId()) | |
817 | { | |
818 | case StatusBar_SetStyleSizeGrip: | |
819 | newStyleBit = wxSTB_SIZEGRIP; | |
820 | break; | |
821 | case StatusBar_SetStyleShowTips: | |
822 | newStyleBit = wxSTB_SHOW_TIPS; | |
823 | break; | |
824 | ||
825 | case StatusBar_SetStyleEllipsizeStart: | |
826 | newStyleBit = wxSTB_ELLIPSIZE_START; | |
827 | newStyle &= ~STB_ELLIPSIZE_MASK; | |
828 | break; | |
829 | case StatusBar_SetStyleEllipsizeMiddle: | |
830 | newStyleBit = wxSTB_ELLIPSIZE_MIDDLE; | |
831 | newStyle &= ~STB_ELLIPSIZE_MASK; | |
832 | break; | |
833 | case StatusBar_SetStyleEllipsizeEnd: | |
834 | newStyleBit = wxSTB_ELLIPSIZE_END; | |
835 | newStyle &= ~STB_ELLIPSIZE_MASK; | |
836 | break; | |
837 | } | |
41d6e8b6 | 838 | |
c4c178c1 FM |
839 | newStyle = event.IsChecked() ? (newStyle | newStyleBit) : |
840 | (newStyle & ~newStyleBit); | |
841 | if (newStyle != oldStyle) | |
842 | { | |
843 | DoCreateStatusBar(m_statbarKind, newStyle); | |
844 | SetStatusText("Status bar recreated with a new style"); | |
845 | } | |
846 | } | |
847 | ||
cbc66a27 VZ |
848 | // ---------------------------------------------------------------------------- |
849 | // MyAboutDialog | |
850 | // ---------------------------------------------------------------------------- | |
851 | ||
852 | MyAboutDialog::MyAboutDialog(wxWindow *parent) | |
9a83f860 | 853 | : wxDialog(parent, wxID_ANY, wxString(wxT("About statbar")), |
cbc66a27 VZ |
854 | wxDefaultPosition, wxDefaultSize, |
855 | wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) | |
856 | { | |
ee1a622d | 857 | wxStaticText *text = new wxStaticText(this, wxID_ANY, |
9a83f860 VZ |
858 | wxT("wxStatusBar sample\n") |
859 | wxT("(c) 2000 Vadim Zeitlin")); | |
cbc66a27 | 860 | |
9a83f860 | 861 | wxButton *btn = new wxButton(this, wxID_OK, wxT("&Close")); |
a1a43961 | 862 | |
8b8bff20 VZ |
863 | // create the top status bar without the size grip (default style), |
864 | // otherwise it looks weird | |
ee1a622d | 865 | wxStatusBar *statbarTop = new wxStatusBar(this, wxID_ANY, 0); |
8b8bff20 | 866 | statbarTop->SetFieldsCount(3); |
9a83f860 VZ |
867 | statbarTop->SetStatusText(wxT("This is a top status bar"), 0); |
868 | statbarTop->SetStatusText(wxT("in a dialog"), 1); | |
869 | statbarTop->SetStatusText(wxT("Great, isn't it?"), 2); | |
8b8bff20 | 870 | |
ee1a622d | 871 | wxStatusBar *statbarBottom = new wxStatusBar(this, wxID_ANY); |
8b8bff20 | 872 | statbarBottom->SetFieldsCount(2); |
9a83f860 VZ |
873 | statbarBottom->SetStatusText(wxT("This is a bottom status bar"), 0); |
874 | statbarBottom->SetStatusText(wxT("in a dialog"), 1); | |
cbc66a27 VZ |
875 | |
876 | wxBoxSizer *sizerTop = new wxBoxSizer(wxVERTICAL); | |
8b8bff20 | 877 | sizerTop->Add(statbarTop, 0, wxGROW); |
cbc66a27 | 878 | sizerTop->Add(-1, 10, 1, wxGROW); |
a1a43961 VZ |
879 | sizerTop->Add(text, 0, wxCENTRE | wxRIGHT | wxLEFT, 20); |
880 | sizerTop->Add(-1, 10, 1, wxGROW); | |
881 | sizerTop->Add(btn, 0, wxCENTRE | wxRIGHT | wxLEFT, 20); | |
cbc66a27 | 882 | sizerTop->Add(-1, 10, 1, wxGROW); |
8b8bff20 | 883 | sizerTop->Add(statbarBottom, 0, wxGROW); |
cbc66a27 | 884 | |
92c01615 | 885 | SetSizerAndFit(sizerTop); |
2286341c VZ |
886 | } |
887 | ||
888 | // ---------------------------------------------------------------------------- | |
889 | // MyStatusBar | |
890 | // ---------------------------------------------------------------------------- | |
891 | ||
85401ffe VZ |
892 | #ifdef __VISUALC__ |
893 | // 'this' : used in base member initializer list -- so what?? | |
894 | #pragma warning(disable: 4355) | |
895 | #endif | |
896 | ||
bced985e VZ |
897 | static const char *numlockIndicators[] = { "OFF", "NUM" }; |
898 | static const char *capslockIndicators[] = { "", "CAPS" }; | |
899 | ||
c4c178c1 FM |
900 | MyStatusBar::MyStatusBar(wxWindow *parent, long style) |
901 | : wxStatusBar(parent, wxID_ANY, style, "MyStatusBar") | |
a6ebd559 | 902 | #if wxUSE_TIMER |
fd3ece57 | 903 | , m_timer(this) |
a6ebd559 WS |
904 | #endif |
905 | #if wxUSE_CHECKBOX | |
fd3ece57 | 906 | , m_checkbox(NULL) |
a6ebd559 | 907 | #endif |
2286341c | 908 | { |
bced985e VZ |
909 | // compute the size needed for num lock indicator pane |
910 | wxClientDC dc(this); | |
911 | wxSize sizeNumLock = dc.GetTextExtent(numlockIndicators[0]); | |
912 | sizeNumLock.IncTo(dc.GetTextExtent(numlockIndicators[1])); | |
913 | ||
914 | int widths[Field_Max]; | |
915 | widths[Field_Text] = -1; // growable | |
916 | widths[Field_Checkbox] = 150; | |
917 | widths[Field_Bitmap] = BITMAP_SIZE_X; | |
918 | widths[Field_NumLockIndicator] = sizeNumLock.x; | |
919 | widths[Field_Clock] = 100; | |
920 | widths[Field_CapsLockIndicator] = dc.GetTextExtent(capslockIndicators[1]).x; | |
2286341c VZ |
921 | |
922 | SetFieldsCount(Field_Max); | |
923 | SetStatusWidths(Field_Max, widths); | |
924 | ||
a6ebd559 | 925 | #if wxUSE_CHECKBOX |
9a83f860 | 926 | m_checkbox = new wxCheckBox(this, StatusBar_Checkbox, wxT("&Toggle clock")); |
ee1a622d | 927 | m_checkbox->SetValue(true); |
a6ebd559 | 928 | #endif |
2286341c | 929 | |
ee1a622d | 930 | m_statbmp = new wxStaticBitmap(this, wxID_ANY, wxIcon(green_xpm)); |
2286341c | 931 | |
a6ebd559 | 932 | #if wxUSE_TIMER |
2286341c | 933 | m_timer.Start(1000); |
a6ebd559 | 934 | #endif |
2286341c | 935 | |
fd3ece57 FM |
936 | SetMinHeight(wxMax(m_statbmp->GetBestSize().GetHeight(), |
937 | m_checkbox->GetBestSize().GetHeight())); | |
85401ffe | 938 | |
2286341c VZ |
939 | UpdateClock(); |
940 | } | |
941 | ||
85401ffe VZ |
942 | #ifdef __VISUALC__ |
943 | #pragma warning(default: 4355) | |
944 | #endif | |
945 | ||
2286341c VZ |
946 | MyStatusBar::~MyStatusBar() |
947 | { | |
a6ebd559 | 948 | #if wxUSE_TIMER |
2286341c VZ |
949 | if ( m_timer.IsRunning() ) |
950 | { | |
951 | m_timer.Stop(); | |
952 | } | |
a6ebd559 | 953 | #endif |
2286341c VZ |
954 | } |
955 | ||
956 | void MyStatusBar::OnSize(wxSizeEvent& event) | |
957 | { | |
a6ebd559 | 958 | #if wxUSE_CHECKBOX |
f6bcfd97 BP |
959 | if ( !m_checkbox ) |
960 | return; | |
a6ebd559 | 961 | #endif |
f6bcfd97 | 962 | |
2286341c | 963 | wxRect rect; |
ea6e41e4 FM |
964 | if (!GetFieldRect(Field_Checkbox, rect)) |
965 | { | |
966 | event.Skip(); | |
967 | return; | |
968 | } | |
2286341c | 969 | |
a6ebd559 | 970 | #if wxUSE_CHECKBOX |
06a0d3ea VZ |
971 | wxRect rectCheck = rect; |
972 | rectCheck.Deflate(2); | |
973 | m_checkbox->SetSize(rectCheck); | |
a6ebd559 | 974 | #endif |
2286341c VZ |
975 | |
976 | GetFieldRect(Field_Bitmap, rect); | |
f6bcfd97 | 977 | wxSize size = m_statbmp->GetSize(); |
f6bcfd97 BP |
978 | |
979 | m_statbmp->Move(rect.x + (rect.width - size.x) / 2, | |
980 | rect.y + (rect.height - size.y) / 2); | |
2286341c VZ |
981 | |
982 | event.Skip(); | |
983 | } | |
984 | ||
f6bcfd97 BP |
985 | void MyStatusBar::OnToggleClock(wxCommandEvent& WXUNUSED(event)) |
986 | { | |
987 | DoToggle(); | |
988 | } | |
989 | ||
bced985e VZ |
990 | void MyStatusBar::OnIdle(wxIdleEvent& event) |
991 | { | |
992 | SetStatusText(numlockIndicators[wxGetKeyState(WXK_NUMLOCK)], | |
993 | Field_NumLockIndicator); | |
994 | SetStatusText(capslockIndicators[wxGetKeyState(WXK_CAPITAL)], | |
995 | Field_CapsLockIndicator); | |
996 | ||
997 | event.Skip(); | |
998 | } | |
999 | ||
f6bcfd97 | 1000 | void MyStatusBar::DoToggle() |
2286341c | 1001 | { |
a6ebd559 | 1002 | #if wxUSE_CHECKBOX |
2286341c VZ |
1003 | if ( m_checkbox->GetValue() ) |
1004 | { | |
a6ebd559 | 1005 | #if wxUSE_TIMER |
2286341c | 1006 | m_timer.Start(1000); |
a6ebd559 | 1007 | #endif |
2286341c | 1008 | |
85401ffe | 1009 | m_statbmp->SetIcon(wxIcon(green_xpm)); |
2286341c VZ |
1010 | |
1011 | UpdateClock(); | |
1012 | } | |
1013 | else // don't show clock | |
1014 | { | |
a6ebd559 | 1015 | #if wxUSE_TIMER |
2286341c | 1016 | m_timer.Stop(); |
a6ebd559 | 1017 | #endif |
2286341c | 1018 | |
85401ffe | 1019 | m_statbmp->SetIcon(wxIcon(red_xpm)); |
2286341c | 1020 | |
dabbc6a5 | 1021 | SetStatusText(wxEmptyString, Field_Clock); |
2286341c | 1022 | } |
5eb65a3b | 1023 | #endif // wxUSE_CHECKBOX |
2286341c VZ |
1024 | } |
1025 | ||
1026 | void MyStatusBar::UpdateClock() | |
1027 | { | |
1028 | SetStatusText(wxDateTime::Now().FormatTime(), Field_Clock); | |
1029 | } |