2009-09-29 19:08:01 +00:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
2009-09-10 03:13:35 +00:00
|
|
|
/*
|
|
|
|
* st-scroll-bar.c: Scroll bar actor
|
|
|
|
*
|
|
|
|
* Copyright 2008 OpenedHand
|
2010-11-10 22:00:45 +00:00
|
|
|
* Copyright 2008, 2009 Intel Corporation.
|
|
|
|
* Copyright 2009, 2010 Red Hat, Inc.
|
|
|
|
* Copyright 2010 Maxim Ermilov
|
2009-09-10 03:13:35 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU Lesser General Public License,
|
|
|
|
* version 2.1, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT ANY
|
|
|
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
2010-11-10 22:00:45 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-09-10 03:13:35 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:st-scroll-bar
|
|
|
|
* @short_description: a user interface element to control scrollable areas.
|
|
|
|
*
|
|
|
|
* The #StScrollBar allows users to scroll scrollable actors, either by
|
|
|
|
* the step or page amount, or by manually dragging the handle.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2012-03-19 20:30:09 +00:00
|
|
|
#include <math.h>
|
2009-09-10 03:13:35 +00:00
|
|
|
#include <clutter/clutter.h>
|
|
|
|
|
|
|
|
#include "st-scroll-bar.h"
|
|
|
|
#include "st-bin.h"
|
|
|
|
#include "st-enum-types.h"
|
|
|
|
#include "st-private.h"
|
|
|
|
#include "st-button.h"
|
2019-07-25 10:50:26 +00:00
|
|
|
#include "st-settings.h"
|
2009-09-10 03:13:35 +00:00
|
|
|
|
|
|
|
#define PAGING_INITIAL_REPEAT_TIMEOUT 500
|
|
|
|
#define PAGING_SUBSEQUENT_REPEAT_TIMEOUT 200
|
|
|
|
|
2015-09-24 14:08:13 +00:00
|
|
|
typedef struct _StScrollBarPrivate StScrollBarPrivate;
|
2009-09-10 03:13:35 +00:00
|
|
|
struct _StScrollBarPrivate
|
|
|
|
{
|
|
|
|
StAdjustment *adjustment;
|
|
|
|
|
|
|
|
gfloat x_origin;
|
|
|
|
gfloat y_origin;
|
|
|
|
|
2019-04-14 16:32:37 +00:00
|
|
|
ClutterInputDevice *grab_device;
|
|
|
|
|
2009-09-10 03:13:35 +00:00
|
|
|
ClutterActor *trough;
|
|
|
|
ClutterActor *handle;
|
|
|
|
|
|
|
|
gfloat move_x;
|
|
|
|
gfloat move_y;
|
|
|
|
|
|
|
|
/* Trough-click handling. */
|
|
|
|
enum { NONE, UP, DOWN } paging_direction;
|
|
|
|
guint paging_source_id;
|
|
|
|
guint paging_event_no;
|
|
|
|
|
2015-09-26 03:20:04 +00:00
|
|
|
ClutterTransition *paging_animation;
|
2009-09-10 03:13:35 +00:00
|
|
|
|
2010-03-05 21:17:07 +00:00
|
|
|
guint vertical : 1;
|
2009-09-10 03:13:35 +00:00
|
|
|
};
|
|
|
|
|
2015-09-24 16:04:48 +00:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (StScrollBar, st_scroll_bar, ST_TYPE_WIDGET)
|
|
|
|
|
2015-09-24 14:08:13 +00:00
|
|
|
#define ST_SCROLL_BAR_PRIVATE(sb) st_scroll_bar_get_instance_private (ST_SCROLL_BAR (sb))
|
|
|
|
|
2009-09-10 03:13:35 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
|
|
|
|
PROP_ADJUSTMENT,
|
2019-07-29 15:59:41 +00:00
|
|
|
PROP_VERTICAL,
|
|
|
|
|
|
|
|
N_PROPS
|
2009-09-10 03:13:35 +00:00
|
|
|
};
|
|
|
|
|
2019-07-29 15:59:41 +00:00
|
|
|
static GParamSpec *props[N_PROPS] = { NULL, };
|
|
|
|
|
2009-09-10 03:13:35 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
SCROLL_START,
|
|
|
|
SCROLL_STOP,
|
|
|
|
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint signals[LAST_SIGNAL] = { 0, };
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
handle_button_press_event_cb (ClutterActor *actor,
|
|
|
|
ClutterButtonEvent *event,
|
|
|
|
StScrollBar *bar);
|
|
|
|
|
2011-04-05 14:54:28 +00:00
|
|
|
static void stop_scrolling (StScrollBar *bar);
|
|
|
|
|
2009-09-10 03:13:35 +00:00
|
|
|
static void
|
|
|
|
st_scroll_bar_get_property (GObject *gobject,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2015-09-24 14:08:13 +00:00
|
|
|
StScrollBarPrivate *priv = ST_SCROLL_BAR_PRIVATE (gobject);
|
2009-09-10 03:13:35 +00:00
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_ADJUSTMENT:
|
|
|
|
g_value_set_object (value, priv->adjustment);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_VERTICAL:
|
|
|
|
g_value_set_boolean (value, priv->vertical);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
st_scroll_bar_set_property (GObject *gobject,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
StScrollBar *bar = ST_SCROLL_BAR (gobject);
|
2015-09-24 14:08:13 +00:00
|
|
|
StScrollBarPrivate *priv = st_scroll_bar_get_instance_private (bar);
|
2009-09-10 03:13:35 +00:00
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_ADJUSTMENT:
|
|
|
|
st_scroll_bar_set_adjustment (bar, g_value_get_object (value));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_VERTICAL:
|
2015-09-24 14:08:13 +00:00
|
|
|
priv->vertical = g_value_get_boolean (value);
|
|
|
|
if (priv->vertical)
|
|
|
|
clutter_actor_set_name (CLUTTER_ACTOR (priv->handle),
|
2012-02-14 04:13:26 +00:00
|
|
|
"vhandle");
|
2009-09-10 03:13:35 +00:00
|
|
|
else
|
2015-09-24 14:08:13 +00:00
|
|
|
clutter_actor_set_name (CLUTTER_ACTOR (priv->handle),
|
2012-02-14 04:13:26 +00:00
|
|
|
"hhandle");
|
2009-09-10 03:13:35 +00:00
|
|
|
clutter_actor_queue_relayout ((ClutterActor*) gobject);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
st_scroll_bar_dispose (GObject *gobject)
|
|
|
|
{
|
|
|
|
StScrollBar *bar = ST_SCROLL_BAR (gobject);
|
2015-09-24 14:08:13 +00:00
|
|
|
StScrollBarPrivate *priv = st_scroll_bar_get_instance_private (bar);
|
2009-09-10 03:13:35 +00:00
|
|
|
|
|
|
|
if (priv->adjustment)
|
|
|
|
st_scroll_bar_set_adjustment (bar, NULL);
|
|
|
|
|
|
|
|
if (priv->handle)
|
|
|
|
{
|
2012-02-14 15:48:00 +00:00
|
|
|
clutter_actor_destroy (priv->handle);
|
2009-09-10 03:13:35 +00:00
|
|
|
priv->handle = NULL;
|
|
|
|
}
|
|
|
|
|
2010-02-26 17:48:07 +00:00
|
|
|
if (priv->trough)
|
|
|
|
{
|
2012-02-14 15:48:00 +00:00
|
|
|
clutter_actor_destroy (priv->trough);
|
2010-02-26 17:48:07 +00:00
|
|
|
priv->trough = NULL;
|
|
|
|
}
|
2009-09-10 03:13:35 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (st_scroll_bar_parent_class)->dispose (gobject);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
st_scroll_bar_unmap (ClutterActor *actor)
|
|
|
|
{
|
|
|
|
CLUTTER_ACTOR_CLASS (st_scroll_bar_parent_class)->unmap (actor);
|
|
|
|
|
2011-04-05 14:54:28 +00:00
|
|
|
stop_scrolling (ST_SCROLL_BAR (actor));
|
2009-09-10 03:13:35 +00:00
|
|
|
}
|
|
|
|
|
2010-03-05 21:17:07 +00:00
|
|
|
static void
|
|
|
|
scroll_bar_allocate_children (StScrollBar *bar,
|
|
|
|
const ClutterActorBox *box,
|
|
|
|
ClutterAllocationFlags flags)
|
|
|
|
{
|
2015-09-24 14:08:13 +00:00
|
|
|
StScrollBarPrivate *priv = st_scroll_bar_get_instance_private (bar);
|
2010-03-05 21:17:07 +00:00
|
|
|
StThemeNode *theme_node = st_widget_get_theme_node (ST_WIDGET (bar));
|
2012-02-14 04:13:26 +00:00
|
|
|
ClutterActorBox content_box, trough_box;
|
2009-09-10 03:13:35 +00:00
|
|
|
|
2009-09-20 17:41:13 +00:00
|
|
|
st_theme_node_get_content_box (theme_node, box, &content_box);
|
2009-09-10 03:13:35 +00:00
|
|
|
|
|
|
|
if (priv->vertical)
|
|
|
|
{
|
2009-09-20 17:41:13 +00:00
|
|
|
trough_box.x1 = content_box.x1;
|
2012-02-14 04:13:26 +00:00
|
|
|
trough_box.y1 = content_box.y1;
|
2009-09-20 17:41:13 +00:00
|
|
|
trough_box.x2 = content_box.x2;
|
2012-02-14 04:13:26 +00:00
|
|
|
trough_box.y2 = content_box.y2;
|
2009-09-10 03:13:35 +00:00
|
|
|
clutter_actor_allocate (priv->trough, &trough_box, flags);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-02-14 04:13:26 +00:00
|
|
|
trough_box.x1 = content_box.x1;
|
2009-09-20 17:41:13 +00:00
|
|
|
trough_box.y1 = content_box.y1;
|
2012-02-14 04:13:26 +00:00
|
|
|
trough_box.x2 = content_box.x2;
|
2009-09-20 17:41:13 +00:00
|
|
|
trough_box.y2 = content_box.y2;
|
2009-09-10 03:13:35 +00:00
|
|
|
clutter_actor_allocate (priv->trough, &trough_box, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (priv->adjustment)
|
|
|
|
{
|
2012-02-14 04:13:26 +00:00
|
|
|
float handle_size, position, avail_size;
|
2009-09-20 01:10:15 +00:00
|
|
|
gdouble value, lower, upper, page_size, increment, min_size, max_size;
|
2009-09-10 03:13:35 +00:00
|
|
|
ClutterActorBox handle_box = { 0, };
|
|
|
|
|
|
|
|
st_adjustment_get_values (priv->adjustment,
|
|
|
|
&value,
|
|
|
|
&lower,
|
|
|
|
&upper,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
&page_size);
|
|
|
|
|
|
|
|
if ((upper == lower)
|
|
|
|
|| (page_size >= (upper - lower)))
|
|
|
|
increment = 1.0;
|
|
|
|
else
|
|
|
|
increment = page_size / (upper - lower);
|
|
|
|
|
2009-09-20 01:10:15 +00:00
|
|
|
min_size = 32.;
|
StThemeNode: simplify use of get_color/get_double/get_length
Although within St itself there are situations where the semantics of
these functions (return TRUE or FALSE and return the actual value in
an out parameter) is useful, it's mostly just annoying at the
application level, where you generally know that the CSS property is
going to specified, and there is no especially sane fallback if it's
not.
So rename the current methods to lookup_color, lookup_double, and
lookup_length, and add new get_color, get_double, and get_length
methods that don't take an "inherit" parameter, and return their
values directly. (Well, except for get_color, due to the lack of (out
caller-allocates) in gjs.)
And update the code to use either the old or new methods as appropriate.
https://bugzilla.gnome.org/show_bug.cgi?id=632590
2010-09-26 21:38:36 +00:00
|
|
|
st_theme_node_lookup_length (theme_node, "min-size", FALSE, &min_size);
|
2009-09-20 01:10:15 +00:00
|
|
|
max_size = G_MAXINT16;
|
StThemeNode: simplify use of get_color/get_double/get_length
Although within St itself there are situations where the semantics of
these functions (return TRUE or FALSE and return the actual value in
an out parameter) is useful, it's mostly just annoying at the
application level, where you generally know that the CSS property is
going to specified, and there is no especially sane fallback if it's
not.
So rename the current methods to lookup_color, lookup_double, and
lookup_length, and add new get_color, get_double, and get_length
methods that don't take an "inherit" parameter, and return their
values directly. (Well, except for get_color, due to the lack of (out
caller-allocates) in gjs.)
And update the code to use either the old or new methods as appropriate.
https://bugzilla.gnome.org/show_bug.cgi?id=632590
2010-09-26 21:38:36 +00:00
|
|
|
st_theme_node_lookup_length (theme_node, "max-size", FALSE, &max_size);
|
2009-09-10 03:13:35 +00:00
|
|
|
|
|
|
|
if (upper - lower - page_size <= 0)
|
|
|
|
position = 0;
|
|
|
|
else
|
|
|
|
position = (value - lower) / (upper - lower - page_size);
|
|
|
|
|
|
|
|
if (priv->vertical)
|
|
|
|
{
|
2012-02-14 04:13:26 +00:00
|
|
|
avail_size = content_box.y2 - content_box.y1;
|
2009-09-10 03:13:35 +00:00
|
|
|
handle_size = increment * avail_size;
|
|
|
|
handle_size = CLAMP (handle_size, min_size, max_size);
|
|
|
|
|
2009-09-20 17:41:13 +00:00
|
|
|
handle_box.x1 = content_box.x1;
|
2012-02-14 04:13:26 +00:00
|
|
|
handle_box.y1 = content_box.y1 + position * (avail_size - handle_size);
|
2009-09-10 03:13:35 +00:00
|
|
|
|
2009-09-20 17:41:13 +00:00
|
|
|
handle_box.x2 = content_box.x2;
|
2009-09-10 03:13:35 +00:00
|
|
|
handle_box.y2 = handle_box.y1 + handle_size;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-02-14 04:13:26 +00:00
|
|
|
avail_size = content_box.x2 - content_box.x1;
|
2009-09-10 03:13:35 +00:00
|
|
|
handle_size = increment * avail_size;
|
|
|
|
handle_size = CLAMP (handle_size, min_size, max_size);
|
|
|
|
|
2012-02-14 04:13:26 +00:00
|
|
|
handle_box.x1 = content_box.x1 + position * (avail_size - handle_size);
|
2009-09-20 17:41:13 +00:00
|
|
|
handle_box.y1 = content_box.y1;
|
2009-09-10 03:13:35 +00:00
|
|
|
|
|
|
|
handle_box.x2 = handle_box.x1 + handle_size;
|
2009-09-20 17:41:13 +00:00
|
|
|
handle_box.y2 = content_box.y2;
|
2009-09-10 03:13:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
clutter_actor_allocate (priv->handle,
|
|
|
|
&handle_box,
|
|
|
|
flags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-09 08:48:49 +00:00
|
|
|
static void
|
|
|
|
st_scroll_bar_get_preferred_width (ClutterActor *self,
|
|
|
|
gfloat for_height,
|
|
|
|
gfloat *min_width_p,
|
|
|
|
gfloat *natural_width_p)
|
|
|
|
{
|
|
|
|
StScrollBar *bar = ST_SCROLL_BAR (self);
|
2015-09-24 14:08:13 +00:00
|
|
|
StScrollBarPrivate *priv = st_scroll_bar_get_instance_private (bar);
|
2010-09-09 08:48:49 +00:00
|
|
|
StThemeNode *theme_node = st_widget_get_theme_node (ST_WIDGET (self));
|
2012-02-14 04:18:36 +00:00
|
|
|
gfloat trough_min_width, trough_natural_width;
|
|
|
|
gfloat handle_min_width, handle_natural_width;
|
2010-09-09 08:48:49 +00:00
|
|
|
|
|
|
|
st_theme_node_adjust_for_height (theme_node, &for_height);
|
|
|
|
|
2012-02-14 04:18:36 +00:00
|
|
|
_st_actor_get_preferred_width (priv->trough, for_height, TRUE,
|
|
|
|
&trough_min_width, &trough_natural_width);
|
|
|
|
|
|
|
|
_st_actor_get_preferred_width (priv->handle, for_height, TRUE,
|
|
|
|
&handle_min_width, &handle_natural_width);
|
2010-09-09 08:48:49 +00:00
|
|
|
|
|
|
|
if (priv->vertical)
|
|
|
|
{
|
2012-02-14 04:18:36 +00:00
|
|
|
if (min_width_p)
|
|
|
|
*min_width_p = MAX (trough_min_width, handle_min_width);
|
2010-09-09 08:48:49 +00:00
|
|
|
|
2012-02-14 04:18:36 +00:00
|
|
|
if (natural_width_p)
|
|
|
|
*natural_width_p = MAX (trough_natural_width, handle_natural_width);
|
2010-09-09 08:48:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-02-14 04:18:36 +00:00
|
|
|
if (min_width_p)
|
|
|
|
*min_width_p = trough_min_width + handle_min_width;
|
2010-09-09 08:48:49 +00:00
|
|
|
|
2012-02-14 04:18:36 +00:00
|
|
|
if (natural_width_p)
|
|
|
|
*natural_width_p = trough_natural_width + handle_natural_width;
|
2010-09-09 08:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
st_theme_node_adjust_preferred_width (theme_node, min_width_p, natural_width_p);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
st_scroll_bar_get_preferred_height (ClutterActor *self,
|
|
|
|
gfloat for_width,
|
|
|
|
gfloat *min_height_p,
|
|
|
|
gfloat *natural_height_p)
|
|
|
|
{
|
|
|
|
StScrollBar *bar = ST_SCROLL_BAR (self);
|
2015-09-24 14:08:13 +00:00
|
|
|
StScrollBarPrivate *priv = st_scroll_bar_get_instance_private (bar);
|
2010-09-09 08:48:49 +00:00
|
|
|
StThemeNode *theme_node = st_widget_get_theme_node (ST_WIDGET (self));
|
2012-02-14 04:18:36 +00:00
|
|
|
gfloat trough_min_height, trough_natural_height;
|
|
|
|
gfloat handle_min_height, handle_natural_height;
|
2010-09-09 08:48:49 +00:00
|
|
|
|
|
|
|
st_theme_node_adjust_for_width (theme_node, &for_width);
|
|
|
|
|
2012-02-14 04:18:36 +00:00
|
|
|
_st_actor_get_preferred_height (priv->trough, for_width, TRUE,
|
|
|
|
&trough_min_height, &trough_natural_height);
|
|
|
|
|
|
|
|
_st_actor_get_preferred_height (priv->handle, for_width, TRUE,
|
|
|
|
&handle_min_height, &handle_natural_height);
|
2010-09-09 08:48:49 +00:00
|
|
|
|
|
|
|
if (priv->vertical)
|
|
|
|
{
|
2012-02-14 04:18:36 +00:00
|
|
|
if (min_height_p)
|
|
|
|
*min_height_p = trough_min_height + handle_min_height;
|
2010-09-09 08:48:49 +00:00
|
|
|
|
2012-02-14 04:18:36 +00:00
|
|
|
if (natural_height_p)
|
|
|
|
*natural_height_p = trough_natural_height + handle_natural_height;
|
2010-09-09 08:48:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-02-14 04:18:36 +00:00
|
|
|
if (min_height_p)
|
|
|
|
*min_height_p = MAX (trough_min_height, handle_min_height);
|
2010-09-09 08:48:49 +00:00
|
|
|
|
2012-02-14 04:18:36 +00:00
|
|
|
if (natural_height_p)
|
|
|
|
*natural_height_p = MAX (trough_natural_height, handle_natural_height);
|
2010-09-09 08:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
st_theme_node_adjust_preferred_height (theme_node, min_height_p, natural_height_p);
|
|
|
|
}
|
|
|
|
|
2010-03-05 21:17:07 +00:00
|
|
|
static void
|
|
|
|
st_scroll_bar_allocate (ClutterActor *actor,
|
|
|
|
const ClutterActorBox *box,
|
|
|
|
ClutterAllocationFlags flags)
|
|
|
|
{
|
|
|
|
StScrollBar *bar = ST_SCROLL_BAR (actor);
|
|
|
|
|
2012-02-15 12:11:41 +00:00
|
|
|
clutter_actor_set_allocation (actor, box, flags);
|
2010-03-05 21:17:07 +00:00
|
|
|
|
|
|
|
scroll_bar_allocate_children (bar, box, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
scroll_bar_update_positions (StScrollBar *bar)
|
|
|
|
{
|
|
|
|
ClutterActorBox box;
|
|
|
|
|
|
|
|
/* Due to a change in the adjustments, we need to reposition our
|
|
|
|
* children; since adjustments changes can come from allocation
|
|
|
|
* changes in the scrolled area, we can't just queue a new relayout -
|
|
|
|
* we may already be in a relayout cycle. On the other hand, if
|
|
|
|
* a relayout is already queued, we can't just go ahead and allocate
|
|
|
|
* our children, since we don't have a valid allocation, and calling
|
|
|
|
* clutter_actor_get_allocation_box() will trigger an immediate
|
|
|
|
* stage relayout. So what we do is go ahead and immediately
|
|
|
|
* allocate our children if we already have a valid allocation, and
|
|
|
|
* otherwise just wait for the queued relayout.
|
|
|
|
*/
|
2011-04-05 14:49:21 +00:00
|
|
|
if (!clutter_actor_has_allocation (CLUTTER_ACTOR (bar)))
|
2010-03-05 21:17:07 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
clutter_actor_get_allocation_box (CLUTTER_ACTOR (bar), &box);
|
|
|
|
scroll_bar_allocate_children (bar, &box, CLUTTER_ALLOCATION_NONE);
|
|
|
|
}
|
|
|
|
|
2009-09-10 03:13:35 +00:00
|
|
|
static void
|
|
|
|
st_scroll_bar_style_changed (StWidget *widget)
|
|
|
|
{
|
2015-09-24 14:08:13 +00:00
|
|
|
StScrollBarPrivate *priv = ST_SCROLL_BAR_PRIVATE (widget);
|
2009-09-10 03:13:35 +00:00
|
|
|
|
2009-09-20 01:10:15 +00:00
|
|
|
st_widget_style_changed (ST_WIDGET (priv->trough));
|
|
|
|
st_widget_style_changed (ST_WIDGET (priv->handle));
|
2009-09-10 03:13:35 +00:00
|
|
|
|
2009-09-20 01:10:15 +00:00
|
|
|
ST_WIDGET_CLASS (st_scroll_bar_parent_class)->style_changed (widget);
|
2009-09-10 03:13:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bar_reactive_notify_cb (GObject *gobject,
|
|
|
|
GParamSpec *arg1,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
StScrollBar *bar = ST_SCROLL_BAR (gobject);
|
2015-09-24 14:08:13 +00:00
|
|
|
StScrollBarPrivate *priv = st_scroll_bar_get_instance_private (bar);
|
2009-09-10 03:13:35 +00:00
|
|
|
|
2015-09-24 14:08:13 +00:00
|
|
|
clutter_actor_set_reactive (priv->handle,
|
2009-09-10 03:13:35 +00:00
|
|
|
clutter_actor_get_reactive (CLUTTER_ACTOR (bar)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static GObject*
|
|
|
|
st_scroll_bar_constructor (GType type,
|
|
|
|
guint n_properties,
|
|
|
|
GObjectConstructParam *properties)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GObject *obj;
|
|
|
|
StScrollBar *bar;
|
|
|
|
|
|
|
|
gobject_class = G_OBJECT_CLASS (st_scroll_bar_parent_class);
|
|
|
|
obj = gobject_class->constructor (type, n_properties, properties);
|
|
|
|
|
|
|
|
bar = ST_SCROLL_BAR (obj);
|
|
|
|
|
|
|
|
g_signal_connect (bar, "notify::reactive",
|
|
|
|
G_CALLBACK (bar_reactive_notify_cb), NULL);
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2012-11-28 22:27:41 +00:00
|
|
|
static void
|
|
|
|
adjust_with_direction (StAdjustment *adj,
|
|
|
|
ClutterScrollDirection direction)
|
|
|
|
{
|
|
|
|
gdouble delta;
|
|
|
|
|
|
|
|
switch (direction)
|
|
|
|
{
|
|
|
|
case CLUTTER_SCROLL_UP:
|
|
|
|
case CLUTTER_SCROLL_LEFT:
|
|
|
|
delta = -1.0;
|
|
|
|
break;
|
|
|
|
case CLUTTER_SCROLL_RIGHT:
|
|
|
|
case CLUTTER_SCROLL_DOWN:
|
|
|
|
delta = 1.0;
|
|
|
|
break;
|
|
|
|
case CLUTTER_SCROLL_SMOOTH:
|
2015-09-22 16:47:25 +00:00
|
|
|
default:
|
2012-11-28 22:27:41 +00:00
|
|
|
g_assert_not_reached ();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
st_adjustment_adjust_for_scroll_event (adj, delta);
|
|
|
|
}
|
|
|
|
|
2009-09-10 03:13:35 +00:00
|
|
|
static gboolean
|
|
|
|
st_scroll_bar_scroll_event (ClutterActor *actor,
|
|
|
|
ClutterScrollEvent *event)
|
|
|
|
{
|
2015-09-24 14:08:13 +00:00
|
|
|
StScrollBarPrivate *priv = ST_SCROLL_BAR_PRIVATE (actor);
|
2009-09-10 03:13:35 +00:00
|
|
|
|
2012-11-28 22:27:41 +00:00
|
|
|
if (clutter_event_is_pointer_emulated ((ClutterEvent *) event))
|
|
|
|
return TRUE;
|
2009-09-10 03:13:35 +00:00
|
|
|
|
|
|
|
switch (event->direction)
|
|
|
|
{
|
2012-03-19 20:30:09 +00:00
|
|
|
case CLUTTER_SCROLL_SMOOTH:
|
2012-11-28 22:27:41 +00:00
|
|
|
{
|
|
|
|
gdouble delta_x, delta_y;
|
|
|
|
clutter_event_get_scroll_delta ((ClutterEvent *)event, &delta_x, &delta_y);
|
|
|
|
|
|
|
|
if (priv->vertical)
|
|
|
|
st_adjustment_adjust_for_scroll_event (priv->adjustment, delta_y);
|
|
|
|
else
|
|
|
|
st_adjustment_adjust_for_scroll_event (priv->adjustment, delta_x);
|
|
|
|
}
|
2012-03-19 20:30:09 +00:00
|
|
|
break;
|
2009-09-10 03:13:35 +00:00
|
|
|
case CLUTTER_SCROLL_UP:
|
|
|
|
case CLUTTER_SCROLL_DOWN:
|
2012-11-28 22:27:41 +00:00
|
|
|
case CLUTTER_SCROLL_LEFT:
|
2009-09-10 03:13:35 +00:00
|
|
|
case CLUTTER_SCROLL_RIGHT:
|
2012-11-28 22:27:41 +00:00
|
|
|
adjust_with_direction (priv->adjustment, event->direction);
|
2009-09-10 03:13:35 +00:00
|
|
|
break;
|
2015-09-22 16:47:25 +00:00
|
|
|
default:
|
|
|
|
g_return_val_if_reached (FALSE);
|
|
|
|
break;
|
2009-09-10 03:13:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
st_scroll_bar_class_init (StScrollBarClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
|
2009-09-20 01:10:15 +00:00
|
|
|
StWidgetClass *widget_class = ST_WIDGET_CLASS (klass);
|
2009-09-10 03:13:35 +00:00
|
|
|
|
|
|
|
object_class->get_property = st_scroll_bar_get_property;
|
|
|
|
object_class->set_property = st_scroll_bar_set_property;
|
|
|
|
object_class->dispose = st_scroll_bar_dispose;
|
|
|
|
object_class->constructor = st_scroll_bar_constructor;
|
|
|
|
|
2010-09-09 08:48:49 +00:00
|
|
|
actor_class->get_preferred_width = st_scroll_bar_get_preferred_width;
|
|
|
|
actor_class->get_preferred_height = st_scroll_bar_get_preferred_height;
|
2009-09-10 03:13:35 +00:00
|
|
|
actor_class->allocate = st_scroll_bar_allocate;
|
|
|
|
actor_class->scroll_event = st_scroll_bar_scroll_event;
|
|
|
|
actor_class->unmap = st_scroll_bar_unmap;
|
|
|
|
|
2009-09-20 01:10:15 +00:00
|
|
|
widget_class->style_changed = st_scroll_bar_style_changed;
|
|
|
|
|
2019-07-29 15:59:41 +00:00
|
|
|
props[PROP_ADJUSTMENT] =
|
|
|
|
g_param_spec_object ("adjustment", "Adjustment", "The adjustment",
|
|
|
|
ST_TYPE_ADJUSTMENT,
|
|
|
|
ST_PARAM_READWRITE);
|
|
|
|
|
|
|
|
props[PROP_VERTICAL] =
|
|
|
|
g_param_spec_boolean ("vertical",
|
|
|
|
"Vertical Orientation",
|
|
|
|
"Vertical Orientation",
|
|
|
|
FALSE,
|
|
|
|
ST_PARAM_READWRITE);
|
|
|
|
|
|
|
|
g_object_class_install_properties (object_class, N_PROPS, props);
|
2009-09-10 03:13:35 +00:00
|
|
|
|
|
|
|
signals[SCROLL_START] =
|
|
|
|
g_signal_new ("scroll-start",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (StScrollBarClass, scroll_start),
|
2011-10-18 22:17:49 +00:00
|
|
|
NULL, NULL, NULL,
|
2009-09-10 03:13:35 +00:00
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
|
|
|
signals[SCROLL_STOP] =
|
|
|
|
g_signal_new ("scroll-stop",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (StScrollBarClass, scroll_stop),
|
2011-10-18 22:17:49 +00:00
|
|
|
NULL, NULL, NULL,
|
2009-09-10 03:13:35 +00:00
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
move_slider (StScrollBar *bar,
|
|
|
|
gfloat x,
|
|
|
|
gfloat y)
|
|
|
|
{
|
2015-09-24 14:08:13 +00:00
|
|
|
StScrollBarPrivate *priv = st_scroll_bar_get_instance_private (bar);
|
2009-09-10 03:13:35 +00:00
|
|
|
gdouble position, lower, upper, page_size;
|
|
|
|
gfloat ux, uy, pos, size;
|
|
|
|
|
|
|
|
if (!priv->adjustment)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!clutter_actor_transform_stage_point (priv->trough, x, y, &ux, &uy))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (priv->vertical)
|
|
|
|
size = clutter_actor_get_height (priv->trough)
|
|
|
|
- clutter_actor_get_height (priv->handle);
|
|
|
|
else
|
|
|
|
size = clutter_actor_get_width (priv->trough)
|
|
|
|
- clutter_actor_get_width (priv->handle);
|
|
|
|
|
|
|
|
if (size == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (priv->vertical)
|
|
|
|
pos = uy - priv->y_origin;
|
|
|
|
else
|
|
|
|
pos = ux - priv->x_origin;
|
|
|
|
pos = CLAMP (pos, 0, size);
|
|
|
|
|
|
|
|
st_adjustment_get_values (priv->adjustment,
|
|
|
|
NULL,
|
|
|
|
&lower,
|
|
|
|
&upper,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
&page_size);
|
|
|
|
|
|
|
|
position = ((pos / size)
|
|
|
|
* (upper - lower - page_size))
|
|
|
|
+ lower;
|
|
|
|
|
|
|
|
st_adjustment_set_value (priv->adjustment, position);
|
|
|
|
}
|
|
|
|
|
2011-04-05 14:54:28 +00:00
|
|
|
static void
|
|
|
|
stop_scrolling (StScrollBar *bar)
|
|
|
|
{
|
2015-09-24 14:08:13 +00:00
|
|
|
StScrollBarPrivate *priv = st_scroll_bar_get_instance_private (bar);
|
2019-04-14 16:32:37 +00:00
|
|
|
if (!priv->grab_device)
|
2011-04-05 14:54:28 +00:00
|
|
|
return;
|
|
|
|
|
2015-09-24 14:08:13 +00:00
|
|
|
st_widget_remove_style_pseudo_class (ST_WIDGET (priv->handle), "active");
|
2012-08-01 12:15:03 +00:00
|
|
|
|
2019-04-14 16:32:37 +00:00
|
|
|
clutter_input_device_ungrab (priv->grab_device);
|
|
|
|
priv->grab_device = NULL;
|
2011-04-05 14:54:28 +00:00
|
|
|
g_signal_emit (bar, signals[SCROLL_STOP], 0);
|
|
|
|
}
|
|
|
|
|
2009-09-10 03:13:35 +00:00
|
|
|
static gboolean
|
2011-10-28 21:32:32 +00:00
|
|
|
handle_motion_event_cb (ClutterActor *trough,
|
|
|
|
ClutterMotionEvent *event,
|
|
|
|
StScrollBar *bar)
|
2009-09-10 03:13:35 +00:00
|
|
|
{
|
2015-09-24 14:08:13 +00:00
|
|
|
StScrollBarPrivate *priv = st_scroll_bar_get_instance_private (bar);
|
2019-04-14 16:32:37 +00:00
|
|
|
if (!priv->grab_device)
|
2011-10-28 21:32:32 +00:00
|
|
|
return FALSE;
|
2009-09-10 03:13:35 +00:00
|
|
|
|
2011-10-28 21:32:32 +00:00
|
|
|
move_slider (bar, event->x, event->y);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
handle_button_release_event_cb (ClutterActor *trough,
|
|
|
|
ClutterButtonEvent *event,
|
|
|
|
StScrollBar *bar)
|
|
|
|
{
|
|
|
|
if (event->button != 1)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
stop_scrolling (bar);
|
2009-09-10 03:13:35 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
handle_button_press_event_cb (ClutterActor *actor,
|
|
|
|
ClutterButtonEvent *event,
|
|
|
|
StScrollBar *bar)
|
|
|
|
{
|
2015-09-24 14:08:13 +00:00
|
|
|
StScrollBarPrivate *priv = st_scroll_bar_get_instance_private (bar);
|
2019-04-14 16:32:37 +00:00
|
|
|
ClutterInputDevice *device = clutter_event_get_device ((ClutterEvent*) event);
|
2009-09-10 03:13:35 +00:00
|
|
|
|
|
|
|
if (event->button != 1)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!clutter_actor_transform_stage_point (priv->handle,
|
|
|
|
event->x,
|
|
|
|
event->y,
|
|
|
|
&priv->x_origin,
|
|
|
|
&priv->y_origin))
|
|
|
|
return FALSE;
|
|
|
|
|
2012-08-01 15:36:16 +00:00
|
|
|
st_widget_add_style_pseudo_class (ST_WIDGET (priv->handle), "active");
|
2012-08-01 12:15:03 +00:00
|
|
|
|
2009-09-10 03:13:35 +00:00
|
|
|
/* Account for the scrollbar-trough-handle nesting. */
|
|
|
|
priv->x_origin += clutter_actor_get_x (priv->trough);
|
|
|
|
priv->y_origin += clutter_actor_get_y (priv->trough);
|
|
|
|
|
2019-04-14 16:32:37 +00:00
|
|
|
g_assert (!priv->grab_device);
|
2009-09-10 03:13:35 +00:00
|
|
|
|
2019-04-14 16:32:37 +00:00
|
|
|
clutter_input_device_grab (device, priv->handle);
|
|
|
|
priv->grab_device = device;
|
2009-09-10 03:13:35 +00:00
|
|
|
g_signal_emit (bar, signals[SCROLL_START], 0);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-09-26 03:20:04 +00:00
|
|
|
animation_completed_cb (ClutterTransition *animation,
|
|
|
|
gboolean is_finished,
|
2009-09-10 03:13:35 +00:00
|
|
|
StScrollBarPrivate *priv)
|
|
|
|
{
|
2015-09-26 03:20:04 +00:00
|
|
|
g_clear_object (&priv->paging_animation);
|
2009-09-10 03:13:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
trough_paging_cb (StScrollBar *self)
|
|
|
|
{
|
2015-09-24 14:08:13 +00:00
|
|
|
StScrollBarPrivate *priv = st_scroll_bar_get_instance_private (self);
|
2019-07-25 10:50:26 +00:00
|
|
|
StSettings *settings;
|
2009-09-10 03:13:35 +00:00
|
|
|
gfloat handle_pos, event_pos, tx, ty;
|
2015-09-26 03:20:04 +00:00
|
|
|
gdouble value, new_value;
|
2009-09-10 03:13:35 +00:00
|
|
|
gdouble page_increment;
|
2019-07-25 10:50:26 +00:00
|
|
|
gdouble slow_down_factor;
|
2009-09-10 03:13:35 +00:00
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
gulong mode;
|
|
|
|
|
2015-09-24 14:08:13 +00:00
|
|
|
if (priv->paging_event_no == 0)
|
2009-09-10 03:13:35 +00:00
|
|
|
{
|
|
|
|
/* Scroll on after initial timeout. */
|
|
|
|
mode = CLUTTER_EASE_OUT_CUBIC;
|
|
|
|
ret = FALSE;
|
2015-09-24 14:08:13 +00:00
|
|
|
priv->paging_event_no = 1;
|
|
|
|
priv->paging_source_id = g_timeout_add (
|
2009-09-10 03:13:35 +00:00
|
|
|
PAGING_INITIAL_REPEAT_TIMEOUT,
|
|
|
|
(GSourceFunc) trough_paging_cb,
|
|
|
|
self);
|
2015-09-24 14:08:13 +00:00
|
|
|
g_source_set_name_by_id (priv->paging_source_id, "[gnome-shell] trough_paging_cb");
|
2009-09-10 03:13:35 +00:00
|
|
|
}
|
2015-09-24 14:08:13 +00:00
|
|
|
else if (priv->paging_event_no == 1)
|
2009-09-10 03:13:35 +00:00
|
|
|
{
|
|
|
|
/* Scroll on after subsequent timeout. */
|
|
|
|
ret = FALSE;
|
|
|
|
mode = CLUTTER_EASE_IN_CUBIC;
|
2015-09-24 14:08:13 +00:00
|
|
|
priv->paging_event_no = 2;
|
|
|
|
priv->paging_source_id = g_timeout_add (
|
2009-09-10 03:13:35 +00:00
|
|
|
PAGING_SUBSEQUENT_REPEAT_TIMEOUT,
|
|
|
|
(GSourceFunc) trough_paging_cb,
|
|
|
|
self);
|
2015-09-24 14:08:13 +00:00
|
|
|
g_source_set_name_by_id (priv->paging_source_id, "[gnome-shell] trough_paging_cb");
|
2009-09-10 03:13:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Keep scrolling. */
|
|
|
|
ret = TRUE;
|
|
|
|
mode = CLUTTER_LINEAR;
|
2015-09-24 14:08:13 +00:00
|
|
|
priv->paging_event_no++;
|
2009-09-10 03:13:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Do the scrolling */
|
2015-09-24 14:08:13 +00:00
|
|
|
st_adjustment_get_values (priv->adjustment,
|
2009-09-10 03:13:35 +00:00
|
|
|
&value, NULL, NULL,
|
|
|
|
NULL, &page_increment, NULL);
|
|
|
|
|
2015-09-24 14:08:13 +00:00
|
|
|
if (priv->vertical)
|
|
|
|
handle_pos = clutter_actor_get_y (priv->handle);
|
2009-09-10 03:13:35 +00:00
|
|
|
else
|
2015-09-24 14:08:13 +00:00
|
|
|
handle_pos = clutter_actor_get_x (priv->handle);
|
2009-09-10 03:13:35 +00:00
|
|
|
|
2015-09-24 14:08:13 +00:00
|
|
|
clutter_actor_transform_stage_point (CLUTTER_ACTOR (priv->trough),
|
|
|
|
priv->move_x,
|
|
|
|
priv->move_y,
|
2009-09-10 03:13:35 +00:00
|
|
|
&tx, &ty);
|
|
|
|
|
2015-09-24 14:08:13 +00:00
|
|
|
if (priv->vertical)
|
2009-09-10 03:13:35 +00:00
|
|
|
event_pos = ty;
|
|
|
|
else
|
|
|
|
event_pos = tx;
|
|
|
|
|
|
|
|
if (event_pos > handle_pos)
|
|
|
|
{
|
2015-09-24 14:08:13 +00:00
|
|
|
if (priv->paging_direction == NONE)
|
2009-09-10 03:13:35 +00:00
|
|
|
{
|
|
|
|
/* Remember direction. */
|
2015-09-24 14:08:13 +00:00
|
|
|
priv->paging_direction = DOWN;
|
2009-09-10 03:13:35 +00:00
|
|
|
}
|
2015-09-24 14:08:13 +00:00
|
|
|
if (priv->paging_direction == UP)
|
2009-09-10 03:13:35 +00:00
|
|
|
{
|
|
|
|
/* Scrolled far enough. */
|
|
|
|
return FALSE;
|
|
|
|
}
|
2015-09-26 03:20:04 +00:00
|
|
|
new_value = value + page_increment;
|
2009-09-10 03:13:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-09-24 14:08:13 +00:00
|
|
|
if (priv->paging_direction == NONE)
|
2009-09-10 03:13:35 +00:00
|
|
|
{
|
|
|
|
/* Remember direction. */
|
2015-09-24 14:08:13 +00:00
|
|
|
priv->paging_direction = UP;
|
2009-09-10 03:13:35 +00:00
|
|
|
}
|
2015-09-24 14:08:13 +00:00
|
|
|
if (priv->paging_direction == DOWN)
|
2009-09-10 03:13:35 +00:00
|
|
|
{
|
|
|
|
/* Scrolled far enough. */
|
|
|
|
return FALSE;
|
|
|
|
}
|
2015-09-26 03:20:04 +00:00
|
|
|
new_value = value - page_increment;
|
2009-09-10 03:13:35 +00:00
|
|
|
}
|
|
|
|
|
2015-09-24 14:08:13 +00:00
|
|
|
if (priv->paging_animation)
|
2009-09-10 03:13:35 +00:00
|
|
|
{
|
2015-09-26 03:20:04 +00:00
|
|
|
clutter_timeline_stop (CLUTTER_TIMELINE (priv->paging_animation));
|
2009-09-10 03:13:35 +00:00
|
|
|
}
|
|
|
|
|
2019-07-25 10:50:26 +00:00
|
|
|
settings = st_settings_get ();
|
|
|
|
g_object_get (settings, "slow-down-factor", &slow_down_factor, NULL);
|
|
|
|
|
2015-09-26 03:20:04 +00:00
|
|
|
/* FIXME: Creating a new transition for each scroll is probably not the best
|
|
|
|
* idea, but it's a lot less involved than extending the current animation */
|
|
|
|
priv->paging_animation = g_object_new (CLUTTER_TYPE_PROPERTY_TRANSITION,
|
|
|
|
"animatable", priv->adjustment,
|
|
|
|
"property-name", "value",
|
|
|
|
"interval", clutter_interval_new (G_TYPE_DOUBLE, value, new_value),
|
2019-07-25 10:50:26 +00:00
|
|
|
"duration", (guint)(PAGING_SUBSEQUENT_REPEAT_TIMEOUT * slow_down_factor),
|
2015-09-26 03:20:04 +00:00
|
|
|
"progress-mode", mode,
|
|
|
|
NULL);
|
|
|
|
g_signal_connect (priv->paging_animation, "stopped",
|
|
|
|
G_CALLBACK (animation_completed_cb), priv);
|
|
|
|
clutter_timeline_start (CLUTTER_TIMELINE (priv->paging_animation));
|
2009-09-10 03:13:35 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
trough_button_press_event_cb (ClutterActor *actor,
|
|
|
|
ClutterButtonEvent *event,
|
|
|
|
StScrollBar *self)
|
|
|
|
{
|
2015-09-24 14:08:13 +00:00
|
|
|
StScrollBarPrivate *priv;
|
|
|
|
|
2009-09-10 03:13:35 +00:00
|
|
|
g_return_val_if_fail (self, FALSE);
|
|
|
|
|
|
|
|
if (event->button != 1)
|
|
|
|
return FALSE;
|
|
|
|
|
2015-09-24 14:08:13 +00:00
|
|
|
priv = st_scroll_bar_get_instance_private (self);
|
|
|
|
if (priv->adjustment == NULL)
|
2009-09-10 03:13:35 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2015-09-24 14:08:13 +00:00
|
|
|
priv->move_x = event->x;
|
|
|
|
priv->move_y = event->y;
|
|
|
|
priv->paging_direction = NONE;
|
|
|
|
priv->paging_event_no = 0;
|
2009-09-10 03:13:35 +00:00
|
|
|
trough_paging_cb (self);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
trough_button_release_event_cb (ClutterActor *actor,
|
|
|
|
ClutterButtonEvent *event,
|
|
|
|
StScrollBar *self)
|
|
|
|
{
|
2015-09-24 14:08:13 +00:00
|
|
|
StScrollBarPrivate *priv = st_scroll_bar_get_instance_private (self);
|
|
|
|
|
2009-09-10 03:13:35 +00:00
|
|
|
if (event->button != 1)
|
|
|
|
return FALSE;
|
|
|
|
|
2015-09-24 14:08:13 +00:00
|
|
|
if (priv->paging_source_id)
|
2009-09-10 03:13:35 +00:00
|
|
|
{
|
2015-09-24 14:08:13 +00:00
|
|
|
g_source_remove (priv->paging_source_id);
|
|
|
|
priv->paging_source_id = 0;
|
2009-09-10 03:13:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
trough_leave_event_cb (ClutterActor *actor,
|
|
|
|
ClutterEvent *event,
|
|
|
|
StScrollBar *self)
|
|
|
|
{
|
2015-09-24 14:08:13 +00:00
|
|
|
StScrollBarPrivate *priv = st_scroll_bar_get_instance_private (self);
|
|
|
|
|
|
|
|
if (priv->paging_source_id)
|
2009-09-10 03:13:35 +00:00
|
|
|
{
|
2015-09-24 14:08:13 +00:00
|
|
|
g_source_remove (priv->paging_source_id);
|
|
|
|
priv->paging_source_id = 0;
|
2009-09-10 03:13:35 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
st_scroll_bar_notify_reactive (StScrollBar *self)
|
|
|
|
{
|
2015-09-24 14:08:13 +00:00
|
|
|
StScrollBarPrivate *priv = st_scroll_bar_get_instance_private (self);
|
2009-09-10 03:13:35 +00:00
|
|
|
|
2015-07-22 13:43:12 +00:00
|
|
|
gboolean reactive = clutter_actor_get_reactive (CLUTTER_ACTOR (self));
|
2009-09-10 03:13:35 +00:00
|
|
|
|
|
|
|
clutter_actor_set_reactive (CLUTTER_ACTOR (priv->trough), reactive);
|
|
|
|
clutter_actor_set_reactive (CLUTTER_ACTOR (priv->handle), reactive);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
st_scroll_bar_init (StScrollBar *self)
|
|
|
|
{
|
2015-09-24 14:08:13 +00:00
|
|
|
StScrollBarPrivate *priv = st_scroll_bar_get_instance_private (self);
|
2009-09-10 03:13:35 +00:00
|
|
|
|
2015-09-24 14:08:13 +00:00
|
|
|
priv->trough = (ClutterActor *) st_bin_new ();
|
|
|
|
clutter_actor_set_reactive ((ClutterActor *) priv->trough, TRUE);
|
|
|
|
clutter_actor_set_name (CLUTTER_ACTOR (priv->trough), "trough");
|
2012-02-13 20:22:53 +00:00
|
|
|
clutter_actor_add_child (CLUTTER_ACTOR (self),
|
2015-09-24 14:08:13 +00:00
|
|
|
CLUTTER_ACTOR (priv->trough));
|
|
|
|
g_signal_connect (priv->trough, "button-press-event",
|
2009-09-10 03:13:35 +00:00
|
|
|
G_CALLBACK (trough_button_press_event_cb), self);
|
2015-09-24 14:08:13 +00:00
|
|
|
g_signal_connect (priv->trough, "button-release-event",
|
2009-09-10 03:13:35 +00:00
|
|
|
G_CALLBACK (trough_button_release_event_cb), self);
|
2015-09-24 14:08:13 +00:00
|
|
|
g_signal_connect (priv->trough, "leave-event",
|
2009-09-10 03:13:35 +00:00
|
|
|
G_CALLBACK (trough_leave_event_cb), self);
|
|
|
|
|
2015-09-24 14:08:13 +00:00
|
|
|
priv->handle = (ClutterActor *) st_button_new ();
|
|
|
|
clutter_actor_set_name (CLUTTER_ACTOR (priv->handle), "hhandle");
|
2012-02-13 20:22:53 +00:00
|
|
|
clutter_actor_add_child (CLUTTER_ACTOR (self),
|
2015-09-24 14:08:13 +00:00
|
|
|
CLUTTER_ACTOR (priv->handle));
|
|
|
|
g_signal_connect (priv->handle, "button-press-event",
|
2009-09-10 03:13:35 +00:00
|
|
|
G_CALLBACK (handle_button_press_event_cb), self);
|
2015-09-24 14:08:13 +00:00
|
|
|
g_signal_connect (priv->handle, "button-release-event",
|
2011-10-28 21:32:32 +00:00
|
|
|
G_CALLBACK (handle_button_release_event_cb), self);
|
2015-09-24 14:08:13 +00:00
|
|
|
g_signal_connect (priv->handle, "motion-event",
|
2011-10-28 21:32:32 +00:00
|
|
|
G_CALLBACK (handle_motion_event_cb), self);
|
2009-09-10 03:13:35 +00:00
|
|
|
|
|
|
|
clutter_actor_set_reactive (CLUTTER_ACTOR (self), TRUE);
|
|
|
|
|
|
|
|
g_signal_connect (self, "notify::reactive",
|
|
|
|
G_CALLBACK (st_scroll_bar_notify_reactive), NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
StWidget *
|
|
|
|
st_scroll_bar_new (StAdjustment *adjustment)
|
|
|
|
{
|
|
|
|
return g_object_new (ST_TYPE_SCROLL_BAR,
|
|
|
|
"adjustment", adjustment,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2010-03-05 21:17:07 +00:00
|
|
|
static void
|
|
|
|
on_notify_value (GObject *object,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
StScrollBar *bar)
|
|
|
|
{
|
|
|
|
scroll_bar_update_positions (bar);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_changed (StAdjustment *adjustment,
|
|
|
|
StScrollBar *bar)
|
|
|
|
{
|
|
|
|
scroll_bar_update_positions (bar);
|
|
|
|
}
|
|
|
|
|
2009-09-10 03:13:35 +00:00
|
|
|
void
|
|
|
|
st_scroll_bar_set_adjustment (StScrollBar *bar,
|
|
|
|
StAdjustment *adjustment)
|
|
|
|
{
|
|
|
|
StScrollBarPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (ST_IS_SCROLL_BAR (bar));
|
|
|
|
|
2015-09-24 14:08:13 +00:00
|
|
|
priv = st_scroll_bar_get_instance_private (bar);
|
2010-03-10 23:32:10 +00:00
|
|
|
|
|
|
|
if (adjustment == priv->adjustment)
|
|
|
|
return;
|
|
|
|
|
2009-09-10 03:13:35 +00:00
|
|
|
if (priv->adjustment)
|
|
|
|
{
|
|
|
|
g_signal_handlers_disconnect_by_func (priv->adjustment,
|
2010-03-05 21:17:07 +00:00
|
|
|
on_notify_value,
|
2009-09-10 03:13:35 +00:00
|
|
|
bar);
|
|
|
|
g_signal_handlers_disconnect_by_func (priv->adjustment,
|
2010-03-05 21:17:07 +00:00
|
|
|
on_changed,
|
2009-09-10 03:13:35 +00:00
|
|
|
bar);
|
|
|
|
g_object_unref (priv->adjustment);
|
|
|
|
priv->adjustment = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (adjustment)
|
|
|
|
{
|
|
|
|
priv->adjustment = g_object_ref (adjustment);
|
|
|
|
|
2010-03-05 21:17:07 +00:00
|
|
|
g_signal_connect (priv->adjustment, "notify::value",
|
|
|
|
G_CALLBACK (on_notify_value),
|
|
|
|
bar);
|
|
|
|
g_signal_connect (priv->adjustment, "changed",
|
|
|
|
G_CALLBACK (on_changed),
|
|
|
|
bar);
|
2009-09-10 03:13:35 +00:00
|
|
|
|
|
|
|
clutter_actor_queue_relayout (CLUTTER_ACTOR (bar));
|
|
|
|
}
|
2010-03-10 23:32:10 +00:00
|
|
|
|
2019-07-29 15:59:41 +00:00
|
|
|
g_object_notify_by_pspec (G_OBJECT (bar), props[PROP_ADJUSTMENT]);
|
2009-09-10 03:13:35 +00:00
|
|
|
}
|
|
|
|
|
2009-09-16 23:07:23 +00:00
|
|
|
/**
|
|
|
|
* st_scroll_bar_get_adjustment:
|
|
|
|
* @bar: a #StScrollbar
|
|
|
|
*
|
|
|
|
* Gets the adjustment object that stores the current position
|
|
|
|
* of the scrollbar.
|
|
|
|
*
|
|
|
|
* Return value: (transfer none): the adjustment
|
|
|
|
*/
|
2009-09-10 03:13:35 +00:00
|
|
|
StAdjustment *
|
|
|
|
st_scroll_bar_get_adjustment (StScrollBar *bar)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (ST_IS_SCROLL_BAR (bar), NULL);
|
|
|
|
|
2015-09-24 14:08:13 +00:00
|
|
|
return ((StScrollBarPrivate *)ST_SCROLL_BAR_PRIVATE (bar))->adjustment;
|
2009-09-10 03:13:35 +00:00
|
|
|
}
|
|
|
|
|