Update list of wide characters
[centerim5.git] / cppconsui / Button.h
blob61cb98ba7cfe2e7bdeee9a2347e99e18bfa2f5e1
1 // Copyright (C) 2007 Mark Pustjens <pustjens@dds.nl>
2 // Copyright (C) 2010-2015 Petr Pavlu <setup@dagobah.cz>
3 //
4 // This file is part of CenterIM.
5 //
6 // CenterIM is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // CenterIM is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with CenterIM. If not, see <http://www.gnu.org/licenses/>.
19 /// @file
20 /// Button class.
21 ///
22 /// @ingroup cppconsui
24 #ifndef BUTTON_H
25 #define BUTTON_H
27 #include "Widget.h"
29 namespace CppConsUI {
31 /// This class implements a simple button behaviour.
32 ///
33 /// The button does not keep states like pressed or not and it can call back one
34 /// (or more) functions when pressed.
35 class Button : public Widget {
36 public:
37 enum Flag {
38 FLAG_VALUE = 1 << 0,
39 FLAG_UNIT = 1 << 1,
40 FLAG_RIGHT = 1 << 2,
43 Button(int w, int h, const char *text = nullptr, int flags = 0,
44 bool masked = false);
45 explicit Button(
46 const char *text = nullptr, int flags = 0, bool masked = false);
47 Button(int w, int h, int flags = 0, const char *text = nullptr,
48 const char *value = nullptr, const char *unit = nullptr,
49 const char *right = nullptr, bool masked = false);
50 Button(int flags, const char *text = nullptr, const char *value = nullptr,
51 const char *unit = nullptr, const char *right = nullptr,
52 bool masked = false);
53 virtual ~Button() override;
55 // Widget
56 virtual int draw(Curses::ViewPort area, Error &error) override;
58 virtual void setFlags(int new_flags);
59 virtual int getFlags() const { return flags_; }
61 /// Sets a new text and redraws itself.
62 virtual void setText(const char *new_text);
64 /// Returns previously set text.
65 virtual const char *getText() const { return text_; }
67 virtual void setValue(const char *new_value);
68 virtual void setValue(int new_value);
69 virtual const char *getValue() const { return value_; }
71 virtual void setUnit(const char *new_unit);
72 virtual const char *getUnit() const { return unit_; }
74 virtual void setRight(const char *new_right);
75 virtual const char *getRight() const { return right_; }
77 virtual void setMasked(bool new_masked);
78 virtual bool isMasked() const { return masked_; }
80 /// Signal emitted when the button is pressed/activated.
81 sigc::signal<void, Button &> signal_activate;
83 protected:
84 int flags_;
86 char *text_;
87 int text_width_;
88 int text_height_;
90 char *value_;
91 int value_width_;
93 char *unit_;
94 int unit_width_;
96 char *right_;
97 int right_width_;
99 bool masked_;
101 private:
102 CONSUI_DISABLE_COPY(Button);
104 void actionActivate();
106 void declareBindables();
109 } // namespace CppConsUI
111 #endif // BUTTON_H
113 // vim: set tabstop=2 shiftwidth=2 textwidth=80 expandtab: