guit  0.1
 All Classes Functions Variables Typedefs Enumerations Friends
gcontrol.hpp
1 //
2 // Core Layer
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_Control_hpp
9 #define Guit_Control_hpp
10 #include <list>
11 #include <map>
12 #include <functional>
13 #include <gprefs.hpp>
14 #include <gadget.hpp>
15 #include <gcursor.hpp>
16 namespace guit {
17 
18 #define GIMPLEMENT_GADGET_TYPE(T) \
19 G##T::GType& G##T::Type() {static auto* t = new G##T::GType(#T); return *t;} \
20 
21 #define GIMPLEMENT_GADGET(T) GIMPLEMENT_GADGET_TYPE(T) \
22 G##T& T(GString const& spec) {return *new G##T(spec);}
23 
24 #define GIMPLEMENT_GADGET_ALL(T,Super) GIMPLEMENT_GADGET(T) \
25 G##T::G##T(GString const& spec) : Super(Type(), spec) {} \
26 G##T& G##T::clone(GClone const& c) { \
27  auto* g = new G##T; g->initClone(*this, c); return *g; \
28 }
29 
30 #define GIMPLEMENT_PROP_TYPE(T,R) \
31 G##T::GType& G##T::Type() {static auto* t = new G##T::GType(#T,R); return *t;}
32 
33 #define GIMPLEMENT_PROP(T,R) GIMPLEMENT_PROP_TYPE(T,R) \
34 G##T& T() {return *new G##T;} \
35 G##T& T(GString const& val) {return *new G##T(val);}
36 
37 
40 class GFatalError {
41 public:
42  GFatalError(GString const& where, GString const& message, GObject const* object = {});
43  GString what_;
44 };
45 
46 
47 class GPickMode {
48 public:
49  bool find_{}, catchedevent_{};
50  Gadget *catchedchild_{};
51  std::function<bool(Gadget&)> pred_{};
52 };
53 
54 
56 class GChannel : public GCursor {
57 public:
58  GChannel(unsigned int id);
59 
60  struct Clicked {
61  Gadget* target; // last clicked
62  GTime time; // time when last clicked
63  int count; // click count
64  };
65  // gprotect avoids destructing object while processing events
67  enterg_, // last entered
68  pressg_, // last pressed
69  focusg_, // keyboard focus
70  browseg_; // last browsed item in menus
71  Clicked clicked_;
72  GEventState buttonstate{};
73 };
74 
75 using GChannels = std::vector<GChannel*>;
76 
77 
78 class GHotkeys : public std::map<uint64_t, gptr<Gadget>> {};
79 
80 
81 // Guit Core.
82 class GCore : public GPrefs {
83 protected:
84  GCore();
85  GCore(GCore const&) = delete;
86  GCore(GCore const&&) = delete;
87  void operator=(GCore const&) = delete;
88  void operator=(GCore const&&) = delete;
89 
90 public:
91  struct BeginPlainObjects {
92  BeginPlainObjects() {GCore::setPlainMode(true);}
93  };
94  struct EndPlainObjects {
95  EndPlainObjects() {GCore::setPlainMode(false);}
96  };
97 
98  static int start(GWindow* mainwindow);
99  static void exit(int status);
100  static void subLoop(const bool& quit);
101  static bool isRunning();
102  static GTime elapsedTime();
103  static class GNatContext* natApp();
104 
105  static GId getId(GString const& name, bool obtain);
106  static GId findId(GString const& name) {return getId(name, false);}
107  static GId obtainId(GString const& name) {return getId(name, true);}
108 
109  static GChannel* channel(unsigned int id);
110  static GChannel& obtainChannel();
111  static GChannel& obtainChannel(unsigned int id);
112  static GChannels& channels();
113 
114  static void paintAll();
115  static GWindow* mainWindow();
116  static GWindow* modalWindow();
117  static GStyle* mainWindowStyle();
118  static std::list<GWindow*>& windowList();
119  static void addWindow(GWindow&);
120  static void removeWindow(GWindow&);
121  static void setModalWindow(GWindow*);
122  static void showOverlay(GBox& overlay, Gadget* opener,
123  bool state, bool autoclose, bool showaswin);
124  static void updateLayout(GWindow* upd_win, Gadget* upd_root, bool upd_css);
125  static void requestUpdate();
126 
127  static void printClassSizes();
128  static bool plainMode();
129  static void setPlainMode(bool mode);
130 
131  static int inspecting() {return inspecting_;}
132  static Gadget* inspected() {return inspected_;}
133 
134  static int argc_;
135  static const char** argv_;
136  static class GTheme* theme_;
137  static class GInspector* inspector_;
138  static int inspecting_;
139  static Gadget* inspected_;
140  static std::function<void(Gadget*)> doinspect_;
141 };
142 
143 }
144 #endif