]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/plugintoolbar.cpp
Merge commit 'c5a6237a2b002c9811719172931b0c9cc5a725f4' into master-merge
[xonotic/netradiant.git] / radiant / plugintoolbar.cpp
index 3a79f3e13a61a20a4dfc6c6fa895a1f8226fbc59..25ff2cd49fc8fbd7ee714e8931bcc99e11cf9aa7 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "plugintoolbar.h"
 
+#include <gtk/gtk.h>
 
 #include "itoolbar.h"
 #include "modulesystem.h"
@@ -41,63 +42,73 @@ ui::Image new_plugin_image( const char* filename ){
 
        {
                StringOutputStream fullpath( 256 );
-               fullpath << AppPath_get() << g_pluginsDir << "bitmaps/" << filename;
+               fullpath << DataPath_get() << g_pluginsDir << "bitmaps/" << filename;
                if ( auto image = image_new_from_file_with_mask(fullpath.c_str()) ) return image;
        }
 
        {
                StringOutputStream fullpath( 256 );
-               fullpath << AppPath_get() << g_modulesDir << "bitmaps/" << filename;
+               fullpath << DataPath_get() << g_modulesDir << "bitmaps/" << filename;
                if ( auto image = image_new_from_file_with_mask(fullpath.c_str()) ) return image;
        }
 
        return image_new_missing();
 }
 
-void toolbar_insert( GtkToolbar *toolbar, const char* icon, const char* text, const char* tooltip, IToolbarButton::EType type, GCallback handler, gpointer data ){
+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 = gtk_separator_tool_item_new();
-               gtk_widget_show(GTK_WIDGET(it));
-               gtk_container_add(GTK_CONTAINER(toolbar), GTK_WIDGET(it));
+               auto it = ui::ToolItem::from(gtk_separator_tool_item_new());
+               it.show();
+               toolbar.add(it);
                return;
        }
+       #define GARUX_DISABLE_SPACER_NOFOCUS
+       #ifndef GARUX_DISABLE_SPACER_NOFOCUS
+       else {
+               GTK_WIDGET_UNSET_FLAGS( widget, GTK_CAN_FOCUS );
+               GTK_WIDGET_UNSET_FLAGS( widget, GTK_CAN_DEFAULT );
+       }
+       #endif // GARUX_DISABLE_SPACER_NOFOCUS
+
        if (type == IToolbarButton::eButton) {
-               auto button = gtk_tool_button_new(GTK_WIDGET(new_plugin_image(icon)), text);
-               gtk_widget_set_tooltip_text(GTK_WIDGET(button), tooltip);
-               gtk_widget_show_all(GTK_WIDGET(button));
-               g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(handler), data);
-               gtk_container_add(GTK_CONTAINER(toolbar), GTK_WIDGET(button));
+               auto button = ui::ToolButton::from(gtk_tool_button_new(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 = 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);
-               gtk_widget_set_tooltip_text(GTK_WIDGET(button), tooltip);
-               gtk_widget_show_all(GTK_WIDGET(button));
-               g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(handler), data);
-               gtk_container_add(GTK_CONTAINER(toolbar), GTK_WIDGET(button));
+               auto button = ui::ToolButton::from(gtk_toggle_tool_button_new());
+               gtk_tool_button_set_icon_widget(button, 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" );
 }
 
-void ActivateToolbarButton( GtkToolButton *widget, gpointer data ){
+void ActivateToolbarButton( ui::ToolButton widget, gpointer data ){
        (const_cast<const IToolbarButton *>( reinterpret_cast<IToolbarButton *>( data )))->activate();
 }
 
-void PlugInToolbar_AddButton( GtkToolbar* toolbar, const IToolbarButton* 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<gpointer>( const_cast<IToolbarButton*>( button ) ) );
 }
 
-ui::Toolbar g_plugin_toolbar{nullptr};
+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 {
@@ -119,7 +130,7 @@ void PluginToolbar_clear(){
 
 ui::Toolbar create_plugin_toolbar(){
 
-       auto toolbar = ui::Toolbar(GTK_TOOLBAR( gtk_toolbar_new() ));
+       auto toolbar = ui::Toolbar::from( gtk_toolbar_new() );
        gtk_orientable_set_orientation( GTK_ORIENTABLE(toolbar), GTK_ORIENTATION_HORIZONTAL );
        gtk_toolbar_set_style( toolbar, GTK_TOOLBAR_ICONS );
        toolbar.show();