1 /////////////////////////////////////////////////////////////////////////////
2 // Program: wxWidgets Widgets Sample
4 // Purpose: Part of the widgets sample showing wxEditableListbox
5 // Author: Francesco Montorsi
8 // Copyright: (c) 2009 Francesco Montorsi
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // for compilers that support precompilation, includes "wx/wx.h".
21 #include "wx/wxprec.h"
27 #if wxUSE_EDITABLELISTBOX
29 // for all others, include the necessary headers
33 #include "wx/bitmap.h"
34 #include "wx/button.h"
35 #include "wx/checkbox.h"
36 #include "wx/combobox.h"
37 #include "wx/listbox.h"
38 #include "wx/radiobox.h"
39 #include "wx/statbox.h"
40 #include "wx/textctrl.h"
44 #include "wx/editlbox.h"
45 #include "wx/listctrl.h"
47 #include "itemcontainer.h"
50 #include "icons/listbox.xpm"
52 // ----------------------------------------------------------------------------
54 // ----------------------------------------------------------------------------
59 EditableListboxPage_Reset
= wxID_HIGHEST
,
60 EditableListboxPage_Listbox
,
61 EditableListboxPage_ContainerTests
64 // ----------------------------------------------------------------------------
65 // EditableListboxWidgetsPage
66 // ----------------------------------------------------------------------------
68 class EditableListboxWidgetsPage
: public WidgetsPage
71 EditableListboxWidgetsPage(WidgetsBookCtrl
*book
, wxImageList
*imaglist
);
73 virtual wxControl
*GetWidget() const { return m_lbox
->GetListCtrl(); }
74 virtual void RecreateWidget() { CreateLbox(); }
76 // lazy creation of the content
77 virtual void CreateContent();
81 void OnButtonReset(wxCommandEvent
& event
);
82 void OnCheckBox(wxCommandEvent
& event
);
84 // reset the listbox parameters
87 // (re)create the listbox
91 wxCheckBox
*m_chkAllowNew
,
102 DECLARE_EVENT_TABLE()
103 DECLARE_WIDGETS_PAGE(EditableListboxWidgetsPage
)
106 // ----------------------------------------------------------------------------
108 // ----------------------------------------------------------------------------
110 BEGIN_EVENT_TABLE(EditableListboxWidgetsPage
, WidgetsPage
)
111 EVT_BUTTON(EditableListboxPage_Reset
, EditableListboxWidgetsPage::OnButtonReset
)
112 EVT_CHECKBOX(wxID_ANY
, EditableListboxWidgetsPage::OnCheckBox
)
115 // ============================================================================
117 // ============================================================================
119 IMPLEMENT_WIDGETS_PAGE(EditableListboxWidgetsPage
, wxT("EditableListbox"), GENERIC_CTRLS
);
121 EditableListboxWidgetsPage::EditableListboxWidgetsPage(WidgetsBookCtrl
*book
,
122 wxImageList
*imaglist
)
123 : WidgetsPage(book
, imaglist
, listbox_xpm
)
128 void EditableListboxWidgetsPage::CreateContent()
131 What we create here is a frame having 2 panes: style pane is the
132 leftmost one and the pane containing the listbox itself to the right
134 wxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
137 wxStaticBox
*box
= new wxStaticBox(this, wxID_ANY
,
138 wxT("&Set listbox parameters"));
139 wxSizer
*sizerLeft
= new wxStaticBoxSizer(box
, wxVERTICAL
);
141 m_chkAllowNew
= CreateCheckBoxAndAddToSizer(sizerLeft
, wxT("Allow new items"));
142 m_chkAllowEdit
= CreateCheckBoxAndAddToSizer(sizerLeft
, wxT("Allow editing items"));
143 m_chkAllowDelete
= CreateCheckBoxAndAddToSizer(sizerLeft
, wxT("Allow deleting items"));
144 m_chkAllowNoReorder
= CreateCheckBoxAndAddToSizer(sizerLeft
, wxT("Block user reordering"));
146 wxButton
*btn
= new wxButton(this, EditableListboxPage_Reset
, wxT("&Reset"));
147 sizerLeft
->Add(btn
, 0, wxALIGN_CENTRE_HORIZONTAL
| wxALL
, 15);
150 wxSizer
*sizerRight
= new wxBoxSizer(wxVERTICAL
);
151 m_lbox
= new wxEditableListBox(this, EditableListboxPage_Listbox
,
152 _("Match these wildcards:"),
153 wxDefaultPosition
, wxDefaultSize
, 0);
154 sizerRight
->Add(m_lbox
, 1, wxGROW
| wxALL
, 5);
155 sizerRight
->SetMinSize(150, 0);
156 m_sizerLbox
= sizerRight
; // save it to modify it later
158 // the 3 panes panes compose the window
159 sizerTop
->Add(sizerLeft
, 0, wxGROW
| (wxALL
& ~wxLEFT
), 10);
160 sizerTop
->Add(sizerRight
, 1, wxGROW
| (wxALL
& ~wxRIGHT
), 10);
162 // final initializations
168 // ----------------------------------------------------------------------------
170 // ----------------------------------------------------------------------------
172 void EditableListboxWidgetsPage::Reset()
174 m_chkAllowNew
->SetValue(false);
175 m_chkAllowEdit
->SetValue(false);
176 m_chkAllowDelete
->SetValue(false);
177 m_chkAllowNoReorder
->SetValue(false);
180 void EditableListboxWidgetsPage::CreateLbox()
184 if ( m_chkAllowNew
->GetValue() )
185 flags
|= wxEL_ALLOW_NEW
;
186 if ( m_chkAllowEdit
->GetValue() )
187 flags
|= wxEL_ALLOW_EDIT
;
188 if ( m_chkAllowDelete
->GetValue() )
189 flags
|= wxEL_ALLOW_DELETE
;
190 if ( m_chkAllowNoReorder
->GetValue() )
191 flags
|= wxEL_NO_REORDER
;
196 m_lbox
->GetStrings(items
);
197 m_sizerLbox
->Detach( m_lbox
);
201 m_lbox
= new wxEditableListBox(this, EditableListboxPage_Listbox
,
202 _("Match these wildcards:"),
203 wxDefaultPosition
, wxDefaultSize
,
206 m_lbox
->SetStrings(items
);
207 m_sizerLbox
->Add(m_lbox
, 1, wxGROW
| wxALL
, 5);
208 m_sizerLbox
->Layout();
211 // ----------------------------------------------------------------------------
213 // ----------------------------------------------------------------------------
215 void EditableListboxWidgetsPage::OnButtonReset(wxCommandEvent
& WXUNUSED(event
))
222 void EditableListboxWidgetsPage::OnCheckBox(wxCommandEvent
& WXUNUSED(event
))
227 #endif // wxUSE_EDITABLELISTBOX