diff options
| author | Jon A. Cruz <jon@joncruz.org> | 2011-04-19 06:14:35 +0000 |
|---|---|---|
| committer | Jon A. Cruz <jon@joncruz.org> | 2011-04-19 06:14:35 +0000 |
| commit | 84766315ff4f59563bc8e6e100b6fc1d435df6f7 (patch) | |
| tree | 356f15b57275349155e9c80a1b4323619be5645e /src | |
| parent | dxf import. add support for longer cubic NURB (Bug 685707) (diff) | |
| download | inkscape-84766315ff4f59563bc8e6e100b6fc1d435df6f7.tar.gz inkscape-84766315ff4f59563bc8e6e100b6fc1d435df6f7.zip | |
Restore modularity to adjustment action.
(bzr r10184)
Diffstat (limited to 'src')
| -rw-r--r-- | src/ege-adjustment-action.cpp | 47 | ||||
| -rw-r--r-- | src/ege-adjustment-action.h | 18 | ||||
| -rw-r--r-- | src/widgets/select-toolbar.cpp | 17 | ||||
| -rw-r--r-- | src/widgets/toolbox.cpp | 15 |
4 files changed, 76 insertions, 21 deletions
diff --git a/src/ege-adjustment-action.cpp b/src/ege-adjustment-action.cpp index 0a4dde320..9c01b4c7c 100644 --- a/src/ege-adjustment-action.cpp +++ b/src/ege-adjustment-action.cpp @@ -1,5 +1,3 @@ - - /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- * */ @@ -64,8 +62,6 @@ #include "icon-size.h" #include "ege-adjustment-action.h" -#include "ui/widget/spinbutton.h" - static void ege_adjustment_action_class_init( EgeAdjustmentActionClass* klass ); static void ege_adjustment_action_init( EgeAdjustmentAction* action ); @@ -89,14 +85,15 @@ static void egeAct_free_all_descriptions( EgeAdjustmentAction* action ); static GtkActionClass* gParentClass = 0; +static EgeCreateAdjWidgetCB gFactoryCb = 0; static GQuark gDataName = 0; enum { APPEARANCE_UNKNOWN = -1, APPEARANCE_NONE = 0, - APPEARANCE_FULL, // label, then all choices represented by separate buttons - APPEARANCE_COMPACT, // label, then choices in a drop-down menu - APPEARANCE_MINIMAL, // no label, just choices in a drop-down menu + APPEARANCE_FULL, /* label, then all choices represented by separate buttons */ + APPEARANCE_COMPACT, /* label, then choices in a drop-down menu */ + APPEARANCE_MINIMAL, /* no label, just choices in a drop-down menu */ }; #if GTK_CHECK_VERSION(2,12,0) @@ -197,6 +194,7 @@ static void ege_adjustment_action_class_init( EgeAdjustmentActionClass* klass ) gDataName = g_quark_from_string("ege-adj-action"); + objClass->finalize = ege_adjustment_action_finalize; objClass->get_property = ege_adjustment_action_get_property; @@ -283,6 +281,11 @@ static void ege_adjustment_action_class_init( EgeAdjustmentActionClass* klass ) } } +void ege_adjustment_action_set_compact_tool_factory( EgeCreateAdjWidgetCB factoryCb ) +{ + gFactoryCb = factoryCb; +} + static void ege_adjustment_action_init( EgeAdjustmentAction* action ) { action->private_data = EGE_ADJUSTMENT_ACTION_GET_PRIVATE( action ); @@ -383,11 +386,11 @@ static void ege_adjustment_action_get_property( GObject* obj, guint propId, GVal case PROP_ICON_ID: g_value_set_string( value, action->private_data->iconId ); - break; + break; case PROP_ICON_SIZE: g_value_set_int( value, action->private_data->iconSize ); - break; + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID( obj, propId, pspec ); @@ -836,7 +839,7 @@ static GtkWidget* create_tool_item( GtkAction* action ) g_object_get_property( G_OBJECT(action), "short_label", &value ); if ( act->private_data->appearanceMode == APPEARANCE_FULL ) { - // Slider + /* Slider */ gchar *leakyForNow = g_value_dup_string( &value ); spinbutton = gtk_hscale_new( act->private_data->adj); gtk_widget_set_size_request(spinbutton, 100, -1); @@ -850,9 +853,11 @@ static GtkWidget* create_tool_item( GtkAction* action ) gtk_scale_button_set_icons( GTK_SCALE_BUTTON(spinbutton), floogles ); #endif /* GTK_CHECK_VERSION(2,12,0) */ } else { - //spinbutton = gtk_spin_button_new( act->private_data->adj, act->private_data->climbRate, act->private_data->digits ); - Inkscape::UI::Widget::SpinButton *inkscape_spinbutton = new Inkscape::UI::Widget::SpinButton(*Glib::wrap(act->private_data->adj, true), act->private_data->climbRate, act->private_data->digits); - spinbutton = GTK_WIDGET( inkscape_spinbutton->gobj() ); + if ( gFactoryCb ) { + spinbutton = gFactoryCb( act->private_data->adj, act->private_data->climbRate, act->private_data->digits ); + } else { + spinbutton = gtk_spin_button_new( act->private_data->adj, act->private_data->climbRate, act->private_data->digits ); + } } item = GTK_WIDGET( gtk_tool_item_new() ); @@ -869,22 +874,22 @@ static GtkWidget* create_tool_item( GtkAction* action ) } gtk_tooltips_set_tip( act->private_data->toolTips, spinbutton, tipstr, 0 ); } - g_value_unset( &tooltip ); + g_value_unset( &tooltip ); } if ( act->private_data->appearanceMode != APPEARANCE_FULL ) { - GtkWidget* filler1 = gtk_label_new(" "); - gtk_box_pack_start( GTK_BOX(hb), filler1, FALSE, FALSE, 0 ); + GtkWidget* filler1 = gtk_label_new(" "); + gtk_box_pack_start( GTK_BOX(hb), filler1, FALSE, FALSE, 0 ); - // Use an icon if available or use short-label - if ( act->private_data->iconId && strcmp( act->private_data->iconId, "" ) != 0 ) { + /* Use an icon if available or use short-label */ + if ( act->private_data->iconId && strcmp( act->private_data->iconId, "" ) != 0 ) { GtkWidget* icon = sp_icon_new( act->private_data->iconSize, act->private_data->iconId ); gtk_box_pack_start( GTK_BOX(hb), icon, FALSE, FALSE, 0 ); - } else { + } else { GtkWidget* lbl = gtk_label_new( g_value_get_string( &value ) ? g_value_get_string( &value ) : "wwww" ); gtk_misc_set_alignment( GTK_MISC(lbl), 1.0, 0.5 ); gtk_box_pack_start( GTK_BOX(hb), lbl, FALSE, FALSE, 0 ); - } + } } if ( act->private_data->appearanceMode == APPEARANCE_FULL ) { @@ -923,7 +928,7 @@ static GtkWidget* create_tool_item( GtkAction* action ) act->private_data->toolPost( item ); } - g_value_unset( &value ); + g_value_unset( &value ); } else { item = gParentClass->create_tool_item( action ); } diff --git a/src/ege-adjustment-action.h b/src/ege-adjustment-action.h index 4a8a172e2..b7da6a499 100644 --- a/src/ege-adjustment-action.h +++ b/src/ege-adjustment-action.h @@ -87,6 +87,24 @@ struct _EgeAdjustmentActionClass /** Standard Gtk type function */ GType ege_adjustment_action_get_type( void ); + +/* + * Note: This normally could be implemented via a GType property for the class to construct, + * but gtkmm classes implemented in C++ only will often not funciton properly. + * + */ + +/** Callback type for widgets creation factory */ +typedef GtkWidget* (*EgeCreateAdjWidgetCB)( GtkAdjustment *adjustment, gdouble climb_rate, guint digits ); + +/** + * Sets a factory callback to be used to create the specific widget. + * + * @param factoryCb the callback to use to create custom widgets, NULL to use the default. + */ +void ege_adjustment_action_set_compact_tool_factory( EgeCreateAdjWidgetCB factoryCb ); + + /** * Creates a new EgeAdjustmentAction instance. * This is a GtkAction subclass that manages a value stored in a diff --git a/src/widgets/select-toolbar.cpp b/src/widgets/select-toolbar.cpp index 89253983b..e08b4ac61 100644 --- a/src/widgets/select-toolbar.cpp +++ b/src/widgets/select-toolbar.cpp @@ -23,6 +23,7 @@ #include "widgets/spw-utilities.h" #include "widgets/widget-sizes.h" #include "widgets/spinbutton-events.h" +#include "ui/widget/spinbutton.h" #include "widgets/icon.h" #include "widgets/sp-widget.h" @@ -255,6 +256,16 @@ sp_object_layout_any_value_changed(GtkAdjustment *adj, SPWidget *spw) g_object_set_data(G_OBJECT(spw), "update", GINT_TO_POINTER(FALSE)); } +static GtkWidget* createCustomSlider( GtkAdjustment *adjustment, gdouble climbRate, guint digits ) +{ + Inkscape::UI::Widget::SpinButton *inkSpinner = new Inkscape::UI::Widget::SpinButton(*Glib::wrap(adjustment, true), climbRate, digits); + inkSpinner = Gtk::manage( inkSpinner ); + GtkWidget *widget = GTK_WIDGET( inkSpinner->gobj() ); + return widget; +} + +// TODO create_adjustment_action appears to be a rogue tile copy from toolbox.cpp. Resolve it to be unified: + static EgeAdjustmentAction * create_adjustment_action( gchar const *name, gchar const *label, gchar const *shortLabel, @@ -266,6 +277,12 @@ static EgeAdjustmentAction * create_adjustment_action( gchar const *name, gchar const *tooltip, gboolean altx ) { + static bool init = false; + if ( !init ) { + init = true; + ege_adjustment_action_set_compact_tool_factory( createCustomSlider ); + } + GtkAdjustment* adj = GTK_ADJUSTMENT( gtk_adjustment_new( 0.0, lower, 1e6, SPIN_STEP, SPIN_PAGE_STEP, 0 ) ); if (tracker) { tracker->addAdjustment(adj); diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index fe87bc4e2..8496ec0d0 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -100,6 +100,7 @@ #include "../verbs.h" #include "../widgets/button.h" #include "../widgets/spinbutton-events.h" +#include "ui/widget/spinbutton.h" #include "../widgets/spw-utilities.h" #include "../widgets/widget-sizes.h" #include "../xml/attribute-record.h" @@ -1052,6 +1053,14 @@ GtkWidget *ToolboxFactory::createSnapToolbox() return toolboxNewCommon( tb, BAR_SNAP, GTK_POS_LEFT ); } +static GtkWidget* createCustomSlider( GtkAdjustment *adjustment, gdouble climbRate, guint digits ) +{ + Inkscape::UI::Widget::SpinButton *inkSpinner = new Inkscape::UI::Widget::SpinButton(*Glib::wrap(adjustment, true), climbRate, digits); + inkSpinner = Gtk::manage( inkSpinner ); + GtkWidget *widget = GTK_WIDGET( inkSpinner->gobj() ); + return widget; +} + static EgeAdjustmentAction * create_adjustment_action( gchar const *name, gchar const *label, gchar const *shortLabel, gchar const *tooltip, Glib::ustring const &path, gdouble def, @@ -1064,6 +1073,12 @@ static EgeAdjustmentAction * create_adjustment_action( gchar const *name, void (*callback)(GtkAdjustment *, GObject *), gdouble climb = 0.1, guint digits = 3, double factor = 1.0 ) { + static bool init = false; + if ( !init ) { + init = true; + ege_adjustment_action_set_compact_tool_factory( createCustomSlider ); + } + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); GtkAdjustment* adj = GTK_ADJUSTMENT( gtk_adjustment_new( prefs->getDouble(path, def) * factor, lower, upper, step, page, 0 ) ); |
