diff --git a/libs/gtkutil/button.cpp b/libs/gtkutil/button.cpp index a1e2a8c8..fb3d783a 100644 --- a/libs/gtkutil/button.cpp +++ b/libs/gtkutil/button.cpp @@ -41,6 +41,9 @@ void button_connect_callback( GtkButton* button, const Callback& callback ){ g_signal_connect_closure( G_OBJECT( button ), "clicked", create_cclosure( G_CALLBACK( clicked_closure_callback ), callback ), FALSE ); #endif } +void button_connect_callback( GtkToolButton* button, const Callback& callback ){ + g_signal_connect_swapped( G_OBJECT( button ), "clicked", G_CALLBACK( callback.getThunk() ), callback.getEnvironment() ); +} guint toggle_button_connect_callback( GtkToggleButton* button, const Callback& callback ){ #if 1 @@ -51,6 +54,11 @@ guint toggle_button_connect_callback( GtkToggleButton* button, const Callback& c g_object_set_data( G_OBJECT( button ), "handler", gint_to_pointer( handler ) ); return handler; } +guint toggle_button_connect_callback( GtkToggleToolButton* button, const Callback& callback ){ + guint handler = g_signal_connect_swapped( G_OBJECT( button ), "toggled", G_CALLBACK( callback.getThunk() ), callback.getEnvironment() ); + g_object_set_data( G_OBJECT( button ), "handler", gint_to_pointer( handler ) ); + return handler; +} void button_set_icon( GtkButton* button, const char* icon ){ GtkImage* image = new_local_image( icon ); @@ -69,6 +77,12 @@ void toggle_button_set_active_no_signal( GtkToggleButton* button, gboolean activ gtk_toggle_button_set_active( button, active ); g_signal_handler_unblock( G_OBJECT( button ), handler_id ); } +void toggle_button_set_active_no_signal( GtkToggleToolButton* button, gboolean active ){ + guint handler_id = gpointer_to_int( g_object_get_data( G_OBJECT( button ), "handler" ) ); + g_signal_handler_block( G_OBJECT( button ), handler_id ); + gtk_toggle_tool_button_set_active( button, active ); + g_signal_handler_unblock( G_OBJECT( button ), handler_id ); +} void radio_button_print_state( GtkRadioButton* button ){ diff --git a/libs/gtkutil/button.h b/libs/gtkutil/button.h index 15a9f2e8..33d211b3 100644 --- a/libs/gtkutil/button.h +++ b/libs/gtkutil/button.h @@ -25,17 +25,22 @@ #include "generic/callbackfwd.h" typedef struct _GtkButton GtkButton; +typedef struct _GtkToolButton GtkToolButton; typedef struct _GtkToggleButton GtkToggleButton; +typedef struct _GtkToggleToolButton GtkToggleToolButton; typedef struct _GtkRadioButton GtkRadioButton; typedef int gint; typedef gint gboolean; typedef unsigned int guint; void button_connect_callback( GtkButton* button, const Callback& callback ); +void button_connect_callback( GtkToolButton* button, const Callback& callback ); guint toggle_button_connect_callback( GtkToggleButton* button, const Callback& callback ); +guint toggle_button_connect_callback( GtkToggleToolButton* button, const Callback& callback ); void button_set_icon( GtkButton* button, const char* icon ); void toggle_button_set_active_no_signal( GtkToggleButton* item, gboolean active ); +void toggle_button_set_active_no_signal( GtkToggleToolButton* item, gboolean active ); void radio_button_set_active( GtkRadioButton* radio, int index ); void radio_button_set_active_no_signal( GtkRadioButton* radio, int index ); diff --git a/libs/gtkutil/toolbar.cpp b/libs/gtkutil/toolbar.cpp index 37c52f8f..49ebbfd3 100644 --- a/libs/gtkutil/toolbar.cpp +++ b/libs/gtkutil/toolbar.cpp @@ -27,51 +27,61 @@ #include "accelerator.h" #include "button.h" +#include "image.h" #include "closure.h" #include "pointer.h" +GtkToolbar* toolbar_new(){ + GtkToolbar* toolbar = GTK_TOOLBAR( gtk_toolbar_new() ); + gtk_orientable_set_orientation( GTK_ORIENTABLE( toolbar ), GTK_ORIENTATION_HORIZONTAL ); + gtk_toolbar_set_style( toolbar, GTK_TOOLBAR_ICONS ); + gtk_toolbar_set_show_arrow( toolbar, FALSE ); + gtk_widget_show( GTK_WIDGET( toolbar ) ); + return toolbar; +} + void toolbar_append_space( GtkToolbar* toolbar ){ GtkToolItem* space = gtk_separator_tool_item_new(); gtk_widget_show( GTK_WIDGET( space ) ); gtk_toolbar_insert( toolbar, space, -1 ); } -void toolbar_append( GtkToolbar* toolbar, GtkButton* button, const char* description ){ - gtk_widget_show( GTK_WIDGET( button ) ); - gtk_button_set_relief( button, GTK_RELIEF_NONE ); - gtk_widget_set_can_focus( GTK_WIDGET( button ), FALSE ); - gtk_widget_set_can_default( GTK_WIDGET( button ), FALSE ); - gtk_toolbar_append_element( toolbar, GTK_TOOLBAR_CHILD_WIDGET, GTK_WIDGET( button ), "", description, "", 0, 0, 0 ); +void toolbar_append( GtkToolbar* toolbar, GtkToolItem* button, const char* description ){ + gtk_widget_show_all( GTK_WIDGET( button ) ); + gtk_tool_item_set_tooltip_text( button, description ); +// gtk_button_set_relief( button, GTK_RELIEF_NONE ); +// gtk_widget_set_can_focus( GTK_WIDGET( button ), FALSE ); +// gtk_widget_set_can_default( GTK_WIDGET( button ), FALSE ); + gtk_toolbar_insert( toolbar, button, -1 ); } -GtkButton* toolbar_append_button( GtkToolbar* toolbar, const char* description, const char* icon, const Callback& callback ){ - GtkButton* button = GTK_BUTTON( gtk_button_new() ); - button_set_icon( button, icon ); +GtkToolButton* toolbar_append_button( GtkToolbar* toolbar, const char* description, const char* icon, const Callback& callback ){ + GtkToolButton* button = GTK_TOOL_BUTTON( gtk_tool_button_new( GTK_WIDGET( new_local_image( icon ) ), nullptr ) ); button_connect_callback( button, callback ); - toolbar_append( toolbar, button, description ); + toolbar_append( toolbar, GTK_TOOL_ITEM( button ), description ); return button; } -GtkToggleButton* toolbar_append_toggle_button( GtkToolbar* toolbar, const char* description, const char* icon, const Callback& callback ){ - GtkToggleButton* button = GTK_TOGGLE_BUTTON( gtk_toggle_button_new() ); - button_set_icon( GTK_BUTTON( button ), icon ); +GtkToggleToolButton* toolbar_append_toggle_button( GtkToolbar* toolbar, const char* description, const char* icon, const Callback& callback ){ + GtkToggleToolButton* button = GTK_TOGGLE_TOOL_BUTTON( gtk_toggle_tool_button_new() ); + gtk_tool_button_set_icon_widget( GTK_TOOL_BUTTON( button ), GTK_WIDGET( new_local_image( icon ) ) ); toggle_button_connect_callback( button, callback ); - toolbar_append( toolbar, GTK_BUTTON( button ), description ); + toolbar_append( toolbar, GTK_TOOL_ITEM( button ), description ); return button; } -GtkButton* toolbar_append_button( GtkToolbar* toolbar, const char* description, const char* icon, const Command& command ){ +GtkToolButton* toolbar_append_button( GtkToolbar* toolbar, const char* description, const char* icon, const Command& command ){ return toolbar_append_button( toolbar, description, icon, command.m_callback ); } -void toggle_button_set_active_callback( GtkToggleButton& button, bool active ){ +void toggle_button_set_active_callback( GtkToggleToolButton& button, bool active ){ toggle_button_set_active_no_signal( &button, active ); } -typedef ReferenceCaller1 ToggleButtonSetActiveCaller; +typedef ReferenceCaller1 ToggleButtonSetActiveCaller; -GtkToggleButton* toolbar_append_toggle_button( GtkToolbar* toolbar, const char* description, const char* icon, const Toggle& toggle ){ - GtkToggleButton* button = toolbar_append_toggle_button( toolbar, description, icon, toggle.m_command.m_callback ); +GtkToggleToolButton* toolbar_append_toggle_button( GtkToolbar* toolbar, const char* description, const char* icon, const Toggle& toggle ){ + GtkToggleToolButton* button = toolbar_append_toggle_button( toolbar, description, icon, toggle.m_command.m_callback ); toggle.m_exportCallback( ToggleButtonSetActiveCaller( *button ) ); return button; } diff --git a/libs/gtkutil/toolbar.h b/libs/gtkutil/toolbar.h index 91a76495..484d2964 100644 --- a/libs/gtkutil/toolbar.h +++ b/libs/gtkutil/toolbar.h @@ -24,16 +24,19 @@ #include "generic/callbackfwd.h" -typedef struct _GtkButton GtkButton; -typedef struct _GtkToggleButton GtkToggleButton; +typedef struct _GtkToolItem GtkToolItem; +typedef struct _GtkToolButton GtkToolButton; +typedef struct _GtkToggleToolButton GtkToggleToolButton; typedef struct _GtkToolbar GtkToolbar; class Command; class Toggle; +GtkToolbar* toolbar_new(); void toolbar_append_space( GtkToolbar* toolbar ); -GtkButton* toolbar_append_button( GtkToolbar* toolbar, const char* description, const char* icon, const Callback& callback ); -GtkButton* toolbar_append_button( GtkToolbar* toolbar, const char* description, const char* icon, const Command& command ); -GtkToggleButton* toolbar_append_toggle_button( GtkToolbar* toolbar, const char* description, const char* icon, const Callback& callback ); -GtkToggleButton* toolbar_append_toggle_button( GtkToolbar* toolbar, const char* description, const char* icon, const Toggle& toggle ); +void toolbar_append( GtkToolbar* toolbar, GtkToolItem* button, const char* description ); +GtkToolButton* toolbar_append_button( GtkToolbar* toolbar, const char* description, const char* icon, const Callback& callback ); +GtkToolButton* toolbar_append_button( GtkToolbar* toolbar, const char* description, const char* icon, const Command& command ); +GtkToggleToolButton* toolbar_append_toggle_button( GtkToolbar* toolbar, const char* description, const char* icon, const Callback& callback ); +GtkToggleToolButton* toolbar_append_toggle_button( GtkToolbar* toolbar, const char* description, const char* icon, const Toggle& toggle ); #endif diff --git a/radiant/filterbar.cpp b/radiant/filterbar.cpp index 5614993b..07dab671 100644 --- a/radiant/filterbar.cpp +++ b/radiant/filterbar.cpp @@ -213,13 +213,10 @@ gboolean Hide_button_press( GtkWidget *widget, GdkEventButton *event, gpointer d } GtkToolbar* create_filter_toolbar(){ - GtkToolbar* toolbar = GTK_TOOLBAR( gtk_toolbar_new() ); - gtk_toolbar_set_style( toolbar, GTK_TOOLBAR_ICONS ); -// gtk_toolbar_set_show_arrow( toolbar, TRUE ); - gtk_widget_show( GTK_WIDGET( toolbar ) ); + GtkToolbar* toolbar = toolbar_new(); g_signal_connect( G_OBJECT( toolbar ), "enter_notify_event", G_CALLBACK( ToggleActions0 ), 0 ); - GtkToggleButton* button; + GtkToggleToolButton* button; toolbar_append_toggle_button( toolbar, "World (ALT + 1)", "f-world.png", "FilterWorldBrushes" ); diff --git a/radiant/gtkmisc.cpp b/radiant/gtkmisc.cpp index 6787df34..f8a25730 100644 --- a/radiant/gtkmisc.cpp +++ b/radiant/gtkmisc.cpp @@ -92,11 +92,11 @@ GtkMenuItem* create_menu_item_with_mnemonic( GtkMenu* menu, const char *mnemonic return create_menu_item_with_mnemonic( menu, mnemonic, command ); } -GtkButton* toolbar_append_button( GtkToolbar* toolbar, const char* description, const char* icon, const char* commandName ){ +GtkToolButton* toolbar_append_button( GtkToolbar* toolbar, const char* description, const char* icon, const char* commandName ){ return toolbar_append_button( toolbar, description, icon, GlobalCommands_find( commandName ) ); } -GtkToggleButton* toolbar_append_toggle_button( GtkToolbar* toolbar, const char* description, const char* icon, const char* commandName ){ +GtkToggleToolButton* toolbar_append_toggle_button( GtkToolbar* toolbar, const char* description, const char* icon, const char* commandName ){ return toolbar_append_toggle_button( toolbar, description, icon, GlobalToggles_find( commandName ) ); } diff --git a/radiant/gtkmisc.h b/radiant/gtkmisc.h index 986b5f50..639b7723 100644 --- a/radiant/gtkmisc.h +++ b/radiant/gtkmisc.h @@ -47,14 +47,14 @@ GtkMenuItem* create_menu_item_with_mnemonic( GtkMenu *menu, const char *mnemonic // this also sets up the shortcut using command_connect_accelerator GtkCheckMenuItem* create_check_menu_item_with_mnemonic( GtkMenu* menu, const char* mnemonic, const char* commandName ); -typedef struct _GtkButton GtkButton; -typedef struct _GtkToggleButton GtkToggleButton; +typedef struct _GtkToolButton GtkToolButton; +typedef struct _GtkToggleToolButton GtkToggleToolButton; typedef struct _GtkToolbar GtkToolbar; // this DOES NOT set up the shortcut using command_connect_accelerator -GtkButton* toolbar_append_button( GtkToolbar* toolbar, const char* description, const char* icon, const char* commandName ); +GtkToolButton* toolbar_append_button( GtkToolbar* toolbar, const char* description, const char* icon, const char* commandName ); // this DOES NOT set up the shortcut using command_connect_accelerator -GtkToggleButton* toolbar_append_toggle_button( GtkToolbar* toolbar, const char* description, const char* icon, const char* commandName ); +GtkToggleToolButton* toolbar_append_toggle_button( GtkToolbar* toolbar, const char* description, const char* icon, const char* commandName ); typedef struct _GtkWidget GtkWidget; template class BasicVector3; diff --git a/radiant/mainframe.cpp b/radiant/mainframe.cpp index 90ea8046..712c4e49 100644 --- a/radiant/mainframe.cpp +++ b/radiant/mainframe.cpp @@ -2566,11 +2566,7 @@ void Manipulators_constructToolbar( GtkToolbar* toolbar ){ } GtkToolbar* create_main_toolbar( MainFrame::EViewStyle style ){ - GtkToolbar* toolbar = GTK_TOOLBAR( gtk_toolbar_new() ); - gtk_orientable_set_orientation( GTK_ORIENTABLE( toolbar ), GTK_ORIENTATION_HORIZONTAL ); - gtk_toolbar_set_style( toolbar, GTK_TOOLBAR_ICONS ); -// gtk_toolbar_set_show_arrow( toolbar, TRUE ); - gtk_widget_show( GTK_WIDGET( toolbar ) ); + GtkToolbar* toolbar = toolbar_new(); File_constructToolbar( toolbar ); toolbar_append_space( toolbar ); @@ -2618,7 +2614,7 @@ GtkToolbar* create_main_toolbar( MainFrame::EViewStyle style ){ } // TODO: call light inspector - //GtkButton* g_view_lightinspector_button = toolbar_append_button(toolbar, "Light Inspector", "lightinspector.png", "ToggleLightInspector"); + //GtkToolButton* g_view_lightinspector_button = toolbar_append_button(toolbar, "Light Inspector", "lightinspector.png", "ToggleLightInspector"); toolbar_append_space( toolbar ); toolbar_append_button( toolbar, "Refresh Models", "refresh_models.png", "RefreshReferences" ); diff --git a/radiant/modelwindow.cpp b/radiant/modelwindow.cpp index b768798e..9b678593 100644 --- a/radiant/modelwindow.cpp +++ b/radiant/modelwindow.cpp @@ -1273,12 +1273,11 @@ GtkWidget* ModelBrowser_constructWindow( GtkWindow* toplevel ){ gtk_widget_show( vbox ); { // menu bar - GtkToolbar* toolbar = GTK_TOOLBAR( gtk_toolbar_new() ); + GtkToolbar* toolbar = toolbar_new(); gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( toolbar ), FALSE, FALSE, 0 ); - GtkButton* button = toolbar_append_button( toolbar, "Reload Model Folders Tree View", "texbro_refresh.png", FreeCaller() ); - gtk_widget_set_size_request( GTK_WIDGET( button ), 22, 22 ); - gtk_widget_show( GTK_WIDGET( toolbar ) ); + GtkToolButton* button = toolbar_append_button( toolbar, "Reload Model Folders Tree View", "texbro_refresh.png", FreeCaller() ); +// gtk_widget_set_size_request( GTK_WIDGET( button ), 22, 22 ); } { // TreeView GtkWidget* scr = gtk_scrolled_window_new( NULL, NULL ); diff --git a/radiant/plugintoolbar.cpp b/radiant/plugintoolbar.cpp index 39320423..ae31bda9 100644 --- a/radiant/plugintoolbar.cpp +++ b/radiant/plugintoolbar.cpp @@ -30,6 +30,7 @@ #include "stream/stringstream.h" #include "gtkutil/image.h" #include "gtkutil/container.h" +#include "gtkutil/toolbar.h" #include "mainframe.h" #include "plugin.h" @@ -65,27 +66,34 @@ GtkImage* new_plugin_image( const char* filename ){ return image_new_missing(); } -inline GtkToolbarChildType gtktoolbarchildtype_for_toolbarbuttontype( IToolbarButton::EType type ){ +void toolbar_insert( GtkToolbar *toolbar, const char* icon, const char* text, const char* tooltip, IToolbarButton::EType type, GCallback callback, gpointer data ){ switch ( type ) { case IToolbarButton::eSpace: - return GTK_TOOLBAR_CHILD_SPACE; + toolbar_append_space( toolbar ); + return; case IToolbarButton::eButton: - return GTK_TOOLBAR_CHILD_BUTTON; + { + GtkToolButton* button = GTK_TOOL_BUTTON( gtk_tool_button_new( GTK_WIDGET( new_plugin_image( icon ) ), text ) ); + g_signal_connect( G_OBJECT( button ), "clicked", callback, data ); + toolbar_append( toolbar, GTK_TOOL_ITEM( button ), tooltip ); + } + return; case IToolbarButton::eToggleButton: - return GTK_TOOLBAR_CHILD_TOGGLEBUTTON; + { + GtkToggleToolButton* button = GTK_TOGGLE_TOOL_BUTTON( gtk_toggle_tool_button_new() ); + gtk_tool_button_set_icon_widget( GTK_TOOL_BUTTON( button ), GTK_WIDGET( new_plugin_image( icon ) ) ); + gtk_tool_button_set_label( GTK_TOOL_BUTTON( button ), text ); + g_signal_connect( G_OBJECT( button ), "toggled", callback, data ); + toolbar_append( toolbar, GTK_TOOL_ITEM( button ), tooltip ); + } + return; case IToolbarButton::eRadioButton: - return GTK_TOOLBAR_CHILD_RADIOBUTTON; - } - ERROR_MESSAGE( "invalid toolbar button type" ); - return (GtkToolbarChildType)0; -} - -void toolbar_insert( GtkToolbar *toolbar, const char* icon, const char* text, const char* tooltip, IToolbarButton::EType type, GCallback callback, gpointer data ){ - GtkWidget* widget = gtk_toolbar_append_element( toolbar, gtktoolbarchildtype_for_toolbarbuttontype( type ), 0, text, tooltip, "", GTK_WIDGET( new_plugin_image( icon ) ), callback, data ); - if( type != IToolbarButton::eSpace ){ - gtk_widget_set_can_focus( widget, FALSE ); - gtk_widget_set_can_default( widget, FALSE ); + ERROR_MESSAGE( "IToolbarButton::eRadioButton not implemented" ); + return; + default: + ERROR_MESSAGE( "invalid toolbar button type" ); + return; } } @@ -125,17 +133,7 @@ void PluginToolbar_clear(){ } GtkToolbar* create_plugin_toolbar(){ - GtkToolbar *toolbar; - - toolbar = GTK_TOOLBAR( gtk_toolbar_new() ); - gtk_orientable_set_orientation( GTK_ORIENTABLE( toolbar ), GTK_ORIENTATION_HORIZONTAL ); - gtk_toolbar_set_style( toolbar, GTK_TOOLBAR_ICONS ); -// gtk_toolbar_set_show_arrow( toolbar, TRUE ); - gtk_widget_show( GTK_WIDGET( toolbar ) ); - - g_plugin_toolbar = toolbar; - + g_plugin_toolbar = toolbar_new(); PluginToolbar_populate(); - - return toolbar; + return g_plugin_toolbar; } diff --git a/radiant/texwindow.cpp b/radiant/texwindow.cpp index b5b76a8a..f1ae4ecc 100644 --- a/radiant/texwindow.cpp +++ b/radiant/texwindow.cpp @@ -2082,22 +2082,21 @@ GtkWidget* TextureBrowser_constructWindow( GtkWindow* toplevel ){ TextureBrowser_constructViewMenu( menu_view ); gtk_menu_set_title( menu_view, "View" ); - toolbar = GTK_TOOLBAR( gtk_toolbar_new() ); + toolbar = toolbar_new(); gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( toolbar ), FALSE, FALSE, 0 ); //view menu button - GtkButton* button = toolbar_append_button( toolbar, "View", "texbro_view.png", PointerCaller( menu_view ) ); - gtk_widget_set_size_request( GTK_WIDGET( button ), 24, 24 ); // 24 is minimal here for non scissored icon with any gtk theme + GtkToolButton* button = toolbar_append_button( toolbar, "View", "texbro_view.png", PointerCaller( menu_view ) ); +// gtk_widget_set_size_request( GTK_WIDGET( button ), 24, 24 ); // 24 is minimal here for non scissored icon with any gtk theme //show detached menu over floating tex bro gtk_menu_attach_to_widget( menu_view, GTK_WIDGET( button ), NULL ); button = toolbar_append_button( toolbar, "Find / Replace...", "texbro_gtk-find-and-replace.png", "FindReplaceTextures" ); - gtk_widget_set_size_request( GTK_WIDGET( button ), 22, 22 ); +// gtk_widget_set_size_request( GTK_WIDGET( button ), 22, 22 ); button = toolbar_append_button( toolbar, "Flush & Reload Shaders", "texbro_refresh.png", "RefreshShaders" ); - gtk_widget_set_size_request( GTK_WIDGET( button ), 22, 22 ); - gtk_widget_show( GTK_WIDGET( toolbar ) ); +// gtk_widget_set_size_request( GTK_WIDGET( button ), 22, 22 ); } { // filter entry GtkWidget* entry = g_TextureBrowser.m_filter_entry = gtk_entry_new(); @@ -2177,8 +2176,8 @@ GtkWidget* TextureBrowser_constructWindow( GtkWindow* toplevel ){ gtk_menu_set_title( menu_tags, "Tags" ); TextureBrowser_constructTagsMenu( menu_tags ); - GtkButton* button = toolbar_append_button( toolbar, "Tags", "texbro_tags.png", PointerCaller( menu_tags ) ); - gtk_widget_set_size_request( GTK_WIDGET( button ), 22, 22 ); + GtkToolButton* button = toolbar_append_button( toolbar, "Tags", "texbro_tags.png", PointerCaller( menu_tags ) ); +// gtk_widget_set_size_request( GTK_WIDGET( button ), 22, 22 ); //show detached menu over floating tex bro and main wnd... gtk_menu_attach_to_widget( menu_tags, GTK_WIDGET( button ), NULL );