]> git.saurik.com Git - wxWidgets.git/blob - samples/statbar/statbar.cpp
Order of initializations according to class construction.
[wxWidgets.git] / samples / statbar / statbar.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: statbar.cpp
3 // Purpose: wxStatusBar sample
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 04.02.00
7 // RCS-ID: $Id$
8 // Copyright: (c) Vadim Zeitlin
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx/wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #if !wxUSE_STATUSBAR
28 #error "You need to set wxUSE_STATUSBAR to 1 to compile this sample"
29 #endif // wxUSE_STATUSBAR
30
31 // for all others, include the necessary headers
32 #ifndef WX_PRECOMP
33 #include "wx/app.h"
34 #include "wx/log.h"
35 #include "wx/frame.h"
36 #include "wx/statusbr.h"
37 #include "wx/timer.h"
38 #include "wx/checkbox.h"
39 #include "wx/statbmp.h"
40 #include "wx/menu.h"
41 #include "wx/msgdlg.h"
42 #include "wx/textdlg.h"
43 #include "wx/sizer.h"
44 #include "wx/stattext.h"
45 #include "wx/bmpbuttn.h"
46 #include "wx/dcmemory.h"
47 #endif
48
49 #include "wx/datetime.h"
50 #include "wx/numdlg.h"
51
52 // define this for the platforms which don't support wxBitmapButton (such as
53 // Motif), else a wxBitmapButton will be used
54 #ifdef __WXMOTIF__
55 //#define USE_MDI_PARENT_FRAME 1
56
57 #ifdef USE_MDI_PARENT_FRAME
58 #include "wx/mdi.h"
59 #endif // USE_MDI_PARENT_FRAME
60 #define USE_STATIC_BITMAP
61 #endif
62
63 // ----------------------------------------------------------------------------
64 // resources
65 // ----------------------------------------------------------------------------
66
67 #ifdef USE_STATIC_BITMAP
68 #include "green.xpm"
69 #include "red.xpm"
70 #endif // USE_STATIC_BITMAP
71
72 // ----------------------------------------------------------------------------
73 // private classes
74 // ----------------------------------------------------------------------------
75
76 // Define a new application type, each program should derive a class from wxApp
77 class MyApp : public wxApp
78 {
79 public:
80 // override base class virtuals
81 // ----------------------------
82
83 // this one is called on application startup and is a good place for the app
84 // initialization (doing it here and not in the ctor allows to have an error
85 // return: if OnInit() returns false, the application terminates)
86 virtual bool OnInit();
87 };
88
89 // A custom status bar which contains controls, icons &c
90 class MyStatusBar : public wxStatusBar
91 {
92 public:
93 MyStatusBar(wxWindow *parent);
94 virtual ~MyStatusBar();
95
96 void UpdateClock();
97
98 // event handlers
99 void OnTimer(wxTimerEvent& WXUNUSED(event)) { UpdateClock(); }
100 void OnSize(wxSizeEvent& event);
101 void OnToggleClock(wxCommandEvent& event);
102 void OnButton(wxCommandEvent& event);
103
104 private:
105 // toggle the state of the status bar controls
106 void DoToggle();
107
108 wxBitmap CreateBitmapForButton(bool on = false);
109
110 enum
111 {
112 Field_Text,
113 Field_Checkbox,
114 Field_Bitmap,
115 Field_Clock,
116 Field_Max
117 };
118
119 wxTimer m_timer;
120
121 wxCheckBox *m_checkbox;
122 #ifdef USE_STATIC_BITMAP
123 wxStaticBitmap *m_statbmp;
124 #else
125 wxBitmapButton *m_statbmp;
126 #endif
127
128 DECLARE_EVENT_TABLE()
129 };
130
131 // Define a new frame type: this is going to be our main frame
132 class MyFrame : public wxFrame
133 {
134 public:
135 // ctor(s)
136 MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
137 #ifdef USE_MDI_PARENT_FRAME
138 class MyFrame : public wxMDIParentFrame
139 #else
140 virtual ~MyFrame();
141 #endif
142
143 // event handlers (these functions should _not_ be virtual)
144 void OnQuit(wxCommandEvent& event);
145 void OnAbout(wxCommandEvent& event);
146
147 void OnSetStatusFields(wxCommandEvent& event);
148 void OnRecreateStatusBar(wxCommandEvent& event);
149 void OnSetStyleNormal(wxCommandEvent& event);
150 void OnSetStyleFlat(wxCommandEvent& event);
151 void OnSetStyleRaised(wxCommandEvent& event);
152
153 private:
154 enum StatBarKind
155 {
156 StatBar_Default,
157 StatBar_Custom,
158 StatBar_Max
159 } m_statbarKind;
160 void OnUpdateSetStatusFields(wxUpdateUIEvent& event);
161 void OnUpdateStatusBarToggle(wxUpdateUIEvent& event);
162 void OnUpdateSetStyleNormal(wxUpdateUIEvent& event);
163 void OnUpdateSetStyleFlat(wxUpdateUIEvent& event);
164 void OnUpdateSetStyleRaised(wxUpdateUIEvent& event);
165 void OnStatusBarToggle(wxCommandEvent& event);
166 void DoCreateStatusBar(StatBarKind kind);
167 void ApplyStyle();
168
169 wxStatusBar *m_statbarDefault;
170 MyStatusBar *m_statbarCustom;
171
172 int m_statbarStyle;
173
174 // any class wishing to process wxWidgets events must use this macro
175 DECLARE_EVENT_TABLE()
176 };
177
178 // Our about dialog ith its status bar
179 class MyAboutDialog : public wxDialog
180 {
181 public:
182 MyAboutDialog(wxWindow *parent);
183 };
184
185 // ----------------------------------------------------------------------------
186 // constants
187 // ----------------------------------------------------------------------------
188
189 // IDs for the controls and the menu commands
190 enum
191 {
192 // menu items
193 StatusBar_Quit = 1,
194 StatusBar_SetFields,
195 StatusBar_Recreate,
196 StatusBar_About,
197 StatusBar_Toggle,
198 StatusBar_Checkbox = 1000,
199 StatusBar_SetStyle,
200 StatusBar_SetStyleNormal,
201 StatusBar_SetStyleFlat,
202 StatusBar_SetStyleRaised
203 };
204
205 static const int BITMAP_SIZE_X = 32;
206 static const int BITMAP_SIZE_Y = 15;
207
208 // ----------------------------------------------------------------------------
209 // event tables and other macros for wxWidgets
210 // ----------------------------------------------------------------------------
211
212 // the event tables connect the wxWidgets events with the functions (event
213 // handlers) which process them. It can be also done at run-time, but for the
214 // simple menu events like this the static method is much simpler.
215 #ifdef USE_MDI_PARENT_FRAME
216 BEGIN_EVENT_TABLE(MyFrame, wxMDIParentFrame)
217 #else
218 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
219 #endif
220 EVT_MENU(StatusBar_Quit, MyFrame::OnQuit)
221 EVT_MENU(StatusBar_SetFields, MyFrame::OnSetStatusFields)
222 EVT_MENU(StatusBar_Recreate, MyFrame::OnRecreateStatusBar)
223 EVT_MENU(StatusBar_About, MyFrame::OnAbout)
224 EVT_MENU(StatusBar_Toggle, MyFrame::OnStatusBarToggle)
225 EVT_MENU(StatusBar_SetStyleNormal, MyFrame::OnSetStyleNormal)
226 EVT_MENU(StatusBar_SetStyleFlat, MyFrame::OnSetStyleFlat)
227 EVT_MENU(StatusBar_SetStyleRaised, MyFrame::OnSetStyleRaised)
228 EVT_UPDATE_UI(StatusBar_Toggle, MyFrame::OnUpdateStatusBarToggle)
229 EVT_UPDATE_UI(StatusBar_SetFields, MyFrame::OnUpdateSetStatusFields)
230 EVT_UPDATE_UI(StatusBar_SetStyleNormal, MyFrame::OnUpdateSetStyleNormal)
231 EVT_UPDATE_UI(StatusBar_SetStyleFlat, MyFrame::OnUpdateSetStyleFlat)
232 EVT_UPDATE_UI(StatusBar_SetStyleRaised, MyFrame::OnUpdateSetStyleRaised)
233 END_EVENT_TABLE()
234
235 BEGIN_EVENT_TABLE(MyStatusBar, wxStatusBar)
236 EVT_SIZE(MyStatusBar::OnSize)
237 EVT_CHECKBOX(StatusBar_Checkbox, MyStatusBar::OnToggleClock)
238 EVT_BUTTON(wxID_ANY, MyStatusBar::OnButton)
239 EVT_TIMER(wxID_ANY, MyStatusBar::OnTimer)
240 END_EVENT_TABLE()
241
242 // Create a new application object: this macro will allow wxWidgets to create
243 // the application object during program execution (it's better than using a
244 // static object for many reasons) and also declares the accessor function
245 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
246 // not wxApp)
247 IMPLEMENT_APP(MyApp)
248
249 // ============================================================================
250 // implementation
251 // ============================================================================
252
253 // ----------------------------------------------------------------------------
254 // the application class
255 // ----------------------------------------------------------------------------
256
257 // `Main program' equivalent: the program execution "starts" here
258 bool MyApp::OnInit()
259 {
260 // create the main application window
261 MyFrame *frame = new MyFrame(_T("wxStatusBar sample"),
262 wxPoint(50, 50), wxSize(450, 340));
263
264 // and show it (the frames, unlike simple controls, are not shown when
265 // created initially)
266 frame->Show(true);
267
268 // success: wxApp::OnRun() will be called which will enter the main message
269 // loop and the application will run. If we returned 'false' here, the
270 // application would exit immediately.
271 return true;
272 }
273
274 // ----------------------------------------------------------------------------
275 // main frame
276 // ----------------------------------------------------------------------------
277
278 // frame constructor
279 MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
280 #ifdef USE_MDI_PARENT_FRAME
281 : wxMDIParentFrame((wxWindow *)NULL, wxID_ANY, title, pos, size)
282 #else
283 : wxFrame((wxWindow *)NULL, wxID_ANY, title, pos, size)
284 #endif
285 {
286 m_statbarDefault = NULL;
287 m_statbarCustom = NULL;
288
289 m_statbarStyle = wxSB_NORMAL;
290
291 #ifdef __WXMAC__
292 // we need this in order to allow the about menu relocation, since ABOUT is
293 // not the default id of the about menu
294 wxApp::s_macAboutMenuItemId = StatusBar_About;
295 #endif
296
297 // create a menu bar
298 wxMenu *menuFile = new wxMenu;
299 menuFile->Append(StatusBar_Quit, _T("E&xit\tAlt-X"), _T("Quit this program"));
300
301 wxMenu *statbarMenu = new wxMenu;
302 statbarMenu->Append(StatusBar_SetFields, _T("&Set field count\tCtrl-C"),
303 _T("Set the number of status bar fields"));
304 statbarMenu->Append(StatusBar_Toggle, _T("&Toggle Status Bar"),
305 _T("Toggle the status bar display"), true);
306 statbarMenu->Append(StatusBar_Recreate, _T("&Recreate\tCtrl-R"),
307 _T("Toggle status bar format"));
308
309 wxMenu *statbarStyleMenu = new wxMenu;
310 statbarStyleMenu->Append(StatusBar_SetStyleNormal, _T("&Normal"), _T("Sets the style of the first field to normal (sunken) look"), true);
311 statbarStyleMenu->Append(StatusBar_SetStyleFlat, _T("&Flat"), _T("Sets the style of the first field to flat look"), true);
312 statbarStyleMenu->Append(StatusBar_SetStyleRaised, _T("&Raised"), _T("Sets the style of the first field to raised look"), true);
313 statbarMenu->Append(StatusBar_SetStyle, _T("Field style"), statbarStyleMenu);
314
315 wxMenu *helpMenu = new wxMenu;
316 helpMenu->Append(StatusBar_About, _T("&About...\tCtrl-A"), _T("Show about dialog"));
317
318 // now append the freshly created menu to the menu bar...
319 wxMenuBar *menuBar = new wxMenuBar();
320 menuBar->Append(menuFile, _T("&File"));
321 menuBar->Append(statbarMenu, _T("&Status bar"));
322 menuBar->Append(helpMenu, _T("&Help"));
323
324 // ... and attach this menu bar to the frame
325 SetMenuBar(menuBar);
326
327 // create default status bar to start with
328 CreateStatusBar(2);
329 m_statbarKind = StatBar_Default;
330 SetStatusText(_T("Welcome to wxWidgets!"));
331
332 m_statbarDefault = GetStatusBar();
333 }
334
335 MyFrame::~MyFrame()
336 {
337 SetStatusBar(NULL);
338
339 delete m_statbarDefault;
340 delete m_statbarCustom;
341 }
342
343 void MyFrame::DoCreateStatusBar(MyFrame::StatBarKind kind)
344 {
345 wxStatusBar *statbarOld = GetStatusBar();
346 if ( statbarOld )
347 {
348 statbarOld->Hide();
349 }
350
351 switch ( kind )
352 {
353 case StatBar_Default:
354 SetStatusBar(m_statbarDefault);
355 break;
356
357 case StatBar_Custom:
358 if ( !m_statbarCustom )
359 {
360 m_statbarCustom = new MyStatusBar(this);
361 }
362 SetStatusBar(m_statbarCustom);
363 break;
364
365 default:
366 wxFAIL_MSG(wxT("unknown stat bar kind"));
367 }
368
369 ApplyStyle();
370 GetStatusBar()->Show();
371 PositionStatusBar();
372
373 m_statbarKind = kind;
374 }
375
376 void MyFrame::OnUpdateSetStatusFields(wxUpdateUIEvent& event)
377 {
378 // only allow the settings of the number of status fields for the default
379 // status bar
380 wxStatusBar *sb = GetStatusBar();
381 event.Enable(sb == m_statbarDefault);
382 }
383
384 // event handlers
385 void MyFrame::OnSetStatusFields(wxCommandEvent& WXUNUSED(event))
386 {
387 wxStatusBar *sb = GetStatusBar();
388
389 long nFields = wxGetNumberFromUser
390 (
391 _T("Select the number of fields in the status bar"),
392 _T("Fields:"),
393 _T("wxWidgets statusbar sample"),
394 sb->GetFieldsCount(),
395 1, 5,
396 this
397 );
398
399 // we don't check if the number changed at all on purpose: calling
400 // SetFieldsCount() with the same number of fields should be ok
401 if ( nFields != -1 )
402 {
403 static const int widthsFor2Fields[] = { 200, -1 };
404 static const int widthsFor3Fields[] = { -1, -2, -1 };
405 static const int widthsFor4Fields[] = { 100, -1, 100, -2, 100 };
406
407 static const int *widthsAll[] =
408 {
409 NULL, // 1 field: default
410 widthsFor2Fields, // 2 fields: 1 fixed, 1 var
411 widthsFor3Fields, // 3 fields: 3 var
412 widthsFor4Fields, // 4 fields: 3 fixed, 2 vars
413 NULL // 5 fields: default (all have same width)
414 };
415
416 const int * const widths = widthsAll[nFields - 1];
417 sb->SetFieldsCount(nFields, widths);
418
419 wxString s;
420 for ( long n = 0; n < nFields; n++ )
421 {
422 if ( widths )
423 {
424 if ( widths[n] > 0 )
425 s.Printf(_T("fixed (%d)"), widths[n]);
426 else
427 s.Printf(_T("variable (*%d)"), -widths[n]);
428 }
429 else
430 {
431 s = _T("default");
432 }
433
434 SetStatusText(s, n);
435 }
436 }
437 else
438 {
439 wxLogStatus(this, wxT("Cancelled"));
440 }
441 }
442
443 void MyFrame::OnUpdateStatusBarToggle(wxUpdateUIEvent& event)
444 {
445 event.Check(GetStatusBar() != 0);
446 }
447
448 void MyFrame::OnStatusBarToggle(wxCommandEvent& WXUNUSED(event))
449 {
450 wxStatusBar *statbarOld = GetStatusBar();
451 if ( statbarOld )
452 {
453 statbarOld->Hide();
454 SetStatusBar(0);
455 }
456 else
457 {
458 DoCreateStatusBar(m_statbarKind);
459 }
460 #ifdef __WXMSW__
461 // The following is a kludge suggested by Vadim Zeitlin (one of the wxWidgets
462 // authors) while we look for a proper fix..
463 // SendSizeEvent();
464 #endif
465 }
466
467 void MyFrame::OnRecreateStatusBar(wxCommandEvent& WXUNUSED(event))
468 {
469 DoCreateStatusBar(m_statbarKind == StatBar_Custom ? StatBar_Default
470 : StatBar_Custom);
471 }
472
473 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
474 {
475 // true is to force the frame to close
476 Close(true);
477 }
478
479 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
480 {
481 MyAboutDialog dlg(this);
482 dlg.ShowModal();
483 }
484
485 void MyFrame::OnUpdateSetStyleNormal(wxUpdateUIEvent &event)
486 {
487 event.Check(m_statbarStyle == wxSB_NORMAL);
488 }
489
490 void MyFrame::OnUpdateSetStyleFlat(wxUpdateUIEvent &event)
491 {
492 event.Check(m_statbarStyle == wxSB_FLAT);
493 }
494
495 void MyFrame::OnUpdateSetStyleRaised(wxUpdateUIEvent &event)
496 {
497 event.Check(m_statbarStyle == wxSB_RAISED);
498 }
499
500 void MyFrame::OnSetStyleNormal(wxCommandEvent & WXUNUSED(event))
501 {
502 m_statbarStyle = wxSB_NORMAL;
503 ApplyStyle();
504 }
505
506 void MyFrame::OnSetStyleFlat(wxCommandEvent & WXUNUSED(event))
507 {
508 m_statbarStyle = wxSB_FLAT;
509 ApplyStyle();
510 }
511
512 void MyFrame::OnSetStyleRaised(wxCommandEvent & WXUNUSED(event))
513 {
514 m_statbarStyle = wxSB_RAISED;
515 ApplyStyle();
516 }
517
518 void MyFrame::ApplyStyle()
519 {
520 wxStatusBar *sb = GetStatusBar();
521 int fields = sb->GetFieldsCount();
522 int *styles = new int[fields];
523
524 for (int i = 1; i < fields; i++)
525 styles[i] = wxSB_NORMAL;
526
527 styles[0] = m_statbarStyle;
528
529 sb->SetStatusStyles(fields, styles);
530
531 delete [] styles;
532 }
533
534 // ----------------------------------------------------------------------------
535 // MyAboutDialog
536 // ----------------------------------------------------------------------------
537
538 MyAboutDialog::MyAboutDialog(wxWindow *parent)
539 : wxDialog(parent, wxID_ANY, wxString(_T("About statbar")),
540 wxDefaultPosition, wxDefaultSize,
541 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
542 {
543 wxStaticText *text = new wxStaticText(this, wxID_ANY,
544 _T("wxStatusBar sample\n")
545 _T("(c) 2000 Vadim Zeitlin"));
546
547 wxButton *btn = new wxButton(this, wxID_OK, _T("&Close"));
548
549 // create the top status bar without the size grip (default style),
550 // otherwise it looks weird
551 wxStatusBar *statbarTop = new wxStatusBar(this, wxID_ANY, 0);
552 statbarTop->SetFieldsCount(3);
553 statbarTop->SetStatusText(_T("This is a top status bar"), 0);
554 statbarTop->SetStatusText(_T("in a dialog"), 1);
555 statbarTop->SetStatusText(_T("Great, isn't it?"), 2);
556
557 wxStatusBar *statbarBottom = new wxStatusBar(this, wxID_ANY);
558 statbarBottom->SetFieldsCount(2);
559 statbarBottom->SetStatusText(_T("This is a bottom status bar"), 0);
560 statbarBottom->SetStatusText(_T("in a dialog"), 1);
561
562 wxBoxSizer *sizerTop = new wxBoxSizer(wxVERTICAL);
563 sizerTop->Add(statbarTop, 0, wxGROW);
564 sizerTop->Add(-1, 10, 1, wxGROW);
565 sizerTop->Add(text, 0, wxCENTRE | wxRIGHT | wxLEFT, 20);
566 sizerTop->Add(-1, 10, 1, wxGROW);
567 sizerTop->Add(btn, 0, wxCENTRE | wxRIGHT | wxLEFT, 20);
568 sizerTop->Add(-1, 10, 1, wxGROW);
569 sizerTop->Add(statbarBottom, 0, wxGROW);
570
571 SetSizer(sizerTop);
572
573 sizerTop->Fit(this);
574 sizerTop->SetSizeHints(this);
575 }
576
577 // ----------------------------------------------------------------------------
578 // MyStatusBar
579 // ----------------------------------------------------------------------------
580
581 #ifdef __VISUALC__
582 // 'this' : used in base member initializer list -- so what??
583 #pragma warning(disable: 4355)
584 #endif
585
586 MyStatusBar::MyStatusBar(wxWindow *parent)
587 : wxStatusBar(parent, wxID_ANY), m_timer(this), m_checkbox(NULL)
588 {
589 static const int widths[Field_Max] = { -1, 150, BITMAP_SIZE_X, 100 };
590
591 SetFieldsCount(Field_Max);
592 SetStatusWidths(Field_Max, widths);
593
594 m_checkbox = new wxCheckBox(this, StatusBar_Checkbox, _T("&Toggle clock"));
595 m_checkbox->SetValue(true);
596
597 #ifdef USE_STATIC_BITMAP
598 m_statbmp = new wxStaticBitmap(this, wxID_ANY, wxIcon(green_xpm));
599 #else
600 m_statbmp = new wxBitmapButton(this, wxID_ANY, CreateBitmapForButton(),
601 wxDefaultPosition, wxDefaultSize,
602 wxBU_EXACTFIT);
603 #endif
604
605 m_timer.Start(1000);
606
607 SetMinHeight(BITMAP_SIZE_Y);
608
609 UpdateClock();
610 }
611
612 #ifdef __VISUALC__
613 #pragma warning(default: 4355)
614 #endif
615
616 MyStatusBar::~MyStatusBar()
617 {
618 if ( m_timer.IsRunning() )
619 {
620 m_timer.Stop();
621 }
622 }
623
624 wxBitmap MyStatusBar::CreateBitmapForButton(bool on)
625 {
626 static const int BMP_BUTTON_SIZE_X = 10;
627 static const int BMP_BUTTON_SIZE_Y = 9;
628
629 wxBitmap bitmap(BMP_BUTTON_SIZE_X, BMP_BUTTON_SIZE_Y);
630 wxMemoryDC dc;
631 dc.SelectObject(bitmap);
632 dc.SetBrush(on ? *wxGREEN_BRUSH : *wxRED_BRUSH);
633 dc.SetBackground(*wxLIGHT_GREY_BRUSH);
634 dc.Clear();
635 dc.DrawEllipse(0, 0, BMP_BUTTON_SIZE_X, BMP_BUTTON_SIZE_Y);
636 dc.SelectObject(wxNullBitmap);
637
638 return bitmap;
639 }
640
641 void MyStatusBar::OnSize(wxSizeEvent& event)
642 {
643 if ( !m_checkbox )
644 return;
645
646 wxRect rect;
647 GetFieldRect(Field_Checkbox, rect);
648
649 m_checkbox->SetSize(rect.x + 2, rect.y + 2, rect.width - 4, rect.height - 4);
650
651 GetFieldRect(Field_Bitmap, rect);
652 wxSize size = m_statbmp->GetSize();
653
654 m_statbmp->Move(rect.x + (rect.width - size.x) / 2,
655 rect.y + (rect.height - size.y) / 2);
656
657 event.Skip();
658 }
659
660 void MyStatusBar::OnButton(wxCommandEvent& WXUNUSED(event))
661 {
662 m_checkbox->SetValue(!m_checkbox->GetValue());
663
664 DoToggle();
665 }
666
667 void MyStatusBar::OnToggleClock(wxCommandEvent& WXUNUSED(event))
668 {
669 DoToggle();
670 }
671
672 void MyStatusBar::DoToggle()
673 {
674 if ( m_checkbox->GetValue() )
675 {
676 m_timer.Start(1000);
677
678 #ifdef USE_STATIC_BITMAP
679 m_statbmp->SetIcon(wxIcon(green_xpm));
680 #else
681 m_statbmp->SetBitmapLabel(CreateBitmapForButton(false));
682 m_statbmp->Refresh();
683 #endif
684
685 UpdateClock();
686 }
687 else // don't show clock
688 {
689 m_timer.Stop();
690
691 #ifdef USE_STATIC_BITMAP
692 m_statbmp->SetIcon(wxIcon(red_xpm));
693 #else
694 m_statbmp->SetBitmapLabel(CreateBitmapForButton(true));
695 m_statbmp->Refresh();
696 #endif
697
698 SetStatusText(wxEmptyString, Field_Clock);
699 }
700 }
701
702 void MyStatusBar::UpdateClock()
703 {
704 SetStatusText(wxDateTime::Now().FormatTime(), Field_Clock);
705 }