summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7d433c4)
raw | patch | inline | side by side (parent: 7d433c4)
author | joncruz <joncruz@users.sourceforge.net> | |
Sat, 21 Oct 2006 19:37:30 +0000 (19:37 +0000) | ||
committer | joncruz <joncruz@users.sourceforge.net> | |
Sat, 21 Oct 2006 19:37:30 +0000 (19:37 +0000) |
src/ege-adjustment-action.cpp | patch | blob | history | |
src/ege-adjustment-action.h | patch | blob | history | |
src/widgets/toolbox.cpp | patch | blob | history |
index 52037f1e9751431c580dca116c3402f1f63a5586..45bd6a20751103e5b0d8f3fa0212bb4edaf025d8 100644 (file)
#include <string.h>
+#include <gdk/gdkkeysyms.h>
#include <gtk/gtktoolitem.h>
#include <gtk/gtkspinbutton.h>
#include <gtk/gtkhbox.h>
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;
{
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) );
}
}
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,
"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 );
}
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;
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 ); */
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 );
}
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;
+}
index ec93ffbaa6f9bfccbe0ae45d420235a6e8e55865..109b5ff7625e2e773a17e37591d178020b3f1af3 100644 (file)
*
* ***** END LICENSE BLOCK ***** */
+/* Note: this file should be kept compliable as both .cpp and .c */
#include <glib.h>
#include <gtk/gtkaction.h>
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 */
index 8e03e50219023cec27b02058c9e559cf19698189..287a45f1a2c196bb41bf9a04d49a97764bb39f4f 100644 (file)
--- a/src/widgets/toolbox.cpp
+++ b/src/widgets/toolbox.cpp
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,
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)
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) );
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) );
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) );
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) );
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) );
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 );
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) );
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) );
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 ) );
}