From 04a3c56f740db705904558c9fa882a146b0fbf97 Mon Sep 17 00:00:00 2001 From: joncruz Date: Tue, 27 Mar 2007 22:25:59 +0000 Subject: [PATCH] Adding the new/change label to the star toolbar --- src/Makefile_insert | 2 + src/ege-adjustment-action.h | 2 +- src/ege-output-action.cpp | 267 ++++++++++++++++++++++++++++++++++++ src/ege-output-action.h | 85 ++++++++++++ src/widgets/toolbox.cpp | 16 ++- 5 files changed, 367 insertions(+), 5 deletions(-) create mode 100644 src/ege-output-action.cpp create mode 100644 src/ege-output-action.h diff --git a/src/Makefile_insert b/src/Makefile_insert index d109b171b..edf63b7b8 100644 --- a/src/Makefile_insert +++ b/src/Makefile_insert @@ -273,6 +273,8 @@ libinkpost_a_SOURCES = \ dir-util.cpp dir-util.h \ ege-adjustment-action.cpp \ ege-adjustment-action.h \ + ege-output-action.cpp \ + ege-output-action.h \ fill-or-stroke.h \ filter-chemistry.cpp filter-chemistry.h \ fixes.cpp \ diff --git a/src/ege-adjustment-action.h b/src/ege-adjustment-action.h index 53cb493fe..7462448ff 100644 --- a/src/ege-adjustment-action.h +++ b/src/ege-adjustment-action.h @@ -39,7 +39,7 @@ * * ***** END LICENSE BLOCK ***** */ -/* Note: this file should be kept compliable as both .cpp and .c */ +/* Note: this file should be kept compilable as both .cpp and .c */ #include #include diff --git a/src/ege-output-action.cpp b/src/ege-output-action.cpp new file mode 100644 index 000000000..1b014bb65 --- /dev/null +++ b/src/ege-output-action.cpp @@ -0,0 +1,267 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is EGE Output Action. + * + * The Initial Developer of the Original Code is + * Jon A. Cruz. + * Portions created by the Initial Developer are Copyright (C) 2007 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +/* Note: this file should be kept compilable as both .cpp and .c */ + +#include + +#include +#include +#include + +#include "ege-output-action.h" + + +static void ege_output_action_class_init( EgeOutputActionClass* klass ); +static void ege_output_action_init( EgeOutputAction* action ); +static void ege_output_action_get_property( GObject* obj, guint propId, GValue* value, GParamSpec * pspec ); +static void ege_output_action_set_property( GObject* obj, guint propId, const GValue *value, GParamSpec* pspec ); +static void fixup_labels( GObject *gobject, GParamSpec *arg1, gpointer user_data ); + +/* static GtkWidget* create_menu_item( GtkAction* action ); */ +static GtkWidget* create_tool_item( GtkAction* action ); + +static GtkActionClass* gParentClass = 0; + + +struct _EgeOutputActionPrivate +{ + gboolean useMarkup; +}; + +#define EGE_OUTPUT_ACTION_GET_PRIVATE( o ) ( G_TYPE_INSTANCE_GET_PRIVATE( (o), EGE_OUTPUT_ACTION_TYPE, EgeOutputActionPrivate ) ) + +enum { + PROP_USE_MARKUP = 1, +}; + +GType ege_output_action_get_type( void ) +{ + static GType myType = 0; + if ( !myType ) { + static const GTypeInfo myInfo = { + sizeof( EgeOutputActionClass ), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc)ege_output_action_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof( EgeOutputAction ), + 0, /* n_preallocs */ + (GInstanceInitFunc)ege_output_action_init, + NULL + }; + + myType = g_type_register_static( GTK_TYPE_ACTION, "EgeOutputAction", &myInfo, (GTypeFlags)0 ); + } + + return myType; +} + +void ege_output_action_class_init( EgeOutputActionClass* klass ) +{ + if ( klass ) { + GObjectClass* objClass = G_OBJECT_CLASS( klass ); + gParentClass = GTK_ACTION_CLASS( g_type_class_peek_parent( klass ) ); + + objClass->get_property = ege_output_action_get_property; + objClass->set_property = ege_output_action_set_property; + +/* klass->parent_class.create_menu_item = create_menu_item; */ + klass->parent_class.create_tool_item = create_tool_item; + + g_object_class_install_property( objClass, + PROP_USE_MARKUP, + g_param_spec_boolean( "use-markup", + "UseMarkup", + "If markup should be used", + FALSE, + (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT) ) ); + + g_type_class_add_private( klass, sizeof(EgeOutputActionClass) ); + } +} + + +void ege_output_action_init( EgeOutputAction* action ) +{ + action->private_data = EGE_OUTPUT_ACTION_GET_PRIVATE( action ); + action->private_data->useMarkup = FALSE; + + g_signal_connect( action, "notify", G_CALLBACK( fixup_labels ), NULL ); +} + +EgeOutputAction* ege_output_action_new( const gchar *name, + const gchar *label, + const gchar *tooltip, + const gchar *stock_id ) +{ + GObject* obj = (GObject*)g_object_new( EGE_OUTPUT_ACTION_TYPE, + "name", name, + "label", label, + "tooltip", tooltip, + "stock_id", stock_id, + "use-markup", FALSE, + NULL ); + + EgeOutputAction* action = EGE_OUTPUT_ACTION( obj ); + + return action; +} + +gboolean ege_output_action_get_use_markup( EgeOutputAction* action ) +{ + g_return_val_if_fail( IS_EGE_OUTPUT_ACTION(action), FALSE ); + + return action->private_data->useMarkup; +} + +void ege_output_action_set_use_markup( EgeOutputAction* action, gboolean setting ) +{ + g_object_set( G_OBJECT(action), "use-markup", setting, NULL ); +} + +void ege_output_action_get_property( GObject* obj, guint propId, GValue* value, GParamSpec * pspec ) +{ + EgeOutputAction* action = EGE_OUTPUT_ACTION( obj ); + switch ( propId ) { + case PROP_USE_MARKUP: + g_value_set_boolean( value, action->private_data->useMarkup ); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID( obj, propId, pspec ); + } +} + +void ege_output_action_set_property( GObject* obj, guint propId, const GValue *value, GParamSpec* pspec ) +{ + EgeOutputAction* action = EGE_OUTPUT_ACTION( obj ); + switch ( propId ) { + case PROP_USE_MARKUP: + { + action->private_data->useMarkup = g_value_get_boolean( value ); + } + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID( obj, propId, pspec ); + } +} + + +/* static GtkWidget* create_menu_item( GtkAction* action ) */ + +GtkWidget* create_tool_item( GtkAction* action ) +{ + GtkWidget* item = 0; + + if ( IS_EGE_OUTPUT_ACTION(action) ) + { + GValue value; + GtkWidget* hb = gtk_hbox_new( FALSE, 5 ); + GtkWidget* lbl = 0; + memset( &value, 0, sizeof(value) ); + + g_value_init( &value, G_TYPE_STRING ); + g_object_get_property( G_OBJECT(action), "label", &value ); + const gchar* sss = g_value_get_string( &value ); + + item = GTK_WIDGET( gtk_tool_item_new() ); + + lbl = gtk_label_new( " " ); + gtk_container_add( GTK_CONTAINER(hb), lbl ); + + if ( EGE_OUTPUT_ACTION(action)->private_data->useMarkup ) { + lbl = gtk_label_new(NULL); + gtk_label_set_markup( GTK_LABEL(lbl), sss ? sss : " " ); + } else { + lbl = gtk_label_new( sss ? sss : " " ); + } + gtk_container_add( GTK_CONTAINER(hb), lbl ); + + lbl = gtk_label_new( " " ); + gtk_container_add( GTK_CONTAINER(hb), lbl ); + + gtk_container_add( GTK_CONTAINER(item), hb ); + + gtk_widget_show_all( item ); + } else { + item = gParentClass->create_tool_item( action ); + } + + return item; +} + +void fixup_labels( GObject *gobject, GParamSpec *arg1, gpointer user_data ) +{ + /* TODO: handle 'use-markup' getting changed also */ + + if ( arg1 && arg1->name && (strcmp("label", arg1->name) == 0) ) { + GSList* proxies = gtk_action_get_proxies( GTK_ACTION(gobject) ); + gchar* str = 0; + g_object_get( gobject, "label", &str, NULL ); + (void)user_data; + while ( proxies ) { + if ( GTK_IS_TOOL_ITEM(proxies->data) ) { + /* Search for the things we built up in create_tool_item() */ + GList* children = gtk_container_get_children( GTK_CONTAINER(proxies->data) ); + if ( children && children->data ) { + if ( GTK_IS_HBOX(children->data) ) { + children = gtk_container_get_children( GTK_CONTAINER(children->data) ); + if ( children && g_list_next(children) ) { + GtkWidget* child = GTK_WIDGET( g_list_next(children)->data ); + if ( GTK_IS_LABEL(child) ) { + GtkLabel* lbl = GTK_LABEL(child); + if ( EGE_OUTPUT_ACTION(gobject)->private_data->useMarkup ) { + gtk_label_set_markup( lbl, str ); + } else { + gtk_label_set_text( lbl, str ); + } + } + } + } + } + } + proxies = g_slist_next( proxies ); + } + g_free( str ); + } +} + diff --git a/src/ege-output-action.h b/src/ege-output-action.h new file mode 100644 index 000000000..4a8b47b12 --- /dev/null +++ b/src/ege-output-action.h @@ -0,0 +1,85 @@ +#ifndef SEEN_EGE_OUTPUT_ACTION +#define SEEN_EGE_OUTPUT_ACTION +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is EGE Output Action. + * + * The Initial Developer of the Original Code is + * Jon A. Cruz. + * Portions created by the Initial Developer are Copyright (C) 2007 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +/* Note: this file should be kept compilable as both .cpp and .c */ + +#include +#include +#include + +G_BEGIN_DECLS + + +#define EGE_OUTPUT_ACTION_TYPE ( ege_output_action_get_type() ) +#define EGE_OUTPUT_ACTION( obj ) ( G_TYPE_CHECK_INSTANCE_CAST( (obj), EGE_OUTPUT_ACTION_TYPE, EgeOutputAction) ) +#define EGE_OUTPUT_ACTION_CLASS( klass ) ( G_TYPE_CHECK_CLASS_CAST( (klass), EGE_OUTPUT_ACTION_TYPE, EgeOutputActionClass) ) +#define IS_EGE_OUTPUT_ACTION( obj ) ( G_TYPE_CHECK_INSTANCE_TYPE( (obj), EGE_OUTPUT_ACTION_TYPE) ) +#define IS_EGE_OUTPUT_ACTION_CLASS( klass ) ( G_TYPE_CHECK_CLASS_TYPE( (klass), EGE_OUTPUT_ACTION_TYPE) ) +#define EGE_OUTPUT_ACTION_GET_CLASS( obj ) ( G_TYPE_INSTANCE_GET_CLASS( (obj), EGE_OUTPUT_ACTION_TYPE, EgeOutputActionClass) ) + +typedef struct _EgeOutputAction EgeOutputAction; +typedef struct _EgeOutputActionClass EgeOutputActionClass; +typedef struct _EgeOutputActionPrivate EgeOutputActionPrivate; + +struct _EgeOutputAction +{ + GtkAction action; + EgeOutputActionPrivate *private_data; +}; + +struct _EgeOutputActionClass +{ + GtkActionClass parent_class; +}; + +GType ege_output_action_get_type( void ); + +EgeOutputAction* ege_output_action_new( const gchar *name, + const gchar *label, + const gchar *tooltip, + const gchar *stock_id ); + +gboolean ege_output_action_get_use_markup( EgeOutputAction* action ); +void ege_output_action_set_use_markup( EgeOutputAction* action, gboolean setting ); + +G_END_DECLS + +#endif /* SEEN_EGE_OUTPUT_ACTION */ diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 0b7296ce0..3f12dd85c 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -87,6 +87,7 @@ #include "ink-action.h" #include "ege-adjustment-action.h" +#include "ege-output-action.h" typedef void (*SetupFunction)(GtkWidget *toolbox, SPDesktop *desktop); typedef void (*UpdateFunction)(SPDesktop *desktop, SPEventContext *eventcontext, GtkWidget *toolbox); @@ -1147,12 +1148,12 @@ sp_star_toolbox_selection_changed(Inkscape::Selection *selection, GtkObject *tbl } } - //GtkWidget *l = GTK_WIDGET(gtk_object_get_data(GTK_OBJECT(tbl), "mode_label")); + EgeOutputAction* act = EGE_OUTPUT_ACTION( gtk_object_get_data(GTK_OBJECT(tbl), "mode_action") ); if (n_selected == 0) { - //gtk_label_set_markup(GTK_LABEL(l), _("New:")); + g_object_set( G_OBJECT(act), "label", _("New:"), NULL ); } else if (n_selected == 1) { - //gtk_label_set_markup(GTK_LABEL(l), _("Change:")); + g_object_set( G_OBJECT(act), "label", _("Change:"), NULL ); oldrepr = (Inkscape::XML::Node *) gtk_object_get_data(GTK_OBJECT(tbl), "repr"); if (oldrepr) { // remove old listener @@ -1238,6 +1239,8 @@ sp_star_toolbox_new(SPDesktop *desktop) "" " " " " + " " + " " " " " " " " @@ -1252,7 +1255,12 @@ sp_star_toolbox_new(SPDesktop *desktop) GtkUIManager* mgr = gtk_ui_manager_new(); GError* errVal = 0; GtkActionGroup* mainActions = gtk_action_group_new("main"); -// sp_toolbox_add_label(tbl, _("New:")); + { + EgeOutputAction* act = ege_output_action_new( "StarStateAction", _("New:"), "", 0 ); + ege_output_action_set_use_markup( act, TRUE ); + gtk_action_group_add_action( mainActions, GTK_ACTION( act ) ); + gtk_object_set_data( GTK_OBJECT(holder), "mode_action", act ); + } { gtk_object_set_data(GTK_OBJECT(holder), "dtw", desktop->canvas); -- 2.30.2