sptk2 logo
SPTK Home Page
CInput.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_Input.H>
30
31#include <sptk5/gui/CControl.h>
32#include <sptk5/gui/CLayoutClient.h>
33#include <sptk5/sptk.h>
34
35#include <string>
36
37namespace sptk {
38
53class SP_EXPORT CInput_
54 : public Fl_Input
55 , public CLayoutClient
56{
57
61 int m_maxLength;
62
66 std::string m_mask;
67
71 std::string m_inputMask;
72
76 std::string m_backgroundMask;
77
78
82 bool checkCharacterAtPos(int pos, char key);
83
87 bool checkCharacter(int pos, char& key);
88
89protected:
94 void maskValue();
95
96public:
103 CInput_(const char* label = 0, int layoutSize = 20, CLayoutAlign layoutAlign = CLayoutAlign::TOP);
104
105#ifdef __COMPATIBILITY_MODE__
114 CInput_(int x, int y, int w, int h, const char* label = 0);
115#endif
116
122 int handle(int event) override;
123
127 uchar textSize() const
128 {
129 return (uchar) textsize();
130 }
131
135 void textSize(uchar sz)
136 {
137 textsize(sz);
138 }
139
143 Fl_Font textFont() const
144 {
145 return textfont();
146 }
147
151 void textFont(Fl_Font fnt)
152 {
153 textfont(fnt);
154 }
155
159 int maxLength() const
160 {
161 return m_maxLength;
162 }
163
167 void maxLength(int ml)
168 {
169 m_maxLength = ml;
170 }
171
178 bool preferredSize(int& w, int& h) override;
179
184 void mask(const char* maskString);
185};
186
195class SP_EXPORT CInput
196 : public CControl
197{
198
202 void ctor_init(bool autoCreate);
203
204protected:
208 void load(Query*) override;
209
213 void save(Query*) override;
214
223 void load(const xdoc::SNode& node, CLayoutXMLmode xmlMode) override
224 {
225 CControl::load(node, xmlMode);
226 }
227
236 void save(const xdoc::SNode& node, CLayoutXMLmode xmlMode) const override
237 {
238 CControl::save(node, xmlMode);
239 }
240
244 bool valid() const override
245 {
246 return true;
247 }
248
256 CInput(const char* label, int layoutSize, CLayoutAlign layoutAlign, bool autoCreate);
257
258public:
265 CInput(const char* label = 0, int layoutSize = 10, CLayoutAlign layoutAlign = CLayoutAlign::TOP);
266
267#ifdef __COMPATIBILITY_MODE__
276 CInput(int, int, int, int, const char* = 0, bool autoCreate = true);
277#endif
278
282 ~CInput() override;
283
287 int controlType() const;
288
292 void controlType(int type);
293
297 Variant data() const override;
298
302 void data(const Variant& v) override;
303
308 CControlKind kind() const override
309 {
311 }
312
316 String className() const override
317 {
318 return "input";
319 }
320
324 Fl_Font textFont() const override;
325
329 void textFont(Fl_Font f) override;
330
334 uchar textSize() const override;
335
339 void textSize(uchar s) override;
340
344 int maxLength() const override;
345
349 void maxLength(int) override;
350
355 virtual void preferredWidth(int& w) const;
356
361 virtual void preferredHeight(int& h) const;
362
369 bool preferredSize(int& w, int& h) override;
370
374 static CLayoutClient* creator(const xdoc::SNode& node);
375};
379}
Base class for most of SPTK widgets.
Definition: CControl.h:222
virtual void load(Query *)
Loads control data from query fields.
Definition: CControl.h:618
virtual void save(Query *)
Saves control data to query params.
Definition: CControl.h:626
Definition: CInput.h:56
Fl_Font textFont() const
Definition: CInput.h:143
bool preferredSize(int &w, int &h) override
int maxLength() const
Definition: CInput.h:159
int handle(int event) override
void textFont(Fl_Font fnt)
Definition: CInput.h:151
void mask(const char *maskString)
void textSize(uchar sz)
Definition: CInput.h:135
uchar textSize() const
Definition: CInput.h:127
void maskValue()
CInput_(const char *label=0, int layoutSize=20, CLayoutAlign layoutAlign=CLayoutAlign::TOP)
void maxLength(int ml)
Definition: CInput.h:167
Definition: CInput.h:197
static CLayoutClient * creator(const xdoc::SNode &node)
bool valid() const override
Definition: CInput.h:244
virtual void preferredWidth(int &w) const
Variant data() const override
int maxLength() const override
void load(Query *) override
void save(Query *) override
void data(const Variant &v) override
void textFont(Fl_Font f) override
String className() const override
Definition: CInput.h:316
Fl_Font textFont() const override
void save(const xdoc::SNode &node, CLayoutXMLmode xmlMode) const override
Definition: CInput.h:236
CInput(const char *label=0, int layoutSize=10, CLayoutAlign layoutAlign=CLayoutAlign::TOP)
virtual void preferredHeight(int &h) const
void maxLength(int) override
void load(const xdoc::SNode &node, CLayoutXMLmode xmlMode) override
Definition: CInput.h:223
int controlType() const
CInput(const char *label, int layoutSize, CLayoutAlign layoutAlign, bool autoCreate)
void textSize(uchar s) override
CControlKind kind() const override
Definition: CInput.h:308
bool preferredSize(int &w, int &h) override
uchar textSize() const override
void controlType(int type)
~CInput() override
Definition: CLayoutClient.h:82
Definition: Query.h:239
Definition: String.h:49
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
@ TOP
Align to the right.

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