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, (),
234 Window(window_type type);
236 Window create_dialog_window(
244 Window create_modal_dialog_window(
251 Window create_floating_window(const char *title);
253 std::uint64_t on_key_press(
254 bool (*f)(Widget widget, _GdkEventKey *event, void *extra),
255 void *extra = nullptr
258 void add_accel_group(AccelGroup group);
261 WRAP(Dialog, Window, _GtkDialog, (),
265 WRAP(Alignment, Bin, _GtkAlignment, (),
266 Alignment(float xalign, float yalign, float xscale, float yscale);
270 WRAP(Frame, Bin, _GtkFrame, (),
271 Frame(const char *label = nullptr);
275 WRAP(Button, Bin, _GtkButton, (),
277 Button(const char *label);
281 WRAP(ToggleButton, Button, _GtkToggleButton, (),
286 WRAP(CheckButton, ToggleButton, _GtkCheckButton, (),
287 CheckButton(const char *label);
291 WRAP(RadioButton, CheckButton, _GtkRadioButton, (),
295 WRAP(Item, Bin, _GtkItem, (),
299 WRAP(MenuItem, Item, _GtkMenuItem, (),
301 MenuItem(const char *label, bool mnemonic = false);
305 WRAP(CheckMenuItem, MenuItem, _GtkCheckMenuItem, (),
309 WRAP(RadioMenuItem, CheckMenuItem, _GtkRadioMenuItem, (),
313 WRAP(TearoffMenuItem, MenuItem, _GtkTearoffMenuItem, (),
318 WRAP(ComboBox, Bin, _GtkComboBox, (),
322 WRAP(ComboBoxText, ComboBox, _GtkComboBoxText, (),
327 WRAP(ToolItem, Bin, _GtkToolItem, (),
331 WRAP(ToolButton, ToolItem, _GtkToolButton, (),
335 WRAP(ToggleToolButton, ToolButton, _GtkToggleToolButton, (),
339 WRAP(RadioToolButton, ToggleToolButton, _GtkRadioToolButton, (),
343 WRAP(ScrolledWindow, Bin, _GtkScrolledWindow, (),
348 WRAP(Box, Container, _GtkBox, (),
352 WRAP(VBox, Box, _GtkVBox, (),
353 VBox(bool homogenous, int spacing);
357 WRAP(HBox, Box, _GtkHBox, (),
358 HBox(bool homogenous, int spacing);
362 WRAP(Paned, Container, _GtkPaned, (),
366 WRAP(HPaned, Paned, _GtkHPaned, (),
371 WRAP(VPaned, Paned, _GtkVPaned, (),
376 WRAP(MenuShell, Container, _GtkMenuShell, (),
380 WRAP(MenuBar, MenuShell, _GtkMenuBar, (),
384 WRAP(Menu, MenuShell, _GtkMenu, (),
389 WRAP(Table, Container, _GtkTable, (),
390 Table(std::size_t rows, std::size_t columns, bool homogenous);
394 WRAP(TextView, Container, _GtkTextView, (),
399 WRAP(Toolbar, Container, _GtkToolbar, (),
404 WRAP(TreeView, Widget, _GtkTreeView, (),
406 TreeView(TreeModel model);
410 WRAP(Misc, Widget, _GtkMisc, (),
414 WRAP(Label, Widget, _GtkLabel, (),
415 Label(const char *label);
419 WRAP(Image, Widget, _GtkImage, (),
424 WRAP(Entry, Widget, _GtkEntry, (IEditable, ICellEditable),
426 Entry(std::size_t max_length);
431 WRAP(SpinButton, Entry, _GtkSpinButton, (),
432 SpinButton(Adjustment adjustment, double climb_rate, std::size_t digits);
436 WRAP(Range, Widget, _GtkRange, (),
440 WRAP(Scale, Range, _GtkScale, (),
444 WRAP(HScale, Scale, _GtkHScale, (),
445 HScale(Adjustment adjustment);
446 HScale(double min, double max, double step);
450 WRAP(Adjustment, Object, _GtkAdjustment, (),
451 Adjustment(double value,
452 double lower, double upper,
453 double step_increment, double page_increment,
458 WRAP(CellRenderer, Object, _GtkCellRenderer, (),
462 WRAP(CellRendererText, CellRenderer, _GtkCellRendererText, (),
467 struct TreeViewColumnAttribute {
468 const char *attribute;
471 WRAP(TreeViewColumn, Object, _GtkTreeViewColumn, (),
472 TreeViewColumn(const char *title, CellRenderer renderer, std::initializer_list<TreeViewColumnAttribute> attributes);
476 WRAP(AccelGroup, Object, _GtkAccelGroup, (),
481 WRAP(EntryCompletion, Object, _GtkEntryCompletion, (),
485 WRAP(ListStore, Object, _GtkListStore, (ITreeModel),
492 WRAP(TreePath, Object, _GtkTreePath, (),
494 TreePath(const char *path);