summaryrefslogtreecommitdiff
path: root/gtk
diff options
context:
space:
mode:
authorMichael Natterer <mitch@imendio.com>2005-11-11 12:48:29 +0000
committerMichael Natterer <mitch@src.gnome.org>2005-11-11 12:48:29 +0000
commitfc7c8bbeb44648f437d92b2a55270ae991301134 (patch)
tree0192127838ff6a0a9c6ddc5fb078c7af649f6f4b /gtk
parente0cad47afc4fb138709d44b10fdaf7be365620b8 (diff)
downloadgtk+-fc7c8bbeb44648f437d92b2a55270ae991301134.tar.gz
Added per-stepper API for GtkRange's stepper sensitivity as discussed in
2005-11-11 Michael Natterer <mitch@imendio.com> Added per-stepper API for GtkRange's stepper sensitivity as discussed in bug #321056: * gtk/gtkenums.h: added GtkSensitivityType which can be { AUTO, ON, OFF }. * gtk/gtkrange.[ch]: added properties "lower-stepper-sensitivity" and "upper-stepper-sensitivity" and public getters/setters for them. Changed stepper drawing to honor the new properties. * gtk/gtk.symbols: added the new symbols.
Diffstat (limited to 'gtk')
-rw-r--r--gtk/gtk.symbols4
-rw-r--r--gtk/gtkenums.h8
-rw-r--r--gtk/gtkrange.c185
-rw-r--r--gtk/gtkrange.h56
4 files changed, 211 insertions, 42 deletions
diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols
index d45b16ab9b..4a42eb045d 100644
--- a/gtk/gtk.symbols
+++ b/gtk/gtk.symbols
@@ -2492,14 +2492,18 @@ gtk_radio_tool_button_set_group
#if IN_FILE(__GTK_RANGE_C__)
gtk_range_get_adjustment
gtk_range_get_inverted
+gtk_range_get_lower_stepper_sensitivity
gtk_range_get_type G_GNUC_CONST
gtk_range_get_update_policy
+gtk_range_get_upper_stepper_sensitivity
gtk_range_get_value
gtk_range_set_adjustment
gtk_range_set_increments
gtk_range_set_inverted
+gtk_range_set_lower_stepper_sensitivity
gtk_range_set_range
gtk_range_set_update_policy
+gtk_range_set_upper_stepper_sensitivity
gtk_range_set_value
#endif
#endif
diff --git a/gtk/gtkenums.h b/gtk/gtkenums.h
index b55d31cd75..e87ec53e0f 100644
--- a/gtk/gtkenums.h
+++ b/gtk/gtkenums.h
@@ -133,6 +133,14 @@ typedef enum
GTK_ICON_SIZE_DIALOG
} GtkIconSize;
+/* automatic sensitivity */
+typedef enum
+{
+ GTK_SENSITIVITY_AUTO,
+ GTK_SENSITIVITY_ON,
+ GTK_SENSITIVITY_OFF
+} GtkSensitivityType;
+
#ifndef GTK_DISABLE_DEPRECATED
/* side types */
typedef enum
diff --git a/gtk/gtkrange.c b/gtk/gtkrange.c
index 1dc4d4b215..f9c62932a5 100644
--- a/gtk/gtkrange.c
+++ b/gtk/gtkrange.c
@@ -45,7 +45,9 @@ enum {
PROP_0,
PROP_UPDATE_POLICY,
PROP_ADJUSTMENT,
- PROP_INVERTED
+ PROP_INVERTED,
+ PROP_LOWER_STEPPER_SENSITIVITY,
+ PROP_UPPER_STEPPER_SENSITIVITY
};
enum {
@@ -89,6 +91,10 @@ struct _GtkRangeLayout
/* "grabbed" mouse location, OUTSIDE for no grab */
MouseLocation grab_location;
gint grab_button; /* 0 if none */
+
+ /* Stepper sensitivity */
+ GtkSensitivityType lower_sensitivity;
+ GtkSensitivityType upper_sensitivity;
};
@@ -347,7 +353,25 @@ gtk_range_class_init (GtkRangeClass *class)
P_("Invert direction slider moves to increase range value"),
FALSE,
GTK_PARAM_READWRITE));
-
+
+ g_object_class_install_property (gobject_class,
+ PROP_LOWER_STEPPER_SENSITIVITY,
+ g_param_spec_enum ("lower-stepper-sensitivity",
+ P_("Lower stepper sensitivity"),
+ P_("The sensitivity policy for the stepper that points to the adjustment's lower side"),
+ GTK_TYPE_SENSITIVITY_TYPE,
+ GTK_SENSITIVITY_AUTO,
+ GTK_PARAM_READWRITE));
+
+ g_object_class_install_property (gobject_class,
+ PROP_UPPER_STEPPER_SENSITIVITY,
+ g_param_spec_enum ("upper-stepper-sensitivity",
+ P_("Upper stepper sensitivity"),
+ P_("The sensitivity policy for the stepper that points to the adjustment's upper side"),
+ GTK_TYPE_SENSITIVITY_TYPE,
+ GTK_SENSITIVITY_AUTO,
+ GTK_PARAM_READWRITE));
+
gtk_widget_class_install_style_property (widget_class,
g_param_spec_int ("slider-width",
P_("Slider Width"),
@@ -419,6 +443,12 @@ gtk_range_set_property (GObject *object,
case PROP_INVERTED:
gtk_range_set_inverted (range, g_value_get_boolean (value));
break;
+ case PROP_LOWER_STEPPER_SENSITIVITY:
+ gtk_range_set_lower_stepper_sensitivity (range, g_value_get_enum (value));
+ break;
+ case PROP_UPPER_STEPPER_SENSITIVITY:
+ gtk_range_set_upper_stepper_sensitivity (range, g_value_get_enum (value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -446,6 +476,12 @@ gtk_range_get_property (GObject *object,
case PROP_INVERTED:
g_value_set_boolean (value, range->inverted);
break;
+ case PROP_LOWER_STEPPER_SENSITIVITY:
+ g_value_set_enum (value, gtk_range_get_lower_stepper_sensitivity (range));
+ break;
+ case PROP_UPPER_STEPPER_SENSITIVITY:
+ g_value_set_enum (value, gtk_range_get_upper_stepper_sensitivity (range));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -474,6 +510,8 @@ gtk_range_init (GtkRange *range)
range->layout->mouse_y = -1;
range->layout->grab_location = MOUSE_OUTSIDE;
range->layout->grab_button = 0;
+ range->layout->lower_sensitivity = GTK_SENSITIVITY_AUTO;
+ range->layout->upper_sensitivity = GTK_SENSITIVITY_AUTO;
range->timer = NULL;
}
@@ -641,6 +679,92 @@ gtk_range_get_inverted (GtkRange *range)
}
/**
+ * gtk_range_set_lower_stepper_sensitivity:
+ * @range: a #GtkRange
+ * @sensitivity: the lower stepper's sensitivity policy.
+ *
+ * Sets the sensitivity policy for the stepper that points to the
+ * 'lower' end of the GtkRange's adjustment.
+ *
+ * Sine: 2.10
+ **/
+void
+gtk_range_set_lower_stepper_sensitivity (GtkRange *range,
+ GtkSensitivityType sensitivity)
+{
+ g_return_if_fail (GTK_IS_RANGE (range));
+
+ if (range->layout->lower_sensitivity != sensitivity)
+ {
+ range->layout->lower_sensitivity = sensitivity;
+ gtk_widget_queue_draw (GTK_WIDGET (range));
+ g_object_notify (G_OBJECT (range), "lower-stepper-sensitivity");
+ }
+}
+
+/**
+ * gtk_range_get_lower_stepper_sensitivity:
+ * @range: a #GtkRange
+ *
+ * Gets the sensitivity policy for the stepper that points to the
+ * 'lower' end of the GtkRange's adjustment.
+ *
+ * Return value: The lower stepper's sensitivity policy.
+ *
+ * Since: 2.10
+ **/
+GtkSensitivityType
+gtk_range_get_lower_stepper_sensitivity (GtkRange *range)
+{
+ g_return_val_if_fail (GTK_IS_RANGE (range), GTK_SENSITIVITY_AUTO);
+
+ return range->layout->lower_sensitivity;
+}
+
+/**
+ * gtk_range_set_upper_stepper_sensitivity:
+ * @range: a #GtkRange
+ * @sensitivity: the upper stepper's sensitivity policy.
+ *
+ * Sets the sensitivity policy for the stepper that points to the
+ * 'upper' end of the GtkRange's adjustment.
+ *
+ * Sine: 2.10
+ **/
+void
+gtk_range_set_upper_stepper_sensitivity (GtkRange *range,
+ GtkSensitivityType sensitivity)
+{
+ g_return_if_fail (GTK_IS_RANGE (range));
+
+ if (range->layout->upper_sensitivity != sensitivity)
+ {
+ range->layout->upper_sensitivity = sensitivity;
+ gtk_widget_queue_draw (GTK_WIDGET (range));
+ g_object_notify (G_OBJECT (range), "upper-stepper-sensitivity");
+ }
+}
+
+/**
+ * gtk_range_get_upper_stepper_sensitivity:
+ * @range: a #GtkRange
+ *
+ * Gets the sensitivity policy for the stepper that points to the
+ * 'upper' end of the GtkRange's adjustment.
+ *
+ * Return value: The upper stepper's sensitivity policy.
+ *
+ * Since: 2.10
+ **/
+GtkSensitivityType
+gtk_range_get_upper_stepper_sensitivity (GtkRange *range)
+{
+ g_return_val_if_fail (GTK_IS_RANGE (range), GTK_SENSITIVITY_AUTO);
+
+ return range->layout->upper_sensitivity;
+}
+
+/**
* gtk_range_set_increments:
* @range: a #GtkRange
* @step: step size
@@ -919,7 +1043,7 @@ draw_stepper (GtkRange *range,
gint arrow_width;
gint arrow_height;
- gboolean arrow_insensitive = FALSE;
+ gboolean arrow_sensitive = TRUE;
/* More to get the right clip region than for efficiency */
if (!gdk_rectangle_intersect (area, rect, &intersection))
@@ -928,25 +1052,48 @@ draw_stepper (GtkRange *range,
intersection.x += widget->allocation.x;
intersection.y += widget->allocation.y;
- if (((!range->inverted && (arrow_type == GTK_ARROW_DOWN ||
- arrow_type == GTK_ARROW_RIGHT)) ||
- (range->inverted && (arrow_type == GTK_ARROW_UP ||
- arrow_type == GTK_ARROW_LEFT))) &&
- range->adjustment->value >=
- (range->adjustment->upper - range->adjustment->page_size))
+ if ((!range->inverted && (arrow_type == GTK_ARROW_DOWN ||
+ arrow_type == GTK_ARROW_RIGHT)) ||
+ (range->inverted && (arrow_type == GTK_ARROW_UP ||
+ arrow_type == GTK_ARROW_LEFT)))
{
- arrow_insensitive = TRUE;
+ switch (range->layout->upper_sensitivity)
+ {
+ case GTK_SENSITIVITY_AUTO:
+ arrow_sensitive =
+ (range->adjustment->value <
+ (range->adjustment->upper - range->adjustment->page_size));
+ break;
+
+ case GTK_SENSITIVITY_ON:
+ arrow_sensitive = TRUE;
+ break;
+
+ case GTK_SENSITIVITY_OFF:
+ arrow_sensitive = FALSE;
+ break;
+ }
}
- else if (((!range->inverted && (arrow_type == GTK_ARROW_UP ||
- arrow_type == GTK_ARROW_LEFT)) ||
- (range->inverted && (arrow_type == GTK_ARROW_DOWN ||
- arrow_type == GTK_ARROW_RIGHT))) &&
- range->adjustment->value <= range->adjustment->lower)
+ else
{
- arrow_insensitive = TRUE;
+ switch (range->layout->lower_sensitivity)
+ {
+ case GTK_SENSITIVITY_AUTO:
+ arrow_sensitive =
+ (range->adjustment->value > range->adjustment->lower);
+ break;
+
+ case GTK_SENSITIVITY_ON:
+ arrow_sensitive = TRUE;
+ break;
+
+ case GTK_SENSITIVITY_OFF:
+ arrow_sensitive = FALSE;
+ break;
+ }
}
- if (!GTK_WIDGET_IS_SENSITIVE (range) || arrow_insensitive)
+ if (!GTK_WIDGET_IS_SENSITIVE (range) || !arrow_sensitive)
state_type = GTK_STATE_INSENSITIVE;
else if (clicked)
state_type = GTK_STATE_ACTIVE;
@@ -955,7 +1102,7 @@ draw_stepper (GtkRange *range,
else
state_type = GTK_STATE_NORMAL;
- if (clicked && ! arrow_insensitive)
+ if (clicked && arrow_sensitive)
shadow_type = GTK_SHADOW_IN;
else
shadow_type = GTK_SHADOW_OUT;
@@ -975,7 +1122,7 @@ draw_stepper (GtkRange *range,
arrow_x = widget->allocation.x + rect->x + (rect->width - arrow_width) / 2;
arrow_y = widget->allocation.y + rect->y + (rect->height - arrow_height) / 2;
- if (clicked && ! arrow_insensitive)
+ if (clicked && arrow_sensitive)
{
gint arrow_displacement_x;
gint arrow_displacement_y;
diff --git a/gtk/gtkrange.h b/gtk/gtkrange.h
index 7bd057e51b..d4ef1b3e81 100644
--- a/gtk/gtkrange.h
+++ b/gtk/gtkrange.h
@@ -129,29 +129,39 @@ struct _GtkRangeClass
};
-GType gtk_range_get_type (void) G_GNUC_CONST;
-
-void gtk_range_set_update_policy (GtkRange *range,
- GtkUpdateType policy);
-GtkUpdateType gtk_range_get_update_policy (GtkRange *range);
-void gtk_range_set_adjustment (GtkRange *range,
- GtkAdjustment *adjustment);
-GtkAdjustment* gtk_range_get_adjustment (GtkRange *range);
-void gtk_range_set_inverted (GtkRange *range,
- gboolean setting);
-gboolean gtk_range_get_inverted (GtkRange *range);
-void gtk_range_set_increments (GtkRange *range,
- gdouble step,
- gdouble page);
-void gtk_range_set_range (GtkRange *range,
- gdouble min,
- gdouble max);
-void gtk_range_set_value (GtkRange *range,
- gdouble value);
-gdouble gtk_range_get_value (GtkRange *range);
-
-gdouble _gtk_range_get_wheel_delta (GtkRange *range,
- GdkScrollDirection direction);
+GType gtk_range_get_type (void) G_GNUC_CONST;
+
+void gtk_range_set_update_policy (GtkRange *range,
+ GtkUpdateType policy);
+GtkUpdateType gtk_range_get_update_policy (GtkRange *range);
+
+void gtk_range_set_adjustment (GtkRange *range,
+ GtkAdjustment *adjustment);
+GtkAdjustment* gtk_range_get_adjustment (GtkRange *range);
+
+void gtk_range_set_inverted (GtkRange *range,
+ gboolean setting);
+gboolean gtk_range_get_inverted (GtkRange *range);
+
+void gtk_range_set_lower_stepper_sensitivity (GtkRange *range,
+ GtkSensitivityType sensitivity);
+GtkSensitivityType gtk_range_get_lower_stepper_sensitivity (GtkRange *range);
+void gtk_range_set_upper_stepper_sensitivity (GtkRange *range,
+ GtkSensitivityType sensitivity);
+GtkSensitivityType gtk_range_get_upper_stepper_sensitivity (GtkRange *range);
+
+void gtk_range_set_increments (GtkRange *range,
+ gdouble step,
+ gdouble page);
+void gtk_range_set_range (GtkRange *range,
+ gdouble min,
+ gdouble max);
+void gtk_range_set_value (GtkRange *range,
+ gdouble value);
+gdouble gtk_range_get_value (GtkRange *range);
+
+gdouble _gtk_range_get_wheel_delta (GtkRange *range,
+ GdkScrollDirection direction);
G_END_DECLS