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"
26 #include "modulesystem.h"
28 #include <gtk/gtktoolbar.h>
30 #include "stream/stringstream.h"
31 #include "gtkutil/image.h"
32 #include "gtkutil/container.h"
34 #include "mainframe.h"
37 GtkImage* new_plugin_image( const char* filename ){
39 StringOutputStream fullpath( 256 );
40 fullpath << AppPath_get() << g_pluginsDir << "bitmaps/" << filename;
41 GtkImage* image = image_new_from_file_with_mask( fullpath.c_str() );
48 StringOutputStream fullpath( 256 );
49 fullpath << GameToolsPath_get() << g_pluginsDir << "bitmaps/" << filename;
50 GtkImage* image = image_new_from_file_with_mask( fullpath.c_str() );
57 StringOutputStream fullpath( 256 );
58 fullpath << AppPath_get() << g_modulesDir << "bitmaps/" << filename;
59 GtkImage* image = image_new_from_file_with_mask( fullpath.c_str() );
65 return image_new_missing();
68 inline GtkToolbarChildType gtktoolbarchildtype_for_toolbarbuttontype( IToolbarButton::EType type ){
71 case IToolbarButton::eSpace:
72 return GTK_TOOLBAR_CHILD_SPACE;
73 case IToolbarButton::eButton:
74 return GTK_TOOLBAR_CHILD_BUTTON;
75 case IToolbarButton::eToggleButton:
76 return GTK_TOOLBAR_CHILD_TOGGLEBUTTON;
77 case IToolbarButton::eRadioButton:
78 return GTK_TOOLBAR_CHILD_RADIOBUTTON;
80 ERROR_MESSAGE( "invalid toolbar button type" );
81 return (GtkToolbarChildType)0;
84 void toolbar_insert( GtkToolbar *toolbar, const char* icon, const char* text, const char* tooltip, IToolbarButton::EType type, GtkSignalFunc handler, gpointer data ){
85 GtkWidget* widget = gtk_toolbar_append_element( toolbar, gtktoolbarchildtype_for_toolbarbuttontype( type ), 0, text, tooltip, "", GTK_WIDGET( new_plugin_image( icon ) ), handler, data );
86 if( type != IToolbarButton::eSpace ){
87 GTK_WIDGET_UNSET_FLAGS( widget, GTK_CAN_FOCUS );
88 GTK_WIDGET_UNSET_FLAGS( widget, GTK_CAN_DEFAULT );
92 void ActivateToolbarButton( GtkWidget *widget, gpointer data ){
93 const_cast<const IToolbarButton*>( reinterpret_cast<IToolbarButton*>( data ) )->activate();
96 void PlugInToolbar_AddButton( GtkToolbar* toolbar, const IToolbarButton* button ){
97 toolbar_insert( toolbar, button->getImage(), button->getText(), button->getTooltip(), button->getType(), GTK_SIGNAL_FUNC( ActivateToolbarButton ), reinterpret_cast<gpointer>( const_cast<IToolbarButton*>( button ) ) );
100 GtkToolbar* g_plugin_toolbar = 0;
102 void PluginToolbar_populate(){
103 class AddToolbarItemVisitor : public ToolbarModules::Visitor
105 GtkToolbar* m_toolbar;
107 AddToolbarItemVisitor( GtkToolbar* toolbar )
108 : m_toolbar( toolbar ){
110 void visit( const char* name, const _QERPlugToolbarTable& table ) const {
111 const std::size_t count = table.m_pfnToolbarButtonCount();
112 for ( std::size_t i = 0; i < count; ++i )
114 PlugInToolbar_AddButton( m_toolbar, table.m_pfnGetToolbarButton( i ) );
118 } visitor( g_plugin_toolbar );
120 Radiant_getToolbarModules().foreachModule( visitor );
123 void PluginToolbar_clear(){
124 container_remove_all( GTK_CONTAINER( g_plugin_toolbar ) );
127 GtkToolbar* create_plugin_toolbar(){
130 toolbar = GTK_TOOLBAR( gtk_toolbar_new() );
131 gtk_toolbar_set_orientation( toolbar, GTK_ORIENTATION_HORIZONTAL );
132 gtk_toolbar_set_style( toolbar, GTK_TOOLBAR_ICONS );
133 // gtk_toolbar_set_show_arrow( toolbar, TRUE );
134 gtk_widget_show( GTK_WIDGET( toolbar ) );
136 g_plugin_toolbar = toolbar;
138 PluginToolbar_populate();