]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - libs/uilib/uilib.cpp
Remove -Wno-pedantic
[xonotic/netradiant.git] / libs / uilib / uilib.cpp
index a27d2d841a866cb875c72d684319128da54cf6e9..7aaccfa2ef04aa1f24d07500655caceb54897ca5 100644 (file)
 
 namespace ui {
 
-    void init(int argc, char *argv[])
+    bool init(int *argc, char **argv[], char const *parameter_string, char const **error)
     {
         gtk_disable_setlocale();
-        gtk_init(&argc, &argv);
+        static GOptionEntry entries[] = {{NULL}};
+        char const *translation_domain = NULL;
+        GError *gerror = NULL;
+        bool ret = gtk_init_with_args(argc, argv, parameter_string, entries, translation_domain, &gerror) != 0;
+        if (!ret) {
+            *error = gerror->message;
+        }
+        return ret;
     }
 
     void main()
@@ -29,7 +36,7 @@ namespace ui {
         }
     }
 
-    Widget root{nullptr};
+    Widget root;
 
 #define IMPL(T, F) template<> _IMPL(T, F)
 #define _IMPL(T, F) struct verify<T *> { using self = T; static self test(self it) { return self(F(it)); } }
@@ -39,7 +46,7 @@ namespace ui {
 
     template<class T> _IMPL(T,);
 
-#define this verify<self>::test(*static_cast<self>(this))
+#define this (verify<self>::test(*static_cast<self>(this)))
 
     IMPL(Editable, GTK_EDITABLE);
 
@@ -85,11 +92,28 @@ namespace ui {
         return ::file_dialog(this, open, title, path, pattern, want_load, want_import, want_save);
     }
 
+    bool IWidget::visible()
+    {
+        return gtk_widget_get_visible(this) != 0;
+    }
+
     void IWidget::show()
     {
         gtk_widget_show(this);
     }
 
+    Dimensions IWidget::dimensions()
+    {
+        GtkAllocation allocation;
+        gtk_widget_get_allocation(this, &allocation);
+        return Dimensions{allocation.width, allocation.height};
+    }
+
+    void IWidget::dimensions(int width, int height)
+    {
+        gtk_widget_set_size_request(this, width, height);
+    }
+
     IMPL(Container, GTK_CONTAINER);
 
     void IContainer::add(Widget widget)
@@ -97,13 +121,15 @@ namespace ui {
         gtk_container_add(this, widget);
     }
 
+    void IContainer::remove(Widget widget)
+    {
+        gtk_container_remove(this, widget);
+    }
+
     IMPL(Bin, GTK_BIN);
 
     IMPL(Window, GTK_WINDOW);
 
-    Window::Window() : Window(nullptr)
-    {}
-
     Window::Window(window_type type) : Window(GTK_WINDOW(gtk_window_new(
             type == window_type::TOP ? GTK_WINDOW_TOPLEVEL :
             type == window_type::POPUP ? GTK_WINDOW_POPUP :
@@ -176,6 +202,9 @@ namespace ui {
 
     IMPL(CheckButton, GTK_CHECK_BUTTON);
 
+    CheckButton::CheckButton() : CheckButton(GTK_CHECK_BUTTON(gtk_check_button_new()))
+    {}
+
     CheckButton::CheckButton(const char *label) : CheckButton(GTK_CHECK_BUTTON(gtk_check_button_new_with_label(label)))
     {}
 
@@ -203,6 +232,11 @@ namespace ui {
     ScrolledWindow::ScrolledWindow() : ScrolledWindow(GTK_SCROLLED_WINDOW(gtk_scrolled_window_new(nullptr, nullptr)))
     {}
 
+    void IScrolledWindow::overflow(Policy x, Policy y)
+    {
+        gtk_scrolled_window_set_policy(this, static_cast<GtkPolicyType>(x), static_cast<GtkPolicyType>(y));
+    }
+
     IMPL(VBox, GTK_VBOX);
 
     VBox::VBox(bool homogenous, int spacing) : VBox(GTK_VBOX(gtk_vbox_new(homogenous, spacing)))
@@ -240,6 +274,12 @@ namespace ui {
     TextView::TextView() : TextView(GTK_TEXT_VIEW(gtk_text_view_new()))
     {}
 
+    void ITextView::text(char const *str)
+    {
+        GtkTextBuffer *buffer = gtk_text_view_get_buffer(this);
+        gtk_text_buffer_set_text(buffer, str, -1);
+    }
+
     TreeView::TreeView() : TreeView(GTK_TREE_VIEW(gtk_tree_view_new()))
     {}
 
@@ -251,6 +291,11 @@ namespace ui {
     Label::Label(const char *label) : Label(GTK_LABEL(gtk_label_new(label)))
     {}
 
+    void ILabel::text(char const *str)
+    {
+        gtk_label_set_text(this, str);
+    }
+
     IMPL(Image, GTK_IMAGE);
 
     Image::Image() : Image(GTK_IMAGE(gtk_image_new()))
@@ -266,6 +311,16 @@ namespace ui {
         gtk_entry_set_max_length(this, static_cast<gint>(max_length));
     }
 
+    char const *IEntry::text()
+    {
+        return gtk_entry_get_text(this);
+    }
+
+    void IEntry::text(char const *str)
+    {
+        return gtk_entry_set_text(this, str);
+    }
+
     IMPL(SpinButton, GTK_SPIN_BUTTON);
 
     SpinButton::SpinButton(Adjustment adjustment, double climb_rate, std::size_t digits) : SpinButton(
@@ -304,7 +359,7 @@ namespace ui {
         for (auto &it : attributes) {
             gtk_tree_view_column_add_attribute(this, renderer, it.attribute, it.column);
         }
-    };
+    }
 
     IMPL(AccelGroup, GTK_ACCEL_GROUP);
 
@@ -326,4 +381,16 @@ namespace ui {
     TreePath::TreePath(const char *path) : TreePath(gtk_tree_path_new_from_string(path))
     {}
 
+    // Custom
+
+    guint IGLArea::on_render(GCallback pFunction, void *data)
+    {
+#if GTK_TARGET == 3
+        return this.connect("render", pFunction, data);
+#endif
+#if GTK_TARGET == 2
+        return this.connect("expose_event", pFunction, data);
+#endif
+    }
+
 }