]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - libs/uilib/uilib.cpp
Merge commit '146d231d90b19e2a0edcabff1c4eb9ca44e053e7' into master-merge
[xonotic/netradiant.git] / libs / uilib / uilib.cpp
index 1b19229146ead12332f04c0f374cac2fa1434528..8a34ded32e95a139519765e1638c5f1b4c43d1fe 100644 (file)
@@ -36,8 +36,6 @@ namespace ui {
         }
     }
 
-    Widget root{ui::null};
-
 #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::from(F(it)); } }
 
@@ -89,6 +87,16 @@ namespace ui {
     void IWidget::visible(bool shown)
     {
         if (shown) {
+
+#ifdef WORKAROUND_WINDOWS_GTK2_GLWIDGET
+            /* workaround for gtk 2.24 issue: not displayed glwidget after toggle */
+            GtkWidget* glwidget = GTK_WIDGET( g_object_get_data( G_OBJECT( this ), "glwidget" ) );
+            if ( glwidget ){
+                gtk_widget_hide( glwidget );
+                gtk_widget_show( glwidget );
+            }
+#endif // WORKAROUND_WINDOWS_GTK2_GLWIDGET
+
             this.show();
         } else {
             this.hide();
@@ -145,31 +153,6 @@ namespace ui {
     )))
     {}
 
-    alert_response IWindow::alert(std::string text, std::string title, alert_type type, alert_icon icon)
-    {
-        auto ret = gtk_MessageBox(this, text.c_str(),
-                                  title.c_str(),
-                                  type == alert_type::OK ? eMB_OK :
-                                  type == alert_type::OKCANCEL ? eMB_OKCANCEL :
-                                  type == alert_type::YESNO ? eMB_YESNO :
-                                  type == alert_type::YESNOCANCEL ? eMB_YESNOCANCEL :
-                                  type == alert_type::NOYES ? eMB_NOYES :
-                                  eMB_OK,
-                                  icon == alert_icon::Default ? eMB_ICONDEFAULT :
-                                  icon == alert_icon::Error ? eMB_ICONERROR :
-                                  icon == alert_icon::Warning ? eMB_ICONWARNING :
-                                  icon == alert_icon::Question ? eMB_ICONQUESTION :
-                                  icon == alert_icon::Asterisk ? eMB_ICONASTERISK :
-                                  eMB_ICONDEFAULT
-        );
-        return
-                ret == eIDOK ? alert_response::OK :
-                ret == eIDCANCEL ? alert_response::CANCEL :
-                ret == eIDYES ? alert_response::YES :
-                ret == eIDNO ? alert_response::NO :
-                alert_response::OK;
-    }
-
     Window IWindow::create_dialog_window(const char *title, void func(), void *data, int default_w, int default_h)
     {
         return Window(::create_dialog_window(this, title, func, data, default_w, default_h));
@@ -287,6 +270,11 @@ namespace ui {
         gtk_box_pack_end(this, child, expand, fill, padding);
     }
 
+    void IBox::set_child_packing(ui::Widget child, bool expand, bool fill, unsigned int padding, ui::Packing packing)
+    {
+        gtk_box_set_child_packing(this, child, expand, fill, padding, (GtkPackType) packing);
+    }
+
     IMPL(VBox, GTK_VBOX);
 
     VBox::VBox(bool homogenous, int spacing) : VBox(GTK_VBOX(gtk_vbox_new(homogenous, spacing)))
@@ -338,6 +326,8 @@ namespace ui {
         gtk_text_buffer_set_text(buffer, str, -1);
     }
 
+    IMPL(TreeView, GTK_TREE_VIEW);
+
     TreeView::TreeView(ui::New_t) : TreeView(GTK_TREE_VIEW(gtk_tree_view_new()))
     {}
 
@@ -450,7 +440,7 @@ namespace ui {
 
 #if GTK_TARGET == 3
 
-    IMPL(GLArea, (void *));
+    IMPL(GLArea, GTK_GL_AREA);
 
 #elif GTK_TARGET == 2
 
@@ -468,4 +458,33 @@ namespace ui {
 #endif
     }
 
+    // global
+
+    Window root{ui::null};
+
+    alert_response alert(Window parent, std::string text, std::string title, alert_type type, alert_icon icon)
+    {
+        auto ret = gtk_MessageBox(parent, text.c_str(),
+                                  title.c_str(),
+                                  type == alert_type::OK ? eMB_OK :
+                                  type == alert_type::OKCANCEL ? eMB_OKCANCEL :
+                                  type == alert_type::YESNO ? eMB_YESNO :
+                                  type == alert_type::YESNOCANCEL ? eMB_YESNOCANCEL :
+                                  type == alert_type::NOYES ? eMB_NOYES :
+                                  eMB_OK,
+                                  icon == alert_icon::Default ? eMB_ICONDEFAULT :
+                                  icon == alert_icon::Error ? eMB_ICONERROR :
+                                  icon == alert_icon::Warning ? eMB_ICONWARNING :
+                                  icon == alert_icon::Question ? eMB_ICONQUESTION :
+                                  icon == alert_icon::Asterisk ? eMB_ICONASTERISK :
+                                  eMB_ICONDEFAULT
+        );
+        return
+                ret == eIDOK ? alert_response::OK :
+                ret == eIDCANCEL ? alert_response::CANCEL :
+                ret == eIDYES ? alert_response::YES :
+                ret == eIDNO ? alert_response::NO :
+                alert_response::OK;
+    }
+
 }