1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxStatusBar sample
4 // Author: Vadim Zeitlin
6 // Copyright: (c) Vadim Zeitlin
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // ============================================================================
12 // ============================================================================
14 // ----------------------------------------------------------------------------
16 // ----------------------------------------------------------------------------
18 // For compilers that support precompilation, includes "wx/wx.h".
19 #include "wx/wxprec.h"
26 #error "You need to set wxUSE_STATUSBAR to 1 to compile this sample"
27 #endif // wxUSE_STATUSBAR
29 // for all others, include the necessary headers
32 #include "wx/dcclient.h"
35 #include "wx/statusbr.h"
37 #include "wx/checkbox.h"
38 #include "wx/statbmp.h"
40 #include "wx/msgdlg.h"
41 #include "wx/textdlg.h"
43 #include "wx/stattext.h"
44 #include "wx/bmpbuttn.h"
45 #include "wx/dcmemory.h"
48 #include "wx/datetime.h"
49 #include "wx/numdlg.h"
50 #include "wx/fontdlg.h"
52 #ifndef wxHAS_IMAGES_IN_RESOURCES
53 #include "../sample.xpm"
56 //#define USE_MDI_PARENT_FRAME 1
57 #ifdef USE_MDI_PARENT_FRAME
59 #endif // USE_MDI_PARENT_FRAME
61 static const char *SAMPLE_DIALOGS_TITLE
= "wxWidgets statbar sample";
63 // ----------------------------------------------------------------------------
65 // ----------------------------------------------------------------------------
70 // ----------------------------------------------------------------------------
72 // ----------------------------------------------------------------------------
74 // Define a new application type, each program should derive a class from wxApp
75 class MyApp
: public wxApp
78 // override base class virtuals
79 // ----------------------------
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();
87 // A custom status bar which contains controls, icons &c
88 class MyStatusBar
: public wxStatusBar
91 MyStatusBar(wxWindow
*parent
, long style
= wxSTB_DEFAULT_STYLE
);
92 virtual ~MyStatusBar();
98 void OnTimer(wxTimerEvent
& WXUNUSED(event
)) { UpdateClock(); }
100 void OnSize(wxSizeEvent
& event
);
101 void OnToggleClock(wxCommandEvent
& event
);
102 void OnIdle(wxIdleEvent
& event
);
105 // toggle the state of the status bar controls
113 Field_NumLockIndicator
,
115 Field_CapsLockIndicator
,
124 wxCheckBox
*m_checkbox
;
126 wxStaticBitmap
*m_statbmp
;
128 DECLARE_EVENT_TABLE()
131 // Define a new frame type: this is going to be our main frame
132 #ifdef USE_MDI_PARENT_FRAME
133 class MyFrame
: public wxMDIParentFrame
135 class MyFrame
: public wxFrame
140 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
142 // event handlers (these functions should _not_ be virtual)
143 void OnQuit(wxCommandEvent
& event
);
144 void OnAbout(wxCommandEvent
& event
);
146 void OnSetStatusField(wxCommandEvent
& event
);
147 void OnSetStatusText(wxCommandEvent
& event
);
148 void OnPushStatusText(wxCommandEvent
& event
);
149 void OnPopStatusText(wxCommandEvent
& event
);
151 void OnResetFieldsWidth(wxCommandEvent
& event
);
152 void OnShowFieldsRect(wxCommandEvent
& event
);
153 void OnSetStatusFields(wxCommandEvent
& event
);
154 void OnSetStatusFont(wxCommandEvent
& event
);
155 void OnRecreateStatusBar(wxCommandEvent
& event
);
157 void OnSetPaneStyle(wxCommandEvent
& event
);
158 void OnSetStyle(wxCommandEvent
& event
);
169 void OnUpdateForDefaultStatusbar(wxUpdateUIEvent
& event
);
170 void OnUpdateStatusBarToggle(wxUpdateUIEvent
& event
);
171 void OnUpdateSetPaneStyle(wxUpdateUIEvent
& event
);
172 void OnUpdateSetStyle(wxUpdateUIEvent
& event
);
173 void OnStatusBarToggle(wxCommandEvent
& event
);
174 void DoCreateStatusBar(StatusBarKind kind
, long style
);
175 void ApplyPaneStyle();
177 int m_statbarPaneStyle
;
179 // the index of the field used by some commands
182 // any class wishing to process wxWidgets events must use this macro
183 DECLARE_EVENT_TABLE()
186 // Our about dialog ith its status bar
187 class MyAboutDialog
: public wxDialog
190 MyAboutDialog(wxWindow
*parent
);
193 // ----------------------------------------------------------------------------
195 // ----------------------------------------------------------------------------
197 // IDs for the controls and the menu commands
201 StatusBar_Quit
= wxID_EXIT
,
202 StatusBar_About
= wxID_ABOUT
,
204 StatusBar_SetFields
= wxID_HIGHEST
+1,
210 StatusBar_ResetFieldsWidth
,
211 StatusBar_ShowFieldsRect
,
216 StatusBar_SetPaneStyle
,
217 StatusBar_SetPaneStyleNormal
,
218 StatusBar_SetPaneStyleFlat
,
219 StatusBar_SetPaneStyleRaised
,
220 StatusBar_SetPaneStyleSunken
,
222 StatusBar_SetStyleSizeGrip
,
223 StatusBar_SetStyleEllipsizeStart
,
224 StatusBar_SetStyleEllipsizeMiddle
,
225 StatusBar_SetStyleEllipsizeEnd
,
226 StatusBar_SetStyleShowTips
229 static const int BITMAP_SIZE_X
= 32;
230 static const int BITMAP_SIZE_Y
= 15;
232 // ----------------------------------------------------------------------------
233 // event tables and other macros for wxWidgets
234 // ----------------------------------------------------------------------------
236 // the event tables connect the wxWidgets events with the functions (event
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.
239 #ifdef USE_MDI_PARENT_FRAME
240 BEGIN_EVENT_TABLE(MyFrame
, wxMDIParentFrame
)
242 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
244 EVT_MENU(StatusBar_Quit
, MyFrame::OnQuit
)
245 EVT_MENU(StatusBar_SetFields
, MyFrame::OnSetStatusFields
)
246 EVT_MENU(StatusBar_SetField
, MyFrame::OnSetStatusField
)
247 EVT_MENU(StatusBar_SetText
, MyFrame::OnSetStatusText
)
248 EVT_MENU(StatusBar_PushText
, MyFrame::OnPushStatusText
)
249 EVT_MENU(StatusBar_PopText
, MyFrame::OnPopStatusText
)
250 EVT_MENU(StatusBar_SetFont
, MyFrame::OnSetStatusFont
)
251 EVT_MENU(StatusBar_ResetFieldsWidth
, MyFrame::OnResetFieldsWidth
)
252 EVT_MENU(StatusBar_ShowFieldsRect
, MyFrame::OnShowFieldsRect
)
253 EVT_MENU(StatusBar_Recreate
, MyFrame::OnRecreateStatusBar
)
254 EVT_MENU(StatusBar_About
, MyFrame::OnAbout
)
255 EVT_MENU(StatusBar_Toggle
, MyFrame::OnStatusBarToggle
)
256 EVT_MENU(StatusBar_SetPaneStyleNormal
, MyFrame::OnSetPaneStyle
)
257 EVT_MENU(StatusBar_SetPaneStyleFlat
, MyFrame::OnSetPaneStyle
)
258 EVT_MENU(StatusBar_SetPaneStyleRaised
, MyFrame::OnSetPaneStyle
)
259 EVT_MENU(StatusBar_SetPaneStyleSunken
, MyFrame::OnSetPaneStyle
)
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
)
267 EVT_UPDATE_UI_RANGE(StatusBar_SetFields
, StatusBar_ResetFieldsWidth
,
268 MyFrame::OnUpdateForDefaultStatusbar
)
269 EVT_UPDATE_UI(StatusBar_Toggle
, MyFrame::OnUpdateStatusBarToggle
)
270 EVT_UPDATE_UI_RANGE(StatusBar_SetPaneStyleNormal
,
271 StatusBar_SetPaneStyleSunken
,
272 MyFrame::OnUpdateSetPaneStyle
)
273 EVT_UPDATE_UI_RANGE(StatusBar_SetStyleSizeGrip
, StatusBar_SetStyleShowTips
,
274 MyFrame::OnUpdateSetStyle
)
277 BEGIN_EVENT_TABLE(MyStatusBar
, wxStatusBar
)
278 EVT_SIZE(MyStatusBar::OnSize
)
280 EVT_CHECKBOX(StatusBar_Checkbox
, MyStatusBar::OnToggleClock
)
283 EVT_TIMER(wxID_ANY
, MyStatusBar::OnTimer
)
285 EVT_IDLE(MyStatusBar::OnIdle
)
288 // Create a new application object: this macro will allow wxWidgets to create
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
295 // ============================================================================
297 // ============================================================================
299 // ----------------------------------------------------------------------------
300 // the application class
301 // ----------------------------------------------------------------------------
303 // `Main program' equivalent: the program execution "starts" here
306 if ( !wxApp::OnInit() )
309 // create the main application window
310 MyFrame
*frame
= new MyFrame(wxT("wxStatusBar sample"),
311 wxPoint(50, 50), wxSize(450, 340));
313 // and show it (the frames, unlike simple controls, are not shown when
314 // created initially)
317 // success: wxApp::OnRun() will be called which will enter the main message
318 // loop and the application will run. If we returned 'false' here, the
319 // application would exit immediately.
323 // ----------------------------------------------------------------------------
325 // ----------------------------------------------------------------------------
328 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
329 #ifdef USE_MDI_PARENT_FRAME
330 : wxMDIParentFrame(NULL
, wxID_ANY
, title
, pos
, size
)
332 : wxFrame(NULL
, wxID_ANY
, title
, pos
, size
)
335 SetIcon(wxICON(sample
));
337 m_statbarPaneStyle
= wxSB_NORMAL
;
341 wxMenu
*menuFile
= new wxMenu
;
342 menuFile
->Append(StatusBar_Quit
, wxT("E&xit\tAlt-X"),
343 wxT("Quit this program"));
345 wxMenu
*statbarMenu
= new wxMenu
;
347 wxMenu
*statbarStyleMenu
= new wxMenu
;
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);
352 statbarStyleMenu
->AppendSeparator();
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"),
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
->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.");
374 statbarMenu
->AppendSeparator();
376 statbarMenu
->Append(StatusBar_SetFields
, wxT("&Set field count\tCtrl-C"),
377 wxT("Set the number of status bar fields"));
378 statbarMenu
->Append(StatusBar_SetFont
, wxT("&Set field font\tCtrl-F"),
379 wxT("Set the font to use for status bar fields"));
381 wxMenu
*statbarPaneStyleMenu
= new wxMenu
;
382 statbarPaneStyleMenu
->AppendCheckItem
384 StatusBar_SetPaneStyleNormal
,
386 wxT("Sets the style of the first field to normal (sunken) look")
388 statbarPaneStyleMenu
->AppendCheckItem
390 StatusBar_SetPaneStyleFlat
,
392 wxT("Sets the style of the first field to flat look")
394 statbarPaneStyleMenu
->AppendCheckItem
396 StatusBar_SetPaneStyleRaised
,
398 wxT("Sets the style of the first field to raised look")
400 statbarPaneStyleMenu
->AppendCheckItem
402 StatusBar_SetPaneStyleSunken
,
404 wxT("Sets the style of the first field to sunken look")
406 statbarMenu
->Append(StatusBar_SetPaneStyle
, wxT("Field style"),
407 statbarPaneStyleMenu
);
409 statbarMenu
->Append(StatusBar_ResetFieldsWidth
, wxT("Reset field widths"),
410 wxT("Sets all fields to the same width"));
411 statbarMenu
->Append(StatusBar_ShowFieldsRect
,
412 wxT("Sho&w field rectangles\tCtrl-W"),
413 wxT("Visually show field rectangles"));
414 statbarMenu
->AppendSeparator();
416 statbarMenu
->AppendCheckItem(StatusBar_Toggle
, wxT("&Toggle Status Bar"),
417 wxT("Toggle the status bar display"));
418 statbarMenu
->Append(StatusBar_Recreate
, wxT("&Recreate\tCtrl-R"),
419 wxT("Toggle status bar format"));
421 wxMenu
*helpMenu
= new wxMenu
;
422 helpMenu
->Append(StatusBar_About
, wxT("&About\tCtrl-A"),
423 wxT("Show about dialog"));
425 // now append the freshly created menu to the menu bar...
426 wxMenuBar
*menuBar
= new wxMenuBar();
427 menuBar
->Append(menuFile
, wxT("&File"));
428 menuBar
->Append(statbarMenu
, wxT("&Status bar"));
429 menuBar
->Append(helpMenu
, wxT("&Help"));
431 // ... and attach this menu bar to the frame
434 // create default status bar to start with
435 DoCreateStatusBar(StatBar_Default
, wxSTB_DEFAULT_STYLE
);
436 SetStatusText(wxT("Welcome to wxWidgets!"));
439 void MyFrame::DoCreateStatusBar(MyFrame::StatusBarKind kind
, long style
)
441 wxStatusBar
*statbarOld
= GetStatusBar();
448 wxStatusBar
*statbarNew
= NULL
;
451 case StatBar_Default
:
452 statbarNew
= new wxStatusBar(this, wxID_ANY
, style
, "wxStatusBar");
453 statbarNew
->SetFieldsCount(2);
457 statbarNew
= new MyStatusBar(this, style
);
461 wxFAIL_MSG(wxT("unknown status bar kind"));
464 SetStatusBar(statbarNew
);
468 m_statbarKind
= kind
;
472 // ----------------------------------------------------------------------------
473 // main frame - event handlers
474 // ----------------------------------------------------------------------------
476 void MyFrame::OnUpdateForDefaultStatusbar(wxUpdateUIEvent
& event
)
478 // only allow this feature for the default status bar
479 wxStatusBar
*sb
= GetStatusBar();
483 event
.Enable(sb
->GetName() == "wxStatusBar");
486 void MyFrame::OnSetStatusField(wxCommandEvent
& WXUNUSED(event
))
488 wxStatusBar
*sb
= GetStatusBar();
492 long rc
= wxGetNumberFromUser
494 "Configure the field index to be used by the set, push "
495 "and pop text commands in the menu.\n"
497 "0 corresponds to the first field, 1 to the second one "
500 SAMPLE_DIALOGS_TITLE
,
503 sb
->GetFieldsCount() - 1,
512 wxLogStatus("Status bar text will be set for field #%d", m_field
);
515 void MyFrame::OnSetStatusText(wxCommandEvent
& WXUNUSED(event
))
517 wxStatusBar
*sb
= GetStatusBar();
521 wxString txt
= wxGetTextFromUser
525 "Enter the text from for the field #%d",
528 SAMPLE_DIALOGS_TITLE
,
529 sb
->GetStatusText(m_field
),
536 sb
->SetStatusText(txt
, m_field
);
539 // the current depth of the stack used by Push/PopStatusText()
540 static int gs_depth
= 0;
542 void MyFrame::OnPushStatusText(wxCommandEvent
& WXUNUSED(event
))
544 wxStatusBar
*sb
= GetStatusBar();
548 static int s_countPush
= 0;
549 sb
->PushStatusText(wxString::Format
551 "Pushed message #%d (depth = %d)",
552 ++s_countPush
, ++gs_depth
556 void MyFrame::OnPopStatusText(wxCommandEvent
& WXUNUSED(event
))
558 wxStatusBar
*sb
= GetStatusBar();
564 wxLogStatus("No message to pop.");
569 sb
->PopStatusText(m_field
);
572 void MyFrame::OnSetStatusFont(wxCommandEvent
& WXUNUSED(event
))
574 wxStatusBar
*sb
= GetStatusBar();
579 fnt
= wxGetFontFromUser(this, sb
->GetFont(), "Choose status bar font");
583 sb
->SetSize(sb
->GetBestSize());
587 void MyFrame::OnSetStatusFields(wxCommandEvent
& WXUNUSED(event
))
589 wxStatusBar
*sb
= GetStatusBar();
593 long nFields
= wxGetNumberFromUser
595 wxT("Select the number of fields in the status bar"),
597 SAMPLE_DIALOGS_TITLE
,
598 sb
->GetFieldsCount(),
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
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 };
611 static const int *widthsAll
[] =
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)
620 const int * const widths
= widthsAll
[nFields
- 1];
621 sb
->SetFieldsCount(nFields
, widths
);
624 for ( long n
= 0; n
< nFields
; n
++ )
629 s
.Printf(wxT("fixed (%d)"), widths
[n
]);
631 s
.Printf(wxT("variable (*%d)"), -widths
[n
]);
641 if ( m_field
>= nFields
)
642 m_field
= nFields
- 1;
646 wxLogStatus(this, wxT("Cancelled"));
650 void MyFrame::OnResetFieldsWidth(wxCommandEvent
& WXUNUSED(event
))
652 wxStatusBar
*pStat
= GetStatusBar();
656 const int n
= pStat
->GetFieldsCount();
657 pStat
->SetStatusWidths(n
, NULL
);
658 for ( int i
= 0; i
< n
; i
++ )
659 pStat
->SetStatusText("same size", i
);
662 void MyFrame::OnShowFieldsRect(wxCommandEvent
& WXUNUSED(event
))
664 wxStatusBar
*pStat
= GetStatusBar();
668 wxClientDC
dc(pStat
);
669 dc
.SetPen(*wxRED_PEN
);
670 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
672 const int n
= pStat
->GetFieldsCount();
673 for ( int i
= 0; i
< n
; i
++ )
676 if ( pStat
->GetFieldRect(i
, r
) )
681 void MyFrame::OnUpdateStatusBarToggle(wxUpdateUIEvent
& event
)
683 event
.Check(GetStatusBar() != NULL
);
686 void MyFrame::OnStatusBarToggle(wxCommandEvent
& WXUNUSED(event
))
688 wxStatusBar
*statbarOld
= GetStatusBar();
696 DoCreateStatusBar(m_statbarKind
, wxSTB_DEFAULT_STYLE
);
700 void MyFrame::OnRecreateStatusBar(wxCommandEvent
& WXUNUSED(event
))
702 DoCreateStatusBar(m_statbarKind
== StatBar_Custom
? StatBar_Default
704 wxSTB_DEFAULT_STYLE
);
707 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
709 // true is to force the frame to close
713 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
715 MyAboutDialog
dlg(this);
719 void MyFrame::OnUpdateSetPaneStyle(wxUpdateUIEvent
& event
)
721 switch (event
.GetId())
723 case StatusBar_SetPaneStyleNormal
:
724 event
.Check(m_statbarPaneStyle
== wxSB_NORMAL
);
726 case StatusBar_SetPaneStyleFlat
:
727 event
.Check(m_statbarPaneStyle
== wxSB_FLAT
);
729 case StatusBar_SetPaneStyleRaised
:
730 event
.Check(m_statbarPaneStyle
== wxSB_RAISED
);
732 case StatusBar_SetPaneStyleSunken
:
733 event
.Check(m_statbarPaneStyle
== wxSB_SUNKEN
);
738 void MyFrame::OnSetPaneStyle(wxCommandEvent
& event
)
740 switch (event
.GetId())
742 case StatusBar_SetPaneStyleNormal
:
743 m_statbarPaneStyle
= wxSB_NORMAL
;
745 case StatusBar_SetPaneStyleFlat
:
746 m_statbarPaneStyle
= wxSB_FLAT
;
748 case StatusBar_SetPaneStyleRaised
:
749 m_statbarPaneStyle
= wxSB_RAISED
;
751 case StatusBar_SetPaneStyleSunken
:
752 m_statbarPaneStyle
= wxSB_SUNKEN
;
759 void MyFrame::ApplyPaneStyle()
761 wxStatusBar
*sb
= GetStatusBar();
765 int fields
= sb
->GetFieldsCount();
766 int *styles
= new int[fields
];
768 for (int i
= 1; i
< fields
; i
++)
769 styles
[i
] = wxSB_NORMAL
;
771 styles
[0] = m_statbarPaneStyle
;
773 sb
->SetStatusStyles(fields
, styles
);
778 void MyFrame::OnUpdateSetStyle(wxUpdateUIEvent
& event
)
780 long currentStyle
= wxSTB_DEFAULT_STYLE
;
782 currentStyle
= GetStatusBar()->GetWindowStyle();
784 switch (event
.GetId())
786 case StatusBar_SetStyleSizeGrip
:
787 event
.Check((currentStyle
& wxSTB_SIZEGRIP
) != 0);
789 case StatusBar_SetStyleShowTips
:
790 event
.Check((currentStyle
& wxSTB_SHOW_TIPS
) != 0);
793 case StatusBar_SetStyleEllipsizeStart
:
794 event
.Check((currentStyle
& wxSTB_ELLIPSIZE_START
) != 0);
796 case StatusBar_SetStyleEllipsizeMiddle
:
797 event
.Check((currentStyle
& wxSTB_ELLIPSIZE_MIDDLE
) != 0);
799 case StatusBar_SetStyleEllipsizeEnd
:
800 event
.Check((currentStyle
& wxSTB_ELLIPSIZE_END
) != 0);
805 void MyFrame::OnSetStyle(wxCommandEvent
& event
)
807 long oldStyle
= wxSTB_DEFAULT_STYLE
;
809 oldStyle
= GetStatusBar()->GetWindowStyle();
811 #define STB_ELLIPSIZE_MASK \
812 (wxSTB_ELLIPSIZE_START|wxSTB_ELLIPSIZE_MIDDLE|wxSTB_ELLIPSIZE_END)
814 long newStyle
= oldStyle
;
815 long newStyleBit
= 0;
816 switch (event
.GetId())
818 case StatusBar_SetStyleSizeGrip
:
819 newStyleBit
= wxSTB_SIZEGRIP
;
821 case StatusBar_SetStyleShowTips
:
822 newStyleBit
= wxSTB_SHOW_TIPS
;
825 case StatusBar_SetStyleEllipsizeStart
:
826 newStyleBit
= wxSTB_ELLIPSIZE_START
;
827 newStyle
&= ~STB_ELLIPSIZE_MASK
;
829 case StatusBar_SetStyleEllipsizeMiddle
:
830 newStyleBit
= wxSTB_ELLIPSIZE_MIDDLE
;
831 newStyle
&= ~STB_ELLIPSIZE_MASK
;
833 case StatusBar_SetStyleEllipsizeEnd
:
834 newStyleBit
= wxSTB_ELLIPSIZE_END
;
835 newStyle
&= ~STB_ELLIPSIZE_MASK
;
839 newStyle
= event
.IsChecked() ? (newStyle
| newStyleBit
) :
840 (newStyle
& ~newStyleBit
);
841 if (newStyle
!= oldStyle
)
843 DoCreateStatusBar(m_statbarKind
, newStyle
);
844 SetStatusText("Status bar recreated with a new style");
848 // ----------------------------------------------------------------------------
850 // ----------------------------------------------------------------------------
852 MyAboutDialog::MyAboutDialog(wxWindow
*parent
)
853 : wxDialog(parent
, wxID_ANY
, wxString(wxT("About statbar")),
854 wxDefaultPosition
, wxDefaultSize
,
855 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
857 wxStaticText
*text
= new wxStaticText(this, wxID_ANY
,
858 wxT("wxStatusBar sample\n")
859 wxT("(c) 2000 Vadim Zeitlin"));
861 wxButton
*btn
= new wxButton(this, wxID_OK
, wxT("&Close"));
863 // create the top status bar without the size grip (default style),
864 // otherwise it looks weird
865 wxStatusBar
*statbarTop
= new wxStatusBar(this, wxID_ANY
, 0);
866 statbarTop
->SetFieldsCount(3);
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);
871 wxStatusBar
*statbarBottom
= new wxStatusBar(this, wxID_ANY
);
872 statbarBottom
->SetFieldsCount(2);
873 statbarBottom
->SetStatusText(wxT("This is a bottom status bar"), 0);
874 statbarBottom
->SetStatusText(wxT("in a dialog"), 1);
876 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
877 sizerTop
->Add(statbarTop
, 0, wxGROW
);
878 sizerTop
->Add(-1, 10, 1, wxGROW
);
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);
882 sizerTop
->Add(-1, 10, 1, wxGROW
);
883 sizerTop
->Add(statbarBottom
, 0, wxGROW
);
885 SetSizerAndFit(sizerTop
);
888 // ----------------------------------------------------------------------------
890 // ----------------------------------------------------------------------------
893 // 'this' : used in base member initializer list -- so what??
894 #pragma warning(disable: 4355)
897 static const char *numlockIndicators
[] = { "OFF", "NUM" };
898 static const char *capslockIndicators
[] = { "", "CAPS" };
900 MyStatusBar::MyStatusBar(wxWindow
*parent
, long style
)
901 : wxStatusBar(parent
, wxID_ANY
, style
, "MyStatusBar")
909 // compute the size needed for num lock indicator pane
911 wxSize sizeNumLock
= dc
.GetTextExtent(numlockIndicators
[0]);
912 sizeNumLock
.IncTo(dc
.GetTextExtent(numlockIndicators
[1]));
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
;
922 SetFieldsCount(Field_Max
);
923 SetStatusWidths(Field_Max
, widths
);
926 m_checkbox
= new wxCheckBox(this, StatusBar_Checkbox
, wxT("&Toggle clock"));
927 m_checkbox
->SetValue(true);
930 m_statbmp
= new wxStaticBitmap(this, wxID_ANY
, wxIcon(green_xpm
));
936 SetMinHeight(wxMax(m_statbmp
->GetBestSize().GetHeight(),
937 m_checkbox
->GetBestSize().GetHeight()));
943 #pragma warning(default: 4355)
946 MyStatusBar::~MyStatusBar()
949 if ( m_timer
.IsRunning() )
956 void MyStatusBar::OnSize(wxSizeEvent
& event
)
964 if (!GetFieldRect(Field_Checkbox
, rect
))
971 wxRect rectCheck
= rect
;
972 rectCheck
.Deflate(2);
973 m_checkbox
->SetSize(rectCheck
);
976 GetFieldRect(Field_Bitmap
, rect
);
977 wxSize size
= m_statbmp
->GetSize();
979 m_statbmp
->Move(rect
.x
+ (rect
.width
- size
.x
) / 2,
980 rect
.y
+ (rect
.height
- size
.y
) / 2);
985 void MyStatusBar::OnToggleClock(wxCommandEvent
& WXUNUSED(event
))
990 void MyStatusBar::OnIdle(wxIdleEvent
& event
)
992 SetStatusText(numlockIndicators
[wxGetKeyState(WXK_NUMLOCK
)],
993 Field_NumLockIndicator
);
994 SetStatusText(capslockIndicators
[wxGetKeyState(WXK_CAPITAL
)],
995 Field_CapsLockIndicator
);
1000 void MyStatusBar::DoToggle()
1003 if ( m_checkbox
->GetValue() )
1006 m_timer
.Start(1000);
1009 m_statbmp
->SetIcon(wxIcon(green_xpm
));
1013 else // don't show clock
1019 m_statbmp
->SetIcon(wxIcon(red_xpm
));
1021 SetStatusText(wxEmptyString
, Field_Clock
);
1023 #endif // wxUSE_CHECKBOX
1026 void MyStatusBar::UpdateClock()
1028 SetStatusText(wxDateTime::Now().FormatTime(), Field_Clock
);