]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/statbar/statbar.cpp
remove unneeded wxCHECK_MSG: GetNextMessage() can get the msg even if the event loop...
[wxWidgets.git] / samples / statbar / statbar.cpp
index ff9113fb1983b557b6eb84739b39169b4bdb2786..042bfc645a43b892790923d43b3b8ad32c1e1d55 100644 (file)
@@ -48,6 +48,7 @@
 
 #include "wx/datetime.h"
 #include "wx/numdlg.h"
+#include "wx/fontdlg.h"
 
 #ifndef __WXMSW__
     #include "../sample.xpm"
@@ -160,6 +161,7 @@ class MyFrame : public wxMDIParentFrame
     void OnResetFieldsWidth(wxCommandEvent& event);
     void OnSetStatusFields(wxCommandEvent& event);
     void OnSetStatusTexts(wxCommandEvent& event);
+    void OnSetStatusFont(wxCommandEvent& event);
     void OnRecreateStatusBar(wxCommandEvent& event);
     void OnSetStyleNormal(wxCommandEvent& event);
     void OnSetStyleFlat(wxCommandEvent& event);
@@ -174,9 +176,7 @@ private:
     } m_statbarKind;
 
 
-    void OnUpdateSetStatusTexts(wxUpdateUIEvent& event);
-    void OnUpdateResetFieldsWidth(wxUpdateUIEvent& event);
-    void OnUpdateSetStatusFields(wxUpdateUIEvent& event);
+    void OnUpdateForDefaultStatusbar(wxUpdateUIEvent& event);
     void OnUpdateStatusBarToggle(wxUpdateUIEvent& event);
     void OnUpdateSetStyleNormal(wxUpdateUIEvent& event);
     void OnUpdateSetStyleFlat(wxUpdateUIEvent& event);
@@ -210,9 +210,12 @@ enum
 {
     // menu items
     StatusBar_Quit = 1,
+
     StatusBar_SetFields,
     StatusBar_SetTexts,
+    StatusBar_SetFont,
     StatusBar_ResetFieldsWidth,
+
     StatusBar_Recreate,
     StatusBar_About,
     StatusBar_Toggle,
@@ -241,6 +244,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
     EVT_MENU(StatusBar_Quit,  MyFrame::OnQuit)
     EVT_MENU(StatusBar_SetFields, MyFrame::OnSetStatusFields)
     EVT_MENU(StatusBar_SetTexts, MyFrame::OnSetStatusTexts)
+    EVT_MENU(StatusBar_SetFont, MyFrame::OnSetStatusFont)
     EVT_MENU(StatusBar_ResetFieldsWidth, MyFrame::OnResetFieldsWidth)
     EVT_MENU(StatusBar_Recreate, MyFrame::OnRecreateStatusBar)
     EVT_MENU(StatusBar_About, MyFrame::OnAbout)
@@ -249,10 +253,9 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
     EVT_MENU(StatusBar_SetStyleFlat, MyFrame::OnSetStyleFlat)
     EVT_MENU(StatusBar_SetStyleRaised, MyFrame::OnSetStyleRaised)
 
-    EVT_UPDATE_UI(StatusBar_ResetFieldsWidth, MyFrame::OnUpdateResetFieldsWidth)
+    EVT_UPDATE_UI_RANGE(StatusBar_SetFields, StatusBar_ResetFieldsWidth,
+                        MyFrame::OnUpdateForDefaultStatusbar)
     EVT_UPDATE_UI(StatusBar_Toggle, MyFrame::OnUpdateStatusBarToggle)
-    EVT_UPDATE_UI(StatusBar_SetTexts, MyFrame::OnUpdateSetStatusTexts)
-    EVT_UPDATE_UI(StatusBar_SetFields, MyFrame::OnUpdateSetStatusFields)
     EVT_UPDATE_UI(StatusBar_SetStyleNormal, MyFrame::OnUpdateSetStyleNormal)
     EVT_UPDATE_UI(StatusBar_SetStyleFlat, MyFrame::OnUpdateSetStyleFlat)
     EVT_UPDATE_UI(StatusBar_SetStyleRaised, MyFrame::OnUpdateSetStyleRaised)
@@ -338,6 +341,8 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
                         _T("Set the number of status bar fields"));
     statbarMenu->Append(StatusBar_SetTexts, _T("&Set field text\tCtrl-T"),
                         _T("Set the text to display for each status bar field"));
+    statbarMenu->Append(StatusBar_SetFont, _T("&Set field font\tCtrl-F"),
+                        _T("Set the font to use for rendering status bar fields"));
 
     wxMenu *statbarStyleMenu = new wxMenu;
     statbarStyleMenu->Append(StatusBar_SetStyleNormal, _T("&Normal"), _T("Sets the style of the first field to normal (sunken) look"), true);
@@ -421,10 +426,9 @@ void MyFrame::DoCreateStatusBar(MyFrame::StatBarKind kind)
 // main frame - event handlers
 // ----------------------------------------------------------------------------
 
-void MyFrame::OnUpdateSetStatusTexts(wxUpdateUIEvent& event)
+void MyFrame::OnUpdateForDefaultStatusbar(wxUpdateUIEvent& event)
 {
-    // only allow the settings of the text of status fields for the default
-    // status bar
+    // only allow this feature for the default status bar
     wxStatusBar *sb = GetStatusBar();
     event.Enable(sb == m_statbarDefault);
 }
@@ -444,12 +448,16 @@ void MyFrame::OnSetStatusTexts(wxCommandEvent& WXUNUSED(event))
     }
 }
 
-void MyFrame::OnUpdateSetStatusFields(wxUpdateUIEvent& event)
+void MyFrame::OnSetStatusFont(wxCommandEvent& WXUNUSED(event))
 {
-    // only allow the settings of the number of status fields for the default
-    // status bar
     wxStatusBar *sb = GetStatusBar();
-    event.Enable(sb == m_statbarDefault);
+
+    wxFont fnt = wxGetFontFromUser(this, sb->GetFont(), "Choose statusbar font");
+    if (fnt.IsOk())
+    {
+        sb->SetFont(fnt);
+        sb->SetSize(sb->GetBestSize());
+    }
 }
 
 void MyFrame::OnSetStatusFields(wxCommandEvent& WXUNUSED(event))
@@ -510,14 +518,6 @@ void MyFrame::OnSetStatusFields(wxCommandEvent& WXUNUSED(event))
     }
 }
 
-void MyFrame::OnUpdateResetFieldsWidth(wxUpdateUIEvent& event)
-{
-    // only allow the settings of the number of status fields for the default
-    // status bar
-    wxStatusBar *sb = GetStatusBar();
-    event.Enable(sb == m_statbarDefault);
-}
-
 void MyFrame::OnResetFieldsWidth(wxCommandEvent& WXUNUSED(event))
 {
     wxStatusBar *pStat = GetStatusBar();
@@ -740,8 +740,17 @@ void MyStatusBar::OnSize(wxSizeEvent& event)
         return;
 #endif
 
+    // TEMPORARY HACK: TODO find a more general solution
+#ifdef wxStatusBarGeneric
+    wxStatusBar::OnSize(event);
+#endif
+
     wxRect rect;
-    GetFieldRect(Field_Checkbox, rect);
+    if (!GetFieldRect(Field_Checkbox, rect))
+    {
+        event.Skip();
+        return;
+    }
 
 #if wxUSE_CHECKBOX
     m_checkbox->SetSize(rect.x + 2, rect.y + 2, rect.width - 4, rect.height - 4);