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[]);
74 extern class Widget root;
76 enum class alert_type {
84 enum class alert_icon {
92 enum class alert_response {
99 enum class window_type {
110 template<class Self, class T, Convert mode>
113 template<class Self, class T>
114 struct Convertible<Self, T, Convert::Implicit> {
116 { return reinterpret_cast<T>(static_cast<Self const *>(this)->_handle); }
119 template<class Self, class T>
120 struct Convertible<Self, T, Convert::Explicit> {
121 explicit operator T() const
122 { return reinterpret_cast<T>(static_cast<Self const *>(this)->_handle); }
125 template<class Self, class... T>
131 template<class Self, class Interfaces>
134 struct Mixin<Self, void()> {
135 using type = All<Self>;
137 template<class Self, class... Interfaces>
138 struct Mixin<Self, void(Interfaces...)> {
139 using type = All<Self, Interfaces...>;
144 public details::Convertible<Object, _GtkObject *, details::Convert::Explicit>,
145 public details::Convertible<Object, _GTypeInstance *, details::Convert::Explicit> {
147 using native = _GtkObject *;
150 Object(native h) : _handle(h)
153 explicit operator bool() const
154 { return _handle != nullptr; }
156 explicit operator void *() const
159 static_assert(sizeof(Object) == sizeof(Object::native), "object slicing");
161 #define WRAP(name, super, T, interfaces, ctors, methods) \
165 using self = name *; \
168 class name : public super, public details::Convertible<name, T *, details::Convert::Implicit>, public I##name, public details::Mixin<name, void interfaces>::type { \
170 using self = name *; \
171 using native = T *; \
172 explicit name(native h) : super(reinterpret_cast<super::native>(h)) {} \
175 inline bool operator<(name self, name other) { return self._handle < other._handle; } \
176 static_assert(sizeof(name) == sizeof(super), "object slicing")
178 // https://developer.gnome.org/gtk2/stable/ch01.html
180 WRAP(CellEditable, Object, _GtkCellEditable, (),
184 WRAP(Editable, Object, _GtkEditable, (),
187 void editable(bool value);
190 WRAP(Widget, Object, _GtkWidget, (),
193 alert_response alert(
195 std::string title = "NetRadiant",
196 alert_type type = alert_type::OK,
197 alert_icon icon = alert_icon::Default
199 const char *file_dialog(
202 const char *path = nullptr,
203 const char *pattern = nullptr,
204 bool want_load = false,
205 bool want_import = false,
206 bool want_save = false
211 WRAP(Container, Widget, _GtkContainer, (),
215 WRAP(Bin, Container, _GtkBin, (),
220 WRAP(Window, Bin, _GtkWindow, (),
222 Window(window_type type);
224 Window create_dialog_window(
232 Window create_modal_dialog_window(
239 Window create_floating_window(const char *title);
241 std::uint64_t on_key_press(
242 bool (*f)(Widget widget, _GdkEventKey *event, void *extra),
243 void *extra = nullptr
246 void add_accel_group(AccelGroup group);
249 WRAP(Dialog, Window, _GtkDialog, (),
253 WRAP(Alignment, Bin, _GtkAlignment, (),
254 Alignment(float xalign, float yalign, float xscale, float yscale);
258 WRAP(Frame, Bin, _GtkFrame, (),
259 Frame(const char *label = nullptr);
263 WRAP(Button, Bin, _GtkButton, (),
265 Button(const char *label);
269 WRAP(ToggleButton, Button, _GtkToggleButton, (),
274 WRAP(CheckButton, ToggleButton, _GtkCheckButton, (),
275 CheckButton(const char *label);
279 WRAP(RadioButton, CheckButton, _GtkRadioButton, (),
283 WRAP(Item, Bin, _GtkItem, (),
287 WRAP(MenuItem, Item, _GtkMenuItem, (),
289 MenuItem(const char *label, bool mnemonic = false);
293 WRAP(CheckMenuItem, MenuItem, _GtkCheckMenuItem, (),
297 WRAP(RadioMenuItem, CheckMenuItem, _GtkRadioMenuItem, (),
301 WRAP(TearoffMenuItem, MenuItem, _GtkTearoffMenuItem, (),
306 WRAP(ComboBox, Bin, _GtkComboBox, (),
310 WRAP(ComboBoxText, ComboBox, _GtkComboBoxText, (),
315 WRAP(ToolItem, Bin, _GtkToolItem, (),
319 WRAP(ToolButton, ToolItem, _GtkToolButton, (),
323 WRAP(ToggleToolButton, ToolButton, _GtkToggleToolButton, (),
327 WRAP(RadioToolButton, ToggleToolButton, _GtkRadioToolButton, (),
331 WRAP(ScrolledWindow, Bin, _GtkScrolledWindow, (),
336 WRAP(Box, Container, _GtkBox, (),
340 WRAP(VBox, Box, _GtkVBox, (),
341 VBox(bool homogenous, int spacing);
345 WRAP(HBox, Box, _GtkHBox, (),
346 HBox(bool homogenous, int spacing);
350 WRAP(Paned, Container, _GtkPaned, (),
354 WRAP(HPaned, Paned, _GtkHPaned, (),
359 WRAP(VPaned, Paned, _GtkVPaned, (),
364 WRAP(MenuShell, Container, _GtkMenuShell, (),
368 WRAP(MenuBar, MenuShell, _GtkMenuBar, (),
372 WRAP(Menu, MenuShell, _GtkMenu, (),
377 WRAP(Table, Container, _GtkTable, (),
378 Table(std::size_t rows, std::size_t columns, bool homogenous);
382 WRAP(TextView, Container, _GtkTextView, (),
387 WRAP(Toolbar, Container, _GtkToolbar, (),
392 WRAP(TreeView, Widget, _GtkTreeView, (),
394 TreeView(TreeModel model);
398 WRAP(Misc, Widget, _GtkMisc, (),
402 WRAP(Label, Widget, _GtkLabel, (),
403 Label(const char *label);
407 WRAP(Image, Widget, _GtkImage, (),
412 WRAP(Entry, Widget, _GtkEntry, (IEditable, ICellEditable),
414 Entry(std::size_t max_length);
419 WRAP(SpinButton, Entry, _GtkSpinButton, (),
420 SpinButton(Adjustment adjustment, double climb_rate, std::size_t digits);
424 WRAP(Range, Widget, _GtkRange, (),
428 WRAP(Scale, Range, _GtkScale, (),
432 WRAP(HScale, Scale, _GtkHScale, (),
433 HScale(Adjustment adjustment);
434 HScale(double min, double max, double step);
438 WRAP(Adjustment, Object, _GtkAdjustment, (),
439 Adjustment(double value,
440 double lower, double upper,
441 double step_increment, double page_increment,
446 WRAP(CellRenderer, Object, _GtkCellRenderer, (),
450 WRAP(CellRendererText, CellRenderer, _GtkCellRendererText, (),
455 struct TreeViewColumnAttribute {
456 const char *attribute;
459 WRAP(TreeViewColumn, Object, _GtkTreeViewColumn, (),
460 TreeViewColumn(const char *title, CellRenderer renderer, std::initializer_list<TreeViewColumnAttribute> attributes);
464 WRAP(AccelGroup, Object, _GtkAccelGroup, (),
469 WRAP(ListStore, Object, _GtkListStore, (),
474 WRAP(TreeModel, Widget, _GtkTreeModel, (),
478 WRAP(TreePath, Object, _GtkTreePath, (),
480 TreePath(const char *path);