/////////////////////////////////////////////////////////////////////////////
// Name: combo.cpp
-// Purpose: wxComboControl sample
+// Purpose: wxComboCtrl sample
// Author: Jaakko Salli
// Modified by:
// Created: Apr-30-2006
#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"
void OnQuit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
- // log wxComboControl events
+ // log wxComboCtrl events
void OnComboBoxUpdate( wxCommandEvent& event );
protected:
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)
{
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 )
{
{
public:
- TreeCtrlComboPopup(wxComboControlBase* combo)
+/*
+ TreeCtrlComboPopup(wxComboCtrlBase* combo)
: wxTreeCtrl(), wxComboPopup(combo)
{
}
+*/
+
+ virtual void Init()
+ {
+ }
virtual bool Create( wxWindow* parent )
{
// ----------------------------------------------------------------------------
// wxOwnerDrawnComboBox with custom paint list items
// ----------------------------------------------------------------------------
-
+/*
class wxPenStyleComboBox : public wxOwnerDrawnComboBox
{
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,
);
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
}
};
// ----------------------------------------------------------------------------
-// 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,
long style = 0,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxComboBoxNameStr)
- : wxComboControl()
+ : wxComboCtrl()
{
Init();
Create(parent,id,value,
wxEmptyString,
GetValue(),
wxT("All files (*.*)|*.*"),
- wxOPEN);
+ wxFD_OPEN);
if ( dlg.ShowModal() == wxID_OK )
{
// 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;
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
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 );
// 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);
//
- // 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") );
//
- // Tree Ctrl wxComboControl
+ // Tree Ctrl wxComboCtrl
//
// Note that we test that wxGenericComboControl works
// 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
//
- // 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 );
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);
}