[gtk+/treeview-refactor-staging] Fixed GtkTreeView to give focus back to the last focued cell when hitting the edge.



commit 4417a7fde61c7802fc36d0c56420e495cce98ea5
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date:   Fri Dec 10 16:12:02 2010 +0900

    Fixed GtkTreeView to give focus back to the last focued cell when hitting
    the edge.
    
    When focusing left/right or up/down inside GtkCellArea, now we save what
    was the last focused cell and if we hit the side (or top or bottom) of
    the view we then restore focus to the last focused cell.

 gtk/gtktreeview.c |   24 +++++++++++++++++++++---
 1 files changed, 21 insertions(+), 3 deletions(-)
---
diff --git a/gtk/gtktreeview.c b/gtk/gtktreeview.c
index 3095fc7..48225b9 100644
--- a/gtk/gtktreeview.c
+++ b/gtk/gtktreeview.c
@@ -10096,6 +10096,7 @@ gtk_tree_view_move_cursor_up_down (GtkTreeView *tree_view,
   gboolean selectable;
   GtkDirectionType direction;
   GtkCellArea *cell_area = NULL;
+  GtkCellRenderer *last_focus_cell = NULL;
   GtkTreeIter iter;
 
   if (! gtk_widget_has_focus (GTK_WIDGET (tree_view)))
@@ -10116,7 +10117,6 @@ gtk_tree_view_move_cursor_up_down (GtkTreeView *tree_view,
 
   direction = count < 0 ? GTK_DIR_UP : GTK_DIR_DOWN;
 
-
   if (tree_view->priv->focus_column)
     cell_area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (tree_view->priv->focus_column));
 
@@ -10129,7 +10129,12 @@ gtk_tree_view_move_cursor_up_down (GtkTreeView *tree_view,
 					       &iter,
 					       GTK_RBNODE_FLAG_SET (cursor_node, GTK_RBNODE_IS_PARENT),
 					       cursor_node->children?TRUE:FALSE);
-      
+
+      /* Save the last cell that had focus, if we hit the end of the view we'll give
+       * focus back to it. */
+      last_focus_cell = gtk_cell_area_get_focus_cell (cell_area);
+
+      /* If focus stays in the area, no need to change the cursor row */
       if (gtk_cell_area_focus (cell_area, direction))
 	return;
     }
@@ -10235,6 +10240,9 @@ gtk_tree_view_move_cursor_up_down (GtkTreeView *tree_view,
         {
           gtk_widget_error_bell (GTK_WIDGET (tree_view));
         }
+
+      if (cell_area)
+	gtk_cell_area_set_focus_cell (cell_area, last_focus_cell);
     }
 
   if (grab_focus)
@@ -10363,7 +10371,9 @@ gtk_tree_view_move_cursor_left_right (GtkTreeView *tree_view,
   gboolean found_column = FALSE;
   gboolean rtl;
   GtkDirectionType direction;
-  GtkCellArea *cell_area;
+  GtkCellArea     *cell_area;
+  GtkCellRenderer *last_focus_cell = NULL;
+  GtkCellArea     *last_focus_area = NULL;
 
   rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
 
@@ -10388,6 +10398,11 @@ gtk_tree_view_move_cursor_left_right (GtkTreeView *tree_view,
   list = rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns);
   if (tree_view->priv->focus_column)
     {
+      /* Save the cell/area we are moving focus from, if moving the cursor
+       * by one step hits the end we'll set focus back here */
+      last_focus_area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (tree_view->priv->focus_column));
+      last_focus_cell = gtk_cell_area_get_focus_cell (last_focus_area);
+
       for (; list; list = (rtl ? list->prev : list->next))
 	{
 	  if (list->data == tree_view->priv->focus_column)
@@ -10446,6 +10461,9 @@ gtk_tree_view_move_cursor_left_right (GtkTreeView *tree_view,
   else
     {
       gtk_widget_error_bell (GTK_WIDGET (tree_view));
+
+      if (last_focus_area)
+	gtk_cell_area_set_focus_cell (last_focus_area, last_focus_cell);
     }
 
   gtk_tree_view_clamp_column_visible (tree_view,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]