1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxStatusBar sample
4 // Author: Vadim Zeitlin
8 // Copyright: (c) Vadim Zeitlin
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx/wx.h".
21 #include "wx/wxprec.h"
28 #error "You need to set wxUSE_STATUSBAR to 1 to compile this sample"
29 #endif // wxUSE_STATUSBAR
31 // for all others, include the necessary headers
36 #include "wx/statusbr.h"
38 #include "wx/checkbox.h"
39 #include "wx/statbmp.h"
41 #include "wx/msgdlg.h"
42 #include "wx/textdlg.h"
44 #include "wx/stattext.h"
45 #include "wx/bmpbuttn.h"
46 #include "wx/dcmemory.h"
49 #include "wx/datetime.h"
50 #include "wx/numdlg.h"
51 #include "wx/fontdlg.h"
54 #include "../sample.xpm"
58 // define this for the platforms which don't support wxBitmapButton (such as
59 // Motif), else a wxBitmapButton will be used
61 #define USE_STATIC_BITMAP
64 //#define USE_MDI_PARENT_FRAME 1
66 #ifdef USE_MDI_PARENT_FRAME
68 #endif // USE_MDI_PARENT_FRAME
70 static const char *SAMPLE_DIALOGS_TITLE
= "wxWidgets statbar sample";
72 // ----------------------------------------------------------------------------
74 // ----------------------------------------------------------------------------
76 #ifdef USE_STATIC_BITMAP
79 #endif // USE_STATIC_BITMAP
81 // ----------------------------------------------------------------------------
83 // ----------------------------------------------------------------------------
85 // Define a new application type, each program should derive a class from wxApp
86 class MyApp
: public wxApp
89 // override base class virtuals
90 // ----------------------------
92 // this one is called on application startup and is a good place for the app
93 // initialization (doing it here and not in the ctor allows to have an error
94 // return: if OnInit() returns false, the application terminates)
95 virtual bool OnInit();
98 // A custom status bar which contains controls, icons &c
99 class MyStatusBar
: public wxStatusBar
102 MyStatusBar(wxWindow
*parent
, long style
= wxSTB_DEFAULT_STYLE
);
103 virtual ~MyStatusBar();
109 void OnTimer(wxTimerEvent
& WXUNUSED(event
)) { UpdateClock(); }
111 void OnSize(wxSizeEvent
& event
);
112 void OnToggleClock(wxCommandEvent
& event
);
113 void OnButton(wxCommandEvent
& event
);
116 // toggle the state of the status bar controls
119 wxBitmap
CreateBitmapForButton(bool on
= false);
135 wxCheckBox
*m_checkbox
;
137 #ifdef USE_STATIC_BITMAP
138 wxStaticBitmap
*m_statbmp
;
140 wxBitmapButton
*m_statbmp
;
143 DECLARE_EVENT_TABLE()
146 // Define a new frame type: this is going to be our main frame
147 class MyFrame
: public wxFrame
151 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
152 #ifdef USE_MDI_PARENT_FRAME
153 class MyFrame
: public wxMDIParentFrame
158 // event handlers (these functions should _not_ be virtual)
159 void OnQuit(wxCommandEvent
& event
);
160 void OnAbout(wxCommandEvent
& event
);
162 void OnSetStatusField(wxCommandEvent
& event
);
163 void OnSetStatusText(wxCommandEvent
& event
);
164 void OnPushStatusText(wxCommandEvent
& event
);
165 void OnPopStatusText(wxCommandEvent
& event
);
167 void OnResetFieldsWidth(wxCommandEvent
& event
);
168 void OnSetStatusFields(wxCommandEvent
& event
);
169 void OnSetStatusFont(wxCommandEvent
& event
);
170 void OnRecreateStatusBar(wxCommandEvent
& event
);
172 void OnSetPaneStyle(wxCommandEvent
& event
);
173 void OnSetStyle(wxCommandEvent
& event
);
184 void OnUpdateForDefaultStatusbar(wxUpdateUIEvent
& event
);
185 void OnUpdateStatusBarToggle(wxUpdateUIEvent
& event
);
186 void OnUpdateSetPaneStyle(wxUpdateUIEvent
& event
);
187 void OnUpdateSetStyle(wxUpdateUIEvent
& event
);
188 void OnStatusBarToggle(wxCommandEvent
& event
);
189 void DoCreateStatusBar(StatusBarKind kind
, long style
);
190 void ApplyPaneStyle();
192 int m_statbarPaneStyle
;
194 // the index of the field used by some commands
197 // any class wishing to process wxWidgets events must use this macro
198 DECLARE_EVENT_TABLE()
201 // Our about dialog ith its status bar
202 class MyAboutDialog
: public wxDialog
205 MyAboutDialog(wxWindow
*parent
);
208 // ----------------------------------------------------------------------------
210 // ----------------------------------------------------------------------------
212 // IDs for the controls and the menu commands
216 StatusBar_Quit
= wxID_EXIT
,
217 StatusBar_About
= wxID_ABOUT
,
219 StatusBar_SetFields
= wxID_HIGHEST
+1,
225 StatusBar_ResetFieldsWidth
,
230 StatusBar_SetPaneStyle
,
231 StatusBar_SetPaneStyleNormal
,
232 StatusBar_SetPaneStyleFlat
,
233 StatusBar_SetPaneStyleRaised
,
235 StatusBar_SetStyleSizeGrip
,
236 StatusBar_SetStyleEllipsizeStart
,
237 StatusBar_SetStyleEllipsizeMiddle
,
238 StatusBar_SetStyleEllipsizeEnd
,
239 StatusBar_SetStyleShowTips
242 static const int BITMAP_SIZE_X
= 32;
243 static const int BITMAP_SIZE_Y
= 15;
245 // ----------------------------------------------------------------------------
246 // event tables and other macros for wxWidgets
247 // ----------------------------------------------------------------------------
249 // the event tables connect the wxWidgets events with the functions (event
250 // handlers) which process them. It can be also done at run-time, but for the
251 // simple menu events like this the static method is much simpler.
252 #ifdef USE_MDI_PARENT_FRAME
253 BEGIN_EVENT_TABLE(MyFrame
, wxMDIParentFrame
)
255 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
257 EVT_MENU(StatusBar_Quit
, MyFrame::OnQuit
)
258 EVT_MENU(StatusBar_SetFields
, MyFrame::OnSetStatusFields
)
259 EVT_MENU(StatusBar_SetField
, MyFrame::OnSetStatusField
)
260 EVT_MENU(StatusBar_SetText
, MyFrame::OnSetStatusText
)
261 EVT_MENU(StatusBar_PushText
, MyFrame::OnPushStatusText
)
262 EVT_MENU(StatusBar_PopText
, MyFrame::OnPopStatusText
)
263 EVT_MENU(StatusBar_SetFont
, MyFrame::OnSetStatusFont
)
264 EVT_MENU(StatusBar_ResetFieldsWidth
, MyFrame::OnResetFieldsWidth
)
265 EVT_MENU(StatusBar_Recreate
, MyFrame::OnRecreateStatusBar
)
266 EVT_MENU(StatusBar_About
, MyFrame::OnAbout
)
267 EVT_MENU(StatusBar_Toggle
, MyFrame::OnStatusBarToggle
)
268 EVT_MENU(StatusBar_SetPaneStyleNormal
, MyFrame::OnSetPaneStyle
)
269 EVT_MENU(StatusBar_SetPaneStyleFlat
, MyFrame::OnSetPaneStyle
)
270 EVT_MENU(StatusBar_SetPaneStyleRaised
, MyFrame::OnSetPaneStyle
)
272 EVT_MENU(StatusBar_SetStyleSizeGrip
, MyFrame::OnSetStyle
)
273 EVT_MENU(StatusBar_SetStyleEllipsizeStart
, MyFrame::OnSetStyle
)
274 EVT_MENU(StatusBar_SetStyleEllipsizeMiddle
, MyFrame::OnSetStyle
)
275 EVT_MENU(StatusBar_SetStyleEllipsizeEnd
, MyFrame::OnSetStyle
)
276 EVT_MENU(StatusBar_SetStyleShowTips
, MyFrame::OnSetStyle
)
278 EVT_UPDATE_UI_RANGE(StatusBar_SetFields
, StatusBar_ResetFieldsWidth
,
279 MyFrame::OnUpdateForDefaultStatusbar
)
280 EVT_UPDATE_UI(StatusBar_Toggle
, MyFrame::OnUpdateStatusBarToggle
)
281 EVT_UPDATE_UI_RANGE(StatusBar_SetPaneStyleNormal
, StatusBar_SetPaneStyleRaised
,
282 MyFrame::OnUpdateSetPaneStyle
)
283 EVT_UPDATE_UI_RANGE(StatusBar_SetStyleSizeGrip
, StatusBar_SetStyleShowTips
,
284 MyFrame::OnUpdateSetStyle
)
287 BEGIN_EVENT_TABLE(MyStatusBar
, wxStatusBar
)
288 EVT_SIZE(MyStatusBar::OnSize
)
290 EVT_CHECKBOX(StatusBar_Checkbox
, MyStatusBar::OnToggleClock
)
292 EVT_BUTTON(wxID_ANY
, MyStatusBar::OnButton
)
294 EVT_TIMER(wxID_ANY
, MyStatusBar::OnTimer
)
298 // Create a new application object: this macro will allow wxWidgets to create
299 // the application object during program execution (it's better than using a
300 // static object for many reasons) and also declares the accessor function
301 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
305 // ============================================================================
307 // ============================================================================
309 // ----------------------------------------------------------------------------
310 // the application class
311 // ----------------------------------------------------------------------------
313 // `Main program' equivalent: the program execution "starts" here
316 if ( !wxApp::OnInit() )
319 // create the main application window
320 MyFrame
*frame
= new MyFrame(wxT("wxStatusBar sample"),
321 wxPoint(50, 50), wxSize(450, 340));
323 // and show it (the frames, unlike simple controls, are not shown when
324 // created initially)
327 // success: wxApp::OnRun() will be called which will enter the main message
328 // loop and the application will run. If we returned 'false' here, the
329 // application would exit immediately.
333 // ----------------------------------------------------------------------------
335 // ----------------------------------------------------------------------------
338 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
339 #ifdef USE_MDI_PARENT_FRAME
340 : wxMDIParentFrame((wxWindow
*)NULL
, wxID_ANY
, title
, pos
, size
)
342 : wxFrame((wxWindow
*)NULL
, wxID_ANY
, title
, pos
, size
)
345 SetIcon(wxICON(sample
));
347 m_statbarPaneStyle
= wxSB_NORMAL
;
351 // we need this in order to allow the about menu relocation, since ABOUT is
352 // not the default id of the about menu
353 wxApp::s_macAboutMenuItemId
= StatusBar_About
;
357 wxMenu
*menuFile
= new wxMenu
;
358 menuFile
->Append(StatusBar_Quit
, wxT("E&xit\tAlt-X"), wxT("Quit this program"));
360 wxMenu
*statbarMenu
= new wxMenu
;
362 wxMenu
*statbarStyleMenu
= new wxMenu
;
363 statbarStyleMenu
->Append(StatusBar_SetStyleSizeGrip
, wxT("wxSTB_SIZE_GRIP"), wxT("Toggles the wxSTB_SIZE_GRIP style"), true);
364 statbarStyleMenu
->Append(StatusBar_SetStyleShowTips
, wxT("wxSTB_SHOW_TIPS"), wxT("Toggles the wxSTB_SHOW_TIPS style"), true);
365 statbarStyleMenu
->AppendSeparator();
366 statbarStyleMenu
->Append(StatusBar_SetStyleEllipsizeStart
, wxT("wxSTB_ELLIPSIZE_START"), wxT("Toggles the wxSTB_ELLIPSIZE_START style"), true);
367 statbarStyleMenu
->Append(StatusBar_SetStyleEllipsizeMiddle
, wxT("wxSTB_ELLIPSIZE_MIDDLE"), wxT("Toggles the wxSTB_ELLIPSIZE_MIDDLE style"), true);
368 statbarStyleMenu
->Append(StatusBar_SetStyleEllipsizeEnd
, wxT("wxSTB_ELLIPSIZE_END"), wxT("Toggles the wxSTB_ELLIPSIZE_END style"), true);
369 statbarMenu
->Append(StatusBar_SetPaneStyle
, wxT("Status bar style"), statbarStyleMenu
);
370 statbarMenu
->AppendSeparator();
372 statbarMenu
->Append(StatusBar_SetField
, "Set active field &number\tCtrl-N",
373 "Set the number of field used by the next commands.");
374 statbarMenu
->Append(StatusBar_SetText
, wxT("Set field &text\tCtrl-T"),
375 wxT("Set the text of the selected field."));
376 statbarMenu
->Append(StatusBar_PushText
, "P&ush field text\tCtrl-P",
377 "Push a message on top the selected field.");
378 statbarMenu
->Append(StatusBar_PopText
, "&Pop field text\tShift-Ctrl-P",
379 "Restore the previous contents of the selected field.");
380 statbarMenu
->AppendSeparator();
382 statbarMenu
->Append(StatusBar_SetFields
, wxT("&Set field count\tCtrl-C"),
383 wxT("Set the number of status bar fields"));
384 statbarMenu
->Append(StatusBar_SetFont
, wxT("&Set field font\tCtrl-F"),
385 wxT("Set the font to use for rendering status bar fields"));
387 wxMenu
*statbarPaneStyleMenu
= new wxMenu
;
388 statbarPaneStyleMenu
->Append(StatusBar_SetPaneStyleNormal
, wxT("&Normal"), wxT("Sets the style of the first field to normal (sunken) look"), true);
389 statbarPaneStyleMenu
->Append(StatusBar_SetPaneStyleFlat
, wxT("&Flat"), wxT("Sets the style of the first field to flat look"), true);
390 statbarPaneStyleMenu
->Append(StatusBar_SetPaneStyleRaised
, wxT("&Raised"), wxT("Sets the style of the first field to raised look"), true);
391 statbarMenu
->Append(StatusBar_SetPaneStyle
, wxT("Field style"), statbarPaneStyleMenu
);
393 statbarMenu
->Append(StatusBar_ResetFieldsWidth
, wxT("Reset field widths"),
394 wxT("Sets all fields to the same width"));
395 statbarMenu
->AppendSeparator();
397 statbarMenu
->Append(StatusBar_Toggle
, wxT("&Toggle Status Bar"),
398 wxT("Toggle the status bar display"), true);
399 statbarMenu
->Append(StatusBar_Recreate
, wxT("&Recreate\tCtrl-R"),
400 wxT("Toggle status bar format"));
402 wxMenu
*helpMenu
= new wxMenu
;
403 helpMenu
->Append(StatusBar_About
, wxT("&About...\tCtrl-A"), wxT("Show about dialog"));
405 // now append the freshly created menu to the menu bar...
406 wxMenuBar
*menuBar
= new wxMenuBar();
407 menuBar
->Append(menuFile
, wxT("&File"));
408 menuBar
->Append(statbarMenu
, wxT("&Status bar"));
409 menuBar
->Append(helpMenu
, wxT("&Help"));
411 // ... and attach this menu bar to the frame
414 // create default status bar to start with
415 DoCreateStatusBar(StatBar_Default
, wxSTB_DEFAULT_STYLE
);
416 SetStatusText(wxT("Welcome to wxWidgets!"));
423 void MyFrame::DoCreateStatusBar(MyFrame::StatusBarKind kind
, long style
)
425 wxStatusBar
*statbarOld
= GetStatusBar();
432 wxStatusBar
*statbarNew
= NULL
;
435 case StatBar_Default
:
436 statbarNew
= new wxStatusBar(this, wxID_ANY
, style
, "wxStatusBar");
437 statbarNew
->SetFieldsCount(2);
441 statbarNew
= new MyStatusBar(this, style
);
445 wxFAIL_MSG(wxT("unknown status bar kind"));
448 SetStatusBar(statbarNew
);
452 m_statbarKind
= kind
;
456 // ----------------------------------------------------------------------------
457 // main frame - event handlers
458 // ----------------------------------------------------------------------------
460 void MyFrame::OnUpdateForDefaultStatusbar(wxUpdateUIEvent
& event
)
462 // only allow this feature for the default status bar
463 wxStatusBar
*sb
= GetStatusBar();
467 event
.Enable(sb
->GetName() == "wxStatusBar");
470 void MyFrame::OnSetStatusField(wxCommandEvent
& WXUNUSED(event
))
472 wxStatusBar
*sb
= GetStatusBar();
476 long rc
= wxGetNumberFromUser
478 "Configure the field index to be used by the set, push "
479 "and pop text commands in the menu.\n"
481 "0 corresponds to the first field, 1 to the second one "
484 SAMPLE_DIALOGS_TITLE
,
487 sb
->GetFieldsCount() - 1,
496 wxLogStatus("Status bar text will be set for field #%d", m_field
);
499 void MyFrame::OnSetStatusText(wxCommandEvent
& WXUNUSED(event
))
501 wxStatusBar
*sb
= GetStatusBar();
505 wxString txt
= wxGetTextFromUser
509 "Enter the text from for the field #%d",
512 SAMPLE_DIALOGS_TITLE
,
513 sb
->GetStatusText(m_field
),
520 sb
->SetStatusText(txt
, m_field
);
523 // the current depth of the stack used by Push/PopStatusText()
524 static int gs_depth
= 0;
526 void MyFrame::OnPushStatusText(wxCommandEvent
& WXUNUSED(event
))
528 wxStatusBar
*sb
= GetStatusBar();
532 static int s_countPush
= 0;
533 sb
->PushStatusText(wxString::Format
535 "Pushed message #%d (depth = %d)",
536 ++s_countPush
, ++gs_depth
540 void MyFrame::OnPopStatusText(wxCommandEvent
& WXUNUSED(event
))
542 wxStatusBar
*sb
= GetStatusBar();
548 wxLogStatus("No message to pop.");
553 sb
->PopStatusText(m_field
);
556 void MyFrame::OnSetStatusFont(wxCommandEvent
& WXUNUSED(event
))
558 wxStatusBar
*sb
= GetStatusBar();
562 wxFont fnt
= wxGetFontFromUser(this, sb
->GetFont(), "Choose statusbar font");
566 sb
->SetSize(sb
->GetBestSize());
570 void MyFrame::OnSetStatusFields(wxCommandEvent
& WXUNUSED(event
))
572 wxStatusBar
*sb
= GetStatusBar();
576 long nFields
= wxGetNumberFromUser
578 wxT("Select the number of fields in the status bar"),
580 SAMPLE_DIALOGS_TITLE
,
581 sb
->GetFieldsCount(),
586 // we don't check if the number changed at all on purpose: calling
587 // SetFieldsCount() with the same number of fields should be ok
590 static const int widthsFor2Fields
[] = { 200, -1 };
591 static const int widthsFor3Fields
[] = { -1, -2, -1 };
592 static const int widthsFor4Fields
[] = { 100, -1, 100, -2, 100 };
594 static const int *widthsAll
[] =
596 NULL
, // 1 field: default
597 widthsFor2Fields
, // 2 fields: 1 fixed, 1 var
598 widthsFor3Fields
, // 3 fields: 3 var
599 widthsFor4Fields
, // 4 fields: 3 fixed, 2 vars
600 NULL
// 5 fields: default (all have same width)
603 const int * const widths
= widthsAll
[nFields
- 1];
604 sb
->SetFieldsCount(nFields
, widths
);
607 for ( long n
= 0; n
< nFields
; n
++ )
612 s
.Printf(wxT("fixed (%d)"), widths
[n
]);
614 s
.Printf(wxT("variable (*%d)"), -widths
[n
]);
624 if ( m_field
>= nFields
)
625 m_field
= nFields
- 1;
629 wxLogStatus(this, wxT("Cancelled"));
633 void MyFrame::OnResetFieldsWidth(wxCommandEvent
& WXUNUSED(event
))
635 wxStatusBar
*pStat
= GetStatusBar();
639 int n
= pStat
->GetFieldsCount();
640 pStat
->SetStatusWidths(n
, NULL
);
641 for (int i
=0; i
<n
; i
++)
642 pStat
->SetStatusText("same size", i
);
645 void MyFrame::OnUpdateStatusBarToggle(wxUpdateUIEvent
& event
)
647 event
.Check(GetStatusBar() != NULL
);
650 void MyFrame::OnStatusBarToggle(wxCommandEvent
& WXUNUSED(event
))
652 wxStatusBar
*statbarOld
= GetStatusBar();
660 DoCreateStatusBar(m_statbarKind
, wxSTB_DEFAULT_STYLE
);
664 void MyFrame::OnRecreateStatusBar(wxCommandEvent
& WXUNUSED(event
))
666 DoCreateStatusBar(m_statbarKind
== StatBar_Custom
? StatBar_Default
668 wxSTB_DEFAULT_STYLE
);
671 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
673 // true is to force the frame to close
677 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
679 MyAboutDialog
dlg(this);
683 void MyFrame::OnUpdateSetPaneStyle(wxUpdateUIEvent
& event
)
685 switch (event
.GetId())
687 case StatusBar_SetPaneStyleNormal
:
688 event
.Check(m_statbarPaneStyle
== wxSB_NORMAL
);
690 case StatusBar_SetPaneStyleFlat
:
691 event
.Check(m_statbarPaneStyle
== wxSB_FLAT
);
693 case StatusBar_SetPaneStyleRaised
:
694 event
.Check(m_statbarPaneStyle
== wxSB_RAISED
);
699 void MyFrame::OnSetPaneStyle(wxCommandEvent
& event
)
701 switch (event
.GetId())
703 case StatusBar_SetPaneStyleNormal
:
704 m_statbarPaneStyle
= wxSB_NORMAL
;
706 case StatusBar_SetPaneStyleFlat
:
707 m_statbarPaneStyle
= wxSB_FLAT
;
709 case StatusBar_SetPaneStyleRaised
:
710 m_statbarPaneStyle
= wxSB_RAISED
;
717 void MyFrame::ApplyPaneStyle()
719 wxStatusBar
*sb
= GetStatusBar();
723 int fields
= sb
->GetFieldsCount();
724 int *styles
= new int[fields
];
726 for (int i
= 1; i
< fields
; i
++)
727 styles
[i
] = wxSB_NORMAL
;
729 styles
[0] = m_statbarPaneStyle
;
731 sb
->SetStatusStyles(fields
, styles
);
736 void MyFrame::OnUpdateSetStyle(wxUpdateUIEvent
& event
)
738 long currentStyle
= wxSTB_DEFAULT_STYLE
;
740 currentStyle
= GetStatusBar()->GetWindowStyle();
742 switch (event
.GetId())
744 case StatusBar_SetStyleSizeGrip
:
745 event
.Check((currentStyle
& wxSTB_SIZEGRIP
) != 0);
747 case StatusBar_SetStyleShowTips
:
748 event
.Check((currentStyle
& wxSTB_SHOW_TIPS
) != 0);
751 case StatusBar_SetStyleEllipsizeStart
:
752 event
.Check((currentStyle
& wxSTB_ELLIPSIZE_START
) != 0);
754 case StatusBar_SetStyleEllipsizeMiddle
:
755 event
.Check((currentStyle
& wxSTB_ELLIPSIZE_MIDDLE
) != 0);
757 case StatusBar_SetStyleEllipsizeEnd
:
758 event
.Check((currentStyle
& wxSTB_ELLIPSIZE_END
) != 0);
763 void MyFrame::OnSetStyle(wxCommandEvent
& event
)
765 long oldStyle
= wxSTB_DEFAULT_STYLE
;
767 oldStyle
= GetStatusBar()->GetWindowStyle();
769 #define STB_ELLIPSIZE_MASK (wxSTB_ELLIPSIZE_START|wxSTB_ELLIPSIZE_MIDDLE|wxSTB_ELLIPSIZE_END)
771 long newStyle
= oldStyle
;
772 long newStyleBit
= 0;
773 switch (event
.GetId())
775 case StatusBar_SetStyleSizeGrip
:
776 newStyleBit
= wxSTB_SIZEGRIP
;
778 case StatusBar_SetStyleShowTips
:
779 newStyleBit
= wxSTB_SHOW_TIPS
;
782 case StatusBar_SetStyleEllipsizeStart
:
783 newStyleBit
= wxSTB_ELLIPSIZE_START
;
784 newStyle
&= ~STB_ELLIPSIZE_MASK
;
786 case StatusBar_SetStyleEllipsizeMiddle
:
787 newStyleBit
= wxSTB_ELLIPSIZE_MIDDLE
;
788 newStyle
&= ~STB_ELLIPSIZE_MASK
;
790 case StatusBar_SetStyleEllipsizeEnd
:
791 newStyleBit
= wxSTB_ELLIPSIZE_END
;
792 newStyle
&= ~STB_ELLIPSIZE_MASK
;
796 newStyle
= event
.IsChecked() ? (newStyle
| newStyleBit
) :
797 (newStyle
& ~newStyleBit
);
798 if (newStyle
!= oldStyle
)
800 DoCreateStatusBar(m_statbarKind
, newStyle
);
801 SetStatusText("Status bar recreated with a new style");
805 // ----------------------------------------------------------------------------
807 // ----------------------------------------------------------------------------
809 MyAboutDialog::MyAboutDialog(wxWindow
*parent
)
810 : wxDialog(parent
, wxID_ANY
, wxString(wxT("About statbar")),
811 wxDefaultPosition
, wxDefaultSize
,
812 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
814 wxStaticText
*text
= new wxStaticText(this, wxID_ANY
,
815 wxT("wxStatusBar sample\n")
816 wxT("(c) 2000 Vadim Zeitlin"));
818 wxButton
*btn
= new wxButton(this, wxID_OK
, wxT("&Close"));
820 // create the top status bar without the size grip (default style),
821 // otherwise it looks weird
822 wxStatusBar
*statbarTop
= new wxStatusBar(this, wxID_ANY
, 0);
823 statbarTop
->SetFieldsCount(3);
824 statbarTop
->SetStatusText(wxT("This is a top status bar"), 0);
825 statbarTop
->SetStatusText(wxT("in a dialog"), 1);
826 statbarTop
->SetStatusText(wxT("Great, isn't it?"), 2);
828 wxStatusBar
*statbarBottom
= new wxStatusBar(this, wxID_ANY
);
829 statbarBottom
->SetFieldsCount(2);
830 statbarBottom
->SetStatusText(wxT("This is a bottom status bar"), 0);
831 statbarBottom
->SetStatusText(wxT("in a dialog"), 1);
833 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
834 sizerTop
->Add(statbarTop
, 0, wxGROW
);
835 sizerTop
->Add(-1, 10, 1, wxGROW
);
836 sizerTop
->Add(text
, 0, wxCENTRE
| wxRIGHT
| wxLEFT
, 20);
837 sizerTop
->Add(-1, 10, 1, wxGROW
);
838 sizerTop
->Add(btn
, 0, wxCENTRE
| wxRIGHT
| wxLEFT
, 20);
839 sizerTop
->Add(-1, 10, 1, wxGROW
);
840 sizerTop
->Add(statbarBottom
, 0, wxGROW
);
842 SetSizerAndFit(sizerTop
);
845 // ----------------------------------------------------------------------------
847 // ----------------------------------------------------------------------------
850 // 'this' : used in base member initializer list -- so what??
851 #pragma warning(disable: 4355)
854 MyStatusBar::MyStatusBar(wxWindow
*parent
, long style
)
855 : wxStatusBar(parent
, wxID_ANY
, style
, "MyStatusBar")
863 static const int widths
[Field_Max
] = { -1, 150, BITMAP_SIZE_X
, 100 };
865 SetFieldsCount(Field_Max
);
866 SetStatusWidths(Field_Max
, widths
);
869 m_checkbox
= new wxCheckBox(this, StatusBar_Checkbox
, wxT("&Toggle clock"));
870 m_checkbox
->SetValue(true);
873 #ifdef USE_STATIC_BITMAP
874 m_statbmp
= new wxStaticBitmap(this, wxID_ANY
, wxIcon(green_xpm
));
876 m_statbmp
= new wxBitmapButton(this, wxID_ANY
, CreateBitmapForButton(),
877 wxDefaultPosition
, wxDefaultSize
,
885 SetMinHeight(wxMax(m_statbmp
->GetBestSize().GetHeight(),
886 m_checkbox
->GetBestSize().GetHeight()));
892 #pragma warning(default: 4355)
895 MyStatusBar::~MyStatusBar()
898 if ( m_timer
.IsRunning() )
905 #define BMP_BUTTON_SIZE_X 10
906 #define BMP_BUTTON_SIZE_Y 10
908 wxBitmap
MyStatusBar::CreateBitmapForButton(bool on
)
910 wxBitmap
bitmap(BMP_BUTTON_SIZE_X
+1, BMP_BUTTON_SIZE_Y
+1);
912 dc
.SelectObject(bitmap
);
913 dc
.SetBrush(on
? *wxGREEN_BRUSH
: *wxRED_BRUSH
);
914 dc
.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT
);
916 dc
.DrawEllipse(0, 0, BMP_BUTTON_SIZE_X
, BMP_BUTTON_SIZE_Y
);
917 dc
.SelectObject(wxNullBitmap
);
922 void MyStatusBar::OnSize(wxSizeEvent
& event
)
929 // TEMPORARY HACK: TODO find a more general solution
930 #ifdef wxStatusBarGeneric
931 wxStatusBar::OnSize(event
);
935 if (!GetFieldRect(Field_Checkbox
, rect
))
942 m_checkbox
->SetSize(rect
.x
+ 2, rect
.y
+ 2, rect
.width
- 4, rect
.height
- 4);
945 GetFieldRect(Field_Bitmap
, rect
);
946 wxSize size
= m_statbmp
->GetSize();
948 m_statbmp
->Move(rect
.x
+ (rect
.width
- size
.x
) / 2,
949 rect
.y
+ (rect
.height
- size
.y
) / 2);
954 void MyStatusBar::OnButton(wxCommandEvent
& WXUNUSED(event
))
957 m_checkbox
->SetValue(!m_checkbox
->GetValue());
963 void MyStatusBar::OnToggleClock(wxCommandEvent
& WXUNUSED(event
))
968 void MyStatusBar::DoToggle()
971 if ( m_checkbox
->GetValue() )
977 #ifdef USE_STATIC_BITMAP
978 m_statbmp
->SetIcon(wxIcon(green_xpm
));
980 m_statbmp
->SetBitmapLabel(CreateBitmapForButton(false));
981 m_statbmp
->Refresh();
986 else // don't show clock
992 #ifdef USE_STATIC_BITMAP
993 m_statbmp
->SetIcon(wxIcon(red_xpm
));
995 m_statbmp
->SetBitmapLabel(CreateBitmapForButton(true));
996 m_statbmp
->Refresh();
999 SetStatusText(wxEmptyString
, Field_Clock
);
1004 void MyStatusBar::UpdateClock()
1006 SetStatusText(wxDateTime::Now().FormatTime(), Field_Clock
);