]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/combo/combo.cpp
miscellaneous wxFont enhancements (patch 1496606):
[wxWidgets.git] / samples / combo / combo.cpp
index 7d96e34276de33f6cc4e042542291f87f2571b59..43e95ff6336c4e38df9fc20e6aa80646bf08accd 100644 (file)
@@ -1,6 +1,6 @@
 /////////////////////////////////////////////////////////////////////////////
 // Name:        combo.cpp
-// Purpose:     wxComboControl sample
+// Purpose:     wxComboCtrl sample
 // Author:      Jaakko Salli
 // Modified by:
 // Created:     Apr-30-2006
@@ -30,8 +30,8 @@
     #include "wx/wx.h"
 #endif
 
-#if !wxUSE_COMBOCONTROL
-    #error "Please set wxUSE_COMBOCONTROL to 1 and rebuild the library."
+#if !wxUSE_COMBOCTRL
+    #error "Please set wxUSE_COMBOCTRL to 1 and rebuild the library."
 #endif
 
 #include "wx/image.h"
@@ -78,7 +78,7 @@ public:
     void OnQuit(wxCommandEvent& event);
     void OnAbout(wxCommandEvent& event);
 
-    // log wxComboControl events
+    // log wxComboCtrl events
     void OnComboBoxUpdate( wxCommandEvent& event );
 
 protected:
@@ -140,7 +140,7 @@ IMPLEMENT_APP(MyApp)
 bool MyApp::OnInit()
 {
     // create the main application window
-    MyFrame *frame = new MyFrame(_T("wxComboControl Sample"));
+    MyFrame *frame = new MyFrame(_T("wxComboCtrl Sample"));
 
     // and show it (the frames, unlike simple controls, are not shown when
     // created initially)
@@ -163,12 +163,19 @@ class ListViewComboPopup : public wxListView, public wxComboPopup
 {
 public:
 
-    ListViewComboPopup(wxComboControlBase* combo)
+/*
+    ListViewComboPopup(wxComboCtrlBase* combo)
         : wxListView(), wxComboPopup(combo)
     {
         m_value = -1;
         m_itemHere = -1; // hot item in list
     }
+*/
+    virtual void Init()
+    {
+        m_value = -1;
+        m_itemHere = -1; // hot item in list
+    }
 
     virtual bool Create( wxWindow* parent )
     {
@@ -258,10 +265,16 @@ class TreeCtrlComboPopup : public wxTreeCtrl, public wxComboPopup
 {
 public:
 
-    TreeCtrlComboPopup(wxComboControlBase* combo)
+/*
+    TreeCtrlComboPopup(wxComboCtrlBase* combo)
         : wxTreeCtrl(), wxComboPopup(combo)
     {
     }
+*/
+
+    virtual void Init()
+    {
+    }
 
     virtual bool Create( wxWindow* parent )
     {
@@ -383,7 +396,7 @@ END_EVENT_TABLE()
 // ----------------------------------------------------------------------------
 // wxOwnerDrawnComboBox with custom paint list items
 // ----------------------------------------------------------------------------
-
+/*
 class wxPenStyleComboBox : public wxOwnerDrawnComboBox
 {
 public:
@@ -422,7 +435,7 @@ public:
         // Get text colour as pen colour
         dc.SetPen ( pen );
 
-        if ( !(flags & wxCC_PAINTING_CONTROL) )
+        if ( !(flags & wxCP_PAINTING_CONTROL) )
         {
             dc.DrawText(GetString( item ),
                         r.x + 3,
@@ -430,31 +443,90 @@ public:
                        );
 
             dc.DrawLine( r.x+5, r.y+((r.height/4)*3), r.x+r.width - 5, r.y+((r.height/4)*3) );
+        }
+        else
+        {
+            dc.DrawLine( r.x+5, r.y+r.height/2, r.x+r.width - 5, r.y+r.height/2 );
+        }
+
+        return true;
+    }
+
+    virtual wxCoord OnMeasureListItem( int WXUNUSED(item) )
+    {
+        return 24;
+    }
+
+    virtual wxCoord OnMeasureListItemWidth( int WXUNUSED(item) )
+    {
+        return -1; // default - will be measured from text width
+    }
 
-            /*
-            dc.SetBrush( *wxTRANSPARENT_BRUSH );
-            dc.DrawRectangle( r );
+};
+*/
+
+class wxPenStylePopup : public wxVListBoxComboPopup
+{
+public:
+    virtual void OnDrawItem( wxDC& dc, const wxRect& rect, int item, int flags ) const
+    {
+        if ( item == wxNOT_FOUND )
+            return;
 
+        wxRect r(rect);
+        r.Deflate(3);
+        r.height -= 2;
+
+        int pen_style = wxSOLID;
+        if ( item == 1 )
+            pen_style = wxTRANSPARENT;
+        else if ( item == 2 )
+            pen_style = wxDOT;
+        else if ( item == 3 )
+            pen_style = wxLONG_DASH;
+        else if ( item == 4 )
+            pen_style = wxSHORT_DASH;
+        else if ( item == 5 )
+            pen_style = wxDOT_DASH;
+        else if ( item == 6 )
+            pen_style = wxBDIAGONAL_HATCH;
+        else if ( item == 7 )
+            pen_style = wxCROSSDIAG_HATCH;
+        else if ( item == 8 )
+            pen_style = wxFDIAGONAL_HATCH;
+        else if ( item == 9 )
+            pen_style = wxCROSS_HATCH;
+        else if ( item == 10 )
+            pen_style = wxHORIZONTAL_HATCH;
+        else if ( item == 11 )
+            pen_style = wxVERTICAL_HATCH;
+
+        wxPen pen( dc.GetTextForeground(), 3, pen_style );
+
+        // Get text colour as pen colour
+        dc.SetPen ( pen );
+
+        if ( !(flags & wxCP_PAINTING_CONTROL) )
+        {
             dc.DrawText(GetString( item ),
                         r.x + 3,
-                        (r.y + 0) + ( (r.height) - dc.GetCharHeight() )/2
+                        (r.y + 0) + ( (r.height/2) - dc.GetCharHeight() )/2
                        );
-            */
+
+            dc.DrawLine( r.x+5, r.y+((r.height/4)*3), r.x+r.width - 5, r.y+((r.height/4)*3) );
         }
         else
         {
             dc.DrawLine( r.x+5, r.y+r.height/2, r.x+r.width - 5, r.y+r.height/2 );
         }
-
-        return true;
     }
 
-    virtual wxCoord OnMeasureListItem( int WXUNUSED(item) )
+    virtual wxCoord OnMeasureItem( size_t WXUNUSED(item) ) const
     {
         return 24;
     }
 
-    virtual wxCoord OnMeasureListItemWidth( int WXUNUSED(item) )
+    virtual wxCoord OnMeasureItemWidth( size_t WXUNUSED(item) ) const
     {
         return -1; // default - will be measured from text width
     }
@@ -462,13 +534,13 @@ public:
 };
 
 // ----------------------------------------------------------------------------
-// wxComboControl with entirely custom button action (opens file dialog)
+// wxComboCtrl with entirely custom button action (opens file dialog)
 // ----------------------------------------------------------------------------
 
-class wxFileSelectorCombo : public wxComboControl
+class wxFileSelectorCombo : public wxComboCtrl
 {
 public:
-    wxFileSelectorCombo() : wxComboControl() { Init(); }
+    wxFileSelectorCombo() : wxComboCtrl() { Init(); }
 
     wxFileSelectorCombo(wxWindow *parent,
                         wxWindowID id = wxID_ANY,
@@ -478,7 +550,7 @@ public:
                         long style = 0,
                         const wxValidator& validator = wxDefaultValidator,
                         const wxString& name = wxComboBoxNameStr)
-        : wxComboControl()
+        : wxComboCtrl()
     {
         Init();
         Create(parent,id,value,
@@ -525,7 +597,7 @@ public:
                          wxEmptyString,
                          GetValue(),
                          wxT("All files (*.*)|*.*"),
-                         wxOPEN);
+                         wxFD_OPEN);
 
         if ( dlg.ShowModal() == wxID_OK )
         {
@@ -595,13 +667,13 @@ MyFrame::MyFrame(const wxString& title)
 
 
     // Make sure GetFeatures is implemented
-    int features = wxComboControl::GetFeatures();
-    wxLogDebug(wxT("wxComboControl features: 0x%X (all features: 0x%X)"),
-               features,wxComboControlFeatures::All);
+    int features = wxComboCtrl::GetFeatures();
+    wxLogDebug(wxT("wxComboCtrl features: 0x%X (all features: 0x%X)"),
+               features,wxComboCtrlFeatures::All);
 
 
     wxComboBox* cb;
-    wxComboControl* cc;
+    wxComboCtrl* cc;
     wxGenericComboControl* gcc;
     wxOwnerDrawnComboBox* odc;
 
@@ -634,10 +706,10 @@ MyFrame::MyFrame(const wxString& title)
                      wxALIGN_CENTER_VERTICAL|wxRIGHT|wxEXPAND, border );
 
     odc = new wxOwnerDrawnComboBox(panel,wxID_ANY,wxEmptyString,
-                                     wxDefaultPosition, wxDefaultSize,
-                                     arrItems,
-                                     wxCB_SORT // wxNO_BORDER|wxCB_READONLY
-                                     );
+                                   wxDefaultPosition, wxDefaultSize,
+                                   arrItems,
+                                   wxCB_SORT // wxNO_BORDER|wxCB_READONLY
+                                  );
 
     odc->Append(wxT("H - Appended Item")); // test sorting in append
 
@@ -651,12 +723,13 @@ MyFrame::MyFrame(const wxString& title)
                      wxALIGN_CENTER_VERTICAL|wxRIGHT, border );
 
     odc = new wxOwnerDrawnComboBox(panel,wxID_ANY,wxEmptyString,
-                                     wxDefaultPosition, wxDefaultSize,
-                                     arrItems,
-                                     wxCB_SORT|wxCB_READONLY // wxNO_BORDER|wxCB_READONLY
-                                     );
+                                   wxDefaultPosition, wxDefaultSize,
+                                   arrItems,
+                                   wxCB_SORT|wxCB_READONLY // wxNO_BORDER|wxCB_READONLY
+                                  );
 
     odc->SetValue(wxT("Dot Dash"));
+    odc->SetText(wxT("Dot Dash (Testing SetText)"));
 
     groupSizer->Add( odc, 1, wxALIGN_CENTER_VERTICAL|wxEXPAND|wxALL, border );
 
@@ -751,12 +824,13 @@ MyFrame::MyFrame(const wxString& title)
     // When defining derivative class for callbacks, we need
     // to use two-stage creation (or redefine the common wx
     // constructor).
-    odc = new wxPenStyleComboBox();
-    odc->Create(panel,wxID_ANY,wxEmptyString,
-                wxDefaultPosition, wxDefaultSize,
-                arrItems,
-                wxCB_READONLY //wxNO_BORDER | wxCB_READONLY
-               );
+    odc = new wxOwnerDrawnComboBox(panel,wxID_ANY,wxEmptyString,
+                                   wxDefaultPosition, wxDefaultSize,
+                                   arrItems,
+                                   wxCB_READONLY //wxNO_BORDER | wxCB_READONLY
+                                  );
+
+    odc->SetPopupControl( new wxPenStylePopup() );
 
     //m_odc->SetCustomPaintWidth( 60 );
     odc->SetSelection(0);
@@ -772,23 +846,23 @@ MyFrame::MyFrame(const wxString& title)
 
 
     //
-    // List View wxComboControl
+    // List View wxComboCtrl
     //
 
     rowSizer = new wxBoxSizer ( wxHORIZONTAL );
-    rowSizer->Add( new wxStaticText(panel,wxID_ANY,wxT("List View wxComboControl:")), 1,
+    rowSizer->Add( new wxStaticText(panel,wxID_ANY,wxT("List View wxComboCtrl:")), 1,
                    wxALIGN_CENTER_VERTICAL|wxRIGHT, 4 );
     rowSizer->Add( new wxStaticText(panel,wxID_ANY,wxT("Tree Ctrl wxGenericComboControl:")), 1,
                    wxALIGN_CENTER_VERTICAL|wxRIGHT, 4 );
     colSizer->Add( rowSizer, 0, wxEXPAND|wxALL, 5 );
 
     rowSizer = new wxBoxSizer ( wxHORIZONTAL );
-    cc = new wxComboControl(panel,2,wxEmptyString,
+    cc = new wxComboCtrl(panel,2,wxEmptyString,
                             wxDefaultPosition, wxDefaultSize);
 
     cc->SetPopupMinWidth(300);
 
-    ListViewComboPopup* iface = new ListViewComboPopup(cc);
+    ListViewComboPopup* iface = new ListViewComboPopup();
     cc->SetPopupControl(iface);
 
     iface->AddSelection( wxT("Cabbage") );
@@ -814,7 +888,7 @@ MyFrame::MyFrame(const wxString& title)
 
 
     //
-    // Tree Ctrl wxComboControl
+    // Tree Ctrl wxComboCtrl
     //
 
     // Note that we test that wxGenericComboControl works
@@ -823,7 +897,7 @@ MyFrame::MyFrame(const wxString& title)
 
     // Set popup interface right away, otherwise some of the calls
     // below may fail
-    TreeCtrlComboPopup* tcPopup = new TreeCtrlComboPopup(gcc);
+    TreeCtrlComboPopup* tcPopup = new TreeCtrlComboPopup();
     gcc->SetPopupControl(tcPopup);
 
     // Add items using wxTreeCtrl methods directly
@@ -915,11 +989,11 @@ MyFrame::MyFrame(const wxString& title)
 
 
     //
-    // wxComboControl with totally custom button action (open file dialog)
+    // wxComboCtrl with totally custom button action (open file dialog)
     //
     rowSizer = new wxBoxSizer ( wxHORIZONTAL );
     rowSizer->Add( new wxStaticText(panel,wxID_ANY,
-                        wxT("wxComboControl with custom button action:")), 1,
+                        wxT("wxComboCtrl with custom button action:")), 1,
                    wxALIGN_CENTER_VERTICAL|wxRIGHT, 4 );
 
 
@@ -979,12 +1053,12 @@ void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
     wxMessageBox(wxString::Format(
                     _T("Welcome to %s!\n")
                     _T("\n")
-                    _T("This is the wxWidgets wxComboControl sample\n")
+                    _T("This is the wxWidgets wxComboCtrl sample\n")
                     _T("running under %s."),
                     wxVERSION_STRING,
                     wxGetOsDescription().c_str()
                  ),
-                 _T("About wxComboControl sample"),
+                 _T("About wxComboCtrl sample"),
                  wxOK | wxICON_INFORMATION,
                  this);
 }