From 2c07c3a2aaa0b9b16a8fcd50259ebbf28d9f9dc9 Mon Sep 17 00:00:00 2001 From: TimePath Date: Wed, 19 Jul 2017 21:33:18 +1000 Subject: [PATCH] Propagate ui::Window --- CMakeLists.txt | 8 +++++ contrib/sunplug/sunplug.cpp | 4 +-- contrib/ufoaiplug/ufoai_gtk.cpp | 13 +------ libs/gtkutil/accelerator.cpp | 47 +++++++----------------- libs/gtkutil/accelerator.h | 11 +++--- libs/gtkutil/cursor.cpp | 4 +-- libs/gtkutil/cursor.h | 14 ++++---- libs/gtkutil/dialog.cpp | 16 ++++----- libs/gtkutil/dialog.h | 13 ++++--- libs/gtkutil/menu.cpp | 2 +- libs/gtkutil/messagebox.cpp | 10 +++--- libs/gtkutil/window.cpp | 28 +++++++-------- libs/gtkutil/window.h | 25 ++++++------- libs/uilib/uilib.cpp | 63 ++++++++++++++++++--------------- libs/uilib/uilib.h | 3 ++ radiant/commands.cpp | 4 +-- radiant/dialog.h | 1 - radiant/entitylist.cpp | 2 +- radiant/gtkdlgs.cpp | 20 +++++------ radiant/gtkmisc.cpp | 2 +- radiant/main.cpp | 4 --- radiant/mainframe.h | 1 - radiant/map.cpp | 4 +-- radiant/patchmanip.cpp | 8 ++--- radiant/select.cpp | 8 ++--- radiant/xywindow.cpp | 2 +- 26 files changed, 146 insertions(+), 171 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9af79ce9..3cbb897b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -89,6 +89,14 @@ if (NOT CMAKE_BUILD_TYPE MATCHES Release) add_definitions(-D_DEBUG=1) endif () +add_definitions( + -DGTK_DISABLE_SINGLE_INCLUDES + -DGDK_PIXBUF_DISABLE_SINGLE_INCLUDES + -DGSEAL_ENABLE + -DGTK_DISABLE_DEPRECATED + -DGDK_DISABLE_DEPRECATED +) + if (APPLE) option(XWINDOWS "Build against X11" ON) add_definitions( diff --git a/contrib/sunplug/sunplug.cpp b/contrib/sunplug/sunplug.cpp index 7bc81d34..9caa98fb 100644 --- a/contrib/sunplug/sunplug.cpp +++ b/contrib/sunplug/sunplug.cpp @@ -184,11 +184,11 @@ SunPlugPluginDependencies() : // ************************* namespace SunPlug { -GtkWindow* main_window; +ui::Window main_window; char MenuList[100] = ""; const char* init( void* hApp, void* pMainWidget ){ - main_window = GTK_WINDOW( pMainWidget ); + main_window = ui::Window(GTK_WINDOW( pMainWidget )); return "Initializing SunPlug for GTKRadiant"; } const char* getName(){ diff --git a/contrib/ufoaiplug/ufoai_gtk.cpp b/contrib/ufoaiplug/ufoai_gtk.cpp index c5470474..072b8c7e 100644 --- a/contrib/ufoaiplug/ufoai_gtk.cpp +++ b/contrib/ufoaiplug/ufoai_gtk.cpp @@ -23,18 +23,7 @@ #include "iscenegraph.h" #include - -/** - * GTK callback functions - */ - -class UFOAIGtk -{ -GtkWindow* m_gtk_window; -public: -UFOAIGtk( void* gtk_window ) : m_gtk_window( ( GtkWindow* )gtk_window ){ -} -}; +#include /** * @brief If you return FALSE in the "delete_event" signal handler, diff --git a/libs/gtkutil/accelerator.cpp b/libs/gtkutil/accelerator.cpp index c00dcf60..09cc7aa1 100644 --- a/libs/gtkutil/accelerator.cpp +++ b/libs/gtkutil/accelerator.cpp @@ -125,7 +125,7 @@ bool AcceleratorMap_activate( const AcceleratorMap& acceleratorMap, const Accele return false; } -static gboolean accelerator_key_event( GtkWindow* window, GdkEventKey* event, AcceleratorMap* acceleratorMap ){ +static gboolean accelerator_key_event( ui::Window window, GdkEventKey* event, AcceleratorMap* acceleratorMap ){ return AcceleratorMap_activate( *acceleratorMap, accelerator_for_event_key( event->keyval, event->state ) ); } @@ -172,7 +172,7 @@ ButtonMask ButtonMask_for_event_button( guint button ){ return 0; } -bool window_has_accel( GtkWindow* toplevel ){ +bool window_has_accel( ui::Window toplevel ){ return g_slist_length( gtk_accel_groups_from_object( G_OBJECT( toplevel ) ) ) != 0; } @@ -221,14 +221,7 @@ void globalQueuedAccelerators_commit(){ g_queuedAcceleratorsAdd.clear(); } -void accel_group_test( GtkWindow* toplevel, GtkAccelGroup* accel ){ - guint n_entries; - gtk_accel_group_query( accel, '4', (GdkModifierType)0, &n_entries ); - globalOutputStream() << "grid4: " << n_entries << "\n"; - globalOutputStream() << "toplevel accelgroups: " << g_slist_length( gtk_accel_groups_from_object( G_OBJECT( toplevel ) ) ) << "\n"; -} - -typedef std::set WindowSet; +typedef std::set WindowSet; WindowSet g_accel_windows; bool Buttons_press( ButtonMask& buttons, guint button, guint state ){ @@ -237,15 +230,12 @@ bool Buttons_press( ButtonMask& buttons, guint button, guint state ){ g_accel_enabled = false; for ( WindowSet::iterator i = g_accel_windows.begin(); i != g_accel_windows.end(); ++i ) { - GtkWindow* toplevel = *i; + ui::Window toplevel = *i; ASSERT_MESSAGE( window_has_accel( toplevel ), "ERROR" ); ASSERT_MESSAGE( gtk_widget_is_toplevel( GTK_WIDGET(toplevel) ), "disabling accel for non-toplevel window" ); gtk_window_remove_accel_group( toplevel, global_accel ); #if 0 globalOutputStream() << reinterpret_cast( toplevel ) << ": disabled global accelerators\n"; -#endif -#if 0 - accel_group_test( toplevel, global_accel ); #endif } } @@ -263,15 +253,12 @@ bool Buttons_release( ButtonMask& buttons, guint button, guint state ){ g_accel_enabled = true; for ( WindowSet::iterator i = g_accel_windows.begin(); i != g_accel_windows.end(); ++i ) { - GtkWindow* toplevel = *i; + ui::Window toplevel = *i; ASSERT_MESSAGE( !window_has_accel( toplevel ), "ERROR" ); ASSERT_MESSAGE( gtk_widget_is_toplevel( GTK_WIDGET(toplevel) ), "enabling accel for non-toplevel window" ); - gtk_window_add_accel_group( toplevel, global_accel ); + toplevel.add_accel_group( global_accel ); #if 0 globalOutputStream() << reinterpret_cast( toplevel ) << ": enabled global accelerators\n"; -#endif -#if 0 - accel_group_test( toplevel, global_accel ); #endif } globalQueuedAccelerators_commit(); @@ -391,7 +378,7 @@ void GlobalPressedKeys_releaseAll(){ Keys_releaseAll( g_pressedKeys.keys, 0 ); } -void GlobalPressedKeys_connect( GtkWindow* window ){ +void GlobalPressedKeys_connect( ui::Window window ){ unsigned int key_press_handler = g_signal_connect( G_OBJECT( window ), "key_press_event", G_CALLBACK( PressedKeys_key_press ), &g_pressedKeys ); unsigned int key_release_handler = g_signal_connect( G_OBJECT( window ), "key_release_event", G_CALLBACK( PressedKeys_key_release ), &g_pressedKeys ); g_object_set_data( G_OBJECT( window ), "key_press_handler", gint_to_pointer( key_press_handler ) ); @@ -402,7 +389,7 @@ void GlobalPressedKeys_connect( GtkWindow* window ){ g_object_set_data( G_OBJECT( window ), "focus_out_handler", gint_to_pointer( focus_out_handler ) ); } -void GlobalPressedKeys_disconnect( GtkWindow* window ){ +void GlobalPressedKeys_disconnect( ui::Window window ){ g_signal_handler_disconnect( G_OBJECT( window ), gpointer_to_int( g_object_get_data( G_OBJECT( window ), "key_press_handler" ) ) ); g_signal_handler_disconnect( G_OBJECT( window ), gpointer_to_int( g_object_get_data( G_OBJECT( window ), "key_release_handler" ) ) ); g_signal_handler_disconnect( G_OBJECT( window ), gpointer_to_int( g_object_get_data( G_OBJECT( window ), "focus_in_handler" ) ) ); @@ -481,15 +468,7 @@ void accel_group_remove_accelerator( GtkAccelGroup* group, Accelerator accelerat } } -GtkAccelGroup* global_accel = 0; - -void global_accel_init(){ - global_accel = ui::AccelGroup(); -} - -void global_accel_destroy(){ - g_object_unref( global_accel ); -} +ui::AccelGroup global_accel = ui::AccelGroup(); GClosure* global_accel_group_add_accelerator( Accelerator accelerator, const Callback& callback ){ if ( !global_accel_enabled() ) { @@ -510,12 +489,12 @@ void global_accel_group_remove_accelerator( Accelerator accelerator ){ } /// \brief Propagates key events to the focus-widget, overriding global accelerators. -static gboolean override_global_accelerators( GtkWindow* window, GdkEventKey* event, gpointer data ){ +static gboolean override_global_accelerators( ui::Window window, GdkEventKey* event, gpointer data ){ gboolean b = gtk_window_propagate_key_event( window, event ); return b; } -void global_accel_connect_window( GtkWindow* window ){ +void global_accel_connect_window( ui::Window window ){ #if 1 unsigned int override_handler = g_signal_connect( G_OBJECT( window ), "key_press_event", G_CALLBACK( override_global_accelerators ), 0 ); g_object_set_data( G_OBJECT( window ), "override_handler", gint_to_pointer( override_handler ) ); @@ -531,9 +510,9 @@ void global_accel_connect_window( GtkWindow* window ){ g_object_set_data( G_OBJECT( window ), "key_release_handler", gint_to_pointer( key_release_handler ) ); #endif g_accel_windows.insert( window ); - gtk_window_add_accel_group( window, global_accel ); + window.add_accel_group( global_accel ); } -void global_accel_disconnect_window( GtkWindow* window ){ +void global_accel_disconnect_window( ui::Window window ){ #if 1 GlobalPressedKeys_disconnect( window ); diff --git a/libs/gtkutil/accelerator.h b/libs/gtkutil/accelerator.h index a02572e7..0a47ba49 100644 --- a/libs/gtkutil/accelerator.h +++ b/libs/gtkutil/accelerator.h @@ -22,6 +22,7 @@ #if !defined( INCLUDED_GTKUTIL_ACCELERATOR_H ) #define INCLUDED_GTKUTIL_ACCELERATOR_H +#include #include #include "generic/callback.h" @@ -85,16 +86,12 @@ void keyup_accelerators_add( Accelerator accelerator, const Callback& callback ) void keyup_accelerators_remove( Accelerator accelerator ); typedef struct _GtkWidget GtkWidget; -typedef struct _GtkWindow GtkWindow; -void global_accel_connect_window( GtkWindow* window ); -void global_accel_disconnect_window( GtkWindow* window ); +void global_accel_connect_window( ui::Window window ); +void global_accel_disconnect_window( ui::Window window ); void GlobalPressedKeys_releaseAll(); -typedef struct _GtkAccelGroup GtkAccelGroup; -extern GtkAccelGroup* global_accel; -void global_accel_init(); -void global_accel_destroy(); +extern ui::AccelGroup global_accel; GClosure* global_accel_group_find( Accelerator accelerator ); diff --git a/libs/gtkutil/cursor.cpp b/libs/gtkutil/cursor.cpp index 431f60fe..490c34fd 100644 --- a/libs/gtkutil/cursor.cpp +++ b/libs/gtkutil/cursor.cpp @@ -42,11 +42,11 @@ void default_cursor( GtkWidget* widget ){ } -void Sys_GetCursorPos( GtkWindow* window, int *x, int *y ){ +void Sys_GetCursorPos( ui::Window window, int *x, int *y ){ gdk_display_get_pointer( gdk_display_get_default(), 0, x, y, 0 ); } -void Sys_SetCursorPos( GtkWindow* window, int x, int y ){ +void Sys_SetCursorPos( ui::Window window, int x, int y ){ GdkScreen *screen; gdk_display_get_pointer( gdk_display_get_default(), &screen, 0, 0, 0 ); gdk_display_warp_pointer( gdk_display_get_default(), screen, x, y ); diff --git a/libs/gtkutil/cursor.h b/libs/gtkutil/cursor.h index bf4f6ee8..a4d9873a 100644 --- a/libs/gtkutil/cursor.h +++ b/libs/gtkutil/cursor.h @@ -24,18 +24,18 @@ #include #include +#include #include "debugging/debugging.h" typedef struct _GdkCursor GdkCursor; typedef struct _GtkWidget GtkWidget; -typedef struct _GtkWindow GtkWindow; GdkCursor* create_blank_cursor(); void blank_cursor( GtkWidget* widget ); void default_cursor( GtkWidget* widget ); -void Sys_GetCursorPos( GtkWindow* window, int *x, int *y ); -void Sys_SetCursorPos( GtkWindow* window, int x, int y ); +void Sys_GetCursorPos( ui::Window window, int *x, int *y ); +void Sys_SetCursorPos( ui::Window window, int x, int y ); @@ -121,7 +121,7 @@ FreezePointer() : handle_motion( 0 ), m_function( 0 ), m_data( 0 ){ } static gboolean motion_delta( GtkWidget *widget, GdkEventMotion *event, FreezePointer* self ){ int current_x, current_y; - Sys_GetCursorPos( GTK_WINDOW( widget ), ¤t_x, ¤t_y ); + Sys_GetCursorPos( ui::Window(GTK_WINDOW( widget )), ¤t_x, ¤t_y ); int dx = current_x - self->last_x; int dy = current_y - self->last_y; int ddx = current_x - self->recorded_x; @@ -131,7 +131,7 @@ static gboolean motion_delta( GtkWidget *widget, GdkEventMotion *event, FreezePo if ( dx != 0 || dy != 0 ) { //globalOutputStream() << "motion x: " << dx << ", y: " << dy << "\n"; if (ddx < -32 || ddx > 32 || ddy < -32 || ddy > 32) { - Sys_SetCursorPos( GTK_WINDOW( widget ), self->recorded_x, self->recorded_y ); + Sys_SetCursorPos( ui::Window(GTK_WINDOW( widget )), self->recorded_x, self->recorded_y ); self->last_x = self->recorded_x; self->last_y = self->recorded_y; } @@ -140,7 +140,7 @@ static gboolean motion_delta( GtkWidget *widget, GdkEventMotion *event, FreezePo return FALSE; } -void freeze_pointer( GtkWindow* window, MotionDeltaFunction function, void* data ){ +void freeze_pointer( ui::Window window, MotionDeltaFunction function, void* data ){ ASSERT_MESSAGE( m_function == 0, "can't freeze pointer" ); const GdkEventMask mask = static_cast( GDK_POINTER_MOTION_MASK @@ -171,7 +171,7 @@ void freeze_pointer( GtkWindow* window, MotionDeltaFunction function, void* data handle_motion = g_signal_connect( G_OBJECT( window ), "motion_notify_event", G_CALLBACK( motion_delta ), this ); } -void unfreeze_pointer( GtkWindow* window ){ +void unfreeze_pointer( ui::Window window ){ g_signal_handler_disconnect( G_OBJECT( window ), handle_motion ); m_function = 0; diff --git a/libs/gtkutil/dialog.cpp b/libs/gtkutil/dialog.cpp index fce53163..d22dc94c 100644 --- a/libs/gtkutil/dialog.cpp +++ b/libs/gtkutil/dialog.cpp @@ -64,8 +64,8 @@ GtkButton* create_dialog_button( const char* label, GCallback func, gpointer dat return button; } -GtkWindow* create_dialog_window( GtkWindow* parent, const char* title, GCallback func, gpointer data, int default_w, int default_h ){ - GtkWindow* window = create_floating_window( title, parent ); +ui::Window create_dialog_window( ui::Window parent, const char* title, GCallback func, gpointer data, int default_w, int default_h ){ + ui::Window window = create_floating_window( title, parent ); gtk_window_set_default_size( window, default_w, default_h ); gtk_window_set_position( window, GTK_WIN_POS_CENTER_ON_PARENT ); g_signal_connect( G_OBJECT( window ), "delete_event", func, data ); @@ -85,7 +85,7 @@ gboolean modal_dialog_delete( GtkWidget *widget, GdkEvent* event, ModalDialog* d return TRUE; } -EMessageBoxReturn modal_dialog_show( GtkWindow* window, ModalDialog& dialog ){ +EMessageBoxReturn modal_dialog_show( ui::Window window, ModalDialog& dialog ){ gtk_grab_add( GTK_WIDGET( window ) ); gtk_widget_show( GTK_WIDGET( window ) ); @@ -105,12 +105,12 @@ GtkButton* create_modal_dialog_button( const char* label, ModalDialogButton& but return create_dialog_button( label, G_CALLBACK( modal_dialog_button_clicked ), &button ); } -GtkWindow* create_modal_dialog_window( GtkWindow* parent, const char* title, ModalDialog& dialog, int default_w, int default_h ){ +ui::Window create_modal_dialog_window( ui::Window parent, const char* title, ModalDialog& dialog, int default_w, int default_h ){ return create_dialog_window( parent, title, G_CALLBACK( modal_dialog_delete ), &dialog, default_w, default_h ); } -GtkWindow* create_fixedsize_modal_dialog_window( GtkWindow* parent, const char* title, ModalDialog& dialog, int width, int height ){ - GtkWindow* window = create_modal_dialog_window( parent, title, dialog, width, height ); +ui::Window create_fixedsize_modal_dialog_window( ui::Window parent, const char* title, ModalDialog& dialog, int width, int height ){ + ui::Window window = create_modal_dialog_window( parent, title, dialog, width, height ); gtk_window_set_resizable( window, FALSE ); gtk_window_set_modal( window, TRUE ); @@ -157,8 +157,8 @@ gboolean dialog_delete_callback( GtkWidget *widget, GdkEventAny* event, ModalDia return TRUE; } -GtkWindow* create_simple_modal_dialog_window( const char* title, ModalDialog& dialog, GtkWidget* contents ){ - GtkWindow* window = create_fixedsize_modal_dialog_window( 0, title, dialog ); +ui::Window create_simple_modal_dialog_window( const char* title, ModalDialog& dialog, GtkWidget* contents ){ + ui::Window window = create_fixedsize_modal_dialog_window(ui::Window(), title, dialog ); GtkVBox* vbox1 = create_dialog_vbox( 8, 4 ); gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( vbox1 ) ); diff --git a/libs/gtkutil/dialog.h b/libs/gtkutil/dialog.h index b3e5017c..b5a43194 100644 --- a/libs/gtkutil/dialog.h +++ b/libs/gtkutil/dialog.h @@ -61,16 +61,15 @@ struct ModalDialogButton typedef void ( *GCallback )( void ); typedef void* gpointer; -typedef struct _GtkWindow GtkWindow; typedef struct _GtkTable GtkTable; typedef struct _GtkButton GtkButton; typedef struct _GtkVBox GtkVBox; typedef struct _GtkHBox GtkHBox; typedef struct _GtkFrame GtkFrame; -GtkWindow* create_fixedsize_modal_window( GtkWindow* parent, const char* title, int width, int height ); +ui::Window create_fixedsize_modal_window( ui::Window parent, const char* title, int width, int height ); -GtkWindow* create_dialog_window( GtkWindow* parent, const char* title, GCallback func, gpointer data, int default_w = -1, int default_h = -1 ); +ui::Window create_dialog_window( ui::Window parent, const char* title, GCallback func, gpointer data, int default_w = -1, int default_h = -1 ); GtkTable* create_dialog_table( unsigned int rows, unsigned int columns, unsigned int row_spacing, unsigned int col_spacing, int border = 0 ); GtkButton* create_dialog_button( const char* label, GCallback func, gpointer data ); GtkVBox* create_dialog_vbox( int spacing, int border = 0 ); @@ -78,9 +77,9 @@ GtkHBox* create_dialog_hbox( int spacing, int border = 0 ); GtkFrame* create_dialog_frame( const char* label, GtkShadowType shadow = GTK_SHADOW_ETCHED_IN ); GtkButton* create_modal_dialog_button( const char* label, ModalDialogButton& button ); -GtkWindow* create_modal_dialog_window( GtkWindow* parent, const char* title, ModalDialog& dialog, int default_w = -1, int default_h = -1 ); -GtkWindow* create_fixedsize_modal_dialog_window( GtkWindow* parent, const char* title, ModalDialog& dialog, int width = -1, int height = -1 ); -EMessageBoxReturn modal_dialog_show( GtkWindow* window, ModalDialog& dialog ); +ui::Window create_modal_dialog_window( ui::Window parent, const char* title, ModalDialog& dialog, int default_w = -1, int default_h = -1 ); +ui::Window create_fixedsize_modal_dialog_window( ui::Window parent, const char* title, ModalDialog& dialog, int width = -1, int height = -1 ); +EMessageBoxReturn modal_dialog_show( ui::Window window, ModalDialog& dialog ); gboolean dialog_button_ok( GtkWidget *widget, ModalDialog* data ); @@ -89,7 +88,7 @@ gboolean dialog_button_yes( GtkWidget *widget, ModalDialog* data ); gboolean dialog_button_no( GtkWidget *widget, ModalDialog* data ); gboolean dialog_delete_callback( GtkWidget *widget, GdkEventAny* event, ModalDialog* data ); -GtkWindow* create_simple_modal_dialog_window( const char* title, ModalDialog& dialog, GtkWidget* contents ); +ui::Window create_simple_modal_dialog_window( const char* title, ModalDialog& dialog, GtkWidget* contents ); class RadioHBox { diff --git a/libs/gtkutil/menu.cpp b/libs/gtkutil/menu.cpp index 7ef18911..f4191e76 100644 --- a/libs/gtkutil/menu.cpp +++ b/libs/gtkutil/menu.cpp @@ -225,7 +225,7 @@ void accelerator_name( const Accelerator& accelerator, GString* gstring ){ } void menu_item_add_accelerator( GtkMenuItem* item, Accelerator accelerator ){ - if ( accelerator.key != 0 ) { + if ( accelerator.key != 0 && gtk_accelerator_valid( accelerator.key, accelerator.modifiers )) { GClosure* closure = global_accel_group_find( accelerator ); ASSERT_NOTNULL(closure); menu_item_set_accelerator( item, closure ); diff --git a/libs/gtkutil/messagebox.cpp b/libs/gtkutil/messagebox.cpp index 2ae955c7..8930145b 100644 --- a/libs/gtkutil/messagebox.cpp +++ b/libs/gtkutil/messagebox.cpp @@ -58,17 +58,17 @@ EMessageBoxReturn gtk_MessageBox( ui::Widget parent, const char* text, const cha ModalDialogButton yes_button( dialog, eIDYES ); ModalDialogButton no_button( dialog, eIDNO ); - GtkWindow* parentWindow = parent ? GTK_WINDOW( parent ) : 0; + ui::Window parentWindow = ui::Window(parent ? GTK_WINDOW( parent ) : 0); - GtkWindow* window = create_fixedsize_modal_dialog_window( parentWindow, title, dialog, 400, 100 ); + ui::Window window = create_fixedsize_modal_dialog_window( parentWindow, title, dialog, 400, 100 ); - if ( parentWindow != 0 ) { + if ( parentWindow ) { //g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(floating_window_delete_present), parent); gtk_window_deiconify( parentWindow ); } - GtkAccelGroup* accel = ui::AccelGroup(); - gtk_window_add_accel_group( window, accel ); + auto accel = ui::AccelGroup(); + window.add_accel_group( accel ); GtkVBox* vbox = create_dialog_vbox( 8, 8 ); gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( vbox ) ); diff --git a/libs/gtkutil/window.cpp b/libs/gtkutil/window.cpp index 07e04e56..6baa5437 100644 --- a/libs/gtkutil/window.cpp +++ b/libs/gtkutil/window.cpp @@ -51,42 +51,42 @@ static gboolean main_window_iconified( GtkWidget* widget, GdkEventWindowState* e return FALSE; } -unsigned int connect_floating( GtkWindow* main_window, GtkWindow* floating ){ +unsigned int connect_floating( ui::Window main_window, ui::Window floating ){ return g_signal_connect( G_OBJECT( main_window ), "window_state_event", G_CALLBACK( main_window_iconified ), floating ); } -gboolean destroy_disconnect_floating( GtkWindow* widget, gpointer data ){ +gboolean destroy_disconnect_floating( ui::Window widget, gpointer data ){ g_signal_handler_disconnect( G_OBJECT( data ), gpointer_to_int( g_object_get_data( G_OBJECT( widget ), "floating_handler" ) ) ); return FALSE; } -gboolean floating_window_delete_present( GtkWindow* floating, GdkEventFocus *event, GtkWindow* main_window ){ +gboolean floating_window_delete_present( ui::Window floating, GdkEventFocus *event, ui::Window main_window ){ if ( gtk_window_is_active( floating ) || gtk_window_is_active( main_window ) ) { gtk_window_present( main_window ); } return FALSE; } -guint connect_floating_window_delete_present( GtkWindow* floating, GtkWindow* main_window ){ +guint connect_floating_window_delete_present( ui::Window floating, ui::Window main_window ){ return g_signal_connect( G_OBJECT( floating ), "delete_event", G_CALLBACK( floating_window_delete_present ), main_window ); } -gboolean floating_window_destroy_present( GtkWindow* floating, GtkWindow* main_window ){ +gboolean floating_window_destroy_present( ui::Window floating, ui::Window main_window ){ if ( gtk_window_is_active( floating ) || gtk_window_is_active( main_window ) ) { gtk_window_present( main_window ); } return FALSE; } -guint connect_floating_window_destroy_present( GtkWindow* floating, GtkWindow* main_window ){ +guint connect_floating_window_destroy_present( ui::Window floating, ui::Window main_window ){ return g_signal_connect( G_OBJECT( floating ), "destroy", G_CALLBACK( floating_window_destroy_present ), main_window ); } -GtkWindow* create_floating_window( const char* title, GtkWindow* parent ){ - GtkWindow* window = ui::Window( ui::window_type::TOP ); +ui::Window create_floating_window( const char* title, ui::Window parent ){ + ui::Window window = ui::Window( ui::window_type::TOP ); gtk_window_set_title( window, title ); - if ( parent != 0 ) { + if ( parent ) { gtk_window_set_transient_for( window, parent ); connect_floating_window_destroy_present( window, parent ); g_object_set_data( G_OBJECT( window ), "floating_handler", gint_to_pointer( connect_floating( parent, window ) ) ); @@ -96,7 +96,7 @@ GtkWindow* create_floating_window( const char* title, GtkWindow* parent ){ return window; } -void destroy_floating_window( GtkWindow* window ){ +void destroy_floating_window( ui::Window window ){ gtk_widget_destroy( GTK_WIDGET( window ) ); } @@ -105,13 +105,13 @@ gint window_realize_remove_sysmenu( GtkWidget* widget, gpointer data ){ return FALSE; } -gboolean persistent_floating_window_delete( GtkWindow* floating, GdkEvent *event, GtkWindow* main_window ){ +gboolean persistent_floating_window_delete( ui::Window floating, GdkEvent *event, ui::Window main_window ){ gtk_widget_hide( GTK_WIDGET( floating ) ); return TRUE; } -GtkWindow* create_persistent_floating_window( const char* title, GtkWindow* main_window ){ - GtkWindow* window = GTK_WINDOW( create_floating_window( title, main_window ) ); +ui::Window create_persistent_floating_window( const char* title, ui::Window main_window ){ + ui::Window window = ui::Window(GTK_WINDOW( create_floating_window( title, main_window ) )); gtk_widget_set_events( GTK_WIDGET( window ), GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK ); @@ -132,7 +132,7 @@ gint window_realize_remove_minmax( GtkWidget* widget, gpointer data ){ return FALSE; } -void window_remove_minmax( GtkWindow* window ){ +void window_remove_minmax( ui::Window window ){ g_signal_connect( G_OBJECT( window ), "realize", G_CALLBACK( window_realize_remove_minmax ), 0 ); } diff --git a/libs/gtkutil/window.h b/libs/gtkutil/window.h index 96b9be00..6cf8f639 100644 --- a/libs/gtkutil/window.h +++ b/libs/gtkutil/window.h @@ -23,6 +23,7 @@ #define INCLUDED_GTKUTIL_WINDOW_H #include +#include #include "debugging/debugging.h" #include "generic/callback.h" @@ -33,19 +34,19 @@ inline gboolean window_focus_in_clear_focus_widget( GtkWidget* widget, GdkEventK return FALSE; } -inline guint window_connect_focus_in_clear_focus_widget( GtkWindow* window ){ +inline guint window_connect_focus_in_clear_focus_widget( ui::Window window ){ return g_signal_connect( G_OBJECT( window ), "focus_in_event", G_CALLBACK( window_focus_in_clear_focus_widget ), NULL ); } -unsigned int connect_floating( GtkWindow* main_window, GtkWindow* floating ); -GtkWindow* create_floating_window( const char* title, GtkWindow* parent ); -void destroy_floating_window( GtkWindow* window ); +unsigned int connect_floating( ui::Window main_window, ui::Window floating ); +ui::Window create_floating_window( const char* title, ui::Window parent ); +void destroy_floating_window( ui::Window window ); -GtkWindow* create_persistent_floating_window( const char* title, GtkWindow* main_window ); -gboolean persistent_floating_window_delete( GtkWindow* floating, GdkEvent *event, GtkWindow* main_window ); +ui::Window create_persistent_floating_window( const char* title, ui::Window main_window ); +gboolean persistent_floating_window_delete( ui::Window floating, GdkEvent *event, ui::Window main_window ); -void window_remove_minmax( GtkWindow* window ); +void window_remove_minmax( ui::Window window ); typedef struct _GtkScrolledWindow GtkScrolledWindow; GtkScrolledWindow* create_scrolled_window( GtkPolicyType hscrollbar_policy, GtkPolicyType vscrollbar_policy, int border = 0 ); @@ -64,14 +65,14 @@ struct WindowPosition const WindowPosition c_default_window_pos( 50, 25, 400, 300 ); -inline void window_get_position( GtkWindow* window, WindowPosition& position ){ - ASSERT_MESSAGE( window != 0, "error saving window position" ); +inline void window_get_position( ui::Window window, WindowPosition& position ){ + ASSERT_MESSAGE( window , "error saving window position" ); gtk_window_get_position( window, &position.x, &position.y ); gtk_window_get_size( window, &position.w, &position.h ); } -inline void window_set_position( GtkWindow* window, const WindowPosition& position ){ +inline void window_set_position( ui::Window window, const WindowPosition& position ){ gtk_window_set_gravity( window, GDK_GRAVITY_STATIC ); GdkScreen* screen = gdk_screen_get_default(); @@ -119,11 +120,11 @@ WindowPositionTracker() : m_position( c_default_window_pos ){ } -void sync( GtkWindow* window ){ +void sync( ui::Window window ){ window_set_position( window, m_position ); } -void connect( GtkWindow* window ){ +void connect( ui::Window window ){ sync( window ); g_signal_connect( G_OBJECT( window ), "configure_event", G_CALLBACK( configure ), this ); } diff --git a/libs/uilib/uilib.cpp b/libs/uilib/uilib.cpp index eb49165a..a76c0c70 100644 --- a/libs/uilib/uilib.cpp +++ b/libs/uilib/uilib.cpp @@ -61,7 +61,7 @@ namespace ui { type == window_type::TOP ? GTK_WINDOW_TOPLEVEL : type == window_type::POPUP ? GTK_WINDOW_POPUP : GTK_WINDOW_TOPLEVEL))) - { }; + {}; Window Window::create_dialog_window(const char *title, void func(), void *data, int default_w, int default_h) { @@ -95,8 +95,13 @@ namespace ui { return g_signal_connect_closure(G_OBJECT(*this), "key-press-event", clos, false); } + void Window::add_accel_group(AccelGroup group) + { + gtk_window_add_accel_group(*this, group); + } + AccelGroup::AccelGroup() : AccelGroup(GTK_ACCEL_GROUP(gtk_accel_group_new())) - { } + {} Adjustment::Adjustment(double value, double lower, double upper, @@ -104,29 +109,29 @@ namespace ui { double page_size) : Adjustment( GTK_ADJUSTMENT(gtk_adjustment_new(value, lower, upper, step_increment, page_increment, page_size))) - { } + {} Alignment::Alignment(float xalign, float yalign, float xscale, float yscale) : Alignment(GTK_ALIGNMENT(gtk_alignment_new(xalign, yalign, xscale, yscale))) - { } + {} Button::Button() : Button(GTK_BUTTON(gtk_button_new())) - { } + {} Button::Button(const char *label) : Button(GTK_BUTTON(gtk_button_new_with_label(label))) - { } + {} CellRendererText::CellRendererText() : CellRendererText(GTK_CELL_RENDERER_TEXT(gtk_cell_renderer_text_new())) - { } + {} ComboBoxText::ComboBoxText() : ComboBoxText(GTK_COMBO_BOX_TEXT(gtk_combo_box_text_new())) - { } + {} CheckButton::CheckButton(const char *label) : CheckButton(GTK_CHECK_BUTTON(gtk_check_button_new_with_label(label))) - { } + {} Entry::Entry() : Entry(GTK_ENTRY(gtk_entry_new())) - { } + {} Entry::Entry(std::size_t max_length) : Entry() { @@ -134,61 +139,61 @@ namespace ui { } Frame::Frame(const char *label) : Frame(GTK_FRAME(gtk_frame_new(label))) - { } + {} HBox::HBox(bool homogenous, int spacing) : HBox(GTK_HBOX(gtk_hbox_new(homogenous, spacing))) - { } + {} HScale::HScale(Adjustment adjustment) : HScale(GTK_HSCALE(gtk_hscale_new(adjustment))) - { } + {} HScale::HScale(double min, double max, double step) : HScale(GTK_HSCALE(gtk_hscale_new_with_range(min, max, step))) - { } + {} Image::Image() : Image(GTK_IMAGE(gtk_image_new())) - { } + {} Label::Label(const char *label) : Label(GTK_LABEL(gtk_label_new(label))) - { } + {} Menu::Menu() : Menu(GTK_MENU(gtk_menu_new())) - { } + {} MenuItem::MenuItem(const char *label, bool mnemonic) : MenuItem( GTK_MENU_ITEM((mnemonic ? gtk_menu_item_new_with_mnemonic : gtk_menu_item_new_with_label)(label))) - { } + {} HPaned::HPaned() : HPaned(GTK_HPANED(gtk_hpaned_new())) - { } + {} VPaned::VPaned() : VPaned(GTK_VPANED(gtk_vpaned_new())) - { } + {} ScrolledWindow::ScrolledWindow() : ScrolledWindow(GTK_SCROLLED_WINDOW(gtk_scrolled_window_new(nullptr, nullptr))) - { } + {} SpinButton::SpinButton(Adjustment adjustment, double climb_rate, std::size_t digits) : SpinButton( GTK_SPIN_BUTTON(gtk_spin_button_new(adjustment, climb_rate, digits))) - { } + {} Table::Table(std::size_t rows, std::size_t columns, bool homogenous) : Table( GTK_TABLE(gtk_table_new(rows, columns, homogenous))) - { } + {} TextView::TextView() : TextView(GTK_TEXT_VIEW(gtk_text_view_new())) - { } + {} TreePath::TreePath() : TreePath(gtk_tree_path_new()) - { } + {} TreePath::TreePath(const char *path) : TreePath(gtk_tree_path_new_from_string(path)) - { } + {} TreeView::TreeView() : TreeView(GTK_TREE_VIEW(gtk_tree_view_new())) - { } + {} TreeView::TreeView(TreeModel model) : TreeView(GTK_TREE_VIEW(gtk_tree_view_new_with_model(model))) - { } + {} TreeViewColumn::TreeViewColumn(const char *title, CellRenderer renderer, std::initializer_list attributes) @@ -200,6 +205,6 @@ namespace ui { }; VBox::VBox(bool homogenous, int spacing) : VBox(GTK_VBOX(gtk_vbox_new(homogenous, spacing))) - { } + {} } diff --git a/libs/uilib/uilib.h b/libs/uilib/uilib.h index 562d0b08..f3f490c3 100644 --- a/libs/uilib/uilib.h +++ b/libs/uilib/uilib.h @@ -134,6 +134,7 @@ namespace ui { explicit name(impl *h) : super(reinterpret_cast(h)) {} \ methods \ }; \ + inline bool operator<(name self, name other) { return self._handle < other._handle; } \ static_assert(sizeof(name) == sizeof(super), "object slicing") WRAP(AccelGroup, Object, ui_accelgroup, @@ -272,6 +273,8 @@ namespace ui { std::uint64_t on_key_press(bool (*f)(Widget widget, ui_evkey *event, void *extra), void *extra = nullptr); + + void add_accel_group(AccelGroup group); ); #undef WRAP diff --git a/radiant/commands.cpp b/radiant/commands.cpp index f463503e..968d5c55 100644 --- a/radiant/commands.cpp +++ b/radiant/commands.cpp @@ -392,8 +392,8 @@ void DoCommandListDlg(){ return accelerator_window_key_press(widget, event, dialogptr); }, &dialog); - GtkAccelGroup* accel = ui::AccelGroup(); - gtk_window_add_accel_group( window, accel ); + auto accel = ui::AccelGroup(); + window.add_accel_group( accel ); GtkHBox* hbox = create_dialog_hbox( 4, 4 ); gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( hbox ) ); diff --git a/radiant/dialog.h b/radiant/dialog.h index 3e68095f..85b2d8a9 100644 --- a/radiant/dialog.h +++ b/radiant/dialog.h @@ -93,7 +93,6 @@ struct DLG_DATA virtual void exportData() const = 0; }; -typedef struct _GtkWindow GtkWindow; typedef struct _GtkToggleButton GtkToggleButton; typedef struct _GtkRadioButton GtkRadioButton; typedef struct _GtkSpinButton GtkSpinButton; diff --git a/radiant/entitylist.cpp b/radiant/entitylist.cpp index a9b9a668..6ec2f55d 100644 --- a/radiant/entitylist.cpp +++ b/radiant/entitylist.cpp @@ -285,7 +285,7 @@ void EntityList_constructWindow( ui::Window main_window ){ ui::Window window = ui::Window(create_persistent_floating_window( "Entity List", main_window )); - gtk_window_add_accel_group( window, global_accel ); + window.add_accel_group(global_accel); getEntityList().m_positionTracker.connect( window ); diff --git a/radiant/gtkdlgs.cpp b/radiant/gtkdlgs.cpp index 7b71b3d9..92095120 100644 --- a/radiant/gtkdlgs.cpp +++ b/radiant/gtkdlgs.cpp @@ -371,8 +371,8 @@ void DoSides( int type, int axis ){ ui::Window window = MainFrame_getWindow().create_dialog_window("Arbitrary sides", G_CALLBACK(dialog_delete_callback ), &dialog ); - GtkAccelGroup* accel = ui::AccelGroup(); - gtk_window_add_accel_group( window, accel ); + auto accel = ui::AccelGroup(); + window.add_accel_group( accel ); { GtkHBox* hbox = create_dialog_hbox( 4, 4 ); @@ -599,8 +599,8 @@ EMessageBoxReturn DoTextureLayout( float *fx, float *fy ){ ui::Window window = MainFrame_getWindow().create_modal_dialog_window("Patch texture layout", dialog ); - GtkAccelGroup* accel = ui::AccelGroup(); - gtk_window_add_accel_group( window, accel ); + auto accel = ui::AccelGroup(); + window.add_accel_group( accel ); { GtkHBox* hbox = create_dialog_hbox( 4, 4 ); @@ -860,8 +860,8 @@ EMessageBoxReturn DoLightIntensityDlg( int *intensity ){ ui::Window window = MainFrame_getWindow().create_modal_dialog_window("Light intensity", dialog, -1, -1 ); - GtkAccelGroup *accel_group = ui::AccelGroup(); - gtk_window_add_accel_group( window, accel_group ); + auto accel_group = ui::AccelGroup(); + window.add_accel_group( accel_group ); { GtkHBox* hbox = create_dialog_hbox( 4, 4 ); @@ -927,8 +927,8 @@ EMessageBoxReturn DoShaderTagDlg( CopiedString* tag, char* title ){ ui::Window window = MainFrame_getWindow().create_modal_dialog_window(title, dialog, -1, -1 ); - GtkAccelGroup *accel_group = ui::AccelGroup(); - gtk_window_add_accel_group( window, accel_group ); + auto accel_group = ui::AccelGroup(); + window.add_accel_group( accel_group ); { GtkHBox* hbox = create_dialog_hbox( 4, 4 ); @@ -986,8 +986,8 @@ EMessageBoxReturn DoShaderInfoDlg( const char* name, const char* filename, char* ui::Window window = MainFrame_getWindow().create_modal_dialog_window(title, dialog, -1, -1 ); - GtkAccelGroup *accel_group = ui::AccelGroup(); - gtk_window_add_accel_group( window, accel_group ); + auto accel_group = ui::AccelGroup(); + window.add_accel_group( accel_group ); { GtkHBox* hbox = create_dialog_hbox( 4, 4 ); diff --git a/radiant/gtkmisc.cpp b/radiant/gtkmisc.cpp index a2e6e5c7..a38fde78 100644 --- a/radiant/gtkmisc.cpp +++ b/radiant/gtkmisc.cpp @@ -114,7 +114,7 @@ bool color_dialog( ui::Widget parent, Vector3& color, const char* title ){ gtk_window_set_transient_for( GTK_WINDOW( dlg ), GTK_WINDOW( parent ) ); } - bool ok = modal_dialog_show( GTK_WINDOW( dlg ), dialog ) == eIDOK; + bool ok = modal_dialog_show( ui::Window(GTK_WINDOW( dlg )), dialog ) == eIDOK; if ( ok ) { gtk_color_selection_get_current_color( GTK_COLOR_SELECTION( gtk_color_selection_dialog_get_color_selection(GTK_COLOR_SELECTION_DIALOG( dlg )) ), &clr ); color[0] = clr.red / 65535.0f; diff --git a/radiant/main.cpp b/radiant/main.cpp index 6620d662..9e05f25a 100644 --- a/radiant/main.cpp +++ b/radiant/main.cpp @@ -642,8 +642,6 @@ int main( int argc, char* argv[] ){ Radiant_Initialise(); - global_accel_init(); - user_shortcuts_init(); g_pParentWnd = 0; @@ -687,8 +685,6 @@ int main( int argc, char* argv[] ){ user_shortcuts_save(); - global_accel_destroy(); - Radiant_Shutdown(); // close the log file if any diff --git a/radiant/mainframe.h b/radiant/mainframe.h index cb5274f3..e370b01f 100644 --- a/radiant/mainframe.h +++ b/radiant/mainframe.h @@ -38,7 +38,6 @@ class CamWnd; class ZWnd; typedef struct _GtkWidget GtkWidget; -typedef struct _GtkWindow GtkWindow; const int c_command_status = 0; const int c_position_status = 1; diff --git a/radiant/map.cpp b/radiant/map.cpp index 0dc0798d..8aac9a8f 100644 --- a/radiant/map.cpp +++ b/radiant/map.cpp @@ -2040,8 +2040,8 @@ void DoFind(){ ui::Window window = MainFrame_getWindow().create_dialog_window("Find Brush", G_CALLBACK(dialog_delete_callback ), &dialog ); - GtkAccelGroup* accel = ui::AccelGroup(); - gtk_window_add_accel_group( window, accel ); + auto accel = ui::AccelGroup(); + window.add_accel_group( accel ); { GtkVBox* vbox = create_dialog_vbox( 4, 4 ); diff --git a/radiant/patchmanip.cpp b/radiant/patchmanip.cpp index ac4dbd3a..7fa22082 100644 --- a/radiant/patchmanip.cpp +++ b/radiant/patchmanip.cpp @@ -849,8 +849,8 @@ void DoNewPatchDlg( EPatchPrefab prefab, int minrows, int mincols, int defrows, ui::Window window = MainFrame_getWindow().create_dialog_window("Patch density", G_CALLBACK(dialog_delete_callback ), &dialog ); - GtkAccelGroup* accel = ui::AccelGroup(); - gtk_window_add_accel_group( window, accel ); + auto accel = ui::AccelGroup(); + window.add_accel_group( accel ); { GtkHBox* hbox = create_dialog_hbox( 4, 4 ); @@ -976,8 +976,8 @@ EMessageBoxReturn DoCapDlg( ECapDialog* type ){ ui::Window window = MainFrame_getWindow().create_modal_dialog_window( "Cap", dialog ); - GtkAccelGroup *accel_group = ui::AccelGroup(); - gtk_window_add_accel_group( window, accel_group ); + auto accel_group = ui::AccelGroup(); + window.add_accel_group( accel_group ); { GtkHBox* hbox = create_dialog_hbox( 4, 4 ); diff --git a/radiant/select.cpp b/radiant/select.cpp index 0586d417..3f16a522 100644 --- a/radiant/select.cpp +++ b/radiant/select.cpp @@ -911,8 +911,8 @@ void DoRotateDlg(){ if ( !g_rotate_dialog.window ) { g_rotate_dialog.window = MainFrame_getWindow().create_dialog_window("Arbitrary rotation", G_CALLBACK(rotatedlg_delete ), &g_rotate_dialog ); - GtkAccelGroup* accel = ui::AccelGroup(); - gtk_window_add_accel_group( g_rotate_dialog.window, accel ); + auto accel = ui::AccelGroup(); + g_rotate_dialog.window.add_accel_group( accel ); { GtkHBox* hbox = create_dialog_hbox( 4, 4 ); @@ -1064,8 +1064,8 @@ void DoScaleDlg(){ if ( !g_scale_dialog.window ) { g_scale_dialog.window = MainFrame_getWindow().create_dialog_window("Arbitrary scale", G_CALLBACK(scaledlg_delete ), &g_scale_dialog ); - GtkAccelGroup* accel = ui::AccelGroup(); - gtk_window_add_accel_group( g_scale_dialog.window, accel ); + auto accel = ui::AccelGroup(); + g_scale_dialog.window.add_accel_group( accel ); { GtkHBox* hbox = create_dialog_hbox( 4, 4 ); diff --git a/radiant/xywindow.cpp b/radiant/xywindow.cpp index 18106075..3e2b1fd3 100644 --- a/radiant/xywindow.cpp +++ b/radiant/xywindow.cpp @@ -2745,7 +2745,7 @@ void XYWindow_Construct(){ GlobalToggles_insert( "ToggleView", ToggleShown::ToggleCaller( g_xy_top_shown ), ToggleItem::AddCallbackCaller( g_xy_top_shown.m_item ), Accelerator( 'V', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) ); GlobalToggles_insert( "ToggleSideView", ToggleShown::ToggleCaller( g_yz_side_shown ), ToggleItem::AddCallbackCaller( g_yz_side_shown.m_item ) ); GlobalToggles_insert( "ToggleFrontView", ToggleShown::ToggleCaller( g_xz_front_shown ), ToggleItem::AddCallbackCaller( g_xz_front_shown.m_item ) ); - GlobalCommands_insert( "NextView", FreeCaller(), Accelerator( GDK_KEY_Tab, (GdkModifierType)GDK_CONTROL_MASK ) ); + GlobalCommands_insert( "NextView", FreeCaller(), Accelerator( GDK_KEY_Tab, (GdkModifierType)GDK_CONTROL_MASK ) ); // fixme: doesn't show its shortcut GlobalCommands_insert( "ZoomIn", FreeCaller(), Accelerator( GDK_KEY_Delete ) ); GlobalCommands_insert( "ZoomOut", FreeCaller(), Accelerator( GDK_KEY_Insert ) ); GlobalCommands_insert( "ViewTop", FreeCaller(), Accelerator( GDK_KEY_KP_Home ) ); -- 2.39.2