guit  0.1
 All Classes Functions Variables Typedefs Enumerations Friends
gwindow.hpp
1 //
2 // Base class for Windows and Dialogs.
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_Window_hpp
9 #define Guit_Window_hpp
10 #include <gbox.hpp>
11 namespace guit {
12 
52 class GWindow : public GBox {
53 protected:
54  GWindow(GadgetType&, GString const& css_and_title);
55 
56 public:
57  GWindow(GString const& css_and_title = "");
58  ~GWindow();
59 
60  GWindow& clone(GClone const&) override;
61  GWindow* toWindow() override {return this;}
62 
66  virtual int startApp();
67 
69  virtual bool isModal() const {return wmodes_.modal;}
70 
72  virtual void setModal(bool modal);
73 
76  GWindow& show(bool show = true) override;
77 
78  virtual void show(GEvent&, bool autoplace);
79 
88  virtual void close();
89 
93  virtual void dieOnClose(bool dies = true);
94 
96  static GWindow* findWindow(GPoint const& screenpos);
97 
98  GPoint pos() const override {return screenpos_;}
99  float x() const override {return screenpos_.x;}
100  float y() const override {return screenpos_.y;}
101 
102  virtual void raise();
103  virtual void minimize();
104  virtual void maximize();
105  virtual void restore();
106 
107  GWindow& setResizable(bool);
108  GWindow& setMinSize(float w, float h);
109  GWindow& setMaxSize(float w, float h);
110  GWindow& setOpacity(float opacity);
111  GWindow& stayOnTop();
112  GWindow& stayOnTopOf(GWindow&);
113  GWindow& joinAllSpaces();
114  GWindow& setBordered(bool);
115 
116  void setScale(float scale);
117  float scale() const {return scale_;}
118 
119  using GBox::add;
120  void add(Gadget* child, int index = -1) override;
121  void add(Gadget& child, int index = -1) override {GWindow::add(&child, index);}
122  void add(GWindow*) override;
123 
124  bool isTopLevel() const override {return true;}
125  void update() override;
126  void updateLayout(Update = Update::IfNeeded) override;
127 
128  class GNatWindow* nativeWindow() {return natwin_;}
129 
130  using GType = GadgetType_<GWindow,GBox>;
131  static GType& Type();
132  GType& type() const override {return Type();}
133 
136  uint32_t windowID() const;
137  void topInit() override;
138  void addProp(GProp& prop, bool add_to_list) override;
139  void moveImpl(float winx, float winy, bool callcb) override;
140  void addHotkey(Gadget&, class GHotkey&);
141  bool triggerHotkey(GEventState keystate, GKeyCode key);
142  void setIconImpl(GString const& filename);
143 
144  struct WinModes {uint8_t
145  modal:1, mustupdate:1, mustdraw:1, mustlayout:1, dieonclose:1,
146  autoclose:1, softwin:1, quitcalled:1;
147  } wmodes_{};
148  float scale_{1.f};
149  GPoint screenpos_;
150  class GNatWindow* natwin_{};
151  class GHotkeys* hotkeys_{};
153 };
154 
156 GWindow& Window(GString const& css_and_title = "");
157 
158 }
159 #endif