sptk2 logo
SPTK Home Page
CControl.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_Group.H>
30#include <FL/Fl_Menu_Button.H>
31
32#include <sptk5/db/Query.h>
33#include <sptk5/gui/CEvent.h>
34#include <sptk5/gui/CLayoutClient.h>
35#include <sptk5/xdoc/Node.h>
36
37#include <string>
38
39namespace sptk {
40
49enum class CControlKind : uint32_t
50{
54 UNKNOWN = 0,
55
59 BOX = 1,
60
64 HTMLBOX = 2,
65
69 STRING = 4,
70
74 MEMO = 8,
75
79 INTEGER = 0x10,
80
84 FLOAT = 0x20,
85
89 DATE = 0x40,
90
94 TIME = 0x80,
95
99 DATETIME = 0x100,
100
104 DATEINTERVAL = 0x200,
105
109 COMBO = 0x400,
110
114 INTVALUECOMBO = 0x800,
115
119 LISTBOX = 0x1000,
120
124 CHECKBUTTONS = 0x2000,
125
129 RADIOBUTTONS = 0x4000,
130
134 PHONE = 0x8000,
135
139 TREEVIEW = 0x10000,
140
144 GROUP = 0x20000,
145
149 SLIDER = 0x40000,
150
154 PROGRESS = 0x80000
155
156};
157
161enum class InputEntryFlags : uint32_t
162{
166 NONE = 0,
167
171 SPELLCHECK = 1,
172
176 MANDATORY = 2,
177
181 CFIELD = 4,
182
186 SINGLELINEENTRY = 256,
187
191 MULTILINEENTRY = 512
192
193};
194
198constexpr int SINGLE_EDIT_ENTRY_HEIGHT = 23;
199
200class CDBDropDownList;
201
202class CPackedStrings;
203
204class CColumnList;
205
206class Strings;
207
211SP_EXPORT bool checkFieldName(const String& fldName);
212
219class SP_EXPORT CControl
220 : public ::Fl_Group
221 , public CLayoutClient
222{
223 friend class CInternalComboBoxPanel;
224
225 friend class CEditor;
226
227 friend class CBaseButton;
228
229 friend class CRadioButton;
230
231 friend class CCheckButton;
232
233 friend class CInput_;
234
238 void ctor_init(const char*);
239
240protected:
244 bool m_limited {false};
245
249 uint32_t m_labelWidth {0};
250
254 Fl_Color m_labelColor;
255
259 Fl_Color m_textColor;
260
264 Fl_Font m_textFont;
265
269 uchar m_textSize {0};
270
275
280
284 Fl_Widget* m_control {nullptr};
285
289 int m_tag {0};
290
295 uint32_t m_controlFlags {0};
299 Fl_Menu_Button* m_menuButton {nullptr};
300
305
309 bool m_hasFocus {false};
310
314 bool containsFocus() const;
315
319 void notifyFocus(bool gotFocus = true);
320
324 virtual void onEnter();
325
329 virtual void onExit();
330
334 uint32_t labelHeight() const;
335
339 int handle(int) override;
340
344 static void internalCallback(Fl_Widget* internalWidget, void* data);
345
346public:
353 explicit CControl(const char* label, int layoutSize = 20, CLayoutAlign layoutAlign = CLayoutAlign::TOP);
354
355#ifdef __COMPATIBILITY_MODE__
364 CControl(int, int, int, int, const char* = 0);
365#endif
366
374 void resize(int x, int y, int w, int h) override;
375
379 void draw() override;
380
384 virtual int tag() const
385 {
386 return m_tag;
387 }
388
392 virtual void tag(int t)
393 {
394 m_tag = t;
395 }
396
400#if FL_MAJOR_VERSION < 2
401
402 virtual Fl_Font textFont() const;
403
407 virtual void textFont(Fl_Font);
408
409#else
410
411 virtual Font* textFont() const;
412
416 virtual void textFont(Font*);
417#endif
418
422 virtual uchar textSize() const;
423
427 virtual void textSize(uchar);
428
432 virtual Fl_Color textColor() const;
433
437 virtual void textColor(Fl_Color);
438
442 virtual Fl_Color labelColor() const;
443
447 virtual void labelColor(Fl_Color);
448
452 virtual Fl_Color color() const;
453
457 virtual void color(Fl_Color);
458
462 uint32_t flags() const
463 {
464 return m_controlFlags;
465 }
466
470 void flags(uint32_t flags);
471
475 Fl_Widget* control() const
476 {
477 return m_control;
478 }
479
483 const String& label() const override
484 {
485 return m_label;
486 }
487
491 void label(const String&) override;
492
496 Fl_Menu_* menu() const;
497
501 void menu(const Fl_Menu_Item*);
502
506 Fl_Font labelFont() const
507 {
508 return labelfont();
509 }
510
514 void labelSize(Fl_Font f)
515 {
516 labelfont(f);
517 }
518
522 uchar labelSize() const;
523
527 void labelSize(uchar);
528
532 uint32_t labelWidth() const
533 {
534 return m_labelWidth;
535 }
536
540 void labelWidth(uint32_t);
541
546 void hint(const String& str)
547 {
548 if (m_control)
549 {
550 m_hint = str;
551 m_control->tooltip(m_hint.c_str());
552 }
553 }
554
558 String hint() const
559 {
560 return m_hint;
561 }
562
566 virtual int maxLength() const
567 {
568 return 0;
569 }
570
574 virtual void maxLength(int)
575 {
576 // Implemented in derived classes
577 }
578
582 virtual const String& fieldName() const
583 {
584 return m_fieldName;
585 }
586
590 virtual void fieldName(const String&);
591
595 virtual CControlKind kind() const = 0;
596
600 String className() const override
601 {
602 return "control";
603 }
604
610 virtual void reset()
611 {
612 data(Variant(""));
613 }
614
618 virtual void load(Query*)
619 {
620 // Implemented in derived classes
621 }
622
626 virtual void save(Query*)
627 {
628 // Implemented in derived classes
629 }
630
639 void load(const xdoc::SNode& node, CLayoutXMLmode xmlMode) override;
640
648 void load(const xdoc::SNode& node) override
649 {
650 load(node, CLayoutXMLmode::DATA);
651 }
652
661 void save(const xdoc::SNode& node, CLayoutXMLmode xmlMode) const override;
662
670 virtual void save(const xdoc::SNode& node) const
671 {
672 save(node, CLayoutXMLmode::DATA);
673 }
674
678 virtual bool valid() const = 0;
679
684 virtual Variant data() const
685 {
686 return Variant("");
687 }
688
692 virtual void data(const Variant& v)
693 {
694 // Implemented in derived classes
695 }
696
700 void fireEvent(CEvent ev, int32_t arg);
701
705 const CEventInfo& event() const
706 {
707 return m_event;
708 }
709
714 {
715 return m_event.type();
716 }
717
721 int eventArgument() const
722 {
723 return m_event.argument();
724 }
725
729 static CControlKind controlNameToType(const String& typeName, int& maxLength, const String& values = "");
730
735 {
736 data(str);
737 return *this;
738 }
739
743 CControl& operator=(const char* str)
744 {
745 data(str);
746 return *this;
747 }
748
752 CControl& operator=(int32_t v)
753 {
754 data(v);
755 return *this;
756 }
757
761 CControl& operator=(uint32_t v)
762 {
763 data((int) v);
764 return *this;
765 }
766
770 CControl& operator=(int64_t v)
771 {
772 data(v);
773 return *this;
774 }
775
780 {
781 data(v);
782 return *this;
783 }
784
789 {
790 data(v);
791 return *this;
792 }
793
798 {
799 data(Variant(dt));
800 return *this;
801 }
802
807 {
808 data(fld);
809 return *this;
810 }
811
815 explicit operator String() const
816 {
817 return data().asString();
818 }
819
823 explicit operator int32_t() const
824 {
825 return data().asInteger();
826 }
827
831 explicit operator uint32_t() const
832 {
833 return data().asInteger();
834 }
835
839 explicit operator int64_t() const
840 {
841 return data().asInt64();
842 }
843
847 explicit operator uint64_t() const
848 {
849 return data().asInt64();
850 }
851
855 explicit operator float() const
856 {
857 return (float) data().asFloat();
858 }
859
863 explicit operator double() const
864 {
865 return data().asFloat();
866 }
867
871 explicit operator DateTime() const
872 {
873 return data().asDateTime();
874 }
875
879 static void defaultControlMenuCopy(Fl_Widget*, void*);
880
884 static void defaultControlMenuCut(Fl_Widget*, void*);
885
889 static void defaultControlMenuPaste(Fl_Widget*, void*);
890
894 static void defaultControlMenuClear(Fl_Widget*, void*);
895
899 static const Fl_Menu_Item defaultControlMenu[];
900};
901
911CControl* createControl(CControlKind controlKind, const String& label, const String& fieldName, int layoutSize);
912
938void createControls(const xdoc::SNode& xmlControls);
939
943} // namespace sptk
Definition: CButton.h:96
The check button.
Definition: CCheckButtons.h:49
Definition: CColumn.h:178
Base class for most of SPTK widgets.
Definition: CControl.h:222
String m_hint
Definition: CControl.h:279
virtual Fl_Color textColor() const
Returns the control's text color.
CEventInfo m_event
Definition: CControl.h:304
virtual const String & fieldName() const
Returns control's field name for universal data connection.
Definition: CControl.h:582
uint32_t labelWidth() const
Returns control's label width.
Definition: CControl.h:532
String m_fieldName
Definition: CControl.h:274
void save(const xdoc::SNode &node, CLayoutXMLmode xmlMode) const override
Saves control data to XML.
virtual void save(const xdoc::SNode &node) const
Saves control data to XML.
Definition: CControl.h:670
bool containsFocus() const
Does the control contain focus?
virtual Fl_Color color() const
Returns the control's background color.
static void defaultControlMenuClear(Fl_Widget *, void *)
Default callback function to support CControl default menu item 'Clear'.
CControl & operator=(float v)
Control data assignment.
Definition: CControl.h:779
Fl_Font labelFont() const
Returns control's label font.
Definition: CControl.h:506
CControl & operator=(const String &str)
Control data assignment.
Definition: CControl.h:734
virtual void textSize(uchar)
Sets the control's text font size.
virtual void textFont(Fl_Font)
Sets the control's text font.
void label(const String &) override
Sets control's label.
CControl(const char *label, int layoutSize=20, CLayoutAlign layoutAlign=CLayoutAlign::TOP)
Constructor in SPTK style.
int handle(int) override
Special handle() method.
static void defaultControlMenuPaste(Fl_Widget *, void *)
Default callback function to support CControl default menu item 'Paste'.
Fl_Color m_textColor
Definition: CControl.h:259
virtual Fl_Color labelColor() const
Returns the control's label color.
static void defaultControlMenuCut(Fl_Widget *, void *)
Default callback function to support CControl default menu item 'Delete'.
CEvent eventType() const
Returns the event type for the last fired by this control.
Definition: CControl.h:713
void labelSize(Fl_Font f)
Sets control's label font.
Definition: CControl.h:514
static void internalCallback(Fl_Widget *internalWidget, void *data)
Internal callback function.
CControl & operator=(double v)
Control data assignment.
Definition: CControl.h:788
CControl & operator=(const DateTime &dt)
Control data assignment.
Definition: CControl.h:797
const String & label() const override
Returns control's label.
Definition: CControl.h:483
virtual void load(Query *)
Loads control data from query fields.
Definition: CControl.h:618
virtual Variant data() const
The universal data connector.
Definition: CControl.h:684
static CControlKind controlNameToType(const String &typeName, int &maxLength, const String &values="")
Converts control name to control kind.
const CEventInfo & event() const
Returns the last event fired by this control.
Definition: CControl.h:705
CControl & operator=(uint32_t v)
Control data assignment.
Definition: CControl.h:761
void hint(const String &str)
Sets control's hint (tooltip)
Definition: CControl.h:546
virtual void fieldName(const String &)
Sets control's field name for universal data connection.
virtual void save(Query *)
Saves control data to query params.
Definition: CControl.h:626
CControl & operator=(int32_t v)
Control data assignment.
Definition: CControl.h:752
String className() const override
Returns control's class name (internal SPTK RTTI).
Definition: CControl.h:600
void load(const xdoc::SNode &node) override
Loads control data from XML.
Definition: CControl.h:648
Fl_Widget * control() const
Returns main widget inside the container.
Definition: CControl.h:475
uint32_t labelHeight() const
Computes the label height based on the labelFont() and labelWidth()
void flags(uint32_t flags)
Sets the control's flags.
static void defaultControlMenuCopy(Fl_Widget *, void *)
Default callback function to support CControl default menu item 'Copy'.
virtual void tag(int t)
Sets the control's user data tag.
Definition: CControl.h:392
void notifyFocus(bool gotFocus=true)
Internal focus notification on focus change.
void load(const xdoc::SNode &node, CLayoutXMLmode xmlMode) override
Loads control data from XML.
void menu(const Fl_Menu_Item *)
Sets control's menu.
void fireEvent(CEvent ev, int32_t arg)
Fires the event generated by this control.
uint32_t flags() const
Returns the control's flags.
Definition: CControl.h:462
void labelSize(uchar)
Sets control's label font size.
Fl_Menu_ * menu() const
Returns control's menu.
void draw() override
Draws the control.
virtual int maxLength() const
Returns control's max input length, if applicable.
Definition: CControl.h:566
virtual uchar textSize() const
Returns the control's text font size.
int eventArgument() const
Returns the event argument for the last fired by this control.
Definition: CControl.h:721
Fl_Font m_textFont
Definition: CControl.h:264
CControl & operator=(const Field &fld)
Control data assignment.
Definition: CControl.h:806
virtual void labelColor(Fl_Color)
Sets the control's label color.
uchar labelSize() const
Returns control's label font size.
virtual int tag() const
Returns the control's user data tag.
Definition: CControl.h:384
virtual void color(Fl_Color)
Sets the control's background color.
String hint() const
Returns control's hint (tooltip)
Definition: CControl.h:558
void labelWidth(uint32_t)
Sets control's label width.
CControl & operator=(int64_t v)
Control data assignment.
Definition: CControl.h:770
virtual void reset()
Sets the control to empty text (for the input entries)
Definition: CControl.h:610
virtual void textColor(Fl_Color)
Sets the control's text color.
virtual CControlKind kind() const =0
Returns control's kind (internal SPTK RTTI).
Fl_Color m_labelColor
Definition: CControl.h:254
virtual void maxLength(int)
Sets control's max input length, if applicable.
Definition: CControl.h:574
CControl & operator=(const char *str)
Control data assignment.
Definition: CControl.h:743
virtual Fl_Font textFont() const
Returns the control's text font.
virtual void data(const Variant &v)
The universal data connector, sets control data.
Definition: CControl.h:692
void resize(int x, int y, int w, int h) override
Resizes the control and inside widgets.
virtual bool valid() const =0
Returns true if the control state is valid, and the data is inside the limits (if applicable)
virtual void onExit()
Internal focus notification on focus change.
virtual void onEnter()
Internal focus notification on focus change.
Drop-down window with CListView widget inside.
Definition: CDropDownBox.h:95
Text editor widget.
Definition: CEditor.h:50
Definition: CEvent.h:148
int32_t argument() const
Definition: CEvent.h:193
CEvent type() const
Definition: CEvent.h:185
Definition: CInput.h:56
Definition: CLayoutClient.h:82
Packed strings list.
Definition: PackedStrings.h:58
Definition: DateTime.h:86
Definition: Field.h:54
Definition: Query.h:239
Definition: String.h:49
Definition: Strings.h:52
Definition: Variant.h:372
void createControls(const xdoc::SNode &xmlControls)
Create a control or a group of controls.
InputEntryFlags
Special control flags (used as bit combination)
Definition: CControl.h:162
CControlKind
Control kind is the constant to report the internal SPTK RTTI.
Definition: CControl.h:50
CLayoutAlign
Definition: CLayoutClient.h:44
CEvent
Definition: CEvent.h:42
CLayoutXMLmode
Definition: CLayoutClient.h:57
CControl * createControl(CControlKind controlKind, const String &label, const String &fieldName, int layoutSize)
Creates a single control.
SP_EXPORT bool checkFieldName(const String &fldName)
Internal field name validation.
constexpr int SINGLE_EDIT_ENTRY_HEIGHT
Default height for the single-row edit control.
Definition: CControl.h:198
@ TOP
Align to the right.

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