2 * This file is a part of hildon
4 * Copyright (C) 2005, 2008 Nokia Corporation.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free
18 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 * SECTION:hildon-touch-selector
23 * @short_description: A selector widget with several columns
25 * HildonTouchSelector is a selector widget, very similar to the #GtkComboBox, but with
26 * several individual pannable columns
36 #include "hildon-pannable-area.h"
37 #include "hildon-touch-selector.h"
39 #define HILDON_TOUCH_SELECTOR_GET_PRIVATE(obj) \
40 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), HILDON_TYPE_TOUCH_SELECTOR, HildonTouchSelectorPrivate))
42 G_DEFINE_TYPE (HildonTouchSelector, hildon_touch_selector, GTK_TYPE_VBOX)
44 #define CENTER_ON_SELECTED_ITEM_DELAY 50
47 * Struct to maintain the data of each column. The columns are the elements
48 * of the widget that belongs properly to the selection behaviour. As
49 * the selector contents are arranged in a #GtkHBox, you can add more widgets, like buttons etc.
50 * between the columns, but this doesn't belongs to the selection
53 typedef struct _SelectorColumn SelectorColumn;
54 struct _SelectorColumn
56 HildonTouchSelector *parent; /* the selector that contains this column */
58 GtkTreeView *tree_view;
60 GtkWidget *panarea; /* the pannable widget */
63 struct _HildonTouchSelectorPrivate
65 GSList *columns; /* the selection columns */
66 GtkWidget *hbox; /* the container for the selector's columns */
68 HildonTouchSelectorPrintFunc print_func;
77 static gint hildon_touch_selector_signals[LAST_SIGNAL] = { 0 };
80 static void hildon_touch_selector_map (GtkWidget * widget);
83 static void hildon_touch_selector_remove (GtkContainer * container,
85 /* private functions */
86 static void _selection_changed_cb (GtkTreeSelection * selection,
88 static gchar *_default_print_func (HildonTouchSelector * selector);
90 static SelectorColumn *_create_new_column (HildonTouchSelector * selector,
92 GtkCellRenderer * renderer,
94 static gboolean _hildon_touch_selector_center_on_selected_items (gpointer data);
97 hildon_touch_selector_class_init (HildonTouchSelectorClass * class)
99 GObjectClass *gobject_class;
100 GtkObjectClass *object_class;
101 GtkWidgetClass *widget_class;
102 GtkContainerClass *container_class;
104 gobject_class = (GObjectClass *) class;
105 object_class = (GtkObjectClass *) class;
106 widget_class = (GtkWidgetClass *) class;
107 container_class = (GtkContainerClass *) class;
112 widget_class->map = hildon_touch_selector_map;
115 container_class->remove = hildon_touch_selector_remove;
120 * HildonTouchSelector::changed:
121 * @widget: the object which received the signal
123 * The changed signal is emitted when the active
124 * item is changed. The can be due to the user selecting
125 * a different item from the list, or due to a
126 * call to hildon_touch_selector_set_active_iter() on
130 hildon_touch_selector_signals[CHANGED] =
131 g_signal_new ("changed",
132 G_OBJECT_CLASS_TYPE (class),
134 G_STRUCT_OFFSET (HildonTouchSelectorClass, changed),
136 gtk_marshal_NONE__INT, G_TYPE_NONE, 1, G_TYPE_INT);
139 /* style properties */
140 g_type_class_add_private (object_class, sizeof (HildonTouchSelectorPrivate));
145 hildon_touch_selector_init (HildonTouchSelector * selector)
147 selector->priv = HILDON_TOUCH_SELECTOR_GET_PRIVATE (selector);
149 GTK_WIDGET_SET_FLAGS (GTK_WIDGET (selector), GTK_NO_WINDOW);
150 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (selector), FALSE);
152 selector->priv->columns = NULL;
154 selector->priv->print_func = NULL;
155 selector->priv->hbox = gtk_hbox_new (FALSE, 0);
157 gtk_box_pack_end (GTK_BOX (selector), selector->priv->hbox,
159 gtk_widget_show (selector->priv->hbox);
161 /* FIXME: this is the correct height? A fixed height is the correct
163 gtk_widget_set_size_request (GTK_WIDGET (selector), -1, 320);
167 hildon_touch_selector_map (GtkWidget * widget)
169 GTK_WIDGET_CLASS (hildon_touch_selector_parent_class)->map (widget);
171 g_timeout_add (CENTER_ON_SELECTED_ITEM_DELAY,
172 _hildon_touch_selector_center_on_selected_items, widget);
175 /*------------------------------ GtkContainer ------------------------------ */
178 * Required in order to free the column at the columns list
181 hildon_touch_selector_remove (GtkContainer * container, GtkWidget * widget)
183 HildonTouchSelector *selector = NULL;
186 SelectorColumn *current_column = NULL;
187 gint num_columns = 0;
189 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (container));
191 selector = HILDON_TOUCH_SELECTOR (container);
192 num_columns = hildon_touch_selector_get_num_columns (selector);
194 /* Check if the widget is inside a column and remove
196 iter = selector->priv->columns;
199 current_column = (SelectorColumn *) iter->data;
200 if (widget == current_column->panarea) {
201 current_column = g_slist_nth_data (selector->priv->columns, position);
203 selector->priv->columns = g_slist_remove (selector->priv->columns,
205 g_free (current_column);
211 iter = g_slist_next (iter);
213 if (position >= num_columns) {
214 g_debug ("This widget was not inside the selector column");
217 GTK_CONTAINER_CLASS (hildon_touch_selector_parent_class)->remove (container, widget);
220 /* ------------------------------ PRIVATE METHODS ---------------------------- */
222 * default_print_func:
223 * @selector: a #HildonTouchSelector
225 * Default print function
227 * Returns: a new string that represent the selected items
230 _default_print_func (HildonTouchSelector * selector)
232 gchar *result = NULL;
234 gint num_columns = 0;
236 GtkTreeModel *model = NULL;
237 gchar *current_string = NULL;
239 HildonTouchSelectorSelectionMode mode;
241 GtkTreePath *current_path = NULL;
242 GList *selected_rows = NULL;
243 gint initial_value = 0;
245 num_columns = hildon_touch_selector_get_num_columns (selector);
247 mode = hildon_touch_selector_get_column_selection_mode (selector);
249 if ((mode == HILDON_TOUCH_SELECTOR_SELECTION_MODE_MULTIPLE)
250 && (num_columns > 0)) {
251 /* In this case we get the first column first */
252 selected_rows = hildon_touch_selector_get_selected_rows (selector, 0);
253 model = hildon_touch_selector_get_model (selector, 0);
255 result = g_strdup_printf ("(");
257 for (item = selected_rows; item; item = g_list_next (item)) {
258 current_path = item->data;
259 gtk_tree_model_get_iter (model, &iter, current_path);
261 gtk_tree_model_get (model, &iter, 0, ¤t_string, -1);
263 if (i < g_list_length (selected_rows) - 1) {
264 aux = g_strconcat (result, current_string, ",", NULL);
268 aux = g_strconcat (result, current_string, NULL);
275 aux = g_strconcat (result, ")", NULL);
279 g_list_foreach (selected_rows, (GFunc) (gtk_tree_path_free), NULL);
280 g_list_free (selected_rows);
286 for (i = initial_value; i < num_columns; i++) {
287 model = hildon_touch_selector_get_model (selector, i);
288 if (hildon_touch_selector_get_active_iter (selector, i, &iter)) {
290 gtk_tree_model_get (model, &iter, 0, ¤t_string, -1);
292 aux = g_strconcat (result, ":", current_string, NULL);
296 result = g_strdup_printf ("%s", current_string);
305 _selection_changed_cb (GtkTreeSelection * selection, gpointer user_data)
307 HildonTouchSelector *selector = NULL;
308 SelectorColumn *column = NULL;
309 gint num_column = -1;
311 column = (SelectorColumn *) user_data;
312 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (column->parent));
314 selector = column->parent;
316 num_column = g_slist_index (selector->priv->columns, column);
318 g_signal_emit (selector, hildon_touch_selector_signals[CHANGED], 0, num_column);
322 static SelectorColumn *
323 _create_new_column (HildonTouchSelector * selector,
324 GtkTreeModel * model,
325 GtkCellRenderer * renderer, va_list args)
327 SelectorColumn *new_column = NULL;
328 GtkTreeViewColumn *tree_column = NULL;
330 GtkTreeView *tv = NULL;
331 GtkWidget *panarea = NULL;
332 GtkTreeSelection *selection = NULL;
337 tree_column = gtk_tree_view_column_new ();
338 gtk_tree_view_column_pack_start (tree_column, renderer, TRUE);
340 attribute = va_arg (args, gchar *);
341 while (attribute != NULL) {
342 value = va_arg (args, gint);
343 gtk_tree_view_column_add_attribute (tree_column, renderer, attribute,
345 attribute = va_arg (args, gchar *);
348 tv = g_object_new (GTK_TYPE_TREE_VIEW, "model", model, "name", "fremantle-widget", /* FIXME: is this always this name? */
349 "hildon-ui-mode", HILDON_UI_MODE_EDIT,
350 "rules-hint", TRUE, NULL);
352 gtk_tree_view_append_column (GTK_TREE_VIEW (tv), tree_column);
354 new_column = (SelectorColumn *) g_malloc0 (sizeof (SelectorColumn));
355 new_column->parent = selector;
357 panarea = hildon_pannable_area_new ();
359 g_value_init (&val, G_TYPE_INT);
360 g_value_set_int (&val, HILDON_PANNABLE_AREA_INDICATOR_MODE_HIDE);
361 g_object_set_property (G_OBJECT (panarea), "vindicator-mode", &val);
363 g_value_unset (&val);
364 g_value_init (&val, G_TYPE_BOOLEAN);
365 g_value_set_boolean (&val, FALSE);
366 g_object_set_property (G_OBJECT (panarea), "initial-hint", &val);
368 gtk_container_add (GTK_CONTAINER (panarea), GTK_WIDGET (tv));
370 new_column->model = model;
371 new_column->tree_view = tv;
372 new_column->panarea = panarea;
374 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tv));
375 gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
377 /* select the first item */
378 if (gtk_tree_model_get_iter_first (model, &iter)) {
379 gtk_tree_selection_select_iter (selection, &iter);
382 gtk_widget_grab_focus (GTK_WIDGET (tv));
384 /* connect to the changed signal connection */
385 g_signal_connect (G_OBJECT (selection), "changed",
386 G_CALLBACK (_selection_changed_cb), new_column);
391 /* ------------------------------ PUBLIC METHODS ---------------------------- */
394 * hildon_touch_selector_new:
397 * Creates a new empty #HildonTouchSelector
399 * Returns: a new #HildonTouchSelector
402 hildon_touch_selector_new ()
404 return g_object_new (HILDON_TYPE_TOUCH_SELECTOR, NULL);
408 * hildon_touch_selector_new_text:
411 * Creates a #HildonTouchSelector with a single text column that
412 * can be populated conveniently through hildon_touch_selector_append_text(),
413 * hildon_touch_selector_prepend_text(), hildon_touch_selector_insert_text().
415 * Returns: A new #HildonTouchSelector
418 hildon_touch_selector_new_text (void)
423 selector = hildon_touch_selector_new ();
424 store = gtk_list_store_new (1, G_TYPE_STRING);
426 hildon_touch_selector_append_text_column (HILDON_TOUCH_SELECTOR (selector),
427 GTK_TREE_MODEL (store));
433 * hildon_touch_selector_append_text:
434 * @selector: A #HildonTouchSelector.
435 * @text: a non %NULL text string.
437 * Appends a new entry in a #HildonTouchSelector created with
438 * hildon_touch_selector_new_text().
441 hildon_touch_selector_append_text (HildonTouchSelector * selector,
447 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (selector));
448 g_return_if_fail (text != NULL);
450 model = hildon_touch_selector_get_model (HILDON_TOUCH_SELECTOR (selector), 0);
452 g_return_if_fail (GTK_IS_LIST_STORE (model));
454 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
455 gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, text, -1);
459 * hildon_touch_selector_prepend_text:
460 * @selector: A #HildonTouchSelector.
461 * @text: a non %NULL text string.
463 * Prepends a new entry in a #HildonTouchSelector created with
464 * hildon_touch_selector_new_text().
467 hildon_touch_selector_prepend_text (HildonTouchSelector * selector,
473 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (selector));
474 g_return_if_fail (text != NULL);
476 model = hildon_touch_selector_get_model (HILDON_TOUCH_SELECTOR (selector), 0);
478 g_return_if_fail (GTK_IS_LIST_STORE (model));
480 gtk_list_store_prepend (GTK_LIST_STORE (model), &iter);
481 gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, text, -1);
485 * hildon_touch_selector_insert_text:
486 * @selector: a #HildonTouchSelector.
487 * @position: the position to insert @text.
488 * @text: A non %NULL text string.
490 * Inserts a new entry in particular positio of a #HildoTouchSelector created
491 * with hildon_touch_selector_new_text().
495 hildon_touch_selector_insert_text (HildonTouchSelector * selector,
496 gint position, const gchar * text)
501 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (selector));
502 g_return_if_fail (text != NULL);
503 g_return_if_fail (position >= 0);
505 model = hildon_touch_selector_get_model (HILDON_TOUCH_SELECTOR (selector), 0);
507 g_return_if_fail (GTK_IS_LIST_STORE (model));
509 gtk_list_store_insert (GTK_LIST_STORE (model), &iter, position);
510 gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, text, -1);
514 * hildon_touch_selector_append_text_column
515 * @selector: the #HildonTouchSelector widget
516 * @model: the #GtkTreeModel with the data of the column
518 * This functions adds a new column to the widget, with the data on
519 * the model. Only the widgets added in this way should used on
520 * the selection logic, ie: the print function, the "changed" signal etc.
522 * There are a prerequisite on this model: this append
523 * consideres that the text data is in the first column of the model
525 * Basically it adds a tree view to the widget, using the model and
528 * Returns: TRUE if a new column were added, FALSE otherside
531 hildon_touch_selector_append_column (HildonTouchSelector * selector,
532 GtkTreeModel * model,
533 GtkCellRenderer * cell_renderer, ...)
536 SelectorColumn *new_column = NULL;
538 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), FALSE);
539 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), FALSE);
543 va_start (args, cell_renderer);
544 new_column = _create_new_column (selector, model, cell_renderer, args);
547 selector->priv->columns = g_slist_append (selector->priv->columns,
549 gtk_box_pack_start (GTK_BOX (selector->priv->hbox), new_column->panarea, TRUE, TRUE, 6);
551 gtk_widget_show_all (new_column->panarea);
560 * hildon_touch_selector_append_text_column
561 * @selector: the #HildonTouchSelector widget
562 * @model: the #GtkTreeModel with the data of the column
564 * Equivalent to hildon_touch_selector_append_column, but using a
565 * default text cell renderer. This is the most common use of the
568 * Returns: TRUE if a new column were added, FALSE otherside
571 hildon_touch_selector_append_text_column (HildonTouchSelector * selector,
572 GtkTreeModel * model)
574 GtkCellRenderer *renderer = NULL;
577 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), FALSE);
578 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), FALSE);
581 renderer = gtk_cell_renderer_text_new ();
583 g_value_init (&val, G_TYPE_FLOAT);
584 g_value_set_float (&val, 0.5);
585 /* FIXME: center the text, this should be configurable */
586 g_object_set_property (G_OBJECT (renderer), "xalign", &val);
588 return hildon_touch_selector_append_column (selector, model, renderer,
596 * hildon_touch_selector_remove_column
597 * @selector: a #HildonTouchSelector
598 * @position: the column position to remove, counting from 0 to (total column number - 1)
601 * Returns: TRUE is the column was removed, FALSE otherwise
604 hildon_touch_selector_remove_column (HildonTouchSelector * selector, gint position)
606 SelectorColumn *current_column = NULL;
608 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), FALSE);
609 g_return_val_if_fail (position <
610 hildon_touch_selector_get_num_columns (selector), FALSE);
612 current_column = g_slist_nth_data (selector->priv->columns, position);
614 gtk_container_remove (GTK_CONTAINER (selector), current_column->panarea);
620 hildon_touch_selector_set_column_attributes (HildonTouchSelector * selector,
622 GtkCellRenderer * cell_renderer,
626 GtkTreeViewColumn *tree_column = NULL;
627 SelectorColumn *current_column = NULL;
628 gchar *attribute = NULL;
631 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (selector));
632 g_return_if_fail (num_column <
633 hildon_touch_selector_get_num_columns (selector));
635 current_column = g_slist_nth_data (selector->priv->columns, num_column);
637 tree_column = gtk_tree_view_get_column (current_column->tree_view, 0);
638 gtk_tree_view_remove_column (current_column->tree_view, tree_column);
640 tree_column = gtk_tree_view_column_new ();
641 gtk_tree_view_column_pack_start (tree_column, cell_renderer, TRUE);
643 va_start (args, cell_renderer);
644 attribute = va_arg (args, gchar *);
646 gtk_tree_view_column_clear_attributes (tree_column, cell_renderer);
648 while (attribute != NULL) {
649 value = va_arg (args, gint);
650 gtk_tree_view_column_add_attribute (tree_column, cell_renderer,
652 attribute = va_arg (args, gchar *);
657 gtk_tree_view_append_column (current_column->tree_view, tree_column);
661 hildon_touch_selector_insert_column (HildonTouchSelector * selector, gint position)
663 g_warning ("Un-implemented!");
669 hildon_touch_selector_get_num_columns (HildonTouchSelector * selector)
671 return g_slist_length (selector->priv->columns);
674 HildonTouchSelectorSelectionMode
675 hildon_touch_selector_get_column_selection_mode (HildonTouchSelector * selector)
677 HildonTouchSelectorSelectionMode result =
678 HILDON_TOUCH_SELECTOR_SELECTION_MODE_SINGLE;
679 GtkSelectionMode treeview_mode = GTK_SELECTION_SINGLE;
680 SelectorColumn *column = NULL;
681 GtkTreeSelection *selection = NULL;
683 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), result);
684 g_return_val_if_fail (hildon_touch_selector_get_num_columns (selector) > 0,
687 column = (SelectorColumn *) selector->priv->columns->data;
689 selection = gtk_tree_view_get_selection (column->tree_view);
690 treeview_mode = gtk_tree_selection_get_mode (selection);
693 if (treeview_mode == GTK_SELECTION_MULTIPLE) {
694 result = HILDON_TOUCH_SELECTOR_SELECTION_MODE_MULTIPLE;
696 result = HILDON_TOUCH_SELECTOR_SELECTION_MODE_SINGLE;
703 hildon_touch_selector_set_column_selection_mode (HildonTouchSelector * selector,
704 HildonTouchSelectorSelectionMode
707 GtkTreeView *tv = NULL;
708 SelectorColumn *column = NULL;
709 GtkTreeSelection *selection = NULL;
710 GtkSelectionMode treeview_mode;
713 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (selector));
714 g_return_if_fail (hildon_touch_selector_get_num_columns (selector) > 0);
716 column = (SelectorColumn *) (g_slist_nth (selector->priv->columns, 0))->data;
717 tv = column->tree_view;
721 case HILDON_TOUCH_SELECTOR_SELECTION_MODE_SINGLE:
722 treeview_mode = GTK_SELECTION_SINGLE;
724 case HILDON_TOUCH_SELECTOR_SELECTION_MODE_MULTIPLE:
725 treeview_mode = GTK_SELECTION_MULTIPLE;
729 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tv));
730 gtk_tree_selection_set_mode (selection, treeview_mode);
732 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tv));
733 gtk_tree_model_get_iter_first (column->model, &iter);
734 gtk_tree_selection_unselect_all (selection);
735 gtk_tree_selection_select_iter (selection, &iter);
741 hildon_touch_selector_set_print_func (HildonTouchSelector * selector,
742 HildonTouchSelectorPrintFunc func)
744 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (selector));
746 selector->priv->print_func = func;
749 HildonTouchSelectorPrintFunc
750 hildon_touch_selector_get_print_func (HildonTouchSelector * selector)
752 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), NULL);
754 return selector->priv->print_func;
758 * hildon_touch_selector_get_active_iter:
759 * @selector: a #HildonTouchSelector
760 * @column: the column number we want to get the element
761 * @iter: #GtkTreeIter currently selected
763 * Sets iter to the currently selected node on the nth-column, if selection is set to
764 * HILDON_TOUCH_SELECTOR_SINGLE. iter may be NULL if you just want to test if selection
765 * has any selected nodes.
767 * This function will not work if you use selection is HILDON_TOUCH_SELECTOR_MULTIPLE.
769 * See gtk_tree_selection_get_selected for more information
771 * Returns: TRUE if was posible to get the iter, FALSE otherwise
774 hildon_touch_selector_get_active_iter (HildonTouchSelector * selector,
775 gint column, GtkTreeIter * iter)
777 GtkTreeSelection *selection = NULL;
778 SelectorColumn *current_column = NULL;
780 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), FALSE);
781 g_return_val_if_fail (hildon_touch_selector_get_column_selection_mode (selector)
782 == HILDON_TOUCH_SELECTOR_SELECTION_MODE_SINGLE, FALSE);
783 g_return_val_if_fail (column < hildon_touch_selector_get_num_columns (selector),
786 current_column = g_slist_nth_data (selector->priv->columns, column);
789 gtk_tree_view_get_selection (GTK_TREE_VIEW (current_column->tree_view));
791 return gtk_tree_selection_get_selected (selection, NULL, iter);
795 * hildon_touch_selector_set_active_iter
796 * @selector: a #HildonTouchSelector
797 * @column: the column to selects
798 * @iter: the #GtkTreeIter to be selected
800 * Sets the current iter
804 hildon_touch_selector_set_active_iter (HildonTouchSelector * selector,
805 gint column, GtkTreeIter * iter,
811 SelectorColumn *current_column = NULL;
812 GtkTreeSelection *selection = NULL;
815 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (selector));
816 g_return_if_fail (column < hildon_touch_selector_get_num_columns (selector));
818 current_column = g_slist_nth_data (selector->priv->columns, column);
820 selection = gtk_tree_view_get_selection (current_column->tree_view);
822 gtk_tree_selection_select_iter (selection, iter);
825 model = gtk_tree_view_get_model (current_column->tree_view);
826 path = gtk_tree_model_get_path (model, iter);
827 gtk_tree_view_get_background_area (current_column->tree_view,
829 gtk_tree_view_convert_bin_window_to_tree_coords (current_column->tree_view,
830 0, rect.y, NULL, &y);
831 hildon_pannable_area_scroll_to (HILDON_PANNABLE_AREA (current_column->panarea),
833 gtk_tree_path_free (path);
838 * hildon_touch_selector_get_selected_rows:
839 * @selector: a #HildonTouchSelector
842 * Creates a list of path of all selected rows at a concrete column. Additionally,
843 * if you are planning on modifying the model after calling this function, you may
844 * want to convert the returned list into a list of GtkTreeRowReferences. To do this,
845 * you can use gtk_tree_row_reference_new().
847 * See #GtkTreeSelection:gtk_tree_selection_get_selected_rows for more information
849 * Returns: A new GList containing a GtkTreePath for each selected row in the concrete column
853 hildon_touch_selector_get_selected_rows (HildonTouchSelector * selector,
856 GList *result = NULL;
857 SelectorColumn *current_column = NULL;
858 GtkTreeSelection *selection = NULL;
860 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), NULL);
861 g_return_val_if_fail (column < hildon_touch_selector_get_num_columns (selector),
864 current_column = g_slist_nth_data (selector->priv->columns, column);
865 selection = gtk_tree_view_get_selection (current_column->tree_view);
867 result = gtk_tree_selection_get_selected_rows (selection, NULL);
874 hildon_touch_selector_get_model (HildonTouchSelector * selector, gint column)
876 SelectorColumn *current_column = NULL;
878 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), NULL);
879 g_return_val_if_fail (column < hildon_touch_selector_get_num_columns (selector),
882 current_column = g_slist_nth_data (selector->priv->columns, column);
884 return current_column->model;
888 hildon_touch_selector_set_model (HildonTouchSelector * selector,
889 gint num_column, GtkTreeModel * model)
891 SelectorColumn *column = NULL;
893 g_return_if_fail (HILDON_TOUCH_SELECTOR (selector));
894 g_return_if_fail (num_column <
895 hildon_touch_selector_get_num_columns (selector));
898 (SelectorColumn *) g_slist_nth_data (selector->priv->columns, num_column);
900 column->model = model;
901 gtk_tree_view_set_model (column->tree_view, column->model);
905 * hildon_touch_selector_get_active_text
906 * @selector: the #HildonTouchSelector
908 * It return a new gchar that represents the current element(s) selected,
909 * using the current print_func.
911 * Returns: a new allocated gchar*
914 hildon_touch_selector_get_current_text (HildonTouchSelector * selector)
916 gchar *result = NULL;
917 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), NULL);
919 if (selector->priv->print_func) {
920 result = (*selector->priv->print_func) (selector);
922 result = _default_print_func (selector);
929 _hildon_touch_selector_center_on_selected_items (gpointer data)
931 HildonTouchSelector *selector = NULL;
932 SelectorColumn *column = NULL;
933 GSList *iter_column = NULL;
939 HildonTouchSelectorSelectionMode selection_mode;
941 /* ensure to center on the initial values */
942 selector = HILDON_TOUCH_SELECTOR (data);
944 selection_mode = hildon_touch_selector_get_column_selection_mode (selector);
946 iter_column = selector->priv->columns;
948 while (iter_column) {
949 column = (SelectorColumn *) iter_column->data;
952 && (selection_mode == HILDON_TOUCH_SELECTOR_SELECTION_MODE_MULTIPLE)) {
955 if (hildon_touch_selector_get_active_iter (selector, i, &iter)) {
956 path = gtk_tree_model_get_path (column->model, &iter);
957 gtk_tree_view_get_background_area (GTK_TREE_VIEW
958 (column->tree_view), path, NULL,
961 gtk_tree_view_convert_bin_window_to_tree_coords (GTK_TREE_VIEW
962 (column->tree_view), 0,
965 hildon_pannable_area_scroll_to (HILDON_PANNABLE_AREA
966 (column->panarea), -1, y);
968 gtk_tree_path_free (path);
970 iter_column = iter_column->next;