ComboBox.h
1 /* Copyright (C) 2017 Marc Boris Duerner
2 
3  This library is free software; you can redistribute it and/or
4  modify it under the terms of the GNU Lesser General Public
5  License as published by the Free Software Foundation; either
6  version 2.1 of the License, or (at your option) any later version.
7 
8  As a special exception, you may use this file as part of a free
9  software library without restriction. Specifically, if other files
10  instantiate templates or use macros or inline functions from this
11  file, or you compile this file and link it with other files to
12  produce an executable, this file does not by itself cause the
13  resulting executable to be covered by the GNU General Public
14  License. This exception does not however invalidate any other
15  reasons why the executable file might be covered by the GNU Library
16  General Public License.
17 
18  This library is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  Lesser General Public License for more details.
22 
23  You should have received a copy of the GNU Lesser General Public
24  License along with this library; if not, write to the Free Software
25  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
26  MA 02110-1301 USA
27 */
28 
29 #ifndef Pt_Forms_ComboBox_H
30 #define Pt_Forms_ComboBox_H
31 
32 #include <Pt/Forms/Control.h>
33 #include <Pt/Forms/Popup.h>
34 #include <Pt/Forms/ListBox.h>
35 #include <Pt/Forms/LineEditor.h>
36 #include <Pt/SmartPtr.h>
37 #include <Pt/String.h>
38 
39 namespace Pt {
40 
41 namespace Forms {
42 
43 class PT_FORMS_API ComboBox : public Control
44 {
45  typedef Control Base;
46 
47  public:
48  ComboBox();
49 
50  virtual ~ComboBox();
51 
52  void addItem(ListBoxItem& item);
53 
54  void removeItem(ListBoxItem& item);
55 
56  bool isEditable() const;
57 
58  void setEditable(bool e);
59 
60  bool isAccepted() const;
61 
62  void setAccepted(bool a);
63 
64  const Pt::String& text() const;
65 
66  void setText(const Pt::String& str);
67 
68  Adjustment textAdjustment() const;
69 
70  void setTextAdjustment(Adjustment a);
71 
72  void setScrollBars(bool hasScrollBars);
73 
74  void setMaxHeight(double height);
75 
76  void showPopup();
77 
78  void hidePopup();
79 
80  bool isHighlighted() const;
81 
84  Pt::Signal<const Pt::String&>& textChanged();
85 
88  Pt::Signal<const Pt::String&>& textEdited();
89 
90  Pt::Signal<const Pt::String&>& returnPressed();
91 
92  Pt::Signal<const Pt::String&>& editingFinished();
93 
94  Pt::Signal<ListBoxItem&>& selected();
95 
96  public:
97  const Gfx::Brush& background() const;
98 
99  void setBackground(const Gfx::Brush& b);
100 
101  const Gfx::Brush& foreground() const;
102 
103  void setForeground(const Gfx::Brush& b);
104 
105  const Gfx::Pen& contour() const;
106 
107  void setContour(const Gfx::Pen& p);
108 
109  const Gfx::Color& textColor() const;
110 
111  void setTextColor(const Gfx::Color& color);
112 
113  const Gfx::Font& font() const;
114 
115  void setFont(const Gfx::Font& font);
116 
117  void setFontSize(std::size_t size);
118 
119  void setFontWeight(Gfx::Font::Weight weight);
120 
121  void setFontSlant(Gfx::Font::Slant slant);
122 
123  void setRenderer(ComboBoxRenderer* renderer);
124 
125  protected:
126  virtual Gfx::SizeF onMeasure(const SizePolicy& policy);
127 
128  virtual void onInvalidate();
129 
130  virtual void onPaint(PaintSurface& surface, const Gfx::RectF& updateRect);
131 
132  protected:
133  virtual void onProcessMouseEvent(const MouseEvent& ev);
134 
135  protected:
136  virtual void onResizeEvent(const ResizeEvent& ev);
137 
138  virtual bool onKeyEvent(const KeyEvent& ev);
139 
140  virtual bool onMouseEvent(const MouseEvent& ev);
141 
142  virtual bool onTouchEvent(const TouchEvent& ev);
143 
144  virtual bool onEnterEvent(const EnterEvent& ev);
145 
146  virtual bool onLeaveEvent(const LeaveEvent& ev);
147 
148  virtual void onFocusEvent(const FocusEvent& ev);
149 
150  private:
151  void onItemSelected(ListBoxItem& item);
152 
153  void processKeyEvent(const KeyEvent& ev);
154 
155  Gfx::Font getFont() const;
156 
157  private:
158  enum FontOverride : unsigned
159  {
160  OverrideSize = 0x01,
161  OverrideWeight = 0x02,
162  OverrideSlant = 0x04,
163  OverrideAll = 0xFF
164  };
165  Pt::Signal<const Pt::String&> _textChanged;
166  Pt::Signal<const Pt::String&> _textEdited;
167  Pt::Signal<const Pt::String&> _returnPressed;
168  Pt::Signal<const Pt::String&> _editingFinished;
169 
170  LineEditor _editor;
171  TextLine _line;
172  Popup _popup;
173  ListBox _items;
174  Gfx::SizeF _buttonSize;
175  double _maxHeight;
176  double _spacing;
177  bool _isEditable;
178  bool _isAccepted;
179  bool _isTextChanged;
180  bool _isHighlighted;
181 
182  AutoPtr<Gfx::Brush> _background;
183  AutoPtr<Gfx::Brush> _foreground;
184  AutoPtr<Gfx::Pen> _contour;
185  AutoPtr<Gfx::Color> _textColor;
186  Gfx::Font _customFont;
187  unsigned _fontOverride;
188 
189  FacetPtr<ComboBoxRenderer> _renderer;
190  bool _hasRenderer;
191 
192  Gfx::Brush _backgroundBrush;
193  Gfx::Brush _foregroundBrush;
194  Gfx::Pen _pen;
195  Gfx::Pen _textPen;
196  Gfx::Font _font;
197 };
198 
199 } // namespace
200 
201 } // namespace
202 
203 #endif
Multicast Signal to call multiple slots.
Definition: Signal.h:109
Unicode capable basic_string.
Definition: String.h:42