guit  0.1
 All Classes Functions Variables Typedefs Enumerations Friends
gdialog.hpp
1 //
2 // Dialog boxes.
3 // Guit GUI Toolkit
4 // Copyright © 2019/2020 Eric Lecolinet. All rights reserved.
5 // http://www.telecom-paris.fr/~elc
6 //
7 
8 #ifndef Guit_Dialog_hpp
9 #define Guit_Dialog_hpp
10 #include <gwindow.hpp>
11 #include <gbool.hpp>
12 namespace guit {
13 
35 class GDialog : public GWindow {
36 protected:
37  GDialog(GadgetType&, GString const& css_and_title);
38 
39 public:
40  GDialog(GString const& css_and_title = "");
41  GDialog& clone(GClone const&) override;
42 
46  static int alert(GString const& message, GString const& info = "");
47 
52  static int confirm(GString const& message, GString const& info = "",
53  GString const& buttons = "");
54 
58  GDialog& show(bool state = true) override;
59 
64  virtual int open();
65 
69  int result() const {return result_;}
70 
74  virtual Gadget& cancelButton();
75 
80  virtual Gadget& okButton();
81 
85  virtual GBox& buttonBox();
86 
92  virtual void setButtons(GString const& buttons);
93 
96  virtual GItem* findButton(int pos);
97 
98  using GType = GadgetType_<GDialog,GWindow>;
99  static GType& Type();
100  GType& type() const override {return Type();}
101 
102 protected:
103  gptr<GBox> bbox_;
104  int result_{};
105  bool quitloop_{};
106  virtual void setResult(int result, bool hide);
107 };
108 
112 GDialog& Dialog(GString const& css_and_title = "");
113 
114 
115 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
116 
125 class GInfoDialog : public GDialog {
126 protected:
127  GInfoDialog(GadgetType&, GString const& css_and_title);
128 
129 public:
130  GInfoDialog(GString const& css_and_title = "");
131  GInfoDialog& clone(GClone const&) override;
132 
133  GInfoDialog& show(bool state = true) override;
134 
140  GItem& message();
141 
144  GItem& info();
145 
147  GTextItem& input();
148 
151  GInfoDialog& openOnlyIf(GBool& test);
152  GInfoDialog& openOnlyIf(GExprBool const& test);
153  GInfoDialog& openOnlyIf(std::function<bool()> test);
155 
157  static GType& Type();
158  GType& type() const override {return Type();}
159 
160 protected:
161  gptr<GItem> message_, info_;
162  gptr<GTextItem> input_;
163  gprotect<GProp> openonly_;
164 };
165 
167 GInfoDialog& InfoDialog(GString const& title="", GString const& message = "");
168 
169 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
170 
171 
181 class GQuitDialog : public GInfoDialog {
182 protected:
183  GQuitDialog(GadgetType&, GString const& css_and_title);
184 
185 public:
186  GQuitDialog(GString const& css_and_title = "");
187 
188  GQuitDialog& clone(GClone const&) override;
189 
191  static GType& Type();
192  GType& type() const override {return Type();}
193 };
194 
196 GQuitDialog& QuitDialog(GString const& title="", GString const& message="");
197 
198 }
199 #endif
200