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 composition of each column in the selector is represented by 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.
71 * SECTION:hildon-touch-selector-column
72 * @short_description: A visible column in a #HildonTouchSelector
74 * #HildonTouchSelectorColumn object represents a visible column in
75 * #HildonTouchSelector. It allows to manage the cell renderers related to each
79 #undef HILDON_DISABLE_DEPRECATED
88 #include "hildon-gtk.h"
90 #include "hildon-pannable-area.h"
91 #include "hildon-touch-selector.h"
93 #define HILDON_TOUCH_SELECTOR_GET_PRIVATE(obj) \
94 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), HILDON_TYPE_TOUCH_SELECTOR, HildonTouchSelectorPrivate))
96 G_DEFINE_TYPE (HildonTouchSelector, hildon_touch_selector, GTK_TYPE_VBOX)
99 * IMPLEMENTATION NOTES:
100 * Struct to maintain the data of each column. The columns are the elements
101 * of the widget that belongs properly to the selection behaviour. Although
102 * internally the columns are arranged in a private #GtkHBox, as the selector
103 * itself is a #GtkVBox, you can add more widgets, like buttons etc., so
104 * you finally could have a widget with more elements that the columns, but
105 * this doesn't belongs to the selection logic
107 struct _HildonTouchSelectorColumnPrivate
109 HildonTouchSelector *parent; /* the selector that contains this column */
112 GtkTreeView *tree_view;
114 GtkWidget *panarea; /* the pannable widget */
117 struct _HildonTouchSelectorPrivate
119 GSList *columns; /* the selection columns */
120 GtkWidget *hbox; /* the container for the selector's columns */
121 gboolean initial_scroll; /* whether initial fancy scrolling to selection */
123 HildonTouchSelectorPrintFunc print_func;
128 PROP_HAS_MULTIPLE_SELECTION = 1,
138 static gint hildon_touch_selector_signals[LAST_SIGNAL] = { 0 };
141 hildon_touch_selector_get_property (GObject * object,
146 hildon_touch_selector_set_property (GObject *object,
153 static void hildon_touch_selector_remove (GtkContainer * container,
155 /* private functions */
156 static void _selection_changed_cb (GtkTreeSelection * selection,
158 static gchar *_default_print_func (HildonTouchSelector * selector);
160 static HildonTouchSelectorColumn *_create_new_column (HildonTouchSelector * selector,
161 GtkTreeModel * model,
162 GtkCellRenderer * renderer,
165 _hildon_touch_selector_center_on_selected_items (GtkWidget *widget,
169 _hildon_touch_selector_set_model (HildonTouchSelector * selector,
171 GtkTreeModel * model);
173 _hildon_touch_selector_has_multiple_selection (HildonTouchSelector * selector);
175 /* GtkCellLayout implementation (HildonTouchSelectorColumn)*/
176 static void hildon_touch_selector_column_cell_layout_init (GtkCellLayoutIface *iface);
178 static void hildon_touch_selector_column_cell_layout_pack_start (GtkCellLayout *cell_layout,
179 GtkCellRenderer *cell,
181 static void hildon_touch_selector_column_cell_layout_pack_end (GtkCellLayout *cell_layout,
182 GtkCellRenderer *cell,
184 static void hildon_touch_selector_column_cell_layout_clear (GtkCellLayout *cell_layout);
185 static void hildon_touch_selector_column_cell_layout_add_attribute(GtkCellLayout *cell_layout,
186 GtkCellRenderer *cell,
187 const gchar *attribute,
189 static void hildon_touch_selector_column_cell_layout_set_cell_data_func (GtkCellLayout *cell_layout,
190 GtkCellRenderer *cell,
191 GtkCellLayoutDataFunc func,
193 GDestroyNotify destroy);
194 static void hildon_touch_selector_column_cell_layout_clear_attributes (GtkCellLayout *cell_layout,
195 GtkCellRenderer *cell);
196 static void hildon_touch_selector_column_cell_layout_reorder (GtkCellLayout *cell_layout,
197 GtkCellRenderer *cell,
199 static GList *hildon_touch_selector_column_cell_layout_get_cells (GtkCellLayout *cell_layout);
203 hildon_touch_selector_class_init (HildonTouchSelectorClass * class)
205 GObjectClass *gobject_class;
206 GtkObjectClass *object_class;
207 GtkWidgetClass *widget_class;
208 GtkContainerClass *container_class;
210 gobject_class = G_OBJECT_CLASS (class);
211 object_class = GTK_OBJECT_CLASS (class);
212 widget_class = GTK_WIDGET_CLASS (class);
213 container_class = GTK_CONTAINER_CLASS (class);
216 gobject_class->get_property = hildon_touch_selector_get_property;
217 gobject_class->set_property = hildon_touch_selector_set_property;
222 container_class->remove = hildon_touch_selector_remove;
224 /* HildonTouchSelector */
225 class->changed = NULL;
226 class->set_model = _hildon_touch_selector_set_model;
228 class->has_multiple_selection = _hildon_touch_selector_has_multiple_selection;
232 * HildonTouchSelector::changed:
233 * @column: the concrete column being modified
234 * @widget: the object which received the signal
236 * The changed signal is emitted when the active item on any column is changed.
237 * This can be due to the user selecting a different item from the list, or
238 * due to a call to hildon_touch_selector_select_iter() on one of the columns.
241 hildon_touch_selector_signals[CHANGED] =
242 g_signal_new ("changed",
243 G_OBJECT_CLASS_TYPE (class),
245 G_STRUCT_OFFSET (HildonTouchSelectorClass, changed),
247 gtk_marshal_NONE__INT, G_TYPE_NONE, 1, G_TYPE_INT);
250 g_object_class_install_property (gobject_class, PROP_HAS_MULTIPLE_SELECTION,
251 g_param_spec_boolean ("has-multiple-selection",
252 "has multiple selection",
253 "Whether the widget has multiple "
254 "selection (like multiple columns, "
255 "multiselection mode, or multiple "
256 "internal widgets) and therefore "
257 "it may need a confirmation button, "
262 g_object_class_install_property (G_OBJECT_CLASS (gobject_class),
264 g_param_spec_boolean ("initial-scroll",
266 "Whether to scroll to the"
267 "current selection when"
268 "the selector is first"
271 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
273 /* style properties */
274 /* We need to ensure fremantle mode for the treeview in order to work
275 properly. This is not about the appearance, this is about behaviour */
276 gtk_rc_parse_string ("style \"fremantle-htst\" {\n"
277 " GtkWidget::hildon-mode = 1\n"
278 "} widget \"*.fremantle-htst\" style \"fremantle-htst\""
279 "widget_class \"*<HildonPannableArea>.GtkTreeView\" style :highest \"fremantle-htst\"");
281 g_type_class_add_private (object_class, sizeof (HildonTouchSelectorPrivate));
285 hildon_touch_selector_get_property (GObject * object,
287 GValue * value, GParamSpec * pspec)
289 HildonTouchSelectorPrivate *priv = HILDON_TOUCH_SELECTOR (object)->priv;
292 case PROP_HAS_MULTIPLE_SELECTION:
293 g_value_set_boolean (value,
294 hildon_touch_selector_has_multiple_selection (HILDON_TOUCH_SELECTOR (object)));
296 case PROP_INITIAL_SCROLL:
297 g_value_set_boolean (value, priv->initial_scroll);
300 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
306 hildon_touch_selector_set_property (GObject *object, guint prop_id,
307 const GValue *value, GParamSpec *pspec)
309 HildonTouchSelectorPrivate *priv = HILDON_TOUCH_SELECTOR (object)->priv;
312 case PROP_INITIAL_SCROLL:
313 priv->initial_scroll = g_value_get_boolean (value);
316 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
323 hildon_touch_selector_init (HildonTouchSelector * selector)
325 selector->priv = HILDON_TOUCH_SELECTOR_GET_PRIVATE (selector);
327 GTK_WIDGET_SET_FLAGS (GTK_WIDGET (selector), GTK_NO_WINDOW);
328 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (selector), FALSE);
330 selector->priv->columns = NULL;
332 selector->priv->print_func = NULL;
333 selector->priv->initial_scroll = TRUE;
334 selector->priv->hbox = gtk_hbox_new (FALSE, 0);
336 gtk_box_pack_end (GTK_BOX (selector), selector->priv->hbox,
338 gtk_widget_show (selector->priv->hbox);
342 * IMPLEMENTATION NOTES:
343 * Some people sent questions regarding a missing dispose/finalize function on
344 * this widget that could lead to leak memory, so we will clarify this topic.
346 * This is not required as #HildonTouchSelector extends #GtkContainer. When the
347 * widget is freed, the #GtkContainer freeing memory functions are called. This
348 * process includes remove each widget individually, so all the widgets are
351 * In the same way, this widget redefines gtk_container->remove function, in
352 * order to free the column related information if it is required.
354 * Please take a look to hildon_touch_selector_remove for more information.
357 /*------------------------------ GtkContainer ------------------------------ */
360 * Required in order to free the column at the columns list
363 hildon_touch_selector_remove (GtkContainer * container, GtkWidget * widget)
365 HildonTouchSelector *selector = NULL;
367 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (container));
368 selector = HILDON_TOUCH_SELECTOR (container);
370 /* Remove the extra data related to the columns, if required. */
371 if (widget == selector->priv->hbox) {
372 g_slist_foreach (selector->priv->columns, (GFunc) g_object_unref, NULL);
374 g_slist_free (selector->priv->columns);
376 selector->priv->columns = NULL;
378 g_debug ("Freeing a widget outside the columns logic");
381 /* Now remove the widget itself from the container */
382 GTK_CONTAINER_CLASS (hildon_touch_selector_parent_class)->remove (container, widget);
385 /* ------------------------------ PRIVATE METHODS ---------------------------- */
387 * default_print_func:
388 * @selector: a #HildonTouchSelector
390 * Default print function
392 * Returns: a new string that represents the selected items
395 _default_print_func (HildonTouchSelector * selector)
397 gchar *result = NULL;
399 gint num_columns = 0;
401 GtkTreeModel *model = NULL;
402 gchar *current_string = NULL;
404 HildonTouchSelectorSelectionMode mode;
406 GtkTreePath *current_path = NULL;
407 GList *selected_rows = NULL;
408 gint initial_value = 0;
409 gint text_column = -1;
410 HildonTouchSelectorColumn *column = NULL;
412 num_columns = hildon_touch_selector_get_num_columns (selector);
414 mode = hildon_touch_selector_get_column_selection_mode (selector);
416 if ((mode == HILDON_TOUCH_SELECTOR_SELECTION_MODE_MULTIPLE)
417 && (num_columns > 0)) {
418 /* In this case we get the first column first */
419 selected_rows = hildon_touch_selector_get_selected_rows (selector, 0);
420 model = hildon_touch_selector_get_model (selector, 0);
421 column = hildon_touch_selector_get_column (selector, 0);
422 g_object_get (G_OBJECT(column), "text-column", &text_column, NULL);
424 result = g_strdup_printf ("(");
426 for (item = selected_rows; item; item = g_list_next (item)) {
427 current_path = item->data;
428 gtk_tree_model_get_iter (model, &iter, current_path);
430 if (text_column != -1) {
431 gtk_tree_model_get (model, &iter, text_column, ¤t_string, -1);
434 if (i < g_list_length (selected_rows) - 1) {
435 aux = g_strconcat (result, current_string, ",", NULL);
439 aux = g_strconcat (result, current_string, NULL);
446 aux = g_strconcat (result, ")", NULL);
450 g_list_foreach (selected_rows, (GFunc) (gtk_tree_path_free), NULL);
451 g_list_free (selected_rows);
457 for (i = initial_value; i < num_columns; i++) {
458 model = hildon_touch_selector_get_model (selector, i);
459 column = hildon_touch_selector_get_column (selector, 0);
460 g_object_get (G_OBJECT(column), "text-column", &text_column, NULL);
462 if (hildon_touch_selector_get_selected (selector, i, &iter)) {
464 if (text_column != -1 ) {
465 gtk_tree_model_get (model, &iter, text_column, ¤t_string, -1);
468 aux = g_strconcat (result, ":", current_string, NULL);
472 result = current_string;
481 _selection_changed_cb (GtkTreeSelection * selection, gpointer user_data)
483 HildonTouchSelector *selector = NULL;
484 HildonTouchSelectorColumn *column = NULL;
485 gint num_column = -1;
487 column = HILDON_TOUCH_SELECTOR_COLUMN (user_data);
488 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (column->priv->parent));
490 selector = column->priv->parent;
492 num_column = g_slist_index (selector->priv->columns, column);
494 g_signal_emit (selector, hildon_touch_selector_signals[CHANGED], 0, num_column);
498 static HildonTouchSelectorColumn *
499 _create_new_column (HildonTouchSelector * selector,
500 GtkTreeModel * model,
501 GtkCellRenderer * renderer, va_list args)
503 HildonTouchSelectorColumn *new_column = NULL;
504 GtkTreeViewColumn *tree_column = NULL;
505 GtkTreeView *tv = NULL;
506 GtkWidget *panarea = NULL;
507 GtkTreeSelection *selection = NULL;
512 tree_column = gtk_tree_view_column_new ();
514 if (renderer != NULL) {
515 gtk_tree_view_column_pack_start (tree_column, renderer, TRUE);
517 attribute = va_arg (args, gchar *);
518 while (attribute != NULL) {
519 value = va_arg (args, gint);
520 gtk_tree_view_column_add_attribute (tree_column, renderer, attribute,
522 attribute = va_arg (args, gchar *);
527 tv = GTK_TREE_VIEW (hildon_gtk_tree_view_new (HILDON_UI_MODE_EDIT));
529 tv = GTK_TREE_VIEW (gtk_tree_view_new ());
530 #endif /* MAEMO_GTK */
532 gtk_tree_view_set_enable_search (tv, FALSE);
534 gtk_tree_view_set_model (tv, model);
535 gtk_tree_view_set_rules_hint (tv, TRUE);
537 gtk_tree_view_append_column (GTK_TREE_VIEW (tv), tree_column);
539 new_column = g_object_new (HILDON_TYPE_TOUCH_SELECTOR_COLUMN, NULL);
540 new_column->priv->parent = selector;
542 panarea = hildon_pannable_area_new ();
544 g_object_set (G_OBJECT (panarea), "vscrollbar-policy", GTK_POLICY_NEVER,
545 "initial-hint", FALSE, NULL);
547 gtk_container_add (GTK_CONTAINER (panarea), GTK_WIDGET (tv));
549 new_column->priv->model = model;
550 new_column->priv->tree_view = tv;
551 new_column->priv->panarea = panarea;
553 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tv));
554 gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
556 /* select the first item */
557 if (gtk_tree_model_get_iter_first (model, &iter)) {
558 gtk_tree_selection_select_iter (selection, &iter);
561 gtk_widget_grab_focus (GTK_WIDGET (tv));
563 /* connect to the changed signal connection */
564 g_signal_connect (G_OBJECT (selection), "changed",
565 G_CALLBACK (_selection_changed_cb), new_column);
567 g_signal_connect_after (G_OBJECT (panarea), "realize",
568 G_CALLBACK (_hildon_touch_selector_center_on_selected_items),
575 /* ------------------------ HildonTouchSelectorColumn implementation ---------------------- */
576 G_DEFINE_TYPE_WITH_CODE (HildonTouchSelectorColumn, hildon_touch_selector_column, G_TYPE_OBJECT,
577 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
578 hildon_touch_selector_column_cell_layout_init))
586 hildon_touch_selector_column_class_init (HildonTouchSelectorColumnClass *klass);
589 hildon_touch_selector_column_get_property (GObject *object, guint property_id,
590 GValue *value, GParamSpec *pspec);
593 hildon_touch_selector_column_set_property (GObject *object, guint property_id,
594 const GValue *value, GParamSpec *pspec);
597 hildon_touch_selector_column_set_text_column (HildonTouchSelectorColumn *column,
600 hildon_touch_selector_column_get_text_column (HildonTouchSelectorColumn *column);
604 hildon_touch_selector_column_class_init (HildonTouchSelectorColumnClass *klass)
606 GObjectClass *gobject_class = NULL;
608 gobject_class = G_OBJECT_CLASS (klass);
610 g_type_class_add_private (gobject_class, sizeof (HildonTouchSelectorColumnPrivate));
613 gobject_class->get_property = hildon_touch_selector_column_get_property;
614 gobject_class->set_property = hildon_touch_selector_column_set_property;
616 g_object_class_install_property (G_OBJECT_CLASS(klass),
618 g_param_spec_int ("text-column",
620 "A column in the data source model to get the strings from.",
628 hildon_touch_selector_column_init (HildonTouchSelectorColumn *column)
630 column->priv = G_TYPE_INSTANCE_GET_PRIVATE (column, HILDON_TYPE_TOUCH_SELECTOR_COLUMN,
631 HildonTouchSelectorColumnPrivate);
632 column->priv->text_column = -1;
636 hildon_touch_selector_column_set_text_column (HildonTouchSelectorColumn *column,
639 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR_COLUMN (column));
640 g_return_if_fail (text_column >= -1);
642 column->priv->text_column = text_column;
644 g_object_notify (G_OBJECT (column), "text-column");
648 hildon_touch_selector_column_get_text_column (HildonTouchSelectorColumn *column)
650 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR_COLUMN (column), -1);
652 return column->priv->text_column;
656 hildon_touch_selector_column_get_property (GObject *object, guint property_id,
657 GValue *value, GParamSpec *pspec)
659 switch (property_id) {
660 case PROP_TEXT_COLUMN:
661 g_value_set_int (value,
662 hildon_touch_selector_column_get_text_column (HILDON_TOUCH_SELECTOR_COLUMN (object)));
665 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
670 hildon_touch_selector_column_set_property (GObject *object, guint property_id,
671 const GValue *value, GParamSpec *pspec)
673 switch (property_id) {
674 case PROP_TEXT_COLUMN:
675 hildon_touch_selector_column_set_text_column (HILDON_TOUCH_SELECTOR_COLUMN (object),
676 g_value_get_int (value));
679 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
683 /* ------------------------ GtkCellLayout implementation -------------------- */
685 hildon_touch_selector_column_cell_layout_init (GtkCellLayoutIface *iface)
687 iface->pack_start = hildon_touch_selector_column_cell_layout_pack_start;
688 iface->pack_end = hildon_touch_selector_column_cell_layout_pack_end;
689 iface->clear = hildon_touch_selector_column_cell_layout_clear;
690 iface->add_attribute = hildon_touch_selector_column_cell_layout_add_attribute;
691 iface->set_cell_data_func = hildon_touch_selector_column_cell_layout_set_cell_data_func;
692 iface->clear_attributes = hildon_touch_selector_column_cell_layout_clear_attributes;
693 iface->reorder = hildon_touch_selector_column_cell_layout_reorder;
694 iface->get_cells = hildon_touch_selector_column_cell_layout_get_cells;
698 hildon_touch_selector_column_cell_layout_pack_start (GtkCellLayout *cell_layout,
699 GtkCellRenderer *cell,
702 HildonTouchSelectorColumn *sel_column = NULL;
703 GtkTreeViewColumn *view_column = NULL;
705 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR_COLUMN (cell_layout));
706 sel_column = HILDON_TOUCH_SELECTOR_COLUMN (cell_layout);
708 view_column = gtk_tree_view_get_column (sel_column->priv->tree_view, 0);
710 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT(view_column), cell, expand);
715 hildon_touch_selector_column_cell_layout_pack_end (GtkCellLayout *cell_layout,
716 GtkCellRenderer *cell,
719 HildonTouchSelectorColumn *sel_column = NULL;
720 GtkTreeViewColumn *view_column = NULL;
722 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR_COLUMN (cell_layout));
723 sel_column = HILDON_TOUCH_SELECTOR_COLUMN (cell_layout);
725 view_column = gtk_tree_view_get_column (sel_column->priv->tree_view, 0);
727 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT(view_column), cell, expand);
731 hildon_touch_selector_column_cell_layout_clear (GtkCellLayout *cell_layout)
733 HildonTouchSelectorColumn *sel_column = NULL;
734 GtkTreeViewColumn *view_column = NULL;
736 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR_COLUMN (cell_layout));
737 sel_column = HILDON_TOUCH_SELECTOR_COLUMN (cell_layout);
739 view_column = gtk_tree_view_get_column (sel_column->priv->tree_view, 0);
741 gtk_cell_layout_clear (GTK_CELL_LAYOUT(view_column));
745 hildon_touch_selector_column_cell_layout_add_attribute (GtkCellLayout *cell_layout,
746 GtkCellRenderer *cell,
747 const gchar *attribute,
750 HildonTouchSelectorColumn *sel_column = NULL;
751 GtkTreeViewColumn *view_column = NULL;
753 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR_COLUMN (cell_layout));
754 sel_column = HILDON_TOUCH_SELECTOR_COLUMN (cell_layout);
756 view_column = gtk_tree_view_get_column (sel_column->priv->tree_view, 0);
758 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT(view_column), cell, attribute, column);
763 hildon_touch_selector_column_cell_layout_set_cell_data_func (GtkCellLayout *cell_layout,
764 GtkCellRenderer *cell,
765 GtkCellLayoutDataFunc func,
767 GDestroyNotify destroy)
769 HildonTouchSelectorColumn *sel_column = NULL;
770 GtkTreeViewColumn *view_column = NULL;
772 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR_COLUMN (cell_layout));
773 sel_column = HILDON_TOUCH_SELECTOR_COLUMN (cell_layout);
775 view_column = gtk_tree_view_get_column (sel_column->priv->tree_view, 0);
777 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT(view_column), cell, func,
782 hildon_touch_selector_column_cell_layout_clear_attributes (GtkCellLayout *cell_layout,
783 GtkCellRenderer *cell)
785 HildonTouchSelectorColumn *sel_column = NULL;
786 GtkTreeViewColumn *view_column = NULL;
788 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR_COLUMN (cell_layout));
789 sel_column = HILDON_TOUCH_SELECTOR_COLUMN (cell_layout);
791 view_column = gtk_tree_view_get_column (sel_column->priv->tree_view, 0);
793 gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (view_column), cell);
797 hildon_touch_selector_column_cell_layout_reorder (GtkCellLayout *cell_layout,
798 GtkCellRenderer *cell,
801 HildonTouchSelectorColumn *sel_column = NULL;
802 GtkTreeViewColumn *view_column = NULL;
804 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR_COLUMN (cell_layout));
805 sel_column = HILDON_TOUCH_SELECTOR_COLUMN (cell_layout);
807 view_column = gtk_tree_view_get_column (sel_column->priv->tree_view, 0);
809 gtk_cell_layout_reorder (GTK_CELL_LAYOUT(view_column), cell, position);
813 hildon_touch_selector_column_cell_layout_get_cells (GtkCellLayout *cell_layout)
815 HildonTouchSelectorColumn *sel_column = NULL;
816 GtkTreeViewColumn *view_column = NULL;
818 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR_COLUMN (cell_layout), NULL);
819 sel_column = HILDON_TOUCH_SELECTOR_COLUMN (cell_layout);
821 view_column = gtk_tree_view_get_column (sel_column->priv->tree_view, 0);
823 return gtk_cell_layout_get_cells (GTK_CELL_LAYOUT(view_column));
826 /* ------------------------------ PUBLIC METHODS ---------------------------- */
829 * hildon_touch_selector_new:
831 * Creates a new empty #HildonTouchSelector.
833 * Returns: a new #HildonTouchSelector.
836 hildon_touch_selector_new (void)
838 return g_object_new (HILDON_TYPE_TOUCH_SELECTOR, NULL);
842 * hildon_touch_selector_new_text:
844 * Creates a #HildonTouchSelector with a single text column that
845 * can be populated conveniently through hildon_touch_selector_append_text(),
846 * hildon_touch_selector_prepend_text(), hildon_touch_selector_insert_text().
848 * Returns: A new #HildonTouchSelector
851 hildon_touch_selector_new_text (void)
855 HildonTouchSelectorColumn *column = NULL;
857 selector = hildon_touch_selector_new ();
858 store = gtk_list_store_new (1, G_TYPE_STRING);
860 column = hildon_touch_selector_append_text_column (HILDON_TOUCH_SELECTOR (selector),
861 GTK_TREE_MODEL (store), TRUE);
863 g_object_set (G_OBJECT (column), "text-column", 0, NULL);
869 * hildon_touch_selector_append_text:
870 * @selector: A #HildonTouchSelector.
871 * @text: a non %NULL text string.
873 * Appends a new entry in a #HildonTouchSelector created with
874 * hildon_touch_selector_new_text().
877 hildon_touch_selector_append_text (HildonTouchSelector * selector,
883 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (selector));
884 g_return_if_fail (text != NULL);
886 model = hildon_touch_selector_get_model (HILDON_TOUCH_SELECTOR (selector), 0);
888 g_return_if_fail (GTK_IS_LIST_STORE (model));
890 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
891 gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, text, -1);
895 * hildon_touch_selector_prepend_text:
896 * @selector: A #HildonTouchSelector.
897 * @text: a non %NULL text string.
899 * Prepends a new entry in a #HildonTouchSelector created with
900 * hildon_touch_selector_new_text().
903 hildon_touch_selector_prepend_text (HildonTouchSelector * selector,
909 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (selector));
910 g_return_if_fail (text != NULL);
912 model = hildon_touch_selector_get_model (HILDON_TOUCH_SELECTOR (selector), 0);
914 g_return_if_fail (GTK_IS_LIST_STORE (model));
916 gtk_list_store_prepend (GTK_LIST_STORE (model), &iter);
917 gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, text, -1);
921 * hildon_touch_selector_insert_text:
922 * @selector: a #HildonTouchSelector.
923 * @position: the position to insert @text.
924 * @text: A non %NULL text string.
926 * Inserts a new entry in particular position of a #HildoTouchSelector created
927 * with hildon_touch_selector_new_text().
931 hildon_touch_selector_insert_text (HildonTouchSelector * selector,
932 gint position, const gchar * text)
937 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (selector));
938 g_return_if_fail (text != NULL);
939 g_return_if_fail (position >= 0);
941 model = hildon_touch_selector_get_model (HILDON_TOUCH_SELECTOR (selector), 0);
943 g_return_if_fail (GTK_IS_LIST_STORE (model));
945 gtk_list_store_insert (GTK_LIST_STORE (model), &iter, position);
946 gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, text, -1);
950 * hildon_touch_selector_append_column
951 * @selector: a #HildonTouchSelector
952 * @model: the #GtkTreeModel with the data of the column
953 * @cell_renderer: The #GtkCellRenderer where to draw each row contents.
954 * @Varargs: a %NULL-terminated pair of attributes and column numbers.
956 * This functions adds a new column to the widget, whose data will
957 * be obtained from the model. Only widgets added this way should used on
958 * the selection logic, i.e., the print function, the #HildonTouchPicker::changed
961 * You can optionally pass a #GtkCellRenderer in @cell_renderer,
962 * together with a %NULL-terminated list of pairs property/value, in
963 * the same way you would use gtk_tree_view_column_set_attributes().
964 * This will pack @cell_renderer at the start of the column, expanded by default.
965 * If you prefer not to add it this way, you can simply pass %NULL to @cell_renderer
966 * and use the #GtkCellLayout interface on the returned #HildonTouchSelectorColumn
967 * to set your renderers.
969 * There is a prerequisite to be considered on models used: text data must
970 * be in the first column.
972 * This method basically adds a #GtkTreeView to the widget, using the model and
975 * Returns: the new column added added, %NULL otherwise.
978 HildonTouchSelectorColumn*
979 hildon_touch_selector_append_column (HildonTouchSelector * selector,
980 GtkTreeModel * model,
981 GtkCellRenderer * cell_renderer, ...)
984 HildonTouchSelectorColumn *new_column = NULL;
986 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), NULL);
987 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL);
991 va_start (args, cell_renderer);
992 new_column = _create_new_column (selector, model, cell_renderer, args);
993 g_object_ref_sink (new_column);
996 selector->priv->columns = g_slist_append (selector->priv->columns,
998 gtk_box_pack_start (GTK_BOX (selector->priv->hbox),
999 new_column->priv->panarea,
1002 gtk_widget_show_all (new_column->priv->panarea);
1011 * hildon_touch_selector_append_text_column
1012 * @selector: a #HildonTouchSelector
1013 * @model: a #GtkTreeModel with data for the column
1014 * @center: whether to center the text on the column
1016 * Equivalent to hildon_touch_selector_append_column(), but using a
1017 * default text cell renderer. This is the most common use case of the
1020 * Returns: the new column added, NULL otherwise.
1022 HildonTouchSelectorColumn*
1023 hildon_touch_selector_append_text_column (HildonTouchSelector * selector,
1024 GtkTreeModel * model, gboolean center)
1026 GtkCellRenderer *renderer = NULL;
1027 GValue val = { 0, };
1029 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), NULL);
1030 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL);
1032 if (model != NULL) {
1033 renderer = gtk_cell_renderer_text_new ();
1036 g_value_init (&val, G_TYPE_FLOAT);
1037 g_value_set_float (&val, 0.5);
1038 g_object_set_property (G_OBJECT (renderer), "xalign", &val);
1041 return hildon_touch_selector_append_column (selector, model, renderer,
1049 * hildon_touch_selector_remove_column:
1050 * @selector: a #HildonTouchSelector
1051 * @column: the position of the column to be removed
1053 * Removes a column from @selector.
1055 * Returns: %TRUE if the column was removed, %FALSE otherwise
1058 hildon_touch_selector_remove_column (HildonTouchSelector * selector, gint column)
1060 HildonTouchSelectorColumn *current_column = NULL;
1061 HildonTouchSelectorPrivate *priv;
1063 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), FALSE);
1064 g_return_val_if_fail (column <
1065 hildon_touch_selector_get_num_columns (selector), FALSE);
1067 priv = HILDON_TOUCH_SELECTOR_GET_PRIVATE (selector);
1068 current_column = g_slist_nth_data (priv->columns, column);
1070 gtk_container_remove (GTK_CONTAINER (priv->hbox), current_column->priv->panarea);
1071 priv->columns = g_slist_remove (priv->columns, current_column);
1072 g_object_unref (current_column);
1078 * hildon_touch_selector_set_column_attributes:
1079 * @selector: a #HildonTouchSelector
1080 * @num_column: the number of the column whose attributes we're setting
1081 * @cell_renderer: the #GtkCellRendere we're setting the attributes of
1082 * @Varargs: A %NULL-terminated list of attributes.
1084 * Sets the attributes for the given column. The attributes must be given
1085 * in attribute/column pairs, just like in gtk_tree_view_column_set_attributes().
1086 * All existing attributes are removed and replaced with the new ones.
1088 * Deprecated: #HildonTouchSelectorColumn implements #GtkCellLayout, use this
1089 * interface instead. See
1090 * hildon_touch_selector_get_column().
1094 hildon_touch_selector_set_column_attributes (HildonTouchSelector * selector,
1096 GtkCellRenderer * cell_renderer,
1100 GtkTreeViewColumn *tree_column = NULL;
1101 HildonTouchSelectorColumn *current_column = NULL;
1102 gchar *attribute = NULL;
1105 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (selector));
1106 g_return_if_fail (num_column <
1107 hildon_touch_selector_get_num_columns (selector));
1109 current_column = g_slist_nth_data (selector->priv->columns, num_column);
1111 tree_column = gtk_tree_view_get_column (current_column->priv->tree_view, 0);
1112 gtk_tree_view_remove_column (current_column->priv->tree_view, tree_column);
1114 tree_column = gtk_tree_view_column_new ();
1115 gtk_tree_view_column_pack_start (tree_column, cell_renderer, TRUE);
1117 va_start (args, cell_renderer);
1118 attribute = va_arg (args, gchar *);
1120 gtk_tree_view_column_clear_attributes (tree_column, cell_renderer);
1122 while (attribute != NULL) {
1123 value = va_arg (args, gint);
1124 gtk_tree_view_column_add_attribute (tree_column, cell_renderer,
1126 attribute = va_arg (args, gchar *);
1131 gtk_tree_view_append_column (current_column->priv->tree_view, tree_column);
1135 * hildon_touch_selector_get_num_columns:
1136 * @selector: a #HildonTouchSelector
1138 * Gets the number of columns in the #HildonTouchSelector.
1140 * Returns: the number of columns in @selector.
1143 hildon_touch_selector_get_num_columns (HildonTouchSelector * selector)
1145 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), -1);
1147 return g_slist_length (selector->priv->columns);
1151 * hildon_touch_selector_get_column_selection_mode:
1152 * @selector: a #HildonTouchSelector
1154 * Gets the selection mode of @selector.
1156 * Returns: one of #HildonTouchSelectorSelectionMode
1158 HildonTouchSelectorSelectionMode
1159 hildon_touch_selector_get_column_selection_mode (HildonTouchSelector * selector)
1161 HildonTouchSelectorSelectionMode result =
1162 HILDON_TOUCH_SELECTOR_SELECTION_MODE_SINGLE;
1163 GtkSelectionMode treeview_mode = GTK_SELECTION_BROWSE;
1164 HildonTouchSelectorColumn *column = NULL;
1165 GtkTreeSelection *selection = NULL;
1167 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), result);
1168 g_return_val_if_fail (hildon_touch_selector_get_num_columns (selector) > 0,
1171 column = HILDON_TOUCH_SELECTOR_COLUMN (selector->priv->columns->data);
1173 selection = gtk_tree_view_get_selection (column->priv->tree_view);
1174 treeview_mode = gtk_tree_selection_get_mode (selection);
1177 if (treeview_mode == GTK_SELECTION_MULTIPLE) {
1178 result = HILDON_TOUCH_SELECTOR_SELECTION_MODE_MULTIPLE;
1180 result = HILDON_TOUCH_SELECTOR_SELECTION_MODE_SINGLE;
1187 * hildon_touch_selector_set_column_selection_mode:
1188 * @selector: a #HildonTouchSelector
1189 * @mode: the #HildonTouchSelectorMode for @selector
1191 * Sets the selection mode for @selector. See #HildonTouchSelectorSelectionMode.
1194 hildon_touch_selector_set_column_selection_mode (HildonTouchSelector * selector,
1195 HildonTouchSelectorSelectionMode mode)
1197 GtkTreeView *tv = NULL;
1198 HildonTouchSelectorColumn *column = NULL;
1199 GtkTreeSelection *selection = NULL;
1200 GtkSelectionMode treeview_mode = GTK_SELECTION_MULTIPLE;
1202 HildonTouchSelectorSelectionMode current_mode;
1204 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (selector));
1205 g_return_if_fail (hildon_touch_selector_get_num_columns (selector) > 0);
1207 current_mode = hildon_touch_selector_get_column_selection_mode (selector);
1209 if (current_mode == mode) {
1213 column = HILDON_TOUCH_SELECTOR_COLUMN ((g_slist_nth (selector->priv->columns, 0))->data);
1214 tv = column->priv->tree_view;
1218 case HILDON_TOUCH_SELECTOR_SELECTION_MODE_SINGLE:
1219 treeview_mode = GTK_SELECTION_BROWSE;
1221 case HILDON_TOUCH_SELECTOR_SELECTION_MODE_MULTIPLE:
1222 treeview_mode = GTK_SELECTION_MULTIPLE;
1226 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tv));
1227 gtk_tree_selection_set_mode (selection, treeview_mode);
1229 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tv));
1230 gtk_tree_model_get_iter_first (column->priv->model, &iter);
1231 gtk_tree_selection_unselect_all (selection);
1232 gtk_tree_selection_select_iter (selection, &iter);
1238 * hildon_touch_selector_set_print_func:
1239 * @selector: a #HildonTouchSelector
1240 * @func: a #HildonTouchSelectorPrintFunc function
1242 * Sets the function to be used by hildon_touch_selector_get_current_text()
1243 * to produce a text representation of the currently selected items in @selector.
1244 * The default function will return a concatenation of comma separated items
1245 * selected in each column in @selector. Use this to override this method if you
1246 * need a particular representation for your application.
1250 hildon_touch_selector_set_print_func (HildonTouchSelector * selector,
1251 HildonTouchSelectorPrintFunc func)
1253 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (selector));
1255 selector->priv->print_func = func;
1259 * hildon_touch_selector_get_print_func:
1260 * @selector: a #HildonTouchSelector
1262 * Gets the #HildonTouchSelectorPrintFunc currently used. See
1263 * hildon_touch_selector_set_print_func().
1265 * Returns: a #HildonTouchSelectorPrintFunc or %NULL if the default
1266 * one is currently used.
1268 HildonTouchSelectorPrintFunc
1269 hildon_touch_selector_get_print_func (HildonTouchSelector * selector)
1271 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), NULL);
1273 return selector->priv->print_func;
1277 * hildon_touch_selector_set_active:
1278 * @selector: a #HildonTouchSelector
1279 * @column: column number
1280 * @index: the index of the item to select, or -1 to have no active item
1282 * Sets the active item of the #HildonTouchSelector to @index. The
1283 * column number is taken from @column.
1285 * @selector must be in %HILDON_TOUCH_SELECTOR_SELECTION_MODE_SINGLE
1288 hildon_touch_selector_set_active (HildonTouchSelector *selector,
1292 GtkTreeSelection *selection = NULL;
1293 HildonTouchSelectorColumn *current_column = NULL;
1294 HildonTouchSelectorSelectionMode mode;
1297 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (selector));
1298 g_return_if_fail (column < hildon_touch_selector_get_num_columns (selector));
1299 mode = hildon_touch_selector_get_column_selection_mode (selector);
1300 g_return_if_fail (mode == HILDON_TOUCH_SELECTOR_SELECTION_MODE_SINGLE);
1302 current_column = g_slist_nth_data (selector->priv->columns, column);
1304 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (current_column->priv->tree_view));
1305 path = gtk_tree_path_new_from_indices (index, -1);
1306 gtk_tree_selection_unselect_all (selection);
1308 gtk_tree_selection_select_path (selection, path);
1310 gtk_tree_path_free (path);
1314 * hildon_touch_selector_get_active:
1315 * @selector: a #HildonTouchSelector
1316 * @column: column number
1318 * Returns the index of the currently active item in column number
1319 * @column, or -1 if there's no active item.
1321 * @selector must be in %HILDON_TOUCH_SELECTOR_SELECTION_MODE_SINGLE
1323 * Returns: an integer which is the index of the currently active
1324 * item, or -1 if there's no active item.
1327 hildon_touch_selector_get_active (HildonTouchSelector *selector,
1330 GtkTreeSelection *selection = NULL;
1331 HildonTouchSelectorColumn *current_column = NULL;
1332 HildonTouchSelectorSelectionMode mode;
1333 GtkTreeModel *model;
1338 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), -1);
1339 g_return_val_if_fail (column < hildon_touch_selector_get_num_columns (selector), -1);
1340 mode = hildon_touch_selector_get_column_selection_mode (selector);
1341 g_return_val_if_fail (mode == HILDON_TOUCH_SELECTOR_SELECTION_MODE_SINGLE, -1);
1343 current_column = g_slist_nth_data (selector->priv->columns, column);
1345 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (current_column->priv->tree_view));
1346 model = gtk_tree_view_get_model (GTK_TREE_VIEW (current_column->priv->tree_view));
1348 gtk_tree_selection_get_selected (selection, NULL, &iter);
1349 path = gtk_tree_model_get_path (model, &iter);
1350 index = (gtk_tree_path_get_indices (path))[0];
1352 gtk_tree_path_free (path);
1358 * hildon_touch_selector_get_selected:
1359 * @selector: a #HildonTouchSelector
1360 * @column: the column number we want to get the element
1361 * @iter: #GtkTreeIter currently selected
1363 * Sets @iter to the currently selected node on the nth-column, if selection is
1364 * set to %HILDON_TOUCH_SELECTOR_SINGLE or %HILDON_TOUCH_SELECTOR_MULTIPLE with
1365 * a column different that the first one. @iter may be %NULL if you just want to
1366 * test if selection has any selected items.
1368 * This function will not work if selection is in
1369 * %HILDON_TOUCH_SELECTOR_MULTIPLE mode and the column is the first one.
1371 * See gtk_tree_selection_get_selected() for more information.
1373 * Returns: %TRUE if @iter was correctly set, %FALSE otherwise
1376 hildon_touch_selector_get_selected (HildonTouchSelector * selector,
1377 gint column, GtkTreeIter * iter)
1379 GtkTreeSelection *selection = NULL;
1380 HildonTouchSelectorColumn *current_column = NULL;
1381 HildonTouchSelectorSelectionMode mode;
1383 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), FALSE);
1384 g_return_val_if_fail (column < hildon_touch_selector_get_num_columns (selector),
1386 mode = hildon_touch_selector_get_column_selection_mode (selector);
1387 g_return_val_if_fail
1388 ((mode == HILDON_TOUCH_SELECTOR_SELECTION_MODE_SINGLE) ||
1389 ((mode == HILDON_TOUCH_SELECTOR_SELECTION_MODE_MULTIPLE)&&(column>0)),
1392 current_column = g_slist_nth_data (selector->priv->columns, column);
1395 gtk_tree_view_get_selection (GTK_TREE_VIEW (current_column->priv->tree_view));
1397 return gtk_tree_selection_get_selected (selection, NULL, iter);
1401 * hildon_touch_selector_select_iter
1402 * @selector: a #HildonTouchSelector
1403 * @column: the column to selects
1404 * @iter: the #GtkTreeIter to be selected
1405 * @scroll_to: whether to smoothly scroll to the item
1407 * Sets the currently selected item in the column @column to the one pointed by @iter,
1408 * optionally smoothly scrolling to it.
1412 hildon_touch_selector_select_iter (HildonTouchSelector * selector,
1413 gint column, GtkTreeIter * iter,
1417 GtkTreeModel *model;
1419 HildonTouchSelectorColumn *current_column = NULL;
1420 GtkTreeView *tv = NULL;
1421 GtkTreeSelection *selection = NULL;
1424 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (selector));
1425 g_return_if_fail (column < hildon_touch_selector_get_num_columns (selector));
1427 current_column = g_slist_nth_data (selector->priv->columns, column);
1429 tv = current_column->priv->tree_view;
1430 selection = gtk_tree_view_get_selection (tv);
1431 model = gtk_tree_view_get_model (tv);
1432 path = gtk_tree_model_get_path (model, iter);
1434 gtk_tree_selection_select_iter (selection, iter);
1437 gtk_tree_view_get_background_area (tv,
1439 gtk_tree_view_convert_bin_window_to_tree_coords (tv,
1440 0, rect.y, NULL, &y);
1441 hildon_pannable_area_scroll_to (HILDON_PANNABLE_AREA (current_column->priv->panarea),
1444 gtk_tree_path_free (path);
1448 * hildon_touch_selector_unselect_iter
1449 * @selector: a #HildonTouchSelector
1450 * @column: the column to unselects from
1451 * @iter: the #GtkTreeIter to be unselected
1453 * Unselect the item pointed by @iter in the column @column
1457 void hildon_touch_selector_unselect_iter (HildonTouchSelector * selector,
1461 HildonTouchSelectorColumn *current_column = NULL;
1462 GtkTreeSelection *selection = NULL;
1464 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (selector));
1465 g_return_if_fail (column < hildon_touch_selector_get_num_columns (selector));
1467 current_column = g_slist_nth_data (selector->priv->columns, column);
1468 selection = gtk_tree_view_get_selection (current_column->priv->tree_view);
1469 gtk_tree_selection_unselect_iter (selection, iter);
1473 * hildon_touch_selector_get_selected_rows:
1474 * @selector: a #HildonTouchSelector
1475 * @column: the position of the column to get the selected rows from
1477 * Creates a list of #GtkTreePath<!-- -->s of all selected rows in a column. Additionally,
1478 * if you to plan to modify the model after calling this function, you may
1479 * want to convert the returned list into a list of GtkTreeRowReferences. To do this,
1480 * you can use gtk_tree_row_reference_new().
1482 * See gtk_tree_selection_get_selected_rows() for more information.
1484 * Returns: A new #GList containing a #GtkTreePath for each selected row in the column @column.
1488 hildon_touch_selector_get_selected_rows (HildonTouchSelector * selector,
1491 GList *result = NULL;
1492 HildonTouchSelectorColumn *current_column = NULL;
1493 GtkTreeSelection *selection = NULL;
1495 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), NULL);
1496 g_return_val_if_fail (column < hildon_touch_selector_get_num_columns (selector),
1499 current_column = g_slist_nth_data (selector->priv->columns, column);
1500 selection = gtk_tree_view_get_selection (current_column->priv->tree_view);
1502 result = gtk_tree_selection_get_selected_rows (selection, NULL);
1508 * hildon_touch_selector_get_model:
1509 * @selector: a #HildonTouchSelector
1510 * @column: the position of the column in @selector
1512 * Gets the model of a column of @selector.
1514 * Returns: the #GtkTreeModel for the column @column of @selector.
1517 hildon_touch_selector_get_model (HildonTouchSelector * selector, gint column)
1519 HildonTouchSelectorColumn *current_column = NULL;
1521 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), NULL);
1522 g_return_val_if_fail (column < hildon_touch_selector_get_num_columns (selector),
1525 current_column = g_slist_nth_data (selector->priv->columns, column);
1527 return current_column->priv->model;
1531 _hildon_touch_selector_set_model (HildonTouchSelector * selector,
1532 gint column, GtkTreeModel * model)
1534 HildonTouchSelectorColumn *current_column = NULL;
1537 HILDON_TOUCH_SELECTOR_COLUMN (g_slist_nth_data (selector->priv->columns, column));
1539 current_column->priv->model = model;
1540 gtk_tree_view_set_model (current_column->priv->tree_view,
1541 current_column->priv->model);
1545 * hildon_touch_selector_set_model:
1546 * @selector: a #HildonTouchSelector
1547 * @column: the position of the column to set the model to
1548 * @model: a #GtkTreeModel
1550 * Sets the #GtkTreeModel for a particular column in @model.
1553 hildon_touch_selector_set_model (HildonTouchSelector * selector,
1554 gint column, GtkTreeModel * model)
1556 g_return_if_fail (HILDON_TOUCH_SELECTOR (selector));
1557 g_return_if_fail (column < hildon_touch_selector_get_num_columns (selector));
1559 HILDON_TOUCH_SELECTOR_GET_CLASS (selector)->set_model (selector, column, model);
1563 * hildon_touch_selector_get_current_text:
1564 * @selector: a #HildonTouchSelector
1566 * Returns a string representing the currently selected items for
1567 * each column of @selector. See hildon_touch_selector_set_print_func().
1569 * Returns: a newly allocated string.
1572 hildon_touch_selector_get_current_text (HildonTouchSelector * selector)
1574 gchar *result = NULL;
1575 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), NULL);
1577 if (selector->priv->print_func) {
1578 result = (*selector->priv->print_func) (selector);
1580 result = _default_print_func (selector);
1587 _hildon_touch_selector_center_on_selected_items (GtkWidget *widget,
1590 HildonTouchSelector *selector = NULL;
1591 HildonTouchSelectorColumn *column = NULL;
1593 GtkTreePath *path = NULL;
1596 gint num_column = -1;
1597 HildonTouchSelectorSelectionMode selection_mode;
1599 column = HILDON_TOUCH_SELECTOR_COLUMN (data);
1600 selector = column->priv->parent;
1602 if (!selector->priv->initial_scroll) {
1605 selection_mode = hildon_touch_selector_get_column_selection_mode (selector);
1606 num_column = g_slist_index (selector->priv->columns, column);
1608 if ((num_column == 0)
1609 && (selection_mode == HILDON_TOUCH_SELECTOR_SELECTION_MODE_MULTIPLE)) {
1614 if (hildon_touch_selector_get_selected (selector, num_column, &iter)) {
1615 path = gtk_tree_model_get_path (column->priv->model, &iter);
1616 gtk_tree_view_get_background_area (GTK_TREE_VIEW
1617 (column->priv->tree_view), path, NULL,
1620 gtk_tree_view_convert_bin_window_to_tree_coords (GTK_TREE_VIEW
1621 (column->priv->tree_view), 0,
1624 hildon_pannable_area_scroll_to (HILDON_PANNABLE_AREA
1625 (column->priv->panarea), -1, y);
1627 gtk_tree_path_free (path);
1634 _hildon_touch_selector_has_multiple_selection (HildonTouchSelector * selector)
1636 HildonTouchSelectorSelectionMode mode = HILDON_TOUCH_SELECTOR_SELECTION_MODE_SINGLE;
1639 n_columns = hildon_touch_selector_get_num_columns (selector);
1640 mode = hildon_touch_selector_get_column_selection_mode (selector);
1642 return ((n_columns > 1) || (mode == HILDON_TOUCH_SELECTOR_SELECTION_MODE_MULTIPLE));
1646 * hildon_touch_selector_has_multiple_selection:
1647 * @selector: A #HildonTouchSelector
1649 * Determines whether @selector is complex enough to actually require an
1650 * extra selection step than only picking an item. This is normally %TRUE
1651 * if @selector has multiple columns, multiple selection, or when it is a
1652 * more complex widget, like #HildonTouchSelectorEntry.
1654 * This information is useful for widgets containing a #HildonTouchSelector,
1655 * like #HildonPickerDialog, that could need a "Done" button, in case that
1656 * its internal #HildonTouchSelector has multiple columns, for instance.
1658 * Returns: %TRUE if @selector requires multiple selection steps.
1661 hildon_touch_selector_has_multiple_selection (HildonTouchSelector * selector)
1663 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), FALSE);
1665 return HILDON_TOUCH_SELECTOR_GET_CLASS (selector)->has_multiple_selection (selector);
1670 * hildon_touch_selector_get_column:
1671 * @selector: A #HildonTouchSelector
1672 * @column: a column number
1674 * Use this method to retrieve a #HildonTouchSelectorColumn. Then, you can use
1675 * the #GtkCellLayout interface to set up the layout of the column.
1677 * Returns: the @column<!-- -->-th #HildonTouchSelectorColumn in @selector
1679 HildonTouchSelectorColumn *
1680 hildon_touch_selector_get_column (HildonTouchSelector * selector,
1683 gint num_columns = -1;
1685 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), NULL);
1686 num_columns = hildon_touch_selector_get_num_columns (selector);
1687 g_return_val_if_fail (column < num_columns && column >= 0, NULL);
1689 return g_slist_nth_data (selector->priv->columns, column);