merge wxEditableListBox sample in widgets sample (it was a 60-lines sample of a single control showing limited features)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58743 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -59,6 +59,7 @@ WIDGETS_OBJECTS = \
|
||||
widgets_datepick.o \
|
||||
widgets_dirctrl.o \
|
||||
widgets_dirpicker.o \
|
||||
widgets_editlbox.o \
|
||||
widgets_filectrl.o \
|
||||
widgets_filepicker.o \
|
||||
widgets_fontpicker.o \
|
||||
@@ -233,6 +234,9 @@ widgets_dirctrl.o: $(srcdir)/dirctrl.cpp
|
||||
widgets_dirpicker.o: $(srcdir)/dirpicker.cpp
|
||||
$(CXXC) -c -o $@ $(WIDGETS_CXXFLAGS) $(srcdir)/dirpicker.cpp
|
||||
|
||||
widgets_editlbox.o: $(srcdir)/editlbox.cpp
|
||||
$(CXXC) -c -o $@ $(WIDGETS_CXXFLAGS) $(srcdir)/editlbox.cpp
|
||||
|
||||
widgets_filectrl.o: $(srcdir)/filectrl.cpp
|
||||
$(CXXC) -c -o $@ $(WIDGETS_CXXFLAGS) $(srcdir)/filectrl.cpp
|
||||
|
||||
|
227
samples/widgets/editlbox.cpp
Normal file
227
samples/widgets/editlbox.cpp
Normal file
@@ -0,0 +1,227 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Program: wxWidgets Widgets Sample
|
||||
// Name: editlbox.cpp
|
||||
// Purpose: Part of the widgets sample showing wxEditableListbox
|
||||
// Author: Francesco Montorsi
|
||||
// Created: 8/2/2009
|
||||
// Id: $Id$
|
||||
// Copyright: (c) 2009 Francesco Montorsi
|
||||
// License: wxWindows license
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// for compilers that support precompilation, includes "wx/wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_EDITABLELISTBOX
|
||||
|
||||
// for all others, include the necessary headers
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/log.h"
|
||||
|
||||
#include "wx/bitmap.h"
|
||||
#include "wx/button.h"
|
||||
#include "wx/checkbox.h"
|
||||
#include "wx/combobox.h"
|
||||
#include "wx/listbox.h"
|
||||
#include "wx/radiobox.h"
|
||||
#include "wx/statbox.h"
|
||||
#include "wx/textctrl.h"
|
||||
#endif
|
||||
|
||||
#include "wx/sizer.h"
|
||||
#include "wx/editlbox.h"
|
||||
#include "wx/listctrl.h"
|
||||
|
||||
#include "itemcontainer.h"
|
||||
#include "widgets.h"
|
||||
|
||||
#include "icons/listbox.xpm"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// constants
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// control ids
|
||||
enum
|
||||
{
|
||||
EditableListboxPage_Reset = wxID_HIGHEST,
|
||||
EditableListboxPage_Listbox,
|
||||
EditableListboxPage_ContainerTests
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// EditableListboxWidgetsPage
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class EditableListboxWidgetsPage : public WidgetsPage
|
||||
{
|
||||
public:
|
||||
EditableListboxWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist);
|
||||
|
||||
virtual wxControl *GetWidget() const { return m_lbox->GetListCtrl(); }
|
||||
virtual void RecreateWidget() { CreateLbox(); }
|
||||
|
||||
// lazy creation of the content
|
||||
virtual void CreateContent();
|
||||
|
||||
protected:
|
||||
// event handlers
|
||||
void OnButtonReset(wxCommandEvent& event);
|
||||
void OnCheckBox(wxCommandEvent& event);
|
||||
|
||||
// reset the listbox parameters
|
||||
void Reset();
|
||||
|
||||
// (re)create the listbox
|
||||
void CreateLbox();
|
||||
|
||||
// the checkboxes
|
||||
wxCheckBox *m_chkAllowNew,
|
||||
*m_chkAllowEdit,
|
||||
*m_chkAllowDelete,
|
||||
*m_chkAllowNoReorder;
|
||||
|
||||
wxEditableListBox
|
||||
*m_lbox;
|
||||
|
||||
wxSizer *m_sizerLbox;
|
||||
|
||||
private:
|
||||
DECLARE_EVENT_TABLE()
|
||||
DECLARE_WIDGETS_PAGE(EditableListboxWidgetsPage)
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// event tables
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
BEGIN_EVENT_TABLE(EditableListboxWidgetsPage, WidgetsPage)
|
||||
EVT_BUTTON(EditableListboxPage_Reset, EditableListboxWidgetsPage::OnButtonReset)
|
||||
EVT_CHECKBOX(wxID_ANY, EditableListboxWidgetsPage::OnCheckBox)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
IMPLEMENT_WIDGETS_PAGE(EditableListboxWidgetsPage, _T("EditableListbox"), GENERIC_CTRLS);
|
||||
|
||||
EditableListboxWidgetsPage::EditableListboxWidgetsPage(WidgetsBookCtrl *book,
|
||||
wxImageList *imaglist)
|
||||
: WidgetsPage(book, imaglist, listbox_xpm)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void EditableListboxWidgetsPage::CreateContent()
|
||||
{
|
||||
/*
|
||||
What we create here is a frame having 2 panes: style pane is the
|
||||
leftmost one and the pane containing the listbox itself to the right
|
||||
*/
|
||||
wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
|
||||
|
||||
// left pane
|
||||
wxStaticBox *box = new wxStaticBox(this, wxID_ANY,
|
||||
_T("&Set listbox parameters"));
|
||||
wxSizer *sizerLeft = new wxStaticBoxSizer(box, wxVERTICAL);
|
||||
|
||||
m_chkAllowNew = CreateCheckBoxAndAddToSizer(sizerLeft, _T("Allow new items"));
|
||||
m_chkAllowEdit = CreateCheckBoxAndAddToSizer(sizerLeft, _T("Allow editing items"));
|
||||
m_chkAllowDelete = CreateCheckBoxAndAddToSizer(sizerLeft, _T("Allow deleting items"));
|
||||
m_chkAllowNoReorder = CreateCheckBoxAndAddToSizer(sizerLeft, _T("Block user reordering"));
|
||||
|
||||
wxButton *btn = new wxButton(this, EditableListboxPage_Reset, _T("&Reset"));
|
||||
sizerLeft->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15);
|
||||
|
||||
// right pane
|
||||
wxSizer *sizerRight = new wxBoxSizer(wxVERTICAL);
|
||||
m_lbox = new wxEditableListBox(this, EditableListboxPage_Listbox,
|
||||
_("Match these wildcards:"),
|
||||
wxDefaultPosition, wxDefaultSize, 0);
|
||||
sizerRight->Add(m_lbox, 1, wxGROW | wxALL, 5);
|
||||
sizerRight->SetMinSize(150, 0);
|
||||
m_sizerLbox = sizerRight; // save it to modify it later
|
||||
|
||||
// the 3 panes panes compose the window
|
||||
sizerTop->Add(sizerLeft, 0, wxGROW | (wxALL & ~wxLEFT), 10);
|
||||
sizerTop->Add(sizerRight, 1, wxGROW | (wxALL & ~wxRIGHT), 10);
|
||||
|
||||
// final initializations
|
||||
Reset();
|
||||
|
||||
SetSizer(sizerTop);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// operations
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void EditableListboxWidgetsPage::Reset()
|
||||
{
|
||||
m_chkAllowNew->SetValue(false);
|
||||
m_chkAllowEdit->SetValue(false);
|
||||
m_chkAllowDelete->SetValue(false);
|
||||
m_chkAllowNoReorder->SetValue(false);
|
||||
}
|
||||
|
||||
void EditableListboxWidgetsPage::CreateLbox()
|
||||
{
|
||||
int flags = 0;
|
||||
|
||||
if ( m_chkAllowNew->GetValue() )
|
||||
flags |= wxEL_ALLOW_NEW;
|
||||
if ( m_chkAllowEdit->GetValue() )
|
||||
flags |= wxEL_ALLOW_EDIT;
|
||||
if ( m_chkAllowDelete->GetValue() )
|
||||
flags |= wxEL_ALLOW_DELETE;
|
||||
if ( m_chkAllowNoReorder->GetValue() )
|
||||
flags |= wxEL_NO_REORDER;
|
||||
|
||||
wxArrayString items;
|
||||
if ( m_lbox )
|
||||
{
|
||||
m_lbox->GetStrings(items);
|
||||
m_sizerLbox->Detach( m_lbox );
|
||||
delete m_lbox;
|
||||
}
|
||||
|
||||
m_lbox = new wxEditableListBox(this, EditableListboxPage_Listbox,
|
||||
_("Match these wildcards:"),
|
||||
wxDefaultPosition, wxDefaultSize,
|
||||
flags);
|
||||
|
||||
m_lbox->SetStrings(items);
|
||||
m_sizerLbox->Add(m_lbox, 1, wxGROW | wxALL, 5);
|
||||
m_sizerLbox->Layout();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// event handlers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void EditableListboxWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
Reset();
|
||||
|
||||
CreateLbox();
|
||||
}
|
||||
|
||||
void EditableListboxWidgetsPage::OnCheckBox(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
CreateLbox();
|
||||
}
|
||||
|
||||
#endif // wxUSE_EDITABLELISTBOX
|
@@ -44,6 +44,7 @@ WIDGETS_OBJECTS = \
|
||||
$(OBJS)\widgets_datepick.obj \
|
||||
$(OBJS)\widgets_dirctrl.obj \
|
||||
$(OBJS)\widgets_dirpicker.obj \
|
||||
$(OBJS)\widgets_editlbox.obj \
|
||||
$(OBJS)\widgets_filectrl.obj \
|
||||
$(OBJS)\widgets_filepicker.obj \
|
||||
$(OBJS)\widgets_fontpicker.obj \
|
||||
@@ -290,6 +291,9 @@ $(OBJS)\widgets_dirctrl.obj: .\dirctrl.cpp
|
||||
$(OBJS)\widgets_dirpicker.obj: .\dirpicker.cpp
|
||||
$(CXX) -q -c -P -o$@ $(WIDGETS_CXXFLAGS) .\dirpicker.cpp
|
||||
|
||||
$(OBJS)\widgets_editlbox.obj: .\editlbox.cpp
|
||||
$(CXX) -q -c -P -o$@ $(WIDGETS_CXXFLAGS) .\editlbox.cpp
|
||||
|
||||
$(OBJS)\widgets_filectrl.obj: .\filectrl.cpp
|
||||
$(CXX) -q -c -P -o$@ $(WIDGETS_CXXFLAGS) .\filectrl.cpp
|
||||
|
||||
|
@@ -37,6 +37,7 @@ WIDGETS_OBJECTS = \
|
||||
$(OBJS)\widgets_datepick.o \
|
||||
$(OBJS)\widgets_dirctrl.o \
|
||||
$(OBJS)\widgets_dirpicker.o \
|
||||
$(OBJS)\widgets_editlbox.o \
|
||||
$(OBJS)\widgets_filectrl.o \
|
||||
$(OBJS)\widgets_filepicker.o \
|
||||
$(OBJS)\widgets_fontpicker.o \
|
||||
@@ -283,6 +284,9 @@ $(OBJS)\widgets_dirctrl.o: ./dirctrl.cpp
|
||||
$(OBJS)\widgets_dirpicker.o: ./dirpicker.cpp
|
||||
$(CXX) -c -o $@ $(WIDGETS_CXXFLAGS) $(CPPDEPS) $<
|
||||
|
||||
$(OBJS)\widgets_editlbox.o: ./editlbox.cpp
|
||||
$(CXX) -c -o $@ $(WIDGETS_CXXFLAGS) $(CPPDEPS) $<
|
||||
|
||||
$(OBJS)\widgets_filectrl.o: ./filectrl.cpp
|
||||
$(CXX) -c -o $@ $(WIDGETS_CXXFLAGS) $(CPPDEPS) $<
|
||||
|
||||
|
@@ -66,6 +66,7 @@ WIDGETS_OBJECTS = \
|
||||
widgets_datepick.o \
|
||||
widgets_dirctrl.o \
|
||||
widgets_dirpicker.o \
|
||||
widgets_editlbox.o \
|
||||
widgets_filectrl.o \
|
||||
widgets_filepicker.o \
|
||||
widgets_fontpicker.o \
|
||||
@@ -153,6 +154,9 @@ widgets_dirctrl.o: ./dirctrl.cpp
|
||||
widgets_dirpicker.o: ./dirpicker.cpp
|
||||
$(CXX) -c -o $@ $(WIDGETS_CXXFLAGS) $(CPPDEPS) $<
|
||||
|
||||
widgets_editlbox.o: ./editlbox.cpp
|
||||
$(CXX) -c -o $@ $(WIDGETS_CXXFLAGS) $(CPPDEPS) $<
|
||||
|
||||
widgets_filectrl.o: ./filectrl.cpp
|
||||
$(CXX) -c -o $@ $(WIDGETS_CXXFLAGS) $(CPPDEPS) $<
|
||||
|
||||
|
@@ -38,6 +38,7 @@ WIDGETS_OBJECTS = \
|
||||
$(OBJS)\widgets_datepick.obj \
|
||||
$(OBJS)\widgets_dirctrl.obj \
|
||||
$(OBJS)\widgets_dirpicker.obj \
|
||||
$(OBJS)\widgets_editlbox.obj \
|
||||
$(OBJS)\widgets_filectrl.obj \
|
||||
$(OBJS)\widgets_filepicker.obj \
|
||||
$(OBJS)\widgets_fontpicker.obj \
|
||||
@@ -366,6 +367,9 @@ $(OBJS)\widgets_dirctrl.obj: .\dirctrl.cpp
|
||||
$(OBJS)\widgets_dirpicker.obj: .\dirpicker.cpp
|
||||
$(CXX) /c /nologo /TP /Fo$@ $(WIDGETS_CXXFLAGS) .\dirpicker.cpp
|
||||
|
||||
$(OBJS)\widgets_editlbox.obj: .\editlbox.cpp
|
||||
$(CXX) /c /nologo /TP /Fo$@ $(WIDGETS_CXXFLAGS) .\editlbox.cpp
|
||||
|
||||
$(OBJS)\widgets_filectrl.obj: .\filectrl.cpp
|
||||
$(CXX) /c /nologo /TP /Fo$@ $(WIDGETS_CXXFLAGS) .\filectrl.cpp
|
||||
|
||||
|
@@ -241,6 +241,7 @@ WIDGETS_OBJECTS = &
|
||||
$(OBJS)\widgets_datepick.obj &
|
||||
$(OBJS)\widgets_dirctrl.obj &
|
||||
$(OBJS)\widgets_dirpicker.obj &
|
||||
$(OBJS)\widgets_editlbox.obj &
|
||||
$(OBJS)\widgets_filectrl.obj &
|
||||
$(OBJS)\widgets_filepicker.obj &
|
||||
$(OBJS)\widgets_fontpicker.obj &
|
||||
@@ -316,6 +317,9 @@ $(OBJS)\widgets_dirctrl.obj : .AUTODEPEND .\dirctrl.cpp
|
||||
$(OBJS)\widgets_dirpicker.obj : .AUTODEPEND .\dirpicker.cpp
|
||||
$(CXX) -bt=nt -zq -fo=$^@ $(WIDGETS_CXXFLAGS) $<
|
||||
|
||||
$(OBJS)\widgets_editlbox.obj : .AUTODEPEND .\editlbox.cpp
|
||||
$(CXX) -bt=nt -zq -fo=$^@ $(WIDGETS_CXXFLAGS) $<
|
||||
|
||||
$(OBJS)\widgets_filectrl.obj : .AUTODEPEND .\filectrl.cpp
|
||||
$(CXX) -bt=nt -zq -fo=$^@ $(WIDGETS_CXXFLAGS) $<
|
||||
|
||||
|
@@ -15,6 +15,7 @@
|
||||
datepick.cpp
|
||||
dirctrl.cpp
|
||||
dirpicker.cpp
|
||||
editlbox.cpp
|
||||
filectrl.cpp
|
||||
filepicker.cpp
|
||||
fontpicker.cpp
|
||||
|
@@ -288,6 +288,10 @@ SOURCE=.\dirpicker.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\editlbox.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\filectrl.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
@@ -552,6 +552,9 @@
|
||||
<File
|
||||
RelativePath=".\dirpicker.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\editlbox.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\filectrl.cpp">
|
||||
</File>
|
||||
|
@@ -823,6 +823,10 @@
|
||||
RelativePath=".\dirpicker.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\editlbox.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\filectrl.cpp"
|
||||
>
|
||||
|
@@ -795,6 +795,10 @@
|
||||
RelativePath=".\dirpicker.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\editlbox.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\filectrl.cpp"
|
||||
>
|
||||
|
Reference in New Issue
Block a user