summaryrefslogtreecommitdiff
path: root/packages/gtk+/gtk+-2.6.4-1.osso7/gtktreeselection.c.diff
blob: 5361f9b5d1f1c5687f25877eaeb8ca58a8be3165 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
--- gtk+-2.6.4/gtk/gtktreeselection.c	2004-11-20 01:18:38.000000000 +0200
+++ gtk+-2.6.4/gtk/gtktreeselection.c	2005-04-06 16:19:38.186733096 +0300
@@ -190,11 +190,28 @@
 			     GtkSelectionMode  type)
 {
   GtkTreeSelectionFunc tmp_func;
+  
   g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
 
   if (selection->type == type)
     return;
 
+  /* Hildon addition */
+  if ((type == GTK_SELECTION_SINGLE) &&
+      (selection->type == GTK_SELECTION_MULTIPLE ||
+       selection->type == GTK_SELECTION_BROWSE))
+    {
+      GtkTreePath *cursor_path;
+
+      /* to successfully switch from multiple selection mode to single
+         selection, we must ensure that anchor exists and is selected
+         since otherwise gtk_tree_selection_select_path won't work anymore */
+      if (gtk_tree_row_reference_valid (selection->tree_view->priv->cursor))
+        {
+          cursor_path = gtk_tree_row_reference_get_path (selection->tree_view->priv->cursor);          gtk_tree_selection_select_path (selection, cursor_path);
+          gtk_tree_path_free (cursor_path);
+        }
+    }
   
   if (type == GTK_SELECTION_NONE)
     {
@@ -251,6 +268,20 @@
     }
 
   selection->type = type;
+
+  /* Hildon addition */
+  if (type == GTK_SELECTION_SINGLE)
+    {
+      GtkTreePath *path;
+      GtkTreeIter iter;
+
+      /* reset cursor to the selected row */
+      gtk_tree_selection_get_selected (selection, NULL, &iter);
+      path = gtk_tree_model_get_path (selection->tree_view->priv->model,
+                                      &iter);
+      gtk_tree_view_set_cursor (selection->tree_view, path, NULL, FALSE);
+      gtk_tree_path_free (path);
+    }
 }
 
 /**
@@ -1319,10 +1350,10 @@
   return sensitive;
 }
 
-static gboolean
-row_is_selectable (GtkTreeSelection *selection,
-		   GtkRBNode        *node,
-		   GtkTreePath      *path)
+gboolean
+_gtk_tree_selection_is_row_selectable (GtkTreeSelection *selection,
+                                       GtkRBNode        *node,
+                                       GtkTreePath      *path)
 {
   GList *list;
   GtkTreeIter iter;
@@ -1411,7 +1442,7 @@
 	    {
 	      /* We only want to select the new node if we can unselect the old one,
 	       * and we can select the new one. */
-	      dirty = row_is_selectable (selection, node, path);
+	      dirty = _gtk_tree_selection_is_row_selectable (selection, node, path);
 
 	      /* if dirty is FALSE, we weren't able to select the new one, otherwise, we try to
 	       * unselect the new one
@@ -1528,8 +1559,13 @@
   if (GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED) != select)
     {
       path = _gtk_tree_view_find_path (selection->tree_view, tree, node);
-      selected = row_is_selectable (selection, node, path);
+      selected = _gtk_tree_selection_is_row_selectable (selection, node, path);
       gtk_tree_path_free (path);
+
+      /* if row is unselectable, allow unselection only */
+      if (!selected && !select &&
+          GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
+        selected = TRUE;
     }
 
   if (selected == TRUE)