]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/mainframe.cpp
GTK: wrap gtk_widget_set_size_request
[xonotic/netradiant.git] / radiant / mainframe.cpp
index 3195f8d3e031c5d15e430a56f8f0da5ef1aa149f..f23f73237c4b29f0fa3cfcdad4079efa29f239a0 100644 (file)
@@ -26,6 +26,7 @@
 //
 
 #include "mainframe.h"
+#include "globaldefs.h"
 
 #include <gtk/gtk.h>
 
@@ -180,7 +181,7 @@ void VFS_Destroy(){
 
 // Home Paths
 
-#ifdef WIN32
+#if GDEF_OS_WINDOWS
 #include <shlobj.h>
 #include <objbase.h>
 const GUID qFOLDERID_SavedGames = {0x4C5C32FF, 0xBB9D, 0x43b0, {0xB5, 0xB4, 0x2D, 0x72, 0xE5, 0x4E, 0xAA, 0xA4}};
@@ -197,7 +198,7 @@ void HomePaths_Realise(){
                if ( !string_empty( prefix ) ) {
                        StringOutputStream path( 256 );
 
-#if defined( __APPLE__ )
+#if GDEF_OS_MACOS
                        path.clear();
                        path << DirectoryCleaned( g_get_home_dir() ) << "Library/Application Support" << ( prefix + 1 ) << "/";
                        if ( file_is_directory( path.c_str() ) ) {
@@ -208,7 +209,7 @@ void HomePaths_Realise(){
                        path << DirectoryCleaned( g_get_home_dir() ) << prefix << "/";
 #endif
 
-#if defined( WIN32 )
+#if GDEF_OS_WINDOWS
                        TCHAR mydocsdir[MAX_PATH + 1];
                        wchar_t *mydocsdirw;
                        HMODULE shfolder = LoadLibrary( "shfolder.dll" );
@@ -247,7 +248,7 @@ void HomePaths_Realise(){
                        }
 #endif
 
-#if defined( POSIX )
+#if GDEF_OS_POSIX
                        path.clear();
                        path << DirectoryCleaned( g_get_home_dir() ) << prefix << "/";
                        g_qeglobals.m_userEnginePath = path.c_str();
@@ -539,11 +540,11 @@ void operator()( const char* name ) const {
 const char* const c_library_extension =
 #if defined( CMAKE_SHARED_MODULE_SUFFIX )
     CMAKE_SHARED_MODULE_SUFFIX
-#elif defined( WIN32 )
+#elif GDEF_OS_WINDOWS
        "dll"
-#elif defined ( __APPLE__ )
+#elif GDEF_OS_MACOS
        "dylib"
-#elif defined( __linux__ ) || defined ( __FreeBSD__ )
+#elif GDEF_OS_LINUX || GDEF_OS_BSD
        "so"
 #endif
 ;
@@ -1630,7 +1631,7 @@ WaitDialog create_wait_dialog( const char* title, const char* text ){
                gtk_misc_set_alignment( GTK_MISC( dialog.m_label ), 0.0, 0.5 );
                gtk_label_set_justify( dialog.m_label, GTK_JUSTIFY_LEFT );
                dialog.m_label.show();
-               gtk_widget_set_size_request( GTK_WIDGET( dialog.m_label ), 200, -1 );
+               dialog.m_label.dimensions(200, -1);
 
                dialog.m_window.add(dialog.m_label);
        }
@@ -1658,7 +1659,7 @@ bool MainFrame_isActiveApp(){
        for ( GList* i = list; i != 0; i = g_list_next( i ) )
        {
                //globalOutputStream() << "toplevel.. ";
-               if ( gtk_window_is_active( GTK_WINDOW( i->data ) ) ) {
+               if ( gtk_window_is_active( ui::Window::from( i->data ) ) ) {
                        //globalOutputStream() << "is active\n";
                        return true;
                }
@@ -1691,7 +1692,7 @@ void ScreenUpdates_Disable( const char* message, const char* title ){
                bool isActiveApp = MainFrame_isActiveApp();
 
                g_wait = create_wait_dialog( title, message );
-               gtk_grab_add( GTK_WIDGET( g_wait.m_window ) );
+               gtk_grab_add( g_wait.m_window  );
 
                if ( isActiveApp ) {
                        g_wait.m_window.show();
@@ -1710,9 +1711,9 @@ void ScreenUpdates_Enable(){
        g_wait_stack.pop_back();
        if ( g_wait_stack.empty() ) {
                EverySecondTimer_enable();
-               //gtk_widget_set_sensitive(GTK_WIDGET(MainFrame_getWindow()), TRUE);
+               //gtk_widget_set_sensitive(MainFrame_getWindow(), TRUE);
 
-               gtk_grab_remove( GTK_WIDGET( g_wait.m_window ) );
+               gtk_grab_remove( g_wait.m_window  );
                destroy_floating_window( g_wait.m_window );
                g_wait.m_window = ui::Window{ui::null};
 
@@ -2165,7 +2166,7 @@ ui::MenuItem create_help_menu(){
        return help_menu_item;
 }
 
-GtkMenuBar* create_main_menu( MainFrame::EViewStyle style ){
+ui::MenuBar create_main_menu( MainFrame::EViewStyle style ){
        auto menu_bar = ui::MenuBar(GTK_MENU_BAR( gtk_menu_bar_new() ));
        menu_bar.show();
 
@@ -2320,7 +2321,7 @@ ui::Toolbar create_main_toolbar( MainFrame::EViewStyle style ){
        toolbar.show();
 
        auto space = [&]() {
-               auto btn = ui::Widget(GTK_WIDGET(gtk_separator_tool_item_new()));
+               auto btn = ui::ToolItem(gtk_separator_tool_item_new());
                btn.show();
                toolbar.add(btn);
        };
@@ -2385,8 +2386,8 @@ ui::Toolbar create_main_toolbar( MainFrame::EViewStyle style ){
 
        // disable the console and texture button in the regular layouts
        if ( style == MainFrame::eRegular || style == MainFrame::eRegularLeft ) {
-               gtk_widget_set_sensitive( GTK_WIDGET( g_view_console_button ), FALSE );
-               gtk_widget_set_sensitive( GTK_WIDGET( g_view_textures_button ), FALSE );
+               gtk_widget_set_sensitive( g_view_console_button , FALSE );
+               gtk_widget_set_sensitive( g_view_textures_button , FALSE );
        }
 
        return toolbar;
@@ -2401,15 +2402,15 @@ ui::Widget create_main_statusbar( ui::Widget pStatusLabel[c_count_status] ){
                gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
                gtk_misc_set_padding( GTK_MISC( label ), 4, 2 );
                label.show();
-               gtk_table_attach_defaults( table, GTK_WIDGET( label ), 0, 1, 0, 1 );
-               pStatusLabel[c_command_status] = ui::Widget(GTK_WIDGET( label ));
+               table.attach(label, {0, 1, 0, 1});
+               pStatusLabel[c_command_status] = ui::Widget(label );
        }
 
-       for ( int i = 1; i < c_count_status; ++i )
+       for (unsigned int i = 1; (int) i < c_count_status; ++i)
        {
                auto frame = ui::Frame();
                frame.show();
-               gtk_table_attach_defaults( table, GTK_WIDGET( frame ), i, i + 1, 0, 1 );
+               table.attach(frame, {i, i + 1, 0, 1});
                gtk_frame_set_shadow_type( frame, GTK_SHADOW_IN );
 
                auto label = ui::Label( "Label" );
@@ -2418,10 +2419,10 @@ ui::Widget create_main_statusbar( ui::Widget pStatusLabel[c_count_status] ){
                gtk_misc_set_padding( GTK_MISC( label ), 4, 2 );
                label.show();
                frame.add(label);
-               pStatusLabel[i] = ui::Widget(GTK_WIDGET( label ));
+               pStatusLabel[i] = ui::Widget(label );
        }
 
-       return ui::Widget(GTK_WIDGET( table ));
+       return ui::Widget(table );
 }
 
 #if 0
@@ -2520,7 +2521,7 @@ MainFrame::MainFrame() : m_idleRedrawStatusText( RedrawStatusTextCaller( *this )
        m_pActiveXY = 0;
 
        for (auto &n : m_pStatusLabel) {
-        n = ui::Label{ui::null};
+        n = NULL;
        }
 
        m_bSleeping = false;
@@ -2531,16 +2532,16 @@ MainFrame::MainFrame() : m_idleRedrawStatusText( RedrawStatusTextCaller( *this )
 MainFrame::~MainFrame(){
        SaveWindowInfo();
 
-       gtk_widget_hide( GTK_WIDGET( m_window ) );
+       m_window.hide();
 
        Shutdown();
 
        for ( std::vector<ui::Widget>::iterator i = g_floating_windows.begin(); i != g_floating_windows.end(); ++i )
        {
-               gtk_widget_destroy( *i );
+               i->destroy();
        }
 
-       gtk_widget_destroy( GTK_WIDGET( m_window ) );
+       m_window.destroy();
 }
 
 void MainFrame::SetActiveXY( XYWnd* p ){
@@ -2602,7 +2603,7 @@ void MainFrame::CreateContexts(){
 #endif
 }
 
-#ifdef _DEBUG
+#if GDEF_DEBUG
 //#define DBG_SLEEP
 #endif
 
@@ -2673,7 +2674,7 @@ ui::Window create_splash(){
        image.show();
        window.add(image);
 
-       gtk_widget_set_size_request( GTK_WIDGET( window ), -1, -1 );
+       window.dimensions(-1, -1);
        window.show();
 
        return window;
@@ -2688,7 +2689,7 @@ void show_splash(){
 }
 
 void hide_splash(){
-       gtk_widget_destroy( GTK_WIDGET( splash_screen ) );
+       splash_screen.destroy();
 }
 
 WindowPositionTracker g_posCamWnd;
@@ -2711,7 +2712,7 @@ void MainFrame::Create(){
 
        gtk_window_set_transient_for( splash_screen, window );
 
-#if !defined( WIN32 )
+#if !GDEF_OS_WINDOWS
        {
                GdkPixbuf* pixbuf = pixbuf_new_from_file_with_mask( "bitmaps/icon.png" );
                if ( pixbuf != 0 ) {
@@ -2721,7 +2722,7 @@ void MainFrame::Create(){
        }
 #endif
 
-       gtk_widget_add_events( GTK_WIDGET( window ), GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_FOCUS_CHANGE_MASK );
+       gtk_widget_add_events( window , GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_FOCUS_CHANGE_MASK );
        window.connect( "delete_event", G_CALLBACK( mainframe_delete ), this );
 
        m_position_tracker.connect( window );
@@ -2735,7 +2736,7 @@ void MainFrame::Create(){
 
        GetPlugInMgr().Init( window );
 
-       ui::Widget vbox = ui::VBox( FALSE, 0 );
+       auto vbox = ui::VBox( FALSE, 0 );
        window.add(vbox);
        vbox.show();
 
@@ -2745,20 +2746,20 @@ void MainFrame::Create(){
 
        register_shortcuts();
 
-       GtkMenuBar* main_menu = create_main_menu( CurrentStyle() );
-       gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( main_menu ), FALSE, FALSE, 0 );
+    auto main_menu = create_main_menu( CurrentStyle() );
+       vbox.pack_start( main_menu, FALSE, FALSE, 0 );
 
-       GtkToolbar* main_toolbar = create_main_toolbar( CurrentStyle() );
-       gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( main_toolbar ), FALSE, FALSE, 0 );
+    auto main_toolbar = create_main_toolbar( CurrentStyle() );
+       vbox.pack_start( main_toolbar, FALSE, FALSE, 0 );
 
-       GtkToolbar* plugin_toolbar = create_plugin_toolbar();
+       auto plugin_toolbar = create_plugin_toolbar();
        if ( !g_Layout_enablePluginToolbar.m_value ) {
-               gtk_widget_hide( GTK_WIDGET( plugin_toolbar ) );
+               plugin_toolbar.hide();
        }
-       gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( plugin_toolbar ), FALSE, FALSE, 0 );
+       vbox.pack_start( plugin_toolbar, FALSE, FALSE, 0 );
 
        ui::Widget main_statusbar = create_main_statusbar(reinterpret_cast<ui::Widget *>(m_pStatusLabel));
-       gtk_box_pack_end( GTK_BOX( vbox ), main_statusbar, FALSE, TRUE, 2 );
+       vbox.pack_end(main_statusbar, FALSE, TRUE, 2);
 
        GroupDialog_constructWindow( window );
        g_page_entity = GroupDialog_addPage( "Entities", EntityInspector_constructWindow( GroupDialog_getWindow() ), RawStringExportCaller( "Entities" ) );
@@ -2767,7 +2768,7 @@ void MainFrame::Create(){
                g_page_console = GroupDialog_addPage( "Console", Console_constructWindow( GroupDialog_getWindow() ), RawStringExportCaller( "Console" ) );
        }
 
-#ifdef WIN32
+#if GDEF_OS_WINDOWS
        if ( g_multimon_globals.m_bStartOnPrimMon ) {
                PositionWindowOnPrimaryScreen( g_layout_globals.m_position );
                window_set_position( window, g_layout_globals.m_position );
@@ -2792,7 +2793,7 @@ void MainFrame::Create(){
                {
                        ui::Widget vsplit = ui::VPaned(ui::New);
                        m_vSplit = vsplit;
-                       gtk_box_pack_start( GTK_BOX( vbox ), vsplit, TRUE, TRUE, 0 );
+                       vbox.pack_start( vsplit, TRUE, TRUE, 0 );
                        vsplit.show();
 
                        // console
@@ -2808,7 +2809,7 @@ void MainFrame::Create(){
                                // xy
                                m_pXYWnd = new XYWnd();
                                m_pXYWnd->SetViewType( XY );
-                               ui::Widget xy_window = ui::Widget(GTK_WIDGET( create_framed_widget( m_pXYWnd->GetWidget() ) ));
+                               ui::Widget xy_window = ui::Widget(create_framed_widget( m_pXYWnd->GetWidget( ) ));
 
                                {
                                        ui::Widget vsplit2 = ui::VPaned(ui::New);
@@ -2830,14 +2831,14 @@ void MainFrame::Create(){
                                        m_pCamWnd = NewCamWnd();
                                        GlobalCamera_setCamWnd( *m_pCamWnd );
                                        CamWnd_setParent( *m_pCamWnd, window );
-                                       GtkFrame* camera_window = create_framed_widget( CamWnd_getWidget( *m_pCamWnd ) );
+                                       auto camera_window = create_framed_widget( CamWnd_getWidget( *m_pCamWnd ) );
 
-                                       gtk_paned_add1( GTK_PANED( vsplit2 ), GTK_WIDGET( camera_window ) );
+                                       gtk_paned_add1( GTK_PANED( vsplit2 ), camera_window  );
 
                                        // textures
-                                       GtkFrame* texture_window = create_framed_widget( TextureBrowser_constructWindow( window ) );
+                                       auto texture_window = create_framed_widget( TextureBrowser_constructWindow( window ) );
 
-                                       gtk_paned_add2( GTK_PANED( vsplit2 ), GTK_WIDGET( texture_window ) );
+                                       gtk_paned_add2( GTK_PANED( vsplit2 ), texture_window  );
                                }
                        }
                }
@@ -2932,8 +2933,8 @@ void MainFrame::Create(){
                }
 
                {
-                       GtkFrame* frame = create_framed_widget( TextureBrowser_constructWindow( GroupDialog_getWindow() ) );
-                       g_page_textures = GroupDialog_addPage( "Textures", ui::Widget(GTK_WIDGET( frame )), TextureBrowserExportTitleCaller() );
+                       auto frame = create_framed_widget( TextureBrowser_constructWindow( GroupDialog_getWindow() ) );
+                       g_page_textures = GroupDialog_addPage( "Textures", frame, TextureBrowserExportTitleCaller() );
                }
 
                GroupDialog_show();
@@ -2961,12 +2962,12 @@ void MainFrame::Create(){
 
                ui::Widget xz = m_pXZWnd->GetWidget();
 
-               GtkHPaned* split = create_split_views( camera, yz, xy, xz );
-               gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( split ), TRUE, TRUE, 0 );
+        auto split = create_split_views( camera, yz, xy, xz );
+               vbox.pack_start( split, TRUE, TRUE, 0 );
 
                {
-                       GtkFrame* frame = create_framed_widget( TextureBrowser_constructWindow( window ) );
-                       g_page_textures = GroupDialog_addPage( "Textures", ui::Widget(GTK_WIDGET( frame )), TextureBrowserExportTitleCaller() );
+            auto frame = create_framed_widget( TextureBrowser_constructWindow( window ) );
+                       g_page_textures = GroupDialog_addPage( "Textures", frame, TextureBrowserExportTitleCaller() );
                }
        }
 
@@ -3007,7 +3008,7 @@ void MainFrame::SaveWindowInfo(){
 
        g_layout_globals.m_position = m_position_tracker.getPosition();
 
-       g_layout_globals.nState = gdk_window_get_state( gtk_widget_get_window(GTK_WIDGET( m_window )) );
+       g_layout_globals.nState = gdk_window_get_state( gtk_widget_get_window(m_window ) );
 }
 
 void MainFrame::Shutdown(){
@@ -3107,7 +3108,7 @@ void GlobalGL_sharedContextCreated(){
        GlobalShaderCache().realise();
        Textures_Realise();
 
-#ifdef WIN32
+#if GDEF_OS_WINDOWS
        /* win32 is dodgy here, just use courier new then */
        g_font = glfont_create( "arial 9" );
 #else
@@ -3313,11 +3314,11 @@ void MainFrame_Construct(){
 
        {
                const char* ENGINEPATH_ATTRIBUTE =
-#if defined( WIN32 )
+#if GDEF_OS_WINDOWS
                        "enginepath_win32"
-#elif defined( __APPLE__ )
+#elif GDEF_OS_MACOS
                        "enginepath_macos"
-#elif defined( __linux__ ) || defined ( __FreeBSD__ )
+#elif GDEF_OS_LINUX || GDEF_OS_BSD
                        "enginepath_linux"
 #else
 #error "unknown platform"