]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/widgets/button.cpp
use wxDC::GetMultiLineTextExtent() instead of duplicating its code in wxButton::DoGet...
[wxWidgets.git] / samples / widgets / button.cpp
index 29e80d1b9257e99a1da10cce44ceaac955ac92be..11e0e9e6e5a3ad9abec34cb9c321e0177ed44268 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////////////
-// Program:     wxWindows Widgets Sample
+// Program:     wxWidgets Widgets Sample
 // Name:        button.cpp
 // Purpose:     Part of the widgets sample showing wxButton
 // Author:      Vadim Zeitlin
 // Name:        button.cpp
 // Purpose:     Part of the widgets sample showing wxButton
 // Author:      Vadim Zeitlin
     #include "wx/textctrl.h"
 #endif
 
     #include "wx/textctrl.h"
 #endif
 
+#include "wx/artprov.h"
 #include "wx/sizer.h"
 
 #include "widgets.h"
 #include "wx/sizer.h"
 
 #include "widgets.h"
-#if 1
+
 #include "icons/button.xpm"
 
 // ----------------------------------------------------------------------------
 #include "icons/button.xpm"
 
 // ----------------------------------------------------------------------------
@@ -76,8 +77,10 @@ enum
 class ButtonWidgetsPage : public WidgetsPage
 {
 public:
 class ButtonWidgetsPage : public WidgetsPage
 {
 public:
-    ButtonWidgetsPage(wxNotebook *notebook, wxImageList *imaglist);
-    virtual ~ButtonWidgetsPage();
+    ButtonWidgetsPage(wxBookCtrl *book, wxImageList *imaglist);
+    virtual ~ButtonWidgetsPage(){};
+
+    virtual wxControl *GetWidget() const { return m_button; }
 
 protected:
     // event handlers
 
 protected:
     // event handlers
@@ -104,7 +107,7 @@ protected:
     wxRadioBox *m_radioHAlign,
                *m_radioVAlign;
 
     wxRadioBox *m_radioHAlign,
                *m_radioVAlign;
 
-    // the gauge itself and the sizer it is in
+    // the button itself and the sizer it is in
     wxButton *m_button;
     wxSizer *m_sizerButton;
 
     wxButton *m_button;
     wxSizer *m_sizerButton;
 
@@ -126,8 +129,8 @@ BEGIN_EVENT_TABLE(ButtonWidgetsPage, WidgetsPage)
     EVT_BUTTON(ButtonPage_Reset, ButtonWidgetsPage::OnButtonReset)
     EVT_BUTTON(ButtonPage_ChangeLabel, ButtonWidgetsPage::OnButtonChangeLabel)
 
     EVT_BUTTON(ButtonPage_Reset, ButtonWidgetsPage::OnButtonReset)
     EVT_BUTTON(ButtonPage_ChangeLabel, ButtonWidgetsPage::OnButtonChangeLabel)
 
-    EVT_CHECKBOX(-1, ButtonWidgetsPage::OnCheckOrRadioBox)
-    EVT_RADIOBOX(-1, ButtonWidgetsPage::OnCheckOrRadioBox)
+    EVT_CHECKBOX(wxID_ANY, ButtonWidgetsPage::OnCheckOrRadioBox)
+    EVT_RADIOBOX(wxID_ANY, ButtonWidgetsPage::OnCheckOrRadioBox)
 END_EVENT_TABLE()
 
 // ============================================================================
 END_EVENT_TABLE()
 
 // ============================================================================
@@ -136,9 +139,9 @@ END_EVENT_TABLE()
 
 IMPLEMENT_WIDGETS_PAGE(ButtonWidgetsPage, _T("Button"));
 
 
 IMPLEMENT_WIDGETS_PAGE(ButtonWidgetsPage, _T("Button"));
 
-ButtonWidgetsPage::ButtonWidgetsPage(wxNotebook *notebook,
-                                       wxImageList *imaglist)
-                  : WidgetsPage(notebook)
+ButtonWidgetsPage::ButtonWidgetsPage(wxBookCtrl *book,
+                                     wxImageList *imaglist)
+                  : WidgetsPage(book)
 {
     imaglist->Add(wxBitmap(button_xpm));
 
 {
     imaglist->Add(wxBitmap(button_xpm));
 
@@ -158,7 +161,7 @@ ButtonWidgetsPage::ButtonWidgetsPage(wxNotebook *notebook,
     wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
 
     // left pane
     wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
 
     // left pane
-    wxStaticBox *box = new wxStaticBox(this, -1, _T("&Set style"));
+    wxStaticBox *box = new wxStaticBox(this, wxID_ANY, _T("&Set style"));
 
     wxSizer *sizerLeft = new wxStaticBoxSizer(box, wxVERTICAL);
 
 
     wxSizer *sizerLeft = new wxStaticBoxSizer(box, wxVERTICAL);
 
@@ -167,7 +170,7 @@ ButtonWidgetsPage::ButtonWidgetsPage(wxNotebook *notebook,
     m_chkDefault = CreateCheckBoxAndAddToSizer(sizerLeft, _T("&Default"));
 
 #ifndef __WXUNIVERSAL__
     m_chkDefault = CreateCheckBoxAndAddToSizer(sizerLeft, _T("&Default"));
 
 #ifndef __WXUNIVERSAL__
-    // only wxUniv currently supoprts buttons with images
+    // only wxUniv currently supports buttons with images
     m_chkImage->Disable();
 #endif // !wxUniv
 
     m_chkImage->Disable();
 #endif // !wxUniv
 
@@ -188,10 +191,10 @@ ButtonWidgetsPage::ButtonWidgetsPage(wxNotebook *notebook,
         _T("bottom"),
     };
 
         _T("bottom"),
     };
 
-    m_radioHAlign = new wxRadioBox(this, -1, _T("&Horz alignment"),
+    m_radioHAlign = new wxRadioBox(this, wxID_ANY, _T("&Horz alignment"),
                                    wxDefaultPosition, wxDefaultSize,
                                    WXSIZEOF(halign), halign);
                                    wxDefaultPosition, wxDefaultSize,
                                    WXSIZEOF(halign), halign);
-    m_radioVAlign = new wxRadioBox(this, -1, _T("&Vert alignment"),
+    m_radioVAlign = new wxRadioBox(this, wxID_ANY, _T("&Vert alignment"),
                                    wxDefaultPosition, wxDefaultSize,
                                    WXSIZEOF(valign), valign);
 
                                    wxDefaultPosition, wxDefaultSize,
                                    WXSIZEOF(valign), valign);
 
@@ -204,12 +207,12 @@ ButtonWidgetsPage::ButtonWidgetsPage(wxNotebook *notebook,
     sizerLeft->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15);
 
     // middle pane
     sizerLeft->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15);
 
     // middle pane
-    wxStaticBox *box2 = new wxStaticBox(this, -1, _T("&Operations"));
+    wxStaticBox *box2 = new wxStaticBox(this, wxID_ANY, _T("&Operations"));
     wxSizer *sizerMiddle = new wxStaticBoxSizer(box2, wxVERTICAL);
 
     wxSizer *sizerRow = CreateSizerWithTextAndButton(ButtonPage_ChangeLabel,
                                                      _T("Change label"),
     wxSizer *sizerMiddle = new wxStaticBoxSizer(box2, wxVERTICAL);
 
     wxSizer *sizerRow = CreateSizerWithTextAndButton(ButtonPage_ChangeLabel,
                                                      _T("Change label"),
-                                                     -1,
+                                                     wxID_ANY,
                                                      &m_textLabel);
 
     sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
                                                      &m_textLabel);
 
     sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
@@ -231,25 +234,20 @@ ButtonWidgetsPage::ButtonWidgetsPage(wxNotebook *notebook,
     // final initializations
     Reset();
 
     // final initializations
     Reset();
 
-    SetAutoLayout(TRUE);
     SetSizer(sizerTop);
 
     sizerTop->Fit(this);
 }
 
     SetSizer(sizerTop);
 
     sizerTop->Fit(this);
 }
 
-ButtonWidgetsPage::~ButtonWidgetsPage()
-{
-}
-
 // ----------------------------------------------------------------------------
 // operations
 // ----------------------------------------------------------------------------
 
 void ButtonWidgetsPage::Reset()
 {
 // ----------------------------------------------------------------------------
 // operations
 // ----------------------------------------------------------------------------
 
 void ButtonWidgetsPage::Reset()
 {
-    m_chkFit->SetValue(TRUE);
-    m_chkImage->SetValue(FALSE);
-    m_chkDefault->SetValue(FALSE);
+    m_chkFit->SetValue(true);
+    m_chkImage->SetValue(false);
+    m_chkDefault->SetValue(false);
 
     m_radioHAlign->SetSelection(ButtonHAlign_Centre);
     m_radioVAlign->SetSelection(ButtonVAlign_Centre);
 
     m_radioHAlign->SetSelection(ButtonHAlign_Centre);
     m_radioVAlign->SetSelection(ButtonVAlign_Centre);
@@ -265,7 +263,7 @@ void ButtonWidgetsPage::CreateButton()
         size_t count = m_sizerButton->GetChildren().GetCount();
         for ( size_t n = 0; n < count; n++ )
         {
         size_t count = m_sizerButton->GetChildren().GetCount();
         for ( size_t n = 0; n < count; n++ )
         {
-            m_sizerButton->Remove(0);
+            m_sizerButton->Remove( 0 );
         }
 
         delete m_button;
         }
 
         delete m_button;
@@ -279,7 +277,7 @@ void ButtonWidgetsPage::CreateButton()
     switch ( m_radioHAlign->GetSelection() )
     {
         case ButtonHAlign_Left:
     switch ( m_radioHAlign->GetSelection() )
     {
         case ButtonHAlign_Left:
-            flags |= wxALIGN_LEFT;
+            flags |= wxBU_LEFT;
             break;
 
         default:
             break;
 
         default:
@@ -287,18 +285,17 @@ void ButtonWidgetsPage::CreateButton()
             // fall through
 
         case ButtonHAlign_Centre:
             // fall through
 
         case ButtonHAlign_Centre:
-            flags |= wxALIGN_CENTRE_HORIZONTAL;
             break;
 
         case ButtonHAlign_Right:
             break;
 
         case ButtonHAlign_Right:
-            flags |= wxALIGN_RIGHT;
+            flags |= wxBU_RIGHT;
             break;
     }
 
     switch ( m_radioVAlign->GetSelection() )
     {
         case ButtonVAlign_Top:
             break;
     }
 
     switch ( m_radioVAlign->GetSelection() )
     {
         case ButtonVAlign_Top:
-            flags |= wxALIGN_TOP;
+            flags |= wxBU_TOP;
             break;
 
         default:
             break;
 
         default:
@@ -310,7 +307,7 @@ void ButtonWidgetsPage::CreateButton()
             break;
 
         case ButtonVAlign_Bottom:
             break;
 
         case ButtonVAlign_Bottom:
-            flags |= wxALIGN_BOTTOM;
+            flags |= wxBU_BOTTOM;
             break;
     }
 
             break;
     }
 
@@ -321,7 +318,7 @@ void ButtonWidgetsPage::CreateButton()
 #ifdef __WXUNIVERSAL__
     if ( m_chkImage->GetValue() )
     {
 #ifdef __WXUNIVERSAL__
     if ( m_chkImage->GetValue() )
     {
-        m_button->SetImageLabel(wxTheApp->GetStdIcon(wxICON_INFORMATION));
+        m_button->SetImageLabel(wxArtProvider::GetIcon(wxART_INFORMATION));
     }
 #endif // wxUniv
 
     }
 #endif // wxUniv
 
@@ -355,7 +352,7 @@ void ButtonWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event))
     CreateButton();
 }
 
     CreateButton();
 }
 
-void ButtonWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& event)
+void ButtonWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& WXUNUSED(event))
 {
     CreateButton();
 }
 {
     CreateButton();
 }
@@ -365,9 +362,8 @@ void ButtonWidgetsPage::OnButtonChangeLabel(wxCommandEvent& WXUNUSED(event))
     m_button->SetLabel(m_textLabel->GetValue());
 }
 
     m_button->SetLabel(m_textLabel->GetValue());
 }
 
-void ButtonWidgetsPage::OnButton(wxCommandEvent& event)
+void ButtonWidgetsPage::OnButton(wxCommandEvent& WXUNUSED(event))
 {
     wxLogMessage(_T("Test button clicked."));
 }
 
 {
     wxLogMessage(_T("Test button clicked."));
 }
 
-#endif
\ No newline at end of file