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