]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - libs/uilib/uilib.h
Rebase onto master
[xonotic/netradiant.git] / libs / uilib / uilib.h
index 4dbdd7910ae1493c1200337ece777513810834c5..511a40c31e731cdd20a4a00df9de6ae0f7ac7044 100644 (file)
@@ -2,6 +2,7 @@
 #define INCLUDED_UILIB_H
 
 #include <string>
+#include <glib-object.h>
 
 struct _GdkEventKey;
 struct _GtkAccelGroup;
@@ -54,6 +55,7 @@ struct _GtkToolButton;
 struct _GtkToolItem;
 struct _GtkTreeModel;
 struct _GtkTreePath;
+struct _GtkTreeSelection;
 struct _GtkTreeView;
 struct _GtkTreeViewColumn;
 struct _GtkVBox;
@@ -62,11 +64,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();
 
@@ -102,6 +112,20 @@ namespace ui {
         POPUP
     };
 
+    enum class Shadow {
+        NONE,
+        IN,
+        OUT,
+        ETCHED_IN,
+        ETCHED_OUT
+    };
+
+    enum class Policy {
+        ALWAYS,
+        AUTOMATIC,
+        NEVER
+    };
+
     namespace details {
 
         enum class Convert {
@@ -147,6 +171,7 @@ namespace ui {
             public details::Convertible<Object, _GtkObject *, details::Convert::Explicit>,
             public details::Convertible<Object, _GTypeInstance *, details::Convert::Explicit> {
     public:
+        using self = Object *;
         using native = _GtkObject *;
         native _handle;
 
@@ -158,6 +183,15 @@ namespace ui {
 
         explicit operator void *() const
         { return _handle; }
+
+        void unref()
+        { g_object_unref(_handle); }
+
+        template<class Lambda>
+        gulong connect(char const *detailed_signal, Lambda &&c_handler, void *data);
+
+        template<class Lambda>
+        gulong connect(char const *detailed_signal, Lambda &&c_handler, Object data);
     };
     static_assert(sizeof(Object) == sizeof(Object::native), "object slicing");
 
@@ -223,6 +257,11 @@ namespace ui {
     WRAP(Container, Widget, _GtkContainer, (),
     ,
          void add(Widget widget);
+
+         void remove(Widget widget);
+
+         template<class Lambda>
+         void foreach(Lambda &&lambda);
     );
 
     WRAP(Bin, Container, _GtkBin, (),
@@ -231,7 +270,6 @@ namespace ui {
 
     class AccelGroup;
     WRAP(Window, Bin, _GtkWindow, (),
-         Window();
          Window(window_type type);
     ,
          Window create_dialog_window(
@@ -488,6 +526,10 @@ namespace ui {
          void clear();
     );
 
+    WRAP(TreeSelection, Object, _GtkTreeSelection, (),
+    ,
+    );
+
     // GBoxed
 
     WRAP(TreePath, Object, _GtkTreePath, (),
@@ -496,8 +538,51 @@ namespace ui {
     ,
     );
 
+    // Custom
+
+    WRAP(GLArea, Widget, _GtkGLArea, (),
+    ,
+         guint on_render(GCallback pFunction, void *data);
+    );
+
 #undef WRAP
 
+    // callbacks
+
+    namespace {
+        using GtkCallback = void (*)(_GtkWidget *, void *);
+        extern "C" {
+        void gtk_container_foreach(_GtkContainer *, GtkCallback, void *);
+        }
+    }
+
+#define this (*static_cast<self>(this))
+
+    template<class Lambda>
+    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<class Lambda>
+    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<class Lambda>
+    void IContainer::foreach(Lambda &&lambda)
+    {
+        GtkCallback cb = [](_GtkWidget *widget, void *data) -> void {
+            using Function = typename std::decay<Lambda>::type;
+            Function *f = static_cast<Function *>(data);
+            (*f)(Widget(widget));
+        };
+        gtk_container_foreach(this, cb, &lambda);
+    }
+
+#undef this
+
 }
 
 #endif