sptk2 logo
SPTK Home Page
CButton.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/gui/CIcon.h>
30#include <sptk5/gui/CLayoutClient.h>
31#include <sptk5/gui/CThemes.h>
32#include <sptk5/sptk.h>
33#include <string>
34
35#include <FL/Fl_Button.H>
36
37class Fl_Image;
38
39namespace sptk {
40
51enum class CButtonKind : uint32_t
52{
54 OK_BUTTON = 1,
55 CANCEL_BUTTON = 2,
56 NO_BUTTON = 4,
57 ADD_BUTTON = 8,
58 DELETE_BUTTON = 0x10,
59 EDIT_BUTTON = 0x20,
60 BROWSE_BUTTON = 0x40,
61 REFRESH_BUTTON = 0x80,
62 CALENDAR_BUTTON = 0x100,
63 OPEN_BUTTON = 0x200,
64 PRINT_BUTTON = 0x400,
65 SAVE_BUTTON = 0x800,
66 SAVE_AS_BUTTON = 0x1000,
67 COPY_BUTTON = 0x2000,
68 LEFT_BUTTON = 0x4000,
69 NEW_BUTTON = 0x8000,
70 NEXT_BUTTON = 0x10000,
71 PRINTER_BUTTON = 0x20000,
72 PRIOR_BUTTON = 0x40000,
73 RIGHT_BUTTON = 0x80000,
74 SEARCH_BUTTON = 0x100000,
75 SEND_BUTTON = 0x200000,
76 STEPLEFT_BUTTON = 0x400000,
77 STEPRIGHT_BUTTON = 0x800000,
78 VIEW_BUTTON = 0x1000000,
79 HOME_BUTTON = 0x2000000,
80 CONFIGURE_BUTTON = 0x4000000,
81 EXEC_BUTTON = 0x8000000,
82 STOP_BUTTON = 0x10000000,
83 EXIT_BUTTON = 0x20000000,
84 HELP_BUTTON = 0x40000000,
85 MAX_BUTTON = 0x40000001
86};
87
93class SP_EXPORT CBaseButton
94 : public Fl_Button
95 , public CLayoutClient
96{
97 friend class CThemes;
98
99 bool m_default;
100 CThemeButtonType m_type;
102 Fl_Image* m_image {nullptr};
104
112 static void drawFocusLine(int xs, int ys, int xe, int ye);
113
114protected:
121 void image(CButtonKind buttonKind, CIconSize iconSize, String label = "");
122
126 void draw() override;
127
132 void drawFocus(bool usingTheme);
133
137 int handle(int event) override;
138
145 bool preferredSize(int& w, int& h) override;
146
155 CBaseButton(CButtonKind kind, CLayoutAlign layoutAlign = CLayoutAlign::RIGHT, bool is_small = false,
156 const char* label = nullptr, CThemeButtonType tbt = THM_BUTTON_NORMAL);
157
164 CBaseButton(const char* label = nullptr, CLayoutAlign layoutAlign = CLayoutAlign::RIGHT,
165 CThemeButtonType tbt = THM_BUTTON_NORMAL);
166
167#ifdef __COMPATIBILITY_MODE__
178 CBaseButton(CButtonKind kind, int x, int y, int w, const char* l = 0, CThemeButtonType tbt = THM_BUTTON_NORMAL);
179#endif
180
181public:
191 void defaultButton(bool defaultBtn);
192
197 bool defaultButton() const
198 {
199 return m_default;
200 }
201
205 String className() const override
206 {
207 return "button";
208 }
209
216 {
217 image(bkind, iconSize, label());
218 }
219
224 virtual void buttonImage(Fl_Image* image)
225 {
226 m_image = image;
227 }
228
233 virtual const Fl_Image* buttonImage() const
234 {
235 return m_image;
236 }
237
242 const String& label() const override
243 {
244 return m_label;
245 }
246
251 void label(const String& lbl) override
252 {
253 m_label = lbl;
254 }
255};
256
262class SP_EXPORT CButton
263 : public CBaseButton
264{
265public:
266#ifdef __COMPATIBILITY_MODE__
276 CButton(CButtonKind kind, int x, int y, int w, const char* label = 0, CThemeButtonType tbt = THM_BUTTON_NORMAL)
277 : CBaseButton(kind, x, y, w, label, tbt)
278 {
279 }
280#endif
281
289 CButton(CButtonKind kind, CLayoutAlign layoutAlign = CLayoutAlign::RIGHT, const char* label = "",
290 CThemeButtonType tbt = THM_BUTTON_NORMAL)
291 : CBaseButton(kind, layoutAlign, false, label, tbt)
292 {
293 }
294
301 CButton(const char* label = "", CLayoutAlign layoutAlign = CLayoutAlign::RIGHT,
302 CThemeButtonType tbt = THM_BUTTON_NORMAL)
303 : CBaseButton(label, layoutAlign, tbt)
304 {
305 }
306
310 static CLayoutClient* creator(const xdoc::SNode& node);
311
320 void load(const std::shared_ptr<xdoc::Node>& node, CLayoutXMLmode xmlMode) override
321 {
322 load(node);
323 }
324
332 void load(const xdoc::SNode& node) override;
333
342 void save(const std::shared_ptr<xdoc::Node>& node, CLayoutXMLmode lm = CLayoutXMLmode::LAYOUT) const override;
343};
344
351class SP_EXPORT CSmallButton
352 : public CBaseButton
353{
354public:
355#ifdef __COMPATIBILITY_MODE__
365 CSmallButton(CButtonKind kind, int x, int y, int w, const char* label = 0)
366 : CBaseButton(kind, x, y, w, label, THM_BUTTON_COMBO)
367 {
368 }
369#endif
370
377 CSmallButton(CButtonKind kind, CLayoutAlign layoutAlign = CLayoutAlign::RIGHT, const char* label = nullptr)
378 : CBaseButton(kind, layoutAlign, true, label, THM_BUTTON_COMBO)
379 {
380 }
381};
385} // namespace sptk
Definition: CButton.h:96
const String & label() const override
Definition: CButton.h:242
virtual void buttonImage(CButtonKind bkind, CIconSize iconSize=CIconSize::IS_LARGE_ICON)
Definition: CButton.h:215
bool defaultButton() const
Definition: CButton.h:197
CBaseButton(CButtonKind kind, CLayoutAlign layoutAlign=CLayoutAlign::RIGHT, bool is_small=false, const char *label=nullptr, CThemeButtonType tbt=THM_BUTTON_NORMAL)
void image(CButtonKind buttonKind, CIconSize iconSize, String label="")
String className() const override
Definition: CButton.h:205
void drawFocus(bool usingTheme)
bool preferredSize(int &w, int &h) override
virtual void buttonImage(Fl_Image *image)
Definition: CButton.h:224
void label(const String &lbl) override
Definition: CButton.h:251
void draw() override
void defaultButton(bool defaultBtn)
CBaseButton(const char *label=nullptr, CLayoutAlign layoutAlign=CLayoutAlign::RIGHT, CThemeButtonType tbt=THM_BUTTON_NORMAL)
virtual const Fl_Image * buttonImage() const
Definition: CButton.h:233
int handle(int event) override
Definition: CButton.h:264
CButton(const char *label="", CLayoutAlign layoutAlign=CLayoutAlign::RIGHT, CThemeButtonType tbt=THM_BUTTON_NORMAL)
Definition: CButton.h:301
void save(const std::shared_ptr< xdoc::Node > &node, CLayoutXMLmode lm=CLayoutXMLmode::LAYOUT) const override
CButton(CButtonKind kind, CLayoutAlign layoutAlign=CLayoutAlign::RIGHT, const char *label="", CThemeButtonType tbt=THM_BUTTON_NORMAL)
Definition: CButton.h:289
void load(const xdoc::SNode &node) override
static CLayoutClient * creator(const xdoc::SNode &node)
void load(const std::shared_ptr< xdoc::Node > &node, CLayoutXMLmode xmlMode) override
Definition: CButton.h:320
Definition: CLayoutClient.h:82
Definition: CButton.h:353
CSmallButton(CButtonKind kind, CLayoutAlign layoutAlign=CLayoutAlign::RIGHT, const char *label=nullptr)
Definition: CButton.h:377
Widget themes.
Definition: CThemes.h:69
Definition: String.h:49
CLayoutAlign
Definition: CLayoutClient.h:44
CLayoutXMLmode
Definition: CLayoutClient.h:57
CThemeButtonType
Theme button size - defines the button size and look to select the correct pixmap.
Definition: CThemes.h:54
CButtonKind
Definition: CButton.h:52
CIconSize
Icon size variations.
Definition: CIcon.h:45
@ RIGHT
Align to the left.
@ HOME_BUTTON
'Home' button
@ STEPRIGHT_BUTTON
'Step Right' button
@ SEND_BUTTON
'Send' button
@ SAVE_AS_BUTTON
'Save As' button
@ STOP_BUTTON
'Stop' button
@ STEPLEFT_BUTTON
'Step Left' button
@ OK_BUTTON
'Ok' button
@ CALENDAR_BUTTON
'Calendar' button
@ EDIT_BUTTON
'Edit' button
@ NEXT_BUTTON
'Next' button
@ UNDEFINED_BUTTON
Default button without image, or with user-defined image.
@ BROWSE_BUTTON
'Browse' button
@ SAVE_BUTTON
'Save' button
@ VIEW_BUTTON
'View' button
@ CANCEL_BUTTON
'Cancel' button
@ PRINTER_BUTTON
'Printer' button
@ RIGHT_BUTTON
'Right' button
@ HELP_BUTTON
'Help' button
@ EXIT_BUTTON
'Exit' button
@ SEARCH_BUTTON
'Left' button
@ CONFIGURE_BUTTON
'Configure' button
@ MAX_BUTTON
Max button id.
@ COPY_BUTTON
'Copy' button
@ NEW_BUTTON
'New' button
@ OPEN_BUTTON
'Open' button
@ EXEC_BUTTON
Execute' button.
@ PRIOR_BUTTON
'Prior' button
@ PRINT_BUTTON
'Print' button
@ LEFT_BUTTON
'Left' button
@ REFRESH_BUTTON
'Refresh' button
@ DELETE_BUTTON
'Delete' button
@ NO_BUTTON
'No' button
@ ADD_BUTTON
'Add' button

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