X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=radiant%2Fplugintoolbar.cpp;h=32b31c5a382ba753b2999f2ed70cdd0111854d93;hb=6d89c0d85ada682828059c3c69be4747a4933c19;hp=03ef2074b659455dbf2c73683be05d57787b4bf7;hpb=7fc621fc78d0e040dc2c12f38dc53dd9048215dc;p=xonotic%2Fnetradiant.git diff --git a/radiant/plugintoolbar.cpp b/radiant/plugintoolbar.cpp index 03ef2074..32b31c5a 100644 --- a/radiant/plugintoolbar.cpp +++ b/radiant/plugintoolbar.cpp @@ -21,12 +21,11 @@ #include "plugintoolbar.h" +#include #include "itoolbar.h" #include "modulesystem.h" -#include - #include "stream/stringstream.h" #include "gtkutil/image.h" #include "gtkutil/container.h" @@ -34,73 +33,72 @@ #include "mainframe.h" #include "plugin.h" -GtkImage* new_plugin_image( const char* filename ){ +ui::Image new_plugin_image( const char* filename ){ { StringOutputStream fullpath( 256 ); fullpath << GameToolsPath_get() << g_pluginsDir << "bitmaps/" << filename; - GtkImage* image = image_new_from_file_with_mask( fullpath.c_str() ); - if ( image != 0 ) { - return image; - } + if ( auto image = image_new_from_file_with_mask(fullpath.c_str()) ) return image; } { StringOutputStream fullpath( 256 ); fullpath << AppPath_get() << g_pluginsDir << "bitmaps/" << filename; - GtkImage* image = image_new_from_file_with_mask( fullpath.c_str() ); - if ( image != 0 ) { - return image; - } + if ( auto image = image_new_from_file_with_mask(fullpath.c_str()) ) return image; } { StringOutputStream fullpath( 256 ); fullpath << AppPath_get() << g_modulesDir << "bitmaps/" << filename; - GtkImage* image = image_new_from_file_with_mask( fullpath.c_str() ); - if ( image != 0 ) { - return image; - } + if ( auto image = image_new_from_file_with_mask(fullpath.c_str()) ) return image; } return image_new_missing(); } -inline GtkToolbarChildType gtktoolbarchildtype_for_toolbarbuttontype( IToolbarButton::EType type ){ - switch ( type ) - { - case IToolbarButton::eSpace: - return GTK_TOOLBAR_CHILD_SPACE; - case IToolbarButton::eButton: - return GTK_TOOLBAR_CHILD_BUTTON; - case IToolbarButton::eToggleButton: - return GTK_TOOLBAR_CHILD_TOGGLEBUTTON; - case IToolbarButton::eRadioButton: - return GTK_TOOLBAR_CHILD_RADIOBUTTON; +void toolbar_insert( ui::Toolbar toolbar, const char* icon, const char* text, const char* tooltip, IToolbarButton::EType type, GCallback handler, gpointer data ){ + if (type == IToolbarButton::eSpace) { + auto it = ui::Widget(GTK_WIDGET(gtk_separator_tool_item_new())); + it.show(); + toolbar.add(it); + return; + } + if (type == IToolbarButton::eButton) { + auto button = ui::ToolButton(GTK_TOOL_BUTTON(gtk_tool_button_new(GTK_WIDGET(new_plugin_image(icon)), text))); + gtk_widget_set_tooltip_text(button, tooltip); + gtk_widget_show_all(button); + button.connect("clicked", G_CALLBACK(handler), data); + toolbar.add(button); + return; + } + if (type == IToolbarButton::eToggleButton) { + auto button = ui::ToolButton(GTK_TOOL_BUTTON(gtk_toggle_tool_button_new())); + gtk_tool_button_set_icon_widget(button, GTK_WIDGET(new_plugin_image(icon))); + gtk_tool_button_set_label(button, text); + gtk_widget_set_tooltip_text(button, tooltip); + gtk_widget_show_all(button); + button.connect("toggled", G_CALLBACK(handler), data); + toolbar.add(button); + return; } 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, GtkSignalFunc handler, gpointer data ){ - gtk_toolbar_append_element( toolbar, gtktoolbarchildtype_for_toolbarbuttontype( type ), 0, text, tooltip, "", GTK_WIDGET( new_plugin_image( icon ) ), handler, data ); } -void ActivateToolbarButton( GtkWidget *widget, gpointer data ){ - const_cast( reinterpret_cast( data ) )->activate(); +void ActivateToolbarButton( GtkToolButton *widget, gpointer data ){ + (const_cast( reinterpret_cast( data )))->activate(); } -void PlugInToolbar_AddButton( GtkToolbar* toolbar, const IToolbarButton* button ){ - toolbar_insert( toolbar, button->getImage(), button->getText(), button->getTooltip(), button->getType(), GTK_SIGNAL_FUNC( ActivateToolbarButton ), reinterpret_cast( const_cast( button ) ) ); +void PlugInToolbar_AddButton( ui::Toolbar toolbar, const IToolbarButton* button ){ + toolbar_insert( toolbar, button->getImage(), button->getText(), button->getTooltip(), button->getType(), G_CALLBACK( ActivateToolbarButton ), reinterpret_cast( const_cast( button ) ) ); } -GtkToolbar* g_plugin_toolbar = 0; +ui::Toolbar g_plugin_toolbar{ui::null}; void PluginToolbar_populate(){ class AddToolbarItemVisitor : public ToolbarModules::Visitor { - GtkToolbar* m_toolbar; + ui::Toolbar m_toolbar; public: - AddToolbarItemVisitor( GtkToolbar* toolbar ) + AddToolbarItemVisitor( ui::Toolbar toolbar ) : m_toolbar( toolbar ){ } void visit( const char* name, const _QERPlugToolbarTable& table ) const { @@ -117,16 +115,15 @@ public: } void PluginToolbar_clear(){ - container_remove_all( GTK_CONTAINER( g_plugin_toolbar ) ); + container_remove_all( g_plugin_toolbar ); } -GtkToolbar* create_plugin_toolbar(){ - GtkToolbar *toolbar; +ui::Toolbar create_plugin_toolbar(){ - toolbar = GTK_TOOLBAR( gtk_toolbar_new() ); - gtk_toolbar_set_orientation( toolbar, GTK_ORIENTATION_HORIZONTAL ); + auto toolbar = ui::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_widget_show( GTK_WIDGET( toolbar ) ); + toolbar.show(); g_plugin_toolbar = toolbar;