]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/widgets/combobox.cpp
Fix wrong configure test for abi::__forced_unwind in previous commit.
[wxWidgets.git] / samples / widgets / combobox.cpp
index 58bcf7ce4d4854f080605d5149989ec158287af1..23fd516a01d3bb5781efcb5797af33186c27cacc 100644 (file)
@@ -6,7 +6,7 @@
 // Created:     27.03.01
 // Id:          $Id$
 // Copyright:   (c) 2001 Vadim Zeitlin
-// License:     wxWindows license
+// Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 // ============================================================================
@@ -43,7 +43,6 @@
 
 #include "itemcontainer.h"
 #include "widgets.h"
-#if 1
 #include "icons/combobox.xpm"
 
 // ----------------------------------------------------------------------------
@@ -54,6 +53,8 @@
 enum
 {
     ComboPage_Reset = wxID_HIGHEST,
+    ComboPage_Popup,
+    ComboPage_Dismiss,
     ComboPage_SetCurrent,
     ComboPage_CurText,
     ComboPage_InsertionPointText,
@@ -61,6 +62,8 @@ enum
     ComboPage_InsertText,
     ComboPage_Add,
     ComboPage_AddText,
+    ComboPage_SetFirst,
+    ComboPage_SetFirstText,
     ComboPage_AddSeveral,
     ComboPage_AddMany,
     ComboPage_Clear,
@@ -103,12 +106,15 @@ public:
 protected:
     // event handlers
     void OnButtonReset(wxCommandEvent& event);
+    void OnButtonPopup(wxCommandEvent&) { m_combobox->Popup(); }
+    void OnButtonDismiss(wxCommandEvent&) { m_combobox->Dismiss(); }
     void OnButtonChange(wxCommandEvent& event);
     void OnButtonDelete(wxCommandEvent& event);
     void OnButtonDeleteSel(wxCommandEvent& event);
     void OnButtonClear(wxCommandEvent& event);
     void OnButtonInsert(wxCommandEvent &event);
     void OnButtonAdd(wxCommandEvent& event);
+    void OnButtonSetFirst(wxCommandEvent& event);
     void OnButtonAddSeveral(wxCommandEvent& event);
     void OnButtonAddMany(wxCommandEvent& event);
     void OnButtonSetValue(wxCommandEvent& event);
@@ -118,6 +124,7 @@ protected:
     void OnCloseup(wxCommandEvent& event);
     void OnComboBox(wxCommandEvent& event);
     void OnComboText(wxCommandEvent& event);
+    void OnComboTextPasted(wxClipboardTextEvent& event);
 
     void OnCheckOrRadioBox(wxCommandEvent& event);
 
@@ -155,6 +162,7 @@ protected:
     // the text entries for "Add/change string" and "Delete" buttons
     wxTextCtrl *m_textInsert,
                *m_textAdd,
+               *m_textSetFirst,
                *m_textChange,
                *m_textSetValue,
                *m_textDelete,
@@ -171,12 +179,15 @@ private:
 
 BEGIN_EVENT_TABLE(ComboboxWidgetsPage, WidgetsPage)
     EVT_BUTTON(ComboPage_Reset, ComboboxWidgetsPage::OnButtonReset)
+    EVT_BUTTON(ComboPage_Popup, ComboboxWidgetsPage::OnButtonPopup)
+    EVT_BUTTON(ComboPage_Dismiss, ComboboxWidgetsPage::OnButtonDismiss)
     EVT_BUTTON(ComboPage_Change, ComboboxWidgetsPage::OnButtonChange)
     EVT_BUTTON(ComboPage_Delete, ComboboxWidgetsPage::OnButtonDelete)
     EVT_BUTTON(ComboPage_DeleteSel, ComboboxWidgetsPage::OnButtonDeleteSel)
     EVT_BUTTON(ComboPage_Clear, ComboboxWidgetsPage::OnButtonClear)
     EVT_BUTTON(ComboPage_Insert, ComboboxWidgetsPage::OnButtonInsert)
     EVT_BUTTON(ComboPage_Add, ComboboxWidgetsPage::OnButtonAdd)
+    EVT_BUTTON(ComboPage_SetFirst, ComboboxWidgetsPage::OnButtonSetFirst)
     EVT_BUTTON(ComboPage_AddSeveral, ComboboxWidgetsPage::OnButtonAddSeveral)
     EVT_BUTTON(ComboPage_AddMany, ComboboxWidgetsPage::OnButtonAddMany)
     EVT_BUTTON(ComboPage_SetValue, ComboboxWidgetsPage::OnButtonSetValue)
@@ -205,6 +216,7 @@ BEGIN_EVENT_TABLE(ComboboxWidgetsPage, WidgetsPage)
     EVT_COMBOBOX_CLOSEUP(ComboPage_Combo, ComboboxWidgetsPage::OnCloseup)
     EVT_TEXT(ComboPage_Combo, ComboboxWidgetsPage::OnComboText)
     EVT_TEXT_ENTER(ComboPage_Combo, ComboboxWidgetsPage::OnComboText)
+    EVT_TEXT_PASTE(ComboPage_Combo, ComboboxWidgetsPage::OnComboTextPasted)
 
     EVT_CHECKBOX(wxID_ANY, ComboboxWidgetsPage::OnCheckOrRadioBox)
     EVT_RADIOBOX(wxID_ANY, ComboboxWidgetsPage::OnCheckOrRadioBox)
@@ -247,8 +259,7 @@ void ComboboxWidgetsPage::CreateContent()
     */
     wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
 
-    // left pane
-    wxStaticBox *box = new wxStaticBox(this, wxID_ANY, wxT("&Set style"));
+    // upper left pane
 
     // should be in sync with ComboKind_XXX values
     static const wxString kinds[] =
@@ -263,18 +274,31 @@ void ComboboxWidgetsPage::CreateContent()
                                  WXSIZEOF(kinds), kinds,
                                  1, wxRA_SPECIFY_COLS);
 
-    wxSizer *sizerLeft = new wxStaticBoxSizer(box, wxVERTICAL);
+    wxSizer *sizerLeftTop = new wxStaticBoxSizer(wxVERTICAL, this, "&Set style");
 
-    m_chkSort = CreateCheckBoxAndAddToSizer(sizerLeft, wxT("&Sort items"));
-    m_chkReadonly = CreateCheckBoxAndAddToSizer(sizerLeft, wxT("&Read only"));
-    m_chkFilename = CreateCheckBoxAndAddToSizer(sizerLeft, wxT("&File name"));
+    m_chkSort = CreateCheckBoxAndAddToSizer(sizerLeftTop, wxT("&Sort items"));
+    m_chkReadonly = CreateCheckBoxAndAddToSizer(sizerLeftTop, wxT("&Read only"));
+    m_chkFilename = CreateCheckBoxAndAddToSizer(sizerLeftTop, wxT("&File name"));
     m_chkFilename->Disable(); // not implemented yet
 
-    sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer
-    sizerLeft->Add(m_radioKind, 0, wxGROW | wxALL, 5);
+    sizerLeftTop->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer
+    sizerLeftTop->Add(m_radioKind, 0, wxGROW | wxALL, 5);
 
     wxButton *btn = new wxButton(this, ComboPage_Reset, wxT("&Reset"));
-    sizerLeft->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15);
+    sizerLeftTop->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15);
+
+    // lower left pane
+    wxSizer *sizerLeftBottom = new wxStaticBoxSizer(wxVERTICAL, this, "&Popup");
+    sizerLeftBottom->Add(new wxButton(this, ComboPage_Popup, "&Show"),
+                         wxSizerFlags().Border().Centre());
+    sizerLeftBottom->Add(new wxButton(this, ComboPage_Dismiss, "&Hide"),
+                         wxSizerFlags().Border().Centre());
+
+
+    wxSizer *sizerLeft = new wxBoxSizer(wxVERTICAL);
+    sizerLeft->Add(sizerLeftTop);
+    sizerLeft->AddSpacer(10);
+    sizerLeft->Add(sizerLeftBottom);
 
     // middle pane
     wxStaticBox *box2 = new wxStaticBox(this, wxID_ANY,
@@ -310,6 +334,12 @@ void ComboboxWidgetsPage::CreateContent()
                                             &m_textAdd);
     sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
 
+    sizerRow = CreateSizerWithTextAndButton(ComboPage_SetFirst,
+                                            wxT("Change &1st string"),
+                                            ComboPage_SetFirstText,
+                                            &m_textSetFirst);
+    sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
+
     btn = new wxButton(this, ComboPage_AddSeveral, wxT("&Append a few strings"));
     sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5);
 
@@ -453,11 +483,7 @@ void ComboboxWidgetsPage::OnButtonChange(wxCommandEvent& WXUNUSED(event))
     int sel = m_combobox->GetSelection();
     if ( sel != wxNOT_FOUND )
     {
-#ifndef __WXGTK__
         m_combobox->SetString(sel, m_textChange->GetValue());
-#else
-        wxLogMessage(wxT("Not implemented in wxGTK"));
-#endif
     }
 }
 
@@ -522,6 +548,17 @@ void ComboboxWidgetsPage::OnButtonAdd(wxCommandEvent& WXUNUSED(event))
     m_combobox->Append(s);
 }
 
+void ComboboxWidgetsPage::OnButtonSetFirst(wxCommandEvent& WXUNUSED(event))
+{
+    if ( m_combobox->IsListEmpty() )
+    {
+        wxLogWarning("No string to change.");
+        return;
+    }
+
+    m_combobox->SetString(0, m_textSetFirst->GetValue());
+}
+
 void ComboboxWidgetsPage::OnButtonAddMany(wxCommandEvent& WXUNUSED(event))
 {
     // "many" means 1000 here
@@ -627,6 +664,12 @@ void ComboboxWidgetsPage::OnComboText(wxCommandEvent& event)
     }
 }
 
+void ComboboxWidgetsPage::OnComboTextPasted(wxClipboardTextEvent& event)
+{
+    wxLogMessage("Text pasted from clipboard.");
+    event.Skip();
+}
+
 void ComboboxWidgetsPage::OnComboBox(wxCommandEvent& event)
 {
     long sel = event.GetInt();
@@ -637,6 +680,12 @@ void ComboboxWidgetsPage::OnComboBox(wxCommandEvent& event)
     wxLogMessage(wxT("Combobox item %ld selected"), sel);
 
     wxLogMessage(wxT("Combobox GetValue(): %s"), m_combobox->GetValue().c_str() );
+
+    if ( event.GetString() != m_combobox->GetValue() )
+    {
+        wxLogMessage("ERROR: Event has different string \"%s\"",
+                     event.GetString());
+    }
 }
 
 void ComboboxWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& WXUNUSED(event))
@@ -654,6 +703,4 @@ void ComboboxWidgetsPage::OnCloseup(wxCommandEvent& WXUNUSED(event))
     wxLogMessage(wxT("Combobox closed up"));
 }
 
-#endif //wxUSE_COMBOBOX
-
-#endif
+#endif // wxUSE_COMBOBOX