]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/widgets/bmpcombobox.cpp
return 0 (meaning the file is not seekable, as the docs now explain) instead of 4KB...
[wxWidgets.git] / samples / widgets / bmpcombobox.cpp
index 162ba73421c700c19a8b7684c1b3ea0f7e197ff4..f5e73f7331aaf8c79cdcae85533068c4bbb96208 100644 (file)
@@ -87,6 +87,13 @@ enum
     BitmapComboBoxPage_ContainerTests
 };
 
+// kinds of comboboxes
+enum
+{
+    ComboKind_Default,
+    ComboKind_Simple,
+    ComboKind_DropDown
+};
 
 // ----------------------------------------------------------------------------
 // BitmapComboBoxWidgetsPage
@@ -145,7 +152,6 @@ protected:
 
     // helpers for creating bitmaps
     wxBitmap CreateBitmap(const wxColour& colour);
-    wxBitmap CreateRandomBitmap(wxString* pStr);
     wxBitmap LoadBitmap(const wxString& filepath);
     wxBitmap QueryBitmap(wxString* pStr);
 
@@ -162,6 +168,9 @@ protected:
     // the controls
     // ------------
 
+    // the sel mode radiobox
+    wxRadioBox *m_radioKind;
+
     // the checkboxes for styles
     wxCheckBox *m_chkSort,
                *m_chkReadonly;
@@ -228,10 +237,14 @@ END_EVENT_TABLE()
 // 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"),
-                       GENERIC_CTRLS | WITH_ITEMS_CTRLS | COMBO_CTRLS
+                       NATIVE_OR_GENERIC_CTRLS | WITH_ITEMS_CTRLS | COMBO_CTRLS
                        );
 
 
@@ -241,10 +254,15 @@ BitmapComboBoxWidgetsPage::BitmapComboBoxWidgetsPage(WidgetsBookCtrl *book,
 {
     // 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
@@ -274,7 +292,6 @@ void BitmapComboBoxWidgetsPage::CreateContent()
        miscellaneous combobox operations and the pane containing the combobox
        itself to the right
     */
-    //wxTextCtrl *text;
     wxSizer *sizerRow;
 
     wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
@@ -284,6 +301,20 @@ void BitmapComboBoxWidgetsPage::CreateContent()
     // 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"));
@@ -293,6 +324,7 @@ void BitmapComboBoxWidgetsPage::CreateContent()
     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"));
@@ -398,6 +430,24 @@ void BitmapComboBoxWidgetsPage::CreateCombo()
     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 )
@@ -514,7 +564,8 @@ void BitmapComboBoxWidgetsPage::OnButtonInsert(wxCommandEvent& WXUNUSED(event))
 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);
@@ -553,13 +604,22 @@ void BitmapComboBoxWidgetsPage::OnButtonAddSeveral(wxCommandEvent& WXUNUSED(even
 
 void BitmapComboBoxWidgetsPage::OnButtonAddSeveralWithImages(wxCommandEvent& WXUNUSED(event))
 {
-    int i;
+    static const struct TestEntry
+    {
+        const char *text;
+        unsigned long rgb;
+    } s_entries[] =
+    {
+        { "Red circle",     0x0000ff },
+        { "Blue circle",    0xff0000 },
+        { "Green circle",   0x00ff00 },
+        { "Black circle",   0x000000 },
+    };
 
-    for ( i=0; i<4; i++ )
+    for ( unsigned i = 0; i < WXSIZEOF(s_entries); i++ )
     {
-        wxString s;
-        wxBitmap bmp = CreateRandomBitmap(&s);
-        m_combobox->Append(s, bmp);
+        const TestEntry& e = s_entries[i];
+        m_combobox->Append(e.text, CreateBitmap(wxColour(e.rgb)));
     }
 }
 
@@ -870,47 +930,4 @@ wxBitmap BitmapComboBoxWidgetsPage::CreateBitmap(const wxColour& colour)
     return bmp;
 }
 
-wxBitmap BitmapComboBoxWidgetsPage::CreateRandomBitmap( wxString* pStr )
-{
-    int i = rand() % 6;
-    const wxChar* str = wxT("");
-    wxBitmap bmp;
-
-    if ( i == 0 )
-    {
-        str = wxT("Red Circle");
-        bmp = CreateBitmap( *wxRED );
-    }
-    else if ( i == 1 )
-    {
-        str = wxT("Green Circle");
-        bmp = CreateBitmap( *wxGREEN );
-    }
-    else if ( i == 2 )
-    {
-        str = wxT("Blue Circle");
-        bmp = CreateBitmap( *wxBLUE );
-    }
-    else if ( i == 3 )
-    {
-        str = wxT("Black Circle");
-        bmp = CreateBitmap( *wxBLACK );
-    }
-    else if ( i == 4 )
-    {
-        str = wxT("Cyan Circle");
-        bmp = CreateBitmap( *wxCYAN );
-    }
-    else if ( i == 5 )
-    {
-        str = wxT("Light Grey Circle");
-        bmp = CreateBitmap( *wxLIGHT_GREY );
-    }
-
-    if ( pStr )
-        *pStr = str;
-
-    return bmp;
-}
-
-#endif //wxUSE_BITMAPCOMBOBOX
+#endif // wxUSE_BITMAPCOMBOBOX