[maemo-commits] [maemo-commits] r16831 - in projects/haf/trunk/gtk+: . gtk gtk/tests tests

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Mon Dec 1 16:08:55 EET 2008
Author: kris
Date: 2008-12-01 16:08:51 +0200 (Mon, 01 Dec 2008)
New Revision: 16831

Modified:
   projects/haf/trunk/gtk+/ChangeLog
   projects/haf/trunk/gtk+/gtk/gtk.symbols
   projects/haf/trunk/gtk+/gtk/gtkiconview.c
   projects/haf/trunk/gtk+/gtk/gtkiconview.h
   projects/haf/trunk/gtk+/gtk/gtktreeselection.c
   projects/haf/trunk/gtk+/gtk/gtktreeview.c
   projects/haf/trunk/gtk+/gtk/gtktreeview.h
   projects/haf/trunk/gtk+/gtk/tests/iconview-hildon.c
   projects/haf/trunk/gtk+/gtk/tests/treeview-hildon.c
   projects/haf/trunk/gtk+/tests/testhildontreeview.c
Log:
2008-12-01  Kristian Rietveld  <kris at imendio.com>

	Fixes: NB#91480 - GtkTreeView::hildon-ui-mode should not be
	construct-only

	* gtk/gtktreeview.[ch] (gtk_tree_view_class_init): document
	hildon-ui-mode property, remove construct-only requirement,
	(hildon_tree_view_set_hildon_ui_mode): set selection mode when
	to edit mode and the current selection mode is none; make public,
	(hildon_tree_view_get_hildon_ui_mode): new function.

	* gtk/gtktreeselection.c (gtk_tree_selection_set_mode): only
	select a row as anchor path if a selected row exists; otherwise
	it is the responsibility of the tree view to select a row.

	* gtk/gtkiconiew.[ch] (gtk_icon_view_class_init): document
	hildon-ui-mode property, remove construct-only requirement,
	(hildon_icon_view_set_hildon_ui_mode): set selection mode when
	to edit mode and the current selection mode is none; make public,
	(hildon_icon_view_get_hildon_ui_mode): new function.

	* gtk/tests/treeview-hildon.c
	* gtk/tests/iconview-hildon.c: add test cases for testing
	switching between normal and edit mode.

	* tests/testhildontreeview.c: add a simple window where mode
	switching can be tested.  It is a little broken, but does the trick
	;).

	* gtk/gtk.symbols: update with new public functions.



Modified: projects/haf/trunk/gtk+/ChangeLog
===================================================================
--- projects/haf/trunk/gtk+/ChangeLog	2008-12-01 14:05:23 UTC (rev 16830)
+++ projects/haf/trunk/gtk+/ChangeLog	2008-12-01 14:08:51 UTC (rev 16831)
@@ -1,3 +1,34 @@
+2008-12-01  Kristian Rietveld  <kris at imendio.com>
+
+	Fixes: NB#91480 - GtkTreeView::hildon-ui-mode should not be
+	construct-only
+
+	* gtk/gtktreeview.[ch] (gtk_tree_view_class_init): document
+	hildon-ui-mode property, remove construct-only requirement,
+	(hildon_tree_view_set_hildon_ui_mode): set selection mode when
+	to edit mode and the current selection mode is none; make public,
+	(hildon_tree_view_get_hildon_ui_mode): new function.
+
+	* gtk/gtktreeselection.c (gtk_tree_selection_set_mode): only
+	select a row as anchor path if a selected row exists; otherwise
+	it is the responsibility of the tree view to select a row.
+
+	* gtk/gtkiconiew.[ch] (gtk_icon_view_class_init): document
+	hildon-ui-mode property, remove construct-only requirement,
+	(hildon_icon_view_set_hildon_ui_mode): set selection mode when
+	to edit mode and the current selection mode is none; make public,
+	(hildon_icon_view_get_hildon_ui_mode): new function.
+
+	* gtk/tests/treeview-hildon.c
+	* gtk/tests/iconview-hildon.c: add test cases for testing
+	switching between normal and edit mode.
+
+	* tests/testhildontreeview.c: add a simple window where mode
+	switching can be tested.  It is a little broken, but does the trick
+	;).
+
+	* gtk/gtk.symbols: update with new public functions.
+
 2008-11-28  Christian Dywan  <christian at imendio.com>
 
 	Fixes: NB#90883: Progressbar height change

Modified: projects/haf/trunk/gtk+/gtk/gtk.symbols
===================================================================
--- projects/haf/trunk/gtk+/gtk/gtk.symbols	2008-12-01 14:05:23 UTC (rev 16830)
+++ projects/haf/trunk/gtk+/gtk/gtk.symbols	2008-12-01 14:08:51 UTC (rev 16831)
@@ -1897,7 +1897,9 @@
 gtk_icon_view_get_tooltip_context
 gtk_icon_view_set_tooltip_column
 gtk_icon_view_get_tooltip_column
+hildon_icon_view_get_hildon_ui_mode
 hildon_icon_view_get_row_header_func
+hildon_icon_view_set_hildon_ui_mode
 hildon_icon_view_set_row_header_func
 #endif
 #endif
@@ -4521,7 +4523,9 @@
 gtk_tree_view_widget_to_tree_coords
 #endif
 gtk_tree_view_columns_autosize
+hildon_tree_view_get_hildon_ui_mode
 hildon_tree_view_get_row_header_func
+hildon_tree_view_set_hildon_ui_mode
 hildon_tree_view_set_row_header_func
 #endif
 #endif

Modified: projects/haf/trunk/gtk+/gtk/gtkiconview.c
===================================================================
--- projects/haf/trunk/gtk+/gtk/gtkiconview.c	2008-12-01 14:05:23 UTC (rev 16830)
+++ projects/haf/trunk/gtk+/gtk/gtkiconview.c	2008-12-01 14:08:51 UTC (rev 16831)
@@ -484,8 +484,6 @@
 #ifdef MAEMO_CHANGES
 static void     free_queued_activate_item                (GtkIconView   *icon_view);
 static void     free_queued_select_item                  (GtkIconView   *icon_view);
-static void     gtk_icon_view_set_hildon_ui_mode         (GtkIconView   *icon_view,
-                                                          HildonUIMode   hildon_ui_mode);
 #endif /* MAEMO_CHANGES */
 
 /* GtkBuildable */
@@ -795,6 +793,21 @@
                                                        GTK_PARAM_READWRITE));
 
 #ifdef MAEMO_CHANGES
+  /**
+   * GtkIconView::hildon-ui-mode
+   *
+   * Specifies which UI mode to use.  A setting of #HILDON_UI_MODE_NORMAL
+   * will cause the icon view to disable selections and emit item-activated
+   * as soon as an item is pressed.  When #HILDON_UI_MODE_EDIT is set,
+   * selections can be made according to the setting of the mode in
+   * GtkIconView::selection-mode.
+   *
+   * Toggling this property will cause the icon view to select an
+   * appropriate selection mode if not already done.
+   *
+   * Since: maemo 5.0
+   * Stability: unstable.
+   */
   g_object_class_install_property (gobject_class,
 				   PROP_HILDON_UI_MODE,
 				   g_param_spec_enum ("hildon-ui-mode",
@@ -802,7 +815,7 @@
 						      P_("The mode according to which the icon view should behave"),
 						      HILDON_TYPE_UI_MODE,
                                                       HILDON_UI_MODE_NORMAL,
-						      GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+						      GTK_PARAM_READWRITE));
 #endif /* MAEMO_CHANGES */
 
 
@@ -1166,7 +1179,7 @@
 
 #ifdef MAEMO_CHANGES
     case PROP_HILDON_UI_MODE:
-      gtk_icon_view_set_hildon_ui_mode (icon_view, g_value_get_enum (value));
+      hildon_icon_view_set_hildon_ui_mode (icon_view, g_value_get_enum (value));
       break;
 #endif /* MAEMO_CHANGES */
 
@@ -1346,7 +1359,7 @@
 
 #ifdef MAEMO_CHANGES
   /* Reset the UI mode */
-  gtk_icon_view_set_hildon_ui_mode (icon_view, icon_view->priv->hildon_ui_mode);
+  hildon_icon_view_set_hildon_ui_mode (icon_view, icon_view->priv->hildon_ui_mode);
 
   /* FIXME: might want to update the row_header_layout if it exists */
 #endif /* MAEMO_CHANGES */
@@ -8132,12 +8145,22 @@
     }
 }
 
-static void
-gtk_icon_view_set_hildon_ui_mode (GtkIconView   *icon_view,
-                                  HildonUIMode   hildon_ui_mode)
+HildonUIMode
+hildon_icon_view_get_hildon_ui_mode (GtkIconView *icon_view)
 {
+  g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), 0);
+
+  return icon_view->priv->hildon_ui_mode;
+}
+
+void
+hildon_icon_view_set_hildon_ui_mode (GtkIconView   *icon_view,
+                                     HildonUIMode   hildon_ui_mode)
+{
   HildonMode mode;
 
+  g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
+
   icon_view->priv->hildon_ui_mode = hildon_ui_mode;
 
   gtk_widget_style_get (GTK_WIDGET (icon_view),
@@ -8156,6 +8179,11 @@
       int count = 0;
       GList *list;
 
+      if (gtk_icon_view_get_selection_mode (icon_view) == GTK_SELECTION_NONE)
+        {
+          gtk_icon_view_set_selection_mode (icon_view, GTK_SELECTION_SINGLE);
+        }
+
       /* Instead of using gtk_icon_view_get_selected_items() we walk
        * over the list of items ourselves to save allocating/deallocating all
        * paths.

Modified: projects/haf/trunk/gtk+/gtk/gtkiconview.h
===================================================================
--- projects/haf/trunk/gtk+/gtk/gtkiconview.h	2008-12-01 14:05:23 UTC (rev 16830)
+++ projects/haf/trunk/gtk+/gtk/gtkiconview.h	2008-12-01 14:08:51 UTC (rev 16831)
@@ -234,6 +234,10 @@
                                                                   HildonIconViewRowHeaderFunc  func,
                                                                   gpointer                     data,
                                                                   GDestroyNotify               destroy);
+
+HildonUIMode                hildon_icon_view_get_hildon_ui_mode  (GtkIconView                  *icon_view);
+void                        hildon_icon_view_set_hildon_ui_mode  (GtkIconView                  *icon_view,
+                                                                  HildonUIMode                  mode);
 #endif /* MAEMO_CHANGES */
 
 G_END_DECLS

Modified: projects/haf/trunk/gtk+/gtk/gtktreeselection.c
===================================================================
--- projects/haf/trunk/gtk+/gtk/gtktreeselection.c	2008-12-01 14:05:23 UTC (rev 16830)
+++ projects/haf/trunk/gtk+/gtk/gtktreeselection.c	2008-12-01 14:08:51 UTC (rev 16831)
@@ -230,7 +230,9 @@
           /* One item must stay selected; we look for the first selected
            * item we can find, that one becomes the anchor.  We silently
            * assume here that there is at least *one* selected row,
-           * as mandated by any new-style edit mode.
+           * as mandated by any new-style edit mode.  When switching
+           * from SELECTION_NONE there is no selected row, and the
+           * tree view will be responsible for selecting a node.
            */
 
           if (anchor_path)
@@ -242,19 +244,22 @@
            * as soon as a selected node is found.
            */
           rows = gtk_tree_selection_get_selected_rows (selection, NULL);
-          anchor_path = gtk_tree_path_copy (rows->data);
-          g_list_foreach (rows, (GFunc)gtk_tree_path_free, NULL);
-          g_list_free (rows);
+          if (rows)
+            {
+              anchor_path = gtk_tree_path_copy (rows->data);
+              g_list_foreach (rows, (GFunc)gtk_tree_path_free, NULL);
+              g_list_free (rows);
 
-          _gtk_tree_view_find_node (selection->tree_view,
-                                    anchor_path,
-                                    &tree,
-                                    &node);
+              _gtk_tree_view_find_node (selection->tree_view,
+                                        anchor_path,
+                                        &tree,
+                                        &node);
 
-          if (node && GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
-            selected = TRUE;
+              if (node && GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
+                selected = TRUE;
 
-          g_return_if_fail (selected == TRUE);
+              g_return_if_fail (selected == TRUE);
+            }
         }
 #endif /* MAEMO_CHANGES */
 

Modified: projects/haf/trunk/gtk+/gtk/gtktreeview.c
===================================================================
--- projects/haf/trunk/gtk+/gtk/gtktreeview.c	2008-12-01 14:05:23 UTC (rev 16830)
+++ projects/haf/trunk/gtk+/gtk/gtktreeview.c	2008-12-01 14:08:51 UTC (rev 16831)
@@ -493,8 +493,6 @@
 						  GdkEvent  *event);
 static void     free_queued_select_row           (GtkTreeView  *tree_view);
 static void     free_queued_activate_row         (GtkTreeView  *tree_view);
-static void     gtk_tree_view_set_hildon_ui_mode (GtkTreeView  *tree_view,
-                                                  HildonUIMode  hildon_ui_mode);
 #endif /* MAEMO_CHANGES */
 
 static guint tree_view_signals [LAST_SIGNAL] = { 0 };
@@ -810,6 +808,21 @@
 						       GTK_PARAM_READWRITE));
 
 #ifdef MAEMO_CHANGES
+    /**
+     * GtkTreeView:hildon-ui-mode:
+     *
+     * Specifies which UI mode to use.  A setting of #HILDON_UI_MODE_NORMAL
+     * will cause the tree view to disable selections and emit row-activated
+     * as soon as a row is pressed.  When #HILDON_UI_MODE_EDIT is set,
+     * selections can be made according to the setting of the mode on
+     * GtkTreeSelection.
+     *
+     * Toggling this property will cause the tree view to select an
+     * appropriate selection mode if not already done.
+     *
+     * Since: maemo 5.0
+     * Stability: unstable
+     */
     g_object_class_install_property (o_class,
                                      PROP_HILDON_UI_MODE,
                                      g_param_spec_enum ("hildon-ui-mode",
@@ -817,7 +830,7 @@
                                                         P_("The Hildon UI mode according to which the tree view should behave"),
                                                         HILDON_TYPE_UI_MODE,
                                                         HILDON_UI_MODE_NORMAL,
-                                                        GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+                                                        GTK_PARAM_READWRITE));
 #endif /* MAEMO_CHANGES */
 
   /* Style properties */
@@ -1581,7 +1594,7 @@
       break;
 #ifdef MAEMO_CHANGES
     case PROP_HILDON_UI_MODE:
-      gtk_tree_view_set_hildon_ui_mode (tree_view, g_value_get_enum (value));
+      hildon_tree_view_set_hildon_ui_mode (tree_view, g_value_get_enum (value));
       break;
 #endif /* MAEMO_CHANGES */
     default:
@@ -9016,7 +9029,7 @@
 
 #ifdef MAEMO_CHANGES
   /* Reset the UI mode */
-  gtk_tree_view_set_hildon_ui_mode (tree_view, tree_view->priv->hildon_ui_mode);
+  hildon_tree_view_set_hildon_ui_mode (tree_view, tree_view->priv->hildon_ui_mode);
 
   /* FIXME: possibly update row_header_layout if it exists */
 #endif /* MAEMO_CHANGES */
@@ -17297,18 +17310,27 @@
   tree_view->priv->queued_activate_row = NULL;
 }
 
-static void
-gtk_tree_view_set_hildon_ui_mode (GtkTreeView   *tree_view,
-                                  HildonUIMode   hildon_ui_mode)
+HildonUIMode
+hildon_tree_view_get_hildon_ui_mode (GtkTreeView *tree_view)
 {
+  g_return_val_if_fail (GTK_IS_TREE_VIEW (tree_view), 0);
+
+  return tree_view->priv->hildon_ui_mode;
+}
+
+void
+hildon_tree_view_set_hildon_ui_mode (GtkTreeView   *tree_view,
+                                     HildonUIMode   hildon_ui_mode)
+{
   HildonMode mode;
 
+  g_return_if_fail (GTK_IS_TREE_VIEW (tree_view));
+
+  /* Don't check if the new mode matches the old mode; always continue
+   * so that the selection corrections below always happen.
+   */
   tree_view->priv->hildon_ui_mode = hildon_ui_mode;
 
-  /* Since hildon-mode is a construct-only property, we should not
-   * have to deal with the case where we switch from one mode to
-   * the other
-   */
   gtk_widget_style_get (GTK_WIDGET (tree_view),
                         "hildon-mode", &mode,
                         NULL);
@@ -17326,6 +17348,12 @@
     }
   else if (hildon_ui_mode == HILDON_UI_MODE_EDIT)
     {
+      if (gtk_tree_selection_get_mode (tree_view->priv->selection) == GTK_SELECTION_NONE)
+        {
+          gtk_tree_selection_set_mode (tree_view->priv->selection,
+                                       GTK_SELECTION_SINGLE);
+        }
+
       if (gtk_tree_selection_count_selected_rows (tree_view->priv->selection) < 1)
         {
           GtkTreePath *path;

Modified: projects/haf/trunk/gtk+/gtk/gtktreeview.h
===================================================================
--- projects/haf/trunk/gtk+/gtk/gtktreeview.h	2008-12-01 14:05:23 UTC (rev 16830)
+++ projects/haf/trunk/gtk+/gtk/gtktreeview.h	2008-12-01 14:08:51 UTC (rev 16831)
@@ -408,6 +408,10 @@
                                                                   HildonTreeViewRowHeaderFunc  func,
                                                                   gpointer                     data,
                                                                   GDestroyNotify               destroy);
+
+HildonUIMode                hildon_tree_view_get_hildon_ui_mode  (GtkTreeView                 *tree_view);
+void                        hildon_tree_view_set_hildon_ui_mode  (GtkTreeView                 *tree_view,
+                                                                  HildonUIMode                 mode);
 #endif /* MAEMO_CHANGES */
 
 GtkTreeViewGridLines        gtk_tree_view_get_grid_lines         (GtkTreeView                *tree_view);

Modified: projects/haf/trunk/gtk+/gtk/tests/iconview-hildon.c
===================================================================
--- projects/haf/trunk/gtk+/gtk/tests/iconview-hildon.c	2008-12-01 14:05:23 UTC (rev 16830)
+++ projects/haf/trunk/gtk+/gtk/tests/iconview-hildon.c	2008-12-01 14:08:51 UTC (rev 16831)
@@ -239,6 +239,32 @@
   g_assert (gtk_icon_view_count_selected_rows (GTK_ICON_VIEW (fixture->icon_view)) == 1);
 }
 
+static void
+normal_to_edit_test (HildonIconViewFixture *fixture,
+                     gconstpointer          test_data)
+{
+  normal_selection_none (fixture, test_data);
+
+  g_object_set (fixture->icon_view,
+                "hildon-ui-mode", HILDON_UI_MODE_EDIT,
+                NULL);
+
+  edit_selection_single (fixture, test_data);
+}
+
+static void
+edit_multi_to_normal_test (HildonIconViewFixture *fixture,
+                           gconstpointer          test_data)
+{
+  edit_selection_multi (fixture, test_data);
+
+  g_object_set (fixture->icon_view,
+                "hildon-ui-mode", HILDON_UI_MODE_NORMAL,
+                NULL);
+
+  normal_selection_none (fixture, test_data);
+}
+
 int
 main (int argc, char **argv)
 {
@@ -276,5 +302,16 @@
               edit_multi_to_single,
               hildon_icon_view_fixture_teardown);
 
+  g_test_add ("/iconview/hildon/normal-to-edit-test",
+              HildonIconViewFixture, NULL,
+              hildon_icon_view_fixture_single_setup,
+              normal_to_edit_test,
+              hildon_icon_view_fixture_teardown);
+  g_test_add ("/iconview/hildon/edit-multi-to-normal-test",
+              HildonIconViewFixture, NULL,
+              hildon_icon_view_fixture_edit_multi_setup,
+              edit_multi_to_normal_test,
+              hildon_icon_view_fixture_teardown);
+
   return g_test_run ();
 }

Modified: projects/haf/trunk/gtk+/gtk/tests/treeview-hildon.c
===================================================================
--- projects/haf/trunk/gtk+/gtk/tests/treeview-hildon.c	2008-12-01 14:05:23 UTC (rev 16830)
+++ projects/haf/trunk/gtk+/gtk/tests/treeview-hildon.c	2008-12-01 14:08:51 UTC (rev 16831)
@@ -218,6 +218,32 @@
   g_assert (gtk_tree_selection_count_selected_rows (fixture->selection) == 1);
 }
 
+static void
+normal_to_edit_test (HildonTreeViewFixture *fixture,
+                     gconstpointer          test_data)
+{
+  normal_selection_none (fixture, test_data);
+
+  g_object_set (fixture->tree_view,
+                "hildon-ui-mode", HILDON_UI_MODE_EDIT,
+                NULL);
+
+  edit_selection_single (fixture, test_data);
+}
+
+static void
+edit_multi_to_normal_test (HildonTreeViewFixture *fixture,
+                           gconstpointer          test_data)
+{
+  edit_selection_multi (fixture, test_data);
+
+  g_object_set (fixture->tree_view,
+                "hildon-ui-mode", HILDON_UI_MODE_NORMAL,
+                NULL);
+
+  normal_selection_none (fixture, test_data);
+}
+
 int
 main (int argc, char **argv)
 {
@@ -255,5 +281,16 @@
               edit_multi_to_single,
               hildon_tree_view_fixture_teardown);
 
+  g_test_add ("/treeview/hildon/normal-to-edit-test",
+              HildonTreeViewFixture, NULL,
+              hildon_tree_view_fixture_single_setup,
+              normal_to_edit_test,
+              hildon_tree_view_fixture_teardown);
+  g_test_add ("/treeview/hildon/edit-multi-to-normal-test",
+              HildonTreeViewFixture, NULL,
+              hildon_tree_view_fixture_edit_multi_setup,
+              edit_multi_to_normal_test,
+              hildon_tree_view_fixture_teardown);
+
   return g_test_run ();
 }

Modified: projects/haf/trunk/gtk+/tests/testhildontreeview.c
===================================================================
--- projects/haf/trunk/gtk+/tests/testhildontreeview.c	2008-12-01 14:05:23 UTC (rev 16830)
+++ projects/haf/trunk/gtk+/tests/testhildontreeview.c	2008-12-01 14:08:51 UTC (rev 16831)
@@ -6,6 +6,7 @@
  */
 
 #include <gtk/gtk.h>
+#include <string.h>
 
 enum
 {
@@ -36,6 +37,13 @@
 }
 
 static void
+selection_changed_callback (GtkTreeSelection *selection,
+                            gpointer          user_data)
+{
+  g_print ("selection changed.\n");
+}
+
+static void
 row_activated_callback (GtkWidget         *tree_view,
                         GtkTreePath       *path,
                         GtkTreeViewColumn *column,
@@ -90,6 +98,8 @@
                             NULL);
 
   selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));
+  g_signal_connect (selection, "changed",
+                    G_CALLBACK (selection_changed_callback), NULL);
   if (multi_select)
     gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);
   else if (mode != HILDON_UI_MODE_NORMAL)
@@ -161,6 +171,100 @@
   gtk_widget_show_all (window);
 }
 
+static void
+ui_mode_changed (GtkComboBox *combo_box,
+                 gpointer     user_data)
+{
+  gchar *text;
+
+  text = gtk_combo_box_get_active_text (combo_box);
+  if (!strcmp (text, "UI_MODE_NORMAL"))
+    g_object_set (user_data, "hildon-ui-mode", HILDON_UI_MODE_NORMAL, NULL);
+  else if (!strcmp (text, "UI_MODE_EDIT"))
+    g_object_set (user_data, "hildon-ui-mode", HILDON_UI_MODE_EDIT, NULL);
+
+  g_free (text);
+}
+
+static void
+selection_mode_changed (GtkComboBox *combo_box,
+                        gpointer     user_data)
+{
+  gchar *text;
+  GtkTreeSelection *selection;
+
+  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (user_data));
+
+  text = gtk_combo_box_get_active_text (combo_box);
+  if (!strcmp (text, "SINGLE"))
+    gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
+  else if (!strcmp (text, "MULTIPLE"))
+    gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);
+
+  g_free (text);
+}
+
+static void
+create_mode_switch_window (GtkWidget *button,
+                           gpointer   user_data)
+{
+  GtkWidget *window;
+  GtkWidget *mainbox;
+  GtkWidget *sw;
+  GtkWidget *tree_view;
+  GtkWidget *vbox;
+  GtkWidget *combo_box;
+  GtkWidget *close;
+
+  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+  g_signal_connect (window, "delete-event",
+                    G_CALLBACK (gtk_widget_destroy), window);
+  gtk_container_set_border_width (GTK_CONTAINER (window), 6);
+
+  mainbox = gtk_hbox_new (TRUE, 6);
+  gtk_container_add (GTK_CONTAINER (window), mainbox);
+
+  /* tree view */
+  sw = gtk_scrolled_window_new (NULL, NULL);
+  gtk_box_pack_start (GTK_BOX (mainbox), sw, TRUE, TRUE, 0);
+
+  tree_view = create_tree_view (HILDON_UI_MODE_NORMAL, "fremantle-widget",
+                                0);
+  g_signal_connect (tree_view, "row-activated",
+                    G_CALLBACK (row_activated_callback), NULL);
+
+  gtk_widget_set_size_request (tree_view, 280, 400);
+  gtk_container_add (GTK_CONTAINER (sw), tree_view);
+
+  /* combo boxes */
+  vbox = gtk_vbox_new (FALSE, 10);
+  gtk_box_pack_start (GTK_BOX (mainbox), vbox, TRUE, TRUE, 0);
+
+  combo_box = gtk_combo_box_new_text ();
+  gtk_combo_box_append_text (GTK_COMBO_BOX (combo_box), "UI_MODE_NORMAL");
+  gtk_combo_box_append_text (GTK_COMBO_BOX (combo_box), "UI_MODE_EDIT");
+  gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), 0);
+  g_signal_connect (combo_box, "changed",
+                    G_CALLBACK (ui_mode_changed), tree_view);
+  gtk_box_pack_start (GTK_BOX (vbox), combo_box, FALSE, FALSE, 0);
+
+  combo_box = gtk_combo_box_new_text ();
+  gtk_combo_box_append_text (GTK_COMBO_BOX (combo_box), "SINGLE");
+  gtk_combo_box_append_text (GTK_COMBO_BOX (combo_box), "MULTIPLE");
+  gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), 0);
+  g_signal_connect (combo_box, "changed",
+                    G_CALLBACK (selection_mode_changed), tree_view);
+  gtk_box_pack_start (GTK_BOX (vbox), combo_box, FALSE, FALSE, 0);
+
+  /* close */
+  close = gtk_button_new_with_label ("Close");
+  g_signal_connect_swapped (close, "clicked",
+                            G_CALLBACK (gtk_widget_destroy), window);
+  gtk_box_pack_end (GTK_BOX (vbox), close, FALSE, FALSE, 0);
+
+  gtk_widget_show_all (window);
+}
+
 int
 main (int argc, char **argv)
 {
@@ -260,7 +364,13 @@
                     GINT_TO_POINTER (EDIT_MODE | MULTI_SELECT));
   gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
 
+  /* Mode switching */
+  button = gtk_button_new_with_label ("Mode switching");
+  g_signal_connect (button, "clicked",
+                    G_CALLBACK (create_mode_switch_window), NULL);
+  gtk_box_pack_start (GTK_BOX (mainbox), button, FALSE, FALSE, 0);
 
+
   button = gtk_button_new_with_label ("Close");
   g_signal_connect (button, "clicked",
                     G_CALLBACK (gtk_main_quit), NULL);


More information about the maemo-commits mailing list