]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/controls/controls.cpp
wxGTK keyboard handling now behaves (mostly) like wxMSW
[wxWidgets.git] / samples / controls / controls.cpp
index 8f984f0bd681b4857d4e1f56813b6a7a1f4df643..e4b7ae08e7f9610101d6b54fecc6a32a1396031e 100644 (file)
 #include "wx/tglbtn.h"
 #include "wx/notebook.h"
 #include "wx/imaglist.h"
+#include "wx/artprov.h"
 
 #if wxUSE_TOOLTIPS
     #include "wx/tooltip.h"
 #endif
 
-#if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__)
+#if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) || defined(__WXX11__)
     #define USE_XPM
 #endif
 
@@ -291,8 +292,8 @@ private:
 // other
 //----------------------------------------------------------------------
 
-static void SetControlClientData(const wxChar *name,
-                                 wxControlWithItems *control);
+static void SetListboxClientData(const wxChar *name, wxListBox *control);
+static void SetChoiceClientData(const wxChar *name, wxChoice *control);
 
 IMPLEMENT_APP(MyApp)
 
@@ -326,8 +327,8 @@ bool MyApp::OnInit()
         y = 50;
     if ( argc == 3 )
     {
-        wxSscanf(argv[1], "%d", &x);
-        wxSscanf(argv[2], "%d", &y);
+        wxSscanf(wxString(argv[1]), wxT("%d"), &x);
+        wxSscanf(wxString(argv[2]), wxT("%d"), &y);
     }
 
     // Create the main frame window
@@ -483,11 +484,9 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
        : wxPanel( frame, -1, wxPoint(x, y), wxSize(w, h) ),
          m_text(NULL), m_notebook(NULL)
 {
-    wxLayoutConstraints *c;
-
     m_text = new wxTextCtrl(this, -1, "This is the log window.\n",
                             wxPoint(0, 250), wxSize(100, 50), wxTE_MULTILINE);
-    m_text->SetBackgroundColour("wheat");
+    m_text->SetBackgroundColour(wxT("wheat"));
 
     if ( 0 )
         wxLog::AddTraceMask(_T("focus"));
@@ -566,8 +565,8 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
                                      wxPoint(10,90), wxSize(120,70),
                                      5, choices, wxLB_SORT );
 
-    SetControlClientData(wxT("listbox"), m_listbox);
-    SetControlClientData(wxT("listbox"), m_listboxSorted);
+    SetListboxClientData(wxT("listbox"), m_listbox);
+    SetListboxClientData(wxT("listbox"), m_listboxSorted);
 
     m_listbox->SetCursor(*wxCROSS_CURSOR);
 #if wxUSE_TOOLTIPS
@@ -605,11 +604,11 @@ 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 );
 
-    SetControlClientData(wxT("choice"), m_choice);
-    SetControlClientData(wxT("choice"), m_choiceSorted);
+    SetChoiceClientData(wxT("choice"), m_choice);
+    SetChoiceClientData(wxT("choice"), m_choiceSorted);
 
     m_choice->SetSelection(2);
-    m_choice->SetBackgroundColour( "red" );
+    m_choice->SetBackgroundColour( wxT("red") );
     (void)new wxButton( panel, ID_CHOICE_SEL_NUM, "Select #&2", wxPoint(180,30), wxSize(140,30) );
     (void)new wxButton( panel, ID_CHOICE_SEL_STR, "&Select 'This'", wxPoint(340,30), wxSize(140,30) );
     (void)new wxButton( panel, ID_CHOICE_CLEAR, "&Clear", wxPoint(180,80), wxSize(140,30) );
@@ -676,7 +675,10 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
     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) );
+    (void)new wxStaticBox( panel, -1, "&Explanation",
+                           wxPoint(230,10), wxSize(270,130),
+                           wxALIGN_CENTER );
+
 #ifdef __WXMOTIF__
     // No wrapping text in wxStaticText yet :-(
     (void)new wxStaticText( panel, -1,
@@ -720,12 +722,12 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
     panel = new wxPanel(m_notebook);
 
 #if !defined(__WXMOTIF__) && !defined(__WIN16__)  // wxStaticBitmap not working under Motif yet; and icons not allowed under WIN16.
-    wxIcon icon = wxTheApp->GetStdIcon(wxICON_INFORMATION);
+    wxIcon icon = wxArtProvider::GetIcon(wxART_INFORMATION);
     wxStaticBitmap *bmpStatic = new wxStaticBitmap(panel, -1, icon,
                                                    wxPoint(10, 10));
 
     bmpStatic = new wxStaticBitmap(panel, -1, wxNullIcon, wxPoint(50, 10));
-    bmpStatic->SetIcon(wxTheApp->GetStdIcon(wxICON_QUESTION));
+    bmpStatic->SetIcon(wxArtProvider::GetIcon(wxART_QUESTION));
 #endif // !Motif
 
     wxBitmap bitmap( 100, 100 );
@@ -750,9 +752,9 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
     }
 #endif
 
-    wxBitmap bmp1(wxTheApp->GetStdIcon(wxICON_INFORMATION)),
-             bmp2(wxTheApp->GetStdIcon(wxICON_WARNING)),
-             bmp3(wxTheApp->GetStdIcon(wxICON_QUESTION));
+    wxBitmap bmp1(wxArtProvider::GetBitmap(wxART_INFORMATION)),
+             bmp2(wxArtProvider::GetBitmap(wxART_WARNING)),
+             bmp3(wxArtProvider::GetBitmap(wxART_QUESTION));
     wxBitmapButton *bmpBtn = new wxBitmapButton
                                  (
                                   panel, -1,
@@ -776,6 +778,8 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
     m_notebook->AddPage(panel, "wxBitmapXXX");
 
     // layout constraints
+#if wxUSE_CONSTRAINTS
+    wxLayoutConstraints *c;
 
     panel = new wxPanel(m_notebook);
     panel->SetAutoLayout( TRUE );
@@ -799,7 +803,8 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
     pMyButton2->SetConstraints( c );
 
     m_notebook->AddPage(panel, "wxLayoutConstraint");
-
+#endif
+    
     // sizer
 
     panel = new wxPanel(m_notebook);
@@ -876,16 +881,16 @@ void MyPanel::OnChangeColour(wxCommandEvent& WXUNUSED(event))
         SetBackgroundColour(s_colOld);
         s_colOld = wxNullColour;
 
-        m_lbSelectThis->SetForegroundColour("red");
-        m_lbSelectThis->SetBackgroundColour("white");
+        m_lbSelectThis->SetForegroundColour(wxT("red"));
+        m_lbSelectThis->SetBackgroundColour(wxT("white"));
     }
     else
     {
-        s_colOld = wxColour("red");
-        SetBackgroundColour("white");
+        s_colOld = wxColour(wxT("red"));
+        SetBackgroundColour(wxT("white"));
 
-        m_lbSelectThis->SetForegroundColour("white");
-        m_lbSelectThis->SetBackgroundColour("red");
+        m_lbSelectThis->SetForegroundColour(wxT("white"));
+        m_lbSelectThis->SetBackgroundColour(wxT("red"));
     }
 
     m_lbSelectThis->Refresh();
@@ -943,8 +948,8 @@ void MyPanel::OnListBoxButtons( wxCommandEvent &event )
         case ID_LISTBOX_ENABLE:
             {
                 m_text->AppendText("Checkbox clicked.\n");
-                wxCheckBox *cb = (wxCheckBox*)event.GetEventObject();
 #if wxUSE_TOOLTIPS
+                wxCheckBox *cb = (wxCheckBox*)event.GetEventObject();
                 if (event.GetInt())
                     cb->SetToolTip( "Click to enable listbox" );
                 else
@@ -1273,6 +1278,13 @@ void MyPanel::OnUpdateShowProgress( wxUpdateUIEvent& event )
 void MyPanel::OnShowProgress( wxCommandEvent& WXUNUSED(event) )
 {
     int max = m_spinbutton->GetValue();
+    
+    if ( max <= 0 )
+    {
+        wxLogError(_T("You must set positive range!"));
+        return;
+    }
+    
     wxProgressDialog dialog("Progress dialog example",
                             "An informative message",
                             max,    // range
@@ -1515,8 +1527,20 @@ void MyComboBox::OnKeyUp(wxKeyEvent& event)
     event.Skip();
 }
 
-static void SetControlClientData(const wxChar *name,
-                                 wxControlWithItems *control)
+static void SetListboxClientData(const wxChar *name, wxListBox *control)
+{
+    size_t count = control->GetCount();
+    for ( size_t n = 0; n < count; n++ )
+    {
+        wxString s;
+        s.Printf(wxT("%s client data for '%s'"),
+                 name, control->GetString(n).c_str());
+
+        control->SetClientObject(n, new wxStringClientData(s));
+    }
+}
+
+static void SetChoiceClientData(const wxChar *name, wxChoice *control)
 {
     size_t count = control->GetCount();
     for ( size_t n = 0; n < count; n++ )