sptk2 logo
SPTK Home Page
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
sptk::CBaseListBox Class Reference

Base list box widget. More...

#include <CComboBox.h>

Inheritance diagram for sptk::CBaseListBox:
sptk::CControl sptk::CLayoutClient sptk::CComboBox sptk::CListBox sptk::CFontComboBox

Public Member Functions

virtual void clear ()
 
uint32_t buttons () const
 
void buttons (uint32_t)
 
Fl_Callback_p buttonClicked () const
 
void buttonClicked (Fl_Callback *c)
 
void columns (const CColumnList &columnList)
 
CColumnListcolumns ()
 
void addColumn (std::string cname, VariantDataType type=VariantDataType::VAR_STRING, int16_t cwidth=70, bool cvisible=true)
 
void addRow (CPackedStrings *row)
 
void addRow (int rowId, const Strings &strings)
 
void addRows (std::string columnName, Strings rows)
 
void resize (int x, int y, int w, int h) override
 
Variant data () const override
 
void data (const Variant &v) override
 
void dataMode (CListViewDataMode dm)
 
CListViewDataMode dataMode ()
 
CPackedStringsfindCaption (const String &caption)
 
CPackedStringsfindKey (int keyValue)
 
PoolDatabaseConnectiondatabase () const
 
void database (PoolDatabaseConnection *db)
 
String sql () const
 
void sql (std::string s)
 
std::string keyField () const
 
void keyField (std::string keyFieldName)
 
int sortColumn () const
 
void sort ()
 
void sortColumn (int sortColumn)
 
void setup (PoolDatabaseConnection *db, std::string sql, std::string keyField)
 
QueryParameterparam (const char *paramName)
 
void refreshData ()
 
int findString (const std::string &str, bool select=true, uint32_t startRow=0, unsigned endRow=0)
 
CPackedStringsselectedRow () const
 
void selectRow (unsigned rowNumber)
 
void showHeaders ()
 
void hideHeaders ()
 
unsigned size () const
 
bool preferredSize (int &w, int &h) override
 
- Public Member Functions inherited from sptk::CControl
 CControl (const char *label, int layoutSize=20, CLayoutAlign layoutAlign=CLayoutAlign::TOP)
 Constructor in SPTK style. More...
 
void resize (int x, int y, int w, int h) override
 Resizes the control and inside widgets. More...
 
void draw () override
 Draws the control.
 
virtual int tag () const
 Returns the control's user data tag.
 
virtual void tag (int t)
 Sets the control's user data tag.
 
virtual Fl_Font textFont () const
 Returns the control's text font. More...
 
virtual void textFont (Fl_Font)
 Sets the control's text font. More...
 
virtual uchar textSize () const
 Returns the control's text font size. More...
 
virtual void textSize (uchar)
 Sets the control's text font size. More...
 
virtual Fl_Color textColor () const
 Returns the control's text color. More...
 
virtual void textColor (Fl_Color)
 Sets the control's text color. More...
 
virtual Fl_Color labelColor () const
 Returns the control's label color.
 
virtual void labelColor (Fl_Color)
 Sets the control's label color.
 
virtual Fl_Color color () const
 Returns the control's background color.
 
virtual void color (Fl_Color)
 Sets the control's background color.
 
uint32_t flags () const
 Returns the control's flags.
 
void flags (uint32_t flags)
 Sets the control's flags.
 
Fl_Widget * control () const
 Returns main widget inside the container.
 
const Stringlabel () const override
 Returns control's label. More...
 
void label (const String &) override
 Sets control's label. More...
 
Fl_Menu_ * menu () const
 Returns control's menu.
 
void menu (const Fl_Menu_Item *)
 Sets control's menu.
 
Fl_Font labelFont () const
 Returns control's label font.
 
void labelSize (Fl_Font f)
 Sets control's label font.
 
uchar labelSize () const
 Returns control's label font size.
 
void labelSize (uchar)
 Sets control's label font size.
 
uint32_t labelWidth () const
 Returns control's label width.
 
void labelWidth (uint32_t)
 Sets control's label width.
 
void hint (const String &str)
 Sets control's hint (tooltip) More...
 
String hint () const
 Returns control's hint (tooltip)
 
virtual int maxLength () const
 Returns control's max input length, if applicable. More...
 
virtual void maxLength (int)
 Sets control's max input length, if applicable. More...
 
virtual const StringfieldName () const
 Returns control's field name for universal data connection.
 
virtual void fieldName (const String &)
 Sets control's field name for universal data connection.
 
virtual CControlKind kind () const =0
 Returns control's kind (internal SPTK RTTI). More...
 
String className () const override
 Returns control's class name (internal SPTK RTTI). More...
 
virtual void reset ()
 Sets the control to empty text (for the input entries) More...
 
virtual void load (Query *)
 Loads control data from query fields. More...
 
virtual void save (Query *)
 Saves control data to query params. More...
 
void load (const xdoc::SNode &node, CLayoutXMLmode xmlMode) override
 Loads control data from XML. More...
 
void load (const xdoc::SNode &node) override
 Loads control data from XML. More...
 
void save (const xdoc::SNode &node, CLayoutXMLmode xmlMode) const override
 Saves control data to XML. More...
 
virtual void save (const xdoc::SNode &node) const
 Saves control data to XML. More...
 
virtual bool valid () const =0
 Returns true if the control state is valid, and the data is inside the limits (if applicable) More...
 
virtual Variant data () const
 The universal data connector. More...
 
virtual void data (const Variant &v)
 The universal data connector, sets control data. More...
 
void fireEvent (CEvent ev, int32_t arg)
 Fires the event generated by this control.
 
const CEventInfoevent () const
 Returns the last event fired by this control.
 
CEvent eventType () const
 Returns the event type for the last fired by this control.
 
int eventArgument () const
 Returns the event argument for the last fired by this control.
 
CControloperator= (const String &str)
 Control data assignment.
 
CControloperator= (const char *str)
 Control data assignment.
 
CControloperator= (int32_t v)
 Control data assignment.
 
CControloperator= (uint32_t v)
 Control data assignment.
 
CControloperator= (int64_t v)
 Control data assignment.
 
CControloperator= (float v)
 Control data assignment.
 
CControloperator= (double v)
 Control data assignment.
 
CControloperator= (const DateTime &dt)
 Control data assignment.
 
CControloperator= (const Field &fld)
 Control data assignment.
 
 operator String () const
 Control data conversion.
 
 operator int32_t () const
 Control data conversion.
 
 operator uint32_t () const
 Control data conversion.
 
 operator int64_t () const
 Control data conversion.
 
 operator uint64_t () const
 Control data conversion.
 
 operator float () const
 Control data conversion.
 
 operator double () const
 Control data conversion.
 
 operator DateTime () const
 Control data conversion.
 
- Public Member Functions inherited from sptk::CLayoutClient
 CLayoutClient (Fl_Widget *widget, int layoutSize, CLayoutAlign ca)
 
virtual ~CLayoutClient ()
 
CLayoutAlign layoutAlign () const
 
void layoutAlign (CLayoutAlign al)
 
int layoutSize () const
 
void layoutSize (int ls)
 
virtual void label (const String &l)
 
virtual const Stringlabel () const
 
void name (const char *aname)
 
void name (const String &aname)
 
const Stringname () const
 
virtual bool preferredSize (int &w, int &h)
 
virtual bool computeSize (int &w, int &h)
 
virtual String className () const
 
Fl_Widget * widget () const
 
virtual void load (const xdoc::SNode &node, CLayoutXMLmode xmlMode)
 
virtual void load (const std::shared_ptr< xdoc::Node > &node)
 
virtual void save (const std::shared_ptr< xdoc::Node > &node, CLayoutXMLmode xmlMode) const
 

Protected Member Functions

virtual void dropDownList ()
 
void load (Query *) override
 Loads data from the Query. More...
 
void save (Query *) override
 Saves data to the Query. More...
 
void load (const xdoc::SNode &node, CLayoutXMLmode xmlMode) override
 Loads control data from XML. More...
 
void save (const xdoc::SNode &node, CLayoutXMLmode xmlMode) const override
 Saves control data to XML. More...
 
bool valid () const override
 
 CBaseListBox (const char *label, int layoutSize, CLayoutAlign layoutAlign, int mode)
 
 ~CBaseListBox () override
 
virtual void button_handle (uint32_t theButtonKind)
 
- Protected Member Functions inherited from sptk::CControl
bool containsFocus () const
 Does the control contain focus?
 
void notifyFocus (bool gotFocus=true)
 Internal focus notification on focus change.
 
virtual void onEnter ()
 Internal focus notification on focus change.
 
virtual void onExit ()
 Internal focus notification on focus change. More...
 
uint32_t labelHeight () const
 Computes the label height based on the labelFont() and labelWidth()
 
int handle (int) override
 Special handle() method.
 
- Protected Member Functions inherited from sptk::CLayoutClient
int lastPreferredH () const
 
int lastPreferredW () const
 
void lastPreferredH (int height)
 
void lastPreferredW (int width)
 

Protected Attributes

CDBDropDownListm_dropDownWindow
 
CDBListViewm_list
 
int m_buttonSpace
 
- Protected Attributes inherited from sptk::CControl
bool m_limited {false}
 
uint32_t m_labelWidth {0}
 
Fl_Color m_labelColor
 
Fl_Color m_textColor
 
Fl_Font m_textFont
 
uchar m_textSize {0}
 
String m_fieldName
 
String m_hint
 
Fl_Widget * m_control {nullptr}
 
int m_tag {0}
 
uint32_t m_controlFlags {0}
 Control's special flags (a bit combination of InputEntryFlags). More...
 
Fl_Menu_Button * m_menuButton {nullptr}
 
CEventInfo m_event
 
bool m_hasFocus {false}
 
- Protected Attributes inherited from sptk::CLayoutClient
Fl_Widget * m_widget
 
String m_name
 
String m_label
 
CLayoutAlign m_layoutAlign
 

Friends

class CInternalComboBoxPanel
 

Additional Inherited Members

- Static Public Member Functions inherited from sptk::CControl
static CControlKind controlNameToType (const String &typeName, int &maxLength, const String &values="")
 Converts control name to control kind.
 
static void defaultControlMenuCopy (Fl_Widget *, void *)
 Default callback function to support CControl default menu item 'Copy'.
 
static void defaultControlMenuCut (Fl_Widget *, void *)
 Default callback function to support CControl default menu item 'Delete'.
 
static void defaultControlMenuPaste (Fl_Widget *, void *)
 Default callback function to support CControl default menu item 'Paste'.
 
static void defaultControlMenuClear (Fl_Widget *, void *)
 Default callback function to support CControl default menu item 'Clear'.
 
- Static Public Attributes inherited from sptk::CControl
static const Fl_Menu_Item defaultControlMenu []
 CControl default menu.
 
- Static Protected Member Functions inherited from sptk::CControl
static void internalCallback (Fl_Widget *internalWidget, void *data)
 Internal callback function.
 

Detailed Description

Base list box widget.

A base class for CListBox and CComboBox. Implements most of the common methods for these two classes.

Constructor & Destructor Documentation

◆ CBaseListBox()

sptk::CBaseListBox::CBaseListBox ( const char *  label,
int  layoutSize,
CLayoutAlign  layoutAlign,
int  mode 
)
protected

Constructor in SPTK style

Parameters
labelconst char *, label
layoutSizeint, widget align in layout
layoutAlignCLayoutAlign, widget align in layout
modeint, IS_COMBO_BOX or IS_LIST_BOX - internal

◆ ~CBaseListBox()

sptk::CBaseListBox::~CBaseListBox ( )
overrideprotected

Destructor

Member Function Documentation

◆ addColumn()

void sptk::CBaseListBox::addColumn ( std::string  cname,
VariantDataType  type = VariantDataType::VAR_STRING,
int16_t  cwidth = 70,
bool  cvisible = true 
)

Adds a new column to the internal list view.

Parameters
cnamestd::string, column name
typeVariantType, column data type
cwidthint16_t, column width
cvisiblebool, is the column visible?

◆ addRow() [1/2]

void sptk::CBaseListBox::addRow ( CPackedStrings row)

Adds a new row to the internal list view. Doesn't make a copy - just inserts the pointer. The row will be destroyed in CCombo destructor. The row ID may be defined inside CPackedStrings object.

Parameters
rowCPackedStrings *, new row

◆ addRow() [2/2]

void sptk::CBaseListBox::addRow ( int  rowId,
const Strings strings 
)

Adds a new row to the internal list view. Makes a copy of data in rowStrings. The row ID may be defined inside Strings object, or with rowID parameter.

Parameters
rowIdRow argument (key value)
rowRow data

◆ addRows()

void sptk::CBaseListBox::addRows ( std::string  columnName,
Strings  rows 
)

Creates the column as columnName and adds rows to the internal list view. If the column with such name already exists, it will be used. The method is good the a very simple cases of one-column combo boxes. The row IDs may be defined inside Strings object strings.

Parameters
columnNamestd::string, new columnName
rowsStrings, new rows

◆ button_handle()

virtual void sptk::CBaseListBox::button_handle ( uint32_t  theButtonKind)
protectedvirtual

Internal buttons callback function

◆ buttonClicked() [1/2]

Fl_Callback_p sptk::CBaseListBox::buttonClicked ( ) const
inline

Returns buttons' callback function

◆ buttonClicked() [2/2]

void sptk::CBaseListBox::buttonClicked ( Fl_Callback *  c)
inline

Sets buttons' callback function

◆ buttons() [1/2]

uint32_t sptk::CBaseListBox::buttons ( ) const
inline

Returns the bitmask of visible buttons' IDs

◆ buttons() [2/2]

void sptk::CBaseListBox::buttons ( uint32_t  )

Sets the bitmask for visible buttons' IDs

◆ clear()

virtual void sptk::CBaseListBox::clear ( )
virtual

Clears the list view inside

◆ columns() [1/2]

CColumnList & sptk::CBaseListBox::columns ( )

Returns current column list of the internal list view.

Returns
the column list reference

◆ columns() [2/2]

void sptk::CBaseListBox::columns ( const CColumnList columnList)

Sets the internal list view columns from the column list. The old column list is destroyed and replaced with a copy of columnList.

Parameters
columnListCColumnList&, new column list

◆ data() [1/2]

Variant sptk::CBaseListBox::data ( ) const
overridevirtual

Universal data connection. Operates with selected list view item's ID.

Reimplemented from sptk::CControl.

◆ data() [2/2]

void sptk::CBaseListBox::data ( const Variant v)
overridevirtual

Universal data connection. Operates with selected list view item's ID.

Reimplemented from sptk::CControl.

◆ database() [1/2]

PoolDatabaseConnection * sptk::CBaseListBox::database ( ) const

Returns database connection pointer

◆ database() [2/2]

void sptk::CBaseListBox::database ( PoolDatabaseConnection db)

Defines database connection

◆ dataMode() [1/2]

CListViewDataMode sptk::CBaseListBox::dataMode ( )
inline

Returns data mode as LVDM_KEY, LVDM_INDEX, or LVDM_TEXT.

See also
CListViewDataMode for more information

References sptk::CListView::dataMode().

◆ dataMode() [2/2]

void sptk::CBaseListBox::dataMode ( CListViewDataMode  dm)
inline

Sets data mode for the data() methods. Defines which information list view are working with in data() method - key value, item index, or item caption.

See also
CListViewDataMode for more information

References sptk::CListView::dataMode().

◆ dropDownList()

virtual void sptk::CBaseListBox::dropDownList ( )
protectedvirtual

Drops down the window with the List View. CComboBox only.

◆ findCaption()

CPackedStrings * sptk::CBaseListBox::findCaption ( const String caption)
inline

Finds an item with the caption (a string in the first column).

Parameters
captionstd::string, the caption to find and select.
Returns
an item, or NULL if item caption is not found

References sptk::CListView::findCaption().

◆ findKey()

CPackedStrings * sptk::CBaseListBox::findKey ( int  keyValue)
inline

Finds an item with the key (an integer associated with the item - argument()).

Parameters
keyValueint, the caption to find and select.
Returns
an item, or NULL if item caption is not found

References sptk::CListView::findKey().

◆ findString()

int sptk::CBaseListBox::findString ( const std::string &  str,
bool  select = true,
uint32_t  startRow = 0,
unsigned  endRow = 0 
)

Finds a string in the sort column of list view defined with sortColumn()

Parameters
strstd::string, string to find
selectbool, true if we want to select the found row
startRowuint32_t, the row number to start
endRowuint32_t, the row number to finish
Returns
the row number, or -1 if not found

◆ hideHeaders()

void sptk::CBaseListBox::hideHeaders ( )

Hides column headers in the list

◆ keyField() [1/2]

std::string sptk::CBaseListBox::keyField ( ) const

Returns SQL query field name that contains unique row IDS, preferrably - integers.

◆ keyField() [2/2]

void sptk::CBaseListBox::keyField ( std::string  keyFieldName)

Sets SQL query field name that contains unique row IDS, preferrably - integers.

Parameters
keyFieldNamestd::string, a name of the key field

◆ load() [1/2]

void sptk::CBaseListBox::load ( const xdoc::SNode &  node,
CLayoutXMLmode  xmlMode 
)
overrideprotectedvirtual

Loads control data from XML.

Layout information may also include widget size and position, as well as visible() and active() states

Parameters
nodexml::Node*, the XML node
xmlModeCLayoutXMLmode, the mode defining how the layout and/or data should be stored

Reimplemented from sptk::CLayoutClient.

◆ load() [2/2]

void sptk::CBaseListBox::load ( Query )
overrideprotectedvirtual

Loads data from the Query.

Reimplemented from sptk::CControl.

◆ param()

QueryParameter & sptk::CBaseListBox::param ( const char *  paramName)

Returns the SQL query parameter reference for the parameter name. It is typical to call: myCombo.param("customer_id") = 1234

Parameters
paramNameconst char *, parameter name.
Returns
the parameter reference, if found, or throws an excception.

◆ preferredSize()

bool sptk::CBaseListBox::preferredSize ( int &  w,
int &  h 
)
overridevirtual

Computes the optimal widgets size

Parameters
wint&, input - width offered by the program, output - width required by widget
hint&, input - height offered by the program, output - height required by widget
Returns
true if the size is stable (doesn't depend on input sizes)

Reimplemented from sptk::CLayoutClient.

◆ refreshData()

void sptk::CBaseListBox::refreshData ( )

Reloads data from the database if database connection is defined. Throws an exception if any error.

◆ resize()

void sptk::CBaseListBox::resize ( int  x,
int  y,
int  w,
int  h 
)
override

Resizes the control and inside widgets.

Parameters
xint, x-position
yint, y-position
wint, width
hint, height

◆ save() [1/2]

void sptk::CBaseListBox::save ( const xdoc::SNode &  node,
CLayoutXMLmode  xmlMode 
) const
overrideprotected

Saves control data to XML.

Layout information may also include widget size and position, as well as visible() and active() states

Parameters
nodexml::Node*, the XML node
xmlModeCLayoutXMLmode, the mode defining how the layout and/or data should be stored

◆ save() [2/2]

void sptk::CBaseListBox::save ( Query )
overrideprotectedvirtual

Saves data to the Query.

Reimplemented from sptk::CControl.

◆ selectedRow()

CPackedStrings * sptk::CBaseListBox::selectedRow ( ) const

Returns the currently selected row, or reference to NULL if not selected

◆ selectRow()

void sptk::CBaseListBox::selectRow ( unsigned  rowNumber)

Selects a row

Parameters
rowNumberunsigned, row number

◆ setup()

void sptk::CBaseListBox::setup ( PoolDatabaseConnection db,
std::string  sql,
std::string  keyField 
)

The fast way to define a database connection.

Parameters
dbDatabaseConnection *, a pointer to the database
sqlstd::string, a SQL query text
keyFieldstd::string, a name of the query field with unique row IDs

◆ showHeaders()

void sptk::CBaseListBox::showHeaders ( )

Shows column headers in the list

◆ size()

unsigned sptk::CBaseListBox::size ( ) const

Returns the number of rows in list view

◆ sort()

void sptk::CBaseListBox::sort ( )
inline

Sorts the list

References sptk::CListView::sort().

◆ sortColumn() [1/2]

int sptk::CBaseListBox::sortColumn ( ) const

Returns sortColumn

◆ sortColumn() [2/2]

void sptk::CBaseListBox::sortColumn ( int  sortColumn)

Defines sortColumn.

Parameters
sortColumnint, sort column number. -1 means don't sort.

◆ sql() [1/2]

String sptk::CBaseListBox::sql ( ) const

Returns SQL query text

◆ sql() [2/2]

void sptk::CBaseListBox::sql ( std::string  s)

Defines SQL query text

Parameters
sstd::string, SQL text

◆ valid()

bool sptk::CBaseListBox::valid ( ) const
inlineoverrideprotectedvirtual

Returns true, if the data is valid.

Implements sptk::CControl.

Member Data Documentation

◆ m_buttonSpace

int sptk::CBaseListBox::m_buttonSpace
protected

The width of space taken by buttons

◆ m_dropDownWindow

CDBDropDownList* sptk::CBaseListBox::m_dropDownWindow
protected

Drop down window - CComboBox only

◆ m_list

CDBListView* sptk::CBaseListBox::m_list
protected

Internal CDBListView widget


The documentation for this class was generated from the following file:

Fri Oct 14 2022 09:58:33: SPTK 5.4.1