]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/controls/controls.cpp
fix for bug in wxEditableListBox in connection with new wxListCtrl
[wxWidgets.git] / samples / controls / controls.cpp
index 2b4e7e17c8499886d7061b9709ad1ec9941b72f7..4c23313cd19e14aa2ab7158793f6348e42487b5d 100644 (file)
@@ -26,6 +26,7 @@
 #if !defined( __WXMSW__ ) || defined( __WIN95__ )
 #include "wx/spinbutt.h"
 #endif
 #if !defined( __WXMSW__ ) || defined( __WIN95__ )
 #include "wx/spinbutt.h"
 #endif
+#include "wx/tglbtn.h"
 #include "wx/notebook.h"
 #include "wx/imaglist.h"
 
 #include "wx/notebook.h"
 #include "wx/imaglist.h"
 
@@ -33,7 +34,7 @@
     #include "wx/tooltip.h"
 #endif
 
     #include "wx/tooltip.h"
 #endif
 
-#if defined(__WXGTK__) || defined(__WXMOTIF__)
+#if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__)
     #define USE_XPM
 #endif
 
     #define USE_XPM
 #endif
 
@@ -121,7 +122,8 @@ public:
                   *m_choiceSorted;
     wxComboBox    *m_combo;
     wxRadioBox    *m_radio;
                   *m_choiceSorted;
     wxComboBox    *m_combo;
     wxRadioBox    *m_radio;
-    wxGauge       *m_gauge;
+    wxGauge       *m_gauge,
+                  *m_gaugeVert;
     wxSlider      *m_slider;
     wxButton      *m_fontButton;
     wxButton      *m_lbSelectNum;
     wxSlider      *m_slider;
     wxButton      *m_fontButton;
     wxButton      *m_lbSelectNum;
@@ -175,8 +177,11 @@ private:
     void UpdateStatusBar(const wxPoint& pos, const wxSize& size)
     {
         wxString msg;
     void UpdateStatusBar(const wxPoint& pos, const wxSize& size)
     {
         wxString msg;
-        msg.Printf(_("pos=(%d, %d), size=%dx%d"),
-                   pos.x, pos.y, size.x, size.y);
+        wxSize sizeCl = GetClientSize();
+        msg.Printf(_("pos=(%d, %d), size=%dx%d (client=%dx%d)"),
+                   pos.x, pos.y,
+                   size.x, size.y,
+                   sizeCl.x, sizeCl.y);
         SetStatusText(msg, 1);
     }
 
         SetStatusText(msg, 1);
     }
 
@@ -252,7 +257,7 @@ public:
                int majorDim = 1,
                long style = wxRA_HORIZONTAL,
                const wxValidator& validator = wxDefaultValidator,
                int majorDim = 1,
                long style = wxRA_HORIZONTAL,
                const wxValidator& validator = wxDefaultValidator,
-               const wxString& name = wxComboBoxNameStr)
+               const wxString& name = wxRadioBoxNameStr)
         : wxRadioBox(parent, id, title, pos, size, n, choices, majorDim,
                      style, validator, name) { }
 
         : wxRadioBox(parent, id, title, pos, size, n, choices, majorDim,
                      style, validator, name) { }
 
@@ -279,7 +284,7 @@ private:
 // other
 //----------------------------------------------------------------------
 
 // other
 //----------------------------------------------------------------------
 
-static void SetControlClientData(const char *name,
+static void SetControlClientData(const wxChar *name,
                                  wxControlWithItems *control);
 
 IMPLEMENT_APP(MyApp)
                                  wxControlWithItems *control);
 
 IMPLEMENT_APP(MyApp)
@@ -310,8 +315,8 @@ bool MyApp::OnInit()
         y = 50;
     if ( argc == 3 )
     {
         y = 50;
     if ( argc == 3 )
     {
-        wxSscanf(argv[1], "%d", &x);
-        wxSscanf(argv[2], "%d", &y);
+        //wxSscanf(argv[1], "%d", &x);
+        //wxSscanf(argv[2], "%d", &y);
     }
 
     // Create the main frame window
     }
 
     // Create the main frame window
@@ -474,7 +479,9 @@ EVT_BUTTON    (ID_BTNPROGRESS,          MyPanel::OnShowProgress)
 #if wxUSE_SPINCTRL
 EVT_SPINCTRL  (ID_SPINCTRL,             MyPanel::OnSpinCtrl)
 #endif // wxUSE_SPINCTRL
 #if wxUSE_SPINCTRL
 EVT_SPINCTRL  (ID_SPINCTRL,             MyPanel::OnSpinCtrl)
 #endif // wxUSE_SPINCTRL
-EVT_BUTTON    (ID_BUTTON_LABEL,         MyPanel::OnUpdateLabel)
+#if wxUSE_TOGGLEBTN
+EVT_TOGGLEBUTTON(ID_BUTTON_LABEL,       MyPanel::OnUpdateLabel)
+#endif // wxUSE_TOGGLEBTN
 EVT_CHECKBOX  (ID_CHANGE_COLOUR,        MyPanel::OnChangeColour)
 EVT_BUTTON    (ID_BUTTON_TEST1,         MyPanel::OnTestButton)
 EVT_BUTTON    (ID_BUTTON_TEST2,         MyPanel::OnTestButton)
 EVT_CHECKBOX  (ID_CHANGE_COLOUR,        MyPanel::OnChangeColour)
 EVT_BUTTON    (ID_BUTTON_TEST1,         MyPanel::OnTestButton)
 EVT_BUTTON    (ID_BUTTON_TEST2,         MyPanel::OnTestButton)
@@ -562,7 +569,7 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
         wxBitmap bmp(s_iconNames[n]);
         if ( !bmp.Ok() || (imagelist->Add(bmp) == -1) )
         {
         wxBitmap bmp(s_iconNames[n]);
         if ( !bmp.Ok() || (imagelist->Add(bmp) == -1) )
         {
-            wxLogWarning("Couldn't load the image '%s' for the notebook page %d.",
+            wxLogWarning(wxT("Couldn't load the image '%s' for the notebook page %d."),
                     s_iconNames[n], n);
         }
     }
                     s_iconNames[n], n);
         }
     }
@@ -589,8 +596,8 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
                                      wxPoint(10,90), wxSize(120,70),
                                      5, choices, wxLB_SORT );
 
                                      wxPoint(10,90), wxSize(120,70),
                                      5, choices, wxLB_SORT );
 
-    SetControlClientData("listbox", m_listbox);
-    SetControlClientData("listbox", m_listboxSorted);
+    SetControlClientData(wxT("listbox"), m_listbox);
+    SetControlClientData(wxT("listbox"), m_listboxSorted);
 
     m_listbox->SetCursor(*wxCROSS_CURSOR);
 #if wxUSE_TOOLTIPS
 
     m_listbox->SetCursor(*wxCROSS_CURSOR);
 #if wxUSE_TOOLTIPS
@@ -627,8 +634,8 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
     m_choiceSorted = new wxChoice( panel, ID_CHOICE_SORTED, wxPoint(10,70), wxSize(120,-1),
                                    5, choices, wxCB_SORT );
 
     m_choiceSorted = new wxChoice( panel, ID_CHOICE_SORTED, wxPoint(10,70), wxSize(120,-1),
                                    5, choices, wxCB_SORT );
 
-    SetControlClientData("choice", m_choice);
-    SetControlClientData("choice", m_choiceSorted);
+    SetControlClientData(wxT("choice"), m_choice);
+    SetControlClientData(wxT("choice"), m_choiceSorted);
 
     m_choice->SetSelection(2);
     m_choice->SetBackgroundColour( "red" );
 
     m_choice->SetSelection(2);
     m_choice->SetBackgroundColour( "red" );
@@ -687,17 +694,22 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
     m_notebook->AddPage(panel, "wxRadioBox", FALSE, Image_Radio);
 
     panel = new wxPanel(m_notebook);
     m_notebook->AddPage(panel, "wxRadioBox", FALSE, Image_Radio);
 
     panel = new wxPanel(m_notebook);
-    (void)new wxStaticBox( panel, -1, "&wxGauge and wxSlider", wxPoint(10,10), wxSize(200,130) );
+    (void)new wxStaticBox( panel, -1, "&wxGauge and wxSlider", wxPoint(10,10), wxSize(222,130) );
     m_gauge = new wxGauge( panel, -1, 200, wxPoint(18,50), wxSize(155, 30), wxGA_HORIZONTAL|wxNO_BORDER );
     m_gauge->SetBackgroundColour(*wxGREEN);
     m_gauge->SetForegroundColour(*wxRED);
     m_gauge = new wxGauge( panel, -1, 200, wxPoint(18,50), wxSize(155, 30), wxGA_HORIZONTAL|wxNO_BORDER );
     m_gauge->SetBackgroundColour(*wxGREEN);
     m_gauge->SetForegroundColour(*wxRED);
-    m_slider = new wxSlider( panel, ID_SLIDER, 0, 0, 200, wxPoint(18,90), wxSize(155,-1), wxSL_LABELS );
-    (void)new wxStaticBox( panel, -1, "&Explanation", wxPoint(220,10), wxSize(270,130) );
+    m_gaugeVert = new wxGauge( panel, -1, 100,
+                               wxPoint(195,35), wxSize(30, 90),
+                               wxGA_VERTICAL | wxGA_SMOOTH | wxNO_BORDER );
+    m_slider = new wxSlider( panel, ID_SLIDER, 0, 0, 200, wxPoint(18,90), wxSize(155,-1),
+                             wxSL_AUTOTICKS | wxSL_LABELS );
+    m_slider->SetTickFreq(40, 0);
+    (void)new wxStaticBox( panel, -1, "&Explanation", wxPoint(230,10), wxSize(270,130) );
 #ifdef __WXMOTIF__
     // No wrapping text in wxStaticText yet :-(
     (void)new wxStaticText( panel, -1,
                             "Drag the slider!",
 #ifdef __WXMOTIF__
     // No wrapping text in wxStaticText yet :-(
     (void)new wxStaticText( panel, -1,
                             "Drag the slider!",
-                            wxPoint(228,30),
+                            wxPoint(250,30),
                             wxSize(240, -1)
                           );
 #else
                             wxSize(240, -1)
                           );
 #else
@@ -708,7 +720,7 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
                             "\n"
                             "This is also supposed to demonstrate how\n"
                             "to use static controls.\n",
                             "\n"
                             "This is also supposed to demonstrate how\n"
                             "to use static controls.\n",
-                            wxPoint(228,25),
+                            wxPoint(250,25),
                             wxSize(240, 110)
                           );
 #endif
                             wxSize(240, 110)
                           );
 #endif
@@ -773,12 +785,16 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
                                  (
                                   panel, -1,
                                   bmp1,
                                  (
                                   panel, -1,
                                   bmp1,
-                                  wxPoint(30, 50)
+                                  wxPoint(30, 70)
                                  );
     bmpBtn->SetBitmapSelected(bmp2);
     bmpBtn->SetBitmapFocus(bmp3);
 
                                  );
     bmpBtn->SetBitmapSelected(bmp2);
     bmpBtn->SetBitmapFocus(bmp3);
 
-    (void)new wxButton(panel, ID_BUTTON_LABEL, "&Toggle label", wxPoint(250, 20));
+#if wxUSE_TOGGLEBTN
+    (void)new wxToggleButton(panel, ID_BUTTON_LABEL,
+                             "&Toggle label", wxPoint(250, 20));
+#endif // wxUSE_TOGGLEBTN
+
     m_label = new wxStaticText(panel, -1, "Label with some long text",
                                wxPoint(250, 60), wxDefaultSize,
                                wxALIGN_RIGHT /*| wxST_NO_AUTORESIZE*/);
     m_label = new wxStaticText(panel, -1, "Label with some long text",
                                wxPoint(250, 60), wxDefaultSize,
                                wxALIGN_RIGHT /*| wxST_NO_AUTORESIZE*/);
@@ -854,12 +870,16 @@ void MyPanel::OnPageChanging( wxNotebookEvent &event )
         }
     }
 
         }
     }
 
-    *m_text << "Notebook selection is being changed from " << selOld << "\n";
+    *m_text << "Notebook selection is being changed from " << selOld
+            << " to " << event.GetSelection()
+            << " (current page from notebook is "
+            << m_notebook->GetSelection() << ")\n";
 }
 
 void MyPanel::OnPageChanged( wxNotebookEvent &event )
 {
 }
 
 void MyPanel::OnPageChanged( wxNotebookEvent &event )
 {
-    *m_text << "Notebook selection is " << event.GetSelection() << "\n";
+    *m_text << "Notebook selection is now " << event.GetSelection()
+            << " (from notebook: " << m_notebook->GetSelection() << ")\n";
 }
 
 void MyPanel::OnTestButton(wxCommandEvent& event)
 }
 
 void MyPanel::OnTestButton(wxCommandEvent& event)
@@ -1200,17 +1220,16 @@ void MyPanel::OnSetFont( wxCommandEvent &WXUNUSED(event) )
     m_text->SetFont( *wxITALIC_FONT );
 }
 
     m_text->SetFont( *wxITALIC_FONT );
 }
 
-void MyPanel::OnUpdateLabel( wxCommandEvent &WXUNUSED(event) )
+void MyPanel::OnUpdateLabel( wxCommandEvent &event )
 {
 {
-    static bool s_long = TRUE;
-
-    s_long = !s_long;
-    m_label->SetLabel(s_long ? "Very very very very very long text." : "Shorter text.");
+    m_label->SetLabel(event.GetInt() ? "Very very very very very long text."
+                                     : "Shorter text.");
 }
 
 void MyPanel::OnSliderUpdate( wxCommandEvent &WXUNUSED(event) )
 {
     m_gauge->SetValue( m_slider->GetValue() );
 }
 
 void MyPanel::OnSliderUpdate( wxCommandEvent &WXUNUSED(event) )
 {
     m_gauge->SetValue( m_slider->GetValue() );
+    m_gaugeVert->SetValue( m_slider->GetValue() / 2 );
 }
 
 #if wxUSE_SPINCTRL
 }
 
 #if wxUSE_SPINCTRL
@@ -1485,14 +1504,14 @@ void MyComboBox::OnKeyUp(wxKeyEvent& event)
     event.Skip();
 }
 
     event.Skip();
 }
 
-static void SetControlClientData(const char *name,
+static void SetControlClientData(const wxChar *name,
                                  wxControlWithItems *control)
 {
     size_t count = control->GetCount();
     for ( size_t n = 0; n < count; n++ )
     {
         wxString s;
                                  wxControlWithItems *control)
 {
     size_t count = control->GetCount();
     for ( size_t n = 0; n < count; n++ )
     {
         wxString s;
-        s.Printf("%s client data for '%s'",
+        s.Printf(wxT("%s client data for '%s'"),
                  name, control->GetString(n).c_str());
 
         control->SetClientObject(n, new wxStringClientData(s));
                  name, control->GetString(n).c_str());
 
         control->SetClientObject(n, new wxStringClientData(s));