+2008-06-26 Alejandro G. Castro <alex@igalia.com>
+
+ contributed and reviewed by: Claudio Saavedra <csaavedra@igalia.com>
+
+ * src/hildon-pannable-area.c
+ (hildon_pannable_area_button_press_cb),
+ (hildon_pannable_axis_scroll),
+ (hildon_pannable_area_scroll),
+ (hildon_pannable_area_timeout),
+ (hildon_pannable_calculate_vel_factor),
+ (hildon_pannable_area_get_property),
+ (hildon_pannable_area_set_property),
+ (hildon_pannable_area_class_init),
+ (hildon_pannable_area_init),
+ (hildon_pannable_area_scroll_to),
+ (hildon_pannable_area_jump_to),
+ (hildon_pannable_area_scroll_to_child),
+ (hildon_pannable_area_jump_to_child):
+ * src/hildon-pannable-area.h: Added the new API functions:
+ hildon_pannable_area_scroll_to, hildon_pannable_area_jump_to,
+ hildon_pannable_area_scroll_to_child,
+ hildon_pannable_area_jump_to_child
+
+
+ * examples/Makefile.am
+ * examples/hildon-pannable-area-example-2.c
+ * examples/hildon-pannable-area-example-3.c: Added these two new
+ examples in order to test and show how the new APIs work.
+
2008-06-25 Alberto Garcia <agarcia@igalia.com>
* examples/hildon-stackable-window-example.c (new_window):
hildon-hvolumebar-timer-example \
hildon-toolbar-seekbar-example \
hildon-pannable-area-example \
+ hildon-pannable-area-example-2 \
+ hildon-pannable-area-example-3 \
hildon-logical-color-example \
hildon-app-menu-example \
hildon-stackable-window-example \
hildon-dialog-example
-
# Hildon window
hildon_window_example_LDADD = $(HILDON_OBJ_LIBS)
hildon_window_example_CFLAGS = $(HILDON_OBJ_CFLAGS)
hildon_pannable_area_example_CFLAGS = $(HILDON_OBJ_CFLAGS)
hildon_pannable_area_example_SOURCES = hildon-pannable-area-example.c
+# Hildon pannable area 2
+hildon_pannable_area_example_2_LDADD = $(HILDON_OBJ_LIBS)
+hildon_pannable_area_example_2_CFLAGS = $(HILDON_OBJ_CFLAGS)
+hildon_pannable_area_example_2_SOURCES = hildon-pannable-area-example-2.c
+
+# Hildon pannable area 3
+hildon_pannable_area_example_3_LDADD = $(HILDON_OBJ_LIBS)
+hildon_pannable_area_example_3_CFLAGS = $(HILDON_OBJ_CFLAGS)
+hildon_pannable_area_example_3_SOURCES = hildon-pannable-area-example-3.c
+
# Hildon app menu
hildon_app_menu_example_LDADD = $(HILDON_OBJ_LIBS)
hildon_app_menu_example_CFLAGS = $(HILDON_OBJ_CFLAGS)
--- /dev/null
+/*
+ * This file is a part of hildon examples
+ *
+ * Copyright (C) 2008 Nokia Corporation, all rights reserved.
+ *
+ * Based in hildon-pannable-area-example.c
+ * by Karl Lattimer <karl.lattimer@nokia.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that 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 along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <glib.h>
+#include <gtk/gtk.h>
+#include <string.h>
+#include "hildon.h"
+
+enum { TEXT_COLUMN, N_COLUMNS };
+
+typedef struct {
+ GtkWidget *scroll_entry;
+ GtkWidget *jump_entry;
+ GtkWidget *panarea;
+ GtkWidget *treeview;
+} SearchContext;
+
+SearchContext *ctx;
+
+static void
+search_button_clicked (GtkButton *button,
+ gpointer user_data)
+{
+ GtkTreeModel *model;
+ const gchar *s1;
+ gchar *s2;
+ gboolean found;
+ GtkTreeIter iter;
+ GtkTreePath *path;
+ GdkRectangle rect;
+ gint y;
+ gboolean jump_or_scroll;
+
+ jump_or_scroll = *((gboolean *) user_data);
+
+ if (jump_or_scroll)
+ {
+ s1 = gtk_entry_get_text (GTK_ENTRY (ctx->scroll_entry));
+ }
+ else
+ {
+ s1 = gtk_entry_get_text (GTK_ENTRY (ctx->jump_entry));
+ }
+
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (ctx->treeview));
+
+ gtk_tree_model_get_iter_first (model, &iter);
+
+ do {
+ gtk_tree_model_get (model, &iter, TEXT_COLUMN, &s2, -1);
+ found = (strcmp (s1, s2) == 0);
+ g_free (s2);
+ } while (found != TRUE && gtk_tree_model_iter_next (model, &iter));
+
+ if (found) {
+ GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW (ctx->treeview));
+
+ path = gtk_tree_model_get_path (model, &iter);
+
+ gtk_tree_view_get_background_area (GTK_TREE_VIEW (ctx->treeview),
+ path, NULL, &rect);
+ gtk_tree_view_convert_bin_window_to_tree_coords (GTK_TREE_VIEW (ctx->treeview),
+ 0, rect.y, NULL, &y);
+ g_print ("text found in (0, %d)\n", y);
+
+ gtk_tree_selection_select_path (selection, path);
+ if (jump_or_scroll)
+ {
+ hildon_pannable_area_scroll_to (HILDON_PANNABLE_AREA (ctx->panarea),
+ -1, y);
+ }
+ else
+ {
+ hildon_pannable_area_jump_to (HILDON_PANNABLE_AREA (ctx->panarea),
+ -1, y);
+ }
+
+ gtk_tree_path_free (path);
+ }
+}
+
+int
+main (int argc, char **args)
+{
+ int i;
+ HildonProgram *program;
+ GtkWidget *window, *tv, *panarea, *button;
+ GtkTreeViewColumn *col;
+ GtkCellRenderer *renderer;
+ GtkListStore *store;
+ GtkWidget *hbox, *vbox;
+ GtkWidget *entry;
+ gboolean scroll = TRUE;
+ gboolean jump = FALSE;
+
+ gtk_init (&argc, &args);
+
+ program = hildon_program_get_instance ();
+
+ /* Create the main window */
+ window = hildon_window_new ();
+ hildon_program_add_window (program, HILDON_WINDOW (window));
+ gtk_container_set_border_width (GTK_CONTAINER (window), 5);
+
+ /* Create a treeview */
+ tv = gtk_tree_view_new ();
+ renderer = gtk_cell_renderer_text_new ();
+ col = gtk_tree_view_column_new_with_attributes ("Title", renderer, "text", TEXT_COLUMN, NULL);
+ gtk_tree_view_append_column (GTK_TREE_VIEW(tv), col);
+
+ /* Add some rows to the treeview */
+ store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING);
+ for (i = 0; i < 100; i++) {
+ GtkTreeIter iter;
+ gchar *label = g_strdup_printf ("Row %d", i);
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter, TEXT_COLUMN, label, -1);
+ g_free (label);
+ }
+ gtk_tree_view_set_model (GTK_TREE_VIEW (tv), GTK_TREE_MODEL (store));
+ g_object_unref (store);
+
+ /* Put everything in a pannable area */
+ panarea = hildon_pannable_area_new ();
+ gtk_container_add (GTK_CONTAINER (panarea), GTK_WIDGET (tv));
+
+ ctx = g_new0 (SearchContext, 1);
+
+ vbox = gtk_vbox_new (FALSE, 5);
+ hbox = gtk_hbox_new (FALSE, 5);
+ button = gtk_button_new_from_stock (GTK_STOCK_FIND);
+
+ entry = gtk_entry_new ();
+ gtk_entry_set_text (GTK_ENTRY (entry), "Enter some text to scroll");
+
+ g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (search_button_clicked), &scroll);
+
+ gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 10);
+
+ ctx->scroll_entry = entry;
+
+ hbox = gtk_hbox_new (FALSE, 5);
+ button = gtk_button_new_from_stock (GTK_STOCK_FIND);
+
+ entry = gtk_entry_new ();
+ gtk_entry_set_text (GTK_ENTRY (entry), "Enter some text to jump");
+
+ g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (search_button_clicked), &jump);
+
+ gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 10);
+
+ ctx->jump_entry = entry;
+ ctx->treeview = tv;
+ ctx->panarea = panarea;
+
+ g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (gtk_main_quit), NULL);
+
+ gtk_box_pack_start (GTK_BOX (vbox), panarea, TRUE, TRUE, 0);
+
+ gtk_container_add (GTK_CONTAINER (window), vbox);
+
+ gtk_widget_show_all (GTK_WIDGET (window));
+
+ gtk_main ();
+
+ return 0;
+}
--- /dev/null
+/*
+ * This file is a part of hildon examples
+ *
+ * Copyright (C) 2008 Nokia Corporation, all rights reserved.
+ *
+ * Based in hildon-pannable-area-example.c
+ * by Karl Lattimer <karl.lattimer@nokia.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that 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 along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <glib.h>
+#include <gtk/gtk.h>
+#include "hildon.h"
+
+GtkWidget *btn;
+
+static void
+on_button_clicked (GtkWidget *widget, gpointer data)
+{
+ g_debug ("Button %d clicked", GPOINTER_TO_INT (data));
+ btn = widget;
+}
+
+static void
+find_button_clicked (GtkButton *button,
+ gpointer user_data)
+{
+ HildonPannableArea *panarea;
+
+ panarea = HILDON_PANNABLE_AREA (user_data);
+
+ hildon_pannable_area_scroll_to_child (panarea, btn);
+}
+
+int
+main (int argc, char **args)
+{
+ int i;
+ HildonProgram *program;
+ GtkWidget *window, *panarea, *button;
+ GtkWidget *hbox, *vbox;
+
+ gtk_init (&argc, &args);
+
+ program = hildon_program_get_instance ();
+
+ /* Create the main window */
+ window = hildon_window_new ();
+ hildon_program_add_window (program, HILDON_WINDOW (window));
+ gtk_container_set_border_width (GTK_CONTAINER (window), 5);
+
+ /* Create a VBox and pack some buttons */
+ vbox = gtk_vbox_new (FALSE, 1);
+ for (i = 0; i < 80; i++) {
+ gchar *label = g_strdup_printf ("Button number %d", i);
+
+ button = gtk_button_new_with_label (label);
+ gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);
+ g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (on_button_clicked), GINT_TO_POINTER (i));
+ g_free (label);
+ }
+
+ /* Put everything in a pannable area */
+ panarea = hildon_pannable_area_new ();
+ hildon_pannable_area_add_with_viewport(HILDON_PANNABLE_AREA (panarea), GTK_WIDGET (vbox));
+
+ vbox = gtk_vbox_new (FALSE, 10);
+ hbox = gtk_hbox_new (FALSE, 10);
+
+ button = gtk_button_new_with_label ("Find the latest clicked button");
+ g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (find_button_clicked), panarea);
+ gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
+
+ g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (gtk_main_quit), NULL);
+
+ gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 10);
+ gtk_box_pack_start (GTK_BOX (vbox), panarea, TRUE, TRUE, 0);
+
+ gtk_container_add (GTK_CONTAINER (window), vbox);
+
+ gtk_widget_show_all (GTK_WIDGET (window));
+
+ gtk_main ();
+
+ return 0;
+}
#define FORCE 5
#define BOUNCE_STEPS 6
#define SCROLL_BAR_MIN_SIZE 5
+#define RATIO_TOLERANCE 0.000001
G_DEFINE_TYPE (HildonPannableArea, hildon_pannable_area, GTK_TYPE_BIN)
#define PANNABLE_AREA_PRIVATE(o) \
gdouble vmax;
gdouble vfast_factor;
gdouble decel;
+ gdouble scroll_time;
+ gdouble vel_factor;
guint sps;
gdouble vel_x;
gdouble vel_y;
gint cx; /* Initial click child window mouse co-ordinates */
gint cy;
guint idle_id;
+ gdouble scroll_to_x;
+ gdouble scroll_to_y;
gint overshot_dist_x;
gint overshot_dist_y;
gint overshooting_y;
PROP_SPS,
PROP_VINDICATOR,
PROP_HINDICATOR,
- PROP_OVERSHOOT_MAX
+ PROP_OVERSHOOT_MAX,
+ PROP_SCROLL_TIME
};
static GdkWindow *hildon_pannable_area_get_topmost (GdkWindow * window,
priv->click_x = event->x;
priv->click_y = event->y;
+ priv->scroll_to_x = -1;
+ priv->scroll_to_y = -1;
+
if (priv->clicked && priv->child) {
/* Widget stole focus on last click, send crossing-out event */
synth_crossing (priv->child, 0, 0, event->x_root, event->y_root,
gdouble inc,
gint *overshooting,
gint *overshot_dist,
+ gdouble *scroll_to,
gboolean *s)
{
gdouble dist;
dist = adjust->lower;
*overshooting = 1;
+ *scroll_to = -1;
*overshot_dist = CLAMP (*overshot_dist + *vel, 0, priv->overshoot_max);
gtk_widget_queue_resize (GTK_WIDGET (area));
} else if (dist > adjust->upper - adjust->page_size) {
dist = adjust->upper - adjust->page_size;
*overshooting = 1;
+ *scroll_to = -1;
*overshot_dist = CLAMP (*overshot_dist + *vel, -1*priv->overshoot_max, 0);
gtk_widget_queue_resize (GTK_WIDGET (area));
} else {
+ if ((*scroll_to) != -1) {
+ if (((inc < 0)&&(*scroll_to <= dist))||
+ ((inc > 0)&&(*scroll_to >= dist))) {
+ dist = *scroll_to;
+ *scroll_to = -1;
+ *vel = 0;
+ }
+ }
+
gtk_adjustment_set_value (adjust, dist);
if (s) {
if (vscroll) {
hildon_pannable_axis_scroll (area, priv->vadjust, &priv->vel_y, y,
&priv->overshooting_y, &priv->overshot_dist_y,
- sy);
+ &priv->scroll_to_y, sy);
}
if (hscroll) {
hildon_pannable_axis_scroll (area, priv->hadjust, &priv->vel_x, x,
&priv->overshooting_x, &priv->overshot_dist_x,
- sx);
+ &priv->scroll_to_x, sx);
}
/* If the scroll on a particular axis wasn't succesful, reset the
/* Decelerate gradually when pointer is raised */
if ((!priv->overshot_dist_y) &&
(!priv->overshot_dist_x)) {
- priv->vel_x *= priv->decel;
- priv->vel_y *= priv->decel;
- if ((ABS (priv->vel_x) < 1.0) && (ABS (priv->vel_y) < 1.0)) {
- priv->idle_id = 0;
- return FALSE;
+
+ /* in case we move to a specific point do not decelerate when arriving */
+ if ((priv->scroll_to_x != -1)||(priv->scroll_to_y != -1)) {
+
+ if (ABS (priv->vel_x) >= 1.5) {
+ priv->vel_x *= priv->decel;
+ }
+
+ if (ABS (priv->vel_y) >= 1.5) {
+ priv->vel_y *= priv->decel;
+ }
+
+ } else {
+ priv->vel_x *= priv->decel;
+ priv->vel_y *= priv->decel;
+
+ if ((ABS (priv->vel_x) < 1.0) && (ABS (priv->vel_y) < 1.0)) {
+ priv->idle_id = 0;
+ return FALSE;
+ }
}
}
} else if (priv->mode == HILDON_PANNABLE_AREA_MODE_AUTO) {
}
static void
+hildon_pannable_calculate_vel_factor (HildonPannableArea * self)
+{
+ HildonPannableAreaPrivate *priv = PANNABLE_AREA_PRIVATE (self);
+ gfloat fct = 0;
+ gfloat fct_i = 1;
+ gint i, n;
+
+ n = ceil (priv->sps * priv->scroll_time);
+
+ for (i = 0; i < n && fct_i >= RATIO_TOLERANCE; i++) {
+ fct_i *= priv->decel;
+ fct += fct_i;
+ }
+
+ priv->vel_factor = fct;
+}
+
+static void
hildon_pannable_area_get_property (GObject * object, guint property_id,
GValue * value, GParamSpec * pspec)
{
case PROP_OVERSHOOT_MAX:
g_value_set_int (value, priv->overshoot_max);
break;
+ case PROP_SCROLL_TIME:
+ g_value_set_double (value, priv->scroll_time);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
priv->vfast_factor = g_value_get_double (value);
break;
case PROP_DECELERATION:
+ hildon_pannable_calculate_vel_factor (HILDON_PANNABLE_AREA (object));
+
priv->decel = g_value_get_double (value);
break;
case PROP_SPS:
case PROP_OVERSHOOT_MAX:
priv->overshoot_max = g_value_get_int (value);
break;
+ case PROP_SCROLL_TIME:
+ priv->scroll_time = g_value_get_double (value);
+
+ hildon_pannable_calculate_vel_factor (HILDON_PANNABLE_AREA (object));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
+ g_object_class_install_property (object_class,
+ PROP_SCROLL_TIME,
+ g_param_spec_double ("scroll_time",
+ "Time to scroll to a position",
+ "The time to scroll to a position when calling the hildon_pannable_scroll_to function"
+ "acceleration scrolling mode.",
+ 1.0, 20.0, 10.0,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT));
+
+
gtk_widget_class_install_style_property (widget_class,
g_param_spec_uint
("indicator-width",
priv->overshooting_y = 0;
priv->overshooting_x = 0;
priv->idle_id = 0;
+ priv->vel_x = 0.0;
+ priv->vel_y = 0.0;
priv->scroll_indicator_alpha = 1;
priv->scroll_indicator_timeout = 0;
priv->scroll_indicator_event_interrupt = 0;
priv->scroll_delay_counter = 0;
+ priv->scroll_to_x = -1;
+ priv->scroll_to_y = -1;
+
+ hildon_pannable_calculate_vel_factor (self);
priv->align = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
+
GTK_CONTAINER_CLASS (hildon_pannable_area_parent_class)->
add (GTK_CONTAINER (self), priv->align);
gtk_alignment_set_padding (GTK_ALIGNMENT (priv->align), 0, priv->area_width,
gtk_widget_show (viewport);
gtk_container_add (GTK_CONTAINER (area), viewport);
}
+
+/**
+ * hildon_pannable_area_scroll_to:
+ * @area: A #HildonPannableArea.
+ * @x: The x coordinate of the destination point or -1 to ignore this axis.
+ * @y: The y coordinate of the destination point or -1 to ignore this axis.
+ *
+ * Smoothly scrolls @area to ensure that (@x, @y) is a visible point
+ * on the widget. To move only in one coordinate, you can set the other one
+ * to -1. Notice that in PUSH mode this function works like jump_to.
+ *
+ * This is and example of how to calculate the position of a row in a
+ * #GtkTreeview:
+ * Here is a simple example:
+ * <informalexample><programlisting>
+ * path = gtk_tree_model_get_path (model, &iter);
+ * gtk_tree_view_get_background_area (GTK_TREE_VIEW (treeview),
+ * path, NULL, &rect);
+ * gtk_tree_view_convert_bin_window_to_tree_coords (GTK_TREE_VIEW (treeview),
+ * 0, rect.y, NULL, &y);
+ * hildon_pannable_area_scroll_to (HILDON_PANNABLE_AREA (ctx->panarea),
+ * -1, y - rect.height);
+ * </programlisting></informalexample>
+ **/
+void
+hildon_pannable_area_scroll_to (HildonPannableArea *area,
+ const gint x, const gint y)
+{
+ HildonPannableAreaPrivate *priv;
+ gint width, height;
+ gint dist_x, dist_y;
+
+ g_return_if_fail (HILDON_IS_PANNABLE_AREA (area));
+
+ priv = PANNABLE_AREA_PRIVATE (area);
+
+ if (priv->mode == HILDON_PANNABLE_AREA_MODE_PUSH)
+ hildon_pannable_area_jump_to (area, x, y);
+
+ g_return_if_fail (x >= -1 && y >= -1);
+
+ if (x == -1 && y == -1) {
+ return;
+ }
+
+ width = priv->hadjust->upper - priv->hadjust->lower;
+ height = priv->vadjust->upper - priv->vadjust->lower;
+
+ g_return_if_fail (x < width || y < height);
+
+ if (x > -1) {
+ priv->scroll_to_x = x - priv->hadjust->page_size/2;
+ dist_x = priv->scroll_to_x - priv->hadjust->value;
+ if (dist_x == 0) {
+ priv->scroll_to_x = -1;
+ } else {
+ priv->vel_x = - dist_x/priv->vel_factor;
+ }
+ } else {
+ priv->scroll_to_x = -1;
+ }
+
+ if (y > -1) {
+ priv->scroll_to_y = y - priv->vadjust->page_size/2;
+ dist_y = priv->scroll_to_y - priv->vadjust->value;
+ if (dist_y == 0) {
+ priv->scroll_to_y = -1;
+ } else {
+ priv->vel_y = - dist_y/priv->vel_factor;
+ }
+ } else {
+ priv->scroll_to_y = y;
+ }
+
+ if ((priv->scroll_to_y == -1) && (priv->scroll_to_y == -1)) {
+ return;
+ }
+
+ priv->scroll_indicator_alpha = 1.0;
+
+ if (priv->scroll_indicator_timeout)
+ g_source_remove (priv->scroll_indicator_timeout);
+ priv->scroll_indicator_timeout = g_timeout_add ((gint) (1000.0 / (gdouble) priv->sps),
+ (GSourceFunc) hildon_pannable_area_scroll_indicator_fade, area);
+
+ if (priv->idle_id)
+ g_source_remove (priv->idle_id);
+ priv->idle_id = g_timeout_add ((gint) (1000.0 / (gdouble) priv->sps),
+ (GSourceFunc)
+ hildon_pannable_area_timeout, area);
+}
+
+/**
+ * hildon_pannable_area_jump_to:
+ * @area: A #HildonPannableArea.
+ * @x: The x coordinate of the destination point or -1 to ignore this axis.
+ * @y: The y coordinate of the destination point or -1 to ignore this axis.
+ *
+ * Jumps the position of the @area to ensure that (@x, @y) is a
+ * visible point on the widget, . To move only in one coordinate, you
+ * can set the other one to -1. Check hildon_pannable_area_scroll_to()
+ * function for an example of how to calculate position of children in
+ * complex widgets like #GtkTreeview.
+ *
+ **/
+void
+hildon_pannable_area_jump_to (HildonPannableArea *area,
+ const gint x, const gint y)
+{
+ HildonPannableAreaPrivate *priv;
+ gint width, height;
+
+ g_return_if_fail (HILDON_IS_PANNABLE_AREA (area));
+ g_return_if_fail (x >= -1 && y >= -1);
+
+ if (x == -1 && y == -1) {
+ return;
+ }
+
+ priv = PANNABLE_AREA_PRIVATE (area);
+
+ width = priv->hadjust->upper - priv->hadjust->lower;
+ height = priv->vadjust->upper - priv->vadjust->lower;
+
+ g_return_if_fail (x < width || y < height);
+
+ if (x != -1) {
+ gdouble jump_to = x - priv->hadjust->page_size/2;
+
+ if (jump_to > priv->hadjust->upper - priv->hadjust->page_size) {
+ jump_to = priv->hadjust->upper - priv->hadjust->page_size;
+ }
+
+ gtk_adjustment_set_value (priv->hadjust, jump_to);
+ }
+
+ if (y != -1) {
+ gdouble jump_to = y - priv->vadjust->page_size/2;
+
+ if (jump_to > priv->vadjust->upper - priv->vadjust->page_size) {
+ jump_to = priv->vadjust->upper - priv->vadjust->page_size;
+ }
+
+ gtk_adjustment_set_value (priv->vadjust, jump_to);
+ }
+
+ priv->scroll_indicator_alpha = 1.0;
+
+ if (priv->scroll_indicator_timeout) {
+
+ priv->vel_x = 0.0;
+ priv->vel_y = 0.0;
+ priv->overshooting_x = 0;
+ priv->overshooting_y = 0;
+
+ if ((priv->overshot_dist_x>0)||(priv->overshot_dist_y>0)) {
+ priv->overshot_dist_x = 0;
+ priv->overshot_dist_y = 0;
+
+ gtk_widget_queue_resize (GTK_WIDGET (area));
+ }
+ g_source_remove (priv->scroll_indicator_timeout);
+ }
+
+ if (priv->idle_id)
+ g_source_remove (priv->idle_id);
+}
+
+/**
+ * hildon_pannable_area_scroll_to_child:
+ * @area: A #HildonPannableArea.
+ * @child: A #GtkWidget, descendant of @area.
+ *
+ * Smoothly scrolls until @child is visible inside @area. @child must
+ * be a descendant of @area. If you want to move inside a scrolleable
+ * widget, i. e. #GtkTreeview, it is better you use the
+ * hildon_pannable_area_scroll_to() function, you can calculate the
+ * position of the row using gtk_tree_view_get_background_area() and
+ * converting the coordinates with
+ * gtk_tree_view_convert_bin_window_to_tree_coords()
+ *
+ **/
+void
+hildon_pannable_area_scroll_to_child (HildonPannableArea *area, GtkWidget *child)
+{
+ GtkWidget *bin_child;
+ gint x, y;
+
+ g_return_if_fail (HILDON_IS_PANNABLE_AREA (area));
+ g_return_if_fail (GTK_IS_WIDGET (child));
+ g_return_if_fail (gtk_widget_is_ancestor (child, GTK_WIDGET (area)));
+
+ /* We need to get to check the child of the alignment inside the
+ * area */
+ bin_child = GTK_BIN (GTK_BIN (area)->child)->child;
+
+ /* we check if we added a viewport */
+ if (GTK_IS_VIEWPORT (bin_child)) {
+ bin_child = GTK_BIN (bin_child)->child;
+ }
+
+ if (gtk_widget_translate_coordinates (child, bin_child, 0, 0, &x, &y))
+ hildon_pannable_area_scroll_to (area, x, y);
+}
+
+/**
+ * hildon_pannable_area_scroll_to_child:
+ * @area: A #HildonPannableArea.
+ * @child: A #GtkWidget, descendant of @area.
+ *
+ * Smoothly scrolls until @child is visible inside @area. @child must
+ * be a descendant of @area. If you want to move inside a scrolleable
+ * widget, i. e. #GtkTreeview, it is better you use the
+ * hildon_pannable_area_scroll_to() function, you can calculate the
+ * position of the row using gtk_tree_view_get_background_area() and
+ * converting the coordinates with
+ * gtk_tree_view_convert_bin_window_to_tree_coords()
+ *
+ **/
+void
+hildon_pannable_area_jump_to_child (HildonPannableArea *area, GtkWidget *child)
+{
+ GtkWidget *bin_child;
+ gint x, y;
+
+ g_return_if_fail (HILDON_IS_PANNABLE_AREA (area));
+ g_return_if_fail (GTK_IS_WIDGET (child));
+ g_return_if_fail (gtk_widget_is_ancestor (child, GTK_WIDGET (area)));
+
+ /* We need to get to check the child of the alignment inside the
+ * area */
+ bin_child = GTK_BIN (GTK_BIN (area)->child)->child;
+
+ /* we check if we added a viewport */
+ if (GTK_IS_VIEWPORT (bin_child)) {
+ bin_child = GTK_BIN (bin_child)->child;
+ }
+
+ if (gtk_widget_translate_coordinates (child, bin_child, 0, 0, &x, &y))
+ hildon_pannable_area_jump_to (area, x, y);
+}
gdouble decel, guint sps);
void hildon_pannable_area_add_with_viewport (HildonPannableArea *area,
GtkWidget *child);
+void hildon_pannable_area_scroll_to (HildonPannableArea *area,
+ const gint x, const gint y);
+void hildon_pannable_area_jump_to (HildonPannableArea *area,
+ const gint x, const gint y);
+void hildon_pannable_area_scroll_to_child (HildonPannableArea *area,
+ GtkWidget *child);
+void hildon_pannable_area_jump_to_child (HildonPannableArea *area,
+ GtkWidget *child);
G_END_DECLS
#endif /* _HILDON_PANNABLE_AREA */
-