1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxStatusBar sample
4 // Author: Vadim Zeitlin
7 // Copyright: (c) Vadim Zeitlin
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx/wx.h".
20 #include "wx/wxprec.h"
27 #error "You need to set wxUSE_STATUSBAR to 1 to compile this sample"
28 #endif // wxUSE_STATUSBAR
30 // for all others, include the necessary headers
33 #include "wx/dcclient.h"
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"
57 //#define USE_MDI_PARENT_FRAME 1
58 #ifdef USE_MDI_PARENT_FRAME
60 #endif // USE_MDI_PARENT_FRAME
62 static const char *SAMPLE_DIALOGS_TITLE
= "wxWidgets statbar sample";
64 // ----------------------------------------------------------------------------
66 // ----------------------------------------------------------------------------
71 // ----------------------------------------------------------------------------
73 // ----------------------------------------------------------------------------
75 // Define a new application type, each program should derive a class from wxApp
76 class MyApp
: public wxApp
79 // override base class virtuals
80 // ----------------------------
82 // this one is called on application startup and is a good place for the app
83 // initialization (doing it here and not in the ctor allows to have an error
84 // return: if OnInit() returns false, the application terminates)
85 virtual bool OnInit();
88 // A custom status bar which contains controls, icons &c
89 class MyStatusBar
: public wxStatusBar
92 MyStatusBar(wxWindow
*parent
, long style
= wxSTB_DEFAULT_STYLE
);
93 virtual ~MyStatusBar();
99 void OnTimer(wxTimerEvent
& WXUNUSED(event
)) { UpdateClock(); }
101 void OnSize(wxSizeEvent
& event
);
102 void OnToggleClock(wxCommandEvent
& event
);
103 void OnIdle(wxIdleEvent
& event
);
106 // toggle the state of the status bar controls
114 Field_NumLockIndicator
,
116 Field_CapsLockIndicator
,
125 wxCheckBox
*m_checkbox
;
127 wxStaticBitmap
*m_statbmp
;
129 DECLARE_EVENT_TABLE()
132 // Define a new frame type: this is going to be our main frame
133 #ifdef USE_MDI_PARENT_FRAME
134 class MyFrame
: public wxMDIParentFrame
136 class MyFrame
: public wxFrame
141 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
143 // event handlers (these functions should _not_ be virtual)
144 void OnQuit(wxCommandEvent
& event
);
145 void OnAbout(wxCommandEvent
& event
);
147 void OnSetStatusField(wxCommandEvent
& event
);
148 void OnSetStatusText(wxCommandEvent
& event
);
149 void OnPushStatusText(wxCommandEvent
& event
);
150 void OnPopStatusText(wxCommandEvent
& event
);
152 void OnResetFieldsWidth(wxCommandEvent
& event
);
153 void OnShowFieldsRect(wxCommandEvent
& event
);
154 void OnSetStatusFields(wxCommandEvent
& event
);
155 void OnSetStatusFont(wxCommandEvent
& event
);
156 void OnRecreateStatusBar(wxCommandEvent
& event
);
158 void OnSetPaneStyle(wxCommandEvent
& event
);
159 void OnSetStyle(wxCommandEvent
& event
);
170 void OnUpdateForDefaultStatusbar(wxUpdateUIEvent
& event
);
171 void OnUpdateStatusBarToggle(wxUpdateUIEvent
& event
);
172 void OnUpdateSetPaneStyle(wxUpdateUIEvent
& event
);
173 void OnUpdateSetStyle(wxUpdateUIEvent
& event
);
174 void OnStatusBarToggle(wxCommandEvent
& event
);
175 void DoCreateStatusBar(StatusBarKind kind
, long style
);
176 void ApplyPaneStyle();
178 int m_statbarPaneStyle
;
180 // the index of the field used by some commands
183 // any class wishing to process wxWidgets events must use this macro
184 DECLARE_EVENT_TABLE()
187 // Our about dialog ith its status bar
188 class MyAboutDialog
: public wxDialog
191 MyAboutDialog(wxWindow
*parent
);
194 // ----------------------------------------------------------------------------
196 // ----------------------------------------------------------------------------
198 // IDs for the controls and the menu commands
202 StatusBar_Quit
= wxID_EXIT
,
203 StatusBar_About
= wxID_ABOUT
,
205 StatusBar_SetFields
= wxID_HIGHEST
+1,
211 StatusBar_ResetFieldsWidth
,
212 StatusBar_ShowFieldsRect
,
217 StatusBar_SetPaneStyle
,
218 StatusBar_SetPaneStyleNormal
,
219 StatusBar_SetPaneStyleFlat
,
220 StatusBar_SetPaneStyleRaised
,
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
)
260 EVT_MENU(StatusBar_SetStyleSizeGrip
, MyFrame::OnSetStyle
)
261 EVT_MENU(StatusBar_SetStyleEllipsizeStart
, MyFrame::OnSetStyle
)
262 EVT_MENU(StatusBar_SetStyleEllipsizeMiddle
, MyFrame::OnSetStyle
)
263 EVT_MENU(StatusBar_SetStyleEllipsizeEnd
, MyFrame::OnSetStyle
)
264 EVT_MENU(StatusBar_SetStyleShowTips
, MyFrame::OnSetStyle
)
266 EVT_UPDATE_UI_RANGE(StatusBar_SetFields
, StatusBar_ResetFieldsWidth
,
267 MyFrame::OnUpdateForDefaultStatusbar
)
268 EVT_UPDATE_UI(StatusBar_Toggle
, MyFrame::OnUpdateStatusBarToggle
)
269 EVT_UPDATE_UI_RANGE(StatusBar_SetPaneStyleNormal
,
270 StatusBar_SetPaneStyleRaised
,
271 MyFrame::OnUpdateSetPaneStyle
)
272 EVT_UPDATE_UI_RANGE(StatusBar_SetStyleSizeGrip
, StatusBar_SetStyleShowTips
,
273 MyFrame::OnUpdateSetStyle
)
276 BEGIN_EVENT_TABLE(MyStatusBar
, wxStatusBar
)
277 EVT_SIZE(MyStatusBar::OnSize
)
279 EVT_CHECKBOX(StatusBar_Checkbox
, MyStatusBar::OnToggleClock
)
282 EVT_TIMER(wxID_ANY
, MyStatusBar::OnTimer
)
284 EVT_IDLE(MyStatusBar::OnIdle
)
287 // Create a new application object: this macro will allow wxWidgets to create
288 // the application object during program execution (it's better than using a
289 // static object for many reasons) and also declares the accessor function
290 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
294 // ============================================================================
296 // ============================================================================
298 // ----------------------------------------------------------------------------
299 // the application class
300 // ----------------------------------------------------------------------------
302 // `Main program' equivalent: the program execution "starts" here
305 if ( !wxApp::OnInit() )
308 // create the main application window
309 MyFrame
*frame
= new MyFrame(wxT("wxStatusBar sample"),
310 wxPoint(50, 50), wxSize(450, 340));
312 // and show it (the frames, unlike simple controls, are not shown when
313 // created initially)
316 // success: wxApp::OnRun() will be called which will enter the main message
317 // loop and the application will run. If we returned 'false' here, the
318 // application would exit immediately.
322 // ----------------------------------------------------------------------------
324 // ----------------------------------------------------------------------------
327 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
328 #ifdef USE_MDI_PARENT_FRAME
329 : wxMDIParentFrame(NULL
, wxID_ANY
, title
, pos
, size
)
331 : wxFrame(NULL
, wxID_ANY
, title
, pos
, size
)
334 SetIcon(wxICON(sample
));
336 m_statbarPaneStyle
= wxSB_NORMAL
;
340 wxMenu
*menuFile
= new wxMenu
;
341 menuFile
->Append(StatusBar_Quit
, wxT("E&xit\tAlt-X"),
342 wxT("Quit this program"));
344 wxMenu
*statbarMenu
= new wxMenu
;
346 wxMenu
*statbarStyleMenu
= new wxMenu
;
347 statbarStyleMenu
->Append(StatusBar_SetStyleSizeGrip
, wxT("wxSTB_SIZE_GRIP"),
348 wxT("Toggles the wxSTB_SIZE_GRIP style"), true);
349 statbarStyleMenu
->Append(StatusBar_SetStyleShowTips
, wxT("wxSTB_SHOW_TIPS"),
350 wxT("Toggles the wxSTB_SHOW_TIPS style"), true);
351 statbarStyleMenu
->AppendSeparator();
352 statbarStyleMenu
->AppendCheckItem(StatusBar_SetStyleEllipsizeStart
,
353 wxT("wxSTB_ELLIPSIZE_START"),
354 wxT("Toggle wxSTB_ELLIPSIZE_START style"));
355 statbarStyleMenu
->AppendCheckItem(StatusBar_SetStyleEllipsizeMiddle
,
356 wxT("wxSTB_ELLIPSIZE_MIDDLE"),
357 wxT("Toggle wxSTB_ELLIPSIZE_MIDDLE style"));
358 statbarStyleMenu
->AppendCheckItem(StatusBar_SetStyleEllipsizeEnd
,
359 wxT("wxSTB_ELLIPSIZE_END"),
360 wxT("Toggle wxSTB_ELLIPSIZE_END style"));
361 statbarMenu
->Append(StatusBar_SetPaneStyle
, wxT("Status bar style"),
363 statbarMenu
->AppendSeparator();
365 statbarMenu
->Append(StatusBar_SetField
, "Set active field &number\tCtrl-N",
366 "Set the number of field used by the next commands.");
367 statbarMenu
->Append(StatusBar_SetText
, wxT("Set field &text\tCtrl-T"),
368 wxT("Set the text of the selected field."));
369 statbarMenu
->Append(StatusBar_PushText
, "P&ush field text\tCtrl-P",
370 "Push a message on top the selected field.");
371 statbarMenu
->Append(StatusBar_PopText
, "&Pop field text\tShift-Ctrl-P",
372 "Restore the previous contents of the selected field.");
373 statbarMenu
->AppendSeparator();
375 statbarMenu
->Append(StatusBar_SetFields
, wxT("&Set field count\tCtrl-C"),
376 wxT("Set the number of status bar fields"));
377 statbarMenu
->Append(StatusBar_SetFont
, wxT("&Set field font\tCtrl-F"),
378 wxT("Set the font to use for status bar fields"));
380 wxMenu
*statbarPaneStyleMenu
= new wxMenu
;
381 statbarPaneStyleMenu
->AppendCheckItem
383 StatusBar_SetPaneStyleNormal
,
385 wxT("Sets the style of the first field to normal (sunken) look")
387 statbarPaneStyleMenu
->AppendCheckItem
389 StatusBar_SetPaneStyleFlat
,
391 wxT("Sets the style of the first field to flat look")
393 statbarPaneStyleMenu
->AppendCheckItem
395 StatusBar_SetPaneStyleRaised
,
397 wxT("Sets the style of the first field to raised look")
399 statbarMenu
->Append(StatusBar_SetPaneStyle
, wxT("Field style"),
400 statbarPaneStyleMenu
);
402 statbarMenu
->Append(StatusBar_ResetFieldsWidth
, wxT("Reset field widths"),
403 wxT("Sets all fields to the same width"));
404 statbarMenu
->Append(StatusBar_ShowFieldsRect
,
405 wxT("Sho&w field rectangles\tCtrl-W"),
406 wxT("Visually show field rectangles"));
407 statbarMenu
->AppendSeparator();
409 statbarMenu
->AppendCheckItem(StatusBar_Toggle
, wxT("&Toggle Status Bar"),
410 wxT("Toggle the status bar display"));
411 statbarMenu
->Append(StatusBar_Recreate
, wxT("&Recreate\tCtrl-R"),
412 wxT("Toggle status bar format"));
414 wxMenu
*helpMenu
= new wxMenu
;
415 helpMenu
->Append(StatusBar_About
, wxT("&About...\tCtrl-A"),
416 wxT("Show about dialog"));
418 // now append the freshly created menu to the menu bar...
419 wxMenuBar
*menuBar
= new wxMenuBar();
420 menuBar
->Append(menuFile
, wxT("&File"));
421 menuBar
->Append(statbarMenu
, wxT("&Status bar"));
422 menuBar
->Append(helpMenu
, wxT("&Help"));
424 // ... and attach this menu bar to the frame
427 // create default status bar to start with
428 DoCreateStatusBar(StatBar_Default
, wxSTB_DEFAULT_STYLE
);
429 SetStatusText(wxT("Welcome to wxWidgets!"));
432 void MyFrame::DoCreateStatusBar(MyFrame::StatusBarKind kind
, long style
)
434 wxStatusBar
*statbarOld
= GetStatusBar();
441 wxStatusBar
*statbarNew
= NULL
;
444 case StatBar_Default
:
445 statbarNew
= new wxStatusBar(this, wxID_ANY
, style
, "wxStatusBar");
446 statbarNew
->SetFieldsCount(2);
450 statbarNew
= new MyStatusBar(this, style
);
454 wxFAIL_MSG(wxT("unknown status bar kind"));
457 SetStatusBar(statbarNew
);
461 m_statbarKind
= kind
;
465 // ----------------------------------------------------------------------------
466 // main frame - event handlers
467 // ----------------------------------------------------------------------------
469 void MyFrame::OnUpdateForDefaultStatusbar(wxUpdateUIEvent
& event
)
471 // only allow this feature for the default status bar
472 wxStatusBar
*sb
= GetStatusBar();
476 event
.Enable(sb
->GetName() == "wxStatusBar");
479 void MyFrame::OnSetStatusField(wxCommandEvent
& WXUNUSED(event
))
481 wxStatusBar
*sb
= GetStatusBar();
485 long rc
= wxGetNumberFromUser
487 "Configure the field index to be used by the set, push "
488 "and pop text commands in the menu.\n"
490 "0 corresponds to the first field, 1 to the second one "
493 SAMPLE_DIALOGS_TITLE
,
496 sb
->GetFieldsCount() - 1,
505 wxLogStatus("Status bar text will be set for field #%d", m_field
);
508 void MyFrame::OnSetStatusText(wxCommandEvent
& WXUNUSED(event
))
510 wxStatusBar
*sb
= GetStatusBar();
514 wxString txt
= wxGetTextFromUser
518 "Enter the text from for the field #%d",
521 SAMPLE_DIALOGS_TITLE
,
522 sb
->GetStatusText(m_field
),
529 sb
->SetStatusText(txt
, m_field
);
532 // the current depth of the stack used by Push/PopStatusText()
533 static int gs_depth
= 0;
535 void MyFrame::OnPushStatusText(wxCommandEvent
& WXUNUSED(event
))
537 wxStatusBar
*sb
= GetStatusBar();
541 static int s_countPush
= 0;
542 sb
->PushStatusText(wxString::Format
544 "Pushed message #%d (depth = %d)",
545 ++s_countPush
, ++gs_depth
549 void MyFrame::OnPopStatusText(wxCommandEvent
& WXUNUSED(event
))
551 wxStatusBar
*sb
= GetStatusBar();
557 wxLogStatus("No message to pop.");
562 sb
->PopStatusText(m_field
);
565 void MyFrame::OnSetStatusFont(wxCommandEvent
& WXUNUSED(event
))
567 wxStatusBar
*sb
= GetStatusBar();
572 fnt
= wxGetFontFromUser(this, sb
->GetFont(), "Choose status bar font");
576 sb
->SetSize(sb
->GetBestSize());
580 void MyFrame::OnSetStatusFields(wxCommandEvent
& WXUNUSED(event
))
582 wxStatusBar
*sb
= GetStatusBar();
586 long nFields
= wxGetNumberFromUser
588 wxT("Select the number of fields in the status bar"),
590 SAMPLE_DIALOGS_TITLE
,
591 sb
->GetFieldsCount(),
596 // we don't check if the number changed at all on purpose: calling
597 // SetFieldsCount() with the same number of fields should be ok
600 static const int widthsFor2Fields
[] = { 200, -1 };
601 static const int widthsFor3Fields
[] = { -1, -2, -1 };
602 static const int widthsFor4Fields
[] = { 100, -1, 100, -2, 100 };
604 static const int *widthsAll
[] =
606 NULL
, // 1 field: default
607 widthsFor2Fields
, // 2 fields: 1 fixed, 1 var
608 widthsFor3Fields
, // 3 fields: 3 var
609 widthsFor4Fields
, // 4 fields: 3 fixed, 2 vars
610 NULL
// 5 fields: default (all have same width)
613 const int * const widths
= widthsAll
[nFields
- 1];
614 sb
->SetFieldsCount(nFields
, widths
);
617 for ( long n
= 0; n
< nFields
; n
++ )
622 s
.Printf(wxT("fixed (%d)"), widths
[n
]);
624 s
.Printf(wxT("variable (*%d)"), -widths
[n
]);
634 if ( m_field
>= nFields
)
635 m_field
= nFields
- 1;
639 wxLogStatus(this, wxT("Cancelled"));
643 void MyFrame::OnResetFieldsWidth(wxCommandEvent
& WXUNUSED(event
))
645 wxStatusBar
*pStat
= GetStatusBar();
649 const int n
= pStat
->GetFieldsCount();
650 pStat
->SetStatusWidths(n
, NULL
);
651 for ( int i
= 0; i
< n
; i
++ )
652 pStat
->SetStatusText("same size", i
);
655 void MyFrame::OnShowFieldsRect(wxCommandEvent
& WXUNUSED(event
))
657 wxStatusBar
*pStat
= GetStatusBar();
661 wxClientDC
dc(pStat
);
662 dc
.SetPen(*wxRED_PEN
);
663 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
665 const int n
= pStat
->GetFieldsCount();
666 for ( int i
= 0; i
< n
; i
++ )
669 if ( pStat
->GetFieldRect(i
, r
) )
674 void MyFrame::OnUpdateStatusBarToggle(wxUpdateUIEvent
& event
)
676 event
.Check(GetStatusBar() != NULL
);
679 void MyFrame::OnStatusBarToggle(wxCommandEvent
& WXUNUSED(event
))
681 wxStatusBar
*statbarOld
= GetStatusBar();
689 DoCreateStatusBar(m_statbarKind
, wxSTB_DEFAULT_STYLE
);
693 void MyFrame::OnRecreateStatusBar(wxCommandEvent
& WXUNUSED(event
))
695 DoCreateStatusBar(m_statbarKind
== StatBar_Custom
? StatBar_Default
697 wxSTB_DEFAULT_STYLE
);
700 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
702 // true is to force the frame to close
706 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
708 MyAboutDialog
dlg(this);
712 void MyFrame::OnUpdateSetPaneStyle(wxUpdateUIEvent
& event
)
714 switch (event
.GetId())
716 case StatusBar_SetPaneStyleNormal
:
717 event
.Check(m_statbarPaneStyle
== wxSB_NORMAL
);
719 case StatusBar_SetPaneStyleFlat
:
720 event
.Check(m_statbarPaneStyle
== wxSB_FLAT
);
722 case StatusBar_SetPaneStyleRaised
:
723 event
.Check(m_statbarPaneStyle
== wxSB_RAISED
);
728 void MyFrame::OnSetPaneStyle(wxCommandEvent
& event
)
730 switch (event
.GetId())
732 case StatusBar_SetPaneStyleNormal
:
733 m_statbarPaneStyle
= wxSB_NORMAL
;
735 case StatusBar_SetPaneStyleFlat
:
736 m_statbarPaneStyle
= wxSB_FLAT
;
738 case StatusBar_SetPaneStyleRaised
:
739 m_statbarPaneStyle
= wxSB_RAISED
;
746 void MyFrame::ApplyPaneStyle()
748 wxStatusBar
*sb
= GetStatusBar();
752 int fields
= sb
->GetFieldsCount();
753 int *styles
= new int[fields
];
755 for (int i
= 1; i
< fields
; i
++)
756 styles
[i
] = wxSB_NORMAL
;
758 styles
[0] = m_statbarPaneStyle
;
760 sb
->SetStatusStyles(fields
, styles
);
765 void MyFrame::OnUpdateSetStyle(wxUpdateUIEvent
& event
)
767 long currentStyle
= wxSTB_DEFAULT_STYLE
;
769 currentStyle
= GetStatusBar()->GetWindowStyle();
771 switch (event
.GetId())
773 case StatusBar_SetStyleSizeGrip
:
774 event
.Check((currentStyle
& wxSTB_SIZEGRIP
) != 0);
776 case StatusBar_SetStyleShowTips
:
777 event
.Check((currentStyle
& wxSTB_SHOW_TIPS
) != 0);
780 case StatusBar_SetStyleEllipsizeStart
:
781 event
.Check((currentStyle
& wxSTB_ELLIPSIZE_START
) != 0);
783 case StatusBar_SetStyleEllipsizeMiddle
:
784 event
.Check((currentStyle
& wxSTB_ELLIPSIZE_MIDDLE
) != 0);
786 case StatusBar_SetStyleEllipsizeEnd
:
787 event
.Check((currentStyle
& wxSTB_ELLIPSIZE_END
) != 0);
792 void MyFrame::OnSetStyle(wxCommandEvent
& event
)
794 long oldStyle
= wxSTB_DEFAULT_STYLE
;
796 oldStyle
= GetStatusBar()->GetWindowStyle();
798 #define STB_ELLIPSIZE_MASK \
799 (wxSTB_ELLIPSIZE_START|wxSTB_ELLIPSIZE_MIDDLE|wxSTB_ELLIPSIZE_END)
801 long newStyle
= oldStyle
;
802 long newStyleBit
= 0;
803 switch (event
.GetId())
805 case StatusBar_SetStyleSizeGrip
:
806 newStyleBit
= wxSTB_SIZEGRIP
;
808 case StatusBar_SetStyleShowTips
:
809 newStyleBit
= wxSTB_SHOW_TIPS
;
812 case StatusBar_SetStyleEllipsizeStart
:
813 newStyleBit
= wxSTB_ELLIPSIZE_START
;
814 newStyle
&= ~STB_ELLIPSIZE_MASK
;
816 case StatusBar_SetStyleEllipsizeMiddle
:
817 newStyleBit
= wxSTB_ELLIPSIZE_MIDDLE
;
818 newStyle
&= ~STB_ELLIPSIZE_MASK
;
820 case StatusBar_SetStyleEllipsizeEnd
:
821 newStyleBit
= wxSTB_ELLIPSIZE_END
;
822 newStyle
&= ~STB_ELLIPSIZE_MASK
;
826 newStyle
= event
.IsChecked() ? (newStyle
| newStyleBit
) :
827 (newStyle
& ~newStyleBit
);
828 if (newStyle
!= oldStyle
)
830 DoCreateStatusBar(m_statbarKind
, newStyle
);
831 SetStatusText("Status bar recreated with a new style");
835 // ----------------------------------------------------------------------------
837 // ----------------------------------------------------------------------------
839 MyAboutDialog::MyAboutDialog(wxWindow
*parent
)
840 : wxDialog(parent
, wxID_ANY
, wxString(wxT("About statbar")),
841 wxDefaultPosition
, wxDefaultSize
,
842 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
844 wxStaticText
*text
= new wxStaticText(this, wxID_ANY
,
845 wxT("wxStatusBar sample\n")
846 wxT("(c) 2000 Vadim Zeitlin"));
848 wxButton
*btn
= new wxButton(this, wxID_OK
, wxT("&Close"));
850 // create the top status bar without the size grip (default style),
851 // otherwise it looks weird
852 wxStatusBar
*statbarTop
= new wxStatusBar(this, wxID_ANY
, 0);
853 statbarTop
->SetFieldsCount(3);
854 statbarTop
->SetStatusText(wxT("This is a top status bar"), 0);
855 statbarTop
->SetStatusText(wxT("in a dialog"), 1);
856 statbarTop
->SetStatusText(wxT("Great, isn't it?"), 2);
858 wxStatusBar
*statbarBottom
= new wxStatusBar(this, wxID_ANY
);
859 statbarBottom
->SetFieldsCount(2);
860 statbarBottom
->SetStatusText(wxT("This is a bottom status bar"), 0);
861 statbarBottom
->SetStatusText(wxT("in a dialog"), 1);
863 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
864 sizerTop
->Add(statbarTop
, 0, wxGROW
);
865 sizerTop
->Add(-1, 10, 1, wxGROW
);
866 sizerTop
->Add(text
, 0, wxCENTRE
| wxRIGHT
| wxLEFT
, 20);
867 sizerTop
->Add(-1, 10, 1, wxGROW
);
868 sizerTop
->Add(btn
, 0, wxCENTRE
| wxRIGHT
| wxLEFT
, 20);
869 sizerTop
->Add(-1, 10, 1, wxGROW
);
870 sizerTop
->Add(statbarBottom
, 0, wxGROW
);
872 SetSizerAndFit(sizerTop
);
875 // ----------------------------------------------------------------------------
877 // ----------------------------------------------------------------------------
880 // 'this' : used in base member initializer list -- so what??
881 #pragma warning(disable: 4355)
884 static const char *numlockIndicators
[] = { "OFF", "NUM" };
885 static const char *capslockIndicators
[] = { "", "CAPS" };
887 MyStatusBar::MyStatusBar(wxWindow
*parent
, long style
)
888 : wxStatusBar(parent
, wxID_ANY
, style
, "MyStatusBar")
896 // compute the size needed for num lock indicator pane
898 wxSize sizeNumLock
= dc
.GetTextExtent(numlockIndicators
[0]);
899 sizeNumLock
.IncTo(dc
.GetTextExtent(numlockIndicators
[1]));
901 int widths
[Field_Max
];
902 widths
[Field_Text
] = -1; // growable
903 widths
[Field_Checkbox
] = 150;
904 widths
[Field_Bitmap
] = BITMAP_SIZE_X
;
905 widths
[Field_NumLockIndicator
] = sizeNumLock
.x
;
906 widths
[Field_Clock
] = 100;
907 widths
[Field_CapsLockIndicator
] = dc
.GetTextExtent(capslockIndicators
[1]).x
;
909 SetFieldsCount(Field_Max
);
910 SetStatusWidths(Field_Max
, widths
);
913 m_checkbox
= new wxCheckBox(this, StatusBar_Checkbox
, wxT("&Toggle clock"));
914 m_checkbox
->SetValue(true);
917 m_statbmp
= new wxStaticBitmap(this, wxID_ANY
, wxIcon(green_xpm
));
923 SetMinHeight(wxMax(m_statbmp
->GetBestSize().GetHeight(),
924 m_checkbox
->GetBestSize().GetHeight()));
930 #pragma warning(default: 4355)
933 MyStatusBar::~MyStatusBar()
936 if ( m_timer
.IsRunning() )
943 void MyStatusBar::OnSize(wxSizeEvent
& event
)
950 // TEMPORARY HACK: TODO find a more general solution
951 #ifdef wxStatusBarGeneric
952 wxStatusBar::OnSize(event
);
956 if (!GetFieldRect(Field_Checkbox
, rect
))
963 wxRect rectCheck
= rect
;
964 rectCheck
.Deflate(2);
965 m_checkbox
->SetSize(rectCheck
);
968 GetFieldRect(Field_Bitmap
, rect
);
969 wxSize size
= m_statbmp
->GetSize();
971 m_statbmp
->Move(rect
.x
+ (rect
.width
- size
.x
) / 2,
972 rect
.y
+ (rect
.height
- size
.y
) / 2);
977 void MyStatusBar::OnToggleClock(wxCommandEvent
& WXUNUSED(event
))
982 void MyStatusBar::OnIdle(wxIdleEvent
& event
)
984 SetStatusText(numlockIndicators
[wxGetKeyState(WXK_NUMLOCK
)],
985 Field_NumLockIndicator
);
986 SetStatusText(capslockIndicators
[wxGetKeyState(WXK_CAPITAL
)],
987 Field_CapsLockIndicator
);
992 void MyStatusBar::DoToggle()
995 if ( m_checkbox
->GetValue() )
1001 m_statbmp
->SetIcon(wxIcon(green_xpm
));
1005 else // don't show clock
1011 m_statbmp
->SetIcon(wxIcon(red_xpm
));
1013 SetStatusText(wxEmptyString
, Field_Clock
);
1015 #endif // wxUSE_CHECKBOX
1018 void MyStatusBar::UpdateClock()
1020 SetStatusText(wxDateTime::Now().FormatTime(), Field_Clock
);