From 48c4b55de86fc48d1142e6f5b1bf6f39446a5582 Mon Sep 17 00:00:00 2001 From: joncruz Date: Mon, 9 Apr 2007 21:32:41 +0000 Subject: [PATCH] Updated simple action to work like toggle and radion versions --- src/ink-action.cpp | 75 ++++++++++++++++++++++++++++++---------------- src/ink-action.h | 2 -- 2 files changed, 50 insertions(+), 27 deletions(-) diff --git a/src/ink-action.cpp b/src/ink-action.cpp index 7764acc31..ecdc8e63c 100644 --- a/src/ink-action.cpp +++ b/src/ink-action.cpp @@ -17,6 +17,7 @@ static void ink_action_class_init( InkActionClass* klass ); static void ink_action_init( InkAction* action ); +static void ink_action_finalize( GObject* obj ); static void ink_action_get_property( GObject* obj, guint propId, GValue* value, GParamSpec * pspec ); static void ink_action_set_property( GObject* obj, guint propId, const GValue *value, GParamSpec* pspec ); @@ -25,6 +26,14 @@ static GtkWidget* ink_action_create_tool_item( GtkAction* action ); static GtkActionClass* gInkActionParentClass = 0; +struct _InkActionPrivate +{ + gchar* iconId; + Inkscape::IconSize iconSize; +}; + +#define INK_ACTION_GET_PRIVATE( o ) ( G_TYPE_INSTANCE_GET_PRIVATE( (o), INK_ACTION_TYPE, InkActionPrivate ) ) + GType ink_action_get_type( void ) { static GType myType = 0; @@ -59,6 +68,7 @@ static void ink_action_class_init( InkActionClass* klass ) gInkActionParentClass = GTK_ACTION_CLASS( g_type_class_peek_parent( klass ) ); GObjectClass * objClass = G_OBJECT_CLASS( klass ); + objClass->finalize = ink_action_finalize; objClass->get_property = ink_action_get_property; objClass->set_property = ink_action_set_property; @@ -84,11 +94,25 @@ static void ink_action_class_init( InkActionClass* klass ) (int)Inkscape::ICON_SIZE_DECORATION, (int)Inkscape::ICON_SIZE_SMALL_TOOLBAR, (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT) ) ); + + g_type_class_add_private( klass, sizeof(InkActionClass) ); } } static void ink_action_init( InkAction* action ) { + action->private_data = INK_ACTION_GET_PRIVATE( action ); + action->private_data->iconId = 0; + action->private_data->iconSize = Inkscape::ICON_SIZE_SMALL_TOOLBAR; +} + +static void ink_action_finalize( GObject* obj ) +{ + InkAction* action = INK_ACTION( obj ); + + g_free( action->private_data->iconId ); + g_free( action->private_data ); + } InkAction* ink_action_new( const gchar *name, @@ -117,13 +141,13 @@ static void ink_action_get_property( GObject* obj, guint propId, GValue* value, switch ( propId ) { case PROP_INK_ID: { - //g_value_set_pointer( value, action->private_data->adj ); + g_value_set_string( value, action->private_data->iconId ); } break; case PROP_INK_SIZE: { - //g_value_set_pointer( value, action->private_data->adj ); + g_value_set_int( value, action->private_data->iconSize ); } break; @@ -139,50 +163,51 @@ void ink_action_set_property( GObject* obj, guint propId, const GValue *value, G switch ( propId ) { case PROP_INK_ID: { -// gchar* tmp = action->private_data->iconId; -// action->private_data->iconId = g_value_dup_string( value ); -// g_free( tmp ); + gchar* tmp = action->private_data->iconId; + action->private_data->iconId = g_value_dup_string( value ); + g_free( tmp ); } break; case PROP_INK_SIZE: { -// action->private_data->iconSize = g_value_get_( value ); + action->private_data->iconSize = (Inkscape::IconSize)g_value_get_int( value ); } break; default: + { G_OBJECT_WARN_INVALID_PROPERTY_ID( obj, propId, pspec ); + } } } static GtkWidget* ink_action_create_menu_item( GtkAction* action ) { - GtkWidget* item = 0; - g_message("INK ACTION CREATE MENU ITEM"); - item = gInkActionParentClass->create_menu_item( action ); + GtkWidget* item = gInkActionParentClass->create_menu_item( action ); + return item; } static GtkWidget* ink_action_create_tool_item( GtkAction* action ) { - GtkWidget* item = 0; - g_message("INK ACTION CREATE TOOL ITEM"); - - - //item = gInkActionParentClass->create_tool_item( action ); - GtkTooltips *tt = gtk_tooltips_new(); - GtkWidget *button = sp_button_new_from_data( Inkscape::ICON_SIZE_DECORATION, - SP_BUTTON_TYPE_NORMAL, - NULL, - "use_pressure", - _("Use the pressure of the input device to alter the width of the pen"), - tt); - //g_signal_connect_after (G_OBJECT (button), "clicked", G_CALLBACK (sp_ddc_pressure_state_changed), NULL); - //gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), prefs_get_int_attribute ("tools.calligraphic", "usepressure", 1)); - item = GTK_WIDGET(gtk_tool_item_new()); - gtk_container_add( GTK_CONTAINER(item), button ); + InkAction* act = INK_ACTION( action ); + GtkWidget* item = gInkActionParentClass->create_tool_item(action); + + if ( act->private_data->iconId ) { + if ( GTK_IS_TOOL_BUTTON(item) ) { + GtkToolButton* button = GTK_TOOL_BUTTON(item); + GtkWidget* child = sp_icon_new( act->private_data->iconSize, act->private_data->iconId ); + gtk_tool_button_set_icon_widget( button, child ); + } else { + // For now trigger a warning but don't do anything else + GtkToolButton* button = GTK_TOOL_BUTTON(item); + (void)button; + } + } + + // TODO investigate if needed gtk_widget_show_all( item ); return item; diff --git a/src/ink-action.h b/src/ink-action.h index 8e82efeda..7ff7ab7d8 100644 --- a/src/ink-action.h +++ b/src/ink-action.h @@ -121,5 +121,3 @@ InkRadioAction* ink_radio_action_new( const gchar *name, G_END_DECLS #endif /* SEEN_INK_ACTION */ - - -- 2.30.2