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
);
105 // toggle the state of the status bar controls
122 wxCheckBox
*m_checkbox
;
124 wxStaticBitmap
*m_statbmp
;
126 DECLARE_EVENT_TABLE()
129 // Define a new frame type: this is going to be our main frame
130 #ifdef USE_MDI_PARENT_FRAME
131 class MyFrame
: public wxMDIParentFrame
133 class MyFrame
: public wxFrame
138 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
140 // event handlers (these functions should _not_ be virtual)
141 void OnQuit(wxCommandEvent
& event
);
142 void OnAbout(wxCommandEvent
& event
);
144 void OnSetStatusField(wxCommandEvent
& event
);
145 void OnSetStatusText(wxCommandEvent
& event
);
146 void OnPushStatusText(wxCommandEvent
& event
);
147 void OnPopStatusText(wxCommandEvent
& event
);
149 void OnResetFieldsWidth(wxCommandEvent
& event
);
150 void OnShowFieldsRect(wxCommandEvent
& event
);
151 void OnSetStatusFields(wxCommandEvent
& event
);
152 void OnSetStatusFont(wxCommandEvent
& event
);
153 void OnRecreateStatusBar(wxCommandEvent
& event
);
155 void OnSetPaneStyle(wxCommandEvent
& event
);
156 void OnSetStyle(wxCommandEvent
& event
);
167 void OnUpdateForDefaultStatusbar(wxUpdateUIEvent
& event
);
168 void OnUpdateStatusBarToggle(wxUpdateUIEvent
& event
);
169 void OnUpdateSetPaneStyle(wxUpdateUIEvent
& event
);
170 void OnUpdateSetStyle(wxUpdateUIEvent
& event
);
171 void OnStatusBarToggle(wxCommandEvent
& event
);
172 void DoCreateStatusBar(StatusBarKind kind
, long style
);
173 void ApplyPaneStyle();
175 int m_statbarPaneStyle
;
177 // the index of the field used by some commands
180 // any class wishing to process wxWidgets events must use this macro
181 DECLARE_EVENT_TABLE()
184 // Our about dialog ith its status bar
185 class MyAboutDialog
: public wxDialog
188 MyAboutDialog(wxWindow
*parent
);
191 // ----------------------------------------------------------------------------
193 // ----------------------------------------------------------------------------
195 // IDs for the controls and the menu commands
199 StatusBar_Quit
= wxID_EXIT
,
200 StatusBar_About
= wxID_ABOUT
,
202 StatusBar_SetFields
= wxID_HIGHEST
+1,
208 StatusBar_ResetFieldsWidth
,
209 StatusBar_ShowFieldsRect
,
214 StatusBar_SetPaneStyle
,
215 StatusBar_SetPaneStyleNormal
,
216 StatusBar_SetPaneStyleFlat
,
217 StatusBar_SetPaneStyleRaised
,
219 StatusBar_SetStyleSizeGrip
,
220 StatusBar_SetStyleEllipsizeStart
,
221 StatusBar_SetStyleEllipsizeMiddle
,
222 StatusBar_SetStyleEllipsizeEnd
,
223 StatusBar_SetStyleShowTips
226 static const int BITMAP_SIZE_X
= 32;
227 static const int BITMAP_SIZE_Y
= 15;
229 // ----------------------------------------------------------------------------
230 // event tables and other macros for wxWidgets
231 // ----------------------------------------------------------------------------
233 // the event tables connect the wxWidgets events with the functions (event
234 // handlers) which process them. It can be also done at run-time, but for the
235 // simple menu events like this the static method is much simpler.
236 #ifdef USE_MDI_PARENT_FRAME
237 BEGIN_EVENT_TABLE(MyFrame
, wxMDIParentFrame
)
239 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
241 EVT_MENU(StatusBar_Quit
, MyFrame
::OnQuit
)
242 EVT_MENU(StatusBar_SetFields
, MyFrame
::OnSetStatusFields
)
243 EVT_MENU(StatusBar_SetField
, MyFrame
::OnSetStatusField
)
244 EVT_MENU(StatusBar_SetText
, MyFrame
::OnSetStatusText
)
245 EVT_MENU(StatusBar_PushText
, MyFrame
::OnPushStatusText
)
246 EVT_MENU(StatusBar_PopText
, MyFrame
::OnPopStatusText
)
247 EVT_MENU(StatusBar_SetFont
, MyFrame
::OnSetStatusFont
)
248 EVT_MENU(StatusBar_ResetFieldsWidth
, MyFrame
::OnResetFieldsWidth
)
249 EVT_MENU(StatusBar_ShowFieldsRect
, MyFrame
::OnShowFieldsRect
)
250 EVT_MENU(StatusBar_Recreate
, MyFrame
::OnRecreateStatusBar
)
251 EVT_MENU(StatusBar_About
, MyFrame
::OnAbout
)
252 EVT_MENU(StatusBar_Toggle
, MyFrame
::OnStatusBarToggle
)
253 EVT_MENU(StatusBar_SetPaneStyleNormal
, MyFrame
::OnSetPaneStyle
)
254 EVT_MENU(StatusBar_SetPaneStyleFlat
, MyFrame
::OnSetPaneStyle
)
255 EVT_MENU(StatusBar_SetPaneStyleRaised
, MyFrame
::OnSetPaneStyle
)
257 EVT_MENU(StatusBar_SetStyleSizeGrip
, MyFrame
::OnSetStyle
)
258 EVT_MENU(StatusBar_SetStyleEllipsizeStart
, MyFrame
::OnSetStyle
)
259 EVT_MENU(StatusBar_SetStyleEllipsizeMiddle
, MyFrame
::OnSetStyle
)
260 EVT_MENU(StatusBar_SetStyleEllipsizeEnd
, MyFrame
::OnSetStyle
)
261 EVT_MENU(StatusBar_SetStyleShowTips
, MyFrame
::OnSetStyle
)
263 EVT_UPDATE_UI_RANGE(StatusBar_SetFields
, StatusBar_ResetFieldsWidth
,
264 MyFrame
::OnUpdateForDefaultStatusbar
)
265 EVT_UPDATE_UI(StatusBar_Toggle
, MyFrame
::OnUpdateStatusBarToggle
)
266 EVT_UPDATE_UI_RANGE(StatusBar_SetPaneStyleNormal
,
267 StatusBar_SetPaneStyleRaised
,
268 MyFrame
::OnUpdateSetPaneStyle
)
269 EVT_UPDATE_UI_RANGE(StatusBar_SetStyleSizeGrip
, StatusBar_SetStyleShowTips
,
270 MyFrame
::OnUpdateSetStyle
)
273 BEGIN_EVENT_TABLE(MyStatusBar
, wxStatusBar
)
274 EVT_SIZE(MyStatusBar
::OnSize
)
276 EVT_CHECKBOX(StatusBar_Checkbox
, MyStatusBar
::OnToggleClock
)
279 EVT_TIMER(wxID_ANY
, MyStatusBar
::OnTimer
)
283 // Create a new application object: this macro will allow wxWidgets to create
284 // the application object during program execution (it's better than using a
285 // static object for many reasons) and also declares the accessor function
286 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
290 // ============================================================================
292 // ============================================================================
294 // ----------------------------------------------------------------------------
295 // the application class
296 // ----------------------------------------------------------------------------
298 // `Main program' equivalent: the program execution "starts" here
301 if ( !wxApp
::OnInit() )
304 // create the main application window
305 MyFrame
*frame
= new MyFrame(wxT("wxStatusBar sample"),
306 wxPoint(50, 50), wxSize(450, 340));
308 // and show it (the frames, unlike simple controls, are not shown when
309 // created initially)
312 // success: wxApp::OnRun() will be called which will enter the main message
313 // loop and the application will run. If we returned 'false' here, the
314 // application would exit immediately.
318 // ----------------------------------------------------------------------------
320 // ----------------------------------------------------------------------------
323 MyFrame
::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
324 #ifdef USE_MDI_PARENT_FRAME
325 : wxMDIParentFrame(NULL
, wxID_ANY
, title
, pos
, size
)
327 : wxFrame(NULL
, wxID_ANY
, title
, pos
, size
)
330 SetIcon(wxICON(sample
));
332 m_statbarPaneStyle
= wxSB_NORMAL
;
336 wxMenu
*menuFile
= new wxMenu
;
337 menuFile
->Append(StatusBar_Quit
, wxT("E&xit\tAlt-X"),
338 wxT("Quit this program"));
340 wxMenu
*statbarMenu
= new wxMenu
;
342 wxMenu
*statbarStyleMenu
= new wxMenu
;
343 statbarStyleMenu
->Append(StatusBar_SetStyleSizeGrip
, wxT("wxSTB_SIZE_GRIP"),
344 wxT("Toggles the wxSTB_SIZE_GRIP style"), true);
345 statbarStyleMenu
->Append(StatusBar_SetStyleShowTips
, wxT("wxSTB_SHOW_TIPS"),
346 wxT("Toggles the wxSTB_SHOW_TIPS style"), true);
347 statbarStyleMenu
->AppendSeparator();
348 statbarStyleMenu
->AppendCheckItem(StatusBar_SetStyleEllipsizeStart
,
349 wxT("wxSTB_ELLIPSIZE_START"),
350 wxT("Toggle wxSTB_ELLIPSIZE_START style"));
351 statbarStyleMenu
->AppendCheckItem(StatusBar_SetStyleEllipsizeMiddle
,
352 wxT("wxSTB_ELLIPSIZE_MIDDLE"),
353 wxT("Toggle wxSTB_ELLIPSIZE_MIDDLE style"));
354 statbarStyleMenu
->AppendCheckItem(StatusBar_SetStyleEllipsizeEnd
,
355 wxT("wxSTB_ELLIPSIZE_END"),
356 wxT("Toggle wxSTB_ELLIPSIZE_END style"));
357 statbarMenu
->Append(StatusBar_SetPaneStyle
, wxT("Status bar style"),
359 statbarMenu
->AppendSeparator();
361 statbarMenu
->Append(StatusBar_SetField
, "Set active field &number\tCtrl-N",
362 "Set the number of field used by the next commands.");
363 statbarMenu
->Append(StatusBar_SetText
, wxT("Set field &text\tCtrl-T"),
364 wxT("Set the text of the selected field."));
365 statbarMenu
->Append(StatusBar_PushText
, "P&ush field text\tCtrl-P",
366 "Push a message on top the selected field.");
367 statbarMenu
->Append(StatusBar_PopText
, "&Pop field text\tShift-Ctrl-P",
368 "Restore the previous contents of the selected field.");
369 statbarMenu
->AppendSeparator();
371 statbarMenu
->Append(StatusBar_SetFields
, wxT("&Set field count\tCtrl-C"),
372 wxT("Set the number of status bar fields"));
373 statbarMenu
->Append(StatusBar_SetFont
, wxT("&Set field font\tCtrl-F"),
374 wxT("Set the font to use for status bar fields"));
376 wxMenu
*statbarPaneStyleMenu
= new wxMenu
;
377 statbarPaneStyleMenu
->AppendCheckItem
379 StatusBar_SetPaneStyleNormal
,
381 wxT("Sets the style of the first field to normal (sunken) look")
383 statbarPaneStyleMenu
->AppendCheckItem
385 StatusBar_SetPaneStyleFlat
,
387 wxT("Sets the style of the first field to flat look")
389 statbarPaneStyleMenu
->AppendCheckItem
391 StatusBar_SetPaneStyleRaised
,
393 wxT("Sets the style of the first field to raised look")
395 statbarMenu
->Append(StatusBar_SetPaneStyle
, wxT("Field style"),
396 statbarPaneStyleMenu
);
398 statbarMenu
->Append(StatusBar_ResetFieldsWidth
, wxT("Reset field widths"),
399 wxT("Sets all fields to the same width"));
400 statbarMenu
->Append(StatusBar_ShowFieldsRect
,
401 wxT("Sho&w field rectangles\tCtrl-W"),
402 wxT("Visually show field rectangles"));
403 statbarMenu
->AppendSeparator();
405 statbarMenu
->AppendCheckItem(StatusBar_Toggle
, wxT("&Toggle Status Bar"),
406 wxT("Toggle the status bar display"));
407 statbarMenu
->Append(StatusBar_Recreate
, wxT("&Recreate\tCtrl-R"),
408 wxT("Toggle status bar format"));
410 wxMenu
*helpMenu
= new wxMenu
;
411 helpMenu
->Append(StatusBar_About
, wxT("&About...\tCtrl-A"),
412 wxT("Show about dialog"));
414 // now append the freshly created menu to the menu bar...
415 wxMenuBar
*menuBar
= new wxMenuBar();
416 menuBar
->Append(menuFile
, wxT("&File"));
417 menuBar
->Append(statbarMenu
, wxT("&Status bar"));
418 menuBar
->Append(helpMenu
, wxT("&Help"));
420 // ... and attach this menu bar to the frame
423 // create default status bar to start with
424 DoCreateStatusBar(StatBar_Default
, wxSTB_DEFAULT_STYLE
);
425 SetStatusText(wxT("Welcome to wxWidgets!"));
428 void MyFrame
::DoCreateStatusBar(MyFrame
::StatusBarKind kind
, long style
)
430 wxStatusBar
*statbarOld
= GetStatusBar();
437 wxStatusBar
*statbarNew
= NULL
;
440 case StatBar_Default
:
441 statbarNew
= new wxStatusBar(this, wxID_ANY
, style
, "wxStatusBar");
442 statbarNew
->SetFieldsCount(2);
446 statbarNew
= new MyStatusBar(this, style
);
450 wxFAIL_MSG(wxT("unknown status bar kind"));
453 SetStatusBar(statbarNew
);
457 m_statbarKind
= kind
;
461 // ----------------------------------------------------------------------------
462 // main frame - event handlers
463 // ----------------------------------------------------------------------------
465 void MyFrame
::OnUpdateForDefaultStatusbar(wxUpdateUIEvent
& event
)
467 // only allow this feature for the default status bar
468 wxStatusBar
*sb
= GetStatusBar();
472 event
.Enable(sb
->GetName() == "wxStatusBar");
475 void MyFrame
::OnSetStatusField(wxCommandEvent
& WXUNUSED(event
))
477 wxStatusBar
*sb
= GetStatusBar();
481 long rc
= wxGetNumberFromUser
483 "Configure the field index to be used by the set, push "
484 "and pop text commands in the menu.\n"
486 "0 corresponds to the first field, 1 to the second one "
489 SAMPLE_DIALOGS_TITLE
,
492 sb
->GetFieldsCount() - 1,
501 wxLogStatus("Status bar text will be set for field #%d", m_field
);
504 void MyFrame
::OnSetStatusText(wxCommandEvent
& WXUNUSED(event
))
506 wxStatusBar
*sb
= GetStatusBar();
510 wxString txt
= wxGetTextFromUser
514 "Enter the text from for the field #%d",
517 SAMPLE_DIALOGS_TITLE
,
518 sb
->GetStatusText(m_field
),
525 sb
->SetStatusText(txt
, m_field
);
528 // the current depth of the stack used by Push/PopStatusText()
529 static int gs_depth
= 0;
531 void MyFrame
::OnPushStatusText(wxCommandEvent
& WXUNUSED(event
))
533 wxStatusBar
*sb
= GetStatusBar();
537 static int s_countPush
= 0;
538 sb
->PushStatusText(wxString
::Format
540 "Pushed message #%d (depth = %d)",
541 ++s_countPush
, ++gs_depth
545 void MyFrame
::OnPopStatusText(wxCommandEvent
& WXUNUSED(event
))
547 wxStatusBar
*sb
= GetStatusBar();
553 wxLogStatus("No message to pop.");
558 sb
->PopStatusText(m_field
);
561 void MyFrame
::OnSetStatusFont(wxCommandEvent
& WXUNUSED(event
))
563 wxStatusBar
*sb
= GetStatusBar();
568 fnt
= wxGetFontFromUser(this, sb
->GetFont(), "Choose status bar font");
572 sb
->SetSize(sb
->GetBestSize());
576 void MyFrame
::OnSetStatusFields(wxCommandEvent
& WXUNUSED(event
))
578 wxStatusBar
*sb
= GetStatusBar();
582 long nFields
= wxGetNumberFromUser
584 wxT("Select the number of fields in the status bar"),
586 SAMPLE_DIALOGS_TITLE
,
587 sb
->GetFieldsCount(),
592 // we don't check if the number changed at all on purpose: calling
593 // SetFieldsCount() with the same number of fields should be ok
596 static const int widthsFor2Fields
[] = { 200, -1 };
597 static const int widthsFor3Fields
[] = { -1, -2, -1 };
598 static const int widthsFor4Fields
[] = { 100, -1, 100, -2, 100 };
600 static const int *widthsAll
[] =
602 NULL
, // 1 field: default
603 widthsFor2Fields
, // 2 fields: 1 fixed, 1 var
604 widthsFor3Fields
, // 3 fields: 3 var
605 widthsFor4Fields
, // 4 fields: 3 fixed, 2 vars
606 NULL
// 5 fields: default (all have same width)
609 const int * const widths
= widthsAll
[nFields
- 1];
610 sb
->SetFieldsCount(nFields
, widths
);
613 for ( long n
= 0; n
< nFields
; n
++ )
618 s
.Printf(wxT("fixed (%d)"), widths
[n
]);
620 s
.Printf(wxT("variable (*%d)"), -widths
[n
]);
630 if ( m_field
>= nFields
)
631 m_field
= nFields
- 1;
635 wxLogStatus(this, wxT("Cancelled"));
639 void MyFrame
::OnResetFieldsWidth(wxCommandEvent
& WXUNUSED(event
))
641 wxStatusBar
*pStat
= GetStatusBar();
645 const int n
= pStat
->GetFieldsCount();
646 pStat
->SetStatusWidths(n
, NULL
);
647 for ( int i
= 0; i
< n
; i
++ )
648 pStat
->SetStatusText("same size", i
);
651 void MyFrame
::OnShowFieldsRect(wxCommandEvent
& WXUNUSED(event
))
653 wxStatusBar
*pStat
= GetStatusBar();
657 wxClientDC
dc(pStat
);
658 dc
.SetPen(*wxRED_PEN
);
659 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
661 const int n
= pStat
->GetFieldsCount();
662 for ( int i
= 0; i
< n
; i
++ )
665 if ( pStat
->GetFieldRect(i
, r
) )
670 void MyFrame
::OnUpdateStatusBarToggle(wxUpdateUIEvent
& event
)
672 event
.Check(GetStatusBar() != NULL
);
675 void MyFrame
::OnStatusBarToggle(wxCommandEvent
& WXUNUSED(event
))
677 wxStatusBar
*statbarOld
= GetStatusBar();
685 DoCreateStatusBar(m_statbarKind
, wxSTB_DEFAULT_STYLE
);
689 void MyFrame
::OnRecreateStatusBar(wxCommandEvent
& WXUNUSED(event
))
691 DoCreateStatusBar(m_statbarKind
== StatBar_Custom ? StatBar_Default
693 wxSTB_DEFAULT_STYLE
);
696 void MyFrame
::OnQuit(wxCommandEvent
& WXUNUSED(event
))
698 // true is to force the frame to close
702 void MyFrame
::OnAbout(wxCommandEvent
& WXUNUSED(event
))
704 MyAboutDialog
dlg(this);
708 void MyFrame
::OnUpdateSetPaneStyle(wxUpdateUIEvent
& event
)
710 switch (event
.GetId())
712 case StatusBar_SetPaneStyleNormal
:
713 event
.Check(m_statbarPaneStyle
== wxSB_NORMAL
);
715 case StatusBar_SetPaneStyleFlat
:
716 event
.Check(m_statbarPaneStyle
== wxSB_FLAT
);
718 case StatusBar_SetPaneStyleRaised
:
719 event
.Check(m_statbarPaneStyle
== wxSB_RAISED
);
724 void MyFrame
::OnSetPaneStyle(wxCommandEvent
& event
)
726 switch (event
.GetId())
728 case StatusBar_SetPaneStyleNormal
:
729 m_statbarPaneStyle
= wxSB_NORMAL
;
731 case StatusBar_SetPaneStyleFlat
:
732 m_statbarPaneStyle
= wxSB_FLAT
;
734 case StatusBar_SetPaneStyleRaised
:
735 m_statbarPaneStyle
= wxSB_RAISED
;
742 void MyFrame
::ApplyPaneStyle()
744 wxStatusBar
*sb
= GetStatusBar();
748 int fields
= sb
->GetFieldsCount();
749 int *styles
= new int[fields
];
751 for (int i
= 1; i
< fields
; i
++)
752 styles
[i
] = wxSB_NORMAL
;
754 styles
[0] = m_statbarPaneStyle
;
756 sb
->SetStatusStyles(fields
, styles
);
761 void MyFrame
::OnUpdateSetStyle(wxUpdateUIEvent
& event
)
763 long currentStyle
= wxSTB_DEFAULT_STYLE
;
765 currentStyle
= GetStatusBar()->GetWindowStyle();
767 switch (event
.GetId())
769 case StatusBar_SetStyleSizeGrip
:
770 event
.Check((currentStyle
& wxSTB_SIZEGRIP
) != 0);
772 case StatusBar_SetStyleShowTips
:
773 event
.Check((currentStyle
& wxSTB_SHOW_TIPS
) != 0);
776 case StatusBar_SetStyleEllipsizeStart
:
777 event
.Check((currentStyle
& wxSTB_ELLIPSIZE_START
) != 0);
779 case StatusBar_SetStyleEllipsizeMiddle
:
780 event
.Check((currentStyle
& wxSTB_ELLIPSIZE_MIDDLE
) != 0);
782 case StatusBar_SetStyleEllipsizeEnd
:
783 event
.Check((currentStyle
& wxSTB_ELLIPSIZE_END
) != 0);
788 void MyFrame
::OnSetStyle(wxCommandEvent
& event
)
790 long oldStyle
= wxSTB_DEFAULT_STYLE
;
792 oldStyle
= GetStatusBar()->GetWindowStyle();
794 #define STB_ELLIPSIZE_MASK \
795 (wxSTB_ELLIPSIZE_START|wxSTB_ELLIPSIZE_MIDDLE|wxSTB_ELLIPSIZE_END)
797 long newStyle
= oldStyle
;
798 long newStyleBit
= 0;
799 switch (event
.GetId())
801 case StatusBar_SetStyleSizeGrip
:
802 newStyleBit
= wxSTB_SIZEGRIP
;
804 case StatusBar_SetStyleShowTips
:
805 newStyleBit
= wxSTB_SHOW_TIPS
;
808 case StatusBar_SetStyleEllipsizeStart
:
809 newStyleBit
= wxSTB_ELLIPSIZE_START
;
810 newStyle
&= ~STB_ELLIPSIZE_MASK
;
812 case StatusBar_SetStyleEllipsizeMiddle
:
813 newStyleBit
= wxSTB_ELLIPSIZE_MIDDLE
;
814 newStyle
&= ~STB_ELLIPSIZE_MASK
;
816 case StatusBar_SetStyleEllipsizeEnd
:
817 newStyleBit
= wxSTB_ELLIPSIZE_END
;
818 newStyle
&= ~STB_ELLIPSIZE_MASK
;
822 newStyle
= event
.IsChecked() ?
(newStyle
| newStyleBit
) :
823 (newStyle
& ~newStyleBit
);
824 if (newStyle
!= oldStyle
)
826 DoCreateStatusBar(m_statbarKind
, newStyle
);
827 SetStatusText("Status bar recreated with a new style");
831 // ----------------------------------------------------------------------------
833 // ----------------------------------------------------------------------------
835 MyAboutDialog
::MyAboutDialog(wxWindow
*parent
)
836 : wxDialog(parent
, wxID_ANY
, wxString(wxT("About statbar")),
837 wxDefaultPosition
, wxDefaultSize
,
838 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
840 wxStaticText
*text
= new wxStaticText(this, wxID_ANY
,
841 wxT("wxStatusBar sample\n")
842 wxT("(c) 2000 Vadim Zeitlin"));
844 wxButton
*btn
= new wxButton(this, wxID_OK
, wxT("&Close"));
846 // create the top status bar without the size grip (default style),
847 // otherwise it looks weird
848 wxStatusBar
*statbarTop
= new wxStatusBar(this, wxID_ANY
, 0);
849 statbarTop
->SetFieldsCount(3);
850 statbarTop
->SetStatusText(wxT("This is a top status bar"), 0);
851 statbarTop
->SetStatusText(wxT("in a dialog"), 1);
852 statbarTop
->SetStatusText(wxT("Great, isn't it?"), 2);
854 wxStatusBar
*statbarBottom
= new wxStatusBar(this, wxID_ANY
);
855 statbarBottom
->SetFieldsCount(2);
856 statbarBottom
->SetStatusText(wxT("This is a bottom status bar"), 0);
857 statbarBottom
->SetStatusText(wxT("in a dialog"), 1);
859 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
860 sizerTop
->Add(statbarTop
, 0, wxGROW
);
861 sizerTop
->Add(-1, 10, 1, wxGROW
);
862 sizerTop
->Add(text
, 0, wxCENTRE
| wxRIGHT
| wxLEFT
, 20);
863 sizerTop
->Add(-1, 10, 1, wxGROW
);
864 sizerTop
->Add(btn
, 0, wxCENTRE
| wxRIGHT
| wxLEFT
, 20);
865 sizerTop
->Add(-1, 10, 1, wxGROW
);
866 sizerTop
->Add(statbarBottom
, 0, wxGROW
);
868 SetSizerAndFit(sizerTop
);
871 // ----------------------------------------------------------------------------
873 // ----------------------------------------------------------------------------
876 // 'this' : used in base member initializer list -- so what??
877 #pragma warning(disable: 4355)
880 MyStatusBar
::MyStatusBar(wxWindow
*parent
, long style
)
881 : wxStatusBar(parent
, wxID_ANY
, style
, "MyStatusBar")
889 static const int widths
[Field_Max
] = { -1, 150, BITMAP_SIZE_X
, 100 };
891 SetFieldsCount(Field_Max
);
892 SetStatusWidths(Field_Max
, widths
);
895 m_checkbox
= new wxCheckBox(this, StatusBar_Checkbox
, wxT("&Toggle clock"));
896 m_checkbox
->SetValue(true);
899 m_statbmp
= new wxStaticBitmap(this, wxID_ANY
, wxIcon(green_xpm
));
905 SetMinHeight(wxMax(m_statbmp
->GetBestSize().GetHeight(),
906 m_checkbox
->GetBestSize().GetHeight()));
912 #pragma warning(default: 4355)
915 MyStatusBar
::~MyStatusBar()
918 if ( m_timer
.IsRunning() )
925 void MyStatusBar
::OnSize(wxSizeEvent
& event
)
932 // TEMPORARY HACK: TODO find a more general solution
933 #ifdef wxStatusBarGeneric
934 wxStatusBar
::OnSize(event
);
938 if (!GetFieldRect(Field_Checkbox
, rect
))
945 wxRect rectCheck
= rect
;
946 rectCheck
.Deflate(2);
947 m_checkbox
->SetSize(rectCheck
);
950 GetFieldRect(Field_Bitmap
, rect
);
951 wxSize size
= m_statbmp
->GetSize();
953 m_statbmp
->Move(rect
.x
+ (rect
.width
- size
.x
) / 2,
954 rect
.y
+ (rect
.height
- size
.y
) / 2);
959 void MyStatusBar
::OnToggleClock(wxCommandEvent
& WXUNUSED(event
))
964 void MyStatusBar
::DoToggle()
967 if ( m_checkbox
->GetValue() )
973 m_statbmp
->SetIcon(wxIcon(green_xpm
));
977 else // don't show clock
983 m_statbmp
->SetIcon(wxIcon(red_xpm
));
985 SetStatusText(wxEmptyString
, Field_Clock
);
987 #endif // wxUSE_CHECKBOX
990 void MyStatusBar
::UpdateClock()
992 SetStatusText(wxDateTime
::Now().FormatTime(), Field_Clock
);