sptk2 logo
SPTK Home Page
CComboBox.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 <FL/Fl_Box.H>
30#include <FL/Fl_Button.H>
31
32#include <sptk5/db/PoolDatabaseConnection.h>
33#include <sptk5/db/Query.h>
34#include <sptk5/gui/CControl.h>
35#include <sptk5/gui/CDBListView.h>
36
37namespace sptk {
38
44class CInternalComboBoxPanel;
45
46class CDBListView;
47
54class SP_EXPORT CBaseListBox
55 : public CControl
56{
57 friend class CInternalComboBoxPanel;
58
62 Fl_Callback_p m_buttonClicked;
63
67 std::array<Fl_Button*, 5> m_buttons;
68
72 bool m_droppedDown;
73
77 uint32_t m_buttonSet;
78
82 int m_mode;
83
87 void changeControlData(int changeType, int intData = 0, std::string stringData = "");
88
92 void ctor_init(const char* label, int _mode);
93
97 static void comboButtonPressed(Fl_Widget* btn, void* data);
98
99protected:
100
105
110
115
116
120 virtual void dropDownList();
121
125 void load(Query*) override;
126
130 void save(Query*) override;
131
140 void load(const xdoc::SNode& node, CLayoutXMLmode xmlMode) override;
141
150 void save(const xdoc::SNode& node, CLayoutXMLmode xmlMode) const override;
151
155 bool valid() const override
156 {
157 return true;
158 }
159
167 CBaseListBox(const char* label, int layoutSize, CLayoutAlign layoutAlign, int mode);
168
169#ifdef __COMPATIBILITY_MODE__
179 CBaseListBox(int x,int y,int w,int h,const char *label,int mode);
180#endif
181
185 ~CBaseListBox() override;
186
190 virtual void button_handle(uint32_t theButtonKind);
191
192public:
193
197 virtual void clear();
198
202 uint32_t buttons() const
203 {
204 return m_buttonSet;
205 }
206
210 void buttons(uint32_t);
211
215 Fl_Callback_p buttonClicked() const
216 {
217 return m_buttonClicked;
218 }
219
223 void buttonClicked(Fl_Callback* c)
224 {
225 m_buttonClicked = c;
226 }
227
233 void columns(const CColumnList& columnList);
234
240
248 void addColumn(std::string cname, VariantDataType type = VariantDataType::VAR_STRING, int16_t cwidth = 70,
249 bool cvisible = true);
250
258
265 void addRow(int rowId, const Strings& strings);
266
274 void addRows(std::string columnName, Strings rows);
275
283 void resize(int x, int y, int w, int h) override;
284
288 Variant data() const override;
289
293 void data(const Variant& v) override;
294
301 {
302 m_list->dataMode(dm);
303 }
304
310 {
311 return m_list->dataMode();
312 }
313
320 {
321 return m_list->findCaption(caption);
322 }
323
329 CPackedStrings* findKey(int keyValue)
330 {
331 return m_list->findKey(keyValue);
332 }
333
338
343
347 String sql() const;
348
353 void sql(std::string s);
354
358 std::string keyField() const;
359
364 void keyField(std::string keyFieldName);
365
369 int sortColumn() const;
370
374 void sort()
375 {
376 m_list->sort();
377 }
378
383 void sortColumn(int sortColumn);
384
391 void setup(PoolDatabaseConnection* db, std::string sql, std::string keyField);
392
399 QueryParameter& param(const char* paramName);
400
406
415 int findString(const std::string& str, bool select = true, uint32_t startRow = 0, unsigned endRow = 0);
416
421
426 void selectRow(unsigned rowNumber);
427
432
437
441 unsigned size() const;
442
449 bool preferredSize(int& w, int& h) override;
450};
451
459class SP_EXPORT CComboBox
460 : public CBaseListBox
461{
462public:
469 CComboBox(const char* label = nullptr, int layoutSize = 10, CLayoutAlign layoutAlign = CLayoutAlign::TOP);
470
471#ifdef __COMPATIBILITY_MODE__
480 CComboBox(int x,int y,int w,int h,const char *label = 0);
481#endif
482
486 ~CComboBox() override;
487
493 CControlKind kind() const override;
494
499 String className() const override
500 {
501 return "combo_box";
502 }
503
507 static CLayoutClient* creator(const xdoc::SNode& node);
508};
509
517class SP_EXPORT CListBox
518 : public CBaseListBox
519{
520public:
527 CListBox(const char* label = nullptr, int layoutSize = 10, CLayoutAlign layoutAlign = CLayoutAlign::TOP);
528
529#ifdef __COMPATIBILITY_MODE__
538 CListBox(int,int,int,int,const char * = 0);
539#endif
540
546 CControlKind kind() const override
547 {
549 }
550
555 String className() const override
556 {
557 return "list_box";
558 }
559};
563}
Base list box widget.
Definition: CComboBox.h:56
void columns(const CColumnList &columnList)
CDBListView * m_list
Definition: CComboBox.h:109
int m_buttonSpace
Definition: CComboBox.h:114
Variant data() const override
~CBaseListBox() override
int findString(const std::string &str, bool select=true, uint32_t startRow=0, unsigned endRow=0)
CPackedStrings * findKey(int keyValue)
Definition: CComboBox.h:329
virtual void dropDownList()
String sql() const
CListViewDataMode dataMode()
Definition: CComboBox.h:309
unsigned size() const
PoolDatabaseConnection * database() const
void save(Query *) override
Saves data to the Query.
bool preferredSize(int &w, int &h) override
CColumnList & columns()
void addRows(std::string columnName, Strings rows)
CPackedStrings * findCaption(const String &caption)
Definition: CComboBox.h:319
void buttonClicked(Fl_Callback *c)
Definition: CComboBox.h:223
void addRow(CPackedStrings *row)
void buttons(uint32_t)
void load(Query *) override
Loads data from the Query.
virtual void button_handle(uint32_t theButtonKind)
bool valid() const override
Definition: CComboBox.h:155
void dataMode(CListViewDataMode dm)
Definition: CComboBox.h:300
void sort()
Definition: CComboBox.h:374
void resize(int x, int y, int w, int h) override
void sortColumn(int sortColumn)
void selectRow(unsigned rowNumber)
QueryParameter & param(const char *paramName)
void save(const xdoc::SNode &node, CLayoutXMLmode xmlMode) const override
Saves control data to XML.
CPackedStrings * selectedRow() const
void load(const xdoc::SNode &node, CLayoutXMLmode xmlMode) override
Loads control data from XML.
uint32_t buttons() const
Definition: CComboBox.h:202
void database(PoolDatabaseConnection *db)
std::string keyField() const
CBaseListBox(const char *label, int layoutSize, CLayoutAlign layoutAlign, int mode)
int sortColumn() const
void keyField(std::string keyFieldName)
virtual void clear()
CDBDropDownList * m_dropDownWindow
Definition: CComboBox.h:104
void setup(PoolDatabaseConnection *db, std::string sql, std::string keyField)
void addRow(int rowId, const Strings &strings)
void addColumn(std::string cname, VariantDataType type=VariantDataType::VAR_STRING, int16_t cwidth=70, bool cvisible=true)
void data(const Variant &v) override
Fl_Callback_p buttonClicked() const
Definition: CComboBox.h:215
void sql(std::string s)
Definition: CColumn.h:178
Combo box widget.
Definition: CComboBox.h:461
CControlKind kind() const override
static CLayoutClient * creator(const xdoc::SNode &node)
Creates a combo box based on the XML node information.
CComboBox(const char *label=nullptr, int layoutSize=10, CLayoutAlign layoutAlign=CLayoutAlign::TOP)
~CComboBox() override
String className() const override
Definition: CComboBox.h:499
Base class for most of SPTK widgets.
Definition: CControl.h:222
Drop-down window with CListView widget inside.
Definition: CDropDownBox.h:95
List view widget with extended database support.
Definition: CDBListView.h:45
Definition: CLayoutClient.h:82
List Box widget.
Definition: CComboBox.h:519
String className() const override
Definition: CComboBox.h:555
CControlKind kind() const override
Definition: CComboBox.h:546
CListBox(const char *label=nullptr, int layoutSize=10, CLayoutAlign layoutAlign=CLayoutAlign::TOP)
CPackedStrings * findCaption(const String &caption)
Finds an item with the caption (a string in the first column).
CPackedStrings * findKey(int keyValue)
Finds an item with the key (an integer associated with the item - argument()).
void sort()
Sorts ListView rows using existing information about sort column and direction.
Definition: CListView.h:1114
void dataMode(CListViewDataMode dm)
Definition: CListView.h:665
Packed strings list.
Definition: PackedStrings.h:58
Definition: PoolDatabaseConnection.h:231
Definition: QueryParameter.h:44
Definition: Query.h:239
Definition: String.h:49
Definition: Strings.h:52
Definition: Variant.h:372
CControlKind
Control kind is the constant to report the internal SPTK RTTI.
Definition: CControl.h:50
CLayoutAlign
Definition: CLayoutClient.h:44
CLayoutXMLmode
Definition: CLayoutClient.h:57
CListViewDataMode
The data mode for the data() methods.
Definition: CListView.h:76
@ TOP
Align to the right.
VariantDataType
Definition: VariantData.h:44
@ VAR_STRING
String pointer.

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