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
70 static const char *SAMPLE_DIALOGS_TITLE
= "wxWidgets statbar sample";
72 // ----------------------------------------------------------------------------
74 // ----------------------------------------------------------------------------
76 #ifdef USE_STATIC_BITMAP
79 #endif // USE_STATIC_BITMAP
81 // ----------------------------------------------------------------------------
83 // ----------------------------------------------------------------------------
85 // Define a new application type, each program should derive a class from wxApp
86 class MyApp
: public wxApp
89 // override base class virtuals
90 // ----------------------------
92 // this one is called on application startup and is a good place for the app
93 // initialization (doing it here and not in the ctor allows to have an error
94 // return: if OnInit() returns false, the application terminates)
95 virtual bool OnInit();
98 // A custom status bar which contains controls, icons &c
99 class MyStatusBar
: public wxStatusBar
102 MyStatusBar(wxWindow
*parent
, long style
= wxSTB_DEFAULT_STYLE
);
103 virtual ~MyStatusBar();
109 void OnTimer(wxTimerEvent
& WXUNUSED(event
)) { UpdateClock(); }
111 void OnSize(wxSizeEvent
& event
);
112 void OnToggleClock(wxCommandEvent
& event
);
113 void OnButton(wxCommandEvent
& event
);
116 // toggle the state of the status bar controls
119 wxBitmap
CreateBitmapForButton(bool on
= false);
135 wxCheckBox
*m_checkbox
;
137 #ifdef USE_STATIC_BITMAP
138 wxStaticBitmap
*m_statbmp
;
140 wxBitmapButton
*m_statbmp
;
143 DECLARE_EVENT_TABLE()
146 // Define a new frame type: this is going to be our main frame
147 class MyFrame
: public wxFrame
151 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
152 #ifdef USE_MDI_PARENT_FRAME
153 class MyFrame
: public wxMDIParentFrame
158 // event handlers (these functions should _not_ be virtual)
159 void OnQuit(wxCommandEvent
& event
);
160 void OnAbout(wxCommandEvent
& event
);
162 void OnSetStatusField(wxCommandEvent
& event
);
163 void OnSetStatusText(wxCommandEvent
& event
);
165 void OnResetFieldsWidth(wxCommandEvent
& event
);
166 void OnSetStatusFields(wxCommandEvent
& event
);
167 void OnSetStatusFont(wxCommandEvent
& event
);
168 void OnRecreateStatusBar(wxCommandEvent
& event
);
170 void OnSetPaneStyle(wxCommandEvent
& event
);
171 void OnSetStyle(wxCommandEvent
& event
);
182 void OnUpdateForDefaultStatusbar(wxUpdateUIEvent
& event
);
183 void OnUpdateStatusBarToggle(wxUpdateUIEvent
& event
);
184 void OnUpdateSetPaneStyle(wxUpdateUIEvent
& event
);
185 void OnUpdateSetStyle(wxUpdateUIEvent
& event
);
186 void OnStatusBarToggle(wxCommandEvent
& event
);
187 void DoCreateStatusBar(StatusBarKind kind
, long style
);
188 void ApplyPaneStyle();
190 int m_statbarPaneStyle
;
192 // the index of the field used by some commands
195 // any class wishing to process wxWidgets events must use this macro
196 DECLARE_EVENT_TABLE()
199 // Our about dialog ith its status bar
200 class MyAboutDialog
: public wxDialog
203 MyAboutDialog(wxWindow
*parent
);
206 // ----------------------------------------------------------------------------
208 // ----------------------------------------------------------------------------
210 // IDs for the controls and the menu commands
214 StatusBar_Quit
= wxID_EXIT
,
215 StatusBar_About
= wxID_ABOUT
,
217 StatusBar_SetFields
= wxID_HIGHEST
+1,
221 StatusBar_ResetFieldsWidth
,
226 StatusBar_SetPaneStyle
,
227 StatusBar_SetPaneStyleNormal
,
228 StatusBar_SetPaneStyleFlat
,
229 StatusBar_SetPaneStyleRaised
,
231 StatusBar_SetStyleSizeGrip
,
232 StatusBar_SetStyleEllipsizeStart
,
233 StatusBar_SetStyleEllipsizeMiddle
,
234 StatusBar_SetStyleEllipsizeEnd
,
235 StatusBar_SetStyleShowTips
238 static const int BITMAP_SIZE_X
= 32;
239 static const int BITMAP_SIZE_Y
= 15;
241 // ----------------------------------------------------------------------------
242 // event tables and other macros for wxWidgets
243 // ----------------------------------------------------------------------------
245 // the event tables connect the wxWidgets events with the functions (event
246 // handlers) which process them. It can be also done at run-time, but for the
247 // simple menu events like this the static method is much simpler.
248 #ifdef USE_MDI_PARENT_FRAME
249 BEGIN_EVENT_TABLE(MyFrame
, wxMDIParentFrame
)
251 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
253 EVT_MENU(StatusBar_Quit
, MyFrame::OnQuit
)
254 EVT_MENU(StatusBar_SetFields
, MyFrame::OnSetStatusFields
)
255 EVT_MENU(StatusBar_SetField
, MyFrame::OnSetStatusField
)
256 EVT_MENU(StatusBar_SetText
, MyFrame::OnSetStatusText
)
257 EVT_MENU(StatusBar_SetFont
, MyFrame::OnSetStatusFont
)
258 EVT_MENU(StatusBar_ResetFieldsWidth
, MyFrame::OnResetFieldsWidth
)
259 EVT_MENU(StatusBar_Recreate
, MyFrame::OnRecreateStatusBar
)
260 EVT_MENU(StatusBar_About
, MyFrame::OnAbout
)
261 EVT_MENU(StatusBar_Toggle
, MyFrame::OnStatusBarToggle
)
262 EVT_MENU(StatusBar_SetPaneStyleNormal
, MyFrame::OnSetPaneStyle
)
263 EVT_MENU(StatusBar_SetPaneStyleFlat
, MyFrame::OnSetPaneStyle
)
264 EVT_MENU(StatusBar_SetPaneStyleRaised
, MyFrame::OnSetPaneStyle
)
266 EVT_MENU(StatusBar_SetStyleSizeGrip
, MyFrame::OnSetStyle
)
267 EVT_MENU(StatusBar_SetStyleEllipsizeStart
, MyFrame::OnSetStyle
)
268 EVT_MENU(StatusBar_SetStyleEllipsizeMiddle
, MyFrame::OnSetStyle
)
269 EVT_MENU(StatusBar_SetStyleEllipsizeEnd
, MyFrame::OnSetStyle
)
270 EVT_MENU(StatusBar_SetStyleShowTips
, MyFrame::OnSetStyle
)
272 EVT_UPDATE_UI_RANGE(StatusBar_SetFields
, StatusBar_ResetFieldsWidth
,
273 MyFrame::OnUpdateForDefaultStatusbar
)
274 EVT_UPDATE_UI(StatusBar_Toggle
, MyFrame::OnUpdateStatusBarToggle
)
275 EVT_UPDATE_UI_RANGE(StatusBar_SetPaneStyleNormal
, StatusBar_SetPaneStyleRaised
,
276 MyFrame::OnUpdateSetPaneStyle
)
277 EVT_UPDATE_UI_RANGE(StatusBar_SetStyleSizeGrip
, StatusBar_SetStyleShowTips
,
278 MyFrame::OnUpdateSetStyle
)
281 BEGIN_EVENT_TABLE(MyStatusBar
, wxStatusBar
)
282 EVT_SIZE(MyStatusBar::OnSize
)
284 EVT_CHECKBOX(StatusBar_Checkbox
, MyStatusBar::OnToggleClock
)
286 EVT_BUTTON(wxID_ANY
, MyStatusBar::OnButton
)
288 EVT_TIMER(wxID_ANY
, MyStatusBar::OnTimer
)
292 // Create a new application object: this macro will allow wxWidgets to create
293 // the application object during program execution (it's better than using a
294 // static object for many reasons) and also declares the accessor function
295 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
299 // ============================================================================
301 // ============================================================================
303 // ----------------------------------------------------------------------------
304 // the application class
305 // ----------------------------------------------------------------------------
307 // `Main program' equivalent: the program execution "starts" here
310 if ( !wxApp::OnInit() )
313 // create the main application window
314 MyFrame
*frame
= new MyFrame(wxT("wxStatusBar sample"),
315 wxPoint(50, 50), wxSize(450, 340));
317 // and show it (the frames, unlike simple controls, are not shown when
318 // created initially)
321 // success: wxApp::OnRun() will be called which will enter the main message
322 // loop and the application will run. If we returned 'false' here, the
323 // application would exit immediately.
327 // ----------------------------------------------------------------------------
329 // ----------------------------------------------------------------------------
332 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
333 #ifdef USE_MDI_PARENT_FRAME
334 : wxMDIParentFrame((wxWindow
*)NULL
, wxID_ANY
, title
, pos
, size
)
336 : wxFrame((wxWindow
*)NULL
, wxID_ANY
, title
, pos
, size
)
339 SetIcon(wxICON(sample
));
341 m_statbarPaneStyle
= wxSB_NORMAL
;
345 // we need this in order to allow the about menu relocation, since ABOUT is
346 // not the default id of the about menu
347 wxApp::s_macAboutMenuItemId
= StatusBar_About
;
351 wxMenu
*menuFile
= new wxMenu
;
352 menuFile
->Append(StatusBar_Quit
, wxT("E&xit\tAlt-X"), wxT("Quit this program"));
354 wxMenu
*statbarMenu
= new wxMenu
;
356 wxMenu
*statbarStyleMenu
= new wxMenu
;
357 statbarStyleMenu
->Append(StatusBar_SetStyleSizeGrip
, wxT("wxSTB_SIZE_GRIP"), wxT("Toggles the wxSTB_SIZE_GRIP style"), true);
358 statbarStyleMenu
->Append(StatusBar_SetStyleShowTips
, wxT("wxSTB_SHOW_TIPS"), wxT("Toggles the wxSTB_SHOW_TIPS style"), true);
359 statbarStyleMenu
->AppendSeparator();
360 statbarStyleMenu
->Append(StatusBar_SetStyleEllipsizeStart
, wxT("wxSTB_ELLIPSIZE_START"), wxT("Toggles the wxSTB_ELLIPSIZE_START style"), true);
361 statbarStyleMenu
->Append(StatusBar_SetStyleEllipsizeMiddle
, wxT("wxSTB_ELLIPSIZE_MIDDLE"), wxT("Toggles the wxSTB_ELLIPSIZE_MIDDLE style"), true);
362 statbarStyleMenu
->Append(StatusBar_SetStyleEllipsizeEnd
, wxT("wxSTB_ELLIPSIZE_END"), wxT("Toggles the wxSTB_ELLIPSIZE_END style"), true);
363 statbarMenu
->Append(StatusBar_SetPaneStyle
, wxT("Status bar style"), statbarStyleMenu
);
364 statbarMenu
->AppendSeparator();
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."));
370 statbarMenu
->AppendSeparator();
372 statbarMenu
->Append(StatusBar_SetFields
, wxT("&Set field count\tCtrl-C"),
373 wxT("Set the number of status bar fields"));
374 statbarMenu
->Append(StatusBar_SetFont
, wxT("&Set field font\tCtrl-F"),
375 wxT("Set the font to use for rendering status bar fields"));
377 wxMenu
*statbarPaneStyleMenu
= new wxMenu
;
378 statbarPaneStyleMenu
->Append(StatusBar_SetPaneStyleNormal
, wxT("&Normal"), wxT("Sets the style of the first field to normal (sunken) look"), true);
379 statbarPaneStyleMenu
->Append(StatusBar_SetPaneStyleFlat
, wxT("&Flat"), wxT("Sets the style of the first field to flat look"), true);
380 statbarPaneStyleMenu
->Append(StatusBar_SetPaneStyleRaised
, wxT("&Raised"), wxT("Sets the style of the first field to raised look"), true);
381 statbarMenu
->Append(StatusBar_SetPaneStyle
, wxT("Field style"), statbarPaneStyleMenu
);
383 statbarMenu
->Append(StatusBar_ResetFieldsWidth
, wxT("Reset field widths"),
384 wxT("Sets all fields to the same width"));
385 statbarMenu
->AppendSeparator();
387 statbarMenu
->Append(StatusBar_Toggle
, wxT("&Toggle Status Bar"),
388 wxT("Toggle the status bar display"), true);
389 statbarMenu
->Append(StatusBar_Recreate
, wxT("&Recreate\tCtrl-R"),
390 wxT("Toggle status bar format"));
392 wxMenu
*helpMenu
= new wxMenu
;
393 helpMenu
->Append(StatusBar_About
, wxT("&About...\tCtrl-A"), wxT("Show about dialog"));
395 // now append the freshly created menu to the menu bar...
396 wxMenuBar
*menuBar
= new wxMenuBar();
397 menuBar
->Append(menuFile
, wxT("&File"));
398 menuBar
->Append(statbarMenu
, wxT("&Status bar"));
399 menuBar
->Append(helpMenu
, wxT("&Help"));
401 // ... and attach this menu bar to the frame
404 // create default status bar to start with
405 DoCreateStatusBar(StatBar_Default
, wxSTB_DEFAULT_STYLE
);
406 SetStatusText(wxT("Welcome to wxWidgets!"));
413 void MyFrame::DoCreateStatusBar(MyFrame::StatusBarKind kind
, long style
)
415 wxStatusBar
*statbarOld
= GetStatusBar();
422 wxStatusBar
*statbarNew
= NULL
;
425 case StatBar_Default
:
426 statbarNew
= new wxStatusBar(this, wxID_ANY
, style
, "wxStatusBar");
427 statbarNew
->SetFieldsCount(2);
431 statbarNew
= new MyStatusBar(this, style
);
435 wxFAIL_MSG(wxT("unknown status bar kind"));
438 SetStatusBar(statbarNew
);
442 m_statbarKind
= kind
;
446 // ----------------------------------------------------------------------------
447 // main frame - event handlers
448 // ----------------------------------------------------------------------------
450 void MyFrame::OnUpdateForDefaultStatusbar(wxUpdateUIEvent
& event
)
452 // only allow this feature for the default status bar
453 wxStatusBar
*sb
= GetStatusBar();
457 event
.Enable(sb
->GetName() == "wxStatusBar");
460 void MyFrame::OnSetStatusField(wxCommandEvent
& WXUNUSED(event
))
462 wxStatusBar
*sb
= GetStatusBar();
466 long rc
= wxGetNumberFromUser
468 "Configure the field index to be used by the set, push "
469 "and pop text commands in the menu.\n"
471 "0 corresponds to the first field, 1 to the second one "
474 SAMPLE_DIALOGS_TITLE
,
477 sb
->GetFieldsCount() - 1,
486 wxLogStatus("Status bar text will be set for field #%d", m_field
);
489 void MyFrame::OnSetStatusText(wxCommandEvent
& WXUNUSED(event
))
491 wxStatusBar
*sb
= GetStatusBar();
495 wxString txt
= wxGetTextFromUser
499 "Enter the text from for the field #%d",
502 SAMPLE_DIALOGS_TITLE
,
503 sb
->GetStatusText(m_field
),
510 sb
->SetStatusText(txt
, m_field
);
513 void MyFrame::OnSetStatusFont(wxCommandEvent
& WXUNUSED(event
))
515 wxStatusBar
*sb
= GetStatusBar();
519 wxFont fnt
= wxGetFontFromUser(this, sb
->GetFont(), "Choose statusbar font");
523 sb
->SetSize(sb
->GetBestSize());
527 void MyFrame::OnSetStatusFields(wxCommandEvent
& WXUNUSED(event
))
529 wxStatusBar
*sb
= GetStatusBar();
533 long nFields
= wxGetNumberFromUser
535 wxT("Select the number of fields in the status bar"),
537 SAMPLE_DIALOGS_TITLE
,
538 sb
->GetFieldsCount(),
543 // we don't check if the number changed at all on purpose: calling
544 // SetFieldsCount() with the same number of fields should be ok
547 static const int widthsFor2Fields
[] = { 200, -1 };
548 static const int widthsFor3Fields
[] = { -1, -2, -1 };
549 static const int widthsFor4Fields
[] = { 100, -1, 100, -2, 100 };
551 static const int *widthsAll
[] =
553 NULL
, // 1 field: default
554 widthsFor2Fields
, // 2 fields: 1 fixed, 1 var
555 widthsFor3Fields
, // 3 fields: 3 var
556 widthsFor4Fields
, // 4 fields: 3 fixed, 2 vars
557 NULL
// 5 fields: default (all have same width)
560 const int * const widths
= widthsAll
[nFields
- 1];
561 sb
->SetFieldsCount(nFields
, widths
);
564 for ( long n
= 0; n
< nFields
; n
++ )
569 s
.Printf(wxT("fixed (%d)"), widths
[n
]);
571 s
.Printf(wxT("variable (*%d)"), -widths
[n
]);
581 if ( m_field
>= nFields
)
582 m_field
= nFields
- 1;
586 wxLogStatus(this, wxT("Cancelled"));
590 void MyFrame::OnResetFieldsWidth(wxCommandEvent
& WXUNUSED(event
))
592 wxStatusBar
*pStat
= GetStatusBar();
596 int n
= pStat
->GetFieldsCount();
597 pStat
->SetStatusWidths(n
, NULL
);
598 for (int i
=0; i
<n
; i
++)
599 pStat
->SetStatusText("same size", i
);
602 void MyFrame::OnUpdateStatusBarToggle(wxUpdateUIEvent
& event
)
604 event
.Check(GetStatusBar() != NULL
);
607 void MyFrame::OnStatusBarToggle(wxCommandEvent
& WXUNUSED(event
))
609 wxStatusBar
*statbarOld
= GetStatusBar();
617 DoCreateStatusBar(m_statbarKind
, wxSTB_DEFAULT_STYLE
);
621 void MyFrame::OnRecreateStatusBar(wxCommandEvent
& WXUNUSED(event
))
623 DoCreateStatusBar(m_statbarKind
== StatBar_Custom
? StatBar_Default
625 wxSTB_DEFAULT_STYLE
);
628 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
630 // true is to force the frame to close
634 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
636 MyAboutDialog
dlg(this);
640 void MyFrame::OnUpdateSetPaneStyle(wxUpdateUIEvent
& event
)
642 switch (event
.GetId())
644 case StatusBar_SetPaneStyleNormal
:
645 event
.Check(m_statbarPaneStyle
== wxSB_NORMAL
);
647 case StatusBar_SetPaneStyleFlat
:
648 event
.Check(m_statbarPaneStyle
== wxSB_FLAT
);
650 case StatusBar_SetPaneStyleRaised
:
651 event
.Check(m_statbarPaneStyle
== wxSB_RAISED
);
656 void MyFrame::OnSetPaneStyle(wxCommandEvent
& event
)
658 switch (event
.GetId())
660 case StatusBar_SetPaneStyleNormal
:
661 m_statbarPaneStyle
= wxSB_NORMAL
;
663 case StatusBar_SetPaneStyleFlat
:
664 m_statbarPaneStyle
= wxSB_FLAT
;
666 case StatusBar_SetPaneStyleRaised
:
667 m_statbarPaneStyle
= wxSB_RAISED
;
674 void MyFrame::ApplyPaneStyle()
676 wxStatusBar
*sb
= GetStatusBar();
680 int fields
= sb
->GetFieldsCount();
681 int *styles
= new int[fields
];
683 for (int i
= 1; i
< fields
; i
++)
684 styles
[i
] = wxSB_NORMAL
;
686 styles
[0] = m_statbarPaneStyle
;
688 sb
->SetStatusStyles(fields
, styles
);
693 void MyFrame::OnUpdateSetStyle(wxUpdateUIEvent
& event
)
695 long currentStyle
= wxSTB_DEFAULT_STYLE
;
697 currentStyle
= GetStatusBar()->GetWindowStyle();
699 switch (event
.GetId())
701 case StatusBar_SetStyleSizeGrip
:
702 event
.Check((currentStyle
& wxSTB_SIZEGRIP
) != 0);
704 case StatusBar_SetStyleShowTips
:
705 event
.Check((currentStyle
& wxSTB_SHOW_TIPS
) != 0);
708 case StatusBar_SetStyleEllipsizeStart
:
709 event
.Check((currentStyle
& wxSTB_ELLIPSIZE_START
) != 0);
711 case StatusBar_SetStyleEllipsizeMiddle
:
712 event
.Check((currentStyle
& wxSTB_ELLIPSIZE_MIDDLE
) != 0);
714 case StatusBar_SetStyleEllipsizeEnd
:
715 event
.Check((currentStyle
& wxSTB_ELLIPSIZE_END
) != 0);
720 void MyFrame::OnSetStyle(wxCommandEvent
& event
)
722 long oldStyle
= wxSTB_DEFAULT_STYLE
;
724 oldStyle
= GetStatusBar()->GetWindowStyle();
726 #define STB_ELLIPSIZE_MASK (wxSTB_ELLIPSIZE_START|wxSTB_ELLIPSIZE_MIDDLE|wxSTB_ELLIPSIZE_END)
728 long newStyle
= oldStyle
;
729 long newStyleBit
= 0;
730 switch (event
.GetId())
732 case StatusBar_SetStyleSizeGrip
:
733 newStyleBit
= wxSTB_SIZEGRIP
;
735 case StatusBar_SetStyleShowTips
:
736 newStyleBit
= wxSTB_SHOW_TIPS
;
739 case StatusBar_SetStyleEllipsizeStart
:
740 newStyleBit
= wxSTB_ELLIPSIZE_START
;
741 newStyle
&= ~STB_ELLIPSIZE_MASK
;
743 case StatusBar_SetStyleEllipsizeMiddle
:
744 newStyleBit
= wxSTB_ELLIPSIZE_MIDDLE
;
745 newStyle
&= ~STB_ELLIPSIZE_MASK
;
747 case StatusBar_SetStyleEllipsizeEnd
:
748 newStyleBit
= wxSTB_ELLIPSIZE_END
;
749 newStyle
&= ~STB_ELLIPSIZE_MASK
;
753 newStyle
= event
.IsChecked() ? (newStyle
| newStyleBit
) :
754 (newStyle
& ~newStyleBit
);
755 if (newStyle
!= oldStyle
)
757 DoCreateStatusBar(m_statbarKind
, newStyle
);
758 SetStatusText("Status bar recreated with a new style");
762 // ----------------------------------------------------------------------------
764 // ----------------------------------------------------------------------------
766 MyAboutDialog::MyAboutDialog(wxWindow
*parent
)
767 : wxDialog(parent
, wxID_ANY
, wxString(wxT("About statbar")),
768 wxDefaultPosition
, wxDefaultSize
,
769 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
771 wxStaticText
*text
= new wxStaticText(this, wxID_ANY
,
772 wxT("wxStatusBar sample\n")
773 wxT("(c) 2000 Vadim Zeitlin"));
775 wxButton
*btn
= new wxButton(this, wxID_OK
, wxT("&Close"));
777 // create the top status bar without the size grip (default style),
778 // otherwise it looks weird
779 wxStatusBar
*statbarTop
= new wxStatusBar(this, wxID_ANY
, 0);
780 statbarTop
->SetFieldsCount(3);
781 statbarTop
->SetStatusText(wxT("This is a top status bar"), 0);
782 statbarTop
->SetStatusText(wxT("in a dialog"), 1);
783 statbarTop
->SetStatusText(wxT("Great, isn't it?"), 2);
785 wxStatusBar
*statbarBottom
= new wxStatusBar(this, wxID_ANY
);
786 statbarBottom
->SetFieldsCount(2);
787 statbarBottom
->SetStatusText(wxT("This is a bottom status bar"), 0);
788 statbarBottom
->SetStatusText(wxT("in a dialog"), 1);
790 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
791 sizerTop
->Add(statbarTop
, 0, wxGROW
);
792 sizerTop
->Add(-1, 10, 1, wxGROW
);
793 sizerTop
->Add(text
, 0, wxCENTRE
| wxRIGHT
| wxLEFT
, 20);
794 sizerTop
->Add(-1, 10, 1, wxGROW
);
795 sizerTop
->Add(btn
, 0, wxCENTRE
| wxRIGHT
| wxLEFT
, 20);
796 sizerTop
->Add(-1, 10, 1, wxGROW
);
797 sizerTop
->Add(statbarBottom
, 0, wxGROW
);
799 SetSizerAndFit(sizerTop
);
802 // ----------------------------------------------------------------------------
804 // ----------------------------------------------------------------------------
807 // 'this' : used in base member initializer list -- so what??
808 #pragma warning(disable: 4355)
811 MyStatusBar::MyStatusBar(wxWindow
*parent
, long style
)
812 : wxStatusBar(parent
, wxID_ANY
, style
, "MyStatusBar")
820 static const int widths
[Field_Max
] = { -1, 150, BITMAP_SIZE_X
, 100 };
822 SetFieldsCount(Field_Max
);
823 SetStatusWidths(Field_Max
, widths
);
826 m_checkbox
= new wxCheckBox(this, StatusBar_Checkbox
, wxT("&Toggle clock"));
827 m_checkbox
->SetValue(true);
830 #ifdef USE_STATIC_BITMAP
831 m_statbmp
= new wxStaticBitmap(this, wxID_ANY
, wxIcon(green_xpm
));
833 m_statbmp
= new wxBitmapButton(this, wxID_ANY
, CreateBitmapForButton(),
834 wxDefaultPosition
, wxDefaultSize
,
842 SetMinHeight(wxMax(m_statbmp
->GetBestSize().GetHeight(),
843 m_checkbox
->GetBestSize().GetHeight()));
849 #pragma warning(default: 4355)
852 MyStatusBar::~MyStatusBar()
855 if ( m_timer
.IsRunning() )
862 #define BMP_BUTTON_SIZE_X 10
863 #define BMP_BUTTON_SIZE_Y 10
865 wxBitmap
MyStatusBar::CreateBitmapForButton(bool on
)
867 wxBitmap
bitmap(BMP_BUTTON_SIZE_X
+1, BMP_BUTTON_SIZE_Y
+1);
869 dc
.SelectObject(bitmap
);
870 dc
.SetBrush(on
? *wxGREEN_BRUSH
: *wxRED_BRUSH
);
871 dc
.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT
);
873 dc
.DrawEllipse(0, 0, BMP_BUTTON_SIZE_X
, BMP_BUTTON_SIZE_Y
);
874 dc
.SelectObject(wxNullBitmap
);
879 void MyStatusBar::OnSize(wxSizeEvent
& event
)
886 // TEMPORARY HACK: TODO find a more general solution
887 #ifdef wxStatusBarGeneric
888 wxStatusBar::OnSize(event
);
892 if (!GetFieldRect(Field_Checkbox
, rect
))
899 m_checkbox
->SetSize(rect
.x
+ 2, rect
.y
+ 2, rect
.width
- 4, rect
.height
- 4);
902 GetFieldRect(Field_Bitmap
, rect
);
903 wxSize size
= m_statbmp
->GetSize();
905 m_statbmp
->Move(rect
.x
+ (rect
.width
- size
.x
) / 2,
906 rect
.y
+ (rect
.height
- size
.y
) / 2);
911 void MyStatusBar::OnButton(wxCommandEvent
& WXUNUSED(event
))
914 m_checkbox
->SetValue(!m_checkbox
->GetValue());
920 void MyStatusBar::OnToggleClock(wxCommandEvent
& WXUNUSED(event
))
925 void MyStatusBar::DoToggle()
928 if ( m_checkbox
->GetValue() )
934 #ifdef USE_STATIC_BITMAP
935 m_statbmp
->SetIcon(wxIcon(green_xpm
));
937 m_statbmp
->SetBitmapLabel(CreateBitmapForButton(false));
938 m_statbmp
->Refresh();
943 else // don't show clock
949 #ifdef USE_STATIC_BITMAP
950 m_statbmp
->SetIcon(wxIcon(red_xpm
));
952 m_statbmp
->SetBitmapLabel(CreateBitmapForButton(true));
953 m_statbmp
->Refresh();
956 SetStatusText(wxEmptyString
, Field_Clock
);
961 void MyStatusBar::UpdateClock()
963 SetStatusText(wxDateTime::Now().FormatTime(), Field_Clock
);