1 #ifndef INCLUDED_UILIB_H
2 #define INCLUDED_UILIB_H
13 struct _GtkCellEditable;
14 struct _GtkCellRenderer;
15 struct _GtkCellRendererText;
16 struct _GtkCheckButton;
18 struct _GtkComboBoxText;
37 struct _GtkRadioButton;
38 struct _GtkRadioToolButton;
41 struct _GtkScrolledWindow;
42 struct _GtkSpinButton;
44 struct _GtkTearoffMenuItem;
46 struct _GtkToggleButton;
47 struct _GtkToggleToolButton;
48 struct _GtkToolButton;
53 struct _GtkTreeViewColumn;
58 struct _GTypeInstance;
64 void init(int argc, char *argv[]);
68 extern class Widget root;
70 enum class alert_type {
78 enum class alert_icon {
86 enum class alert_response {
93 enum class window_type {
104 template<class Self, class T, Convert mode>
107 template<class Self, class T>
108 struct Convertible<Self, T, Convert::Implicit> {
110 { return reinterpret_cast<T>(static_cast<Self const *>(this)->_handle); }
113 template<class Self, class T>
114 struct Convertible<Self, T, Convert::Explicit> {
115 explicit operator T() const
116 { return reinterpret_cast<T>(static_cast<Self const *>(this)->_handle); }
119 template<class Self, class... T>
125 template<class Self, class Interfaces>
128 struct Mixin<Self, void()> {
129 using type = All<Self>;
131 template<class Self, class... Interfaces>
132 struct Mixin<Self, void(Interfaces...)> {
133 using type = All<Self, Interfaces...>;
138 public details::Convertible<Object, _GtkObject *, details::Convert::Explicit>,
139 public details::Convertible<Object, _GTypeInstance *, details::Convert::Explicit> {
141 using native = _GtkObject *;
144 Object(native h) : _handle(h)
147 explicit operator bool() const
148 { return _handle != nullptr; }
150 explicit operator void *() const
153 static_assert(sizeof(Object) == sizeof(Object::native), "object slicing");
155 #define WRAP(name, super, T, interfaces, ctors, methods) \
159 using self = name *; \
162 class name : public super, public details::Convertible<name, T *, details::Convert::Implicit>, public I##name, public details::Mixin<name, void interfaces>::type { \
164 using self = name *; \
165 using native = T *; \
166 explicit name(native h) : super(reinterpret_cast<super::native>(h)) {} \
169 inline bool operator<(name self, name other) { return self._handle < other._handle; } \
170 static_assert(sizeof(name) == sizeof(super), "object slicing")
172 // https://developer.gnome.org/gtk2/stable/ch01.html
174 WRAP(CellEditable, Object, _GtkCellEditable, (),
178 WRAP(Editable, Object, _GtkEditable, (),
181 void editable(bool value);
184 WRAP(Widget, Object, _GtkWidget, (),
187 alert_response alert(
189 std::string title = "NetRadiant",
190 alert_type type = alert_type::OK,
191 alert_icon icon = alert_icon::Default
193 const char *file_dialog(
196 const char *path = nullptr,
197 const char *pattern = nullptr,
198 bool want_load = false,
199 bool want_import = false,
200 bool want_save = false
205 WRAP(Container, Widget, _GtkContainer, (),
209 WRAP(Bin, Container, _GtkBin, (),
214 WRAP(Window, Bin, _GtkWindow, (),
216 Window(window_type type);
218 Window create_dialog_window(
226 Window create_modal_dialog_window(
233 Window create_floating_window(const char *title);
235 std::uint64_t on_key_press(
236 bool (*f)(Widget widget, _GdkEventKey *event, void *extra),
237 void *extra = nullptr
240 void add_accel_group(AccelGroup group);
243 WRAP(Dialog, Window, _GtkDialog, (),
247 WRAP(Alignment, Bin, _GtkAlignment, (),
248 Alignment(float xalign, float yalign, float xscale, float yscale);
252 WRAP(Frame, Bin, _GtkFrame, (),
253 Frame(const char *label = nullptr);
257 WRAP(Button, Bin, _GtkButton, (),
259 Button(const char *label);
263 WRAP(ToggleButton, Button, _GtkToggleButton, (),
268 WRAP(CheckButton, ToggleButton, _GtkCheckButton, (),
269 CheckButton(const char *label);
273 WRAP(RadioButton, CheckButton, _GtkRadioButton, (),
277 WRAP(Item, Bin, _GtkItem, (),
281 WRAP(MenuItem, Item, _GtkMenuItem, (),
283 MenuItem(const char *label, bool mnemonic = false);
286 WRAP(TearoffMenuItem, MenuItem, _GtkTearoffMenuItem, (),
291 WRAP(ComboBox, Bin, _GtkComboBox, (),
295 WRAP(ComboBoxText, ComboBox, _GtkComboBoxText, (),
300 WRAP(ToolItem, Bin, _GtkToolItem, (),
304 WRAP(ToolButton, ToolItem, _GtkToolButton, (),
308 WRAP(ToggleToolButton, ToolButton, _GtkToggleToolButton, (),
312 WRAP(RadioToolButton, ToggleToolButton, _GtkRadioToolButton, (),
316 WRAP(ScrolledWindow, Bin, _GtkScrolledWindow, (),
321 WRAP(Box, Container, _GtkBox, (),
325 WRAP(VBox, Box, _GtkVBox, (),
326 VBox(bool homogenous, int spacing);
330 WRAP(HBox, Box, _GtkHBox, (),
331 HBox(bool homogenous, int spacing);
335 WRAP(Paned, Container, _GtkPaned, (),
339 WRAP(HPaned, Paned, _GtkHPaned, (),
344 WRAP(VPaned, Paned, _GtkVPaned, (),
349 WRAP(MenuShell, Container, _GtkMenuShell, (),
353 WRAP(Menu, Widget, _GtkMenu, (),
358 WRAP(Table, Widget, _GtkTable, (),
359 Table(std::size_t rows, std::size_t columns, bool homogenous);
363 WRAP(TextView, Widget, _GtkTextView, (),
369 WRAP(TreeView, Widget, _GtkTreeView, (),
371 TreeView(TreeModel model);
375 WRAP(Misc, Widget, _GtkMisc, (),
379 WRAP(Label, Widget, _GtkLabel, (),
380 Label(const char *label);
384 WRAP(Image, Widget, _GtkImage, (),
389 WRAP(Entry, Widget, _GtkEntry, (IEditable, ICellEditable),
391 Entry(std::size_t max_length);
396 WRAP(SpinButton, Entry, _GtkSpinButton, (),
397 SpinButton(Adjustment adjustment, double climb_rate, std::size_t digits);
401 WRAP(Range, Widget, _GtkRange, (),
405 WRAP(Scale, Range, _GtkScale, (),
409 WRAP(HScale, Scale, _GtkHScale, (),
410 HScale(Adjustment adjustment);
411 HScale(double min, double max, double step);
415 WRAP(Adjustment, Object, _GtkAdjustment, (),
416 Adjustment(double value,
417 double lower, double upper,
418 double step_increment, double page_increment,
423 WRAP(CellRenderer, Object, _GtkCellRenderer, (),
427 WRAP(CellRendererText, CellRenderer, _GtkCellRendererText, (),
432 struct TreeViewColumnAttribute {
433 const char *attribute;
436 WRAP(TreeViewColumn, Object, _GtkTreeViewColumn, (),
437 TreeViewColumn(const char *title, CellRenderer renderer, std::initializer_list<TreeViewColumnAttribute> attributes);
441 WRAP(AccelGroup, Object, _GtkAccelGroup, (),
446 WRAP(ListStore, Object, _GtkListStore, (),
451 WRAP(TreeModel, Widget, _GtkTreeModel, (),
455 WRAP(TreePath, Object, _GtkTreePath, (),
457 TreePath(const char *path);