wex  v20.04.0
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
wex::item Class Reference

Container class for using with item_dialog. More...

#include <wex/item.h>

Public Types

enum  type_t {
  BUTTON, CHECKBOX, CHECKLISTBOX_BIT, CHECKLISTBOX_BOOL,
  COLOURPICKERWIDGET, COMBOBOX, COMBOBOX_DIR, COMBOBOX_FILE,
  COMMANDLINKBUTTON, DIRPICKERCTRL, EMPTY, FILEPICKERCTRL,
  FONTPICKERCTRL, GRID, HYPERLINKCTRL, LISTVIEW,
  NOTEBOOK, NOTEBOOK_AUI, NOTEBOOK_CHOICE, NOTEBOOK_LIST,
  NOTEBOOK_SIMPLE, NOTEBOOK_TOOL, NOTEBOOK_TREE, NOTEBOOK_WEX,
  RADIOBOX, SLIDER, SPACER, SPINCTRL,
  SPINCTRLDOUBLE, STATICBOX, STATICLINE, STATICTEXT,
  STC, TEXTCTRL, TEXTCTRL_FLOAT, TEXTCTRL_INT,
  TOGGLEBUTTON, USER
}
 The item types supported. More...
 
enum  label_t { LABEL_NONE, LABEL_LEFT, LABEL_ABOVE }
 Label types supported. More...
 
typedef std::map< long, const std::string > choices_t
 Choices for radioboxes.
 
typedef std::set< std::string > choices_bool_t
 Choices for listboxes with toggle options.
 
typedef std::vector< group_t > notebook_t
 A notebook is a vector of groups.
 
typedef std::function< void(wxWindow *user, const std::any &value, bool save)> user_apply_t
 A function that you can provide to e.g. More...
 
typedef std::function< void(wxWindow *user, wxWindow *parent, bool readonly)> user_window_create_t
 A function that you can provide to specify what needs to be done for creating a user item.
 
typedef std::function< bool(wxWindow *user, bool save)> user_window_to_config_t
 A function that you can provide to specify what needs to be done of loading or saving a user item to the config.
 

Public Member Functions

 item ()
 Default constructor for an EMPTY item.
 
 item (int size)
 Constructor for a SPACER item. More...
 
 item (wxOrientation orientation)
 Constructor for a STATICLINE item. More...
 
 item (const std::string &label, const std::string &value=std::string(), type_t type=TEXTCTRL, const control_data &data=control_data(), label_t label_t=LABEL_LEFT, user_apply_t apply=nullptr)
 Constructor for several items. More...
 
 item (const std::string &label, int min, int max, const std::any &value=std::any(), type_t type=SPINCTRL, const control_data &data=control_data().window(window_data().style(wxSP_ARROW_KEYS)), user_apply_t apply=nullptr)
 Constructor for a SPINCTRL or a SLIDER item. More...
 
 item (const std::string &label, double min, double max, const std::any &value=std::any(), double inc=1, const control_data &data=control_data().window(window_data().style(wxSP_ARROW_KEYS)), user_apply_t apply=nullptr)
 Constructor for a SPINCTRLDOUBLE item. More...
 
 item (const choices_bool_t &choices, const control_data &data=control_data(), user_apply_t apply=nullptr)
 Constructor for a CHECKLISTBOX_BOOL item. More...
 
 item (const std::string &label, const notebook_t &v, type_t type=NOTEBOOK, int rows=0, int cols=1, const control_data &data=control_data(), label_t label_t=LABEL_NONE, wxImageList *imageList=nullptr)
 Constructor for a NOTEBOOK item, being a vector of a pair of pages with a vector of items. More...
 
 item (const group_t &v, const control_data &data=control_data())
 Constructor for a STATICBOX item. More...
 
 item (const std::string &label, const choices_t &choices, bool use_radiobox=true, int major_dimension=1, const control_data &data=control_data().window(window_data().style(wxRA_SPECIFY_COLS)), user_apply_t apply=nullptr)
 Constructor for a RADIOBOX, or a CHECKLISTBOX_BIT item. More...
 
 item (const std::string &label, wxWindow *window, user_window_create_t create, user_window_to_config_t config=nullptr, label_t label_t=LABEL_LEFT, user_apply_t apply=nullptr)
 Constructor for a USER item. More...
 
 item (const std::string &label, const listview_data &data, const std::any &value=std::any(), label_t label_t=LABEL_NONE, user_apply_t apply=nullptr)
 Constructor a LISTVIEW item. More...
 
 item (const std::string &label, type_t type, const std::any &value=std::any(), const control_data &data=control_data(), label_t label_t=LABEL_LEFT, user_apply_t apply=nullptr)
 Constructor several items. More...
 
bool apply (bool save=true) const
 If apply callback has been provided calls apply. More...
 
auto columns () const
 Returns the number of columns for the current page.
 
const auto & data () const
 Returns control data.
 
bool empty () const
 Returns true if this item is empty.
 
const std::any get_value () const
 Returns actual value, or empty object if this item has no (or not yet) associated window, or conversion is not implemented.
 
const auto & initial () const
 Returns the initial value.
 
bool is_notebook () const
 Returns true if this item is a notebook.
 
auto is_row_growable () const
 Is this item allowed to be expanded on a row.
 
const auto & label () const
 Returns the label.
 
wxFlexGridSizer * layout (wxWindow *parent, wxSizer *sizer, bool readonly=false, wxFlexGridSizer *fgz=nullptr)
 layouts this item (creates the window) on the specified sizer. More...
 
std::stringstream log () const
 Logs info about this item.
 
const auto & page () const
 Returns the page.
 
void set_imagelist (wxImageList *il)
 Sets image list.
 
void set_row_growable (bool value)
 Sets this item to be growable. More...
 
bool set_value (const std::any &value) const
 Sets actual value for the associated window. More...
 
bool to_config (bool save) const
 Loads or saves this item to the config. More...
 
auto type () const
 Returns the type.
 
auto * window () const
 Returns the window (first call layout, to create it, otherwise it is nullptr).
 

Static Public Member Functions

static void set_dialog (item_template_dialog< item > *dlg)
 Sets dialog to parent, to allow subitems to be added to the template dialog.
 
static void use_config (bool use)
 Use config for getting and retrieving values. More...
 

Protected Member Functions

 item (type_t type, const std::string &label=std::string(), const std::any &value=std::string(), label_t label_t=LABEL_NONE, int major_dimension=1, const std::any &min=0, const std::any &max=1, const std::any &inc=1, wxWindow *window=nullptr, user_window_create_t create=nullptr, user_window_to_config_t config=nullptr, wxImageList *imageList=nullptr)
 Delegate constructor. More...
 

Detailed Description

Container class for using with item_dialog.

The next items can be set using specified control_data:

For corresponding window (such as wxFLP_DEFAULT_STYLE for FILEPICKERCTRL) the style for the control used (e.g. wxTE_MULTILINE or wxTE_PASSWORD). If the window supports it you can use a markup label.

Member Typedef Documentation

◆ user_apply_t

typedef std::function< void(wxWindow* user, const std::any& value, bool save)> wex::item::user_apply_t

A function that you can provide to e.g.

specify what to do when clicking on a button item.

Member Enumeration Documentation

◆ label_t

Label types supported.

Enumerator
LABEL_NONE 

no label

LABEL_LEFT 

label left from window

LABEL_ABOVE 

label above window

◆ type_t

The item types supported.

Enumerator
BUTTON 

wxButton item

CHECKBOX 

wxCheckBox item

CHECKLISTBOX_BIT 

wxCheckListBox item to set individual bits in a long

CHECKLISTBOX_BOOL 

wxCheckListBox item using boolean choices

COLOURPICKERWIDGET 

wxColourPickerWidget item

COMBOBOX 

wxComboBox item

COMBOBOX_DIR 

wxComboBox item with a browse button for a directory

COMBOBOX_FILE 

wxComboBox item with a browse button for a file

COMMANDLINKBUTTON 

wxCommandLinkButton button

DIRPICKERCTRL 

wxDirPickerCtrl item

EMPTY 

empty item

FILEPICKERCTRL 

wxFilePickerCtrl item

FONTPICKERCTRL 

wxFontPickerCtrl item

GRID 

wex::grid item

HYPERLINKCTRL 

wxHyperlinkCtrl item

LISTVIEW 

wex::listview item

NOTEBOOK 

wxNotebook item

NOTEBOOK_AUI 

wxAuiNotebook item

NOTEBOOK_CHOICE 

wxChoicebook item

NOTEBOOK_LIST 

wxListbook item

NOTEBOOK_SIMPLE 

wxSimpleNotebook item

NOTEBOOK_TOOL 

wxToolbook item

NOTEBOOK_TREE 

wxTreebook item

NOTEBOOK_WEX 

wex::notebook item

RADIOBOX 

wxRadioBox item

SLIDER 

wxSlider item

SPACER 

spacer item

SPINCTRL 

wxSpinCtrl item

SPINCTRLDOUBLE 

wxSpinCtrlDouble item

STATICBOX 

wxStaticBox item

STATICLINE 

wxStaticLine item

STATICTEXT 

wxStaticText item

STC 

wex::stc item

TEXTCTRL 

wxTextCtrl item

TEXTCTRL_FLOAT 

wxTextCtrl item that only accepts a float (double)

TEXTCTRL_INT 

wxTextCtrl item that only accepts an integer (long)

TOGGLEBUTTON 

wxToggleButton item

USER 

provide your own window

Constructor & Destructor Documentation

◆ item() [1/13]

wex::item::item ( int  size)
inline

Constructor for a SPACER item.

The size is the size for the spacer used.

◆ item() [2/13]

wex::item::item ( wxOrientation  orientation)
inline

Constructor for a STATICLINE item.

The orientation is wxHORIZONTAL or wxVERTICAL.

◆ item() [3/13]

wex::item::item ( const std::string &  label,
const std::string &  value = std::string(),
type_t  type = TEXTCTRL,
const control_data data = control_data(),
label_t  label_t = LABEL_LEFT,
user_apply_t  apply = nullptr 
)

Constructor for several items.

Parameters
labellabel for the window as on the dialog, might also contain the note after a tab for a command link button you can use a parent child config item by using a dot in the label, the prefix is not shown on the window
valueinitial value, also used as default for a hyperlink ctrl, or as lexer for STC
typetype of this item:
  • GRID
  • HYPERLINKCTRL
  • STATICTEXT
  • STC
  • TEXTCTRL if the label contains a colon, it is a STATICTEXT, otherwise default TEXTCTRL if type is STATICTEXT then markup is allowed in the label text
datacontrol data
label_twill the label be displayed as a static text ignored for a static text
applycallback to apply

◆ item() [4/13]

wex::item::item ( const std::string &  label,
int  min,
int  max,
const std::any &  value = std::any(),
type_t  type = SPINCTRL,
const control_data data = control_data().window(window_data().style(wxSP_ARROW_KEYS)),
user_apply_t  apply = nullptr 
)
inline

Constructor for a SPINCTRL or a SLIDER item.

Parameters
labellabel for this item
minmin value
maxmax value
valuedefault value
typetype of item:
  • SPINCTRL
  • SLIDER
datacontrol data
applycallback to apply

◆ item() [5/13]

wex::item::item ( const std::string &  label,
double  min,
double  max,
const std::any &  value = std::any(),
double  inc = 1,
const control_data data = control_data().window(window_data().style(wxSP_ARROW_KEYS)),
user_apply_t  apply = nullptr 
)
inline

Constructor for a SPINCTRLDOUBLE item.

Parameters
labellabel for this item
minmin value
maxmax value
valuedefault value
incinc value
datacontrol data
applycallback to apply

◆ item() [6/13]

wex::item::item ( const choices_bool_t choices,
const control_data data = control_data(),
user_apply_t  apply = nullptr 
)
inline

Constructor for a CHECKLISTBOX_BOOL item.

This checklistbox can be used to get/set several boolean values.

Parameters
choicesthe set with names of boolean items the default value is false, but can be changed by adding a ',1' postfix to the name
datacontrol data
applycallback to apply

◆ item() [7/13]

wex::item::item ( const std::string &  label,
const notebook_t v,
type_t  type = NOTEBOOK,
int  rows = 0,
int  cols = 1,
const control_data data = control_data(),
label_t  label_t = LABEL_NONE,
wxImageList *  imageList = nullptr 
)
inline

Constructor for a NOTEBOOK item, being a vector of a pair of pages with a vector of items.

e.g.:

wex::item("notebook", {
{"page1",
{{"string1"},
{"string2"},
{"string3"}}},
{"page2",
{{"spin1", 5, 0, 10},
{"spin2", 5, 0, 10},
{"spin3", 5, 0, 10}}}})
Parameters
labellabel for this item
vnotebook items
typetype of this item (kind of notebook):
  • NOTEBOOK
  • NOTEBOOK_AUI
  • NOTEBOOK_CHOICE
  • NOTEBOOK_LIST
  • NOTEBOOK_SIMPLE
  • NOTEBOOK_TOOL
  • NOTEBOOK_TREE
  • NOTEBOOK_WEX
rowsnumber of rows
colsnumber of cols
datacontrol data
label_ttype of label
imageListimage list to be used (required for a tool book)

◆ item() [8/13]

wex::item::item ( const group_t &  v,
const control_data data = control_data() 
)
inline

Constructor for a STATICBOX item.

Parameters
vgroup items
datacontrol data

◆ item() [9/13]

wex::item::item ( const std::string &  label,
const choices_t choices,
bool  use_radiobox = true,
int  major_dimension = 1,
const control_data data = control_data().window(window_data().style(wxRA_SPECIFY_COLS)),
user_apply_t  apply = nullptr 
)
inline

Constructor for a RADIOBOX, or a CHECKLISTBOX_BIT item.

This checklistbox (not mutually exclusive choices) can be used to get/set individual bits in a long. A radiobox (mutually exclusive choices) should be used when a long value can have a short set of possible individual values.

Parameters
labellabel for this item
choicesthe map with values and text
use_radioboxindicates whether to use a radiobox or a checklistbox.
major_dimensionmajor dimension for the radiobox
datacontrol data
applycallback to apply

◆ item() [10/13]

wex::item::item ( const std::string &  label,
wxWindow *  window,
user_window_create_t  create,
user_window_to_config_t  config = nullptr,
label_t  label_t = LABEL_LEFT,
user_apply_t  apply = nullptr 
)
inline

Constructor for a USER item.

Parameters
labellabel for this item
windowthe window (use default constructor for it)
createcallback for window creation (required, useless without one)
configcallback for load and save to config if nullptr it has no relation to the config
label_ttype of label
applycallback to apply

◆ item() [11/13]

wex::item::item ( const std::string &  label,
const listview_data data,
const std::any &  value = std::any(),
label_t  label_t = LABEL_NONE,
user_apply_t  apply = nullptr 
)
inline

Constructor a LISTVIEW item.

Parameters
labellabel for this item
datalistview data
valueinitial value expects std::list< std::string>
label_ttype of label
applycallback to apply

◆ item() [12/13]

wex::item::item ( const std::string &  label,
type_t  type,
const std::any &  value = std::any(),
const control_data data = control_data(),
label_t  label_t = LABEL_LEFT,
user_apply_t  apply = nullptr 
)
inline

Constructor several items.

Parameters
labellabel for this item if type is BUTTON then markup is allowed in the label text
typetype of item:
  • BUTTON
  • CHECKBOX
  • COLOURPICKERWIDGET
  • COMBOBOX
  • COMBOBOX_DIR
  • COMBOBOX_FILE
  • COMMANDLINKBUTTON
  • DIRPICKERCTRL
  • FILEPICKERCTRL
  • FONTPICKERCTRL
  • TEXTCTRL_FLOAT
  • TEXTCTRL_INT
  • TOGGLEBUTTON
valueinitial value for the control, if appropriate:
  • CHECKBOX expects bool
  • COMBOXBOX expects std::list< std::string>
  • COLOURPICKERWIDGET expects a wxColour
  • TEXTCTRL_FLOAT expects std::string with float contents
  • TEXTCTRL_INT expects std::string with int contents
datacontrol data
label_ttype of label
applycallback to apply

◆ item() [13/13]

wex::item::item ( type_t  type,
const std::string &  label = std::string(),
const std::any &  value = std::string(),
label_t  label_t = LABEL_NONE,
int  major_dimension = 1,
const std::any &  min = 0,
const std::any &  max = 1,
const std::any &  inc = 1,
wxWindow *  window = nullptr,
user_window_create_t  create = nullptr,
user_window_to_config_t  config = nullptr,
wxImageList *  imageList = nullptr 
)
protected

Delegate constructor.

Parameters
typethe item type
labelthe label to appear in front of the item
valueintitial value if appropriate
label_tIf you specify add label, then the label is added as a label in front of the item, otherwise the label is not added
major_dimensionmajor dimention for radio boxes
minmin value if appropriate
maxmax value if appropriate
incincrement value if appropriate
windowwindow, normally created by layout, but may be supplied here
createthe process callback for window creation
configthe process callback for window config
imageListthe imagelist

Member Function Documentation

◆ apply()

bool wex::item::apply ( bool  save = true) const
inline

If apply callback has been provided calls apply.

Otherwise return false.

◆ layout()

wxFlexGridSizer* wex::item::layout ( wxWindow *  parent,
wxSizer *  sizer,
bool  readonly = false,
wxFlexGridSizer *  fgz = nullptr 
)

layouts this item (creates the window) on the specified sizer.

It returns the flex grid sizer that was used for creating the item sizer. Or it returns nullptr if no flex grid sizer was used.

Parameters
parentthe parent
sizerthe sizer
readonlyspecify the item will be readonly, it will not be changeable if underlying control supports this
fgzspecify the sizer for creating the item, or nullptr, than a new one is created

◆ set_row_growable()

void wex::item::set_row_growable ( bool  value)
inline

Sets this item to be growable.

Default whether the item row is growable is determined by the kind of item. You can override this using SetRowGrowable.

◆ set_value()

bool wex::item::set_value ( const std::any &  value) const

Sets actual value for the associated window.

Returns false if window is nullptr, or value was not set.

◆ to_config()

bool wex::item::to_config ( bool  save) const

Loads or saves this item to the config.

Returns true if the config was accessed, as not all config items associate with the config.

◆ use_config()

static void wex::item::use_config ( bool  use)
inlinestatic

Use config for getting and retrieving values.

Default the config is used. The label is used as entry in the config.

wex::item
Container class for using with item_dialog.
Definition: item.h:41