X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=libs%2Fuilib%2Fuilib.h;h=4a6eff476df13bf993c1698f90564d2bb8561ef6;hb=2951e448a7f008f2438be4bd5feba2e4f4400eef;hp=b9588dee282aff0169971b837efc59e15770be0f;hpb=e075e775ce2359d9ac8e0fe6c44d03a7d7ecae9d;p=xonotic%2Fnetradiant.git diff --git a/libs/uilib/uilib.h b/libs/uilib/uilib.h index b9588dee..4a6eff47 100644 --- a/libs/uilib/uilib.h +++ b/libs/uilib/uilib.h @@ -2,6 +2,7 @@ #define INCLUDED_UILIB_H #include +#include struct _GdkEventKey; struct _GtkAccelGroup; @@ -30,6 +31,7 @@ struct _GtkImage; struct _GtkItem; struct _GtkLabel; struct _GtkListStore; +struct _GtkTreeIter; struct _GtkMenu; struct _GtkMenuBar; struct _GtkMenuItem; @@ -54,6 +56,7 @@ struct _GtkToolButton; struct _GtkToolItem; struct _GtkTreeModel; struct _GtkTreePath; +struct _GtkTreeSelection; struct _GtkTreeView; struct _GtkTreeViewColumn; struct _GtkVBox; @@ -62,11 +65,19 @@ struct _GtkWidget; struct _GtkWindow; struct _GTypeInstance; +#if GTK_TARGET == 3 +struct _GtkGLArea; +#endif + +#if GTK_TARGET == 2 +using _GtkGLArea = struct _GtkDrawingArea; +#endif + struct ModalDialog; namespace ui { - void init(int argc, char *argv[]); + bool init(int *argc, char **argv[], char const *parameter_string, char const **error); void main(); @@ -110,6 +121,12 @@ namespace ui { ETCHED_OUT }; + enum class Policy { + ALWAYS, + AUTOMATIC, + NEVER + }; + namespace details { enum class Convert { @@ -150,15 +167,17 @@ namespace ui { } extern struct Null {} null; + extern struct New_t {} New; class Object : public details::Convertible, public details::Convertible { public: + using self = Object *; using native = _GtkObject *; native _handle; - Object(native h) : _handle(h) + explicit Object(native h) : _handle(h) {} explicit operator bool() const @@ -166,6 +185,15 @@ namespace ui { explicit operator void *() const { return _handle; } + + void unref() + { g_object_unref(_handle); } + + template + gulong connect(char const *detailed_signal, Lambda &&c_handler, void *data); + + template + gulong connect(char const *detailed_signal, Lambda &&c_handler, Object data); }; static_assert(sizeof(Object) == sizeof(Object::native), "object slicing"); @@ -182,6 +210,8 @@ namespace ui { using native = T *; \ explicit name(native h) : super(reinterpret_cast(h)) {} \ explicit name(Null n) : name((native) nullptr) {} \ + explicit name(New_t); \ + static name from(void *ptr) { return name((native) ptr); } \ ctors \ }; \ inline bool operator<(name self, name other) { return self._handle < other._handle; } \ @@ -196,7 +226,6 @@ namespace ui { ); WRAP(Editable, Object, _GtkEditable, (), - Editable(); , void editable(bool value); ); @@ -207,8 +236,12 @@ namespace ui { // GObject + struct Dimensions { + int width; + int height; + }; + WRAP(Widget, Object, _GtkWidget, (), - Widget(); , alert_response alert( std::string text, @@ -225,7 +258,13 @@ namespace ui { bool want_import = false, bool want_save = false ); + bool visible(); + void visible(bool shown); void show(); + void hide(); + Dimensions dimensions(); + void dimensions(int width, int height); + void destroy(); ); WRAP(Container, Widget, _GtkContainer, (), @@ -244,7 +283,7 @@ namespace ui { class AccelGroup; WRAP(Window, Bin, _GtkWindow, (), - Window(window_type type); + explicit Window(window_type type); , Window create_dialog_window( const char *title, @@ -281,13 +320,12 @@ namespace ui { ); WRAP(Frame, Bin, _GtkFrame, (), - Frame(const char *label = nullptr); + explicit Frame(const char *label = nullptr); , ); WRAP(Button, Bin, _GtkButton, (), - Button(); - Button(const char *label); + explicit Button(const char *label); , ); @@ -297,7 +335,7 @@ namespace ui { ); WRAP(CheckButton, ToggleButton, _GtkCheckButton, (), - CheckButton(const char *label); + explicit CheckButton(const char *label); , ); @@ -310,8 +348,7 @@ namespace ui { ); WRAP(MenuItem, Item, _GtkMenuItem, (), - MenuItem(); - MenuItem(const char *label, bool mnemonic = false); + explicit MenuItem(const char *label, bool mnemonic = false); , ); @@ -324,7 +361,6 @@ namespace ui { ); WRAP(TearoffMenuItem, MenuItem, _GtkTearoffMenuItem, (), - TearoffMenuItem(); , ); @@ -333,7 +369,6 @@ namespace ui { ); WRAP(ComboBoxText, ComboBox, _GtkComboBoxText, (), - ComboBoxText(); , ); @@ -354,12 +389,14 @@ namespace ui { ); WRAP(ScrolledWindow, Bin, _GtkScrolledWindow, (), - ScrolledWindow(); , + void overflow(Policy x, Policy y); ); WRAP(Box, Container, _GtkBox, (), , + void pack_start(ui::Widget child, bool expand, bool fill, unsigned int padding); + void pack_end(ui::Widget child, bool expand, bool fill, unsigned int padding); ); WRAP(VBox, Box, _GtkVBox, (), @@ -377,12 +414,10 @@ namespace ui { ); WRAP(HPaned, Paned, _GtkHPaned, (), - HPaned(); , ); WRAP(VPaned, Paned, _GtkVPaned, (), - VPaned(); , ); @@ -395,7 +430,6 @@ namespace ui { ); WRAP(Menu, MenuShell, _GtkMenu, (), - Menu(); , ); @@ -405,8 +439,8 @@ namespace ui { ); WRAP(TextView, Container, _GtkTextView, (), - TextView(); , + void text(char const *str); ); WRAP(Toolbar, Container, _GtkToolbar, (), @@ -415,7 +449,6 @@ namespace ui { class TreeModel; WRAP(TreeView, Widget, _GtkTreeView, (), - TreeView(); TreeView(TreeModel model); , ); @@ -425,19 +458,20 @@ namespace ui { ); WRAP(Label, Widget, _GtkLabel, (), - Label(const char *label); + explicit Label(const char *label); , + void text(char const *str); ); WRAP(Image, Widget, _GtkImage, (), - Image(); , ); WRAP(Entry, Widget, _GtkEntry, (IEditable, ICellEditable), - Entry(); - Entry(std::size_t max_length); + explicit Entry(std::size_t max_length); , + char const *text(); + void text(char const *str); ); class Adjustment; @@ -455,7 +489,7 @@ namespace ui { ); WRAP(HScale, Scale, _GtkHScale, (), - HScale(Adjustment adjustment); + explicit HScale(Adjustment adjustment); HScale(double min, double max, double step); , ); @@ -473,7 +507,6 @@ namespace ui { ); WRAP(CellRendererText, CellRenderer, _GtkCellRendererText, (), - CellRendererText(); , ); @@ -487,7 +520,6 @@ namespace ui { ); WRAP(AccelGroup, Object, _GtkAccelGroup, (), - AccelGroup(); , ); @@ -498,16 +530,31 @@ namespace ui { WRAP(ListStore, Object, _GtkListStore, (ITreeModel), , void clear(); + + template + void append(T... args); + + void append(); + ); + + WRAP(TreeSelection, Object, _GtkTreeSelection, (), + , ); // GBoxed WRAP(TreePath, Object, _GtkTreePath, (), - TreePath(); - TreePath(const char *path); + explicit TreePath(const char *path); , ); + // Custom + + WRAP(GLArea, Widget, _GtkGLArea, (), + , + guint on_render(GCallback pFunction, void *data); + ); + #undef WRAP // callbacks @@ -521,6 +568,18 @@ namespace ui { #define this (*static_cast(this)) + template + gulong Object::connect(char const *detailed_signal, Lambda &&c_handler, void *data) + { + return g_signal_connect(G_OBJECT(this), detailed_signal, c_handler, data); + } + + template + gulong Object::connect(char const *detailed_signal, Lambda &&c_handler, Object data) + { + return g_signal_connect(G_OBJECT(this), detailed_signal, c_handler, (_GtkObject *) data); + } + template void IContainer::foreach(Lambda &&lambda) { @@ -532,6 +591,18 @@ namespace ui { gtk_container_foreach(this, cb, &lambda); } + namespace { + extern "C" { + void gtk_list_store_insert_with_values(_GtkListStore *, _GtkTreeIter *, gint position, ...); + } + } + + template + void IListStore::append(T... args) { + static_assert(sizeof...(args) % 2 == 0, "received an odd number of arguments"); + gtk_list_store_insert_with_values(this, NULL, -1, args..., -1); + } + #undef this }