]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/widgets/bmpcombobox.cpp
Implement ability to rapidly change spin value of SpinCtrl property editor by moving...
[wxWidgets.git] / samples / widgets / bmpcombobox.cpp
index 59b06e47edf1b033fd4e52dfdb07aa95eca9d67e..61ef1dac4680d8d36b0b9c85c514885b12db06ff 100644 (file)
@@ -87,6 +87,13 @@ enum
     BitmapComboBoxPage_ContainerTests
 };
 
     BitmapComboBoxPage_ContainerTests
 };
 
+// kinds of comboboxes
+enum
+{
+    ComboKind_Default,
+    ComboKind_Simple,
+    ComboKind_DropDown
+};
 
 // ----------------------------------------------------------------------------
 // BitmapComboBoxWidgetsPage
 
 // ----------------------------------------------------------------------------
 // BitmapComboBoxWidgetsPage
@@ -161,6 +168,9 @@ protected:
     // the controls
     // ------------
 
     // the controls
     // ------------
 
+    // the sel mode radiobox
+    wxRadioBox *m_radioKind;
+
     // the checkboxes for styles
     wxCheckBox *m_chkSort,
                *m_chkReadonly;
     // the checkboxes for styles
     wxCheckBox *m_chkSort,
                *m_chkReadonly;
@@ -227,10 +237,14 @@ END_EVENT_TABLE()
 // implementation
 // ============================================================================
 
 // implementation
 // ============================================================================
 
-
+#if defined(__WXMSW__) || defined(__WXGTK__)
+    #define NATIVE_OR_GENERIC_CTRLS     NATIVE_CTRLS
+#else
+    #define NATIVE_OR_GENERIC_CTRLS     GENERIC_CTRLS
+#endif
 
 IMPLEMENT_WIDGETS_PAGE(BitmapComboBoxWidgetsPage, _T("BitmapCombobox"),
 
 IMPLEMENT_WIDGETS_PAGE(BitmapComboBoxWidgetsPage, _T("BitmapCombobox"),
-                       GENERIC_CTRLS | WITH_ITEMS_CTRLS | COMBO_CTRLS
+                       NATIVE_OR_GENERIC_CTRLS | WITH_ITEMS_CTRLS | COMBO_CTRLS
                        );
 
 
                        );
 
 
@@ -240,10 +254,15 @@ BitmapComboBoxWidgetsPage::BitmapComboBoxWidgetsPage(WidgetsBookCtrl *book,
 {
     // init everything
     m_chkSort =
 {
     // init everything
     m_chkSort =
-    m_chkReadonly = (wxCheckBox *)NULL;
+    m_chkReadonly = NULL;
+
+    m_combobox = NULL;
+    m_sizerCombo = NULL;
 
 
-    m_combobox = (wxBitmapComboBox *)NULL;
-    m_sizerCombo = (wxSizer *)NULL;
+    m_textInsert =
+    m_textChangeHeight =
+    m_textChange =
+    m_textDelete = NULL;
 }
 
 // create a sizer containing a label and a small text ctrl
 }
 
 // create a sizer containing a label and a small text ctrl
@@ -273,7 +292,6 @@ void BitmapComboBoxWidgetsPage::CreateContent()
        miscellaneous combobox operations and the pane containing the combobox
        itself to the right
     */
        miscellaneous combobox operations and the pane containing the combobox
        itself to the right
     */
-    //wxTextCtrl *text;
     wxSizer *sizerRow;
 
     wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
     wxSizer *sizerRow;
 
     wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
@@ -283,6 +301,20 @@ void BitmapComboBoxWidgetsPage::CreateContent()
     // left pane - style box
     wxStaticBox *box = new wxStaticBox(this, wxID_ANY, _T("&Set style"));
 
     // left pane - style box
     wxStaticBox *box = new wxStaticBox(this, wxID_ANY, _T("&Set style"));
 
+
+    // should be in sync with ComboKind_XXX values
+    static const wxString kinds[] =
+    {
+        _T("default"),
+        _T("simple"),
+        _T("drop down"),
+    };
+
+    m_radioKind = new wxRadioBox(this, wxID_ANY, _T("Combobox &kind:"),
+                                 wxDefaultPosition, wxDefaultSize,
+                                 WXSIZEOF(kinds), kinds,
+                                 1, wxRA_SPECIFY_COLS);
+
     wxSizer *sizerStyle = new wxStaticBoxSizer(box, wxVERTICAL);
 
     m_chkSort = CreateCheckBoxAndAddToSizer(sizerStyle, _T("&Sort items"));
     wxSizer *sizerStyle = new wxStaticBoxSizer(box, wxVERTICAL);
 
     m_chkSort = CreateCheckBoxAndAddToSizer(sizerStyle, _T("&Sort items"));
@@ -292,6 +324,7 @@ void BitmapComboBoxWidgetsPage::CreateContent()
     sizerStyle->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 3);
 
     sizerLeft->Add(sizerStyle, 0, wxGROW | wxALIGN_CENTRE_HORIZONTAL);
     sizerStyle->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 3);
 
     sizerLeft->Add(sizerStyle, 0, wxGROW | wxALIGN_CENTRE_HORIZONTAL);
+    sizerLeft->Add(m_radioKind, 0, wxGROW | wxALL, 5);
 
     // left pane - other options box
     box = new wxStaticBox(this, wxID_ANY, _T("Demo options"));
 
     // left pane - other options box
     box = new wxStaticBox(this, wxID_ANY, _T("Demo options"));
@@ -397,6 +430,24 @@ void BitmapComboBoxWidgetsPage::CreateCombo()
     if ( m_chkReadonly->GetValue() )
         flags |= wxCB_READONLY;
 
     if ( m_chkReadonly->GetValue() )
         flags |= wxCB_READONLY;
 
+    switch ( m_radioKind->GetSelection() )
+    {
+        default:
+            wxFAIL_MSG( _T("unknown combo kind") );
+            // fall through
+
+        case ComboKind_Default:
+            break;
+
+        case ComboKind_Simple:
+            flags |= wxCB_SIMPLE;
+            break;
+
+        case ComboKind_DropDown:
+            flags = wxCB_DROPDOWN;
+            break;
+    }
+
     wxArrayString items;
     wxArrayPtrVoid bitmaps;
     if ( m_combobox )
     wxArrayString items;
     wxArrayPtrVoid bitmaps;
     if ( m_combobox )
@@ -513,7 +564,8 @@ void BitmapComboBoxWidgetsPage::OnButtonInsert(wxCommandEvent& WXUNUSED(event))
 void BitmapComboBoxWidgetsPage::OnTextChangeHeight(wxCommandEvent& WXUNUSED(event))
 {
     long h = 0;
 void BitmapComboBoxWidgetsPage::OnTextChangeHeight(wxCommandEvent& WXUNUSED(event))
 {
     long h = 0;
-    m_textChangeHeight->GetValue().ToLong(&h);
+    if ( m_textChangeHeight )
+        m_textChangeHeight->GetValue().ToLong(&h);
     if ( h < 5 )
         return;
     m_combobox->SetSize(wxDefaultCoord, h);
     if ( h < 5 )
         return;
     m_combobox->SetSize(wxDefaultCoord, h);
@@ -526,12 +578,16 @@ void BitmapComboBoxWidgetsPage::OnButtonLoadFromFile(wxCommandEvent& WXUNUSED(ev
     if ( sel == wxNOT_FOUND )
         sel = m_combobox->GetCount();
 
     if ( sel == wxNOT_FOUND )
         sel = m_combobox->GetCount();
 
-    m_combobox->Insert(s, QueryBitmap(&s), sel);
+    wxBitmap bmp = QueryBitmap(&s);
+    if (bmp.IsOk())
+        m_combobox->Insert(s, bmp, sel);
 }
 
 void BitmapComboBoxWidgetsPage::OnButtonSetFromFile(wxCommandEvent& WXUNUSED(event))
 {
 }
 
 void BitmapComboBoxWidgetsPage::OnButtonSetFromFile(wxCommandEvent& WXUNUSED(event))
 {
-    m_combobox->SetItemBitmap(m_combobox->GetSelection(), QueryBitmap(NULL));
+    wxBitmap bmp = QueryBitmap(NULL);
+    if (bmp.IsOk())
+        m_combobox->SetItemBitmap(m_combobox->GetSelection(), bmp);
 }
 
 void BitmapComboBoxWidgetsPage::OnButtonAddMany(wxCommandEvent& WXUNUSED(event))
 }
 
 void BitmapComboBoxWidgetsPage::OnButtonAddMany(wxCommandEvent& WXUNUSED(event))
@@ -609,6 +665,7 @@ void BitmapComboBoxWidgetsPage::LoadWidgetImages( wxArrayString* strings, wxImag
     if ( !wxDir::Exists(fn.GetFullPath()) ||
          !wxDir::GetAllFiles(fn.GetFullPath(),strings,wxT("*.xpm")) )
     {
     if ( !wxDir::Exists(fn.GetFullPath()) ||
          !wxDir::GetAllFiles(fn.GetFullPath(),strings,wxT("*.xpm")) )
     {
+        // Try ../../samples/widgets/icons
         fn.RemoveLastDir();
         fn.RemoveLastDir();
         fn.AppendDir(wxT("icons"));
         fn.RemoveLastDir();
         fn.RemoveLastDir();
         fn.AppendDir(wxT("icons"));
@@ -641,7 +698,7 @@ void BitmapComboBoxWidgetsPage::LoadWidgetImages( wxArrayString* strings, wxImag
     for ( i=0; i<strings->size(); i++ )
     {
         fn.SetFullName((*strings)[i]);
     for ( i=0; i<strings->size(); i++ )
     {
         fn.SetFullName((*strings)[i]);
-        wxString name =fn.GetName();
+        wxString name = fn.GetName();
 
         // Handle few exceptions
         if ( name == wxT("bmpbtn") )
 
         // Handle few exceptions
         if ( name == wxT("bmpbtn") )
@@ -663,6 +720,11 @@ void BitmapComboBoxWidgetsPage::LoadWidgetImages( wxArrayString* strings, wxImag
 #endif
             images->Add(bmp);
             (*strings)[i] = name;
 #endif
             images->Add(bmp);
             (*strings)[i] = name;
+
+            // if the combobox is empty, use as bitmap size of the image list
+            // the size of the first valid image loaded
+            if (foundSize == wxDefaultSize)
+                foundSize = bmp.GetSize();
         }
     }
 
         }
     }
 
@@ -842,7 +904,8 @@ wxBitmap BitmapComboBoxWidgetsPage::QueryBitmap(wxString* pStr)
         bitmap = LoadBitmap(filepath);
     }
 
         bitmap = LoadBitmap(filepath);
     }
 
-    wxLogDebug(wxT("%i, %i"),bitmap.GetWidth(), bitmap.GetHeight());
+    if (bitmap.IsOk())
+        wxLogDebug(wxT("%i, %i"),bitmap.GetWidth(), bitmap.GetHeight());
 
     ::wxSetCursor( *wxSTANDARD_CURSOR );
 
 
     ::wxSetCursor( *wxSTANDARD_CURSOR );