]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - libs/uilib/uilib.h
Remove <gtk/gtk.h> from gtkutil/container.h
[xonotic/netradiant.git] / libs / uilib / uilib.h
index 284609d630d571cf640f304ac4c23c9f3000cd46..6ebb6420deda599407c771f2d83bb282d5274bdc 100644 (file)
@@ -14,12 +14,14 @@ struct _GtkCellEditable;
 struct _GtkCellRenderer;
 struct _GtkCellRendererText;
 struct _GtkCheckButton;
+struct _GtkCheckMenuItem;
 struct _GtkComboBox;
 struct _GtkComboBoxText;
 struct _GtkContainer;
 struct _GtkDialog;
 struct _GtkEditable;
 struct _GtkEntry;
+struct _GtkEntryCompletion;
 struct _GtkFrame;
 struct _GtkHBox;
 struct _GtkHPaned;
@@ -29,11 +31,15 @@ struct _GtkItem;
 struct _GtkLabel;
 struct _GtkListStore;
 struct _GtkMenu;
-struct _GtkMenuShell;
+struct _GtkMenuBar;
 struct _GtkMenuItem;
+struct _GtkMenuShell;
 struct _GtkMisc;
 struct _GtkObject;
 struct _GtkPaned;
+struct _GtkRadioButton;
+struct _GtkRadioMenuItem;
+struct _GtkRadioToolButton;
 struct _GtkRange;
 struct _GtkScale;
 struct _GtkScrolledWindow;
@@ -42,6 +48,10 @@ struct _GtkTable;
 struct _GtkTearoffMenuItem;
 struct _GtkTextView;
 struct _GtkToggleButton;
+struct _GtkToggleToolButton;
+struct _GtkToolbar;
+struct _GtkToolButton;
+struct _GtkToolItem;
 struct _GtkTreeModel;
 struct _GtkTreePath;
 struct _GtkTreeView;
@@ -60,6 +70,8 @@ namespace ui {
 
     void main();
 
+    void process();
+
     extern class Widget root;
 
     enum class alert_type {
@@ -129,6 +141,8 @@ namespace ui {
         };
     }
 
+    extern struct Null {} null;
+
     class Object :
             public details::Convertible<Object, _GtkObject *, details::Convert::Explicit>,
             public details::Convertible<Object, _GTypeInstance *, details::Convert::Explicit> {
@@ -149,16 +163,17 @@ namespace ui {
 
 #define WRAP(name, super, T, interfaces, ctors, methods) \
     class name; \
-    class I##name { \
+    class I##name : public details::Convertible<name, T *, details::Convert::Implicit> { \
     public: \
         using self = name *; \
         methods \
     }; \
-    class name : public super, public details::Convertible<name, T *, details::Convert::Implicit>, public I##name, public details::Mixin<name, void interfaces>::type { \
+    class name : public super, public I##name, public details::Mixin<name, void interfaces>::type { \
     public: \
         using self = name *; \
         using native = T *; \
         explicit name(native h) : super(reinterpret_cast<super::native>(h)) {} \
+        explicit name(Null n) : name((native) nullptr) {} \
         ctors \
     }; \
     inline bool operator<(name self, name other) { return self._handle < other._handle; } \
@@ -166,6 +181,8 @@ namespace ui {
 
     // https://developer.gnome.org/gtk2/stable/ch01.html
 
+    // GInterface
+
     WRAP(CellEditable, Object, _GtkCellEditable, (),
     ,
     );
@@ -176,6 +193,12 @@ namespace ui {
          void editable(bool value);
     );
 
+    WRAP(TreeModel, Object, _GtkTreeModel, (),
+    ,
+    );
+
+    // GObject
+
     WRAP(Widget, Object, _GtkWidget, (),
          Widget();
     ,
@@ -194,10 +217,17 @@ namespace ui {
                  bool want_import = false,
                  bool want_save = false
          );
+         void show();
     );
 
     WRAP(Container, Widget, _GtkContainer, (),
     ,
+         void add(Widget widget);
+
+         void remove(Widget widget);
+
+         template<class Lambda>
+         void foreach(Lambda &&lambda);
     );
 
     WRAP(Bin, Container, _GtkBin, (),
@@ -206,7 +236,6 @@ namespace ui {
 
     class AccelGroup;
     WRAP(Window, Bin, _GtkWindow, (),
-         Window();
          Window(window_type type);
     ,
          Window create_dialog_window(
@@ -264,6 +293,10 @@ namespace ui {
     ,
     );
 
+    WRAP(RadioButton, CheckButton, _GtkRadioButton, (),
+    ,
+    );
+
     WRAP(Item, Bin, _GtkItem, (),
     ,
     );
@@ -273,6 +306,15 @@ namespace ui {
          MenuItem(const char *label, bool mnemonic = false);
     ,
     );
+
+    WRAP(CheckMenuItem, MenuItem, _GtkCheckMenuItem, (),
+    ,
+    );
+
+    WRAP(RadioMenuItem, CheckMenuItem, _GtkRadioMenuItem, (),
+    ,
+    );
+
     WRAP(TearoffMenuItem, MenuItem, _GtkTearoffMenuItem, (),
          TearoffMenuItem();
     ,
@@ -287,6 +329,22 @@ namespace ui {
     ,
     );
 
+    WRAP(ToolItem, Bin, _GtkToolItem, (),
+    ,
+    );
+
+    WRAP(ToolButton, ToolItem, _GtkToolButton, (),
+    ,
+    );
+
+    WRAP(ToggleToolButton, ToolButton, _GtkToggleToolButton, (),
+    ,
+    );
+
+    WRAP(RadioToolButton, ToggleToolButton, _GtkRadioToolButton, (),
+    ,
+    );
+
     WRAP(ScrolledWindow, Bin, _GtkScrolledWindow, (),
          ScrolledWindow();
     ,
@@ -324,21 +382,29 @@ namespace ui {
     ,
     );
 
-    WRAP(Menu, Widget, _GtkMenu, (),
+    WRAP(MenuBar, MenuShell, _GtkMenuBar, (),
+    ,
+    );
+
+    WRAP(Menu, MenuShell, _GtkMenu, (),
          Menu();
     ,
     );
 
-    WRAP(Table, Widget, _GtkTable, (),
+    WRAP(Table, Container, _GtkTable, (),
          Table(std::size_t rows, std::size_t columns, bool homogenous);
     ,
     );
 
-    WRAP(TextView, Widget, _GtkTextView, (),
+    WRAP(TextView, Container, _GtkTextView, (),
          TextView();
     ,
     );
 
+    WRAP(Toolbar, Container, _GtkToolbar, (),
+    ,
+    );
+
     class TreeModel;
     WRAP(TreeView, Widget, _GtkTreeView, (),
          TreeView();
@@ -417,15 +483,17 @@ namespace ui {
     ,
     );
 
-    WRAP(ListStore, Object, _GtkListStore, (),
+    WRAP(EntryCompletion, Object, _GtkEntryCompletion, (),
     ,
-         void clear();
     );
 
-    WRAP(TreeModel, Widget, _GtkTreeModel, (),
+    WRAP(ListStore, Object, _GtkListStore, (ITreeModel),
     ,
+         void clear();
     );
 
+    // GBoxed
+
     WRAP(TreePath, Object, _GtkTreePath, (),
          TreePath();
          TreePath(const char *path);
@@ -434,6 +502,30 @@ namespace ui {
 
 #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>
+    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