1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxStatusBar sample
4 // Author: Vadim Zeitlin
8 // Copyright: (c) Vadim Zeitlin
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx/wx.h".
21 #include "wx/wxprec.h"
28 #error "You need to set wxUSE_STATUSBAR to 1 to compile this sample"
29 #endif // wxUSE_STATUSBAR
31 // for all others, include the necessary headers
36 #include "wx/statusbr.h"
38 #include "wx/checkbox.h"
39 #include "wx/statbmp.h"
41 #include "wx/msgdlg.h"
42 #include "wx/textdlg.h"
44 #include "wx/stattext.h"
45 #include "wx/bmpbuttn.h"
46 #include "wx/dcmemory.h"
49 #include "wx/datetime.h"
50 #include "wx/numdlg.h"
51 #include "wx/fontdlg.h"
54 #include "../sample.xpm"
58 // define this for the platforms which don't support wxBitmapButton (such as
59 // Motif), else a wxBitmapButton will be used
61 #define USE_STATIC_BITMAP
64 //#define USE_MDI_PARENT_FRAME 1
66 #ifdef USE_MDI_PARENT_FRAME
68 #endif // USE_MDI_PARENT_FRAME
71 // ----------------------------------------------------------------------------
73 // ----------------------------------------------------------------------------
75 #ifdef USE_STATIC_BITMAP
78 #endif // USE_STATIC_BITMAP
80 // ----------------------------------------------------------------------------
82 // ----------------------------------------------------------------------------
84 // Define a new application type, each program should derive a class from wxApp
85 class MyApp
: public wxApp
88 // override base class virtuals
89 // ----------------------------
91 // this one is called on application startup and is a good place for the app
92 // initialization (doing it here and not in the ctor allows to have an error
93 // return: if OnInit() returns false, the application terminates)
94 virtual bool OnInit();
97 // A custom status bar which contains controls, icons &c
98 class MyStatusBar
: public wxStatusBar
101 MyStatusBar(wxWindow
*parent
, long style
= wxSTB_DEFAULT_STYLE
);
102 virtual ~MyStatusBar();
108 void OnTimer(wxTimerEvent
& WXUNUSED(event
)) { UpdateClock(); }
110 void OnSize(wxSizeEvent
& event
);
111 void OnToggleClock(wxCommandEvent
& event
);
112 void OnButton(wxCommandEvent
& event
);
115 // toggle the state of the status bar controls
118 wxBitmap
CreateBitmapForButton(bool on
= false);
134 wxCheckBox
*m_checkbox
;
136 #ifdef USE_STATIC_BITMAP
137 wxStaticBitmap
*m_statbmp
;
139 wxBitmapButton
*m_statbmp
;
142 DECLARE_EVENT_TABLE()
145 // Define a new frame type: this is going to be our main frame
146 class MyFrame
: public wxFrame
150 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
151 #ifdef USE_MDI_PARENT_FRAME
152 class MyFrame
: public wxMDIParentFrame
157 // event handlers (these functions should _not_ be virtual)
158 void OnQuit(wxCommandEvent
& event
);
159 void OnAbout(wxCommandEvent
& event
);
161 void OnResetFieldsWidth(wxCommandEvent
& event
);
162 void OnSetStatusFields(wxCommandEvent
& event
);
163 void OnSetStatusTexts(wxCommandEvent
& event
);
164 void OnSetStatusFont(wxCommandEvent
& event
);
165 void OnRecreateStatusBar(wxCommandEvent
& event
);
167 void OnSetPaneStyle(wxCommandEvent
& event
);
168 void OnSetStyle(wxCommandEvent
& event
);
179 void OnUpdateForDefaultStatusbar(wxUpdateUIEvent
& event
);
180 void OnUpdateStatusBarToggle(wxUpdateUIEvent
& event
);
181 void OnUpdateSetPaneStyle(wxUpdateUIEvent
& event
);
182 void OnUpdateSetStyle(wxUpdateUIEvent
& event
);
183 void OnStatusBarToggle(wxCommandEvent
& event
);
184 void DoCreateStatusBar(StatusBarKind kind
, long style
);
185 void ApplyPaneStyle();
187 int m_statbarPaneStyle
;
189 // any class wishing to process wxWidgets events must use this macro
190 DECLARE_EVENT_TABLE()
193 // Our about dialog ith its status bar
194 class MyAboutDialog
: public wxDialog
197 MyAboutDialog(wxWindow
*parent
);
200 // ----------------------------------------------------------------------------
202 // ----------------------------------------------------------------------------
204 // IDs for the controls and the menu commands
208 StatusBar_Quit
= wxID_EXIT
,
209 StatusBar_About
= wxID_ABOUT
,
211 StatusBar_SetFields
= wxID_HIGHEST
+1,
214 StatusBar_ResetFieldsWidth
,
219 StatusBar_SetPaneStyle
,
220 StatusBar_SetPaneStyleNormal
,
221 StatusBar_SetPaneStyleFlat
,
222 StatusBar_SetPaneStyleRaised
,
224 StatusBar_SetStyleSizeGrip
,
225 StatusBar_SetStyleEllipsizeStart
,
226 StatusBar_SetStyleEllipsizeMiddle
,
227 StatusBar_SetStyleEllipsizeEnd
,
228 StatusBar_SetStyleShowTips
231 static const int BITMAP_SIZE_X
= 32;
232 static const int BITMAP_SIZE_Y
= 15;
234 // ----------------------------------------------------------------------------
235 // event tables and other macros for wxWidgets
236 // ----------------------------------------------------------------------------
238 // the event tables connect the wxWidgets events with the functions (event
239 // handlers) which process them. It can be also done at run-time, but for the
240 // simple menu events like this the static method is much simpler.
241 #ifdef USE_MDI_PARENT_FRAME
242 BEGIN_EVENT_TABLE(MyFrame
, wxMDIParentFrame
)
244 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
246 EVT_MENU(StatusBar_Quit
, MyFrame::OnQuit
)
247 EVT_MENU(StatusBar_SetFields
, MyFrame::OnSetStatusFields
)
248 EVT_MENU(StatusBar_SetTexts
, MyFrame::OnSetStatusTexts
)
249 EVT_MENU(StatusBar_SetFont
, MyFrame::OnSetStatusFont
)
250 EVT_MENU(StatusBar_ResetFieldsWidth
, MyFrame::OnResetFieldsWidth
)
251 EVT_MENU(StatusBar_Recreate
, MyFrame::OnRecreateStatusBar
)
252 EVT_MENU(StatusBar_About
, MyFrame::OnAbout
)
253 EVT_MENU(StatusBar_Toggle
, MyFrame::OnStatusBarToggle
)
254 EVT_MENU(StatusBar_SetPaneStyleNormal
, MyFrame::OnSetPaneStyle
)
255 EVT_MENU(StatusBar_SetPaneStyleFlat
, MyFrame::OnSetPaneStyle
)
256 EVT_MENU(StatusBar_SetPaneStyleRaised
, MyFrame::OnSetPaneStyle
)
258 EVT_MENU(StatusBar_SetStyleSizeGrip
, MyFrame::OnSetStyle
)
259 EVT_MENU(StatusBar_SetStyleEllipsizeStart
, MyFrame::OnSetStyle
)
260 EVT_MENU(StatusBar_SetStyleEllipsizeMiddle
, MyFrame::OnSetStyle
)
261 EVT_MENU(StatusBar_SetStyleEllipsizeEnd
, MyFrame::OnSetStyle
)
262 EVT_MENU(StatusBar_SetStyleShowTips
, MyFrame::OnSetStyle
)
264 EVT_UPDATE_UI_RANGE(StatusBar_SetFields
, StatusBar_ResetFieldsWidth
,
265 MyFrame::OnUpdateForDefaultStatusbar
)
266 EVT_UPDATE_UI(StatusBar_Toggle
, MyFrame::OnUpdateStatusBarToggle
)
267 EVT_UPDATE_UI_RANGE(StatusBar_SetPaneStyleNormal
, StatusBar_SetPaneStyleRaised
,
268 MyFrame::OnUpdateSetPaneStyle
)
269 EVT_UPDATE_UI_RANGE(StatusBar_SetStyleSizeGrip
, StatusBar_SetStyleShowTips
,
270 MyFrame::OnUpdateSetStyle
)
273 BEGIN_EVENT_TABLE(MyStatusBar
, wxStatusBar
)
274 EVT_SIZE(MyStatusBar::OnSize
)
276 EVT_CHECKBOX(StatusBar_Checkbox
, MyStatusBar::OnToggleClock
)
278 EVT_BUTTON(wxID_ANY
, MyStatusBar::OnButton
)
280 EVT_TIMER(wxID_ANY
, MyStatusBar::OnTimer
)
284 // Create a new application object: this macro will allow wxWidgets to create
285 // the application object during program execution (it's better than using a
286 // static object for many reasons) and also declares the accessor function
287 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
291 // ============================================================================
293 // ============================================================================
295 // ----------------------------------------------------------------------------
296 // the application class
297 // ----------------------------------------------------------------------------
299 // `Main program' equivalent: the program execution "starts" here
302 if ( !wxApp::OnInit() )
305 // create the main application window
306 MyFrame
*frame
= new MyFrame(_T("wxStatusBar sample"),
307 wxPoint(50, 50), wxSize(450, 340));
309 // and show it (the frames, unlike simple controls, are not shown when
310 // created initially)
313 // success: wxApp::OnRun() will be called which will enter the main message
314 // loop and the application will run. If we returned 'false' here, the
315 // application would exit immediately.
319 // ----------------------------------------------------------------------------
321 // ----------------------------------------------------------------------------
324 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
325 #ifdef USE_MDI_PARENT_FRAME
326 : wxMDIParentFrame((wxWindow
*)NULL
, wxID_ANY
, title
, pos
, size
)
328 : wxFrame((wxWindow
*)NULL
, wxID_ANY
, title
, pos
, size
)
331 SetIcon(wxICON(sample
));
333 m_statbarPaneStyle
= wxSB_NORMAL
;
336 // we need this in order to allow the about menu relocation, since ABOUT is
337 // not the default id of the about menu
338 wxApp::s_macAboutMenuItemId
= StatusBar_About
;
342 wxMenu
*menuFile
= new wxMenu
;
343 menuFile
->Append(StatusBar_Quit
, _T("E&xit\tAlt-X"), _T("Quit this program"));
345 wxMenu
*statbarMenu
= new wxMenu
;
347 wxMenu
*statbarStyleMenu
= new wxMenu
;
348 statbarStyleMenu
->Append(StatusBar_SetStyleSizeGrip
, _T("wxSTB_SIZE_GRIP"), _T("Toggles the wxSTB_SIZE_GRIP style"), true);
349 statbarStyleMenu
->Append(StatusBar_SetStyleShowTips
, _T("wxSTB_SHOW_TIPS"), _T("Toggles the wxSTB_SHOW_TIPS style"), true);
350 statbarStyleMenu
->AppendSeparator();
351 statbarStyleMenu
->Append(StatusBar_SetStyleEllipsizeStart
, _T("wxSTB_ELLIPSIZE_START"), _T("Toggles the wxSTB_ELLIPSIZE_START style"), true);
352 statbarStyleMenu
->Append(StatusBar_SetStyleEllipsizeMiddle
, _T("wxSTB_ELLIPSIZE_MIDDLE"), _T("Toggles the wxSTB_ELLIPSIZE_MIDDLE style"), true);
353 statbarStyleMenu
->Append(StatusBar_SetStyleEllipsizeEnd
, _T("wxSTB_ELLIPSIZE_END"), _T("Toggles the wxSTB_ELLIPSIZE_END style"), true);
354 statbarMenu
->Append(StatusBar_SetPaneStyle
, _T("Status bar style"), statbarStyleMenu
);
355 statbarMenu
->AppendSeparator();
357 statbarMenu
->Append(StatusBar_SetFields
, _T("&Set field count\tCtrl-C"),
358 _T("Set the number of status bar fields"));
359 statbarMenu
->Append(StatusBar_SetTexts
, _T("&Set field text\tCtrl-T"),
360 _T("Set the text to display for each status bar field"));
361 statbarMenu
->Append(StatusBar_SetFont
, _T("&Set field font\tCtrl-F"),
362 _T("Set the font to use for rendering status bar fields"));
364 wxMenu
*statbarPaneStyleMenu
= new wxMenu
;
365 statbarPaneStyleMenu
->Append(StatusBar_SetPaneStyleNormal
, _T("&Normal"), _T("Sets the style of the first field to normal (sunken) look"), true);
366 statbarPaneStyleMenu
->Append(StatusBar_SetPaneStyleFlat
, _T("&Flat"), _T("Sets the style of the first field to flat look"), true);
367 statbarPaneStyleMenu
->Append(StatusBar_SetPaneStyleRaised
, _T("&Raised"), _T("Sets the style of the first field to raised look"), true);
368 statbarMenu
->Append(StatusBar_SetPaneStyle
, _T("Field style"), statbarPaneStyleMenu
);
370 statbarMenu
->Append(StatusBar_ResetFieldsWidth
, _T("Reset field widths"),
371 _T("Sets all fields to the same width"));
372 statbarMenu
->AppendSeparator();
374 statbarMenu
->Append(StatusBar_Toggle
, _T("&Toggle Status Bar"),
375 _T("Toggle the status bar display"), true);
376 statbarMenu
->Append(StatusBar_Recreate
, _T("&Recreate\tCtrl-R"),
377 _T("Toggle status bar format"));
379 wxMenu
*helpMenu
= new wxMenu
;
380 helpMenu
->Append(StatusBar_About
, _T("&About...\tCtrl-A"), _T("Show about dialog"));
382 // now append the freshly created menu to the menu bar...
383 wxMenuBar
*menuBar
= new wxMenuBar();
384 menuBar
->Append(menuFile
, _T("&File"));
385 menuBar
->Append(statbarMenu
, _T("&Status bar"));
386 menuBar
->Append(helpMenu
, _T("&Help"));
388 // ... and attach this menu bar to the frame
391 // create default status bar to start with
392 DoCreateStatusBar(StatBar_Default
, wxSTB_DEFAULT_STYLE
);
393 SetStatusText(_T("Welcome to wxWidgets!"));
400 void MyFrame::DoCreateStatusBar(MyFrame::StatusBarKind kind
, long style
)
402 wxStatusBar
*statbarOld
= GetStatusBar();
409 wxStatusBar
*statbarNew
= NULL
;
412 case StatBar_Default
:
413 statbarNew
= new wxStatusBar(this, wxID_ANY
, style
, "wxStatusBar");
414 statbarNew
->SetFieldsCount(2);
418 statbarNew
= new MyStatusBar(this, style
);
422 wxFAIL_MSG(wxT("unknown status bar kind"));
425 SetStatusBar(statbarNew
);
429 m_statbarKind
= kind
;
433 // ----------------------------------------------------------------------------
434 // main frame - event handlers
435 // ----------------------------------------------------------------------------
437 void MyFrame::OnUpdateForDefaultStatusbar(wxUpdateUIEvent
& event
)
439 // only allow this feature for the default status bar
440 wxStatusBar
*sb
= GetStatusBar();
444 event
.Enable(sb
->GetName() == "wxStatusBar");
447 void MyFrame::OnSetStatusTexts(wxCommandEvent
& WXUNUSED(event
))
449 wxStatusBar
*sb
= GetStatusBar();
454 for (int i
=0; i
<sb
->GetFieldsCount(); i
++)
457 wxGetTextFromUser(wxString::Format("Enter the text for the %d-th field:", i
+1),
458 "Input field text", "A dummy test string", this);
460 sb
->SetStatusText(txt
, i
);
464 void MyFrame::OnSetStatusFont(wxCommandEvent
& WXUNUSED(event
))
466 wxStatusBar
*sb
= GetStatusBar();
470 wxFont fnt
= wxGetFontFromUser(this, sb
->GetFont(), "Choose statusbar font");
474 sb
->SetSize(sb
->GetBestSize());
478 void MyFrame::OnSetStatusFields(wxCommandEvent
& WXUNUSED(event
))
480 wxStatusBar
*sb
= GetStatusBar();
484 long nFields
= wxGetNumberFromUser
486 _T("Select the number of fields in the status bar"),
488 _T("wxWidgets statusbar sample"),
489 sb
->GetFieldsCount(),
494 // we don't check if the number changed at all on purpose: calling
495 // SetFieldsCount() with the same number of fields should be ok
498 static const int widthsFor2Fields
[] = { 200, -1 };
499 static const int widthsFor3Fields
[] = { -1, -2, -1 };
500 static const int widthsFor4Fields
[] = { 100, -1, 100, -2, 100 };
502 static const int *widthsAll
[] =
504 NULL
, // 1 field: default
505 widthsFor2Fields
, // 2 fields: 1 fixed, 1 var
506 widthsFor3Fields
, // 3 fields: 3 var
507 widthsFor4Fields
, // 4 fields: 3 fixed, 2 vars
508 NULL
// 5 fields: default (all have same width)
511 const int * const widths
= widthsAll
[nFields
- 1];
512 sb
->SetFieldsCount(nFields
, widths
);
515 for ( long n
= 0; n
< nFields
; n
++ )
520 s
.Printf(_T("fixed (%d)"), widths
[n
]);
522 s
.Printf(_T("variable (*%d)"), -widths
[n
]);
534 wxLogStatus(this, wxT("Cancelled"));
538 void MyFrame::OnResetFieldsWidth(wxCommandEvent
& WXUNUSED(event
))
540 wxStatusBar
*pStat
= GetStatusBar();
544 int n
= pStat
->GetFieldsCount();
545 pStat
->SetStatusWidths(n
, NULL
);
546 for (int i
=0; i
<n
; i
++)
547 pStat
->SetStatusText("same size", i
);
550 void MyFrame::OnUpdateStatusBarToggle(wxUpdateUIEvent
& event
)
552 event
.Check(GetStatusBar() != NULL
);
555 void MyFrame::OnStatusBarToggle(wxCommandEvent
& WXUNUSED(event
))
557 wxStatusBar
*statbarOld
= GetStatusBar();
565 DoCreateStatusBar(m_statbarKind
, wxSTB_DEFAULT_STYLE
);
569 void MyFrame::OnRecreateStatusBar(wxCommandEvent
& WXUNUSED(event
))
571 DoCreateStatusBar(m_statbarKind
== StatBar_Custom
? StatBar_Default
573 wxSTB_DEFAULT_STYLE
);
576 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
578 // true is to force the frame to close
582 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
584 MyAboutDialog
dlg(this);
588 void MyFrame::OnUpdateSetPaneStyle(wxUpdateUIEvent
& event
)
590 switch (event
.GetId())
592 case StatusBar_SetPaneStyleNormal
:
593 event
.Check(m_statbarPaneStyle
== wxSB_NORMAL
);
595 case StatusBar_SetPaneStyleFlat
:
596 event
.Check(m_statbarPaneStyle
== wxSB_FLAT
);
598 case StatusBar_SetPaneStyleRaised
:
599 event
.Check(m_statbarPaneStyle
== wxSB_RAISED
);
604 void MyFrame::OnSetPaneStyle(wxCommandEvent
& event
)
606 switch (event
.GetId())
608 case StatusBar_SetPaneStyleNormal
:
609 m_statbarPaneStyle
= wxSB_NORMAL
;
611 case StatusBar_SetPaneStyleFlat
:
612 m_statbarPaneStyle
= wxSB_FLAT
;
614 case StatusBar_SetPaneStyleRaised
:
615 m_statbarPaneStyle
= wxSB_RAISED
;
622 void MyFrame::ApplyPaneStyle()
624 wxStatusBar
*sb
= GetStatusBar();
628 int fields
= sb
->GetFieldsCount();
629 int *styles
= new int[fields
];
631 for (int i
= 1; i
< fields
; i
++)
632 styles
[i
] = wxSB_NORMAL
;
634 styles
[0] = m_statbarPaneStyle
;
636 sb
->SetStatusStyles(fields
, styles
);
641 void MyFrame::OnUpdateSetStyle(wxUpdateUIEvent
& event
)
643 long currentStyle
= wxSTB_DEFAULT_STYLE
;
645 currentStyle
= GetStatusBar()->GetWindowStyle();
647 switch (event
.GetId())
649 case StatusBar_SetStyleSizeGrip
:
650 event
.Check((currentStyle
& wxSTB_SIZEGRIP
) != 0);
652 case StatusBar_SetStyleShowTips
:
653 event
.Check((currentStyle
& wxSTB_SHOW_TIPS
) != 0);
656 case StatusBar_SetStyleEllipsizeStart
:
657 event
.Check((currentStyle
& wxSTB_ELLIPSIZE_START
) != 0);
659 case StatusBar_SetStyleEllipsizeMiddle
:
660 event
.Check((currentStyle
& wxSTB_ELLIPSIZE_MIDDLE
) != 0);
662 case StatusBar_SetStyleEllipsizeEnd
:
663 event
.Check((currentStyle
& wxSTB_ELLIPSIZE_END
) != 0);
668 void MyFrame::OnSetStyle(wxCommandEvent
& event
)
670 long oldStyle
= wxSTB_DEFAULT_STYLE
;
672 oldStyle
= GetStatusBar()->GetWindowStyle();
674 #define STB_ELLIPSIZE_MASK (wxSTB_ELLIPSIZE_START|wxSTB_ELLIPSIZE_MIDDLE|wxSTB_ELLIPSIZE_END)
676 long newStyle
= oldStyle
;
677 long newStyleBit
= 0;
678 switch (event
.GetId())
680 case StatusBar_SetStyleSizeGrip
:
681 newStyleBit
= wxSTB_SIZEGRIP
;
683 case StatusBar_SetStyleShowTips
:
684 newStyleBit
= wxSTB_SHOW_TIPS
;
687 case StatusBar_SetStyleEllipsizeStart
:
688 newStyleBit
= wxSTB_ELLIPSIZE_START
;
689 newStyle
&= ~STB_ELLIPSIZE_MASK
;
691 case StatusBar_SetStyleEllipsizeMiddle
:
692 newStyleBit
= wxSTB_ELLIPSIZE_MIDDLE
;
693 newStyle
&= ~STB_ELLIPSIZE_MASK
;
695 case StatusBar_SetStyleEllipsizeEnd
:
696 newStyleBit
= wxSTB_ELLIPSIZE_END
;
697 newStyle
&= ~STB_ELLIPSIZE_MASK
;
701 newStyle
= event
.IsChecked() ? (newStyle
| newStyleBit
) :
702 (newStyle
& ~newStyleBit
);
703 if (newStyle
!= oldStyle
)
705 DoCreateStatusBar(m_statbarKind
, newStyle
);
706 SetStatusText("Status bar recreated with a new style");
710 // ----------------------------------------------------------------------------
712 // ----------------------------------------------------------------------------
714 MyAboutDialog::MyAboutDialog(wxWindow
*parent
)
715 : wxDialog(parent
, wxID_ANY
, wxString(_T("About statbar")),
716 wxDefaultPosition
, wxDefaultSize
,
717 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
719 wxStaticText
*text
= new wxStaticText(this, wxID_ANY
,
720 _T("wxStatusBar sample\n")
721 _T("(c) 2000 Vadim Zeitlin"));
723 wxButton
*btn
= new wxButton(this, wxID_OK
, _T("&Close"));
725 // create the top status bar without the size grip (default style),
726 // otherwise it looks weird
727 wxStatusBar
*statbarTop
= new wxStatusBar(this, wxID_ANY
, 0);
728 statbarTop
->SetFieldsCount(3);
729 statbarTop
->SetStatusText(_T("This is a top status bar"), 0);
730 statbarTop
->SetStatusText(_T("in a dialog"), 1);
731 statbarTop
->SetStatusText(_T("Great, isn't it?"), 2);
733 wxStatusBar
*statbarBottom
= new wxStatusBar(this, wxID_ANY
);
734 statbarBottom
->SetFieldsCount(2);
735 statbarBottom
->SetStatusText(_T("This is a bottom status bar"), 0);
736 statbarBottom
->SetStatusText(_T("in a dialog"), 1);
738 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
739 sizerTop
->Add(statbarTop
, 0, wxGROW
);
740 sizerTop
->Add(-1, 10, 1, wxGROW
);
741 sizerTop
->Add(text
, 0, wxCENTRE
| wxRIGHT
| wxLEFT
, 20);
742 sizerTop
->Add(-1, 10, 1, wxGROW
);
743 sizerTop
->Add(btn
, 0, wxCENTRE
| wxRIGHT
| wxLEFT
, 20);
744 sizerTop
->Add(-1, 10, 1, wxGROW
);
745 sizerTop
->Add(statbarBottom
, 0, wxGROW
);
747 SetSizerAndFit(sizerTop
);
750 // ----------------------------------------------------------------------------
752 // ----------------------------------------------------------------------------
755 // 'this' : used in base member initializer list -- so what??
756 #pragma warning(disable: 4355)
759 MyStatusBar::MyStatusBar(wxWindow
*parent
, long style
)
760 : wxStatusBar(parent
, wxID_ANY
, style
, "MyStatusBar")
768 static const int widths
[Field_Max
] = { -1, 150, BITMAP_SIZE_X
, 100 };
770 SetFieldsCount(Field_Max
);
771 SetStatusWidths(Field_Max
, widths
);
774 m_checkbox
= new wxCheckBox(this, StatusBar_Checkbox
, _T("&Toggle clock"));
775 m_checkbox
->SetValue(true);
778 #ifdef USE_STATIC_BITMAP
779 m_statbmp
= new wxStaticBitmap(this, wxID_ANY
, wxIcon(green_xpm
));
781 m_statbmp
= new wxBitmapButton(this, wxID_ANY
, CreateBitmapForButton(),
782 wxDefaultPosition
, wxDefaultSize
,
790 SetMinHeight(wxMax(m_statbmp
->GetBestSize().GetHeight(),
791 m_checkbox
->GetBestSize().GetHeight()));
797 #pragma warning(default: 4355)
800 MyStatusBar::~MyStatusBar()
803 if ( m_timer
.IsRunning() )
810 #define BMP_BUTTON_SIZE_X 10
811 #define BMP_BUTTON_SIZE_Y 10
813 wxBitmap
MyStatusBar::CreateBitmapForButton(bool on
)
815 wxBitmap
bitmap(BMP_BUTTON_SIZE_X
+1, BMP_BUTTON_SIZE_Y
+1);
817 dc
.SelectObject(bitmap
);
818 dc
.SetBrush(on
? *wxGREEN_BRUSH
: *wxRED_BRUSH
);
819 dc
.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT
);
821 dc
.DrawEllipse(0, 0, BMP_BUTTON_SIZE_X
, BMP_BUTTON_SIZE_Y
);
822 dc
.SelectObject(wxNullBitmap
);
827 void MyStatusBar::OnSize(wxSizeEvent
& event
)
834 // TEMPORARY HACK: TODO find a more general solution
835 #ifdef wxStatusBarGeneric
836 wxStatusBar::OnSize(event
);
840 if (!GetFieldRect(Field_Checkbox
, rect
))
847 m_checkbox
->SetSize(rect
.x
+ 2, rect
.y
+ 2, rect
.width
- 4, rect
.height
- 4);
850 GetFieldRect(Field_Bitmap
, rect
);
851 wxSize size
= m_statbmp
->GetSize();
853 m_statbmp
->Move(rect
.x
+ (rect
.width
- size
.x
) / 2,
854 rect
.y
+ (rect
.height
- size
.y
) / 2);
859 void MyStatusBar::OnButton(wxCommandEvent
& WXUNUSED(event
))
862 m_checkbox
->SetValue(!m_checkbox
->GetValue());
868 void MyStatusBar::OnToggleClock(wxCommandEvent
& WXUNUSED(event
))
873 void MyStatusBar::DoToggle()
876 if ( m_checkbox
->GetValue() )
882 #ifdef USE_STATIC_BITMAP
883 m_statbmp
->SetIcon(wxIcon(green_xpm
));
885 m_statbmp
->SetBitmapLabel(CreateBitmapForButton(false));
886 m_statbmp
->Refresh();
891 else // don't show clock
897 #ifdef USE_STATIC_BITMAP
898 m_statbmp
->SetIcon(wxIcon(red_xpm
));
900 m_statbmp
->SetBitmapLabel(CreateBitmapForButton(true));
901 m_statbmp
->Refresh();
904 SetStatusText(wxEmptyString
, Field_Clock
);
909 void MyStatusBar::UpdateClock()
911 SetStatusText(wxDateTime::Now().FormatTime(), Field_Clock
);