[gtk+/treeview-refactor] Fixed GtkTreeView to give focus back to the last focued cell when hitting the edge.
- From: Kristian Rietveld <kristian src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/treeview-refactor] Fixed GtkTreeView to give focus back to the last focued cell when hitting the edge.
- Date: Sun, 12 Dec 2010 16:25:50 +0000 (UTC)
commit 31226ebfb220a9b0419c1cc98b5238ec203c8a9e
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 b624d25..95550fe 100644
--- a/gtk/gtktreeview.c
+++ b/gtk/gtktreeview.c
@@ -10103,6 +10103,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)))
@@ -10123,7 +10124,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));
@@ -10136,7 +10136,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;
}
@@ -10242,6 +10247,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)
@@ -10370,7 +10378,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);
@@ -10395,6 +10405,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)
@@ -10453,6 +10468,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]