From 81a9af22c466ddef2c71616702e565245ea37254 Mon Sep 17 00:00:00 2001 From: joncruz Date: Sat, 21 Oct 2006 19:37:30 +0000 Subject: [PATCH] Adding climb and digits properties, key processing and focus handling --- src/ege-adjustment-action.cpp | 216 +++++++++++++++++++++++++++++----- src/ege-adjustment-action.h | 7 +- src/widgets/toolbox.cpp | 31 +++-- 3 files changed, 208 insertions(+), 46 deletions(-) diff --git a/src/ege-adjustment-action.cpp b/src/ege-adjustment-action.cpp index 52037f1e9..45bd6a207 100644 --- a/src/ege-adjustment-action.cpp +++ b/src/ege-adjustment-action.cpp @@ -43,6 +43,7 @@ #include +#include #include #include #include @@ -63,8 +64,12 @@ static void connect_proxy( GtkAction *action, GtkWidget *proxy ); static void disconnect_proxy( GtkAction *action, GtkWidget *proxy ); static gboolean focus_in_cb( GtkWidget *widget, GdkEventKey *event, gpointer data ); +static gboolean focus_out_cb( GtkWidget *widget, GdkEventKey *event, gpointer data ); static gboolean keypress_cb( GtkWidget *widget, GdkEventKey *event, gpointer data ); +static void ege_adjustment_action_defocus( EgeAdjustmentAction* action ); + + static GtkActionClass* gParentClass = 0; @@ -72,15 +77,21 @@ struct _EgeAdjustmentActionPrivate { GtkAdjustment* adj; GtkWidget* focusWidget; + gdouble climbRate; + guint digits; gdouble lastVal; - gboolean keepFocus; + gdouble step; + gdouble page; + gboolean transferFocus; }; #define EGE_ADJUSTMENT_ACTION_GET_PRIVATE( o ) ( G_TYPE_INSTANCE_GET_PRIVATE( (o), EGE_ADJUSTMENT_ACTION_TYPE, EgeAdjustmentActionPrivate ) ) enum { PROP_ADJUSTMENT = 1, - PROP_FOCUS_WIDGET + PROP_FOCUS_WIDGET, + PROP_CLIMB_RATE, + PROP_DIGITS }; GType ege_adjustment_action_get_type( void ) @@ -123,10 +134,11 @@ static void ege_adjustment_action_class_init( EgeAdjustmentActionClass* klass ) g_object_class_install_property( objClass, PROP_ADJUSTMENT, - g_param_spec_pointer( "adjustment", - "Adjustment", - "The adjustment to change", - (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT) ) ); + g_param_spec_object( "adjustment", + "Adjustment", + "The adjustment to change", + GTK_TYPE_ADJUSTMENT, + (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT) ) ); g_object_class_install_property( objClass, PROP_FOCUS_WIDGET, @@ -135,6 +147,22 @@ static void ege_adjustment_action_class_init( EgeAdjustmentActionClass* klass ) "The widget to return focus to", (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT) ) ); + g_object_class_install_property( objClass, + PROP_CLIMB_RATE, + g_param_spec_double( "climb-rate", + "Climb Rate", + "The acelleraton rate", + 0.0, G_MAXDOUBLE, 0.0, + (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT) ) ); + + g_object_class_install_property( objClass, + PROP_DIGITS, + g_param_spec_uint( "digits", + "Digits", + "The number of digits to show", + 0, 20, 0, + (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT) ) ); + g_type_class_add_private( klass, sizeof(EgeAdjustmentActionClass) ); } } @@ -144,15 +172,21 @@ static void ege_adjustment_action_init( EgeAdjustmentAction* action ) action->private_data = EGE_ADJUSTMENT_ACTION_GET_PRIVATE( action ); action->private_data->adj = 0; action->private_data->focusWidget = 0; + action->private_data->climbRate = 0.0; + action->private_data->digits = 2; action->private_data->lastVal = 0.0; - action->private_data->keepFocus = FALSE; + action->private_data->step = 0.0; + action->private_data->page = 0.0; + action->private_data->transferFocus = FALSE; } EgeAdjustmentAction* ege_adjustment_action_new( GtkAdjustment* adjustment, const gchar *name, const gchar *label, const gchar *tooltip, - const gchar *stock_id ) + const gchar *stock_id, + gdouble climb_rate, + guint digits ) { GObject* obj = (GObject*)g_object_new( EGE_ADJUSTMENT_ACTION_TYPE, "name", name, @@ -160,6 +194,8 @@ EgeAdjustmentAction* ege_adjustment_action_new( GtkAdjustment* adjustment, "tooltip", tooltip, "stock_id", stock_id, "adjustment", adjustment, + "climb-rate", climb_rate, + "digits", digits, NULL ); EgeAdjustmentAction* action = EGE_ADJUSTMENT_ACTION( obj ); @@ -172,16 +208,20 @@ static void ege_adjustment_action_get_property( GObject* obj, guint propId, GVal EgeAdjustmentAction* action = EGE_ADJUSTMENT_ACTION( obj ); switch ( propId ) { case PROP_ADJUSTMENT: - { - g_value_set_pointer( value, action->private_data->adj ); - } - break; + g_value_set_object( value, action->private_data->adj ); + break; case PROP_FOCUS_WIDGET: - { g_value_set_pointer( value, action->private_data->focusWidget ); - } - break; + break; + + case PROP_CLIMB_RATE: + g_value_set_double( value, action->private_data->climbRate ); + break; + + case PROP_DIGITS: + g_value_set_uint( value, action->private_data->digits ); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID( obj, propId, pspec ); @@ -194,7 +234,11 @@ void ege_adjustment_action_set_property( GObject* obj, guint propId, const GValu switch ( propId ) { case PROP_ADJUSTMENT: { - action->private_data->adj = (GtkAdjustment*)g_value_get_pointer( value ); + action->private_data->adj = GTK_ADJUSTMENT( g_value_get_object( value ) ); + g_object_get( G_OBJECT(action->private_data->adj), + "step-increment", &action->private_data->step, + "page-increment", &action->private_data->page, + NULL ); } break; @@ -205,6 +249,20 @@ void ege_adjustment_action_set_property( GObject* obj, guint propId, const GValu } break; + case PROP_CLIMB_RATE: + { + /* TODO pass on */ + action->private_data->climbRate = g_value_get_double( value ); + } + break; + + case PROP_DIGITS: + { + /* TODO pass on */ + action->private_data->digits = g_value_get_uint( value ); + } + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID( obj, propId, pspec ); } @@ -242,22 +300,20 @@ static GtkWidget* create_menu_item( GtkAction* action ) return item; } -/* void flippy(GtkAdjustment *adj, GtkWidget *) */ -/* { */ -/* g_message("flippy on %p to %f", adj, gtk_adjustment_get_value(adj) ); */ -/* } */ - -/* void floppy(GtkSpinButton *spin, GtkWidget *) */ -/* { */ -/* g_message("f__ppy on %p to %f", spin, gtk_spin_button_get_value(spin) ); */ -/* } */ +void value_changed_cb( GtkSpinButton* spin, EgeAdjustmentAction* act ) +{ + if ( GTK_WIDGET_HAS_FOCUS( GTK_WIDGET(spin) ) ) { + ege_adjustment_action_defocus( act ); + } +} static GtkWidget* create_tool_item( GtkAction* action ) { GtkWidget* item = 0; if ( IS_EGE_ADJUSTMENT_ACTION(action) ) { - GtkWidget* spinbutton = gtk_spin_button_new( EGE_ADJUSTMENT_ACTION(action)->private_data->adj, 0.1, 2 ); + EgeAdjustmentAction* act = EGE_ADJUSTMENT_ACTION( action ); + GtkWidget* spinbutton = gtk_spin_button_new( act->private_data->adj, act->private_data->climbRate, act->private_data->digits ); GtkWidget* hb = gtk_hbox_new( FALSE, 5 ); GValue value; @@ -276,9 +332,10 @@ static GtkWidget* create_tool_item( GtkAction* action ) gtk_container_add( GTK_CONTAINER(item), hb ); g_signal_connect( G_OBJECT(spinbutton), "focus-in-event", G_CALLBACK(focus_in_cb), action ); + g_signal_connect( G_OBJECT(spinbutton), "focus-out-event", G_CALLBACK(focus_out_cb), action ); g_signal_connect( G_OBJECT(spinbutton), "key-press-event", G_CALLBACK(keypress_cb), action ); -/* g_signal_connect( G_OBJECT(spinbutton), "value-changed", G_CALLBACK(floppy), action ); */ + g_signal_connect( G_OBJECT(spinbutton), "value-changed", G_CALLBACK(value_changed_cb), action ); /* g_signal_connect( G_OBJECT(EGE_ADJUSTMENT_ACTION(action)->private_data->adj), "value-changed", G_CALLBACK(flippy), action ); */ @@ -302,9 +359,7 @@ static void disconnect_proxy( GtkAction *action, GtkWidget *proxy ) void ege_adjustment_action_defocus( EgeAdjustmentAction* action ) { - if ( action->private_data->keepFocus ) { - action->private_data->keepFocus = FALSE; - } else { + if ( action->private_data->transferFocus ) { if ( action->private_data->focusWidget ) { gtk_widget_grab_focus( action->private_data->focusWidget ); } @@ -313,16 +368,115 @@ void ege_adjustment_action_defocus( EgeAdjustmentAction* action ) gboolean focus_in_cb( GtkWidget *widget, GdkEventKey *event, gpointer data ) { + (void)event; if ( IS_EGE_ADJUSTMENT_ACTION(data) ) { EgeAdjustmentAction* action = EGE_ADJUSTMENT_ACTION( data ); action->private_data->lastVal = gtk_spin_button_get_value( GTK_SPIN_BUTTON(widget) ); + action->private_data->transferFocus = TRUE; } return FALSE; /* report event not consumed */ } -gboolean keypress_cb( GtkWidget *widget, GdkEventKey *event, gpointer data ) +static gboolean focus_out_cb( GtkWidget *widget, GdkEventKey *event, gpointer data ) { + (void)widget; + (void)event; + if ( IS_EGE_ADJUSTMENT_ACTION(data) ) { + EgeAdjustmentAction* action = EGE_ADJUSTMENT_ACTION( data ); + action->private_data->transferFocus = FALSE; + } return FALSE; /* report event not consumed */ } + + +gboolean keypress_cb( GtkWidget *widget, GdkEventKey *event, gpointer data ) +{ + gboolean wasConsumed = FALSE; /* default to report event not consumed */ + EgeAdjustmentAction* action = EGE_ADJUSTMENT_ACTION(data); + guint key = 0; + gdk_keymap_translate_keyboard_state( gdk_keymap_get_for_display( gdk_display_get_default() ), + event->hardware_keycode, (GdkModifierType)event->state, + 0, &key, 0, 0, 0 ); + + switch ( key ) { + case GDK_Escape: + { + gtk_spin_button_set_value( GTK_SPIN_BUTTON(widget), action->private_data->lastVal ); + action->private_data->transferFocus = TRUE; + ege_adjustment_action_defocus( action ); + wasConsumed = TRUE; + } + break; + + case GDK_Return: + case GDK_KP_Enter: + { + action->private_data->transferFocus = TRUE; + ege_adjustment_action_defocus( action ); + wasConsumed = TRUE; + } + break; + + case GDK_Tab: + case GDK_ISO_Left_Tab: + { + action->private_data->transferFocus = FALSE; + wasConsumed = FALSE; + } + break; + + case GDK_Up: + case GDK_KP_Up: + { + gdouble val = gtk_spin_button_get_value( GTK_SPIN_BUTTON(widget) ); + gtk_spin_button_set_value( GTK_SPIN_BUTTON(widget), val + action->private_data->step ); + action->private_data->transferFocus = FALSE; + wasConsumed = TRUE; + } + break; + + case GDK_Down: + case GDK_KP_Down: + { + gdouble val = gtk_spin_button_get_value( GTK_SPIN_BUTTON(widget) ); + gtk_spin_button_set_value( GTK_SPIN_BUTTON(widget), val - action->private_data->step ); + action->private_data->transferFocus = FALSE; + wasConsumed = TRUE; + } + break; + + case GDK_Page_Up: + case GDK_KP_Page_Up: + { + gdouble val = gtk_spin_button_get_value( GTK_SPIN_BUTTON(widget) ); + gtk_spin_button_set_value( GTK_SPIN_BUTTON(widget), val + action->private_data->page ); + action->private_data->transferFocus = FALSE; + wasConsumed = TRUE; + } + break; + + case GDK_Page_Down: + case GDK_KP_Page_Down: + { + gdouble val = gtk_spin_button_get_value( GTK_SPIN_BUTTON(widget) ); + gtk_spin_button_set_value( GTK_SPIN_BUTTON(widget), val - action->private_data->page ); + action->private_data->transferFocus = FALSE; + wasConsumed = TRUE; + } + break; + + case GDK_z: + case GDK_Z: + { + gtk_spin_button_set_value( GTK_SPIN_BUTTON(widget), action->private_data->lastVal ); + action->private_data->transferFocus = FALSE; + wasConsumed = TRUE; + } + break; + + } + + return wasConsumed; +} diff --git a/src/ege-adjustment-action.h b/src/ege-adjustment-action.h index ec93ffbaa..109b5ff76 100644 --- a/src/ege-adjustment-action.h +++ b/src/ege-adjustment-action.h @@ -39,6 +39,7 @@ * * ***** END LICENSE BLOCK ***** */ +/* Note: this file should be kept compliable as both .cpp and .c */ #include #include @@ -75,15 +76,15 @@ EgeAdjustmentAction* ege_adjustment_action_new( GtkAdjustment* adjustment, const gchar *name, const gchar *label, const gchar *tooltip, - const gchar *stock_id ); + const gchar *stock_id, + gdouble climb_rate, + guint digits ); GtkAdjustment* ege_adjustment_action_get_adjustment( EgeAdjustmentAction* action ); void ege_adjustment_action_set_focuswidget( EgeAdjustmentAction* action, GtkWidget* widget ); GtkWidget* ege_adjustment_action_get_focuswidget( EgeAdjustmentAction* action ); -void ege_adjustment_action_defocus( EgeAdjustmentAction* action ); - G_END_DECLS #endif /* SEEN_EGE_ADJUSTMENT_ACTION */ diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 8e03e5021..287a45f1a 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -818,6 +818,7 @@ sp_tb_spinbutton( static EgeAdjustmentAction * create_adjustment_action( gchar const *name, gchar const *label, gchar const *tooltip, gchar const *path, gchar const *data, gdouble def, + GtkWidget *focusTarget, GtkWidget *us, GtkWidget *dataKludge, gboolean altx, gchar const *altx_mark, @@ -833,9 +834,15 @@ static EgeAdjustmentAction * create_adjustment_action( gchar const *name, gtk_signal_connect( GTK_OBJECT(adj), "value-changed", GTK_SIGNAL_FUNC(callback), dataKludge ); - EgeAdjustmentAction* act = ege_adjustment_action_new( adj, name, label, tooltip, 0 ); + EgeAdjustmentAction* act = ege_adjustment_action_new( adj, name, label, tooltip, 0, climb, digits ); - gtk_object_set_data( GTK_OBJECT(dataKludge), data, adj ); + if ( focusTarget ) { + ege_adjustment_action_set_focuswidget( act, focusTarget ); + } + + if ( dataKludge ) { + gtk_object_set_data( GTK_OBJECT(dataKludge), data, adj ); + } return act; } @@ -2022,7 +2029,7 @@ static void sp_ddc_tilt_state_changed2( GtkToggleAction *act, GtkAction *calligr { prefs_set_int_attribute( "tools.calligraphic", "usetilt", gtk_toggle_action_get_active( act ) ? 1 : 0 ); - gtk_action_set_sensitive( calligraphy_angle, gtk_toggle_action_get_active( act ) ); + gtk_action_set_sensitive( calligraphy_angle, !gtk_toggle_action_get_active( act ) ); } static void sp_ddc_defaults2(GtkWidget *, GtkWidget *dataKludge) @@ -2191,7 +2198,7 @@ sp_calligraphy_toolbox_new(SPDesktop *desktop) eact = create_adjustment_action( "WidthAction", _("Width:"), _("The width of the calligraphic pen (relative to the visible canvas area)"), "tools.calligraphic", "width", 15, - NULL, holder, TRUE, "altx-calligraphy", + GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "altx-calligraphy", 1, 100, 1.0, 10.0, sp_ddc_width_value_changed2, 0.01, 0, 100 ); gtk_action_group_add_action( mainActions, GTK_ACTION(eact) ); @@ -2201,7 +2208,7 @@ sp_calligraphy_toolbox_new(SPDesktop *desktop) eact = create_adjustment_action( "ThinningAction", _("Thinning:"), _("How much velocity thins the stroke (> 0 makes fast strokes thinner, < 0 makes them broader, 0 makes width independent of velocity)"), "tools.calligraphic", "thinning", 0.1, - NULL, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL, -1.0, 1.0, 0.01, 0.1, sp_ddc_velthin_value_changed2, 0.01, 2); gtk_action_group_add_action( mainActions, GTK_ACTION(eact) ); @@ -2211,7 +2218,7 @@ sp_calligraphy_toolbox_new(SPDesktop *desktop) eact = create_adjustment_action( "AngleAction", _("Angle:"), _("The angle of the pen's nib (in degrees; 0 = horizontal; has no effect if fixation = 0)"), "tools.calligraphic", "angle", 30, - NULL, holder, TRUE, "calligraphy-angle", + GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "calligraphy-angle", -90.0, 90.0, 1.0, 10.0, sp_ddc_angle_value_changed2, 1, 0 ); gtk_action_group_add_action( mainActions, GTK_ACTION(eact) ); @@ -2222,7 +2229,7 @@ sp_calligraphy_toolbox_new(SPDesktop *desktop) eact = create_adjustment_action( "FixationAction", _("Fixation:"), _("Angle behavior (0 = nib always perpendicular to stroke direction, 1 = fixed angle)"), "tools.calligraphic", "flatness", 0.9, - NULL, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL, 0.0, 1.0, 0.01, 0.1, sp_ddc_flatness_value_changed2, 0.01, 2 ); gtk_action_group_add_action( mainActions, GTK_ACTION(eact) ); @@ -2233,7 +2240,7 @@ sp_calligraphy_toolbox_new(SPDesktop *desktop) eact = create_adjustment_action( "CapRoundingAction", _("Round:"), _("Increase to round the ends of strokes"), "tools.calligraphic", "cap_rounding", 0.0, - NULL, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL, 0.0, 1.0, 0.01, 0.1, sp_ddc_cap_rounding_value_changed2, 0.01, 2 ); gtk_action_group_add_action( mainActions, GTK_ACTION(eact) ); @@ -2243,7 +2250,7 @@ sp_calligraphy_toolbox_new(SPDesktop *desktop) eact = create_adjustment_action( "TremorAction", _("Tremor:"), _("Increase to make strokes rugged and trembling"), "tools.calligraphic", "tremor", 0.0, - NULL, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL, 0.0, 1.0, 0.01, 0.1, sp_ddc_tremor_value_changed2, 0.01, 2 ); @@ -2254,7 +2261,7 @@ sp_calligraphy_toolbox_new(SPDesktop *desktop) eact = create_adjustment_action( "WiggleAction", _("Wiggle:"), _("Increase to make the pen waver and wiggle"), "tools.calligraphic", "wiggle", 0.0, - NULL, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL, 0.0, 1.0, 0.01, 0.1, sp_ddc_wiggle_value_changed2, 0.01, 2 ); gtk_action_group_add_action( mainActions, GTK_ACTION(eact) ); @@ -2264,7 +2271,7 @@ sp_calligraphy_toolbox_new(SPDesktop *desktop) eact = create_adjustment_action( "MassAction", _("Mass:"), _("Increase to make the pen drag behind, as if slowed by inertia"), "tools.calligraphic", "mass", 0.02, - NULL, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL, 0.0, 1.0, 0.01, 0.1, sp_ddc_mass_value_changed2, 0.01, 2 ); gtk_action_group_add_action( mainActions, GTK_ACTION(eact) ); @@ -2292,7 +2299,7 @@ sp_calligraphy_toolbox_new(SPDesktop *desktop) Inkscape::ICON_SIZE_DECORATION ); gtk_action_group_add_action( mainActions, GTK_ACTION( act ) ); g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_ddc_tilt_state_changed2), calligraphy_angle ); - gtk_action_set_sensitive( GTK_ACTION(calligraphy_angle), prefs_get_int_attribute( "tools.calligraphic", "usetilt", 1 ) ); + gtk_action_set_sensitive( GTK_ACTION(calligraphy_angle), !prefs_get_int_attribute( "tools.calligraphic", "usetilt", 1 ) ); gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs_get_int_attribute( "tools.calligraphic", "usetilt", 1 ) ); } -- 2.30.2