]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/statbar/statbar.cpp
Allow the release tag to be specified on the rpmbuild command line
[wxWidgets.git] / samples / statbar / statbar.cpp
index 2b9924d343edfc62d913e9bcb294c138d33db803..e98da938a3ce690dcf48ed6999bdf3397ab06a83 100644 (file)
@@ -31,6 +31,7 @@
 // for all others, include the necessary headers
 #ifndef WX_PRECOMP
     #include "wx/app.h"
+    #include "wx/log.h"
     #include "wx/frame.h"
     #include "wx/statusbr.h"
     #include "wx/timer.h"
@@ -46,6 +47,7 @@
 #endif
 
 #include "wx/datetime.h"
+#include "wx/numdlg.h"
 
 // define this for the platforms which don't support wxBitmapButton (such as
 // Motif), else a wxBitmapButton will be used
@@ -94,7 +96,7 @@ public:
     void UpdateClock();
 
     // event handlers
-    void OnTimer(wxTimerEvent& event) { UpdateClock(); }
+    void OnTimer(wxTimerEvent& WXUNUSED(event)) { UpdateClock(); }
     void OnSize(wxSizeEvent& event);
     void OnToggleClock(wxCommandEvent& event);
     void OnButton(wxCommandEvent& event);
@@ -103,7 +105,7 @@ private:
     // toggle the state of the status bar controls
     void DoToggle();
 
-    wxBitmap CreateBitmapForButton(bool on = FALSE);
+    wxBitmap CreateBitmapForButton(bool on = false);
 
     enum
     {
@@ -160,7 +162,7 @@ private:
     wxStatusBar *m_statbarDefault;
     MyStatusBar *m_statbarCustom;
 
-    // any class wishing to process wxWindows events must use this macro
+    // any class wishing to process wxWidgets events must use this macro
     DECLARE_EVENT_TABLE()
 };
 
@@ -191,10 +193,10 @@ static const int BITMAP_SIZE_X = 32;
 static const int BITMAP_SIZE_Y = 15;
 
 // ----------------------------------------------------------------------------
-// event tables and other macros for wxWindows
+// event tables and other macros for wxWidgets
 // ----------------------------------------------------------------------------
 
-// the event tables connect the wxWindows events with the functions (event
+// the event tables connect the wxWidgets events with the functions (event
 // handlers) which process them. It can be also done at run-time, but for the
 // simple menu events like this the static method is much simpler.
 #ifdef USE_MDI_PARENT_FRAME
@@ -214,11 +216,11 @@ END_EVENT_TABLE()
 BEGIN_EVENT_TABLE(MyStatusBar, wxStatusBar)
     EVT_SIZE(MyStatusBar::OnSize)
     EVT_CHECKBOX(StatusBar_Checkbox, MyStatusBar::OnToggleClock)
-    EVT_BUTTON(-1, MyStatusBar::OnButton)
-    EVT_TIMER(-1, MyStatusBar::OnTimer)
+    EVT_BUTTON(wxID_ANY, MyStatusBar::OnButton)
+    EVT_TIMER(wxID_ANY, MyStatusBar::OnTimer)
 END_EVENT_TABLE()
 
-// Create a new application object: this macro will allow wxWindows to create
+// Create a new application object: this macro will allow wxWidgets to create
 // the application object during program execution (it's better than using a
 // static object for many reasons) and also declares the accessor function
 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
@@ -237,17 +239,17 @@ IMPLEMENT_APP(MyApp)
 bool MyApp::OnInit()
 {
     // create the main application window
-    MyFrame *frame = new MyFrame("wxStatusBar sample",
+    MyFrame *frame = new MyFrame(_T("wxStatusBar sample"),
                                  wxPoint(50, 50), wxSize(450, 340));
 
     // and show it (the frames, unlike simple controls, are not shown when
     // created initially)
-    frame->Show(TRUE);
+    frame->Show(true);
 
     // success: wxApp::OnRun() will be called which will enter the main message
-    // loop and the application will run. If we returned FALSE here, the
+    // loop and the application will run. If we returned 'false' here, the
     // application would exit immediately.
-    return TRUE;
+    return true;
 }
 
 // ----------------------------------------------------------------------------
@@ -257,9 +259,9 @@ bool MyApp::OnInit()
 // frame constructor
 MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
 #ifdef USE_MDI_PARENT_FRAME
-       : wxMDIParentFrame((wxWindow *)NULL, -1, title, pos, size)
+       : wxMDIParentFrame((wxWindow *)NULL, wxID_ANY, title, pos, size)
 #else
-       : wxFrame((wxWindow *)NULL, -1, title, pos, size)
+       : wxFrame((wxWindow *)NULL, wxID_ANY, title, pos, size)
 #endif
 {
     m_statbarDefault = NULL;
@@ -273,24 +275,24 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
 
     // create a menu bar
     wxMenu *menuFile = new wxMenu;
-    menuFile->Append(StatusBar_Quit, "E&xit\tAlt-X", "Quit this program");
+    menuFile->Append(StatusBar_Quit, _T("E&xit\tAlt-X"), _T("Quit this program"));
 
     wxMenu *statbarMenu = new wxMenu;
-    statbarMenu->Append(StatusBar_SetFields, "&Set field count\tCtrl-C",
-                        "Set the number of status bar fields");
-    statbarMenu->Append(StatusBar_Toggle, "&Toggle Status Bar",
-                        "Toggle the status bar display", true);
-    statbarMenu->Append(StatusBar_Recreate, "&Recreate\tCtrl-R",
-                        "Toggle status bar format");
+    statbarMenu->Append(StatusBar_SetFields, _T("&Set field count\tCtrl-C"),
+                        _T("Set the number of status bar fields"));
+    statbarMenu->Append(StatusBar_Toggle, _T("&Toggle Status Bar"),
+                        _T("Toggle the status bar display"), true);
+    statbarMenu->Append(StatusBar_Recreate, _T("&Recreate\tCtrl-R"),
+                        _T("Toggle status bar format"));
 
     wxMenu *helpMenu = new wxMenu;
-    helpMenu->Append(StatusBar_About, "&About...\tCtrl-A", "Show about dialog");
+    helpMenu->Append(StatusBar_About, _T("&About...\tCtrl-A"), _T("Show about dialog"));
 
     // now append the freshly created menu to the menu bar...
     wxMenuBar *menuBar = new wxMenuBar();
-    menuBar->Append(menuFile, "&File");
-    menuBar->Append(statbarMenu, "&Status bar");
-    menuBar->Append(helpMenu, "&Help");
+    menuBar->Append(menuFile, _T("&File"));
+    menuBar->Append(statbarMenu, _T("&Status bar"));
+    menuBar->Append(helpMenu, _T("&Help"));
 
     // ... and attach this menu bar to the frame
     SetMenuBar(menuBar);
@@ -298,7 +300,7 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
     // create default status bar to start with
     CreateStatusBar(2);
     m_statbarKind = StatBar_Default;
-    SetStatusText("Welcome to wxWindows!");
+    SetStatusText(_T("Welcome to wxWidgets!"));
 
     m_statbarDefault = GetStatusBar();
 }
@@ -361,7 +363,7 @@ void MyFrame::OnSetStatusFields(wxCommandEvent& WXUNUSED(event))
                    (
                     _T("Select the number of fields in the status bar"),
                     _T("Fields:"),
-                    _T("wxWindows statusbar sample"),
+                    _T("wxWidgets statusbar sample"),
                     sb->GetFieldsCount(),
                     1, 5,
                     this
@@ -429,7 +431,7 @@ void MyFrame::OnStatusBarToggle(wxCommandEvent& WXUNUSED(event))
         DoCreateStatusBar(m_statbarKind);
     }
 #ifdef __WXMSW__
-    // The following is a kludge suggested by Vadim Zeitlin (one of the wxWindows
+    // The following is a kludge suggested by Vadim Zeitlin (one of the wxWidgets
     // authors) while we look for a proper fix..
 //    SendSizeEvent();
 #endif
@@ -443,8 +445,8 @@ void MyFrame::OnRecreateStatusBar(wxCommandEvent& WXUNUSED(event))
 
 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
 {
-    // TRUE is to force the frame to close
-    Close(TRUE);
+    // true is to force the frame to close
+    Close(true);
 }
 
 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
@@ -458,28 +460,28 @@ void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
 // ----------------------------------------------------------------------------
 
 MyAboutDialog::MyAboutDialog(wxWindow *parent)
-             : wxDialog(parent, -1, wxString("About statbar"),
+             : wxDialog(parent, wxID_ANY, wxString(_T("About statbar")),
                         wxDefaultPosition, wxDefaultSize,
                         wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
 {
-    wxStaticText *text = new wxStaticText(this, -1,
-                                          "wxStatusBar sample\n"
-                                          "(c) 2000 Vadim Zeitlin");
+    wxStaticText *text = new wxStaticText(this, wxID_ANY,
+                                          _T("wxStatusBar sample\n")
+                                          _T("(c) 2000 Vadim Zeitlin"));
 
-    wxButton *btn = new wxButton(this, wxID_OK, "&Close");
+    wxButton *btn = new wxButton(this, wxID_OK, _T("&Close"));
 
     // create the top status bar without the size grip (default style),
     // otherwise it looks weird
-    wxStatusBar *statbarTop = new wxStatusBar(this, -1, 0);
+    wxStatusBar *statbarTop = new wxStatusBar(this, wxID_ANY, 0);
     statbarTop->SetFieldsCount(3);
-    statbarTop->SetStatusText("This is a top status bar", 0);
-    statbarTop->SetStatusText("in a dialog", 1);
-    statbarTop->SetStatusText("Great, isn't it?", 2);
+    statbarTop->SetStatusText(_T("This is a top status bar"), 0);
+    statbarTop->SetStatusText(_T("in a dialog"), 1);
+    statbarTop->SetStatusText(_T("Great, isn't it?"), 2);
 
-    wxStatusBar *statbarBottom = new wxStatusBar(this, -1);
+    wxStatusBar *statbarBottom = new wxStatusBar(this, wxID_ANY);
     statbarBottom->SetFieldsCount(2);
-    statbarBottom->SetStatusText("This is a bottom status bar", 0);
-    statbarBottom->SetStatusText("in a dialog", 1);
+    statbarBottom->SetStatusText(_T("This is a bottom status bar"), 0);
+    statbarBottom->SetStatusText(_T("in a dialog"), 1);
 
     wxBoxSizer *sizerTop = new wxBoxSizer(wxVERTICAL);
     sizerTop->Add(statbarTop, 0, wxGROW);
@@ -490,7 +492,6 @@ MyAboutDialog::MyAboutDialog(wxWindow *parent)
     sizerTop->Add(-1, 10, 1, wxGROW);
     sizerTop->Add(statbarBottom, 0, wxGROW);
 
-    SetAutoLayout(TRUE);
     SetSizer(sizerTop);
 
     sizerTop->Fit(this);
@@ -507,7 +508,7 @@ MyAboutDialog::MyAboutDialog(wxWindow *parent)
 #endif
 
 MyStatusBar::MyStatusBar(wxWindow *parent)
-           : wxStatusBar(parent, -1), m_timer(this), m_checkbox(NULL)
+           : wxStatusBar(parent, wxID_ANY), m_timer(this), m_checkbox(NULL)
 {
     static const int widths[Field_Max] = { -1, 150, BITMAP_SIZE_X, 100 };
 
@@ -515,12 +516,12 @@ MyStatusBar::MyStatusBar(wxWindow *parent)
     SetStatusWidths(Field_Max, widths);
 
     m_checkbox = new wxCheckBox(this, StatusBar_Checkbox, _T("&Toggle clock"));
-    m_checkbox->SetValue(TRUE);
+    m_checkbox->SetValue(true);
 
 #ifdef USE_STATIC_BITMAP
-    m_statbmp = new wxStaticBitmap(this, -1, wxIcon(green_xpm));
+    m_statbmp = new wxStaticBitmap(this, wxID_ANY, wxIcon(green_xpm));
 #else
-    m_statbmp = new wxBitmapButton(this, -1, CreateBitmapForButton(),
+    m_statbmp = new wxBitmapButton(this, wxID_ANY, CreateBitmapForButton(),
                                    wxDefaultPosition, wxDefaultSize,
                                    wxBU_EXACTFIT);
 #endif
@@ -601,7 +602,7 @@ void MyStatusBar::DoToggle()
 #ifdef USE_STATIC_BITMAP
         m_statbmp->SetIcon(wxIcon(green_xpm));
 #else
-        m_statbmp->SetBitmapLabel(CreateBitmapForButton(FALSE));
+        m_statbmp->SetBitmapLabel(CreateBitmapForButton(false));
         m_statbmp->Refresh();
 #endif
 
@@ -614,11 +615,11 @@ void MyStatusBar::DoToggle()
 #ifdef USE_STATIC_BITMAP
         m_statbmp->SetIcon(wxIcon(red_xpm));
 #else
-        m_statbmp->SetBitmapLabel(CreateBitmapForButton(TRUE));
+        m_statbmp->SetBitmapLabel(CreateBitmapForButton(true));
         m_statbmp->Refresh();
 #endif
 
-        SetStatusText("", Field_Clock);
+        SetStatusText(wxEmptyString, Field_Clock);
     }
 }