]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/statbar/statbar.cpp
Make it possible to use svn-find-native-eols script without svn checkout.
[wxWidgets.git] / samples / statbar / statbar.cpp
index d01af49259db7ef933b16b92496f84ae7e78a812..d81ddd46060c53c616d94892acdd6d3f5c0d31e3 100644 (file)
@@ -50,7 +50,7 @@
 #include "wx/numdlg.h"
 #include "wx/fontdlg.h"
 
 #include "wx/numdlg.h"
 #include "wx/fontdlg.h"
 
-#ifndef __WXMSW__
+#ifndef wxHAS_IMAGES_IN_RESOURCES
     #include "../sample.xpm"
 #endif
 
     #include "../sample.xpm"
 #endif
 
@@ -100,6 +100,7 @@ public:
 #endif
     void OnSize(wxSizeEvent& event);
     void OnToggleClock(wxCommandEvent& event);
 #endif
     void OnSize(wxSizeEvent& event);
     void OnToggleClock(wxCommandEvent& event);
+    void OnIdle(wxIdleEvent& event);
 
 private:
     // toggle the state of the status bar controls
 
 private:
     // toggle the state of the status bar controls
@@ -110,7 +111,9 @@ private:
         Field_Text,
         Field_Checkbox,
         Field_Bitmap,
         Field_Text,
         Field_Checkbox,
         Field_Bitmap,
+        Field_NumLockIndicator,
         Field_Clock,
         Field_Clock,
+        Field_CapsLockIndicator,
         Field_Max
     };
 
         Field_Max
     };
 
@@ -215,6 +218,7 @@ enum
     StatusBar_SetPaneStyleNormal,
     StatusBar_SetPaneStyleFlat,
     StatusBar_SetPaneStyleRaised,
     StatusBar_SetPaneStyleNormal,
     StatusBar_SetPaneStyleFlat,
     StatusBar_SetPaneStyleRaised,
+    StatusBar_SetPaneStyleSunken,
 
     StatusBar_SetStyleSizeGrip,
     StatusBar_SetStyleEllipsizeStart,
 
     StatusBar_SetStyleSizeGrip,
     StatusBar_SetStyleEllipsizeStart,
@@ -253,6 +257,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
     EVT_MENU(StatusBar_SetPaneStyleNormal, MyFrame::OnSetPaneStyle)
     EVT_MENU(StatusBar_SetPaneStyleFlat, MyFrame::OnSetPaneStyle)
     EVT_MENU(StatusBar_SetPaneStyleRaised, MyFrame::OnSetPaneStyle)
     EVT_MENU(StatusBar_SetPaneStyleNormal, MyFrame::OnSetPaneStyle)
     EVT_MENU(StatusBar_SetPaneStyleFlat, MyFrame::OnSetPaneStyle)
     EVT_MENU(StatusBar_SetPaneStyleRaised, MyFrame::OnSetPaneStyle)
+    EVT_MENU(StatusBar_SetPaneStyleSunken, MyFrame::OnSetPaneStyle)
 
     EVT_MENU(StatusBar_SetStyleSizeGrip, MyFrame::OnSetStyle)
     EVT_MENU(StatusBar_SetStyleEllipsizeStart, MyFrame::OnSetStyle)
 
     EVT_MENU(StatusBar_SetStyleSizeGrip, MyFrame::OnSetStyle)
     EVT_MENU(StatusBar_SetStyleEllipsizeStart, MyFrame::OnSetStyle)
@@ -264,7 +269,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
                         MyFrame::OnUpdateForDefaultStatusbar)
     EVT_UPDATE_UI(StatusBar_Toggle, MyFrame::OnUpdateStatusBarToggle)
     EVT_UPDATE_UI_RANGE(StatusBar_SetPaneStyleNormal,
                         MyFrame::OnUpdateForDefaultStatusbar)
     EVT_UPDATE_UI(StatusBar_Toggle, MyFrame::OnUpdateStatusBarToggle)
     EVT_UPDATE_UI_RANGE(StatusBar_SetPaneStyleNormal,
-                        StatusBar_SetPaneStyleRaised,
+                        StatusBar_SetPaneStyleSunken,
                         MyFrame::OnUpdateSetPaneStyle)
     EVT_UPDATE_UI_RANGE(StatusBar_SetStyleSizeGrip, StatusBar_SetStyleShowTips,
                         MyFrame::OnUpdateSetStyle)
                         MyFrame::OnUpdateSetPaneStyle)
     EVT_UPDATE_UI_RANGE(StatusBar_SetStyleSizeGrip, StatusBar_SetStyleShowTips,
                         MyFrame::OnUpdateSetStyle)
@@ -278,6 +283,7 @@ BEGIN_EVENT_TABLE(MyStatusBar, wxStatusBar)
 #if wxUSE_TIMER
     EVT_TIMER(wxID_ANY, MyStatusBar::OnTimer)
 #endif
 #if wxUSE_TIMER
     EVT_TIMER(wxID_ANY, MyStatusBar::OnTimer)
 #endif
+    EVT_IDLE(MyStatusBar::OnIdle)
 END_EVENT_TABLE()
 
 // Create a new application object: this macro will allow wxWidgets to create
 END_EVENT_TABLE()
 
 // Create a new application object: this macro will allow wxWidgets to create
@@ -392,6 +398,12 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
             wxT("&Raised"),
             wxT("Sets the style of the first field to raised look")
         );
             wxT("&Raised"),
             wxT("Sets the style of the first field to raised look")
         );
+    statbarPaneStyleMenu->AppendCheckItem
+        (
+            StatusBar_SetPaneStyleSunken,
+            wxT("&Sunken"),
+            wxT("Sets the style of the first field to sunken look")
+        );
     statbarMenu->Append(StatusBar_SetPaneStyle, wxT("Field style"),
                         statbarPaneStyleMenu);
 
     statbarMenu->Append(StatusBar_SetPaneStyle, wxT("Field style"),
                         statbarPaneStyleMenu);
 
@@ -408,7 +420,7 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
                         wxT("Toggle status bar format"));
 
     wxMenu *helpMenu = new wxMenu;
                         wxT("Toggle status bar format"));
 
     wxMenu *helpMenu = new wxMenu;
-    helpMenu->Append(StatusBar_About, wxT("&About...\tCtrl-A"),
+    helpMenu->Append(StatusBar_About, wxT("&About\tCtrl-A"),
                      wxT("Show about dialog"));
 
     // now append the freshly created menu to the menu bar...
                      wxT("Show about dialog"));
 
     // now append the freshly created menu to the menu bar...
@@ -718,6 +730,9 @@ void MyFrame::OnUpdateSetPaneStyle(wxUpdateUIEvent& event)
         case StatusBar_SetPaneStyleRaised:
             event.Check(m_statbarPaneStyle == wxSB_RAISED);
             break;
         case StatusBar_SetPaneStyleRaised:
             event.Check(m_statbarPaneStyle == wxSB_RAISED);
             break;
+        case StatusBar_SetPaneStyleSunken:
+            event.Check(m_statbarPaneStyle == wxSB_SUNKEN);
+            break;
     }
 }
 
     }
 }
 
@@ -734,6 +749,9 @@ void MyFrame::OnSetPaneStyle(wxCommandEvent& event)
         case StatusBar_SetPaneStyleRaised:
             m_statbarPaneStyle = wxSB_RAISED;
             break;
         case StatusBar_SetPaneStyleRaised:
             m_statbarPaneStyle = wxSB_RAISED;
             break;
+        case StatusBar_SetPaneStyleSunken:
+            m_statbarPaneStyle = wxSB_SUNKEN;
+            break;
     }
 
     ApplyPaneStyle();
     }
 
     ApplyPaneStyle();
@@ -877,6 +895,9 @@ MyAboutDialog::MyAboutDialog(wxWindow *parent)
     #pragma warning(disable: 4355)
 #endif
 
     #pragma warning(disable: 4355)
 #endif
 
+static const char *numlockIndicators[] = { "OFF", "NUM" };
+static const char *capslockIndicators[] = { "", "CAPS" };
+
 MyStatusBar::MyStatusBar(wxWindow *parent, long style)
         : wxStatusBar(parent, wxID_ANY, style, "MyStatusBar")
 #if wxUSE_TIMER
 MyStatusBar::MyStatusBar(wxWindow *parent, long style)
         : wxStatusBar(parent, wxID_ANY, style, "MyStatusBar")
 #if wxUSE_TIMER
@@ -886,7 +907,18 @@ MyStatusBar::MyStatusBar(wxWindow *parent, long style)
             , m_checkbox(NULL)
 #endif
 {
             , m_checkbox(NULL)
 #endif
 {
-    static const int widths[Field_Max] = { -1, 150, BITMAP_SIZE_X, 100 };
+    // compute the size needed for num lock indicator pane
+    wxClientDC dc(this);
+    wxSize sizeNumLock = dc.GetTextExtent(numlockIndicators[0]);
+    sizeNumLock.IncTo(dc.GetTextExtent(numlockIndicators[1]));
+
+    int widths[Field_Max];
+    widths[Field_Text] = -1; // growable
+    widths[Field_Checkbox] = 150;
+    widths[Field_Bitmap] = BITMAP_SIZE_X;
+    widths[Field_NumLockIndicator] = sizeNumLock.x;
+    widths[Field_Clock] = 100;
+    widths[Field_CapsLockIndicator] = dc.GetTextExtent(capslockIndicators[1]).x;
 
     SetFieldsCount(Field_Max);
     SetStatusWidths(Field_Max, widths);
 
     SetFieldsCount(Field_Max);
     SetStatusWidths(Field_Max, widths);
@@ -929,11 +961,6 @@ void MyStatusBar::OnSize(wxSizeEvent& event)
         return;
 #endif
 
         return;
 #endif
 
-    // TEMPORARY HACK: TODO find a more general solution
-#ifdef wxStatusBarGeneric
-    wxStatusBar::OnSize(event);
-#endif
-
     wxRect rect;
     if (!GetFieldRect(Field_Checkbox, rect))
     {
     wxRect rect;
     if (!GetFieldRect(Field_Checkbox, rect))
     {
@@ -961,6 +988,16 @@ void MyStatusBar::OnToggleClock(wxCommandEvent& WXUNUSED(event))
     DoToggle();
 }
 
     DoToggle();
 }
 
+void MyStatusBar::OnIdle(wxIdleEvent& event)
+{
+    SetStatusText(numlockIndicators[wxGetKeyState(WXK_NUMLOCK)],
+                  Field_NumLockIndicator);
+    SetStatusText(capslockIndicators[wxGetKeyState(WXK_CAPITAL)],
+                  Field_CapsLockIndicator);
+
+    event.Skip();
+}
+
 void MyStatusBar::DoToggle()
 {
 #if wxUSE_CHECKBOX
 void MyStatusBar::DoToggle()
 {
 #if wxUSE_CHECKBOX