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"
53 #ifndef wxHAS_IMAGES_IN_RESOURCES
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
,
221 StatusBar_SetPaneStyleSunken
,
223 StatusBar_SetStyleSizeGrip
,
224 StatusBar_SetStyleEllipsizeStart
,
225 StatusBar_SetStyleEllipsizeMiddle
,
226 StatusBar_SetStyleEllipsizeEnd
,
227 StatusBar_SetStyleShowTips
230 static const int BITMAP_SIZE_X
= 32;
231 static const int BITMAP_SIZE_Y
= 15;
233 // ----------------------------------------------------------------------------
234 // event tables and other macros for wxWidgets
235 // ----------------------------------------------------------------------------
237 // the event tables connect the wxWidgets events with the functions (event
238 // handlers) which process them. It can be also done at run-time, but for the
239 // simple menu events like this the static method is much simpler.
240 #ifdef USE_MDI_PARENT_FRAME
241 BEGIN_EVENT_TABLE(MyFrame
, wxMDIParentFrame
)
243 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
245 EVT_MENU(StatusBar_Quit
, MyFrame::OnQuit
)
246 EVT_MENU(StatusBar_SetFields
, MyFrame::OnSetStatusFields
)
247 EVT_MENU(StatusBar_SetField
, MyFrame::OnSetStatusField
)
248 EVT_MENU(StatusBar_SetText
, MyFrame::OnSetStatusText
)
249 EVT_MENU(StatusBar_PushText
, MyFrame::OnPushStatusText
)
250 EVT_MENU(StatusBar_PopText
, MyFrame::OnPopStatusText
)
251 EVT_MENU(StatusBar_SetFont
, MyFrame::OnSetStatusFont
)
252 EVT_MENU(StatusBar_ResetFieldsWidth
, MyFrame::OnResetFieldsWidth
)
253 EVT_MENU(StatusBar_ShowFieldsRect
, MyFrame::OnShowFieldsRect
)
254 EVT_MENU(StatusBar_Recreate
, MyFrame::OnRecreateStatusBar
)
255 EVT_MENU(StatusBar_About
, MyFrame::OnAbout
)
256 EVT_MENU(StatusBar_Toggle
, MyFrame::OnStatusBarToggle
)
257 EVT_MENU(StatusBar_SetPaneStyleNormal
, MyFrame::OnSetPaneStyle
)
258 EVT_MENU(StatusBar_SetPaneStyleFlat
, MyFrame::OnSetPaneStyle
)
259 EVT_MENU(StatusBar_SetPaneStyleRaised
, MyFrame::OnSetPaneStyle
)
260 EVT_MENU(StatusBar_SetPaneStyleSunken
, MyFrame::OnSetPaneStyle
)
262 EVT_MENU(StatusBar_SetStyleSizeGrip
, MyFrame::OnSetStyle
)
263 EVT_MENU(StatusBar_SetStyleEllipsizeStart
, MyFrame::OnSetStyle
)
264 EVT_MENU(StatusBar_SetStyleEllipsizeMiddle
, MyFrame::OnSetStyle
)
265 EVT_MENU(StatusBar_SetStyleEllipsizeEnd
, MyFrame::OnSetStyle
)
266 EVT_MENU(StatusBar_SetStyleShowTips
, MyFrame::OnSetStyle
)
268 EVT_UPDATE_UI_RANGE(StatusBar_SetFields
, StatusBar_ResetFieldsWidth
,
269 MyFrame::OnUpdateForDefaultStatusbar
)
270 EVT_UPDATE_UI(StatusBar_Toggle
, MyFrame::OnUpdateStatusBarToggle
)
271 EVT_UPDATE_UI_RANGE(StatusBar_SetPaneStyleNormal
,
272 StatusBar_SetPaneStyleSunken
,
273 MyFrame::OnUpdateSetPaneStyle
)
274 EVT_UPDATE_UI_RANGE(StatusBar_SetStyleSizeGrip
, StatusBar_SetStyleShowTips
,
275 MyFrame::OnUpdateSetStyle
)
278 BEGIN_EVENT_TABLE(MyStatusBar
, wxStatusBar
)
279 EVT_SIZE(MyStatusBar::OnSize
)
281 EVT_CHECKBOX(StatusBar_Checkbox
, MyStatusBar::OnToggleClock
)
284 EVT_TIMER(wxID_ANY
, MyStatusBar::OnTimer
)
286 EVT_IDLE(MyStatusBar::OnIdle
)
289 // Create a new application object: this macro will allow wxWidgets to create
290 // the application object during program execution (it's better than using a
291 // static object for many reasons) and also declares the accessor function
292 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
296 // ============================================================================
298 // ============================================================================
300 // ----------------------------------------------------------------------------
301 // the application class
302 // ----------------------------------------------------------------------------
304 // `Main program' equivalent: the program execution "starts" here
307 if ( !wxApp::OnInit() )
310 // create the main application window
311 MyFrame
*frame
= new MyFrame(wxT("wxStatusBar sample"),
312 wxPoint(50, 50), wxSize(450, 340));
314 // and show it (the frames, unlike simple controls, are not shown when
315 // created initially)
318 // success: wxApp::OnRun() will be called which will enter the main message
319 // loop and the application will run. If we returned 'false' here, the
320 // application would exit immediately.
324 // ----------------------------------------------------------------------------
326 // ----------------------------------------------------------------------------
329 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
330 #ifdef USE_MDI_PARENT_FRAME
331 : wxMDIParentFrame(NULL
, wxID_ANY
, title
, pos
, size
)
333 : wxFrame(NULL
, wxID_ANY
, title
, pos
, size
)
336 SetIcon(wxICON(sample
));
338 m_statbarPaneStyle
= wxSB_NORMAL
;
342 wxMenu
*menuFile
= new wxMenu
;
343 menuFile
->Append(StatusBar_Quit
, wxT("E&xit\tAlt-X"),
344 wxT("Quit this program"));
346 wxMenu
*statbarMenu
= new wxMenu
;
348 wxMenu
*statbarStyleMenu
= new wxMenu
;
349 statbarStyleMenu
->Append(StatusBar_SetStyleSizeGrip
, wxT("wxSTB_SIZE_GRIP"),
350 wxT("Toggles the wxSTB_SIZE_GRIP style"), true);
351 statbarStyleMenu
->Append(StatusBar_SetStyleShowTips
, wxT("wxSTB_SHOW_TIPS"),
352 wxT("Toggles the wxSTB_SHOW_TIPS style"), true);
353 statbarStyleMenu
->AppendSeparator();
354 statbarStyleMenu
->AppendCheckItem(StatusBar_SetStyleEllipsizeStart
,
355 wxT("wxSTB_ELLIPSIZE_START"),
356 wxT("Toggle wxSTB_ELLIPSIZE_START style"));
357 statbarStyleMenu
->AppendCheckItem(StatusBar_SetStyleEllipsizeMiddle
,
358 wxT("wxSTB_ELLIPSIZE_MIDDLE"),
359 wxT("Toggle wxSTB_ELLIPSIZE_MIDDLE style"));
360 statbarStyleMenu
->AppendCheckItem(StatusBar_SetStyleEllipsizeEnd
,
361 wxT("wxSTB_ELLIPSIZE_END"),
362 wxT("Toggle wxSTB_ELLIPSIZE_END style"));
363 statbarMenu
->Append(StatusBar_SetPaneStyle
, wxT("Status bar style"),
365 statbarMenu
->AppendSeparator();
367 statbarMenu
->Append(StatusBar_SetField
, "Set active field &number\tCtrl-N",
368 "Set the number of field used by the next commands.");
369 statbarMenu
->Append(StatusBar_SetText
, wxT("Set field &text\tCtrl-T"),
370 wxT("Set the text of the selected field."));
371 statbarMenu
->Append(StatusBar_PushText
, "P&ush field text\tCtrl-P",
372 "Push a message on top the selected field.");
373 statbarMenu
->Append(StatusBar_PopText
, "&Pop field text\tShift-Ctrl-P",
374 "Restore the previous contents of the selected field.");
375 statbarMenu
->AppendSeparator();
377 statbarMenu
->Append(StatusBar_SetFields
, wxT("&Set field count\tCtrl-C"),
378 wxT("Set the number of status bar fields"));
379 statbarMenu
->Append(StatusBar_SetFont
, wxT("&Set field font\tCtrl-F"),
380 wxT("Set the font to use for status bar fields"));
382 wxMenu
*statbarPaneStyleMenu
= new wxMenu
;
383 statbarPaneStyleMenu
->AppendCheckItem
385 StatusBar_SetPaneStyleNormal
,
387 wxT("Sets the style of the first field to normal (sunken) look")
389 statbarPaneStyleMenu
->AppendCheckItem
391 StatusBar_SetPaneStyleFlat
,
393 wxT("Sets the style of the first field to flat look")
395 statbarPaneStyleMenu
->AppendCheckItem
397 StatusBar_SetPaneStyleRaised
,
399 wxT("Sets the style of the first field to raised look")
401 statbarPaneStyleMenu
->AppendCheckItem
403 StatusBar_SetPaneStyleSunken
,
405 wxT("Sets the style of the first field to sunken look")
407 statbarMenu
->Append(StatusBar_SetPaneStyle
, wxT("Field style"),
408 statbarPaneStyleMenu
);
410 statbarMenu
->Append(StatusBar_ResetFieldsWidth
, wxT("Reset field widths"),
411 wxT("Sets all fields to the same width"));
412 statbarMenu
->Append(StatusBar_ShowFieldsRect
,
413 wxT("Sho&w field rectangles\tCtrl-W"),
414 wxT("Visually show field rectangles"));
415 statbarMenu
->AppendSeparator();
417 statbarMenu
->AppendCheckItem(StatusBar_Toggle
, wxT("&Toggle Status Bar"),
418 wxT("Toggle the status bar display"));
419 statbarMenu
->Append(StatusBar_Recreate
, wxT("&Recreate\tCtrl-R"),
420 wxT("Toggle status bar format"));
422 wxMenu
*helpMenu
= new wxMenu
;
423 helpMenu
->Append(StatusBar_About
, wxT("&About\tCtrl-A"),
424 wxT("Show about dialog"));
426 // now append the freshly created menu to the menu bar...
427 wxMenuBar
*menuBar
= new wxMenuBar();
428 menuBar
->Append(menuFile
, wxT("&File"));
429 menuBar
->Append(statbarMenu
, wxT("&Status bar"));
430 menuBar
->Append(helpMenu
, wxT("&Help"));
432 // ... and attach this menu bar to the frame
435 // create default status bar to start with
436 DoCreateStatusBar(StatBar_Default
, wxSTB_DEFAULT_STYLE
);
437 SetStatusText(wxT("Welcome to wxWidgets!"));
440 void MyFrame::DoCreateStatusBar(MyFrame::StatusBarKind kind
, long style
)
442 wxStatusBar
*statbarOld
= GetStatusBar();
449 wxStatusBar
*statbarNew
= NULL
;
452 case StatBar_Default
:
453 statbarNew
= new wxStatusBar(this, wxID_ANY
, style
, "wxStatusBar");
454 statbarNew
->SetFieldsCount(2);
458 statbarNew
= new MyStatusBar(this, style
);
462 wxFAIL_MSG(wxT("unknown status bar kind"));
465 SetStatusBar(statbarNew
);
469 m_statbarKind
= kind
;
473 // ----------------------------------------------------------------------------
474 // main frame - event handlers
475 // ----------------------------------------------------------------------------
477 void MyFrame::OnUpdateForDefaultStatusbar(wxUpdateUIEvent
& event
)
479 // only allow this feature for the default status bar
480 wxStatusBar
*sb
= GetStatusBar();
484 event
.Enable(sb
->GetName() == "wxStatusBar");
487 void MyFrame::OnSetStatusField(wxCommandEvent
& WXUNUSED(event
))
489 wxStatusBar
*sb
= GetStatusBar();
493 long rc
= wxGetNumberFromUser
495 "Configure the field index to be used by the set, push "
496 "and pop text commands in the menu.\n"
498 "0 corresponds to the first field, 1 to the second one "
501 SAMPLE_DIALOGS_TITLE
,
504 sb
->GetFieldsCount() - 1,
513 wxLogStatus("Status bar text will be set for field #%d", m_field
);
516 void MyFrame::OnSetStatusText(wxCommandEvent
& WXUNUSED(event
))
518 wxStatusBar
*sb
= GetStatusBar();
522 wxString txt
= wxGetTextFromUser
526 "Enter the text from for the field #%d",
529 SAMPLE_DIALOGS_TITLE
,
530 sb
->GetStatusText(m_field
),
537 sb
->SetStatusText(txt
, m_field
);
540 // the current depth of the stack used by Push/PopStatusText()
541 static int gs_depth
= 0;
543 void MyFrame::OnPushStatusText(wxCommandEvent
& WXUNUSED(event
))
545 wxStatusBar
*sb
= GetStatusBar();
549 static int s_countPush
= 0;
550 sb
->PushStatusText(wxString::Format
552 "Pushed message #%d (depth = %d)",
553 ++s_countPush
, ++gs_depth
557 void MyFrame::OnPopStatusText(wxCommandEvent
& WXUNUSED(event
))
559 wxStatusBar
*sb
= GetStatusBar();
565 wxLogStatus("No message to pop.");
570 sb
->PopStatusText(m_field
);
573 void MyFrame::OnSetStatusFont(wxCommandEvent
& WXUNUSED(event
))
575 wxStatusBar
*sb
= GetStatusBar();
580 fnt
= wxGetFontFromUser(this, sb
->GetFont(), "Choose status bar font");
584 sb
->SetSize(sb
->GetBestSize());
588 void MyFrame::OnSetStatusFields(wxCommandEvent
& WXUNUSED(event
))
590 wxStatusBar
*sb
= GetStatusBar();
594 long nFields
= wxGetNumberFromUser
596 wxT("Select the number of fields in the status bar"),
598 SAMPLE_DIALOGS_TITLE
,
599 sb
->GetFieldsCount(),
604 // we don't check if the number changed at all on purpose: calling
605 // SetFieldsCount() with the same number of fields should be ok
608 static const int widthsFor2Fields
[] = { 200, -1 };
609 static const int widthsFor3Fields
[] = { -1, -2, -1 };
610 static const int widthsFor4Fields
[] = { 100, -1, 100, -2, 100 };
612 static const int *widthsAll
[] =
614 NULL
, // 1 field: default
615 widthsFor2Fields
, // 2 fields: 1 fixed, 1 var
616 widthsFor3Fields
, // 3 fields: 3 var
617 widthsFor4Fields
, // 4 fields: 3 fixed, 2 vars
618 NULL
// 5 fields: default (all have same width)
621 const int * const widths
= widthsAll
[nFields
- 1];
622 sb
->SetFieldsCount(nFields
, widths
);
625 for ( long n
= 0; n
< nFields
; n
++ )
630 s
.Printf(wxT("fixed (%d)"), widths
[n
]);
632 s
.Printf(wxT("variable (*%d)"), -widths
[n
]);
642 if ( m_field
>= nFields
)
643 m_field
= nFields
- 1;
647 wxLogStatus(this, wxT("Cancelled"));
651 void MyFrame::OnResetFieldsWidth(wxCommandEvent
& WXUNUSED(event
))
653 wxStatusBar
*pStat
= GetStatusBar();
657 const int n
= pStat
->GetFieldsCount();
658 pStat
->SetStatusWidths(n
, NULL
);
659 for ( int i
= 0; i
< n
; i
++ )
660 pStat
->SetStatusText("same size", i
);
663 void MyFrame::OnShowFieldsRect(wxCommandEvent
& WXUNUSED(event
))
665 wxStatusBar
*pStat
= GetStatusBar();
669 wxClientDC
dc(pStat
);
670 dc
.SetPen(*wxRED_PEN
);
671 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
673 const int n
= pStat
->GetFieldsCount();
674 for ( int i
= 0; i
< n
; i
++ )
677 if ( pStat
->GetFieldRect(i
, r
) )
682 void MyFrame::OnUpdateStatusBarToggle(wxUpdateUIEvent
& event
)
684 event
.Check(GetStatusBar() != NULL
);
687 void MyFrame::OnStatusBarToggle(wxCommandEvent
& WXUNUSED(event
))
689 wxStatusBar
*statbarOld
= GetStatusBar();
697 DoCreateStatusBar(m_statbarKind
, wxSTB_DEFAULT_STYLE
);
701 void MyFrame::OnRecreateStatusBar(wxCommandEvent
& WXUNUSED(event
))
703 DoCreateStatusBar(m_statbarKind
== StatBar_Custom
? StatBar_Default
705 wxSTB_DEFAULT_STYLE
);
708 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
710 // true is to force the frame to close
714 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
716 MyAboutDialog
dlg(this);
720 void MyFrame::OnUpdateSetPaneStyle(wxUpdateUIEvent
& event
)
722 switch (event
.GetId())
724 case StatusBar_SetPaneStyleNormal
:
725 event
.Check(m_statbarPaneStyle
== wxSB_NORMAL
);
727 case StatusBar_SetPaneStyleFlat
:
728 event
.Check(m_statbarPaneStyle
== wxSB_FLAT
);
730 case StatusBar_SetPaneStyleRaised
:
731 event
.Check(m_statbarPaneStyle
== wxSB_RAISED
);
733 case StatusBar_SetPaneStyleSunken
:
734 event
.Check(m_statbarPaneStyle
== wxSB_SUNKEN
);
739 void MyFrame::OnSetPaneStyle(wxCommandEvent
& event
)
741 switch (event
.GetId())
743 case StatusBar_SetPaneStyleNormal
:
744 m_statbarPaneStyle
= wxSB_NORMAL
;
746 case StatusBar_SetPaneStyleFlat
:
747 m_statbarPaneStyle
= wxSB_FLAT
;
749 case StatusBar_SetPaneStyleRaised
:
750 m_statbarPaneStyle
= wxSB_RAISED
;
752 case StatusBar_SetPaneStyleSunken
:
753 m_statbarPaneStyle
= wxSB_SUNKEN
;
760 void MyFrame::ApplyPaneStyle()
762 wxStatusBar
*sb
= GetStatusBar();
766 int fields
= sb
->GetFieldsCount();
767 int *styles
= new int[fields
];
769 for (int i
= 1; i
< fields
; i
++)
770 styles
[i
] = wxSB_NORMAL
;
772 styles
[0] = m_statbarPaneStyle
;
774 sb
->SetStatusStyles(fields
, styles
);
779 void MyFrame::OnUpdateSetStyle(wxUpdateUIEvent
& event
)
781 long currentStyle
= wxSTB_DEFAULT_STYLE
;
783 currentStyle
= GetStatusBar()->GetWindowStyle();
785 switch (event
.GetId())
787 case StatusBar_SetStyleSizeGrip
:
788 event
.Check((currentStyle
& wxSTB_SIZEGRIP
) != 0);
790 case StatusBar_SetStyleShowTips
:
791 event
.Check((currentStyle
& wxSTB_SHOW_TIPS
) != 0);
794 case StatusBar_SetStyleEllipsizeStart
:
795 event
.Check((currentStyle
& wxSTB_ELLIPSIZE_START
) != 0);
797 case StatusBar_SetStyleEllipsizeMiddle
:
798 event
.Check((currentStyle
& wxSTB_ELLIPSIZE_MIDDLE
) != 0);
800 case StatusBar_SetStyleEllipsizeEnd
:
801 event
.Check((currentStyle
& wxSTB_ELLIPSIZE_END
) != 0);
806 void MyFrame::OnSetStyle(wxCommandEvent
& event
)
808 long oldStyle
= wxSTB_DEFAULT_STYLE
;
810 oldStyle
= GetStatusBar()->GetWindowStyle();
812 #define STB_ELLIPSIZE_MASK \
813 (wxSTB_ELLIPSIZE_START|wxSTB_ELLIPSIZE_MIDDLE|wxSTB_ELLIPSIZE_END)
815 long newStyle
= oldStyle
;
816 long newStyleBit
= 0;
817 switch (event
.GetId())
819 case StatusBar_SetStyleSizeGrip
:
820 newStyleBit
= wxSTB_SIZEGRIP
;
822 case StatusBar_SetStyleShowTips
:
823 newStyleBit
= wxSTB_SHOW_TIPS
;
826 case StatusBar_SetStyleEllipsizeStart
:
827 newStyleBit
= wxSTB_ELLIPSIZE_START
;
828 newStyle
&= ~STB_ELLIPSIZE_MASK
;
830 case StatusBar_SetStyleEllipsizeMiddle
:
831 newStyleBit
= wxSTB_ELLIPSIZE_MIDDLE
;
832 newStyle
&= ~STB_ELLIPSIZE_MASK
;
834 case StatusBar_SetStyleEllipsizeEnd
:
835 newStyleBit
= wxSTB_ELLIPSIZE_END
;
836 newStyle
&= ~STB_ELLIPSIZE_MASK
;
840 newStyle
= event
.IsChecked() ? (newStyle
| newStyleBit
) :
841 (newStyle
& ~newStyleBit
);
842 if (newStyle
!= oldStyle
)
844 DoCreateStatusBar(m_statbarKind
, newStyle
);
845 SetStatusText("Status bar recreated with a new style");
849 // ----------------------------------------------------------------------------
851 // ----------------------------------------------------------------------------
853 MyAboutDialog::MyAboutDialog(wxWindow
*parent
)
854 : wxDialog(parent
, wxID_ANY
, wxString(wxT("About statbar")),
855 wxDefaultPosition
, wxDefaultSize
,
856 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
858 wxStaticText
*text
= new wxStaticText(this, wxID_ANY
,
859 wxT("wxStatusBar sample\n")
860 wxT("(c) 2000 Vadim Zeitlin"));
862 wxButton
*btn
= new wxButton(this, wxID_OK
, wxT("&Close"));
864 // create the top status bar without the size grip (default style),
865 // otherwise it looks weird
866 wxStatusBar
*statbarTop
= new wxStatusBar(this, wxID_ANY
, 0);
867 statbarTop
->SetFieldsCount(3);
868 statbarTop
->SetStatusText(wxT("This is a top status bar"), 0);
869 statbarTop
->SetStatusText(wxT("in a dialog"), 1);
870 statbarTop
->SetStatusText(wxT("Great, isn't it?"), 2);
872 wxStatusBar
*statbarBottom
= new wxStatusBar(this, wxID_ANY
);
873 statbarBottom
->SetFieldsCount(2);
874 statbarBottom
->SetStatusText(wxT("This is a bottom status bar"), 0);
875 statbarBottom
->SetStatusText(wxT("in a dialog"), 1);
877 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
878 sizerTop
->Add(statbarTop
, 0, wxGROW
);
879 sizerTop
->Add(-1, 10, 1, wxGROW
);
880 sizerTop
->Add(text
, 0, wxCENTRE
| wxRIGHT
| wxLEFT
, 20);
881 sizerTop
->Add(-1, 10, 1, wxGROW
);
882 sizerTop
->Add(btn
, 0, wxCENTRE
| wxRIGHT
| wxLEFT
, 20);
883 sizerTop
->Add(-1, 10, 1, wxGROW
);
884 sizerTop
->Add(statbarBottom
, 0, wxGROW
);
886 SetSizerAndFit(sizerTop
);
889 // ----------------------------------------------------------------------------
891 // ----------------------------------------------------------------------------
894 // 'this' : used in base member initializer list -- so what??
895 #pragma warning(disable: 4355)
898 static const char *numlockIndicators
[] = { "OFF", "NUM" };
899 static const char *capslockIndicators
[] = { "", "CAPS" };
901 MyStatusBar::MyStatusBar(wxWindow
*parent
, long style
)
902 : wxStatusBar(parent
, wxID_ANY
, style
, "MyStatusBar")
910 // compute the size needed for num lock indicator pane
912 wxSize sizeNumLock
= dc
.GetTextExtent(numlockIndicators
[0]);
913 sizeNumLock
.IncTo(dc
.GetTextExtent(numlockIndicators
[1]));
915 int widths
[Field_Max
];
916 widths
[Field_Text
] = -1; // growable
917 widths
[Field_Checkbox
] = 150;
918 widths
[Field_Bitmap
] = BITMAP_SIZE_X
;
919 widths
[Field_NumLockIndicator
] = sizeNumLock
.x
;
920 widths
[Field_Clock
] = 100;
921 widths
[Field_CapsLockIndicator
] = dc
.GetTextExtent(capslockIndicators
[1]).x
;
923 SetFieldsCount(Field_Max
);
924 SetStatusWidths(Field_Max
, widths
);
927 m_checkbox
= new wxCheckBox(this, StatusBar_Checkbox
, wxT("&Toggle clock"));
928 m_checkbox
->SetValue(true);
931 m_statbmp
= new wxStaticBitmap(this, wxID_ANY
, wxIcon(green_xpm
));
937 SetMinHeight(wxMax(m_statbmp
->GetBestSize().GetHeight(),
938 m_checkbox
->GetBestSize().GetHeight()));
944 #pragma warning(default: 4355)
947 MyStatusBar::~MyStatusBar()
950 if ( m_timer
.IsRunning() )
957 void MyStatusBar::OnSize(wxSizeEvent
& event
)
965 if (!GetFieldRect(Field_Checkbox
, rect
))
972 wxRect rectCheck
= rect
;
973 rectCheck
.Deflate(2);
974 m_checkbox
->SetSize(rectCheck
);
977 GetFieldRect(Field_Bitmap
, rect
);
978 wxSize size
= m_statbmp
->GetSize();
980 m_statbmp
->Move(rect
.x
+ (rect
.width
- size
.x
) / 2,
981 rect
.y
+ (rect
.height
- size
.y
) / 2);
986 void MyStatusBar::OnToggleClock(wxCommandEvent
& WXUNUSED(event
))
991 void MyStatusBar::OnIdle(wxIdleEvent
& event
)
993 SetStatusText(numlockIndicators
[wxGetKeyState(WXK_NUMLOCK
)],
994 Field_NumLockIndicator
);
995 SetStatusText(capslockIndicators
[wxGetKeyState(WXK_CAPITAL
)],
996 Field_CapsLockIndicator
);
1001 void MyStatusBar::DoToggle()
1004 if ( m_checkbox
->GetValue() )
1007 m_timer
.Start(1000);
1010 m_statbmp
->SetIcon(wxIcon(green_xpm
));
1014 else // don't show clock
1020 m_statbmp
->SetIcon(wxIcon(red_xpm
));
1022 SetStatusText(wxEmptyString
, Field_Clock
);
1024 #endif // wxUSE_CHECKBOX
1027 void MyStatusBar::UpdateClock()
1029 SetStatusText(wxDateTime::Now().FormatTime(), Field_Clock
);