sptk2 logo
SPTK Home Page
CDialog.h
1/*
2╔══════════════════════════════════════════════════════════════════════════════╗
3║ SIMPLY POWERFUL TOOLKIT (SPTK) ║
4╟──────────────────────────────────────────────────────────────────────────────╢
5║ copyright © 1999-2022 Alexey Parshin. All rights reserved. ║
6║ email alexeyp@gmail.com ║
7╚══════════════════════════════════════════════════════════════════════════════╝
8┌──────────────────────────────────────────────────────────────────────────────┐
9│ This library is free software; you can redistribute it and/or modify it │
10│ under the terms of the GNU Library General Public License as published by │
11│ the Free Software Foundation; either version 2 of the License, or (at your │
12│ option) any later version. │
13│ │
14│ This library is distributed in the hope that it will be useful, but │
15│ WITHOUT ANY WARRANTY; without even the implied warranty of │
16│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library │
17│ General Public License for more details. │
18│ │
19│ You should have received a copy of the GNU Library General Public License │
20│ along with this library; if not, write to the Free Software Foundation, │
21│ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. │
22│ │
23│ Please report all bugs and problems to alexeyp@gmail.com. │
24└──────────────────────────────────────────────────────────────────────────────┘
25*/
26
27#pragma once
28
29#include <sptk5/xdoc/Node.h>
30
31#include <sptk5/Strings.h>
32#include <sptk5/gui/CButton.h>
33#include <sptk5/gui/CControlList.h>
34#include <sptk5/gui/CDataControl.h>
35#include <sptk5/gui/CGroup.h>
36#include <sptk5/gui/CScroll.h>
37#include <sptk5/gui/CTabs.h>
38#include <sptk5/gui/CWindow.h>
39
40class Fl_Group;
41
42namespace sptk {
43
44class Query;
45
46class PoolDatabaseConnection;
47
48class CButton;
49
50class CControl;
51
52class CDlgControls;
53
66enum class CDialogModalResult : uint8_t
67{
71 NONE,
72
76 OK,
77
81 CANCEL,
82
86 USER
87
88};
89
96class SP_EXPORT CDialogTabs
97 : public CTabs
98{
99protected:
103 void prepareNewPage(Fl_Group* page, bool autoColor) override;
104
105public:
110 : CTabs("", 10, CLayoutAlign::CLIENT)
111 {
112 }
113};
114
124class SP_EXPORT CDialog
125 : public CWindow
126{
133 void load(const xdoc::SNode& node, CLayoutXMLmode xmlMode) override
134 {
135 CWindow::load(node, xmlMode);
136 }
137
144 void save(const xdoc::SNode& node, CLayoutXMLmode xmlMode) const override
145 {
146 CWindow::save(node, xmlMode);
147 }
148
149protected:
154
159
164
169
174
179
184
189
194
199
204
209
214
219
224
229
234
235
242 virtual bool okPressed();
243
250 virtual bool cancelPressed();
251
257 virtual void scanControls();
258
264 virtual bool buildQueries();
265
273 virtual bool load();
274
282 virtual bool save();
283
284public:
291 CDialog(int w, int h, const char* label = nullptr);
292
296 ~CDialog() override;
297
301 virtual bool reset();
302
308 int handle(int event) override;
309
314 bool showModal();
315
319 void alert(const String& s) const;
320
326
332
337
342 void table(const String& tableName);
343
347 String table() const
348 {
349 return m_tableName;
350 }
351
358 void table(PoolDatabaseConnection* db, const String& tableName, const String& keyFieldName);
359
366 void keyField(const String& keyFieldName);
367
372 {
373 return m_keyField;
374 }
375
379 void keyValue(int val);
380
384 int keyValue() const;
385
392 virtual Fl_Group* newPage(const char* label, bool autoColor);
393
400 virtual Fl_Group* newScroll(const char* label, bool autoColor);
401
411 CButton* addExtraButton(CButtonKind buttonKind, const char* label, Fl_Callback_p callback);
412
416 uint32_t fieldCount() const
417 {
418 return (uint32_t) m_allFields.size();
419 }
420
426 CControl& operator[](const String& fieldName);
427
431 void rescan()
432 {
433 m_queriesBuilt = false;
434 m_controlsScanned = false;
435 }
436
442 void load(const xdoc::SNode& node) override;
443
449 void save(const xdoc::SNode& node) const override;
450
457 {
458 return m_modalResult;
459 }
460
464 String className() const override
465 {
466 return "dialog";
467 }
468};
472} // namespace sptk
Definition: CButton.h:264
List of CControl object pointers in Fl_Group.
Definition: CControlList.h:52
Base class for most of SPTK widgets.
Definition: CControl.h:222
Definition: CDialog.h:98
void prepareNewPage(Fl_Group *page, bool autoColor) override
CDialogTabs()
Default constructor.
Definition: CDialog.h:109
Definition: CDialog.h:126
String m_tableName
Definition: CDialog.h:168
~CDialog() override
CGroup * m_buttonGroup
Definition: CDialog.h:193
bool showModal()
void table(const String &tableName)
virtual bool cancelPressed()
Query * m_updateQuery
Definition: CDialog.h:208
CButton * m_cancelButton
Definition: CDialog.h:158
bool m_queriesBuilt
Definition: CDialog.h:218
String keyField() const
Definition: CDialog.h:371
CControlList m_allFields
Definition: CDialog.h:188
CButton * addExtraButton(CButtonKind buttonKind, const char *label, Fl_Callback_p callback)
int m_keyValue
Definition: CDialog.h:178
virtual Fl_Group * newScroll(const char *label, bool autoColor)
void load(const xdoc::SNode &node) override
virtual void database(PoolDatabaseConnection *db)
bool m_controlsScanned
Definition: CDialog.h:223
CControl & operator[](const String &fieldName)
Index operator to access controls with defined field name.
PoolDatabaseConnection * database() const
void defaultButton(CButton *btn)
CControlList m_specialProcessingControls
Definition: CDialog.h:228
String className() const override
Returns widget class name (internal SPTK RTTI).
Definition: CDialog.h:464
virtual Fl_Group * newPage(const char *label, bool autoColor)
int handle(int event) override
virtual bool okPressed()
virtual void scanControls()
uint32_t fieldCount() const
Definition: CDialog.h:416
void table(PoolDatabaseConnection *db, const String &tableName, const String &keyFieldName)
Fast setup of the database connection.
void keyValue(int val)
virtual bool reset()
String table() const
Definition: CDialog.h:347
Query * m_insertQuery
Definition: CDialog.h:213
CButton * m_defaultButton
Definition: CDialog.h:163
int keyValue() const
CControlList m_defaultFields
Definition: CDialog.h:183
virtual bool load()
void save(const xdoc::SNode &node) const override
virtual bool buildQueries()
CDialog(int w, int h, const char *label=nullptr)
void rescan()
Makes dialog to scan the widgets inside.
Definition: CDialog.h:431
virtual bool save()
String m_keyField
Definition: CDialog.h:173
CDialogTabs * m_pages
Definition: CDialog.h:198
void keyField(const String &keyFieldName)
void alert(const String &s) const
CButton * m_okButton
Definition: CDialog.h:153
CDialogModalResult modalResult() const
Definition: CDialog.h:456
Query * m_selectQuery
Definition: CDialog.h:203
CDialogModalResult m_modalResult
Definition: CDialog.h:233
SPTK group widget.
Definition: CGroup.h:50
Tabs widget.
Definition: CTabs.h:48
Window widget.
Definition: CWindow.h:57
void load(const std::shared_ptr< xdoc::Node > &node, CLayoutXMLmode xmlMode) override
Loads window coordinates and widgets from XML node.
void save(const std::shared_ptr< xdoc::Node > &node, CLayoutXMLmode xmlMode) const override
Saves window coordinates and widgets into XML node.
Definition: PoolDatabaseConnection.h:231
Definition: Query.h:239
Definition: String.h:49
CDialogModalResult
Definition: CDialog.h:67
CLayoutAlign
Definition: CLayoutClient.h:44
CLayoutXMLmode
Definition: CLayoutClient.h:57
CButtonKind
Definition: CButton.h:52
@ CLIENT
Align to the bottom.

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