]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/statbar/statbar.cpp
correct size of extra controls in pixels to dialogs units correctly (see #9679)
[wxWidgets.git] / samples / statbar / statbar.cpp
index 86d8f23d24c7e0bf0d1317e138e86434378e39ce..1c5c0a008be3e80b07fb1c1ad13de62640fe3a50 100644 (file)
 
 #include "wx/datetime.h"
 #include "wx/numdlg.h"
+#include "wx/fontdlg.h"
+
+#ifndef __WXMSW__
+    #include "../sample.xpm"
+#endif
 
 
 // define this for the platforms which don't support wxBitmapButton (such as
@@ -155,6 +160,8 @@ 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);
@@ -168,8 +175,8 @@ private:
         StatBar_Max
     } m_statbarKind;
 
-    void OnUpdateResetFieldsWidth(wxUpdateUIEvent& event);
-    void OnUpdateSetStatusFields(wxUpdateUIEvent& event);
+
+    void OnUpdateForDefaultStatusbar(wxUpdateUIEvent& event);
     void OnUpdateStatusBarToggle(wxUpdateUIEvent& event);
     void OnUpdateSetStyleNormal(wxUpdateUIEvent& event);
     void OnUpdateSetStyleFlat(wxUpdateUIEvent& event);
@@ -203,8 +210,12 @@ enum
 {
     // menu items
     StatusBar_Quit = 1,
+
     StatusBar_SetFields,
+    StatusBar_SetTexts,
+    StatusBar_SetFont,
     StatusBar_ResetFieldsWidth,
+
     StatusBar_Recreate,
     StatusBar_About,
     StatusBar_Toggle,
@@ -232,6 +243,8 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
 #endif
     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)
@@ -240,9 +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_SetFields, MyFrame::OnUpdateSetStatusFields)
     EVT_UPDATE_UI(StatusBar_SetStyleNormal, MyFrame::OnUpdateSetStyleNormal)
     EVT_UPDATE_UI(StatusBar_SetStyleFlat, MyFrame::OnUpdateSetStyleFlat)
     EVT_UPDATE_UI(StatusBar_SetStyleRaised, MyFrame::OnUpdateSetStyleRaised)
@@ -306,6 +319,8 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
     : wxFrame((wxWindow *)NULL, wxID_ANY, title, pos, size)
 #endif
 {
+    SetIcon(wxICON(sample));
+
     m_statbarDefault = NULL;
     m_statbarCustom = NULL;
 
@@ -324,11 +339,16 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
     wxMenu *statbarMenu = new wxMenu;
     statbarMenu->Append(StatusBar_SetFields, _T("&Set field count\tCtrl-C"),
                         _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);
     statbarStyleMenu->Append(StatusBar_SetStyleFlat, _T("&Flat"), _T("Sets the style of the first field to flat look"), true);
     statbarStyleMenu->Append(StatusBar_SetStyleRaised, _T("&Raised"), _T("Sets the style of the first field to raised look"), true);
+
     statbarMenu->Append(StatusBar_SetStyle, _T("Field style"), statbarStyleMenu);
 
     statbarMenu->Append(StatusBar_ResetFieldsWidth, _T("Reset field widths"),
@@ -401,15 +421,45 @@ void MyFrame::DoCreateStatusBar(MyFrame::StatBarKind kind)
     m_statbarKind = kind;
 }
 
-void MyFrame::OnUpdateSetStatusFields(wxUpdateUIEvent& event)
+
+// ----------------------------------------------------------------------------
+// main frame - event handlers
+// ----------------------------------------------------------------------------
+
+void MyFrame::OnUpdateForDefaultStatusbar(wxUpdateUIEvent& event)
 {
-    // only allow the settings of the number 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);
 }
 
-// event handlers
+void MyFrame::OnSetStatusTexts(wxCommandEvent& WXUNUSED(event))
+{
+    wxStatusBar *sb = GetStatusBar();
+
+    wxString txt;
+    for (int i=0; i<sb->GetFieldsCount(); i++)
+    {
+        txt =
+            wxGetTextFromUser(wxString::Format("Enter the text for the %d-th field:", i+1),
+                              "Input field text", "A dummy test string", this);
+
+        sb->SetStatusText(txt, i);
+    }
+}
+
+void MyFrame::OnSetStatusFont(wxCommandEvent& WXUNUSED(event))
+{
+    wxStatusBar *sb = GetStatusBar();
+
+    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))
 {
     wxStatusBar *sb = GetStatusBar();
@@ -468,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();
@@ -699,7 +741,11 @@ void MyStatusBar::OnSize(wxSizeEvent& 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);