1 #ifndef INCLUDED_UILIB_H
2 #define INCLUDED_UILIB_H
13 struct _GtkCellEditable;
14 struct _GtkCellRenderer;
15 struct _GtkCellRendererText;
16 struct _GtkCheckButton;
17 struct _GtkCheckMenuItem;
19 struct _GtkComboBoxText;
39 struct _GtkRadioButton;
40 struct _GtkRadioMenuItem;
41 struct _GtkRadioToolButton;
44 struct _GtkScrolledWindow;
45 struct _GtkSpinButton;
47 struct _GtkTearoffMenuItem;
49 struct _GtkToggleButton;
50 struct _GtkToggleToolButton;
52 struct _GtkToolButton;
57 struct _GtkTreeViewColumn;
62 struct _GTypeInstance;
68 void init(int argc, char *argv[]);
72 extern class Widget root;
74 enum class alert_type {
82 enum class alert_icon {
90 enum class alert_response {
97 enum class window_type {
108 template<class Self, class T, Convert mode>
111 template<class Self, class T>
112 struct Convertible<Self, T, Convert::Implicit> {
114 { return reinterpret_cast<T>(static_cast<Self const *>(this)->_handle); }
117 template<class Self, class T>
118 struct Convertible<Self, T, Convert::Explicit> {
119 explicit operator T() const
120 { return reinterpret_cast<T>(static_cast<Self const *>(this)->_handle); }
123 template<class Self, class... T>
129 template<class Self, class Interfaces>
132 struct Mixin<Self, void()> {
133 using type = All<Self>;
135 template<class Self, class... Interfaces>
136 struct Mixin<Self, void(Interfaces...)> {
137 using type = All<Self, Interfaces...>;
142 public details::Convertible<Object, _GtkObject *, details::Convert::Explicit>,
143 public details::Convertible<Object, _GTypeInstance *, details::Convert::Explicit> {
145 using native = _GtkObject *;
148 Object(native h) : _handle(h)
151 explicit operator bool() const
152 { return _handle != nullptr; }
154 explicit operator void *() const
157 static_assert(sizeof(Object) == sizeof(Object::native), "object slicing");
159 #define WRAP(name, super, T, interfaces, ctors, methods) \
163 using self = name *; \
166 class name : public super, public details::Convertible<name, T *, details::Convert::Implicit>, public I##name, public details::Mixin<name, void interfaces>::type { \
168 using self = name *; \
169 using native = T *; \
170 explicit name(native h) : super(reinterpret_cast<super::native>(h)) {} \
173 inline bool operator<(name self, name other) { return self._handle < other._handle; } \
174 static_assert(sizeof(name) == sizeof(super), "object slicing")
176 // https://developer.gnome.org/gtk2/stable/ch01.html
178 WRAP(CellEditable, Object, _GtkCellEditable, (),
182 WRAP(Editable, Object, _GtkEditable, (),
185 void editable(bool value);
188 WRAP(Widget, Object, _GtkWidget, (),
191 alert_response alert(
193 std::string title = "NetRadiant",
194 alert_type type = alert_type::OK,
195 alert_icon icon = alert_icon::Default
197 const char *file_dialog(
200 const char *path = nullptr,
201 const char *pattern = nullptr,
202 bool want_load = false,
203 bool want_import = false,
204 bool want_save = false
209 WRAP(Container, Widget, _GtkContainer, (),
213 WRAP(Bin, Container, _GtkBin, (),
218 WRAP(Window, Bin, _GtkWindow, (),
220 Window(window_type type);
222 Window create_dialog_window(
230 Window create_modal_dialog_window(
237 Window create_floating_window(const char *title);
239 std::uint64_t on_key_press(
240 bool (*f)(Widget widget, _GdkEventKey *event, void *extra),
241 void *extra = nullptr
244 void add_accel_group(AccelGroup group);
247 WRAP(Dialog, Window, _GtkDialog, (),
251 WRAP(Alignment, Bin, _GtkAlignment, (),
252 Alignment(float xalign, float yalign, float xscale, float yscale);
256 WRAP(Frame, Bin, _GtkFrame, (),
257 Frame(const char *label = nullptr);
261 WRAP(Button, Bin, _GtkButton, (),
263 Button(const char *label);
267 WRAP(ToggleButton, Button, _GtkToggleButton, (),
272 WRAP(CheckButton, ToggleButton, _GtkCheckButton, (),
273 CheckButton(const char *label);
277 WRAP(RadioButton, CheckButton, _GtkRadioButton, (),
281 WRAP(Item, Bin, _GtkItem, (),
285 WRAP(MenuItem, Item, _GtkMenuItem, (),
287 MenuItem(const char *label, bool mnemonic = false);
291 WRAP(CheckMenuItem, MenuItem, _GtkCheckMenuItem, (),
295 WRAP(RadioMenuItem, CheckMenuItem, _GtkRadioMenuItem, (),
299 WRAP(TearoffMenuItem, MenuItem, _GtkTearoffMenuItem, (),
304 WRAP(ComboBox, Bin, _GtkComboBox, (),
308 WRAP(ComboBoxText, ComboBox, _GtkComboBoxText, (),
313 WRAP(ToolItem, Bin, _GtkToolItem, (),
317 WRAP(ToolButton, ToolItem, _GtkToolButton, (),
321 WRAP(ToggleToolButton, ToolButton, _GtkToggleToolButton, (),
325 WRAP(RadioToolButton, ToggleToolButton, _GtkRadioToolButton, (),
329 WRAP(ScrolledWindow, Bin, _GtkScrolledWindow, (),
334 WRAP(Box, Container, _GtkBox, (),
338 WRAP(VBox, Box, _GtkVBox, (),
339 VBox(bool homogenous, int spacing);
343 WRAP(HBox, Box, _GtkHBox, (),
344 HBox(bool homogenous, int spacing);
348 WRAP(Paned, Container, _GtkPaned, (),
352 WRAP(HPaned, Paned, _GtkHPaned, (),
357 WRAP(VPaned, Paned, _GtkVPaned, (),
362 WRAP(MenuShell, Container, _GtkMenuShell, (),
366 WRAP(MenuBar, MenuShell, _GtkMenuBar, (),
370 WRAP(Menu, MenuShell, _GtkMenu, (),
375 WRAP(Table, Container, _GtkTable, (),
376 Table(std::size_t rows, std::size_t columns, bool homogenous);
380 WRAP(TextView, Container, _GtkTextView, (),
385 WRAP(Toolbar, Container, _GtkToolbar, (),
390 WRAP(TreeView, Widget, _GtkTreeView, (),
392 TreeView(TreeModel model);
396 WRAP(Misc, Widget, _GtkMisc, (),
400 WRAP(Label, Widget, _GtkLabel, (),
401 Label(const char *label);
405 WRAP(Image, Widget, _GtkImage, (),
410 WRAP(Entry, Widget, _GtkEntry, (IEditable, ICellEditable),
412 Entry(std::size_t max_length);
417 WRAP(SpinButton, Entry, _GtkSpinButton, (),
418 SpinButton(Adjustment adjustment, double climb_rate, std::size_t digits);
422 WRAP(Range, Widget, _GtkRange, (),
426 WRAP(Scale, Range, _GtkScale, (),
430 WRAP(HScale, Scale, _GtkHScale, (),
431 HScale(Adjustment adjustment);
432 HScale(double min, double max, double step);
436 WRAP(Adjustment, Object, _GtkAdjustment, (),
437 Adjustment(double value,
438 double lower, double upper,
439 double step_increment, double page_increment,
444 WRAP(CellRenderer, Object, _GtkCellRenderer, (),
448 WRAP(CellRendererText, CellRenderer, _GtkCellRendererText, (),
453 struct TreeViewColumnAttribute {
454 const char *attribute;
457 WRAP(TreeViewColumn, Object, _GtkTreeViewColumn, (),
458 TreeViewColumn(const char *title, CellRenderer renderer, std::initializer_list<TreeViewColumnAttribute> attributes);
462 WRAP(AccelGroup, Object, _GtkAccelGroup, (),
467 WRAP(ListStore, Object, _GtkListStore, (),
472 WRAP(TreeModel, Widget, _GtkTreeModel, (),
476 WRAP(TreePath, Object, _GtkTreePath, (),
478 TreePath(const char *path);