2009-02-07 19:47:04 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Program: wxWidgets Widgets Sample
|
|
|
|
// Name: editlbox.cpp
|
|
|
|
// Purpose: Part of the widgets sample showing wxEditableListbox
|
|
|
|
// Author: Francesco Montorsi
|
|
|
|
// Created: 8/2/2009
|
|
|
|
// Copyright: (c) 2009 Francesco Montorsi
|
2010-07-13 09:29:13 -04:00
|
|
|
// Licence: wxWindows licence
|
2009-02-07 19:47:04 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// declarations
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// for compilers that support precompilation, includes "wx/wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
|
|
|
|
#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);
|
|
|
|
|
2015-07-31 11:53:55 -04:00
|
|
|
virtual wxWindow *GetWidget() const wxOVERRIDE { return m_lbox->GetListCtrl(); }
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual void RecreateWidget() wxOVERRIDE { CreateLbox(); }
|
2009-02-07 19:47:04 -05:00
|
|
|
|
|
|
|
// lazy creation of the content
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual void CreateContent() wxOVERRIDE;
|
2009-02-07 19:47:04 -05:00
|
|
|
|
|
|
|
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:
|
2014-03-30 03:07:55 -04:00
|
|
|
wxDECLARE_EVENT_TABLE();
|
2009-02-07 19:47:04 -05:00
|
|
|
DECLARE_WIDGETS_PAGE(EditableListboxWidgetsPage)
|
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// event tables
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2014-03-30 03:07:55 -04:00
|
|
|
wxBEGIN_EVENT_TABLE(EditableListboxWidgetsPage, WidgetsPage)
|
2009-02-07 19:47:04 -05:00
|
|
|
EVT_BUTTON(EditableListboxPage_Reset, EditableListboxWidgetsPage::OnButtonReset)
|
|
|
|
EVT_CHECKBOX(wxID_ANY, EditableListboxWidgetsPage::OnCheckBox)
|
2014-03-30 03:07:55 -04:00
|
|
|
wxEND_EVENT_TABLE()
|
2009-02-07 19:47:04 -05:00
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// implementation
|
|
|
|
// ============================================================================
|
|
|
|
|
2018-09-28 21:45:15 -04:00
|
|
|
IMPLEMENT_WIDGETS_PAGE(EditableListboxWidgetsPage, "EditableListbox", GENERIC_CTRLS);
|
2009-02-07 19:47:04 -05:00
|
|
|
|
|
|
|
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,
|
2018-09-28 21:45:15 -04:00
|
|
|
"&Set listbox parameters");
|
2009-02-07 19:47:04 -05:00
|
|
|
wxSizer *sizerLeft = new wxStaticBoxSizer(box, wxVERTICAL);
|
|
|
|
|
2018-09-28 21:45:15 -04:00
|
|
|
m_chkAllowNew = CreateCheckBoxAndAddToSizer(sizerLeft, "Allow new items");
|
|
|
|
m_chkAllowEdit = CreateCheckBoxAndAddToSizer(sizerLeft, "Allow editing items");
|
|
|
|
m_chkAllowDelete = CreateCheckBoxAndAddToSizer(sizerLeft, "Allow deleting items");
|
|
|
|
m_chkAllowNoReorder = CreateCheckBoxAndAddToSizer(sizerLeft, "Block user reordering");
|
2009-02-07 19:47:04 -05:00
|
|
|
|
2018-09-28 21:45:15 -04:00
|
|
|
wxButton *btn = new wxButton(this, EditableListboxPage_Reset, "&Reset");
|
2009-02-07 19:47:04 -05:00
|
|
|
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()
|
|
|
|
{
|
2018-03-17 12:50:56 -04:00
|
|
|
long flags = GetAttrs().m_defaultFlags;
|
2009-02-07 19:47:04 -05:00
|
|
|
|
|
|
|
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
|