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,
168 _hildon_touch_selector_set_model (HildonTouchSelector * selector,
170 GtkTreeModel * model);
172 _hildon_touch_selector_has_multiple_selection (HildonTouchSelector * selector);
174 /* GtkCellLayout implementation (HildonTouchSelectorColumn)*/
175 static void hildon_touch_selector_column_cell_layout_init (GtkCellLayoutIface *iface);
177 static void hildon_touch_selector_column_cell_layout_pack_start (GtkCellLayout *cell_layout,
178 GtkCellRenderer *cell,
180 static void hildon_touch_selector_column_cell_layout_pack_end (GtkCellLayout *cell_layout,
181 GtkCellRenderer *cell,
183 static void hildon_touch_selector_column_cell_layout_clear (GtkCellLayout *cell_layout);
184 static void hildon_touch_selector_column_cell_layout_add_attribute(GtkCellLayout *cell_layout,
185 GtkCellRenderer *cell,
186 const gchar *attribute,
188 static void hildon_touch_selector_column_cell_layout_set_cell_data_func (GtkCellLayout *cell_layout,
189 GtkCellRenderer *cell,
190 GtkCellLayoutDataFunc func,
192 GDestroyNotify destroy);
193 static void hildon_touch_selector_column_cell_layout_clear_attributes (GtkCellLayout *cell_layout,
194 GtkCellRenderer *cell);
195 static void hildon_touch_selector_column_cell_layout_reorder (GtkCellLayout *cell_layout,
196 GtkCellRenderer *cell,
198 static GList *hildon_touch_selector_column_cell_layout_get_cells (GtkCellLayout *cell_layout);
202 hildon_touch_selector_class_init (HildonTouchSelectorClass * class)
204 GObjectClass *gobject_class;
205 GtkObjectClass *object_class;
206 GtkWidgetClass *widget_class;
207 GtkContainerClass *container_class;
209 gobject_class = G_OBJECT_CLASS (class);
210 object_class = GTK_OBJECT_CLASS (class);
211 widget_class = GTK_WIDGET_CLASS (class);
212 container_class = GTK_CONTAINER_CLASS (class);
215 gobject_class->get_property = hildon_touch_selector_get_property;
216 gobject_class->set_property = hildon_touch_selector_set_property;
221 container_class->remove = hildon_touch_selector_remove;
223 /* HildonTouchSelector */
224 class->set_model = _hildon_touch_selector_set_model;
226 class->has_multiple_selection = _hildon_touch_selector_has_multiple_selection;
230 * HildonTouchSelector::changed:
231 * @widget: the object which received the signal
233 * The changed signal is emitted when the active
234 * item is changed. This can be due to the user selecting
235 * a different item from the list, or due to a
236 * call to hildon_touch_selector_select_iter() on
237 * one of the columns.
240 hildon_touch_selector_signals[CHANGED] =
241 g_signal_new ("changed",
242 G_OBJECT_CLASS_TYPE (class),
244 G_STRUCT_OFFSET (HildonTouchSelectorClass, changed),
246 gtk_marshal_NONE__INT, G_TYPE_NONE, 1, G_TYPE_INT);
249 g_object_class_install_property (gobject_class, PROP_HAS_MULTIPLE_SELECTION,
250 g_param_spec_boolean ("has-multiple-selection",
251 "has multiple selection",
252 "Whether the widget has multiple "
253 "selection (like multiple columns, "
254 "multiselection mode, or multiple "
255 "internal widgets) and therefore "
256 "it may need a confirmation button, "
261 g_object_class_install_property (G_OBJECT_CLASS (gobject_class),
263 g_param_spec_boolean ("initial-scroll",
265 "Whether to scroll to the"
266 "current selection when"
267 "the selector is first"
270 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
272 /* style properties */
273 /* We need to ensure fremantle mode for the treeview in order to work
274 properly. This is not about the appearance, this is about behaviour */
275 gtk_rc_parse_string ("style \"fremantle-htst\" {\n"
276 " GtkWidget::hildon-mode = 1\n"
277 "} widget \"*.fremantle-htst\" style \"fremantle-htst\""
278 "widget_class \"*<HildonPannableArea>.GtkTreeView\" style :highest \"fremantle-htst\"");
280 g_type_class_add_private (object_class, sizeof (HildonTouchSelectorPrivate));
284 hildon_touch_selector_get_property (GObject * object,
286 GValue * value, GParamSpec * pspec)
288 HildonTouchSelectorPrivate *priv = HILDON_TOUCH_SELECTOR (object)->priv;
291 case PROP_HAS_MULTIPLE_SELECTION:
292 g_value_set_boolean (value,
293 hildon_touch_selector_has_multiple_selection (HILDON_TOUCH_SELECTOR (object)));
295 case PROP_INITIAL_SCROLL:
296 g_value_set_boolean (value, priv->initial_scroll);
299 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
305 hildon_touch_selector_set_property (GObject *object, guint prop_id,
306 const GValue *value, GParamSpec *pspec)
308 HildonTouchSelectorPrivate *priv = HILDON_TOUCH_SELECTOR (object)->priv;
311 case PROP_INITIAL_SCROLL:
312 priv->initial_scroll = g_value_get_boolean (value);
315 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
322 hildon_touch_selector_init (HildonTouchSelector * selector)
324 selector->priv = HILDON_TOUCH_SELECTOR_GET_PRIVATE (selector);
326 GTK_WIDGET_SET_FLAGS (GTK_WIDGET (selector), GTK_NO_WINDOW);
327 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (selector), FALSE);
329 selector->priv->columns = NULL;
331 selector->priv->print_func = NULL;
332 selector->priv->initial_scroll = TRUE;
333 selector->priv->hbox = gtk_hbox_new (FALSE, 0);
335 gtk_box_pack_end (GTK_BOX (selector), selector->priv->hbox,
337 gtk_widget_show (selector->priv->hbox);
341 * IMPLEMENTATION NOTES:
342 * Some people sent questions regarding a missing dispose/finalize function on
343 * this widget that could lead to leak memory, so we will clarify this topic.
345 * This is not required as #HildonTouchSelector extends #GtkContainer. When the
346 * widget is freed, the #GtkContainer freeing memory functions are called. This
347 * process includes remove each widget individually, so all the widgets are
350 * In the same way, this widget redefines gtk_container->remove function, in
351 * order to free the column related information if it is required.
353 * Please take a look to hildon_touch_selector_remove for more information.
356 /*------------------------------ GtkContainer ------------------------------ */
359 * Required in order to free the column at the columns list
362 hildon_touch_selector_remove (GtkContainer * container, GtkWidget * widget)
364 HildonTouchSelector *selector = NULL;
366 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (container));
367 selector = HILDON_TOUCH_SELECTOR (container);
369 /* Remove the extra data related to the columns, if required. */
370 if (widget == selector->priv->hbox) {
371 g_slist_foreach (selector->priv->columns, (GFunc) g_object_unref, NULL);
373 g_slist_free (selector->priv->columns);
375 selector->priv->columns = NULL;
377 g_debug ("Freeing a widget outside the columns logic");
380 /* Now remove the widget itself from the container */
381 GTK_CONTAINER_CLASS (hildon_touch_selector_parent_class)->remove (container, widget);
384 /* ------------------------------ PRIVATE METHODS ---------------------------- */
386 * default_print_func:
387 * @selector: a #HildonTouchSelector
389 * Default print function
391 * Returns: a new string that represents the selected items
394 _default_print_func (HildonTouchSelector * selector)
396 gchar *result = NULL;
398 gint num_columns = 0;
400 GtkTreeModel *model = NULL;
401 gchar *current_string = NULL;
403 HildonTouchSelectorSelectionMode mode;
405 GtkTreePath *current_path = NULL;
406 GList *selected_rows = NULL;
407 gint initial_value = 0;
408 gint text_column = -1;
409 HildonTouchSelectorColumn *column = NULL;
411 num_columns = hildon_touch_selector_get_num_columns (selector);
413 mode = hildon_touch_selector_get_column_selection_mode (selector);
415 if ((mode == HILDON_TOUCH_SELECTOR_SELECTION_MODE_MULTIPLE)
416 && (num_columns > 0)) {
417 /* In this case we get the first column first */
418 selected_rows = hildon_touch_selector_get_selected_rows (selector, 0);
419 model = hildon_touch_selector_get_model (selector, 0);
420 column = hildon_touch_selector_get_column (selector, 0);
421 g_object_get (G_OBJECT(column), "text-column", &text_column, NULL);
423 result = g_strdup_printf ("(");
425 for (item = selected_rows; item; item = g_list_next (item)) {
426 current_path = item->data;
427 gtk_tree_model_get_iter (model, &iter, current_path);
429 if (text_column != -1) {
430 gtk_tree_model_get (model, &iter, text_column, ¤t_string, -1);
433 if (i < g_list_length (selected_rows) - 1) {
434 aux = g_strconcat (result, current_string, ",", NULL);
438 aux = g_strconcat (result, current_string, NULL);
445 aux = g_strconcat (result, ")", NULL);
449 g_list_foreach (selected_rows, (GFunc) (gtk_tree_path_free), NULL);
450 g_list_free (selected_rows);
456 for (i = initial_value; i < num_columns; i++) {
457 model = hildon_touch_selector_get_model (selector, i);
458 column = hildon_touch_selector_get_column (selector, 0);
459 g_object_get (G_OBJECT(column), "text-column", &text_column, NULL);
461 if (hildon_touch_selector_get_selected (selector, i, &iter)) {
463 if (text_column != -1 ) {
464 gtk_tree_model_get (model, &iter, text_column, ¤t_string, -1);
467 aux = g_strconcat (result, ":", current_string, NULL);
471 result = current_string;
480 _selection_changed_cb (GtkTreeSelection * selection, gpointer user_data)
482 HildonTouchSelector *selector = NULL;
483 HildonTouchSelectorColumn *column = NULL;
484 gint num_column = -1;
486 column = HILDON_TOUCH_SELECTOR_COLUMN (user_data);
487 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (column->priv->parent));
489 selector = column->priv->parent;
491 num_column = g_slist_index (selector->priv->columns, column);
493 g_signal_emit (selector, hildon_touch_selector_signals[CHANGED], 0, num_column);
497 static HildonTouchSelectorColumn *
498 _create_new_column (HildonTouchSelector * selector,
499 GtkTreeModel * model,
500 GtkCellRenderer * renderer, va_list args)
502 HildonTouchSelectorColumn *new_column = NULL;
503 GtkTreeViewColumn *tree_column = NULL;
504 GtkTreeView *tv = NULL;
505 GtkWidget *panarea = NULL;
506 GtkTreeSelection *selection = NULL;
511 tree_column = gtk_tree_view_column_new ();
513 if (renderer != NULL) {
514 gtk_tree_view_column_pack_start (tree_column, renderer, TRUE);
516 attribute = va_arg (args, gchar *);
517 while (attribute != NULL) {
518 value = va_arg (args, gint);
519 gtk_tree_view_column_add_attribute (tree_column, renderer, attribute,
521 attribute = va_arg (args, gchar *);
526 tv = GTK_TREE_VIEW (hildon_gtk_tree_view_new (HILDON_UI_MODE_EDIT));
528 tv = GTK_TREE_VIEW (gtk_tree_view_new ());
529 #endif /* MAEMO_GTK */
531 gtk_tree_view_set_enable_search (tv, FALSE);
533 gtk_tree_view_set_model (tv, model);
534 gtk_tree_view_set_rules_hint (tv, TRUE);
536 gtk_tree_view_append_column (GTK_TREE_VIEW (tv), tree_column);
538 new_column = g_object_new (HILDON_TYPE_TOUCH_SELECTOR_COLUMN, NULL);
539 new_column->priv->parent = selector;
541 panarea = hildon_pannable_area_new ();
543 g_object_set (G_OBJECT (panarea), "vscrollbar-policy", GTK_POLICY_NEVER,
544 "initial-hint", FALSE, NULL);
546 gtk_container_add (GTK_CONTAINER (panarea), GTK_WIDGET (tv));
548 new_column->priv->model = model;
549 new_column->priv->tree_view = tv;
550 new_column->priv->panarea = panarea;
552 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tv));
553 gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
555 /* select the first item */
556 if (gtk_tree_model_get_iter_first (model, &iter)) {
557 gtk_tree_selection_select_iter (selection, &iter);
560 gtk_widget_grab_focus (GTK_WIDGET (tv));
562 /* connect to the changed signal connection */
563 g_signal_connect (G_OBJECT (selection), "changed",
564 G_CALLBACK (_selection_changed_cb), new_column);
566 g_signal_connect_after (G_OBJECT (panarea), "realize",
567 G_CALLBACK (_hildon_touch_selector_center_on_selected_items),
574 /* ------------------------ HildonTouchSelectorColumn implementation ---------------------- */
575 G_DEFINE_TYPE_WITH_CODE (HildonTouchSelectorColumn, hildon_touch_selector_column, G_TYPE_OBJECT,
576 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
577 hildon_touch_selector_column_cell_layout_init))
585 hildon_touch_selector_column_class_init (HildonTouchSelectorColumnClass *klass);
588 hildon_touch_selector_column_get_property (GObject *object, guint property_id,
589 GValue *value, GParamSpec *pspec);
592 hildon_touch_selector_column_set_property (GObject *object, guint property_id,
593 const GValue *value, GParamSpec *pspec);
596 hildon_touch_selector_column_set_text_column (HildonTouchSelectorColumn *column,
599 hildon_touch_selector_column_get_text_column (HildonTouchSelectorColumn *column);
603 hildon_touch_selector_column_class_init (HildonTouchSelectorColumnClass *klass)
605 GObjectClass *gobject_class = NULL;
607 gobject_class = G_OBJECT_CLASS (klass);
609 g_type_class_add_private (gobject_class, sizeof (HildonTouchSelectorColumnPrivate));
612 gobject_class->get_property = hildon_touch_selector_column_get_property;
613 gobject_class->set_property = hildon_touch_selector_column_set_property;
615 g_object_class_install_property (G_OBJECT_CLASS(klass),
617 g_param_spec_int ("text-column",
619 "A column in the data source model to get the strings from.",
627 hildon_touch_selector_column_init (HildonTouchSelectorColumn *column)
629 column->priv = G_TYPE_INSTANCE_GET_PRIVATE (column, HILDON_TYPE_TOUCH_SELECTOR_COLUMN,
630 HildonTouchSelectorColumnPrivate);
631 column->priv->text_column = -1;
635 hildon_touch_selector_column_set_text_column (HildonTouchSelectorColumn *column,
638 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR_COLUMN (column));
639 g_return_if_fail (text_column >= -1);
641 column->priv->text_column = text_column;
643 g_object_notify (G_OBJECT (column), "text-column");
647 hildon_touch_selector_column_get_text_column (HildonTouchSelectorColumn *column)
649 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR_COLUMN (column), -1);
651 return column->priv->text_column;
655 hildon_touch_selector_column_get_property (GObject *object, guint property_id,
656 GValue *value, GParamSpec *pspec)
658 switch (property_id) {
659 case PROP_TEXT_COLUMN:
660 g_value_set_int (value,
661 hildon_touch_selector_column_get_text_column (HILDON_TOUCH_SELECTOR_COLUMN (object)));
664 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
669 hildon_touch_selector_column_set_property (GObject *object, guint property_id,
670 const GValue *value, GParamSpec *pspec)
672 switch (property_id) {
673 case PROP_TEXT_COLUMN:
674 hildon_touch_selector_column_set_text_column (HILDON_TOUCH_SELECTOR_COLUMN (object),
675 g_value_get_int (value));
678 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
682 /* ------------------------ GtkCellLayout implementation -------------------- */
684 hildon_touch_selector_column_cell_layout_init (GtkCellLayoutIface *iface)
686 iface->pack_start = hildon_touch_selector_column_cell_layout_pack_start;
687 iface->pack_end = hildon_touch_selector_column_cell_layout_pack_end;
688 iface->clear = hildon_touch_selector_column_cell_layout_clear;
689 iface->add_attribute = hildon_touch_selector_column_cell_layout_add_attribute;
690 iface->set_cell_data_func = hildon_touch_selector_column_cell_layout_set_cell_data_func;
691 iface->clear_attributes = hildon_touch_selector_column_cell_layout_clear_attributes;
692 iface->reorder = hildon_touch_selector_column_cell_layout_reorder;
693 iface->get_cells = hildon_touch_selector_column_cell_layout_get_cells;
697 hildon_touch_selector_column_cell_layout_pack_start (GtkCellLayout *cell_layout,
698 GtkCellRenderer *cell,
701 HildonTouchSelectorColumn *sel_column = NULL;
702 GtkTreeViewColumn *view_column = NULL;
704 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR_COLUMN (cell_layout));
705 sel_column = HILDON_TOUCH_SELECTOR_COLUMN (cell_layout);
707 view_column = gtk_tree_view_get_column (sel_column->priv->tree_view, 0);
709 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT(view_column), cell, expand);
714 hildon_touch_selector_column_cell_layout_pack_end (GtkCellLayout *cell_layout,
715 GtkCellRenderer *cell,
718 HildonTouchSelectorColumn *sel_column = NULL;
719 GtkTreeViewColumn *view_column = NULL;
721 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR_COLUMN (cell_layout));
722 sel_column = HILDON_TOUCH_SELECTOR_COLUMN (cell_layout);
724 view_column = gtk_tree_view_get_column (sel_column->priv->tree_view, 0);
726 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT(view_column), cell, expand);
730 hildon_touch_selector_column_cell_layout_clear (GtkCellLayout *cell_layout)
732 HildonTouchSelectorColumn *sel_column = NULL;
733 GtkTreeViewColumn *view_column = NULL;
735 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR_COLUMN (cell_layout));
736 sel_column = HILDON_TOUCH_SELECTOR_COLUMN (cell_layout);
738 view_column = gtk_tree_view_get_column (sel_column->priv->tree_view, 0);
740 gtk_cell_layout_clear (GTK_CELL_LAYOUT(view_column));
744 hildon_touch_selector_column_cell_layout_add_attribute (GtkCellLayout *cell_layout,
745 GtkCellRenderer *cell,
746 const gchar *attribute,
749 HildonTouchSelectorColumn *sel_column = NULL;
750 GtkTreeViewColumn *view_column = NULL;
752 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR_COLUMN (cell_layout));
753 sel_column = HILDON_TOUCH_SELECTOR_COLUMN (cell_layout);
755 view_column = gtk_tree_view_get_column (sel_column->priv->tree_view, 0);
757 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT(view_column), cell, attribute, column);
762 hildon_touch_selector_column_cell_layout_set_cell_data_func (GtkCellLayout *cell_layout,
763 GtkCellRenderer *cell,
764 GtkCellLayoutDataFunc func,
766 GDestroyNotify destroy)
768 HildonTouchSelectorColumn *sel_column = NULL;
769 GtkTreeViewColumn *view_column = NULL;
771 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR_COLUMN (cell_layout));
772 sel_column = HILDON_TOUCH_SELECTOR_COLUMN (cell_layout);
774 view_column = gtk_tree_view_get_column (sel_column->priv->tree_view, 0);
776 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT(view_column), cell, func,
781 hildon_touch_selector_column_cell_layout_clear_attributes (GtkCellLayout *cell_layout,
782 GtkCellRenderer *cell)
784 HildonTouchSelectorColumn *sel_column = NULL;
785 GtkTreeViewColumn *view_column = NULL;
787 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR_COLUMN (cell_layout));
788 sel_column = HILDON_TOUCH_SELECTOR_COLUMN (cell_layout);
790 view_column = gtk_tree_view_get_column (sel_column->priv->tree_view, 0);
792 gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (view_column), cell);
796 hildon_touch_selector_column_cell_layout_reorder (GtkCellLayout *cell_layout,
797 GtkCellRenderer *cell,
800 HildonTouchSelectorColumn *sel_column = NULL;
801 GtkTreeViewColumn *view_column = NULL;
803 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR_COLUMN (cell_layout));
804 sel_column = HILDON_TOUCH_SELECTOR_COLUMN (cell_layout);
806 view_column = gtk_tree_view_get_column (sel_column->priv->tree_view, 0);
808 gtk_cell_layout_reorder (GTK_CELL_LAYOUT(view_column), cell, position);
812 hildon_touch_selector_column_cell_layout_get_cells (GtkCellLayout *cell_layout)
814 HildonTouchSelectorColumn *sel_column = NULL;
815 GtkTreeViewColumn *view_column = NULL;
817 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR_COLUMN (cell_layout), NULL);
818 sel_column = HILDON_TOUCH_SELECTOR_COLUMN (cell_layout);
820 view_column = gtk_tree_view_get_column (sel_column->priv->tree_view, 0);
822 return gtk_cell_layout_get_cells (GTK_CELL_LAYOUT(view_column));
825 /* ------------------------------ PUBLIC METHODS ---------------------------- */
828 * hildon_touch_selector_new:
830 * Creates a new empty #HildonTouchSelector.
832 * Returns: a new #HildonTouchSelector.
835 hildon_touch_selector_new (void)
837 return g_object_new (HILDON_TYPE_TOUCH_SELECTOR, NULL);
841 * hildon_touch_selector_new_text:
843 * Creates a #HildonTouchSelector with a single text column that
844 * can be populated conveniently through hildon_touch_selector_append_text(),
845 * hildon_touch_selector_prepend_text(), hildon_touch_selector_insert_text().
847 * Returns: A new #HildonTouchSelector
850 hildon_touch_selector_new_text (void)
854 HildonTouchSelectorColumn *column = NULL;
856 selector = hildon_touch_selector_new ();
857 store = gtk_list_store_new (1, G_TYPE_STRING);
859 column = hildon_touch_selector_append_text_column (HILDON_TOUCH_SELECTOR (selector),
860 GTK_TREE_MODEL (store), TRUE);
862 g_object_set (G_OBJECT (column), "text-column", 0, NULL);
868 * hildon_touch_selector_append_text:
869 * @selector: A #HildonTouchSelector.
870 * @text: a non %NULL text string.
872 * Appends a new entry in a #HildonTouchSelector created with
873 * hildon_touch_selector_new_text().
876 hildon_touch_selector_append_text (HildonTouchSelector * selector,
882 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (selector));
883 g_return_if_fail (text != NULL);
885 model = hildon_touch_selector_get_model (HILDON_TOUCH_SELECTOR (selector), 0);
887 g_return_if_fail (GTK_IS_LIST_STORE (model));
889 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
890 gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, text, -1);
894 * hildon_touch_selector_prepend_text:
895 * @selector: A #HildonTouchSelector.
896 * @text: a non %NULL text string.
898 * Prepends a new entry in a #HildonTouchSelector created with
899 * hildon_touch_selector_new_text().
902 hildon_touch_selector_prepend_text (HildonTouchSelector * selector,
908 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (selector));
909 g_return_if_fail (text != NULL);
911 model = hildon_touch_selector_get_model (HILDON_TOUCH_SELECTOR (selector), 0);
913 g_return_if_fail (GTK_IS_LIST_STORE (model));
915 gtk_list_store_prepend (GTK_LIST_STORE (model), &iter);
916 gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, text, -1);
920 * hildon_touch_selector_insert_text:
921 * @selector: a #HildonTouchSelector.
922 * @position: the position to insert @text.
923 * @text: A non %NULL text string.
925 * Inserts a new entry in particular position of a #HildoTouchSelector created
926 * with hildon_touch_selector_new_text().
930 hildon_touch_selector_insert_text (HildonTouchSelector * selector,
931 gint position, const gchar * text)
936 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (selector));
937 g_return_if_fail (text != NULL);
938 g_return_if_fail (position >= 0);
940 model = hildon_touch_selector_get_model (HILDON_TOUCH_SELECTOR (selector), 0);
942 g_return_if_fail (GTK_IS_LIST_STORE (model));
944 gtk_list_store_insert (GTK_LIST_STORE (model), &iter, position);
945 gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, text, -1);
949 * hildon_touch_selector_append_column
950 * @selector: a #HildonTouchSelector
951 * @model: the #GtkTreeModel with the data of the column
952 * @cell_renderer: The #GtkCellRenderer where to draw each row contents.
953 * @Varargs: a %NULL-terminated pair of attributes and column numbers.
955 * This functions adds a new column to the widget, whose data will
956 * be obtained from the model. Only widgets added this way should used on
957 * the selection logic, i.e., the print function, the #HildonTouchPicker::changed
960 * You can optionally pass a #GtkCellRenderer in @cell_renderer,
961 * together with a %NULL-terminated list of pairs property/value, in
962 * the same way you would use gtk_tree_view_column_set_attributes().
963 * This will pack @cell_renderer at the start of the column, expanded by default.
964 * If you prefer not to add it this way, you can simply pass %NULL to @cell_renderer
965 * and use the #GtkCellLayout interface on the returned #HildonTouchSelectorColumn
966 * to set your renderers.
968 * There is a prerequisite to be considered on models used: text data must
969 * be in the first column.
971 * This method basically adds a #GtkTreeView to the widget, using the model and
974 * Returns: the new column added added, %NULL otherwise.
977 HildonTouchSelectorColumn*
978 hildon_touch_selector_append_column (HildonTouchSelector * selector,
979 GtkTreeModel * model,
980 GtkCellRenderer * cell_renderer, ...)
983 HildonTouchSelectorColumn *new_column = NULL;
985 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), NULL);
986 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL);
990 va_start (args, cell_renderer);
991 new_column = _create_new_column (selector, model, cell_renderer, args);
992 g_object_ref_sink (new_column);
995 selector->priv->columns = g_slist_append (selector->priv->columns,
997 gtk_box_pack_start (GTK_BOX (selector->priv->hbox),
998 new_column->priv->panarea,
1001 gtk_widget_show_all (new_column->priv->panarea);
1010 * hildon_touch_selector_append_text_column
1011 * @selector: a #HildonTouchSelector
1012 * @model: a #GtkTreeModel with data for the column
1013 * @center: whether to center the text on the column
1015 * Equivalent to hildon_touch_selector_append_column(), but using a
1016 * default text cell renderer. This is the most common use case of the
1019 * Returns: the new column added, NULL otherwise.
1021 HildonTouchSelectorColumn*
1022 hildon_touch_selector_append_text_column (HildonTouchSelector * selector,
1023 GtkTreeModel * model, gboolean center)
1025 GtkCellRenderer *renderer = NULL;
1026 GValue val = { 0, };
1028 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), NULL);
1029 g_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL);
1031 if (model != NULL) {
1032 renderer = gtk_cell_renderer_text_new ();
1035 g_value_init (&val, G_TYPE_FLOAT);
1036 g_value_set_float (&val, 0.5);
1037 g_object_set_property (G_OBJECT (renderer), "xalign", &val);
1040 return hildon_touch_selector_append_column (selector, model, renderer,
1048 * hildon_touch_selector_remove_column:
1049 * @selector: a #HildonTouchSelector
1050 * @column: the position of the column to be removed
1052 * Removes a column from @selector.
1054 * Returns: %TRUE if the column was removed, %FALSE otherwise
1057 hildon_touch_selector_remove_column (HildonTouchSelector * selector, gint column)
1059 HildonTouchSelectorColumn *current_column = NULL;
1060 HildonTouchSelectorPrivate *priv;
1062 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), FALSE);
1063 g_return_val_if_fail (column <
1064 hildon_touch_selector_get_num_columns (selector), FALSE);
1066 priv = HILDON_TOUCH_SELECTOR_GET_PRIVATE (selector);
1067 current_column = g_slist_nth_data (priv->columns, column);
1069 gtk_container_remove (GTK_CONTAINER (priv->hbox), current_column->priv->panarea);
1070 priv->columns = g_slist_remove (priv->columns, current_column);
1071 g_object_unref (current_column);
1077 * hildon_touch_selector_set_column_attributes:
1078 * @selector: a #HildonTouchSelector
1079 * @num_column: the number of the column whose attributes we're setting
1080 * @cell_renderer: the #GtkCellRendere we're setting the attributes of
1081 * @Varargs: A %NULL-terminated list of attributes.
1083 * Sets the attributes for the given column. The attributes must be given
1084 * in attribute/column pairs, just like in gtk_tree_view_column_set_attributes().
1085 * All existing attributes are removed and replaced with the new ones.
1087 * Deprecated: #HildonTouchSelectorColumn implements #GtkCellLayout, use this
1088 * interface instead. See
1089 * hildon_touch_selector_get_column().
1093 hildon_touch_selector_set_column_attributes (HildonTouchSelector * selector,
1095 GtkCellRenderer * cell_renderer,
1099 GtkTreeViewColumn *tree_column = NULL;
1100 HildonTouchSelectorColumn *current_column = NULL;
1101 gchar *attribute = NULL;
1104 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (selector));
1105 g_return_if_fail (num_column <
1106 hildon_touch_selector_get_num_columns (selector));
1108 current_column = g_slist_nth_data (selector->priv->columns, num_column);
1110 tree_column = gtk_tree_view_get_column (current_column->priv->tree_view, 0);
1111 gtk_tree_view_remove_column (current_column->priv->tree_view, tree_column);
1113 tree_column = gtk_tree_view_column_new ();
1114 gtk_tree_view_column_pack_start (tree_column, cell_renderer, TRUE);
1116 va_start (args, cell_renderer);
1117 attribute = va_arg (args, gchar *);
1119 gtk_tree_view_column_clear_attributes (tree_column, cell_renderer);
1121 while (attribute != NULL) {
1122 value = va_arg (args, gint);
1123 gtk_tree_view_column_add_attribute (tree_column, cell_renderer,
1125 attribute = va_arg (args, gchar *);
1130 gtk_tree_view_append_column (current_column->priv->tree_view, tree_column);
1134 * hildon_touch_selector_get_num_columns:
1135 * @selector: a #HildonTouchSelector
1137 * Gets the number of columns in the #HildonTouchSelector.
1139 * Returns: the number of columns in @selector.
1142 hildon_touch_selector_get_num_columns (HildonTouchSelector * selector)
1144 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), -1);
1146 return g_slist_length (selector->priv->columns);
1150 * hildon_touch_selector_get_column_selection_mode:
1151 * @selector: a #HildonTouchSelector
1153 * Gets the selection mode of @selector.
1155 * Returns: one of #HildonTouchSelectorSelectionMode
1157 HildonTouchSelectorSelectionMode
1158 hildon_touch_selector_get_column_selection_mode (HildonTouchSelector * selector)
1160 HildonTouchSelectorSelectionMode result =
1161 HILDON_TOUCH_SELECTOR_SELECTION_MODE_SINGLE;
1162 GtkSelectionMode treeview_mode = GTK_SELECTION_BROWSE;
1163 HildonTouchSelectorColumn *column = NULL;
1164 GtkTreeSelection *selection = NULL;
1166 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), result);
1167 g_return_val_if_fail (hildon_touch_selector_get_num_columns (selector) > 0,
1170 column = HILDON_TOUCH_SELECTOR_COLUMN (selector->priv->columns->data);
1172 selection = gtk_tree_view_get_selection (column->priv->tree_view);
1173 treeview_mode = gtk_tree_selection_get_mode (selection);
1176 if (treeview_mode == GTK_SELECTION_MULTIPLE) {
1177 result = HILDON_TOUCH_SELECTOR_SELECTION_MODE_MULTIPLE;
1179 result = HILDON_TOUCH_SELECTOR_SELECTION_MODE_SINGLE;
1186 * hildon_touch_selector_set_column_selection_mode:
1187 * @selector: a #HildonTouchSelector
1188 * @mode: the #HildonTouchSelectorMode for @selector
1190 * Sets the selection mode for @selector. See #HildonTouchSelectorSelectionMode.
1193 hildon_touch_selector_set_column_selection_mode (HildonTouchSelector * selector,
1194 HildonTouchSelectorSelectionMode mode)
1196 GtkTreeView *tv = NULL;
1197 HildonTouchSelectorColumn *column = NULL;
1198 GtkTreeSelection *selection = NULL;
1199 GtkSelectionMode treeview_mode = GTK_SELECTION_MULTIPLE;
1201 HildonTouchSelectorSelectionMode current_mode;
1203 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (selector));
1204 g_return_if_fail (hildon_touch_selector_get_num_columns (selector) > 0);
1206 current_mode = hildon_touch_selector_get_column_selection_mode (selector);
1208 if (current_mode == mode) {
1212 column = HILDON_TOUCH_SELECTOR_COLUMN ((g_slist_nth (selector->priv->columns, 0))->data);
1213 tv = column->priv->tree_view;
1217 case HILDON_TOUCH_SELECTOR_SELECTION_MODE_SINGLE:
1218 treeview_mode = GTK_SELECTION_BROWSE;
1220 case HILDON_TOUCH_SELECTOR_SELECTION_MODE_MULTIPLE:
1221 treeview_mode = GTK_SELECTION_MULTIPLE;
1225 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tv));
1226 gtk_tree_selection_set_mode (selection, treeview_mode);
1228 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tv));
1229 gtk_tree_model_get_iter_first (column->priv->model, &iter);
1230 gtk_tree_selection_unselect_all (selection);
1231 gtk_tree_selection_select_iter (selection, &iter);
1237 * hildon_touch_selector_set_print_func:
1238 * @selector: a #HildonTouchSelector
1239 * @func: a #HildonTouchSelectorPrintFunc function
1241 * Sets the function to be used by hildon_touch_selector_get_current_text()
1242 * to produce a text representation of the currently selected items in @selector.
1243 * The default function will return a concatenation of comma separated items
1244 * selected in each column in @selector. Use this to override this method if you
1245 * need a particular representation for your application.
1249 hildon_touch_selector_set_print_func (HildonTouchSelector * selector,
1250 HildonTouchSelectorPrintFunc func)
1252 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (selector));
1254 selector->priv->print_func = func;
1258 * hildon_touch_selector_get_print_func:
1259 * @selector: a #HildonTouchSelector
1261 * Gets the #HildonTouchSelectorPrintFunc currently used. See
1262 * hildon_touch_selector_set_print_func().
1264 * Returns: a #HildonTouchSelectorPrintFunc or %NULL if the default
1265 * one is currently used.
1267 HildonTouchSelectorPrintFunc
1268 hildon_touch_selector_get_print_func (HildonTouchSelector * selector)
1270 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), NULL);
1272 return selector->priv->print_func;
1276 * hildon_touch_selector_set_active:
1277 * @selector: a #HildonTouchSelector
1278 * @column: column number
1279 * @index: the index of the item to select, or -1 to have no active item
1281 * Sets the active item of the #HildonTouchSelector to @index. The
1282 * column number is taken from @column.
1284 * @selector must be in %HILDON_TOUCH_SELECTOR_SELECTION_MODE_SINGLE
1287 hildon_touch_selector_set_active (HildonTouchSelector *selector,
1291 GtkTreeSelection *selection = NULL;
1292 HildonTouchSelectorColumn *current_column = NULL;
1293 HildonTouchSelectorSelectionMode mode;
1296 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (selector));
1297 g_return_if_fail (column < hildon_touch_selector_get_num_columns (selector));
1298 mode = hildon_touch_selector_get_column_selection_mode (selector);
1299 g_return_if_fail (mode == HILDON_TOUCH_SELECTOR_SELECTION_MODE_SINGLE);
1301 current_column = g_slist_nth_data (selector->priv->columns, column);
1303 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (current_column->priv->tree_view));
1304 path = gtk_tree_path_new_from_indices (index, -1);
1305 gtk_tree_selection_unselect_all (selection);
1307 gtk_tree_selection_select_path (selection, path);
1309 gtk_tree_path_free (path);
1313 * hildon_touch_selector_get_active:
1314 * @selector: a #HildonTouchSelector
1315 * @column: column number
1317 * Returns the index of the currently active item in column number
1318 * @column, or -1 if there's no active item.
1320 * @selector must be in %HILDON_TOUCH_SELECTOR_SELECTION_MODE_SINGLE
1322 * Returns: an integer which is the index of the currently active
1323 * item, or -1 if there's no active item.
1326 hildon_touch_selector_get_active (HildonTouchSelector *selector,
1329 GtkTreeSelection *selection = NULL;
1330 HildonTouchSelectorColumn *current_column = NULL;
1331 HildonTouchSelectorSelectionMode mode;
1332 GtkTreeModel *model;
1337 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), -1);
1338 g_return_val_if_fail (column < hildon_touch_selector_get_num_columns (selector), -1);
1339 mode = hildon_touch_selector_get_column_selection_mode (selector);
1340 g_return_val_if_fail (mode == HILDON_TOUCH_SELECTOR_SELECTION_MODE_SINGLE, -1);
1342 current_column = g_slist_nth_data (selector->priv->columns, column);
1344 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (current_column->priv->tree_view));
1345 model = gtk_tree_view_get_model (GTK_TREE_VIEW (current_column->priv->tree_view));
1347 gtk_tree_selection_get_selected (selection, NULL, &iter);
1348 path = gtk_tree_model_get_path (model, &iter);
1349 index = (gtk_tree_path_get_indices (path))[0];
1351 gtk_tree_path_free (path);
1357 * hildon_touch_selector_get_selected:
1358 * @selector: a #HildonTouchSelector
1359 * @column: the column number we want to get the element
1360 * @iter: #GtkTreeIter currently selected
1362 * Sets @iter to the currently selected node on the nth-column, if selection is
1363 * set to %HILDON_TOUCH_SELECTOR_SINGLE or %HILDON_TOUCH_SELECTOR_MULTIPLE with
1364 * a column different that the first one. @iter may be %NULL if you just want to
1365 * test if selection has any selected items.
1367 * This function will not work if selection is in
1368 * %HILDON_TOUCH_SELECTOR_MULTIPLE mode and the column is the first one.
1370 * See gtk_tree_selection_get_selected() for more information.
1372 * Returns: %TRUE if @iter was correctly set, %FALSE otherwise
1375 hildon_touch_selector_get_selected (HildonTouchSelector * selector,
1376 gint column, GtkTreeIter * iter)
1378 GtkTreeSelection *selection = NULL;
1379 HildonTouchSelectorColumn *current_column = NULL;
1380 HildonTouchSelectorSelectionMode mode;
1382 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), FALSE);
1383 g_return_val_if_fail (column < hildon_touch_selector_get_num_columns (selector),
1385 mode = hildon_touch_selector_get_column_selection_mode (selector);
1386 g_return_val_if_fail
1387 ((mode == HILDON_TOUCH_SELECTOR_SELECTION_MODE_SINGLE) ||
1388 ((mode == HILDON_TOUCH_SELECTOR_SELECTION_MODE_MULTIPLE)&&(column>0)),
1391 current_column = g_slist_nth_data (selector->priv->columns, column);
1394 gtk_tree_view_get_selection (GTK_TREE_VIEW (current_column->priv->tree_view));
1396 return gtk_tree_selection_get_selected (selection, NULL, iter);
1400 * hildon_touch_selector_select_iter
1401 * @selector: a #HildonTouchSelector
1402 * @column: the column to selects
1403 * @iter: the #GtkTreeIter to be selected
1404 * @scroll_to: whether to smoothly scroll to the item
1406 * Sets the currently selected item in the column @column to the one pointed by @iter,
1407 * optionally smoothly scrolling to it.
1411 hildon_touch_selector_select_iter (HildonTouchSelector * selector,
1412 gint column, GtkTreeIter * iter,
1416 GtkTreeModel *model;
1418 HildonTouchSelectorColumn *current_column = NULL;
1419 GtkTreeView *tv = NULL;
1420 GtkTreeSelection *selection = NULL;
1423 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (selector));
1424 g_return_if_fail (column < hildon_touch_selector_get_num_columns (selector));
1426 current_column = g_slist_nth_data (selector->priv->columns, column);
1428 tv = current_column->priv->tree_view;
1429 selection = gtk_tree_view_get_selection (tv);
1430 model = gtk_tree_view_get_model (tv);
1431 path = gtk_tree_model_get_path (model, iter);
1433 gtk_tree_selection_select_iter (selection, iter);
1436 gtk_tree_view_get_background_area (tv,
1438 gtk_tree_view_convert_bin_window_to_tree_coords (tv,
1439 0, rect.y, NULL, &y);
1440 hildon_pannable_area_scroll_to (HILDON_PANNABLE_AREA (current_column->priv->panarea),
1443 gtk_tree_path_free (path);
1447 * hildon_touch_selector_unselect_iter
1448 * @selector: a #HildonTouchSelector
1449 * @column: the column to unselects from
1450 * @iter: the #GtkTreeIter to be unselected
1452 * Unselect the item pointed by @iter in the column @column
1456 void hildon_touch_selector_unselect_iter (HildonTouchSelector * selector,
1460 HildonTouchSelectorColumn *current_column = NULL;
1461 GtkTreeSelection *selection = NULL;
1463 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (selector));
1464 g_return_if_fail (column < hildon_touch_selector_get_num_columns (selector));
1466 current_column = g_slist_nth_data (selector->priv->columns, column);
1467 selection = gtk_tree_view_get_selection (current_column->priv->tree_view);
1468 gtk_tree_selection_unselect_iter (selection, iter);
1472 * hildon_touch_selector_get_selected_rows:
1473 * @selector: a #HildonTouchSelector
1474 * @column: the position of the column to get the selected rows from
1476 * Creates a list of #GtkTreePath<!-- -->s of all selected rows in a column. Additionally,
1477 * if you to plan to modify the model after calling this function, you may
1478 * want to convert the returned list into a list of GtkTreeRowReferences. To do this,
1479 * you can use gtk_tree_row_reference_new().
1481 * See gtk_tree_selection_get_selected_rows() for more information.
1483 * Returns: A new #GList containing a #GtkTreePath for each selected row in the column @column.
1487 hildon_touch_selector_get_selected_rows (HildonTouchSelector * selector,
1490 GList *result = NULL;
1491 HildonTouchSelectorColumn *current_column = NULL;
1492 GtkTreeSelection *selection = NULL;
1494 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), NULL);
1495 g_return_val_if_fail (column < hildon_touch_selector_get_num_columns (selector),
1498 current_column = g_slist_nth_data (selector->priv->columns, column);
1499 selection = gtk_tree_view_get_selection (current_column->priv->tree_view);
1501 result = gtk_tree_selection_get_selected_rows (selection, NULL);
1507 * hildon_touch_selector_get_model:
1508 * @selector: a #HildonTouchSelector
1509 * @column: the position of the column in @selector
1511 * Gets the model of a column of @selector.
1513 * Returns: the #GtkTreeModel for the column @column of @selector.
1516 hildon_touch_selector_get_model (HildonTouchSelector * selector, gint column)
1518 HildonTouchSelectorColumn *current_column = NULL;
1520 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), NULL);
1521 g_return_val_if_fail (column < hildon_touch_selector_get_num_columns (selector),
1524 current_column = g_slist_nth_data (selector->priv->columns, column);
1526 return current_column->priv->model;
1530 _hildon_touch_selector_set_model (HildonTouchSelector * selector,
1531 gint column, GtkTreeModel * model)
1533 HildonTouchSelectorColumn *current_column = NULL;
1536 HILDON_TOUCH_SELECTOR_COLUMN (g_slist_nth_data (selector->priv->columns, column));
1538 current_column->priv->model = model;
1539 gtk_tree_view_set_model (current_column->priv->tree_view,
1540 current_column->priv->model);
1544 * hildon_touch_selector_set_model:
1545 * @selector: a #HildonTouchSelector
1546 * @column: the position of the column to set the model to
1547 * @model: a #GtkTreeModel
1549 * Sets the #GtkTreeModel for a particular column in @model.
1552 hildon_touch_selector_set_model (HildonTouchSelector * selector,
1553 gint column, GtkTreeModel * model)
1555 g_return_if_fail (HILDON_TOUCH_SELECTOR (selector));
1556 g_return_if_fail (column < hildon_touch_selector_get_num_columns (selector));
1558 HILDON_TOUCH_SELECTOR_GET_CLASS (selector)->set_model (selector, column, model);
1562 * hildon_touch_selector_get_current_text:
1563 * @selector: a #HildonTouchSelector
1565 * Returns a string representing the currently selected items for
1566 * each column of @selector. See hildon_touch_selector_set_print_func().
1568 * Returns: a newly allocated string.
1571 hildon_touch_selector_get_current_text (HildonTouchSelector * selector)
1573 gchar *result = NULL;
1574 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), NULL);
1576 if (selector->priv->print_func) {
1577 result = (*selector->priv->print_func) (selector);
1579 result = _default_print_func (selector);
1586 _hildon_touch_selector_center_on_selected_items (GtkWidget *widget,
1589 HildonTouchSelector *selector = NULL;
1590 HildonTouchSelectorColumn *column = NULL;
1592 GtkTreePath *path = NULL;
1595 gint num_column = -1;
1596 HildonTouchSelectorSelectionMode selection_mode;
1598 column = HILDON_TOUCH_SELECTOR_COLUMN (data);
1599 selector = column->priv->parent;
1601 if (!selector->priv->initial_scroll) {
1604 selection_mode = hildon_touch_selector_get_column_selection_mode (selector);
1605 num_column = g_slist_index (selector->priv->columns, column);
1607 if ((num_column == 0)
1608 && (selection_mode == HILDON_TOUCH_SELECTOR_SELECTION_MODE_MULTIPLE)) {
1613 if (hildon_touch_selector_get_selected (selector, num_column, &iter)) {
1614 path = gtk_tree_model_get_path (column->priv->model, &iter);
1615 gtk_tree_view_get_background_area (GTK_TREE_VIEW
1616 (column->priv->tree_view), path, NULL,
1619 gtk_tree_view_convert_bin_window_to_tree_coords (GTK_TREE_VIEW
1620 (column->priv->tree_view), 0,
1623 hildon_pannable_area_scroll_to (HILDON_PANNABLE_AREA
1624 (column->priv->panarea), -1, y);
1626 gtk_tree_path_free (path);
1633 _hildon_touch_selector_has_multiple_selection (HildonTouchSelector * selector)
1635 HildonTouchSelectorSelectionMode mode = HILDON_TOUCH_SELECTOR_SELECTION_MODE_SINGLE;
1638 n_columns = hildon_touch_selector_get_num_columns (selector);
1639 mode = hildon_touch_selector_get_column_selection_mode (selector);
1641 return ((n_columns > 1) || (mode == HILDON_TOUCH_SELECTOR_SELECTION_MODE_MULTIPLE));
1645 * hildon_touch_selector_has_multiple_selection:
1646 * @selector: A #HildonTouchSelector
1648 * Determines whether @selector is complex enough to actually require an
1649 * extra selection step than only picking an item. This is normally %TRUE
1650 * if @selector has multiple columns, multiple selection, or when it is a
1651 * more complex widget, like #HildonTouchSelectorEntry.
1653 * This information is useful for widgets containing a #HildonTouchSelector,
1654 * like #HildonPickerDialog, that could need a "Done" button, in case that
1655 * its internal #HildonTouchSelector has multiple columns, for instance.
1657 * Returns: %TRUE if @selector requires multiple selection steps.
1660 hildon_touch_selector_has_multiple_selection (HildonTouchSelector * selector)
1662 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), FALSE);
1664 return HILDON_TOUCH_SELECTOR_GET_CLASS (selector)->has_multiple_selection (selector);
1669 * hildon_touch_selector_get_column:
1670 * @selector: A #HildonTouchSelector
1671 * @column: a column number
1673 * Use this method to retrieve a #HildonTouchSelectorColumn. Then, you can use
1674 * the #GtkCellLayout interface to set up the layout of the column.
1676 * Returns: the @column<!-- -->-th #HildonTouchSelectorColumn in @selector
1678 HildonTouchSelectorColumn *
1679 hildon_touch_selector_get_column (HildonTouchSelector * selector,
1682 gint num_columns = -1;
1684 g_return_val_if_fail (HILDON_IS_TOUCH_SELECTOR (selector), NULL);
1685 num_columns = hildon_touch_selector_get_num_columns (selector);
1686 g_return_val_if_fail (column < num_columns && column >= 0, NULL);
1688 return g_slist_nth_data (selector->priv->columns, column);