1 /////////////////////////////////////////////////////////////////////////////
2 // Program: wxWidgets Widgets Sample
4 // Purpose: Part of the widgets sample showing wxEditableListbox
5 // Author: Francesco Montorsi
7 // Copyright: (c) 2009 Francesco Montorsi
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // for compilers that support precompilation, includes "wx/wx.h".
20 #include "wx/wxprec.h"
26 #if wxUSE_EDITABLELISTBOX
28 // for all others, include the necessary headers
32 #include "wx/bitmap.h"
33 #include "wx/button.h"
34 #include "wx/checkbox.h"
35 #include "wx/combobox.h"
36 #include "wx/listbox.h"
37 #include "wx/radiobox.h"
38 #include "wx/statbox.h"
39 #include "wx/textctrl.h"
43 #include "wx/editlbox.h"
44 #include "wx/listctrl.h"
46 #include "itemcontainer.h"
49 #include "icons/listbox.xpm"
51 // ----------------------------------------------------------------------------
53 // ----------------------------------------------------------------------------
58 EditableListboxPage_Reset
= wxID_HIGHEST
,
59 EditableListboxPage_Listbox
,
60 EditableListboxPage_ContainerTests
63 // ----------------------------------------------------------------------------
64 // EditableListboxWidgetsPage
65 // ----------------------------------------------------------------------------
67 class EditableListboxWidgetsPage
: public WidgetsPage
70 EditableListboxWidgetsPage(WidgetsBookCtrl
*book
, wxImageList
*imaglist
);
72 virtual wxControl
*GetWidget() const { return m_lbox
->GetListCtrl(); }
73 virtual void RecreateWidget() { CreateLbox(); }
75 // lazy creation of the content
76 virtual void CreateContent();
80 void OnButtonReset(wxCommandEvent
& event
);
81 void OnCheckBox(wxCommandEvent
& event
);
83 // reset the listbox parameters
86 // (re)create the listbox
90 wxCheckBox
*m_chkAllowNew
,
101 DECLARE_EVENT_TABLE()
102 DECLARE_WIDGETS_PAGE(EditableListboxWidgetsPage
)
105 // ----------------------------------------------------------------------------
107 // ----------------------------------------------------------------------------
109 BEGIN_EVENT_TABLE(EditableListboxWidgetsPage
, WidgetsPage
)
110 EVT_BUTTON(EditableListboxPage_Reset
, EditableListboxWidgetsPage::OnButtonReset
)
111 EVT_CHECKBOX(wxID_ANY
, EditableListboxWidgetsPage::OnCheckBox
)
114 // ============================================================================
116 // ============================================================================
118 IMPLEMENT_WIDGETS_PAGE(EditableListboxWidgetsPage
, wxT("EditableListbox"), GENERIC_CTRLS
);
120 EditableListboxWidgetsPage::EditableListboxWidgetsPage(WidgetsBookCtrl
*book
,
121 wxImageList
*imaglist
)
122 : WidgetsPage(book
, imaglist
, listbox_xpm
)
127 void EditableListboxWidgetsPage::CreateContent()
130 What we create here is a frame having 2 panes: style pane is the
131 leftmost one and the pane containing the listbox itself to the right
133 wxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
136 wxStaticBox
*box
= new wxStaticBox(this, wxID_ANY
,
137 wxT("&Set listbox parameters"));
138 wxSizer
*sizerLeft
= new wxStaticBoxSizer(box
, wxVERTICAL
);
140 m_chkAllowNew
= CreateCheckBoxAndAddToSizer(sizerLeft
, wxT("Allow new items"));
141 m_chkAllowEdit
= CreateCheckBoxAndAddToSizer(sizerLeft
, wxT("Allow editing items"));
142 m_chkAllowDelete
= CreateCheckBoxAndAddToSizer(sizerLeft
, wxT("Allow deleting items"));
143 m_chkAllowNoReorder
= CreateCheckBoxAndAddToSizer(sizerLeft
, wxT("Block user reordering"));
145 wxButton
*btn
= new wxButton(this, EditableListboxPage_Reset
, wxT("&Reset"));
146 sizerLeft
->Add(btn
, 0, wxALIGN_CENTRE_HORIZONTAL
| wxALL
, 15);
149 wxSizer
*sizerRight
= new wxBoxSizer(wxVERTICAL
);
150 m_lbox
= new wxEditableListBox(this, EditableListboxPage_Listbox
,
151 _("Match these wildcards:"),
152 wxDefaultPosition
, wxDefaultSize
, 0);
153 sizerRight
->Add(m_lbox
, 1, wxGROW
| wxALL
, 5);
154 sizerRight
->SetMinSize(150, 0);
155 m_sizerLbox
= sizerRight
; // save it to modify it later
157 // the 3 panes panes compose the window
158 sizerTop
->Add(sizerLeft
, 0, wxGROW
| (wxALL
& ~wxLEFT
), 10);
159 sizerTop
->Add(sizerRight
, 1, wxGROW
| (wxALL
& ~wxRIGHT
), 10);
161 // final initializations
167 // ----------------------------------------------------------------------------
169 // ----------------------------------------------------------------------------
171 void EditableListboxWidgetsPage::Reset()
173 m_chkAllowNew
->SetValue(false);
174 m_chkAllowEdit
->SetValue(false);
175 m_chkAllowDelete
->SetValue(false);
176 m_chkAllowNoReorder
->SetValue(false);
179 void EditableListboxWidgetsPage::CreateLbox()
183 if ( m_chkAllowNew
->GetValue() )
184 flags
|= wxEL_ALLOW_NEW
;
185 if ( m_chkAllowEdit
->GetValue() )
186 flags
|= wxEL_ALLOW_EDIT
;
187 if ( m_chkAllowDelete
->GetValue() )
188 flags
|= wxEL_ALLOW_DELETE
;
189 if ( m_chkAllowNoReorder
->GetValue() )
190 flags
|= wxEL_NO_REORDER
;
195 m_lbox
->GetStrings(items
);
196 m_sizerLbox
->Detach( m_lbox
);
200 m_lbox
= new wxEditableListBox(this, EditableListboxPage_Listbox
,
201 _("Match these wildcards:"),
202 wxDefaultPosition
, wxDefaultSize
,
205 m_lbox
->SetStrings(items
);
206 m_sizerLbox
->Add(m_lbox
, 1, wxGROW
| wxALL
, 5);
207 m_sizerLbox
->Layout();
210 // ----------------------------------------------------------------------------
212 // ----------------------------------------------------------------------------
214 void EditableListboxWidgetsPage::OnButtonReset(wxCommandEvent
& WXUNUSED(event
))
221 void EditableListboxWidgetsPage::OnCheckBox(wxCommandEvent
& WXUNUSED(event
))
226 #endif // wxUSE_EDITABLELISTBOX