Add CombineURIs implementation for wxWebFileProtocolHandler. Update the IE backend...
[wxWidgets.git] / samples / widgets / editlbox.cpp
CommitLineData
27721528
FM
1/////////////////////////////////////////////////////////////////////////////
2// Program: wxWidgets Widgets Sample
3// Name: editlbox.cpp
4// Purpose: Part of the widgets sample showing wxEditableListbox
5// Author: Francesco Montorsi
6// Created: 8/2/2009
7// Id: $Id$
8// Copyright: (c) 2009 Francesco Montorsi
526954c5 9// Licence: wxWindows licence
27721528
FM
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20// for compilers that support precompilation, includes "wx/wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
24 #pragma hdrstop
25#endif
26
27#if wxUSE_EDITABLELISTBOX
28
29// for all others, include the necessary headers
30#ifndef WX_PRECOMP
31 #include "wx/log.h"
32
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"
41#endif
42
43#include "wx/sizer.h"
44#include "wx/editlbox.h"
45#include "wx/listctrl.h"
46
47#include "itemcontainer.h"
48#include "widgets.h"
49
50#include "icons/listbox.xpm"
51
52// ----------------------------------------------------------------------------
53// constants
54// ----------------------------------------------------------------------------
55
56// control ids
57enum
58{
59 EditableListboxPage_Reset = wxID_HIGHEST,
60 EditableListboxPage_Listbox,
61 EditableListboxPage_ContainerTests
62};
63
64// ----------------------------------------------------------------------------
65// EditableListboxWidgetsPage
66// ----------------------------------------------------------------------------
67
68class EditableListboxWidgetsPage : public WidgetsPage
69{
70public:
71 EditableListboxWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist);
72
73 virtual wxControl *GetWidget() const { return m_lbox->GetListCtrl(); }
74 virtual void RecreateWidget() { CreateLbox(); }
75
76 // lazy creation of the content
77 virtual void CreateContent();
78
79protected:
80 // event handlers
81 void OnButtonReset(wxCommandEvent& event);
82 void OnCheckBox(wxCommandEvent& event);
83
84 // reset the listbox parameters
85 void Reset();
86
87 // (re)create the listbox
88 void CreateLbox();
89
90 // the checkboxes
91 wxCheckBox *m_chkAllowNew,
92 *m_chkAllowEdit,
93 *m_chkAllowDelete,
94 *m_chkAllowNoReorder;
95
96 wxEditableListBox
97 *m_lbox;
98
99 wxSizer *m_sizerLbox;
100
101private:
102 DECLARE_EVENT_TABLE()
103 DECLARE_WIDGETS_PAGE(EditableListboxWidgetsPage)
104};
105
106// ----------------------------------------------------------------------------
107// event tables
108// ----------------------------------------------------------------------------
109
110BEGIN_EVENT_TABLE(EditableListboxWidgetsPage, WidgetsPage)
111 EVT_BUTTON(EditableListboxPage_Reset, EditableListboxWidgetsPage::OnButtonReset)
112 EVT_CHECKBOX(wxID_ANY, EditableListboxWidgetsPage::OnCheckBox)
113END_EVENT_TABLE()
114
115// ============================================================================
116// implementation
117// ============================================================================
118
9a83f860 119IMPLEMENT_WIDGETS_PAGE(EditableListboxWidgetsPage, wxT("EditableListbox"), GENERIC_CTRLS);
27721528
FM
120
121EditableListboxWidgetsPage::EditableListboxWidgetsPage(WidgetsBookCtrl *book,
122 wxImageList *imaglist)
123 : WidgetsPage(book, imaglist, listbox_xpm)
124{
125
126}
127
128void EditableListboxWidgetsPage::CreateContent()
129{
130 /*
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
133 */
134 wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
135
136 // left pane
137 wxStaticBox *box = new wxStaticBox(this, wxID_ANY,
9a83f860 138 wxT("&Set listbox parameters"));
27721528
FM
139 wxSizer *sizerLeft = new wxStaticBoxSizer(box, wxVERTICAL);
140
9a83f860
VZ
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"));
27721528 145
9a83f860 146 wxButton *btn = new wxButton(this, EditableListboxPage_Reset, wxT("&Reset"));
27721528
FM
147 sizerLeft->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15);
148
149 // right pane
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
157
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);
161
162 // final initializations
163 Reset();
164
165 SetSizer(sizerTop);
166}
167
168// ----------------------------------------------------------------------------
169// operations
170// ----------------------------------------------------------------------------
171
172void EditableListboxWidgetsPage::Reset()
173{
174 m_chkAllowNew->SetValue(false);
175 m_chkAllowEdit->SetValue(false);
176 m_chkAllowDelete->SetValue(false);
177 m_chkAllowNoReorder->SetValue(false);
178}
179
180void EditableListboxWidgetsPage::CreateLbox()
181{
182 int flags = 0;
183
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;
192
193 wxArrayString items;
194 if ( m_lbox )
195 {
196 m_lbox->GetStrings(items);
197 m_sizerLbox->Detach( m_lbox );
198 delete m_lbox;
199 }
200
201 m_lbox = new wxEditableListBox(this, EditableListboxPage_Listbox,
202 _("Match these wildcards:"),
203 wxDefaultPosition, wxDefaultSize,
204 flags);
205
206 m_lbox->SetStrings(items);
207 m_sizerLbox->Add(m_lbox, 1, wxGROW | wxALL, 5);
208 m_sizerLbox->Layout();
209}
210
211// ----------------------------------------------------------------------------
212// event handlers
213// ----------------------------------------------------------------------------
214
215void EditableListboxWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event))
216{
217 Reset();
218
219 CreateLbox();
220}
221
222void EditableListboxWidgetsPage::OnCheckBox(wxCommandEvent& WXUNUSED(event))
223{
224 CreateLbox();
225}
226
227#endif // wxUSE_EDITABLELISTBOX