]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/groupdialog.cpp
windows: reword a bit the gtkglext workaround
[xonotic/netradiant.git] / radiant / groupdialog.cpp
index 7b954535adc1c9a0cb064930f142b226aff3df19..d96bc7c271bea3be9beae9c5f8974eb08d7bd0d0 100644 (file)
 //
 
 #include "groupdialog.h"
+#include "globaldefs.h"
 
 #include "debugging/debugging.h"
 
 #include <vector>
-
 #include <gtk/gtk.h>
 
 #include "gtkutil/widget.h"
 #include "multimon.h"
 #include "console.h"
 #include "commands.h"
-
-
 #include "gtkutil/window.h"
 
+#if defined(WORKAROUND_WINDOWS_GTK2_GLWIDGET) || defined(WORKAROUND_MACOS_GTK2_GLWIDGET)
+#include "texwindow.h"
+#endif // WORKAROUND_WINDOWS_GTK2_GLWIDGET || WORKAROUND_MACOS_GTK2_GLWIDGET
+
 class GroupDlg
 {
 public:
-ui::Widget m_pNotebook;
-ui::Window m_window;
+ui::Widget m_pNotebook{ui::null};
+ui::Window m_window{ui::null};
 
 GroupDlg();
 void Create( ui::Window parent );
@@ -57,10 +59,10 @@ void Create( ui::Window parent );
 void Show(){
        // workaround for strange gtk behaviour - modifying the contents of a window while it is not visible causes the window position to change without sending a configure_event
        m_position_tracker.sync( m_window );
-       gtk_widget_show( GTK_WIDGET( m_window ) );
+       m_window.show();
 }
 void Hide(){
-       gtk_widget_hide( GTK_WIDGET( m_window ) );
+       m_window.hide();
 }
 
 WindowPositionTracker m_position_tracker;
@@ -71,30 +73,44 @@ namespace
 GroupDlg g_GroupDlg;
 
 std::size_t g_current_page;
-std::vector<StringExportCallback> g_pages;
+std::vector<Callback<void(const Callback<void(const char *)> &)>> g_pages;
+}
+
+static void workaround_macos_show_hide(){
+#ifdef WORKAROUND_MACOS_GTK2_GLWIDGET
+       if ( g_current_page == 2 )
+       {
+               TextureBrowser_showGLWidget();
+       }
+       else
+       {
+               TextureBrowser_hideGLWidget();
+       }
+#endif // WORKAROUND_MACOS_GTK2_GLWIDGET
 }
 
 void GroupDialog_updatePageTitle( ui::Window window, std::size_t pageIndex ){
        if ( pageIndex < g_pages.size() ) {
-               g_pages[pageIndex]( PointerCaller1<GtkWindow, const char*, gtk_window_set_title>( window ) );
+               g_pages[pageIndex]( PointerCaller<GtkWindow, void(const char*), gtk_window_set_title>( window ) );
        }
+
+       workaround_macos_show_hide();
 }
 
 static gboolean switch_page( GtkNotebook *notebook, gpointer page, guint page_num, gpointer data ){
-       GroupDialog_updatePageTitle( ui::Window(GTK_WINDOW( data )), page_num );
        g_current_page = page_num;
-
+       GroupDialog_updatePageTitle( ui::Window::from(data), page_num );
        return FALSE;
 }
 
-GroupDlg::GroupDlg() : m_window( 0 ){
+GroupDlg::GroupDlg() : m_window( ui::null ){
        m_position_tracker.setPosition( c_default_window_pos );
 }
 
 void GroupDlg::Create( ui::Window parent ){
        ASSERT_MESSAGE( !m_window, "dialog already created" );
 
-       ui::Window window = ui::Window(create_persistent_floating_window( "Entities", parent ));
+       auto window = ui::Window(create_persistent_floating_window( "Entities", parent ));
 
        global_accel_connect_window( window );
 
@@ -102,7 +118,7 @@ void GroupDlg::Create( ui::Window parent ){
 
        m_window = window;
 
-#ifdef WIN32
+#if GDEF_OS_WINDOWS
        if ( g_multimon_globals.m_bStartOnPrimMon ) {
                WindowPosition pos( m_position_tracker.getPosition() );
                PositionWindowOnPrimaryScreen( pos );
@@ -112,29 +128,27 @@ void GroupDlg::Create( ui::Window parent ){
        m_position_tracker.connect( window );
 
        {
-               ui::Widget notebook = ui::Widget(gtk_notebook_new());
-               gtk_widget_show( notebook );
-               gtk_container_add( GTK_CONTAINER( window ), notebook );
+               ui::Widget notebook = ui::Widget::from(gtk_notebook_new());
+               notebook.show();
+               window.add(notebook);
                gtk_notebook_set_tab_pos( GTK_NOTEBOOK( notebook ), GTK_POS_BOTTOM );
                m_pNotebook = notebook;
 
-               g_signal_connect( G_OBJECT(notebook), "switch_page", G_CALLBACK( switch_page ), (gpointer) window );
+               notebook.connect( "switch_page", G_CALLBACK( switch_page ), (gpointer) window );
        }
 }
 
-
-ui::Widget GroupDialog_addPage( const char* tabLabel, ui::Widget widget, const StringExportCallback& title ){
+ui::Widget GroupDialog_addPage( const char* tabLabel, ui::Widget widget, const Callback<void(const Callback<void(const char *)> &)>& title ){
        ui::Widget w = ui::Label( tabLabel );
-       gtk_widget_show( w );
-       ui::Widget page = ui::Widget(gtk_notebook_get_nth_page( GTK_NOTEBOOK( g_GroupDlg.m_pNotebook ), gtk_notebook_insert_page( GTK_NOTEBOOK( g_GroupDlg.m_pNotebook ), widget, w, -1 ) ));
+       w.show();
+       auto page = ui::Widget::from(gtk_notebook_get_nth_page( GTK_NOTEBOOK( g_GroupDlg.m_pNotebook ), gtk_notebook_insert_page( GTK_NOTEBOOK( g_GroupDlg.m_pNotebook ), widget, w, -1 ) ));
        g_pages.push_back( title );
 
        return page;
 }
 
-
 bool GroupDialog_isShown(){
-       return widget_is_visible( GTK_WIDGET( g_GroupDlg.m_window ) );
+       return g_GroupDlg.m_window.visible();
 }
 void GroupDialog_setShown( bool shown ){
        shown ? g_GroupDlg.Show() : g_GroupDlg.Hide();
@@ -149,10 +163,9 @@ void GroupDialog_constructWindow( ui::Window main_window ){
 void GroupDialog_destroyWindow(){
        ASSERT_TRUE( g_GroupDlg.m_window );
        destroy_floating_window( g_GroupDlg.m_window );
-       g_GroupDlg.m_window = ui::Window();
+       g_GroupDlg.m_window = ui::Window{ui::null};
 }
 
-
 ui::Window GroupDialog_getWindow(){
        return ui::Window(g_GroupDlg.m_window);
 }
@@ -161,28 +174,46 @@ void GroupDialog_show(){
 }
 
 ui::Widget GroupDialog_getPage(){
-       return ui::Widget(gtk_notebook_get_nth_page( GTK_NOTEBOOK( g_GroupDlg.m_pNotebook ), gint( g_current_page ) ));
+       return ui::Widget::from(gtk_notebook_get_nth_page( GTK_NOTEBOOK( g_GroupDlg.m_pNotebook ), gint( g_current_page ) ) );
 }
 
 void GroupDialog_setPage( ui::Widget page ){
        g_current_page = gtk_notebook_page_num( GTK_NOTEBOOK( g_GroupDlg.m_pNotebook ), page );
        gtk_notebook_set_current_page( GTK_NOTEBOOK( g_GroupDlg.m_pNotebook ), gint( g_current_page ) );
+
+       workaround_macos_show_hide();
+}
+
+#ifdef WORKAROUND_WINDOWS_GTK2_GLWIDGET
+void GroupDialog_cycle(){
+       g_current_page = ( g_current_page + 1 ) % g_pages.size();
+       gtk_notebook_set_current_page( GTK_NOTEBOOK( g_GroupDlg.m_pNotebook ), gint( g_current_page ) );
 }
+#endif // WORKAROUND_WINDOWS_GTK2_GLWIDGET
 
 void GroupDialog_showPage( ui::Widget page ){
+
        if ( GroupDialog_getPage() == page ) {
                GroupDialog_ToggleShow();
+
+#ifdef WORKAROUND_WINDOWS_GTK2_GLWIDGET
+               /* workaround for gtk 2.24 issue: not displayed glwidget after toggle */
+               /* this is very ugly: cycle to next tab then return to current tab immediately to force the refresh
+                * this fixes the drawing of texture tab when window is restored and current tab is texture tab
+                * this is called for nothing when windows is minimized and called for nothing when current tab
+                * is not texture tab, hopefully it's a workaround that would disappear with gtk 3 */
+               GroupDialog_cycle();
+               GroupDialog_setPage( page );
+#endif // WORKAROUND_WINDOWS_GTK2_GLWIDGET
+
        }
        else
        {
-               gtk_widget_show( GTK_WIDGET( g_GroupDlg.m_window ) );
+               g_GroupDlg.m_window.show();
                GroupDialog_setPage( page );
        }
-}
 
-void GroupDialog_cycle(){
-       g_current_page = ( g_current_page + 1 ) % g_pages.size();
-       gtk_notebook_set_current_page( GTK_NOTEBOOK( g_GroupDlg.m_pNotebook ), gint( g_current_page ) );
+       workaround_macos_show_hide();
 }
 
 void GroupDialog_updatePageTitle( ui::Widget page ){
@@ -191,13 +222,12 @@ void GroupDialog_updatePageTitle( ui::Widget page ){
        }
 }
 
-
 #include "preferencesystem.h"
 
 void GroupDialog_Construct(){
-       GlobalPreferenceSystem().registerPreference( "EntityWnd", WindowPositionTrackerImportStringCaller( g_GroupDlg.m_position_tracker ), WindowPositionTrackerExportStringCaller( g_GroupDlg.m_position_tracker ) );
+       GlobalPreferenceSystem().registerPreference( "EntityWnd", make_property<WindowPositionTracker_String>( g_GroupDlg.m_position_tracker ) );
 
-       GlobalCommands_insert( "ViewEntityInfo", FreeCaller<GroupDialog_ToggleShow>(), Accelerator( 'N' ) );
+       GlobalCommands_insert( "ViewEntityInfo", makeCallbackF(GroupDialog_ToggleShow), Accelerator( 'N' ) );
 }
 void GroupDialog_Destroy(){
 }