X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c2919ab326e60322b63ae9b5d50e83bb5156efce..05e0b047d879cdbfade7f2ab346c0acdf3e29f96:/samples/statbar/statbar.cpp?ds=sidebyside diff --git a/samples/statbar/statbar.cpp b/samples/statbar/statbar.cpp index 7761a5e1d5..91cf5c9c90 100644 --- a/samples/statbar/statbar.cpp +++ b/samples/statbar/statbar.cpp @@ -96,7 +96,9 @@ public: void UpdateClock(); // event handlers +#if wxUSE_TIMER void OnTimer(wxTimerEvent& WXUNUSED(event)) { UpdateClock(); } +#endif void OnSize(wxSizeEvent& event); void OnToggleClock(wxCommandEvent& event); void OnButton(wxCommandEvent& event); @@ -116,9 +118,13 @@ private: Field_Max }; +#if wxUSE_TIMER wxTimer m_timer; +#endif +#if wxUSE_CHECKBOX wxCheckBox *m_checkbox; +#endif #ifdef USE_STATIC_BITMAP wxStaticBitmap *m_statbmp; #else @@ -234,9 +240,13 @@ END_EVENT_TABLE() BEGIN_EVENT_TABLE(MyStatusBar, wxStatusBar) EVT_SIZE(MyStatusBar::OnSize) +#if wxUSE_CHECKBOX EVT_CHECKBOX(StatusBar_Checkbox, MyStatusBar::OnToggleClock) +#endif EVT_BUTTON(wxID_ANY, MyStatusBar::OnButton) +#if wxUSE_TIMER EVT_TIMER(wxID_ANY, MyStatusBar::OnTimer) +#endif END_EVENT_TABLE() // Create a new application object: this macro will allow wxWidgets to create @@ -257,6 +267,9 @@ IMPLEMENT_APP(MyApp) // `Main program' equivalent: the program execution "starts" here bool MyApp::OnInit() { + if ( !wxApp::OnInit() ) + return false; + // create the main application window MyFrame *frame = new MyFrame(_T("wxStatusBar sample"), wxPoint(50, 50), wxSize(450, 340)); @@ -442,7 +455,7 @@ void MyFrame::OnSetStatusFields(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnUpdateStatusBarToggle(wxUpdateUIEvent& event) { - event.Check(GetStatusBar() != 0); + event.Check(GetStatusBar() != NULL); } void MyFrame::OnStatusBarToggle(wxCommandEvent& WXUNUSED(event)) @@ -451,17 +464,12 @@ void MyFrame::OnStatusBarToggle(wxCommandEvent& WXUNUSED(event)) if ( statbarOld ) { statbarOld->Hide(); - SetStatusBar(0); + SetStatusBar(NULL); } else { DoCreateStatusBar(m_statbarKind); } -#ifdef __WXMSW__ - // The following is a kludge suggested by Vadim Zeitlin (one of the wxWidgets - // authors) while we look for a proper fix.. -// SendSizeEvent(); -#endif } void MyFrame::OnRecreateStatusBar(wxCommandEvent& WXUNUSED(event)) @@ -497,19 +505,19 @@ void MyFrame::OnUpdateSetStyleRaised(wxUpdateUIEvent &event) event.Check(m_statbarStyle == wxSB_RAISED); } -void MyFrame::OnSetStyleNormal(wxCommandEvent &event) +void MyFrame::OnSetStyleNormal(wxCommandEvent & WXUNUSED(event)) { m_statbarStyle = wxSB_NORMAL; ApplyStyle(); } -void MyFrame::OnSetStyleFlat(wxCommandEvent &event) +void MyFrame::OnSetStyleFlat(wxCommandEvent & WXUNUSED(event)) { m_statbarStyle = wxSB_FLAT; ApplyStyle(); } -void MyFrame::OnSetStyleRaised(wxCommandEvent &event) +void MyFrame::OnSetStyleRaised(wxCommandEvent & WXUNUSED(event)) { m_statbarStyle = wxSB_RAISED; ApplyStyle(); @@ -568,10 +576,7 @@ MyAboutDialog::MyAboutDialog(wxWindow *parent) sizerTop->Add(-1, 10, 1, wxGROW); sizerTop->Add(statbarBottom, 0, wxGROW); - SetSizer(sizerTop); - - sizerTop->Fit(this); - sizerTop->SetSizeHints(this); + SetSizerAndFit(sizerTop); } // ---------------------------------------------------------------------------- @@ -584,15 +589,23 @@ MyAboutDialog::MyAboutDialog(wxWindow *parent) #endif MyStatusBar::MyStatusBar(wxWindow *parent) - : wxStatusBar(parent, wxID_ANY), m_timer(this), m_checkbox(NULL) + : wxStatusBar(parent, wxID_ANY) +#if wxUSE_TIMER + , m_timer(this) +#endif +#if wxUSE_CHECKBOX + , m_checkbox(NULL) +#endif { static const int widths[Field_Max] = { -1, 150, BITMAP_SIZE_X, 100 }; SetFieldsCount(Field_Max); SetStatusWidths(Field_Max, widths); +#if wxUSE_CHECKBOX m_checkbox = new wxCheckBox(this, StatusBar_Checkbox, _T("&Toggle clock")); m_checkbox->SetValue(true); +#endif #ifdef USE_STATIC_BITMAP m_statbmp = new wxStaticBitmap(this, wxID_ANY, wxIcon(green_xpm)); @@ -602,7 +615,9 @@ MyStatusBar::MyStatusBar(wxWindow *parent) wxBU_EXACTFIT); #endif +#if wxUSE_TIMER m_timer.Start(1000); +#endif SetMinHeight(BITMAP_SIZE_Y); @@ -615,10 +630,12 @@ MyStatusBar::MyStatusBar(wxWindow *parent) MyStatusBar::~MyStatusBar() { +#if wxUSE_TIMER if ( m_timer.IsRunning() ) { m_timer.Stop(); } +#endif } wxBitmap MyStatusBar::CreateBitmapForButton(bool on) @@ -640,13 +657,17 @@ wxBitmap MyStatusBar::CreateBitmapForButton(bool on) void MyStatusBar::OnSize(wxSizeEvent& event) { +#if wxUSE_CHECKBOX if ( !m_checkbox ) return; +#endif wxRect rect; GetFieldRect(Field_Checkbox, rect); +#if wxUSE_CHECKBOX m_checkbox->SetSize(rect.x + 2, rect.y + 2, rect.width - 4, rect.height - 4); +#endif GetFieldRect(Field_Bitmap, rect); wxSize size = m_statbmp->GetSize(); @@ -659,7 +680,9 @@ void MyStatusBar::OnSize(wxSizeEvent& event) void MyStatusBar::OnButton(wxCommandEvent& WXUNUSED(event)) { +#if wxUSE_CHECKBOX m_checkbox->SetValue(!m_checkbox->GetValue()); +#endif DoToggle(); } @@ -671,9 +694,12 @@ void MyStatusBar::OnToggleClock(wxCommandEvent& WXUNUSED(event)) void MyStatusBar::DoToggle() { +#if wxUSE_CHECKBOX if ( m_checkbox->GetValue() ) { +#if wxUSE_TIMER m_timer.Start(1000); +#endif #ifdef USE_STATIC_BITMAP m_statbmp->SetIcon(wxIcon(green_xpm)); @@ -686,7 +712,9 @@ void MyStatusBar::DoToggle() } else // don't show clock { +#if wxUSE_TIMER m_timer.Stop(); +#endif #ifdef USE_STATIC_BITMAP m_statbmp->SetIcon(wxIcon(red_xpm)); @@ -697,6 +725,7 @@ void MyStatusBar::DoToggle() SetStatusText(wxEmptyString, Field_Clock); } +#endif } void MyStatusBar::UpdateClock()