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

#include <CDialog.h>

Inheritance diagram for sptk::CDialog:
sptk::CWindow sptk::CLayoutManager sptk::CWindowShape sptk::CLayoutClient sptk::CAskDialog sptk::CFileDialog sptk::CSpellChecker sptk::CInputDialog sptk::CMessageDialog sptk::CDirOpenDialog sptk::CFileOpenDialog sptk::CFileSaveDialog sptk::CEditorSpellChecker

Public Member Functions

 CDialog (int w, int h, const char *label=nullptr)
 
 ~CDialog () override
 
virtual bool reset ()
 
int handle (int event) override
 
bool showModal ()
 
void alert (const String &s) const
 
void defaultButton (CButton *btn)
 
virtual void database (PoolDatabaseConnection *db)
 
PoolDatabaseConnectiondatabase () const
 
void table (const String &tableName)
 
String table () const
 
void table (PoolDatabaseConnection *db, const String &tableName, const String &keyFieldName)
 Fast setup of the database connection. More...
 
void keyField (const String &keyFieldName)
 
String keyField () const
 
void keyValue (int val)
 
int keyValue () const
 
virtual Fl_Group * newPage (const char *label, bool autoColor)
 
virtual Fl_Group * newScroll (const char *label, bool autoColor)
 
CButtonaddExtraButton (CButtonKind buttonKind, const char *label, Fl_Callback_p callback)
 
uint32_t fieldCount () const
 
CControloperator[] (const String &fieldName)
 Index operator to access controls with defined field name. More...
 
void rescan ()
 Makes dialog to scan the widgets inside.
 
void load (const xdoc::SNode &node) override
 
void save (const xdoc::SNode &node) const override
 
CDialogModalResult modalResult () const
 
String className () const override
 Returns widget class name (internal SPTK RTTI). More...
 
- Public Member Functions inherited from sptk::CWindow
 CWindow (int w, int h, const char *label=0L)
 Constructor. More...
 
 CWindow (int x, int y, int w, int h, const char *label=0L)
 Constructor. More...
 
void draw () override
 Draws a window, including an optional background image.
 
void show () override
 Custom show method.
 
void show (int argc, char *argv[])
 Custom show method. More...
 
void hide () override
 Custom hide method.
 
virtual void relayout ()
 Relayouts window's widgets that have CLayoutClient interface.
 
void clear () override
 Removes all the widgets inside the window. More...
 
void resize (int x, int y, int w, int h) override
 Resizes the window and inside widgets. More...
 
bool preferredSize (int &w, int &h) override
 Computes the optimal window size. More...
 
int handle (int event) override
 Custom window events handle. More...
 
void load (const std::shared_ptr< xdoc::Node > &node, CLayoutXMLmode xmlMode) override
 Loads window coordinates and widgets from XML node. More...
 
void load (const std::shared_ptr< xdoc::Node > &node) override
 Loads window coordinates and widgets from XML node. More...
 
void save (const std::shared_ptr< xdoc::Node > &node, CLayoutXMLmode xmlMode) const override
 Saves window coordinates and widgets into XML node. More...
 
virtual void save (const xdoc::SNode &node) const
 Saves window coordinates and widgets into XML node. More...
 
void loadPosition (const xdoc::SNode &node)
 Loads the window position from XML node. More...
 
void savePosition (const xdoc::SNode &node) const
 Saves the window position into XML node. More...
 
const Stringlabel () const override
 Returns the current label. More...
 
String className () const override
 Returns widget class name (internal SPTK RTTI). More...
 
virtual void label (const String &l)
 
virtual const Stringlabel () const
 
- Public Member Functions inherited from sptk::CLayoutManager
 CLayoutManager (Fl_Group *group, int layoutSize, CLayoutAlign ca)
 
 ~CLayoutManager () override=default
 
virtual void clear ()
 Removes all the children. More...
 
int layoutSpacing () const
 
void layoutSpacing (int ls)
 
void layoutGrowMode (CLayoutGrowMode gm=CLayoutGrowMode::LGM_AUTO_GROW)
 
CLayoutGrowMode layoutGrowMode () const
 
void relayout ()
 
void frame (CFrame *frame, bool drawBackground=true)
 Defines frame. More...
 
const CFrameframe () const
 Returnes the current frame.
 
uint32_t frameWidth () const
 Returns frame width.
 
virtual void loadLayout (const xdoc::SNode &node, CLayoutXMLmode xmlMode)
 Loads group controls data from XML node. More...
 
virtual void saveLayout (const xdoc::SNode &node, CLayoutXMLmode xmlMode) const
 Saves group controls data into XML node. More...
 
void nameIndex (CWidgetNamesMap &index, bool recursive, bool clean=true) const
 Builds an index of internal widget names. More...
 
bool noXml () const
 Returns flag of blocking XML processing. More...
 
void noXml (bool noXml)
 Sets flag of blocking XML processing. More...
 
- 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
 
- Public Member Functions inherited from sptk::CWindowShape
 CWindowShape (sptk::CWindow *window)
 Constructor. More...
 
virtual ~CWindowShape ()
 Destructor.
 
bool shapeResizing ()
 Returns true if the window is resizing as a result of border drag. More...
 

Protected Member Functions

virtual bool okPressed ()
 
virtual bool cancelPressed ()
 
virtual void scanControls ()
 
virtual bool buildQueries ()
 
virtual bool load ()
 
virtual bool save ()
 
- Protected Member Functions inherited from sptk::CLayoutManager
bool autoLayout (int x, int y, int &w, int &h, bool resizeWidgets) const
 
virtual void paintBackground ()
 
- Protected Member Functions inherited from sptk::CLayoutClient
int lastPreferredH () const
 
int lastPreferredW () const
 
void lastPreferredH (int height)
 
void lastPreferredW (int width)
 
- Protected Member Functions inherited from sptk::CWindowShape
int mouseZone (int mouseX, int mouseY) const
 Computes mouse zone from window coordinates. More...
 
void changeSize (int mouseX, int mouseY)
 Resizes the window based on mouse zone and mouse screen coordinates. More...
 
virtual int shapeCursorHandle (int event)
 Changes the window cursor based on the mouse position in the window. More...
 
void initShapeExtension ()
 Initializes shape extension. More...
 
bool borderCleared () const
 Returns true if border was cleared for the shape.
 
void shapeApply ()
 Sets the shape to the window during window->draw()
 
void resizingShape (int w, int h)
 Calls resizeShape() from inside CWindow::resize()
 
virtual void shapeResize (int w, int h)
 Shape resize. More...
 

Protected Attributes

CButtonm_okButton
 
CButtonm_cancelButton
 
CButtonm_defaultButton
 
String m_tableName
 
String m_keyField
 
int m_keyValue
 
CControlList m_defaultFields
 
CControlList m_allFields
 
CGroupm_buttonGroup
 
CDialogTabsm_pages
 
Querym_selectQuery
 
Querym_updateQuery
 
Querym_insertQuery
 
bool m_queriesBuilt
 
bool m_controlsScanned
 
CControlList m_specialProcessingControls
 
CDialogModalResult m_modalResult
 
- Protected Attributes inherited from sptk::CLayoutManager
int m_layoutSpacing
 
CLayoutGrowMode m_layoutGrowMode
 
Fl_Group * m_group
 
CFramem_frame
 
bool m_frameDrawBackground
 
bool m_noXml
 
- Protected Attributes inherited from sptk::CLayoutClient
Fl_Widget * m_widget
 
String m_name
 
String m_label
 
CLayoutAlign m_layoutAlign
 
- Protected Attributes inherited from sptk::CWindowShape
int m_resizingZone {0}
 
int m_pushedX {0}
 
int m_pushedY {0}
 
std::vector< CShapePointm_shapePoints
 
bool m_shapeChanged {true}
 
int m_borderWidth {6}
 
bool m_borderCleared {false}
 
bool m_shapeExtension {false}
 

Additional Inherited Members

- Static Public Member Functions inherited from sptk::CLayoutManager
static void registerControl (std::string typeName, createControlCallback creator) noexcept
 Register control type for loading layouts. More...
 
static const std::map< std::string, Fl_Boxtype > & boxTypeNames ()
 Returns a read-only map of box type names and corresponding constants.
 
- Static Protected Attributes inherited from sptk::CLayoutManager
static std::map< std::string, Fl_Boxtype > m_boxTypeNames
 
static createControlCallbackMap controlCreator
 

Detailed Description

Dialog window.

Shows a modal window on the screen. CDialog has support for the database data exchange to edit a database record. The required SQL queries in this case are created on the fly, from the list of controls inside the dialog. Controls should have the field names defined, though. And don't forget to define a table name and key field name.

Constructor & Destructor Documentation

◆ CDialog()

sptk::CDialog::CDialog ( int  w,
int  h,
const char *  label = nullptr 
)

Constructor

Parameters
wDialog width
hDialog height
labelDialog caption

◆ ~CDialog()

sptk::CDialog::~CDialog ( )
override

Destructor

Member Function Documentation

◆ addExtraButton()

CButton * sptk::CDialog::addExtraButton ( CButtonKind  buttonKind,
const char *  label,
Fl_Callback_p  callback 
)

Adds a user-defined button to the dialog.

User-defined buttons usually do something in the dialog without closing the dialog.

Parameters
buttonKindCButtonKind, button type
labelconst char *, button label
callbackFl_Callback_p, button callback

◆ alert()

void sptk::CDialog::alert ( const String s) const

Shows an alert box

◆ buildQueries()

virtual bool sptk::CDialog::buildQueries ( )
protectedvirtual

Builds database interface queries using table(), keyField(), and control field names

If m_queriesBuilt is already true, does nothing.

◆ cancelPressed()

virtual bool sptk::CDialog::cancelPressed ( )
protectedvirtual

Ok button callback

If it returns true the dialog closes. False indicates an error and dialog stays open.

◆ className()

String sptk::CDialog::className ( ) const
inlineoverridevirtual

Returns widget class name (internal SPTK RTTI).

Reimplemented from sptk::CLayoutClient.

◆ database() [1/2]

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

Returns current database connection

◆ database() [2/2]

virtual void sptk::CDialog::database ( PoolDatabaseConnection db)
virtual

Sets the database connection

Parameters
dbDatabase connection

◆ defaultButton()

void sptk::CDialog::defaultButton ( CButton btn)

Defines the default button

Parameters
btnButton in dialog to become the default button

◆ fieldCount()

uint32_t sptk::CDialog::fieldCount ( ) const
inline

Returns the number of controls inside the dialog with defined field names

◆ handle()

int sptk::CDialog::handle ( int  event)
override

Own handle() method to process dialog events the special way

Parameters
eventFLTK event
Returns
true if event was processed

◆ keyField() [1/2]

String sptk::CDialog::keyField ( ) const
inline

Returns the key field name for the database table.

◆ keyField() [2/2]

void sptk::CDialog::keyField ( const String keyFieldName)

Sets the key field name for the database table.

The key field contains the unique value to find the database record.

Parameters
keyFieldNameName of the key field in the database table

◆ keyValue() [1/2]

int sptk::CDialog::keyValue ( ) const

Returns the current database record key value.

◆ keyValue() [2/2]

void sptk::CDialog::keyValue ( int  val)

Finds the database record by the value in previously defined key field.

◆ load() [1/2]

virtual bool sptk::CDialog::load ( )
protectedvirtual

Loads data into dialog

Returns true upon success. If you're overwriting this method make sure you're calling the original CDialog::load() and use the result of it.

◆ load() [2/2]

void sptk::CDialog::load ( const xdoc::SNode &  node)
override

Loads the dialog controls data from XML

Parameters
nodeXML node to load data from
See also
xml::Node

◆ modalResult()

CDialogModalResult sptk::CDialog::modalResult ( ) const
inline

Returns the modal result of the dialog.

See also
CDialogModalResult for more information.
Returns
modal result

◆ newPage()

virtual Fl_Group * sptk::CDialog::newPage ( const char *  label,
bool  autoColor 
)
virtual

Creates a new page as CGroup

Parameters
Pagelabel
autoColorIf true the page color is assigned automatically
Returns
created group

◆ newScroll()

virtual Fl_Group * sptk::CDialog::newScroll ( const char *  label,
bool  autoColor 
)
virtual

Creates a new page as CScroll

Parameters
labelPage label
autoColorIf true the page color is assigned automatically
Returns
created group

◆ okPressed()

virtual bool sptk::CDialog::okPressed ( )
protectedvirtual

Ok button callback

If it returns true the dialog closes. False indicates an error and dialog stays open.

Reimplemented in sptk::CDirOpenDialog, sptk::CFileOpenDialog, and sptk::CFileSaveDialog.

◆ operator[]()

CControl & sptk::CDialog::operator[] ( const String fieldName)

Index operator to access controls with defined field name.

Parameters
fieldNameThe control field name

◆ reset()

virtual bool sptk::CDialog::reset ( )
virtual

Resets all the controls inside the dialog tabs by calling reset() for every control

◆ save() [1/2]

virtual bool sptk::CDialog::save ( )
protectedvirtual

Saves data from dialog

Returns true upon success. If you're overwriting this method make sure you're calling the original CDialog::save() and use the result of it.

◆ save() [2/2]

void sptk::CDialog::save ( const xdoc::SNode &  node) const
overridevirtual

Saves the dialog controls into XML

Parameters
nodeXML node to save data into
See also
xml::Node* node

Reimplemented from sptk::CWindow.

◆ scanControls()

virtual void sptk::CDialog::scanControls ( )
protectedvirtual

Scans dialog controls

If m_controlsScanned is already true, does nothing.

◆ showModal()

bool sptk::CDialog::showModal ( )

Shows modal dialog

Returns
true if Ok button was used to close the dialog

◆ table() [1/3]

String sptk::CDialog::table ( ) const
inline

Returnes used database table

◆ table() [2/3]

void sptk::CDialog::table ( const String tableName)

Defines database table to use

Parameters
tableNameName of the database table

◆ table() [3/3]

void sptk::CDialog::table ( PoolDatabaseConnection db,
const String tableName,
const String keyFieldName 
)

Fast setup of the database connection.

Parameters
dbDatabase connection
tableNameName of the database table
keyFieldNameName of the key field in the database table

Member Data Documentation

◆ m_allFields

CControlList sptk::CDialog::m_allFields
protected

The list of all controls (CControl-descendants)

◆ m_buttonGroup

CGroup* sptk::CDialog::m_buttonGroup
protected

The group buttons are placed on.

◆ m_cancelButton

CButton* sptk::CDialog::m_cancelButton
protected

Standard Cancel button

◆ m_controlsScanned

bool sptk::CDialog::m_controlsScanned
protected

Database interface: The flag indicating if available controls were scanned for field names.

◆ m_defaultButton

CButton* sptk::CDialog::m_defaultButton
protected

Pointer to the default button

◆ m_defaultFields

CControlList sptk::CDialog::m_defaultFields
protected

Database interface: The list of controls for standard processing

◆ m_insertQuery

Query* sptk::CDialog::m_insertQuery
protected

Database interface: The query to insert a new database record

◆ m_keyField

String sptk::CDialog::m_keyField
protected

Database interface: table key field name

◆ m_keyValue

int sptk::CDialog::m_keyValue
protected

Database interface: table key field value for the record to edit

◆ m_modalResult

CDialogModalResult sptk::CDialog::m_modalResult
protected

The result of exiting the modal mode.

◆ m_okButton

CButton* sptk::CDialog::m_okButton
protected

Standard Ok button

◆ m_pages

CDialogTabs* sptk::CDialog::m_pages
protected

The tabs

◆ m_queriesBuilt

bool sptk::CDialog::m_queriesBuilt
protected

Database interface: The flag indicating if queries are created from available controls.

◆ m_selectQuery

Query* sptk::CDialog::m_selectQuery
protected

Database interface: The query to select a database record

◆ m_specialProcessingControls

CControlList sptk::CDialog::m_specialProcessingControls
protected

Database interface: The list of the controls to exclude from standard database queries.

◆ m_tableName

String sptk::CDialog::m_tableName
protected

Database interface: table name

◆ m_updateQuery

Query* sptk::CDialog::m_updateQuery
protected

Database interface: The query to update a database record


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

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