guit  0.1
 All Classes Functions Variables Typedefs Enumerations Friends
gchoicebox.hpp
1 //
2 // Boxes that enforce mutual exclusion of their items.
3 // Guit GUI Toolkit
4 // Copyright © 2020 Eric Lecolinet. All rights reserved.
5 // http://www.telecom-paris.fr/~elc
6 //
7 
8 #ifndef Guit_ChoiceBox_hpp
9 #define Guit_ChoiceBox_hpp
10 #include <gbox.hpp>
11 #include <gchoice.hpp>
12 namespace guit {
13 
74 class GChoiceBox : public GBox {
75 protected:
76  GChoiceBox(GadgetType&, GString const& css_and_title);
77 
78 public:
79  ~GChoiceBox();
80  GChoiceBox(GString const& css_and_title = "");
81  GChoiceBox& clone(GClone const&) override;
82 
83  GChoiceBox* toChoiceBox() override {return this;}
84 
91  virtual void choose(Gadget* item);
92  virtual void choose(Gadget& item) {GChoiceBox::choose(&item);}
93  virtual void choose(int index);
94  virtual void choose(GString const& string);
96 
103  virtual Gadget* chosen() const;
104  virtual int chosenIndex() const;
105  virtual GString chosenText() const;
107 
112  void setValue(GString const& string) override {choose(string);}
113  int value() const;
114  GString stringValue() const override;
116 
119  GChoice& choice();
120  GChoice* choiceProp() override {return choice_;}
121  GProp* valueProp() override {return choice_;}
123 
124  bool hasValue() const override {return true;}
125 
126  using GType = GadgetType_<GChoiceBox,GBox>;
127  static GType& Type();
128  GType& type() const override {return Type();}
129 
133  gptr<GChoice> choice_;
134  void initClone(Gadget& from, GClone const&) override;
135  void addProp(GProp&, bool add_to_proplist) override;
136  void setChoiceImpl(GChoice& c, bool add_to_list) override;
137  virtual GBox& itemBox() {return *this;}
138  virtual GBox const& itemBox() const {return *this;}
139  Gadget& createDefaultItem(GString const& arg) override;
141 };
142 
143 GChoiceBox& ChoiceBox(GString const& css_and_title = "");
144 
145 
146 
149 class GListBox : public GChoiceBox {
150 protected:
151  GListBox(GadgetType&, GString const& css_and_title);
152 
153 public:
154  GListBox(GString const& css_and_title = "");
155  GListBox& clone(GClone const&) override;
156 
158  static GType& Type();
159  GType& type() const override {return Type();}
160 };
161 
162 GListBox& ListBox(GString const& css_and_title = "");
163 
164 
165 
167 class GRadioBox : public GChoiceBox {
168 protected:
169  GRadioBox(GadgetType&, GString const& css_and_title);
170 
171 public:
172  GRadioBox(GString const& css_and_title = "");
173  GRadioBox& clone(GClone const&) override;
174 
176  static GType& Type();
177  GType& type() const override {return Type();}
178 };
179 
180 GRadioBox& RadioBox(GString const& css_and_title = "");
181 
182 }
183 #endif