CheckBox.h
1 
2 /* Copyright (C) 2016 Marc Boris Duerner
3  Copyright (C) 2016 Laurentiu-Gheorghe Crisan
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  As a special exception, you may use this file as part of a free
11  software library without restriction. Specifically, if other files
12  instantiate templates or use macros or inline functions from this
13  file, or you compile this file and link it with other files to
14  produce an executable, this file does not by itself cause the
15  resulting executable to be covered by the GNU General Public
16  License. This exception does not however invalidate any other
17  reasons why the executable file might be covered by the GNU Library
18  General Public License.
19 
20  This library is distributed in the hope that it will be useful,
21  but WITHOUT ANY WARRANTY; without even the implied warranty of
22  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23  Lesser General Public License for more details.
24 
25  You should have received a copy of the GNU Lesser General Public
26  License along with this library; if not, write to the Free Software
27  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
28  MA 02110-1301 USA
29 */
30 
31 #ifndef Pt_Forms_CheckBox_h
32 #define Pt_Forms_CheckBox_h
33 
34 #include <Pt/Forms/Button.h>
35 #include <Pt/SmartPtr.h>
36 
37 namespace Pt {
38 
39 namespace Forms {
40 
41 class PT_FORMS_API CheckBox : public Button
42 {
43  public:
44  typedef Button Base;
45 
46  enum State
47  {
48  Unspecified = 0,
49  Checked = 1,
50  Unchecked = 2
51  // Partial
52  };
53 
54  public:
55  CheckBox();
56 
57  virtual ~CheckBox();
58 
59  State state() const;
60 
61  void setState(State s);
62 
63  bool isChecked() const;
64 
65  public:
66  const Gfx::Brush& background() const;
67 
68  void setBackground(const Gfx::Brush& b);
69 
70  const Gfx::Pen& contour() const;
71 
72  void setContour(const Gfx::Pen& p);
73 
74  const Gfx::Color& textColor() const;
75 
76  void setTextColor(const Gfx::Color& color);
77 
78  const Gfx::Font& font() const;
79 
80  void setFont(const Gfx::Font& font);
81 
82  void setFontSize(std::size_t size);
83 
84  void setFontWeight(Gfx::Font::Weight weight);
85 
86  void setFontSlant(Gfx::Font::Slant slant);
87 
88  void setRenderer(CheckBoxRenderer* renderer);
89 
90  protected:
91  virtual Gfx::SizeF onMeasure(const SizePolicy& policy);
92 
93  virtual void onInvalidate();
94 
95  virtual void onPressed();
96 
97  virtual void onReleased();
98 
99  virtual void onCanceled();
100 
101  protected:
102  virtual void onPaint(PaintSurface& surface, const Gfx::RectF& updateRect);
103 
104  private:
105  Gfx::Font getFont() const;
106 
107  private:
108  enum FontOverride : unsigned
109  {
110  OverrideSize = 0x01,
111  OverrideWeight = 0x02,
112  OverrideSlant = 0x04,
113  OverrideAll = 0xFF
114  };
115 
116  State _state;
117 
118  FacetPtr<CheckBoxRenderer> _renderer;
119  bool _hasRenderer;
120 
121  AutoPtr<Gfx::Brush> _background;
122  AutoPtr<Gfx::Pen> _contour;
123  AutoPtr<Gfx::Color> _textColor;
124  Gfx::Font _customFont;
125  unsigned _fontOverride;
126 
127  Gfx::Brush _brush;
128  Gfx::Pen _pen;
129  Gfx::Pen _textPen;
130  Gfx::Font _font;
131  Gfx::SizeF _boxSize;
132 };
133 
134 } // namespace
135 
136 } // namespace
137 
138 #endif