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;
24 struct _GtkEntryCompletion;
40 struct _GtkRadioButton;
41 struct _GtkRadioMenuItem;
42 struct _GtkRadioToolButton;
45 struct _GtkScrolledWindow;
46 struct _GtkSpinButton;
48 struct _GtkTearoffMenuItem;
50 struct _GtkToggleButton;
51 struct _GtkToggleToolButton;
53 struct _GtkToolButton;
58 struct _GtkTreeViewColumn;
63 struct _GTypeInstance;
69 void init(int argc, char *argv[]);
75 extern class Widget root;
77 enum class alert_type {
85 enum class alert_icon {
93 enum class alert_response {
100 enum class window_type {
111 template<class Self, class T, Convert mode>
114 template<class Self, class T>
115 struct Convertible<Self, T, Convert::Implicit> {
117 { return reinterpret_cast<T>(static_cast<Self const *>(this)->_handle); }
120 template<class Self, class T>
121 struct Convertible<Self, T, Convert::Explicit> {
122 explicit operator T() const
123 { return reinterpret_cast<T>(static_cast<Self const *>(this)->_handle); }
126 template<class Self, class... T>
132 template<class Self, class Interfaces>
135 struct Mixin<Self, void()> {
136 using type = All<Self>;
138 template<class Self, class... Interfaces>
139 struct Mixin<Self, void(Interfaces...)> {
140 using type = All<Self, Interfaces...>;
144 extern struct Null {} null;
147 public details::Convertible<Object, _GtkObject *, details::Convert::Explicit>,
148 public details::Convertible<Object, _GTypeInstance *, details::Convert::Explicit> {
150 using native = _GtkObject *;
153 Object(native h) : _handle(h)
156 explicit operator bool() const
157 { return _handle != nullptr; }
159 explicit operator void *() const
162 static_assert(sizeof(Object) == sizeof(Object::native), "object slicing");
164 #define WRAP(name, super, T, interfaces, ctors, methods) \
166 class I##name : public details::Convertible<name, T *, details::Convert::Implicit> { \
168 using self = name *; \
171 class name : public super, public I##name, public details::Mixin<name, void interfaces>::type { \
173 using self = name *; \
174 using native = T *; \
175 explicit name(native h) : super(reinterpret_cast<super::native>(h)) {} \
176 explicit name(Null n) : name((native) nullptr) {} \
179 inline bool operator<(name self, name other) { return self._handle < other._handle; } \
180 static_assert(sizeof(name) == sizeof(super), "object slicing")
182 // https://developer.gnome.org/gtk2/stable/ch01.html
186 WRAP(CellEditable, Object, _GtkCellEditable, (),
190 WRAP(Editable, Object, _GtkEditable, (),
193 void editable(bool value);
196 WRAP(TreeModel, Object, _GtkTreeModel, (),
202 WRAP(Widget, Object, _GtkWidget, (),
205 alert_response alert(
207 std::string title = "NetRadiant",
208 alert_type type = alert_type::OK,
209 alert_icon icon = alert_icon::Default
211 const char *file_dialog(
214 const char *path = nullptr,
215 const char *pattern = nullptr,
216 bool want_load = false,
217 bool want_import = false,
218 bool want_save = false
223 WRAP(Container, Widget, _GtkContainer, (),
225 void add(Widget widget);
228 WRAP(Bin, Container, _GtkBin, (),
233 WRAP(Window, Bin, _GtkWindow, (),
235 Window(window_type type);
237 Window create_dialog_window(
245 Window create_modal_dialog_window(
252 Window create_floating_window(const char *title);
254 std::uint64_t on_key_press(
255 bool (*f)(Widget widget, _GdkEventKey *event, void *extra),
256 void *extra = nullptr
259 void add_accel_group(AccelGroup group);
262 WRAP(Dialog, Window, _GtkDialog, (),
266 WRAP(Alignment, Bin, _GtkAlignment, (),
267 Alignment(float xalign, float yalign, float xscale, float yscale);
271 WRAP(Frame, Bin, _GtkFrame, (),
272 Frame(const char *label = nullptr);
276 WRAP(Button, Bin, _GtkButton, (),
278 Button(const char *label);
282 WRAP(ToggleButton, Button, _GtkToggleButton, (),
287 WRAP(CheckButton, ToggleButton, _GtkCheckButton, (),
288 CheckButton(const char *label);
292 WRAP(RadioButton, CheckButton, _GtkRadioButton, (),
296 WRAP(Item, Bin, _GtkItem, (),
300 WRAP(MenuItem, Item, _GtkMenuItem, (),
302 MenuItem(const char *label, bool mnemonic = false);
306 WRAP(CheckMenuItem, MenuItem, _GtkCheckMenuItem, (),
310 WRAP(RadioMenuItem, CheckMenuItem, _GtkRadioMenuItem, (),
314 WRAP(TearoffMenuItem, MenuItem, _GtkTearoffMenuItem, (),
319 WRAP(ComboBox, Bin, _GtkComboBox, (),
323 WRAP(ComboBoxText, ComboBox, _GtkComboBoxText, (),
328 WRAP(ToolItem, Bin, _GtkToolItem, (),
332 WRAP(ToolButton, ToolItem, _GtkToolButton, (),
336 WRAP(ToggleToolButton, ToolButton, _GtkToggleToolButton, (),
340 WRAP(RadioToolButton, ToggleToolButton, _GtkRadioToolButton, (),
344 WRAP(ScrolledWindow, Bin, _GtkScrolledWindow, (),
349 WRAP(Box, Container, _GtkBox, (),
353 WRAP(VBox, Box, _GtkVBox, (),
354 VBox(bool homogenous, int spacing);
358 WRAP(HBox, Box, _GtkHBox, (),
359 HBox(bool homogenous, int spacing);
363 WRAP(Paned, Container, _GtkPaned, (),
367 WRAP(HPaned, Paned, _GtkHPaned, (),
372 WRAP(VPaned, Paned, _GtkVPaned, (),
377 WRAP(MenuShell, Container, _GtkMenuShell, (),
381 WRAP(MenuBar, MenuShell, _GtkMenuBar, (),
385 WRAP(Menu, MenuShell, _GtkMenu, (),
390 WRAP(Table, Container, _GtkTable, (),
391 Table(std::size_t rows, std::size_t columns, bool homogenous);
395 WRAP(TextView, Container, _GtkTextView, (),
400 WRAP(Toolbar, Container, _GtkToolbar, (),
405 WRAP(TreeView, Widget, _GtkTreeView, (),
407 TreeView(TreeModel model);
411 WRAP(Misc, Widget, _GtkMisc, (),
415 WRAP(Label, Widget, _GtkLabel, (),
416 Label(const char *label);
420 WRAP(Image, Widget, _GtkImage, (),
425 WRAP(Entry, Widget, _GtkEntry, (IEditable, ICellEditable),
427 Entry(std::size_t max_length);
432 WRAP(SpinButton, Entry, _GtkSpinButton, (),
433 SpinButton(Adjustment adjustment, double climb_rate, std::size_t digits);
437 WRAP(Range, Widget, _GtkRange, (),
441 WRAP(Scale, Range, _GtkScale, (),
445 WRAP(HScale, Scale, _GtkHScale, (),
446 HScale(Adjustment adjustment);
447 HScale(double min, double max, double step);
451 WRAP(Adjustment, Object, _GtkAdjustment, (),
452 Adjustment(double value,
453 double lower, double upper,
454 double step_increment, double page_increment,
459 WRAP(CellRenderer, Object, _GtkCellRenderer, (),
463 WRAP(CellRendererText, CellRenderer, _GtkCellRendererText, (),
468 struct TreeViewColumnAttribute {
469 const char *attribute;
472 WRAP(TreeViewColumn, Object, _GtkTreeViewColumn, (),
473 TreeViewColumn(const char *title, CellRenderer renderer, std::initializer_list<TreeViewColumnAttribute> attributes);
477 WRAP(AccelGroup, Object, _GtkAccelGroup, (),
482 WRAP(EntryCompletion, Object, _GtkEntryCompletion, (),
486 WRAP(ListStore, Object, _GtkListStore, (ITreeModel),
493 WRAP(TreePath, Object, _GtkTreePath, (),
495 TreePath(const char *path);