diff --git a/src/st/st-scroll-bar.c b/src/st/st-scroll-bar.c index 69f979277..717e7e983 100644 --- a/src/st/st-scroll-bar.c +++ b/src/st/st-scroll-bar.c @@ -66,7 +66,7 @@ struct _StScrollBarPrivate guint paging_source_id; guint paging_event_no; - guint vertical : 1; + ClutterOrientation orientation; }; G_DEFINE_TYPE_WITH_PRIVATE (StScrollBar, st_scroll_bar, ST_TYPE_WIDGET) @@ -78,6 +78,7 @@ enum PROP_0, PROP_ADJUSTMENT, + PROP_ORIENTATION, PROP_VERTICAL, N_PROPS @@ -102,24 +103,49 @@ handle_button_press_event_cb (ClutterActor *actor, static void stop_scrolling (StScrollBar *bar); -static void -st_scroll_bar_set_vertical (StScrollBar *bar, - gboolean vertical) +ClutterOrientation +st_scroll_bar_get_orientation (StScrollBar *bar) { - StScrollBarPrivate *priv = ST_SCROLL_BAR_PRIVATE (bar); + StScrollBarPrivate *priv; - if (priv->vertical == vertical) + g_return_val_if_fail (ST_IS_SCROLL_BAR (bar), CLUTTER_ORIENTATION_HORIZONTAL); + + priv = ST_SCROLL_BAR_PRIVATE (bar); + return priv->orientation; +} + +void +st_scroll_bar_set_orientation (StScrollBar *bar, + ClutterOrientation orientation) +{ + StScrollBarPrivate *priv; + + g_return_if_fail (ST_IS_SCROLL_BAR (bar)); + + priv = ST_SCROLL_BAR_PRIVATE (bar); + + if (priv->orientation == orientation) return; - priv->vertical = vertical; + priv->orientation = orientation; - if (priv->vertical) + if (priv->orientation == CLUTTER_ORIENTATION_VERTICAL) clutter_actor_set_name (CLUTTER_ACTOR (priv->handle), "vhandle"); else clutter_actor_set_name (CLUTTER_ACTOR (priv->handle), "hhandle"); clutter_actor_queue_relayout (CLUTTER_ACTOR (bar)); + g_object_notify_by_pspec (G_OBJECT (bar), props[PROP_ORIENTATION]); +} + +static void +st_scroll_bar_set_vertical (StScrollBar *bar, + gboolean vertical) +{ + st_scroll_bar_set_orientation (bar, + vertical ? CLUTTER_ORIENTATION_VERTICAL + : CLUTTER_ORIENTATION_HORIZONTAL); g_object_notify_by_pspec (G_OBJECT (bar), props[PROP_VERTICAL]); } @@ -137,8 +163,12 @@ st_scroll_bar_get_property (GObject *gobject, g_value_set_object (value, priv->adjustment); break; + case PROP_ORIENTATION: + g_value_set_enum (value, priv->orientation); + break; + case PROP_VERTICAL: - g_value_set_boolean (value, priv->vertical); + g_value_set_boolean (value, priv->orientation == CLUTTER_ORIENTATION_VERTICAL); break; default: @@ -161,6 +191,10 @@ st_scroll_bar_set_property (GObject *gobject, st_scroll_bar_set_adjustment (bar, g_value_get_object (value)); break; + case PROP_ORIENTATION: + st_scroll_bar_set_orientation (bar, g_value_get_enum (value)); + break; + case PROP_VERTICAL: st_scroll_bar_set_vertical (bar, g_value_get_boolean (value)); break; @@ -249,7 +283,7 @@ scroll_bar_allocate_children (StScrollBar *bar, else position = (value - lower) / (upper - lower - page_size); - if (priv->vertical) + if (priv->orientation == CLUTTER_ORIENTATION_VERTICAL) { avail_size = content_box.y2 - content_box.y1; handle_size = increment * avail_size; @@ -309,7 +343,7 @@ st_scroll_bar_get_preferred_width (ClutterActor *self, _st_actor_get_preferred_width (priv->handle, for_height, TRUE, &handle_min_width, &handle_natural_width); - if (priv->vertical) + if (priv->orientation == CLUTTER_ORIENTATION_VERTICAL) { if (min_width_p) *min_width_p = MAX (trough_min_width, handle_min_width); @@ -349,7 +383,7 @@ st_scroll_bar_get_preferred_height (ClutterActor *self, _st_actor_get_preferred_height (priv->handle, for_width, TRUE, &handle_min_height, &handle_natural_height); - if (priv->vertical) + if (priv->orientation == CLUTTER_ORIENTATION_VERTICAL) { if (min_height_p) *min_height_p = trough_min_height + handle_min_height; @@ -485,7 +519,7 @@ st_scroll_bar_scroll_event (ClutterActor *actor, if (direction == CLUTTER_TEXT_DIRECTION_RTL) delta_x *= -1; - if (priv->vertical) + if (priv->orientation == CLUTTER_ORIENTATION_VERTICAL) st_adjustment_adjust_for_scroll_event (priv->adjustment, delta_y); else st_adjustment_adjust_for_scroll_event (priv->adjustment, delta_x); @@ -536,6 +570,17 @@ st_scroll_bar_class_init (StScrollBarClass *klass) ST_TYPE_ADJUSTMENT, ST_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY); + /** + * StScrollBar:orientation: + * + * The orientation of the #StScrollBar, horizontal or vertical. + */ + props[PROP_ORIENTATION] = + g_param_spec_enum ("orientation", NULL, NULL, + CLUTTER_TYPE_ORIENTATION, + CLUTTER_ORIENTATION_HORIZONTAL, + ST_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY); + /** * StScrollBar:vertical: * @@ -585,6 +630,7 @@ move_slider (StScrollBar *bar, { StScrollBarPrivate *priv = st_scroll_bar_get_instance_private (bar); ClutterTextDirection direction; + gboolean vertical; gdouble position, lower, upper, page_size; gfloat ux, uy, pos, size; @@ -594,7 +640,9 @@ move_slider (StScrollBar *bar, if (!clutter_actor_transform_stage_point (priv->trough, x, y, &ux, &uy)) return; - if (priv->vertical) + vertical = priv->orientation == CLUTTER_ORIENTATION_VERTICAL; + + if (vertical) size = clutter_actor_get_height (priv->trough) - clutter_actor_get_height (priv->handle); else @@ -604,7 +652,7 @@ move_slider (StScrollBar *bar, if (size == 0) return; - if (priv->vertical) + if (vertical) pos = uy - priv->y_origin; else pos = ux - priv->x_origin; @@ -619,7 +667,7 @@ move_slider (StScrollBar *bar, &page_size); direction = clutter_actor_get_text_direction (CLUTTER_ACTOR (bar)); - if (!priv->vertical && direction == CLUTTER_TEXT_DIRECTION_RTL) + if (!vertical && direction == CLUTTER_TEXT_DIRECTION_RTL) pos = size - pos; position = ((pos / size) @@ -719,6 +767,7 @@ trough_paging_cb (StScrollBar *self) { StScrollBarPrivate *priv = st_scroll_bar_get_instance_private (self); ClutterTextDirection direction; + gboolean vertical; g_autoptr (ClutterTransition) transition = NULL; StSettings *settings; gfloat handle_pos, event_pos, tx, ty; @@ -729,6 +778,8 @@ trough_paging_cb (StScrollBar *self) gulong mode; + vertical = priv->orientation == CLUTTER_ORIENTATION_VERTICAL; + if (priv->paging_event_no == 0) { /* Scroll on after initial timeout. */ @@ -766,7 +817,7 @@ trough_paging_cb (StScrollBar *self) &value, NULL, NULL, NULL, &page_increment, NULL); - if (priv->vertical) + if (vertical) handle_pos = clutter_actor_get_y (priv->handle); else handle_pos = clutter_actor_get_x (priv->handle); @@ -777,10 +828,10 @@ trough_paging_cb (StScrollBar *self) &tx, &ty); direction = clutter_actor_get_text_direction (CLUTTER_ACTOR (self)); - if (!priv->vertical && direction == CLUTTER_TEXT_DIRECTION_RTL) + if (!vertical && direction == CLUTTER_TEXT_DIRECTION_RTL) page_increment *= -1; - if (priv->vertical) + if (vertical) event_pos = ty; else event_pos = tx; diff --git a/src/st/st-scroll-bar.h b/src/st/st-scroll-bar.h index 6360c5afe..dae022277 100644 --- a/src/st/st-scroll-bar.h +++ b/src/st/st-scroll-bar.h @@ -47,4 +47,8 @@ void st_scroll_bar_set_adjustment (StScrollBar *bar, StAdjustment *adjustment); StAdjustment *st_scroll_bar_get_adjustment (StScrollBar *bar); +void st_scroll_bar_set_orientation (StScrollBar *bar, + ClutterOrientation orientation); +ClutterOrientation st_scroll_bar_get_orientation (StScrollBar *bar); + G_END_DECLS