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, that allows users to
26 * select items from one to many predefined lists. It is very similar
27 * to #GtkComboBox, but with several individual pannable columns.
29 * Normally, you would use #HildonTouchSelector together with a
30 * #HildonPickerDialog activated from a button. For the most common
31 * cases, you should use #HildonPickerButton.
33 * The contents of each #HildonTouchSelector column are stored in a
34 * #GtkTreeModel. To add a new column to a #HildonTouchSelector, use
35 * hildon_touch_selector_append_column(). If you want to add a
36 * text-only column, without special attributes, use
37 * hildon_touch_selector_append_text_column().
39 * It is highly recommended that you use only one column
40 * #HildonTouchSelector<!-- -->s.
41 * If you only need a text only, one column selector, you can create it with
42 * hildon_touch_selector_new_text() and populate with
43 * hildon_touch_selector_append_text(), hildon_touch_selector_prepend_text(),
44 * and hildon_touch_selector_insert_text().
46 * If you need a selector widget that also accepts user inputs, you
47 * can use #HildonTouchSelectorEntry.
49 * The current selection has a string representation. In the most common cases,
50 * each column model will contain a text column. You can configure
51 * which column in particular using the #HildonTouchSelectorColumn property
52 * #HildonTouchSelectorColumn:text-column
54 * You can get this string representation using
55 * hildon_touch_selector_get_current_text().
56 * You can configure how the selection is printed with
57 * hildon_touch_selector_set_print_func(), that sets the current hildon touch
58 * selector print function. The widget has a default print function, that
59 * uses the #HildonTouchSelectorColumn:text-column property on each
60 * #HildonTouchSelectorColumn to compose the final representation.
62 * If you create the selector using hildon_touch_selector_new_text() you
63 * don't need to take care of this property, as the model is created internally.
64 * If you create the selector using hildon_touch_selector_new(), you
65 * need to specify properly the property for your custom model in order to get a
66 * non-empty string representation, or define your custom print function.
69 * <title>Creating a HildonTouchSelector</title>
72 * selection_changed (HildonTouchSelector * selector,
73 * gpointer *user_data)
75 * gchar *current_selection = NULL;
77 * current_selection = hildon_touch_selector_get_current_text (selector);
78 * g_debug ("Current selection : %s", current_selection);
82 * create_customized_selector ()
84 * GtkWidget *selector = NULL;
85 * GSList *icon_list = NULL;
86 * GtkListStore *store_icons = NULL;
87 * GSList *item = NULL;
88 * GtkCellRenderer *renderer = NULL;
89 * HildonTouchSelectorColumn *column = NULL;
91 * selector = hildon_touch_selector_new ();
93 * icon_list = gtk_stock_list_ids ();
95 * store_icons = gtk_list_store_new (1, G_TYPE_STRING);
96 * for (item = icon_list; item; item = g_slist_next (item)) {
98 * gchar *label = item->data;
100 * gtk_list_store_append (store_icons, &iter);
101 * gtk_list_store_set (store_icons, &iter, 0, label, -1);
104 * g_slist_free (icon_list);
106 * renderer = gtk_cell_renderer_pixbuf_new ();
107 * gtk_cell_renderer_set_fixed_size (renderer, -1, 100);
109 * column = hildon_touch_selector_append_column (HILDON_TOUCH_SELECTOR (selector),
110 * GTK_TREE_MODEL (store_icons),
111 * renderer, "stock-id", 0, NULL);
113 * hildon_touch_selector_column_set_text_column (column, 0);
115 * hildon_touch_selector_set_column_selection_mode (HILDON_TOUCH_SELECTOR (selector),
116 * HILDON_TOUCH_SELECTOR_SELECTION_MODE_MULTIPLE);
118 * g_signal_connect (G_OBJECT (selector), "changed",
119 * G_CALLBACK (selection_changed), NULL);
125 * create_simple_selector ()
127 * GtkWidget *selector = NULL;
130 * selector = hildon_touch_selector_new_text ();
131 * hildon_touch_selector_set_column_selection_mode (HILDON_TOUCH_SELECTOR (selector),
132 * HILDON_TOUCH_SELECTOR_SELECTION_MODE_MULTIPLE);
134 * g_signal_connect (G_OBJECT (selector), "changed",
135 * G_CALLBACK (selection_changed), NULL);
137 * for (i = 1; i <= 10 ; i++) {
138 * gchar *label = g_strdup_printf ("Item &percnt;d", i);
140 * hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector),
153 * SECTION:hildon-touch-selector-column
154 * @short_description: A visible column in a #HildonTouchSelector
155 * @see_also: #HildonTouchSelector
157 * A #HildonTouchSelectorColumn is a column in a
158 * #HildonTouchSelector. This class implements the #GtkCellLayout interface, allowing
159 * a flexible management of the cellrenderers in each #HildonTouchSelector column.
162 #undef HILDON_DISABLE_DEPRECATED
171 #include "hildon-gtk.h"
173 #include "hildon-pannable-area.h"
174 #include "hildon-touch-selector.h"
175 #include "hildon-touch-selector-private.h"
177 #define HILDON_TOUCH_SELECTOR_GET_PRIVATE(obj) \
178 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), HILDON_TYPE_TOUCH_SELECTOR, HildonTouchSelectorPrivate))
180 G_DEFINE_TYPE (HildonTouchSelector, hildon_touch_selector, GTK_TYPE_VBOX)
183 * IMPLEMENTATION NOTES:
184 * Struct to maintain the data of each column. The columns are the elements
185 * of the widget that belongs properly to the selection behaviour. Although
186 * internally the columns are arranged in a private #GtkHBox, as the selector
187 * itself is a #GtkVBox, you can add more widgets, like buttons etc., so
188 * you finally could have a widget with more elements that the columns, but
189 * this doesn't belongs to the selection logic
191 struct _HildonTouchSelectorColumnPrivate
193 HildonTouchSelector *parent; /* the selector that contains this column */
196 GtkTreeView *tree_view;
197 gulong realize_handler;
198 GtkTreePath *initial_path;
200 GtkWidget *panarea; /* the pannable widget */
201 GtkTreeRowReference *last_activated;
204 struct _HildonTouchSelectorPrivate
206 GSList *columns; /* the selection columns */
207 GtkWidget *hbox; /* the container for the selector's columns */
208 gboolean initial_scroll; /* whether initial fancy scrolling to selection */
210 gboolean changed_blocked;
212 HildonTouchSelectorPrintFunc print_func;
213 gpointer print_user_data;
214 GDestroyNotify print_destroy_func;
216 HildonUIMode hildon_ui_mode;
221 PROP_HAS_MULTIPLE_SELECTION = 1,
233 static gint hildon_touch_selector_signals[LAST_SIGNAL] = { 0 };
236 hildon_touch_selector_dispose (GObject * object);
239 hildon_touch_selector_get_property (GObject * object,
244 hildon_touch_selector_set_property (GObject *object,
251 static void hildon_touch_selector_remove (GtkContainer * container,
253 /* private functions */
254 static void _row_tapped_cb (GtkTreeView * tree_view,
258 hildon_touch_selector_row_activated_cb (GtkTreeView *tree_view,
260 GtkTreeViewColumn *column,
263 static gchar *_default_print_func (HildonTouchSelector * selector,
266 static HildonTouchSelectorColumn *_create_new_column (HildonTouchSelector * selector,
267 GtkTreeModel * model,
268 gboolean *emit_changed,
269 GtkCellRenderer * renderer,
272 on_realize_cb (GtkWidget *widget,
275 on_row_changed (GtkTreeModel *model,
281 hildon_touch_selector_scroll_to (HildonTouchSelectorColumn *column,
285 _hildon_touch_selector_center_on_selected_items (HildonTouchSelector *selector,
286 HildonTouchSelectorColumn *column);
288 _hildon_touch_selector_set_model (HildonTouchSelector * selector,
290 GtkTreeModel * model);
292 _hildon_touch_selector_has_multiple_selection (HildonTouchSelector * selector);
295 hildon_touch_selector_emit_value_changed (HildonTouchSelector *selector,
298 /* GtkCellLayout implementation (HildonTouchSelectorColumn)*/
299 static void hildon_touch_selector_column_cell_layout_init (GtkCellLayoutIface *iface);
301 static void hildon_touch_selector_column_cell_layout_pack_start (GtkCellLayout *cell_layout,
302 GtkCellRenderer *cell,
304 static void hildon_touch_selector_column_cell_layout_pack_end (GtkCellLayout *cell_layout,
305 GtkCellRenderer *cell,
307 static void hildon_touch_selector_column_cell_layout_clear (GtkCellLayout *cell_layout);
308 static void hildon_touch_selector_column_cell_layout_add_attribute(GtkCellLayout *cell_layout,
309 GtkCellRenderer *cell,
310 const gchar *attribute,
312 static void hildon_touch_selector_column_cell_layout_set_cell_data_func (GtkCellLayout *cell_layout,
313 GtkCellRenderer *cell,
314 GtkCellLayoutDataFunc func,
316 GDestroyNotify destroy);
317 static void hildon_touch_selector_column_cell_layout_clear_attributes (GtkCellLayout *cell_layout,
318 GtkCellRenderer *cell);
319 static void hildon_touch_selector_column_cell_layout_reorder (GtkCellLayout *cell_layout,
320 GtkCellRenderer *cell,
322 static GList *hildon_touch_selector_column_cell_layout_get_cells (GtkCellLayout *cell_layout);
325 hildon_touch_selector_check_ui_mode_coherence (HildonTouchSelector *selector);
328 hildon_touch_selector_class_init (HildonTouchSelectorClass * class)
330 GObjectClass *gobject_class;
331 GtkObjectClass *object_class;
332 GtkContainerClass *container_class;
334 gobject_class = G_OBJECT_CLASS (class);
335 object_class = GTK_OBJECT_CLASS (class);
336 container_class = GTK_CONTAINER_CLASS (class);
339 gobject_class->dispose = hildon_touch_selector_dispose;
340 gobject_class->get_property = hildon_touch_selector_get_property;
341 gobject_class->set_property = hildon_touch_selector_set_property;
346 container_class->remove = hildon_touch_selector_remove;
348 /* HildonTouchSelector */
349 class->changed = NULL;
350 class->set_model = _hildon_touch_selector_set_model;
352 class->has_multiple_selection = _hildon_touch_selector_has_multiple_selection;
356 * HildonTouchSelector::changed:
357 * @widget: the object which received the signal
358 * @column: the number of the column that has changed
360 * The "changed" signal is emitted when the active item on any column is changed.
361 * This can be due to the user selecting a different item from the list, or
362 * due to a call to hildon_touch_selector_select_iter() on one of the columns.
366 hildon_touch_selector_signals[CHANGED] =
367 g_signal_new ("changed",
368 G_OBJECT_CLASS_TYPE (class),
370 G_STRUCT_OFFSET (HildonTouchSelectorClass, changed),
372 g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT);
375 * HildonTouchSelector::columns-changed:
376 * @selector: the object which received the signal
378 * The "columns-changed" signal is emitted when the number
379 * of columns in the #HildonTouchSelector change.
383 hildon_touch_selector_signals[COLUMNS_CHANGED] =
384 g_signal_new ("columns-changed",
385 G_OBJECT_CLASS_TYPE (class),
386 G_SIGNAL_RUN_LAST, 0,
388 g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
392 g_object_class_install_property (gobject_class, PROP_HAS_MULTIPLE_SELECTION,
393 g_param_spec_boolean ("has-multiple-selection",
394 "has multiple selection",
395 "Whether the widget has multiple "
396 "selection (like multiple columns, "
397 "multiselection mode, or multiple "
398 "internal widgets) and therefore "
399 "it may need a confirmation button, "
404 g_object_class_install_property (G_OBJECT_CLASS (gobject_class),
406 g_param_spec_boolean ("initial-scroll",
408 "Whether to scroll to the"
409 "current selection when"
410 "the selector is first"
413 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
416 * HildonTouchSelector:hildon-ui-mode:
418 * Specifies which UI mode to use in the internal treeviews. A setting
419 * of %HILDON_UI_MODE_NORMAL will cause these tree view to disable selections
420 * and emit row-activated as soon as a row is pressed. You can use the
421 * method hildon_touch_selector_get_last_activated_row() to get it. When
422 * %HILDON_UI_MODE_EDIT is set, selections can be made according to the
423 * setting of the mode on GtkTreeSelection.
425 * Toggling this property will cause the tree view to select an
426 * appropriate selection mode if not already done.
430 g_object_class_install_property (gobject_class,
432 g_param_spec_enum ("hildon-ui-mode",
434 "The Hildon UI mode according "
435 "to which the touch selector "
440 /* style properties */
441 /* We need to ensure fremantle mode for the treeview in order to work
442 properly. This is not about the appearance, this is about behaviour */
443 gtk_rc_parse_string ("style \"fremantle-htst\" {\n"
444 " GtkWidget::hildon-mode = 1\n"
445 "} widget \"*.fremantle-htst\" style \"fremantle-htst\""
446 "widget_class \"*<HildonPannableArea>.GtkTreeView\" style :highest \"fremantle-htst\"");
448 g_type_class_add_private (object_class, sizeof (HildonTouchSelectorPrivate));
452 hildon_touch_selector_get_property (GObject * object,
454 GValue * value, GParamSpec * pspec)
456 HildonTouchSelectorPrivate *priv = HILDON_TOUCH_SELECTOR (object)->priv;
459 case PROP_HAS_MULTIPLE_SELECTION:
460 g_value_set_boolean (value,
461 hildon_touch_selector_has_multiple_selection (HILDON_TOUCH_SELECTOR (object)));
463 case PROP_INITIAL_SCROLL:
464 g_value_set_boolean (value, priv->initial_scroll);
466 case PROP_HILDON_UI_MODE:
467 g_value_set_enum (value, priv->hildon_ui_mode);
470 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
476 hildon_touch_selector_set_property (GObject *object, guint prop_id,
477 const GValue *value, GParamSpec *pspec)
479 HildonTouchSelectorPrivate *priv = HILDON_TOUCH_SELECTOR (object)->priv;
482 case PROP_INITIAL_SCROLL:
483 priv->initial_scroll = g_value_get_boolean (value);
485 case PROP_HILDON_UI_MODE:
486 hildon_touch_selector_set_hildon_ui_mode (HILDON_TOUCH_SELECTOR (object),
487 g_value_get_enum (value));
490 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
497 hildon_touch_selector_init (HildonTouchSelector * selector)
499 selector->priv = HILDON_TOUCH_SELECTOR_GET_PRIVATE (selector);
501 GTK_WIDGET_SET_FLAGS (GTK_WIDGET (selector), GTK_NO_WINDOW);
502 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (selector), FALSE);
504 selector->priv->columns = NULL;
506 selector->priv->print_func = NULL;
507 selector->priv->print_user_data = NULL;
508 selector->priv->print_destroy_func = NULL;
509 selector->priv->initial_scroll = TRUE;
510 selector->priv->hbox = gtk_hbox_new (FALSE, 0);
512 selector->priv->changed_blocked = FALSE;
514 selector->priv->hildon_ui_mode = HILDON_UI_MODE_EDIT;
516 gtk_box_pack_end (GTK_BOX (selector), selector->priv->hbox,
518 gtk_widget_show (selector->priv->hbox);
522 hildon_touch_selector_dispose (GObject * object)
524 GObjectClass *gobject_class;
526 hildon_touch_selector_set_print_func_full (HILDON_TOUCH_SELECTOR (object),
529 gobject_class = G_OBJECT_CLASS (hildon_touch_selector_parent_class);
531 if (gobject_class->dispose)
532 (* gobject_class->dispose) (object);
536 clean_column (HildonTouchSelectorColumn *col,
537 HildonTouchSelector *selector)
539 g_signal_handlers_disconnect_by_func (col->priv->model,
540 on_row_changed, selector);
542 if (col->priv->last_activated != NULL) {
543 gtk_tree_row_reference_free (col->priv->last_activated);
544 col->priv->last_activated = NULL;
549 * IMPLEMENTATION NOTES:
550 * Some people sent questions regarding the fact that the dispose/finalize functions
551 * doesn't clean the internal widgets that could lead to leak memory, so we will
552 * clarify this topic.
554 * This is not required as #HildonTouchSelector extends #GtkContainer. When the
555 * widget is freed, the #GtkContainer freeing memory functions are called. This
556 * process includes remove each widget individually, so all the widgets are
559 * In the same way, this widget redefines gtk_container->remove function, in
560 * order to free the column related information if it is required.
562 * Please take a look to hildon_touch_selector_remove for more information.
565 /*------------------------------ GtkContainer ------------------------------ */
568 * Required in order to free the column at the columns list
571 hildon_touch_selector_remove (GtkContainer * container, GtkWidget * widget)
573 HildonTouchSelector *selector = NULL;
575 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (container));
576 selector = HILDON_TOUCH_SELECTOR (container);
578 /* Remove the extra data related to the columns, if required. */
579 if (widget == selector->priv->hbox) {
580 g_slist_foreach (selector->priv->columns, (GFunc) clean_column, selector);
581 g_slist_foreach (selector->priv->columns, (GFunc) g_object_unref, NULL);
583 g_slist_free (selector->priv->columns);
585 selector->priv->columns = NULL;
587 g_debug ("Freeing a widget outside the columns logic");
590 /* Now remove the widget itself from the container */
591 GTK_CONTAINER_CLASS (hildon_touch_selector_parent_class)->remove (container, widget);
594 /* ------------------------------ PRIVATE METHODS ---------------------------- */
596 hildon_touch_selector_block_changed (HildonTouchSelector *selector)
598 selector->priv->changed_blocked = TRUE;
602 hildon_touch_selector_unblock_changed (HildonTouchSelector *selector)
604 selector->priv->changed_blocked = FALSE;
608 hildon_touch_selector_emit_value_changed (HildonTouchSelector *selector,
611 /* FIXME: it could be good to emit too the GtkTreePath of the element
612 selected, as now it is required to connect to the signal and then ask
613 for the element selected. We can't do this API change, in order to avoid
615 if (!selector->priv->changed_blocked) {
616 g_signal_emit (selector, hildon_touch_selector_signals[CHANGED], 0, column);
621 hildon_touch_selector_check_ui_mode_coherence (HildonTouchSelector *selector)
623 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (selector));
625 if (hildon_touch_selector_get_num_columns (selector) > 1) {
626 hildon_touch_selector_set_hildon_ui_mode (selector, HILDON_UI_MODE_EDIT);
631 * default_print_func:
632 * @selector: a #HildonTouchSelector
634 * Default print function
636 * Returns: a new string that represents the selected items
641 _default_print_func (HildonTouchSelector * selector, gpointer user_data)
643 gchar *result = NULL;
645 gint num_columns = 0;
647 GtkTreeModel *model = NULL;
648 gchar *current_string = NULL;
650 HildonTouchSelectorSelectionMode mode;
652 GtkTreePath *current_path = NULL;
653 GList *selected_rows = NULL;
654 gint initial_value = 0;
655 gint text_column = -1;
656 HildonTouchSelectorColumn *column = NULL;
658 num_columns = hildon_touch_selector_get_num_columns (selector);
660 mode = hildon_touch_selector_get_column_selection_mode (selector);
662 if ((mode == HILDON_TOUCH_SELECTOR_SELECTION_MODE_MULTIPLE)
663 && (num_columns > 0)) {
664 /* In this case we get the first column first */
665 selected_rows = hildon_touch_selector_get_selected_rows (selector, 0);
666 model = hildon_touch_selector_get_model (selector, 0);
667 column = hildon_touch_selector_get_column (selector, 0);
668 text_column = hildon_touch_selector_column_get_text_column (column);
670 result = g_strdup_printf ("(");
672 for (item = selected_rows; item; item = g_list_next (item)) {
673 current_path = item->data;
674 gtk_tree_model_get_iter (model, &iter, current_path);
676 if (text_column != -1) {
677 gtk_tree_model_get (model, &iter, text_column, ¤t_string, -1);
680 if (i < g_list_length (selected_rows) - 1) {
681 aux = g_strconcat (result, current_string, ",", NULL);
685 aux = g_strconcat (result, current_string, NULL);
690 if (current_string) {
691 g_free (current_string);
692 current_string = NULL;
698 aux = g_strconcat (result, ")", NULL);
702 g_list_foreach (selected_rows, (GFunc) (gtk_tree_path_free), NULL);
703 g_list_free (selected_rows);
709 for (i = initial_value; i < num_columns; i++) {
710 model = hildon_touch_selector_get_model (selector, i);
711 column = hildon_touch_selector_get_column (selector, i);
712 text_column = hildon_touch_selector_column_get_text_column (column);
714 if (hildon_touch_selector_get_selected (selector, i, &iter)) {
715 if (text_column == -1 ) {
716 g_warning ("Trying to use the default print function in HildonTouchSelector, but "
717 "\"text-column\" property is not set for HildonTouchSelectorColumn %p.", column);
718 current_string = NULL;
720 gtk_tree_model_get (model, &iter, text_column, ¤t_string, -1);
724 result = current_string;
726 aux = g_strconcat (result, ":", current_string, NULL);
728 g_free (current_string);
729 current_string = NULL;
739 hildon_touch_selector_row_activated_cb (GtkTreeView *tree_view,
741 GtkTreeViewColumn *column,
744 HildonTouchSelectorColumn *selector_column = NULL;
745 GtkTreeModel *model = NULL;
747 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR_COLUMN (user_data));
748 selector_column = HILDON_TOUCH_SELECTOR_COLUMN (user_data);
750 model = selector_column->priv->model;
752 if (selector_column->priv->last_activated != NULL) {
753 gtk_tree_row_reference_free (selector_column->priv->last_activated);
756 selector_column->priv->last_activated = gtk_tree_row_reference_new (model, path);
760 _row_tapped_cb (GtkTreeView * tree_view, GtkTreePath * path, gpointer user_data)
762 HildonTouchSelector *selector = NULL;
763 HildonTouchSelectorColumn *column = NULL;
764 gint num_column = -1;
766 column = HILDON_TOUCH_SELECTOR_COLUMN (user_data);
767 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (column->priv->parent));
769 selector = column->priv->parent;
771 num_column = g_slist_index (selector->priv->columns, column);
773 hildon_touch_selector_emit_value_changed (selector, num_column);
777 static HildonTouchSelectorColumn *
778 _create_new_column (HildonTouchSelector * selector,
779 GtkTreeModel * model,
780 gboolean *emit_changed,
781 GtkCellRenderer * renderer, va_list args)
783 HildonTouchSelectorColumn *new_column = NULL;
784 GtkTreeViewColumn *tree_column = NULL;
785 GtkTreeView *tv = NULL;
786 GtkWidget *panarea = NULL;
787 GtkTreeSelection *selection = NULL;
792 tree_column = gtk_tree_view_column_new ();
794 if (renderer != NULL) {
795 gtk_tree_view_column_pack_start (tree_column, renderer, TRUE);
797 attribute = va_arg (args, gchar *);
798 while (attribute != NULL) {
799 value = va_arg (args, gint);
800 gtk_tree_view_column_add_attribute (tree_column, renderer, attribute,
802 attribute = va_arg (args, gchar *);
807 tv = GTK_TREE_VIEW (hildon_gtk_tree_view_new (selector->priv->hildon_ui_mode));
809 tv = GTK_TREE_VIEW (gtk_tree_view_new ());
810 #endif /* MAEMO_GTK */
812 gtk_tree_view_set_enable_search (tv, FALSE);
813 GTK_WIDGET_UNSET_FLAGS (GTK_WIDGET (tv), GTK_CAN_FOCUS);
815 gtk_tree_view_set_model (tv, model);
816 g_signal_connect (model, "row-changed",
817 G_CALLBACK (on_row_changed), selector);
818 gtk_tree_view_set_rules_hint (tv, TRUE);
820 gtk_tree_view_append_column (GTK_TREE_VIEW (tv), tree_column);
822 new_column = g_object_new (HILDON_TYPE_TOUCH_SELECTOR_COLUMN, NULL);
823 new_column->priv->parent = selector;
825 panarea = hildon_pannable_area_new ();
827 g_object_set (G_OBJECT (panarea),
828 "initial-hint", FALSE, NULL);
830 gtk_container_add (GTK_CONTAINER (panarea), GTK_WIDGET (tv));
832 new_column->priv->model = model;
833 new_column->priv->tree_view = tv;
834 new_column->priv->panarea = panarea;
835 new_column->priv->realize_handler = 0;
836 new_column->priv->initial_path = NULL;
838 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tv));
839 gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
841 /* select the first item */
842 *emit_changed = FALSE;
843 if ((gtk_tree_model_get_iter_first (model, &iter))&&
844 (selector->priv->hildon_ui_mode == HILDON_UI_MODE_EDIT)) {
845 gtk_tree_selection_select_iter (selection, &iter);
846 *emit_changed = TRUE;
849 gtk_widget_grab_focus (GTK_WIDGET (tv));
851 /* connect to the hildon-row-tapped signal connection */
852 g_signal_connect (G_OBJECT (tv), "hildon-row-tapped",
853 G_CALLBACK (_row_tapped_cb), new_column);
855 g_signal_connect (G_OBJECT (tv), "row-activated",
856 G_CALLBACK (hildon_touch_selector_row_activated_cb), new_column);
862 /* ------------------------ HildonTouchSelectorColumn implementation ---------------------- */
863 G_DEFINE_TYPE_WITH_CODE (HildonTouchSelectorColumn, hildon_touch_selector_column, G_TYPE_OBJECT,
864 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
865 hildon_touch_selector_column_cell_layout_init))
873 hildon_touch_selector_column_class_init (HildonTouchSelectorColumnClass *klass);
876 hildon_touch_selector_column_get_property (GObject *object, guint property_id,
877 GValue *value, GParamSpec *pspec);
880 hildon_touch_selector_column_set_property (GObject *object, guint property_id,
881 const GValue *value, GParamSpec *pspec);
885 hildon_touch_selector_column_class_init (HildonTouchSelectorColumnClass *klass)
887 GObjectClass *gobject_class = NULL;
889 gobject_class = G_OBJECT_CLASS (klass);
891 g_type_class_add_private (gobject_class, sizeof (HildonTouchSelectorColumnPrivate));
894 gobject_class->get_property = hildon_touch_selector_column_get_property;
895 gobject_class->set_property = hildon_touch_selector_column_set_property;
898 * HildonTouchSelectorColumn:text-column:
900 * A column in the data source model to get the strings from.
904 g_object_class_install_property (G_OBJECT_CLASS(klass),
906 g_param_spec_int ("text-column",
908 "A column in the data source model to get the strings from.",
916 hildon_touch_selector_column_init (HildonTouchSelectorColumn *column)
918 column->priv = G_TYPE_INSTANCE_GET_PRIVATE (column, HILDON_TYPE_TOUCH_SELECTOR_COLUMN,
919 HildonTouchSelectorColumnPrivate);
920 column->priv->text_column = -1;
921 column->priv->last_activated = NULL;
925 * hildon_touch_selector_column_set_text_column:
926 * @column: A #HildonTouchSelectorColumn
927 * @text_column: the index of a model column in the model for @column.
929 * Sets the model column to be displayed in @column. @text_column must point to a
930 * column in the model used with type %G_TYPE_STRING. Initially, this property
931 * is unset. You should set it before using the #HildonTouchSelector that uses
937 hildon_touch_selector_column_set_text_column (HildonTouchSelectorColumn *column,
940 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR_COLUMN (column));
941 g_return_if_fail (text_column >= -1);
943 column->priv->text_column = text_column;
945 g_object_notify (G_OBJECT (column), "text-column");
949 * hildon_touch_selector_column_get_text_column:
950 * @column: a #HildonTouchSelectorColumn
952 * Gets the model column set as the text source for @column.
954 * Returns: the index of the text column for @column, or -1 if unset.
959 hildon_touch_selector_column_get_text_column (HildonTouchSelectorColumn *column)
961 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR_COLUMN (column), -1);
963 return column->priv->text_column;
967 hildon_touch_selector_column_get_property (GObject *object, guint property_id,
968 GValue *value, GParamSpec *pspec)
970 switch (property_id) {
971 case PROP_TEXT_COLUMN:
972 g_value_set_int (value,
973 hildon_touch_selector_column_get_text_column (HILDON_TOUCH_SELECTOR_COLUMN (object)));
976 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
981 hildon_touch_selector_column_set_property (GObject *object, guint property_id,
982 const GValue *value, GParamSpec *pspec)
984 switch (property_id) {
985 case PROP_TEXT_COLUMN:
986 hildon_touch_selector_column_set_text_column (HILDON_TOUCH_SELECTOR_COLUMN (object),
987 g_value_get_int (value));
990 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
994 /* ------------------------ GtkCellLayout implementation -------------------- */
996 hildon_touch_selector_column_cell_layout_init (GtkCellLayoutIface *iface)
998 iface->pack_start = hildon_touch_selector_column_cell_layout_pack_start;
999 iface->pack_end = hildon_touch_selector_column_cell_layout_pack_end;
1000 iface->clear = hildon_touch_selector_column_cell_layout_clear;
1001 iface->add_attribute = hildon_touch_selector_column_cell_layout_add_attribute;
1002 iface->set_cell_data_func = hildon_touch_selector_column_cell_layout_set_cell_data_func;
1003 iface->clear_attributes = hildon_touch_selector_column_cell_layout_clear_attributes;
1004 iface->reorder = hildon_touch_selector_column_cell_layout_reorder;
1005 iface->get_cells = hildon_touch_selector_column_cell_layout_get_cells;
1009 hildon_touch_selector_column_cell_layout_pack_start (GtkCellLayout *cell_layout,
1010 GtkCellRenderer *cell,
1013 HildonTouchSelectorColumn *sel_column = NULL;
1014 GtkTreeViewColumn *view_column = NULL;
1016 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR_COLUMN (cell_layout));
1017 sel_column = HILDON_TOUCH_SELECTOR_COLUMN (cell_layout);
1019 view_column = gtk_tree_view_get_column (sel_column->priv->tree_view, 0);
1021 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT(view_column), cell, expand);
1026 hildon_touch_selector_column_cell_layout_pack_end (GtkCellLayout *cell_layout,
1027 GtkCellRenderer *cell,
1030 HildonTouchSelectorColumn *sel_column = NULL;
1031 GtkTreeViewColumn *view_column = NULL;
1033 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR_COLUMN (cell_layout));
1034 sel_column = HILDON_TOUCH_SELECTOR_COLUMN (cell_layout);
1036 view_column = gtk_tree_view_get_column (sel_column->priv->tree_view, 0);
1038 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT(view_column), cell, expand);
1042 hildon_touch_selector_column_cell_layout_clear (GtkCellLayout *cell_layout)
1044 HildonTouchSelectorColumn *sel_column = NULL;
1045 GtkTreeViewColumn *view_column = NULL;
1047 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR_COLUMN (cell_layout));
1048 sel_column = HILDON_TOUCH_SELECTOR_COLUMN (cell_layout);
1050 view_column = gtk_tree_view_get_column (sel_column->priv->tree_view, 0);
1052 gtk_cell_layout_clear (GTK_CELL_LAYOUT(view_column));
1056 hildon_touch_selector_column_cell_layout_add_attribute (GtkCellLayout *cell_layout,
1057 GtkCellRenderer *cell,
1058 const gchar *attribute,
1061 HildonTouchSelectorColumn *sel_column = NULL;
1062 GtkTreeViewColumn *view_column = NULL;
1064 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR_COLUMN (cell_layout));
1065 sel_column = HILDON_TOUCH_SELECTOR_COLUMN (cell_layout);
1067 view_column = gtk_tree_view_get_column (sel_column->priv->tree_view, 0);
1069 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT(view_column), cell, attribute, column);
1074 hildon_touch_selector_column_cell_layout_set_cell_data_func (GtkCellLayout *cell_layout,
1075 GtkCellRenderer *cell,
1076 GtkCellLayoutDataFunc func,
1078 GDestroyNotify destroy)
1080 HildonTouchSelectorColumn *sel_column = NULL;
1081 GtkTreeViewColumn *view_column = NULL;
1083 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR_COLUMN (cell_layout));
1084 sel_column = HILDON_TOUCH_SELECTOR_COLUMN (cell_layout);
1086 view_column = gtk_tree_view_get_column (sel_column->priv->tree_view, 0);
1088 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT(view_column), cell, func,
1089 func_data, destroy);
1093 hildon_touch_selector_column_cell_layout_clear_attributes (GtkCellLayout *cell_layout,
1094 GtkCellRenderer *cell)
1096 HildonTouchSelectorColumn *sel_column = NULL;
1097 GtkTreeViewColumn *view_column = NULL;
1099 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR_COLUMN (cell_layout));
1100 sel_column = HILDON_TOUCH_SELECTOR_COLUMN (cell_layout);
1102 view_column = gtk_tree_view_get_column (sel_column->priv->tree_view, 0);
1104 gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (view_column), cell);
1108 hildon_touch_selector_column_cell_layout_reorder (GtkCellLayout *cell_layout,
1109 GtkCellRenderer *cell,
1112 HildonTouchSelectorColumn *sel_column = NULL;
1113 GtkTreeViewColumn *view_column = NULL;
1115 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR_COLUMN (cell_layout));
1116 sel_column = HILDON_TOUCH_SELECTOR_COLUMN (cell_layout);
1118 view_column = gtk_tree_view_get_column (sel_column->priv->tree_view, 0);
1120 gtk_cell_layout_reorder (GTK_CELL_LAYOUT(view_column), cell, position);
1124 hildon_touch_selector_column_cell_layout_get_cells (GtkCellLayout *cell_layout)
1126 HildonTouchSelectorColumn *sel_column = NULL;
1127 GtkTreeViewColumn *view_column = NULL;
1129 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR_COLUMN (cell_layout), NULL);
1130 sel_column = HILDON_TOUCH_SELECTOR_COLUMN (cell_layout);
1132 view_column = gtk_tree_view_get_column (sel_column->priv->tree_view, 0);
1134 return gtk_cell_layout_get_cells (GTK_CELL_LAYOUT(view_column));
1137 /* ------------------------------ PUBLIC METHODS ---------------------------- */
1140 * hildon_touch_selector_new:
1142 * Creates a new empty #HildonTouchSelector.
1144 * Returns: a new #HildonTouchSelector.
1149 hildon_touch_selector_new (void)
1151 return g_object_new (HILDON_TYPE_TOUCH_SELECTOR, NULL);
1155 * hildon_touch_selector_new_text:
1157 * Creates a #HildonTouchSelector with a single text column that
1158 * can be populated conveniently through hildon_touch_selector_append_text(),
1159 * hildon_touch_selector_prepend_text(), hildon_touch_selector_insert_text().
1161 * Returns: A new #HildonTouchSelector
1166 hildon_touch_selector_new_text (void)
1168 GtkWidget *selector;
1169 GtkListStore *store;
1170 HildonTouchSelectorColumn *column = NULL;
1172 selector = hildon_touch_selector_new ();
1173 store = gtk_list_store_new (1, G_TYPE_STRING);
1175 column = hildon_touch_selector_append_text_column (HILDON_TOUCH_SELECTOR (selector),
1176 GTK_TREE_MODEL (store), TRUE);
1178 hildon_touch_selector_column_set_text_column (column, 0);
1184 * hildon_touch_selector_append_text:
1185 * @selector: A #HildonTouchSelector.
1186 * @text: a non %NULL text string.
1188 * Appends a new entry in a #HildonTouchSelector created with
1189 * hildon_touch_selector_new_text().
1194 hildon_touch_selector_append_text (HildonTouchSelector * selector,
1198 GtkTreeModel *model;
1200 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (selector));
1201 g_return_if_fail (text != NULL);
1203 model = hildon_touch_selector_get_model (HILDON_TOUCH_SELECTOR (selector), 0);
1205 g_return_if_fail (GTK_IS_LIST_STORE (model));
1207 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1208 gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, text, -1);
1212 * hildon_touch_selector_prepend_text:
1213 * @selector: A #HildonTouchSelector.
1214 * @text: a non %NULL text string.
1216 * Prepends a new entry in a #HildonTouchSelector created with
1217 * hildon_touch_selector_new_text().
1222 hildon_touch_selector_prepend_text (HildonTouchSelector * selector,
1226 GtkTreeModel *model;
1228 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (selector));
1229 g_return_if_fail (text != NULL);
1231 model = hildon_touch_selector_get_model (HILDON_TOUCH_SELECTOR (selector), 0);
1233 g_return_if_fail (GTK_IS_LIST_STORE (model));
1235 gtk_list_store_prepend (GTK_LIST_STORE (model), &iter);
1236 gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, text, -1);
1240 * hildon_touch_selector_insert_text:
1241 * @selector: a #HildonTouchSelector.
1242 * @position: the position to insert @text.
1243 * @text: A non %NULL text string.
1245 * Inserts a new entry in a particular position of a
1246 * #HildonTouchSelector created with hildon_touch_selector_new_text().
1251 hildon_touch_selector_insert_text (HildonTouchSelector * selector,
1252 gint position, const gchar * text)
1255 GtkTreeModel *model;
1257 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (selector));
1258 g_return_if_fail (text != NULL);
1259 g_return_if_fail (position >= 0);
1261 model = hildon_touch_selector_get_model (HILDON_TOUCH_SELECTOR (selector), 0);
1263 g_return_if_fail (GTK_IS_LIST_STORE (model));
1265 gtk_list_store_insert (GTK_LIST_STORE (model), &iter, position);
1266 gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, text, -1);
1270 * hildon_touch_selector_append_column
1271 * @selector: a #HildonTouchSelector
1272 * @model: the #GtkTreeModel with the data of the column
1273 * @cell_renderer: The #GtkCellRenderer where to draw each row contents.
1274 * @Varargs: a %NULL-terminated pair of attributes and column numbers.
1276 * This functions adds a new column to the widget, whose data will
1277 * be obtained from the model. Only widgets added this way should used on
1278 * the selection logic, the print function, the #HildonTouchSelector::changed
1279 * signal, etc. Internally, a #GtkTreeView will be added to the widget, using
1280 * @model as the data source.
1282 * You can optionally pass a #GtkCellRenderer in @cell_renderer,
1283 * together with a %NULL-terminated list of pairs property/value, in
1284 * the same way you would use gtk_tree_view_column_set_attributes().
1285 * This will pack @cell_renderer at the start of the column, expanded
1286 * by default. If you prefer not to add it this way, you can simply
1287 * pass %NULL to @cell_renderer and use the #GtkCellLayout interface
1288 * on the returned #HildonTouchSelectorColumn to set your
1289 * renderers. Please note that the returned #HildonTouchSelectorColumn
1290 * is owned by @selector, you shouldn't unref it after setting it
1293 * Initially, the returned #HildonTouchSelectorColumn will have its
1294 * #HildonTouchSelectorColumn:text-column property unset. You should set
1295 * it to a column in @model with type %G_TYPE_STRING. See
1296 * hildon_touch_selector_column_set_text_column().
1298 * This method could change the current #HildonTouchSelector:hildon-ui-mode.
1299 * %HILDON_UI_MODE_NORMAL is only allowed with one column, so if the selector
1300 * is in this mode, and a additional column is added,
1301 * #HildonTouchSelector:hildon-ui-mode will change to %HILDON_UI_MODE_EDIT.
1303 * Returns: the new column added added, %NULL otherwise.
1308 HildonTouchSelectorColumn*
1309 hildon_touch_selector_append_column (HildonTouchSelector * selector,
1310 GtkTreeModel * model,
1311 GtkCellRenderer * cell_renderer, ...)
1314 HildonTouchSelectorColumn *new_column = NULL;
1315 gboolean emit_changed = FALSE;
1318 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), NULL);
1319 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL);
1321 if (model != NULL) {
1323 va_start (args, cell_renderer);
1324 new_column = _create_new_column (selector, model, &emit_changed, cell_renderer, args);
1327 selector->priv->columns = g_slist_append (selector->priv->columns,
1329 gtk_box_pack_start (GTK_BOX (selector->priv->hbox),
1330 new_column->priv->panarea,
1333 gtk_widget_show_all (new_column->priv->panarea);
1335 if (selector->priv->initial_scroll) {
1336 _hildon_touch_selector_center_on_selected_items (selector, new_column);
1343 g_signal_emit (selector, hildon_touch_selector_signals[COLUMNS_CHANGED], 0);
1345 colnum = g_slist_length (selector->priv->columns);
1346 hildon_touch_selector_emit_value_changed (selector, colnum);
1349 hildon_touch_selector_check_ui_mode_coherence (selector);
1355 * hildon_touch_selector_append_text_column
1356 * @selector: a #HildonTouchSelector
1357 * @model: a #GtkTreeModel with data for the column
1358 * @center: whether to center the text on the column
1360 * Equivalent to hildon_touch_selector_append_column(), but using a
1361 * default text cell renderer. This is the most common use case of the
1364 * Returns: the new column added, NULL otherwise.
1368 HildonTouchSelectorColumn*
1369 hildon_touch_selector_append_text_column (HildonTouchSelector * selector,
1370 GtkTreeModel * model, gboolean center)
1372 gfloat xalign = center ? 0.5 : 0.0;
1373 GtkCellRenderer *renderer;
1375 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), NULL);
1376 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL);
1378 renderer = gtk_cell_renderer_text_new ();
1380 g_object_set (renderer,
1385 return hildon_touch_selector_append_column (selector, model, renderer,
1390 * hildon_touch_selector_remove_column:
1391 * @selector: a #HildonTouchSelector
1392 * @column: the position of the column to be removed
1394 * Removes a column from @selector.
1396 * Returns: %TRUE if the column was removed, %FALSE otherwise
1401 hildon_touch_selector_remove_column (HildonTouchSelector * selector, gint column)
1403 HildonTouchSelectorColumn *current_column = NULL;
1404 HildonTouchSelectorPrivate *priv;
1406 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), FALSE);
1407 g_return_val_if_fail (column <
1408 hildon_touch_selector_get_num_columns (selector), FALSE);
1410 priv = HILDON_TOUCH_SELECTOR_GET_PRIVATE (selector);
1411 current_column = g_slist_nth_data (priv->columns, column);
1413 gtk_container_remove (GTK_CONTAINER (priv->hbox), current_column->priv->panarea);
1414 priv->columns = g_slist_remove (priv->columns, current_column);
1415 g_object_unref (current_column);
1417 g_signal_emit (selector, hildon_touch_selector_signals[COLUMNS_CHANGED], 0);
1423 * hildon_touch_selector_set_column_attributes:
1424 * @selector: a #HildonTouchSelector
1425 * @num_column: the number of the column whose attributes we're setting
1426 * @cell_renderer: the #GtkCellRendere we're setting the attributes of
1427 * @Varargs: A %NULL-terminated list of attributes.
1429 * Sets the attributes for the given column. The attributes must be given
1430 * in attribute/column pairs, just like in gtk_tree_view_column_set_attributes().
1431 * All existing attributes are removed and replaced with the new ones.
1433 * Deprecated: #HildonTouchSelectorColumn implements #GtkCellLayout, use this
1434 * interface instead. See
1435 * hildon_touch_selector_get_column().
1440 hildon_touch_selector_set_column_attributes (HildonTouchSelector * selector,
1442 GtkCellRenderer * cell_renderer,
1446 GtkTreeViewColumn *tree_column = NULL;
1447 HildonTouchSelectorColumn *current_column = NULL;
1448 gchar *attribute = NULL;
1451 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (selector));
1452 g_return_if_fail (num_column <
1453 hildon_touch_selector_get_num_columns (selector));
1455 current_column = g_slist_nth_data (selector->priv->columns, num_column);
1457 tree_column = gtk_tree_view_get_column (current_column->priv->tree_view, 0);
1458 gtk_tree_view_remove_column (current_column->priv->tree_view, tree_column);
1460 tree_column = gtk_tree_view_column_new ();
1461 gtk_tree_view_column_pack_start (tree_column, cell_renderer, TRUE);
1463 va_start (args, cell_renderer);
1464 attribute = va_arg (args, gchar *);
1466 gtk_tree_view_column_clear_attributes (tree_column, cell_renderer);
1468 while (attribute != NULL) {
1469 value = va_arg (args, gint);
1470 gtk_tree_view_column_add_attribute (tree_column, cell_renderer,
1472 attribute = va_arg (args, gchar *);
1477 gtk_tree_view_append_column (current_column->priv->tree_view, tree_column);
1481 * hildon_touch_selector_get_num_columns:
1482 * @selector: a #HildonTouchSelector
1484 * Gets the number of columns in the #HildonTouchSelector.
1486 * Returns: the number of columns in @selector.
1491 hildon_touch_selector_get_num_columns (HildonTouchSelector * selector)
1493 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), -1);
1495 return g_slist_length (selector->priv->columns);
1499 * hildon_touch_selector_get_column_selection_mode:
1500 * @selector: a #HildonTouchSelector
1502 * Gets the selection mode of @selector.
1504 * Returns: one of #HildonTouchSelectorSelectionMode
1508 HildonTouchSelectorSelectionMode
1509 hildon_touch_selector_get_column_selection_mode (HildonTouchSelector * selector)
1511 HildonTouchSelectorSelectionMode result =
1512 HILDON_TOUCH_SELECTOR_SELECTION_MODE_SINGLE;
1513 GtkSelectionMode treeview_mode = GTK_SELECTION_BROWSE;
1514 HildonTouchSelectorColumn *column = NULL;
1515 GtkTreeSelection *selection = NULL;
1517 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), result);
1518 g_return_val_if_fail (hildon_touch_selector_get_num_columns (selector) > 0,
1521 column = HILDON_TOUCH_SELECTOR_COLUMN (selector->priv->columns->data);
1523 selection = gtk_tree_view_get_selection (column->priv->tree_view);
1524 treeview_mode = gtk_tree_selection_get_mode (selection);
1527 if (treeview_mode == GTK_SELECTION_MULTIPLE) {
1528 result = HILDON_TOUCH_SELECTOR_SELECTION_MODE_MULTIPLE;
1530 result = HILDON_TOUCH_SELECTOR_SELECTION_MODE_SINGLE;
1537 * hildon_touch_selector_set_column_selection_mode:
1538 * @selector: a #HildonTouchSelector
1539 * @mode: the #HildonTouchSelectorMode for @selector
1541 * Sets the selection mode for @selector. See #HildonTouchSelectorSelectionMode.
1543 * The new @mode will be set, but take into into account that the
1544 * #HildonTouchSelectorSelectionMode is ignored if the @selector
1545 * #HildonTouchSelector:hildon-ui-mode property is set to %HILDON_UI_MODE_NORMAL
1550 hildon_touch_selector_set_column_selection_mode (HildonTouchSelector * selector,
1551 HildonTouchSelectorSelectionMode mode)
1553 GtkTreeView *tv = NULL;
1554 HildonTouchSelectorColumn *column = NULL;
1555 GtkTreeSelection *selection = NULL;
1556 GtkSelectionMode treeview_mode = GTK_SELECTION_MULTIPLE;
1558 HildonTouchSelectorSelectionMode current_mode;
1560 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (selector));
1561 g_return_if_fail (hildon_touch_selector_get_num_columns (selector) > 0);
1563 current_mode = hildon_touch_selector_get_column_selection_mode (selector);
1565 if (current_mode == mode) {
1569 column = HILDON_TOUCH_SELECTOR_COLUMN ((g_slist_nth (selector->priv->columns, 0))->data);
1570 tv = column->priv->tree_view;
1574 case HILDON_TOUCH_SELECTOR_SELECTION_MODE_SINGLE:
1575 treeview_mode = GTK_SELECTION_BROWSE;
1577 case HILDON_TOUCH_SELECTOR_SELECTION_MODE_MULTIPLE:
1578 treeview_mode = GTK_SELECTION_MULTIPLE;
1582 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tv));
1583 gtk_tree_selection_set_mode (selection, treeview_mode);
1585 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tv));
1586 gtk_tree_model_get_iter_first (column->priv->model, &iter);
1587 gtk_tree_selection_unselect_all (selection);
1588 gtk_tree_selection_select_iter (selection, &iter);
1590 /* the column changed was the first one */
1591 hildon_touch_selector_emit_value_changed (selector, 0);
1597 * hildon_touch_selector_set_print_func:
1598 * @selector: a #HildonTouchSelector
1599 * @func: a #HildonTouchSelectorPrintFunc function
1601 * Sets the function to be used by hildon_touch_selector_get_current_text().
1602 * See hildon_touch_selector_set_print_func_full().
1607 hildon_touch_selector_set_print_func (HildonTouchSelector * selector,
1608 HildonTouchSelectorPrintFunc func)
1610 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (selector));
1612 hildon_touch_selector_set_print_func_full (selector, func, NULL, NULL);
1616 * hildon_touch_selector_set_print_func_full:
1617 * @selector: a #HildonTouchSelector
1618 * @func: a #HildonTouchSelectorPrintFunc function
1619 * @user_data: a pointer to user data or %NULL
1620 * @destroy_func: a callback for freeing the user data or %NULL
1622 * Sets the function to be used by hildon_touch_selector_get_current_text()
1623 * to produce a text representation of the currently selected items in @selector.
1624 * The default function will return a concatenation of comma separated items
1625 * selected in each column in @selector. Use this to override this method if you
1626 * need a particular representation for your application.
1631 hildon_touch_selector_set_print_func_full (HildonTouchSelector *selector,
1632 HildonTouchSelectorPrintFunc func,
1634 GDestroyNotify destroy_func)
1636 gpointer old_user_data;
1637 GDestroyNotify old_destroy_func;
1639 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (selector));
1641 old_user_data = selector->priv->print_user_data;
1642 old_destroy_func = selector->priv->print_destroy_func;
1644 selector->priv->print_func = func;
1645 selector->priv->print_user_data = user_data;
1646 selector->priv->print_destroy_func = destroy_func;
1648 if (old_destroy_func && old_user_data != user_data)
1649 (*old_destroy_func) (old_user_data);
1653 * hildon_touch_selector_get_print_func:
1654 * @selector: a #HildonTouchSelector
1656 * Gets the #HildonTouchSelectorPrintFunc currently used. See
1657 * hildon_touch_selector_set_print_func().
1659 * Returns: a #HildonTouchSelectorPrintFunc or %NULL if the default
1660 * one is currently used.
1662 HildonTouchSelectorPrintFunc
1663 hildon_touch_selector_get_print_func (HildonTouchSelector * selector)
1665 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), NULL);
1667 return selector->priv->print_func;
1671 * hildon_touch_selector_set_active:
1672 * @selector: a #HildonTouchSelector
1673 * @column: column number
1674 * @index: the index of the item to select, or -1 to have no active item
1676 * Sets the active item of the #HildonTouchSelector to @index. The
1677 * column number is taken from @column.
1679 * @selector must be in %HILDON_TOUCH_SELECTOR_SELECTION_MODE_SINGLE
1684 hildon_touch_selector_set_active (HildonTouchSelector *selector,
1688 GtkTreeSelection *selection = NULL;
1689 HildonTouchSelectorColumn *current_column = NULL;
1690 HildonTouchSelectorSelectionMode mode;
1693 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (selector));
1694 g_return_if_fail (column < hildon_touch_selector_get_num_columns (selector));
1695 mode = hildon_touch_selector_get_column_selection_mode (selector);
1696 g_return_if_fail (mode == HILDON_TOUCH_SELECTOR_SELECTION_MODE_SINGLE);
1698 current_column = g_slist_nth_data (selector->priv->columns, column);
1700 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (current_column->priv->tree_view));
1701 path = gtk_tree_path_new_from_indices (index, -1);
1702 gtk_tree_selection_unselect_all (selection);
1704 gtk_tree_selection_select_path (selection, path);
1706 hildon_touch_selector_emit_value_changed (selector, column);
1708 gtk_tree_path_free (path);
1712 * hildon_touch_selector_get_active:
1713 * @selector: a #HildonTouchSelector
1714 * @column: column number
1716 * Returns the index of the currently active item in column number
1717 * @column, or -1 if there's no active item.
1719 * @selector must be in %HILDON_TOUCH_SELECTOR_SELECTION_MODE_SINGLE
1721 * Returns: an integer which is the index of the currently active
1722 * item, or -1 if there's no active item.
1727 hildon_touch_selector_get_active (HildonTouchSelector *selector,
1730 GtkTreeSelection *selection = NULL;
1731 HildonTouchSelectorColumn *current_column = NULL;
1732 HildonTouchSelectorSelectionMode mode;
1733 GtkTreeModel *model;
1738 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), -1);
1739 g_return_val_if_fail (column < hildon_touch_selector_get_num_columns (selector), -1);
1740 mode = hildon_touch_selector_get_column_selection_mode (selector);
1741 g_return_val_if_fail (mode == HILDON_TOUCH_SELECTOR_SELECTION_MODE_SINGLE, -1);
1743 current_column = g_slist_nth_data (selector->priv->columns, column);
1745 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (current_column->priv->tree_view));
1746 g_return_val_if_fail (gtk_tree_selection_get_selected (selection, NULL, &iter), -1);
1748 model = gtk_tree_view_get_model (GTK_TREE_VIEW (current_column->priv->tree_view));
1749 path = gtk_tree_model_get_path (model, &iter);
1750 index = (gtk_tree_path_get_indices (path))[0];
1752 gtk_tree_path_free (path);
1758 * hildon_touch_selector_get_selected:
1759 * @selector: a #HildonTouchSelector
1760 * @column: the column number we want to get the element
1761 * @iter: #GtkTreeIter currently selected
1763 * Sets @iter to the currently selected node on the nth-column, if selection is
1764 * set to %HILDON_TOUCH_SELECTOR_SINGLE or %HILDON_TOUCH_SELECTOR_MULTIPLE with
1765 * a column different that the first one. @iter may be %NULL if you just want to
1766 * test if selection has any selected items.
1768 * This function will not work if selection is in
1769 * %HILDON_TOUCH_SELECTOR_MULTIPLE mode and the column is the first one.
1771 * See gtk_tree_selection_get_selected() for more information.
1773 * Returns: %TRUE if @iter was correctly set, %FALSE otherwise
1778 hildon_touch_selector_get_selected (HildonTouchSelector * selector,
1779 gint column, GtkTreeIter * iter)
1781 GtkTreeSelection *selection = NULL;
1782 HildonTouchSelectorColumn *current_column = NULL;
1783 HildonTouchSelectorSelectionMode mode;
1785 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), FALSE);
1786 g_return_val_if_fail (column < hildon_touch_selector_get_num_columns (selector),
1788 mode = hildon_touch_selector_get_column_selection_mode (selector);
1789 g_return_val_if_fail
1790 ((mode == HILDON_TOUCH_SELECTOR_SELECTION_MODE_SINGLE) ||
1791 ((mode == HILDON_TOUCH_SELECTOR_SELECTION_MODE_MULTIPLE)&&(column>0)),
1794 current_column = g_slist_nth_data (selector->priv->columns, column);
1797 gtk_tree_view_get_selection (GTK_TREE_VIEW (current_column->priv->tree_view));
1799 return gtk_tree_selection_get_selected (selection, NULL, iter);
1803 * hildon_touch_selector_select_iter
1804 * @selector: a #HildonTouchSelector
1805 * @column: the column to selects
1806 * @iter: the #GtkTreeIter to be selected
1807 * @scroll_to: whether to smoothly scroll to the item
1809 * Sets the currently selected item in the column @column to the one pointed by @iter,
1810 * optionally smoothly scrolling to it.
1815 hildon_touch_selector_select_iter (HildonTouchSelector * selector,
1816 gint column, GtkTreeIter * iter,
1820 GtkTreeModel *model;
1821 HildonTouchSelectorColumn *current_column = NULL;
1822 GtkTreeView *tv = NULL;
1823 GtkTreeSelection *selection = NULL;
1825 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (selector));
1826 g_return_if_fail (column < hildon_touch_selector_get_num_columns (selector));
1828 current_column = g_slist_nth_data (selector->priv->columns, column);
1830 tv = current_column->priv->tree_view;
1831 selection = gtk_tree_view_get_selection (tv);
1832 model = gtk_tree_view_get_model (tv);
1833 path = gtk_tree_model_get_path (model, iter);
1835 gtk_tree_selection_select_iter (selection, iter);
1838 hildon_touch_selector_scroll_to (current_column, tv, path);
1841 hildon_touch_selector_emit_value_changed (selector, column);
1843 gtk_tree_path_free (path);
1847 * hildon_touch_selector_unselect_iter
1848 * @selector: a #HildonTouchSelector
1849 * @column: the column to unselects from
1850 * @iter: the #GtkTreeIter to be unselected
1852 * Unselect the item pointed by @iter in the column @column
1857 void hildon_touch_selector_unselect_iter (HildonTouchSelector * selector,
1861 HildonTouchSelectorColumn *current_column = NULL;
1862 GtkTreeSelection *selection = NULL;
1864 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (selector));
1865 g_return_if_fail (column < hildon_touch_selector_get_num_columns (selector));
1867 current_column = g_slist_nth_data (selector->priv->columns, column);
1868 selection = gtk_tree_view_get_selection (current_column->priv->tree_view);
1869 gtk_tree_selection_unselect_iter (selection, iter);
1871 hildon_touch_selector_emit_value_changed (selector, column);
1875 * hildon_touch_selector_unselect_all:
1876 * @selector: a #HildonTouchSelector
1877 * @column: the position of the column to get the selected rows from
1879 * Unselects all the selected items in the column @column.
1884 hildon_touch_selector_unselect_all (HildonTouchSelector * selector,
1887 HildonTouchSelectorColumn *current_column = NULL;
1888 GtkTreeSelection *selection = NULL;
1890 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (selector));
1891 g_return_if_fail (column < hildon_touch_selector_get_num_columns (selector));
1893 current_column = g_slist_nth_data (selector->priv->columns, column);
1894 selection = gtk_tree_view_get_selection (current_column->priv->tree_view);
1895 gtk_tree_selection_unselect_all (selection);
1897 hildon_touch_selector_emit_value_changed (selector, column);
1901 * hildon_touch_selector_get_selected_rows:
1902 * @selector: a #HildonTouchSelector
1903 * @column: the position of the column to get the selected rows from
1905 * Creates a list of #GtkTreePath<!-- -->s of all selected rows in a column. Additionally,
1906 * if you to plan to modify the model after calling this function, you may
1907 * want to convert the returned list into a list of GtkTreeRowReferences. To do this,
1908 * you can use gtk_tree_row_reference_new().
1910 * See gtk_tree_selection_get_selected_rows() for more information.
1912 * Returns: A new #GList containing a #GtkTreePath for each selected row in the column @column.
1917 hildon_touch_selector_get_selected_rows (HildonTouchSelector * selector,
1920 GList *result = NULL;
1921 HildonTouchSelectorColumn *current_column = NULL;
1922 GtkTreeSelection *selection = NULL;
1924 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), NULL);
1925 g_return_val_if_fail (column < hildon_touch_selector_get_num_columns (selector),
1928 current_column = g_slist_nth_data (selector->priv->columns, column);
1929 selection = gtk_tree_view_get_selection (current_column->priv->tree_view);
1931 result = gtk_tree_selection_get_selected_rows (selection, NULL);
1937 * hildon_touch_selector_get_model:
1938 * @selector: a #HildonTouchSelector
1939 * @column: the position of the column in @selector
1941 * Gets the model of a column of @selector.
1943 * Returns: the #GtkTreeModel for the column @column of @selector.
1948 hildon_touch_selector_get_model (HildonTouchSelector * selector, gint column)
1950 HildonTouchSelectorColumn *current_column = NULL;
1952 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), NULL);
1953 g_return_val_if_fail (column < hildon_touch_selector_get_num_columns (selector),
1956 current_column = g_slist_nth_data (selector->priv->columns, column);
1958 return current_column->priv->model;
1962 on_row_changed (GtkTreeModel *model,
1967 HildonTouchSelector *selector;
1968 HildonTouchSelectorColumn *current_column;
1973 selector = HILDON_TOUCH_SELECTOR (userdata);
1975 for (col = selector->priv->columns; col != NULL; col = col->next) {
1976 current_column = HILDON_TOUCH_SELECTOR_COLUMN (col->data);
1977 if (current_column->priv->model == model &&
1978 gtk_tree_selection_path_is_selected (gtk_tree_view_get_selection (current_column->priv->tree_view),
1980 hildon_touch_selector_emit_value_changed (selector, column);
1987 _hildon_touch_selector_set_model (HildonTouchSelector * selector,
1988 gint column, GtkTreeModel * model)
1990 HildonTouchSelectorColumn *current_column = NULL;
1993 HILDON_TOUCH_SELECTOR_COLUMN (g_slist_nth_data (selector->priv->columns, column));
1995 if (current_column->priv->model) {
1996 g_signal_handlers_disconnect_by_func (current_column->priv->model,
1997 on_row_changed, selector);
1999 current_column->priv->model = model;
2000 gtk_tree_view_set_model (current_column->priv->tree_view,
2001 current_column->priv->model);
2002 g_signal_connect (model, "row-changed",
2003 G_CALLBACK (on_row_changed), selector);
2007 * hildon_touch_selector_set_model:
2008 * @selector: a #HildonTouchSelector
2009 * @column: the position of the column to set the model to
2010 * @model: a #GtkTreeModel
2012 * Sets the #GtkTreeModel for a particular column in @model.
2017 hildon_touch_selector_set_model (HildonTouchSelector * selector,
2018 gint column, GtkTreeModel * model)
2020 g_return_if_fail (HILDON_TOUCH_SELECTOR (selector));
2021 g_return_if_fail (column < hildon_touch_selector_get_num_columns (selector));
2023 HILDON_TOUCH_SELECTOR_GET_CLASS (selector)->set_model (selector, column, model);
2027 * hildon_touch_selector_get_current_text:
2028 * @selector: a #HildonTouchSelector
2030 * Returns a string representing the currently selected items for
2031 * each column of @selector. See hildon_touch_selector_set_print_func().
2033 * Returns: a newly allocated string.
2038 hildon_touch_selector_get_current_text (HildonTouchSelector * selector)
2040 gchar *result = NULL;
2041 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), NULL);
2043 if (selector->priv->print_func) {
2044 result = (*selector->priv->print_func) (selector, selector->priv->print_user_data);
2046 result = _default_print_func (selector, NULL);
2053 search_nearest_element (HildonPannableArea *panarea,
2055 GList *selected_rows,
2056 GtkTreePath **nearest_path)
2058 GtkAdjustment *adj = NULL;
2059 gdouble target_value = 0;
2062 GtkTreePath *path = NULL;
2064 gdouble nearest_distance = -1;
2065 gdouble current_distance = -1;
2066 GtkTreePath *result_path = NULL;
2068 g_assert (nearest_path != NULL);
2070 if (selected_rows == NULL) {
2071 *nearest_path = NULL;
2075 adj = hildon_pannable_area_get_vadjustment (panarea);
2076 g_return_if_fail (adj != NULL);
2078 /* we add this in order to check the nearest to the center of
2080 target_value = gtk_adjustment_get_value (adj) + adj->page_size/2;
2082 path = result_path = selected_rows->data;
2083 gtk_tree_view_get_background_area (tv, path, NULL, &rect);
2084 gtk_tree_view_convert_bin_window_to_tree_coords (tv, 0, rect.y, NULL, &y);
2085 nearest_distance = abs (target_value - y);
2087 for (iter = selected_rows->next; iter; iter = g_list_next (iter)) {
2088 gtk_tree_view_get_background_area (tv, path, NULL, &rect);
2089 gtk_tree_view_convert_bin_window_to_tree_coords (tv, 0, rect.y, NULL, &y);
2090 current_distance = abs (target_value - y);
2091 if (current_distance < nearest_distance) {
2092 nearest_distance = current_distance;
2097 *nearest_path = result_path;
2101 on_realize_cb (GtkWidget *widget,
2104 HildonTouchSelectorColumn *column = NULL;
2108 column = HILDON_TOUCH_SELECTOR_COLUMN (data);
2110 if (column->priv->initial_path) {
2111 gtk_tree_view_get_background_area (GTK_TREE_VIEW (column->priv->tree_view),
2112 column->priv->initial_path, NULL, &rect);
2113 gtk_tree_view_convert_bin_window_to_tree_coords
2114 (GTK_TREE_VIEW (column->priv->tree_view),
2115 0, rect.y, NULL, &y);
2117 hildon_pannable_area_scroll_to (HILDON_PANNABLE_AREA (column->priv->panarea),
2120 gtk_tree_path_free (column->priv->initial_path);
2122 column->priv->initial_path = NULL;
2126 g_signal_handler_disconnect (column->priv->panarea,
2127 column->priv->realize_handler);
2133 hildon_touch_selector_scroll_to (HildonTouchSelectorColumn *column,
2137 if (GTK_WIDGET_REALIZED (column->priv->panarea)) {
2141 gtk_tree_view_get_background_area (tv,
2143 gtk_tree_view_convert_bin_window_to_tree_coords (tv,
2144 0, rect.y, NULL, &y);
2146 hildon_pannable_area_scroll_to (HILDON_PANNABLE_AREA
2147 (column->priv->panarea), -1, y);
2149 if (column->priv->realize_handler != 0) {
2151 if (column->priv->initial_path) {
2152 gtk_tree_path_free (column->priv->initial_path);
2153 column->priv->initial_path = NULL;
2156 g_signal_handler_disconnect (column->priv->panarea,
2157 column->priv->realize_handler);
2158 column->priv->realize_handler = 0;
2161 column->priv->initial_path = gtk_tree_path_copy (path);
2162 column->priv->realize_handler =
2163 g_signal_connect_after (G_OBJECT (column->priv->panarea), "realize",
2164 G_CALLBACK (on_realize_cb),
2171 * Center on the selected item of a concrete column
2173 * Returns: TRUE if was able to do that
2177 _hildon_touch_selector_center_on_selected_items (HildonTouchSelector *selector,
2178 HildonTouchSelectorColumn *column)
2180 GtkTreePath *path = NULL;
2181 GList *selected_rows = NULL;
2182 gint num_column = -1;
2184 num_column = g_slist_index (selector->priv->columns, column);
2186 selected_rows = hildon_touch_selector_get_selected_rows (selector, num_column);
2187 if (selected_rows) {
2188 search_nearest_element (HILDON_PANNABLE_AREA (column->priv->panarea),
2189 GTK_TREE_VIEW (column->priv->tree_view),
2194 hildon_touch_selector_scroll_to (column,
2195 GTK_TREE_VIEW (column->priv->tree_view),
2201 g_list_foreach (selected_rows, (GFunc) (gtk_tree_path_free), NULL);
2202 g_list_free (selected_rows);
2209 _hildon_touch_selector_has_multiple_selection (HildonTouchSelector * selector)
2211 HildonTouchSelectorSelectionMode mode;
2214 n_columns = hildon_touch_selector_get_num_columns (selector);
2215 mode = hildon_touch_selector_get_column_selection_mode (selector);
2217 return ((n_columns > 1) || (mode == HILDON_TOUCH_SELECTOR_SELECTION_MODE_MULTIPLE));
2221 * hildon_touch_selector_has_multiple_selection:
2222 * @selector: A #HildonTouchSelector
2224 * Determines whether @selector is complex enough to actually require an
2225 * extra selection step than only picking an item. This is normally %TRUE
2226 * if @selector has multiple columns, multiple selection, or when it is a
2227 * more complex widget, like #HildonTouchSelectorEntry.
2229 * This information is useful for widgets containing a #HildonTouchSelector,
2230 * like #HildonPickerDialog, that could need a "Done" button, in case that
2231 * its internal #HildonTouchSelector has multiple columns, for instance.
2233 * Returns: %TRUE if @selector requires multiple selection steps.
2238 hildon_touch_selector_has_multiple_selection (HildonTouchSelector * selector)
2240 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), FALSE);
2242 return HILDON_TOUCH_SELECTOR_GET_CLASS (selector)->has_multiple_selection (selector);
2247 * hildon_touch_selector_get_column:
2248 * @selector: A #HildonTouchSelector
2249 * @column: a column number
2251 * Use this method to retrieve a #HildonTouchSelectorColumn. Then, you can use
2252 * the #GtkCellLayout interface to set up the layout of the column.
2254 * Returns: the @column<!-- -->-th #HildonTouchSelectorColumn in @selector
2258 HildonTouchSelectorColumn *
2259 hildon_touch_selector_get_column (HildonTouchSelector * selector,
2262 gint num_columns = -1;
2264 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), NULL);
2265 num_columns = hildon_touch_selector_get_num_columns (selector);
2266 g_return_val_if_fail (column < num_columns && column >= 0, NULL);
2268 return g_slist_nth_data (selector->priv->columns, column);
2273 * hildon_touch_selector_center_on_selected:
2274 * @selector: a #HildonTouchSelector
2276 * Ensures all the columns in a #HildonTouchSelector show a selected
2277 * item. If one of the columns is in
2278 * %HILDON_TOUCH_SELECTOR_SELECTION_MODE_MULTIPLE mode, that column
2279 * will be scrolled to ensure the selected item that is closest to the
2280 * currently visible area is shown.
2285 hildon_touch_selector_center_on_selected (HildonTouchSelector *selector)
2287 GSList *iter = NULL;
2289 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (selector));
2291 for (iter = selector->priv->columns; iter; iter = g_slist_next (iter)) {
2292 _hildon_touch_selector_center_on_selected_items (selector,
2293 HILDON_TOUCH_SELECTOR_COLUMN (iter->data));
2298 * hildon_touch_selector_optimal_size_request
2299 * @selector: a #HildonTouchSelector
2300 * @requisition: a #GtkRequisition
2302 * Gets the optimal size request of the touch selector. This function is mostly
2303 * intended for dialog implementations that include a #HildonTouchSelector and
2304 * want to optimize the screen real state, for example, when you want a dialog
2305 * to show as much of the selector, avoiding any extra empty space below the
2308 * See #HildonPickerDialog implementation for an example.
2310 * This function is oriented to be used in the size_request of a dialog or window,
2311 * if you are not sure do not use it.
2313 * There is a precondition to this function: Since this function does not
2314 * call the "size_request" method, it can only be used when you know that
2315 * gtk_widget_size_request() has been called since the last time a resize was
2321 hildon_touch_selector_optimal_size_request (HildonTouchSelector *selector,
2322 GtkRequisition *requisition)
2324 GSList *iter = NULL;
2326 gint base_height = 0;
2328 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (selector));
2330 iter = selector->priv->columns;
2332 /* Default optimal values are the current ones */
2333 gtk_widget_get_child_requisition (GTK_WIDGET (selector),
2337 height = requisition->height;
2339 /* we use the normal requisition as base, as the touch selector can has
2340 extra widgets, not only the columns (ie: HildonTouchSelectorEntry) */
2341 base_height = requisition->height;
2344 /* Compute optimal height for the columns */
2346 HildonTouchSelectorColumn *column;
2348 GtkRequisition child_requisition = {0};
2350 column = HILDON_TOUCH_SELECTOR_COLUMN (iter->data);
2351 child = GTK_WIDGET (column->priv->tree_view);
2353 gtk_widget_get_child_requisition (child, &child_requisition);
2355 height = MAX (height, child_requisition.height);
2357 iter = g_slist_next (iter);
2360 requisition->height = base_height + height;
2366 * hildon_touch_selector_get_hildon_ui_mode
2367 * @selector: a #HildonTouchSelector
2369 * Gets the current hildon-ui-mode, see #HildonUIMode for more information
2371 * Returns: the current hildon-ui-mode
2376 hildon_touch_selector_get_hildon_ui_mode (HildonTouchSelector *selector)
2378 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), HILDON_UI_MODE_EDIT);
2380 return selector->priv->hildon_ui_mode;
2384 * hildon_touch_selector_set_hildon_ui_mode
2385 * @selector: a #HildonTouchSelector
2386 * @mode: a #HildonUIMode
2388 * Sets the value of the property #HildonTouchSelector:hildon-ui-mode to be @mode,
2389 * see #HildonUIMode for more information
2391 * Note that the %HILDON_UI_MODE_NORMAL can be only used when the selector has
2392 * one column, use the return value to check if the change was effective.
2394 * Returns: %TRUE if #HildonTouchSelector:hildon-ui-mode was changed
2400 hildon_touch_selector_set_hildon_ui_mode (HildonTouchSelector *selector,
2404 GSList *iter = NULL;
2405 HildonTouchSelectorColumn *column = NULL;
2406 GtkTreeView *tree_view = NULL;
2408 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), FALSE);
2409 num = hildon_touch_selector_get_num_columns (selector);
2410 g_return_val_if_fail ((mode == HILDON_UI_MODE_EDIT) || (num == 1), FALSE);
2412 if (mode == selector->priv->hildon_ui_mode) {
2416 for (iter = selector->priv->columns; iter; iter = g_slist_next (iter)) {
2417 column = HILDON_TOUCH_SELECTOR_COLUMN (iter->data);
2418 tree_view = column->priv->tree_view;
2420 hildon_tree_view_set_hildon_ui_mode (tree_view, mode);
2422 /* looking at the code of hildon_tree_view_set_hildon_ui_mode, it seems
2423 that it call the unselect_all, but it is required anyway */
2424 if (mode == HILDON_UI_MODE_NORMAL) {
2425 GtkTreeSelection *selection = gtk_tree_view_get_selection (tree_view);
2427 gtk_tree_selection_unselect_all (selection);
2431 selector->priv->hildon_ui_mode = mode;
2437 * hildon_touch_selector_get_last_activated_row
2438 * @selector: a #HildonTouchSelector
2439 * @column: column number
2441 * Gets a #GtkTreePath of the last row activated in a column (the last row that
2442 * emitted a #GtkTreeView::row-activated signal). This is mainly useful if the
2443 * @selector #HildonTouchSelector:hildon-ui-mode in set to %HILDON_UI_MODE_NORMAL,
2444 * as using this state there is no real selection, so a method like
2445 * hildon_touch_selector_get_selected_rows() will return always a empty
2448 * Anyway, this method works as well on %HILDON_UI_MODE_EDIT, but in this case
2449 * is better, and more useful, to get the current selection.
2451 * Returns: a newly allocated #GtkTreePath pointing to the last activated row
2452 * NULL if no row were activated.
2457 hildon_touch_selector_get_last_activated_row (HildonTouchSelector *selector,
2460 HildonTouchSelectorColumn *selector_column = NULL;
2462 /* this method with check selector and that the column number is correct*/
2463 selector_column = hildon_touch_selector_get_column (selector, column);
2465 if (selector_column == NULL) {
2469 if (selector_column->priv->last_activated != NULL) {
2470 return gtk_tree_row_reference_get_path (selector_column->priv->last_activated);