2 Copyright (C) 2001-2006, William Joseph.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "plugintoolbar.h"
27 #include "modulesystem.h"
29 #include "stream/stringstream.h"
30 #include "gtkutil/image.h"
31 #include "gtkutil/container.h"
33 #include "mainframe.h"
36 ui::Image new_plugin_image( const char* filename ){
38 StringOutputStream fullpath( 256 );
39 fullpath << GameToolsPath_get() << g_pluginsDir << "bitmaps/" << filename;
40 if ( auto image = image_new_from_file_with_mask(fullpath.c_str()) ) return image;
44 StringOutputStream fullpath( 256 );
45 fullpath << AppPath_get() << g_pluginsDir << "bitmaps/" << filename;
46 if ( auto image = image_new_from_file_with_mask(fullpath.c_str()) ) return image;
50 StringOutputStream fullpath( 256 );
51 fullpath << AppPath_get() << g_modulesDir << "bitmaps/" << filename;
52 if ( auto image = image_new_from_file_with_mask(fullpath.c_str()) ) return image;
55 return image_new_missing();
58 void toolbar_insert( ui::Toolbar toolbar, const char* icon, const char* text, const char* tooltip, IToolbarButton::EType type, GCallback handler, gpointer data ){
59 if (type == IToolbarButton::eSpace) {
60 auto it = ui::ToolItem::from(gtk_separator_tool_item_new());
65 #define GARUX_DISABLE_SPACER_NOFOCUS
66 #ifndef GARUX_DISABLE_SPACER_NOFOCUS
68 GTK_WIDGET_UNSET_FLAGS( widget, GTK_CAN_FOCUS );
69 GTK_WIDGET_UNSET_FLAGS( widget, GTK_CAN_DEFAULT );
71 #endif // GARUX_DISABLE_SPACER_NOFOCUS
73 if (type == IToolbarButton::eButton) {
74 auto button = ui::ToolButton::from(gtk_tool_button_new(new_plugin_image(icon), text));
75 gtk_widget_set_tooltip_text(button, tooltip);
76 gtk_widget_show_all(button);
77 button.connect("clicked", G_CALLBACK(handler), data);
82 if (type == IToolbarButton::eToggleButton) {
83 auto button = ui::ToolButton::from(gtk_toggle_tool_button_new());
84 gtk_tool_button_set_icon_widget(button, new_plugin_image(icon));
85 gtk_tool_button_set_label(button, text);
86 gtk_widget_set_tooltip_text(button, tooltip);
87 gtk_widget_show_all(button);
88 button.connect("toggled", G_CALLBACK(handler), data);
93 ERROR_MESSAGE( "invalid toolbar button type" );
96 void ActivateToolbarButton( ui::ToolButton widget, gpointer data ){
97 (const_cast<const IToolbarButton *>( reinterpret_cast<IToolbarButton *>( data )))->activate();
100 void PlugInToolbar_AddButton( ui::Toolbar toolbar, const IToolbarButton* button ){
101 toolbar_insert( toolbar, button->getImage(), button->getText(), button->getTooltip(), button->getType(), G_CALLBACK( ActivateToolbarButton ), reinterpret_cast<gpointer>( const_cast<IToolbarButton*>( button ) ) );
104 ui::Toolbar g_plugin_toolbar{ui::null};
106 void PluginToolbar_populate(){
107 class AddToolbarItemVisitor : public ToolbarModules::Visitor
109 ui::Toolbar m_toolbar;
111 AddToolbarItemVisitor( ui::Toolbar toolbar )
112 : m_toolbar( toolbar ){
114 void visit( const char* name, const _QERPlugToolbarTable& table ) const {
115 const std::size_t count = table.m_pfnToolbarButtonCount();
116 for ( std::size_t i = 0; i < count; ++i )
118 PlugInToolbar_AddButton( m_toolbar, table.m_pfnGetToolbarButton( i ) );
122 } visitor( g_plugin_toolbar );
124 Radiant_getToolbarModules().foreachModule( visitor );
127 void PluginToolbar_clear(){
128 container_remove_all( g_plugin_toolbar );
131 ui::Toolbar create_plugin_toolbar(){
133 auto toolbar = ui::Toolbar::from( gtk_toolbar_new() );
134 gtk_orientable_set_orientation( GTK_ORIENTABLE(toolbar), GTK_ORIENTATION_HORIZONTAL );
135 gtk_toolbar_set_style( toolbar, GTK_TOOLBAR_ICONS );
138 g_plugin_toolbar = toolbar;
140 PluginToolbar_populate();