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;
51 struct _GtkToolButton;
56 struct _GtkTreeViewColumn;
61 struct _GTypeInstance;
67 void init(int argc, char *argv[]);
71 extern class Widget root;
73 enum class alert_type {
81 enum class alert_icon {
89 enum class alert_response {
96 enum class window_type {
107 template<class Self, class T, Convert mode>
110 template<class Self, class T>
111 struct Convertible<Self, T, Convert::Implicit> {
113 { return reinterpret_cast<T>(static_cast<Self const *>(this)->_handle); }
116 template<class Self, class T>
117 struct Convertible<Self, T, Convert::Explicit> {
118 explicit operator T() const
119 { return reinterpret_cast<T>(static_cast<Self const *>(this)->_handle); }
122 template<class Self, class... T>
128 template<class Self, class Interfaces>
131 struct Mixin<Self, void()> {
132 using type = All<Self>;
134 template<class Self, class... Interfaces>
135 struct Mixin<Self, void(Interfaces...)> {
136 using type = All<Self, Interfaces...>;
141 public details::Convertible<Object, _GtkObject *, details::Convert::Explicit>,
142 public details::Convertible<Object, _GTypeInstance *, details::Convert::Explicit> {
144 using native = _GtkObject *;
147 Object(native h) : _handle(h)
150 explicit operator bool() const
151 { return _handle != nullptr; }
153 explicit operator void *() const
156 static_assert(sizeof(Object) == sizeof(Object::native), "object slicing");
158 #define WRAP(name, super, T, interfaces, ctors, methods) \
162 using self = name *; \
165 class name : public super, public details::Convertible<name, T *, details::Convert::Implicit>, public I##name, public details::Mixin<name, void interfaces>::type { \
167 using self = name *; \
168 using native = T *; \
169 explicit name(native h) : super(reinterpret_cast<super::native>(h)) {} \
172 inline bool operator<(name self, name other) { return self._handle < other._handle; } \
173 static_assert(sizeof(name) == sizeof(super), "object slicing")
175 // https://developer.gnome.org/gtk2/stable/ch01.html
177 WRAP(CellEditable, Object, _GtkCellEditable, (),
181 WRAP(Editable, Object, _GtkEditable, (),
184 void editable(bool value);
187 WRAP(Widget, Object, _GtkWidget, (),
190 alert_response alert(
192 std::string title = "NetRadiant",
193 alert_type type = alert_type::OK,
194 alert_icon icon = alert_icon::Default
196 const char *file_dialog(
199 const char *path = nullptr,
200 const char *pattern = nullptr,
201 bool want_load = false,
202 bool want_import = false,
203 bool want_save = false
208 WRAP(Container, Widget, _GtkContainer, (),
212 WRAP(Bin, Container, _GtkBin, (),
217 WRAP(Window, Bin, _GtkWindow, (),
219 Window(window_type type);
221 Window create_dialog_window(
229 Window create_modal_dialog_window(
236 Window create_floating_window(const char *title);
238 std::uint64_t on_key_press(
239 bool (*f)(Widget widget, _GdkEventKey *event, void *extra),
240 void *extra = nullptr
243 void add_accel_group(AccelGroup group);
246 WRAP(Dialog, Window, _GtkDialog, (),
250 WRAP(Alignment, Bin, _GtkAlignment, (),
251 Alignment(float xalign, float yalign, float xscale, float yscale);
255 WRAP(Frame, Bin, _GtkFrame, (),
256 Frame(const char *label = nullptr);
260 WRAP(Button, Bin, _GtkButton, (),
262 Button(const char *label);
266 WRAP(ToggleButton, Button, _GtkToggleButton, (),
271 WRAP(CheckButton, ToggleButton, _GtkCheckButton, (),
272 CheckButton(const char *label);
276 WRAP(RadioButton, CheckButton, _GtkRadioButton, (),
280 WRAP(Item, Bin, _GtkItem, (),
284 WRAP(MenuItem, Item, _GtkMenuItem, (),
286 MenuItem(const char *label, bool mnemonic = false);
290 WRAP(CheckMenuItem, MenuItem, _GtkCheckMenuItem, (),
294 WRAP(RadioMenuItem, CheckMenuItem, _GtkRadioMenuItem, (),
298 WRAP(TearoffMenuItem, MenuItem, _GtkTearoffMenuItem, (),
303 WRAP(ComboBox, Bin, _GtkComboBox, (),
307 WRAP(ComboBoxText, ComboBox, _GtkComboBoxText, (),
312 WRAP(ToolItem, Bin, _GtkToolItem, (),
316 WRAP(ToolButton, ToolItem, _GtkToolButton, (),
320 WRAP(ToggleToolButton, ToolButton, _GtkToggleToolButton, (),
324 WRAP(RadioToolButton, ToggleToolButton, _GtkRadioToolButton, (),
328 WRAP(ScrolledWindow, Bin, _GtkScrolledWindow, (),
333 WRAP(Box, Container, _GtkBox, (),
337 WRAP(VBox, Box, _GtkVBox, (),
338 VBox(bool homogenous, int spacing);
342 WRAP(HBox, Box, _GtkHBox, (),
343 HBox(bool homogenous, int spacing);
347 WRAP(Paned, Container, _GtkPaned, (),
351 WRAP(HPaned, Paned, _GtkHPaned, (),
356 WRAP(VPaned, Paned, _GtkVPaned, (),
361 WRAP(MenuShell, Container, _GtkMenuShell, (),
365 WRAP(MenuBar, MenuShell, _GtkMenuBar, (),
369 WRAP(Menu, MenuShell, _GtkMenu, (),
374 WRAP(Table, Widget, _GtkTable, (),
375 Table(std::size_t rows, std::size_t columns, bool homogenous);
379 WRAP(TextView, Widget, _GtkTextView, (),
385 WRAP(TreeView, Widget, _GtkTreeView, (),
387 TreeView(TreeModel model);
391 WRAP(Misc, Widget, _GtkMisc, (),
395 WRAP(Label, Widget, _GtkLabel, (),
396 Label(const char *label);
400 WRAP(Image, Widget, _GtkImage, (),
405 WRAP(Entry, Widget, _GtkEntry, (IEditable, ICellEditable),
407 Entry(std::size_t max_length);
412 WRAP(SpinButton, Entry, _GtkSpinButton, (),
413 SpinButton(Adjustment adjustment, double climb_rate, std::size_t digits);
417 WRAP(Range, Widget, _GtkRange, (),
421 WRAP(Scale, Range, _GtkScale, (),
425 WRAP(HScale, Scale, _GtkHScale, (),
426 HScale(Adjustment adjustment);
427 HScale(double min, double max, double step);
431 WRAP(Adjustment, Object, _GtkAdjustment, (),
432 Adjustment(double value,
433 double lower, double upper,
434 double step_increment, double page_increment,
439 WRAP(CellRenderer, Object, _GtkCellRenderer, (),
443 WRAP(CellRendererText, CellRenderer, _GtkCellRendererText, (),
448 struct TreeViewColumnAttribute {
449 const char *attribute;
452 WRAP(TreeViewColumn, Object, _GtkTreeViewColumn, (),
453 TreeViewColumn(const char *title, CellRenderer renderer, std::initializer_list<TreeViewColumnAttribute> attributes);
457 WRAP(AccelGroup, Object, _GtkAccelGroup, (),
462 WRAP(ListStore, Object, _GtkListStore, (),
467 WRAP(TreeModel, Widget, _GtkTreeModel, (),
471 WRAP(TreePath, Object, _GtkTreePath, (),
473 TreePath(const char *path);