Commit 86d50d90 authored by Christian Neumair's avatar Christian Neumair Committed by Christian Neumair

Split out fallback function that determine the rightmost icon on the

2008-08-30  Christian Neumair  <cneumair@gnome.org>

	* libnautilus-private/nautilus-icon-container.c (get_cmp_point_x),
	(compare_with_start_row), (compare_with_start_column),
	(next_row_rightmost), (next_column_bottommost),
	(same_column_below_highest), (keyboard_home), (keyboard_end),
	(record_arrow_key_start), (keyboard_arrow_key), (keyboard_right),
	(keyboard_left), (keyboard_down), (keyboard_up),
	(button_press_event):
	Split out fallback function that determine the rightmost icon on the
	bottom row, which used to be inside same_column_below_highest().
	Add a similar concept for the vertical layout.

	Vertical layout: Move to the last item when pressing the right arrow
			 key in the penultimate column, below the last item.
				next_row_rightmost().

	Horizontal layout: Move to the last item when pressing the down arrow
			   key in the penultimate row, right to the last item.
				next_column_bottommost().

	Remove arrow_key_start, and use arrow_key_axis_x/_y, for
	horizontal/vertical position constraints in
	compare_with_start_column() and compare_with_start_row().

	Fixes #549686, at least for LTR.

	* libnautilus-private/nautilus-icon-private.h:
	Remove unused arrow_key_axis and arrow_key_start variables.

svn path=/trunk/; revision=14541
parent b3239bf9
2008-08-30 Christian Neumair <cneumair@gnome.org>
* libnautilus-private/nautilus-icon-container.c (get_cmp_point_x),
(compare_with_start_row), (compare_with_start_column),
(next_row_rightmost), (next_column_bottommost),
(same_column_below_highest), (keyboard_home), (keyboard_end),
(record_arrow_key_start), (keyboard_arrow_key), (keyboard_right),
(keyboard_left), (keyboard_down), (keyboard_up),
(button_press_event):
Split out fallback function that determine the rightmost icon on the
bottom row, which used to be inside same_column_below_highest().
Add a similar concept for the vertical layout.
Vertical layout: Move to the last item when pressing the right arrow
key in the penultimate column, below the last item.
next_row_rightmost().
Horizontal layout: Move to the last item when pressing the down arrow
key in the penultimate row, right to the last item.
next_column_bottommost().
Remove arrow_key_start, and use arrow_key_axis_x/_y, for
horizontal/vertical position constraints in
compare_with_start_column() and compare_with_start_row().
Fixes #549686, at least for LTR.
* libnautilus-private/nautilus-icon-private.h:
Remove unused arrow_key_axis and arrow_key_start variables.
2008-08-28 Cosimo Cecchi <cosimoc@gnome.org> 2008-08-28 Cosimo Cecchi <cosimoc@gnome.org>
* src/file-manager/fm-directory-view.c: * src/file-manager/fm-directory-view.c:
......
...@@ -299,6 +299,7 @@ icon_is_positioned (const NautilusIcon *icon) ...@@ -299,6 +299,7 @@ icon_is_positioned (const NautilusIcon *icon)
return icon->x != ICON_UNPOSITIONED_VALUE && icon->y != ICON_UNPOSITIONED_VALUE; return icon->x != ICON_UNPOSITIONED_VALUE && icon->y != ICON_UNPOSITIONED_VALUE;
} }
/* x, y are the top-left coordinates of the icon. */ /* x, y are the top-left coordinates of the icon. */
static void static void
icon_set_position (NautilusIcon *icon, icon_set_position (NautilusIcon *icon,
...@@ -2724,8 +2725,7 @@ get_cmp_point_x (NautilusIconContainer *container, ...@@ -2724,8 +2725,7 @@ get_cmp_point_x (NautilusIconContainer *container,
EelDRect icon_rect) EelDRect icon_rect)
{ {
if (container->details->label_position == NAUTILUS_ICON_LABEL_POSITION_BESIDE) { if (container->details->label_position == NAUTILUS_ICON_LABEL_POSITION_BESIDE) {
if (gtk_widget_get_direction (GTK_WIDGET (container)) == GTK_TEXT_DIR_RTL || if (gtk_widget_get_direction (GTK_WIDGET (container)) == GTK_TEXT_DIR_RTL) {
nautilus_icon_container_is_layout_vertical (container)) {
return icon_rect.x0; return icon_rect.x0;
} else { } else {
return icon_rect.x1; return icon_rect.x1;
...@@ -2784,45 +2784,6 @@ compare_icons_horizontal_first (NautilusIconContainer *container, ...@@ -2784,45 +2784,6 @@ compare_icons_horizontal_first (NautilusIconContainer *container,
return compare_icons_by_uri (container, icon_a, icon_b); return compare_icons_by_uri (container, icon_a, icon_b);
} }
static int
compare_icons_vertical_first_reverse_horizontal (NautilusIconContainer *container,
NautilusIcon *icon_a,
NautilusIcon *icon_b)
{
EelDRect world_rect;
int ax, ay, bx, by;
world_rect = nautilus_icon_canvas_item_get_icon_rectangle (icon_a->item);
eel_canvas_w2c
(EEL_CANVAS (container),
get_cmp_point_x (container, world_rect),
get_cmp_point_y (container, world_rect),
&ax,
&ay);
world_rect = nautilus_icon_canvas_item_get_icon_rectangle (icon_b->item);
eel_canvas_w2c
(EEL_CANVAS (container),
get_cmp_point_x (container, world_rect),
get_cmp_point_y (container, world_rect),
&bx,
&by);
if (ay < by) {
return -1;
}
if (ay > by) {
return +1;
}
if (ax < bx) {
return (nautilus_icon_container_is_layout_rtl (container) ? -1 : +1);
}
if (ax > bx) {
return (nautilus_icon_container_is_layout_rtl (container) ? +1 : -1);
}
return compare_icons_by_uri (container, icon_a, icon_b);
}
static int static int
compare_icons_vertical_first (NautilusIconContainer *container, compare_icons_vertical_first (NautilusIconContainer *container,
NautilusIcon *icon_a, NautilusIcon *icon_a,
...@@ -2895,10 +2856,10 @@ compare_with_start_row (NautilusIconContainer *container, ...@@ -2895,10 +2856,10 @@ compare_with_start_row (NautilusIconContainer *container,
item = EEL_CANVAS_ITEM (icon->item); item = EEL_CANVAS_ITEM (icon->item);
if (container->details->arrow_key_start < item->y1) { if (container->details->arrow_key_start_y < item->y1) {
return -1; return -1;
} }
if (container->details->arrow_key_start > item->y2) { if (container->details->arrow_key_start_y > item->y2) {
return +1; return +1;
} }
return 0; return 0;
...@@ -2912,10 +2873,10 @@ compare_with_start_column (NautilusIconContainer *container, ...@@ -2912,10 +2873,10 @@ compare_with_start_column (NautilusIconContainer *container,
item = EEL_CANVAS_ITEM (icon->item); item = EEL_CANVAS_ITEM (icon->item);
if (container->details->arrow_key_start < item->x1) { if (container->details->arrow_key_start_x < item->x1) {
return -1; return -1;
} }
if (container->details->arrow_key_start > item->x2) { if (container->details->arrow_key_start_x > item->x2) {
return +1; return +1;
} }
return 0; return 0;
...@@ -3013,6 +2974,66 @@ next_row_leftmost (NautilusIconContainer *container, ...@@ -3013,6 +2974,66 @@ next_row_leftmost (NautilusIconContainer *container,
return best_so_far == NULL; return best_so_far == NULL;
} }
static gboolean
next_row_rightmost (NautilusIconContainer *container,
NautilusIcon *start_icon,
NautilusIcon *best_so_far,
NautilusIcon *candidate,
void *data)
{
/* sort out icons that are not below the current row */
if (compare_with_start_row (container, candidate) >= 0) {
return FALSE;
}
if (best_so_far != NULL) {
if (compare_icons_vertical_first (container,
best_so_far,
candidate) > 0) {
/* candidate is above best choice, but below the current row */
return TRUE;
}
if (compare_icons_horizontal_first (container,
best_so_far,
candidate) < 0) {
return TRUE;
}
}
return best_so_far == NULL;
}
static gboolean
next_column_bottommost (NautilusIconContainer *container,
NautilusIcon *start_icon,
NautilusIcon *best_so_far,
NautilusIcon *candidate,
void *data)
{
/* sort out icons that are not on the right of the current column */
if (compare_with_start_column (container, candidate) >= 0) {
return FALSE;
}
if (best_so_far != NULL) {
if (compare_icons_horizontal_first (container,
best_so_far,
candidate) > 0) {
/* candidate is above best choice, but below the current row */
return TRUE;
}
if (compare_icons_vertical_first (container,
best_so_far,
candidate) < 0) {
return TRUE;
}
}
return best_so_far == NULL;
}
static gboolean static gboolean
previous_row_rightmost (NautilusIconContainer *container, previous_row_rightmost (NautilusIconContainer *container,
NautilusIcon *start_icon, NautilusIcon *start_icon,
...@@ -3081,33 +3102,27 @@ same_column_below_highest (NautilusIconContainer *container, ...@@ -3081,33 +3102,27 @@ same_column_below_highest (NautilusIconContainer *container,
NautilusIcon *candidate, NautilusIcon *candidate,
void *data) void *data)
{ {
EelCanvasItem *item; /* Candidates not on the start column do not qualify. */
if (compare_with_start_column (container, candidate) != 0) {
item = EEL_CANVAS_ITEM (candidate->item);
/* Candidates above or on the start row do not qualify. */
if (container->details->arrow_key_start_y >= item->y1) {
return FALSE;
}
/* In vertical layout, candidates on the left do not qualify. */
if (nautilus_icon_container_is_layout_vertical (container) &&
container->details->arrow_key_start_x > item->x1) {
return FALSE; return FALSE;
} }
/* Candidates that are lower lose out. */
if (best_so_far != NULL) { if (best_so_far != NULL) {
/* Candidates on the start column are preferred. */ if (compare_icons_vertical_first (container,
if (compare_with_start_column (container, candidate) != 0 && best_so_far,
compare_with_start_column (container, best_so_far) == 0) { candidate) < 0) {
return FALSE;
}
/* Candidates that are lower or to the left lose out. */
if (compare_icons_vertical_first_reverse_horizontal (container, best_so_far, candidate) <= 0) {
return FALSE; return FALSE;
} }
} }
/* Candidates above the start do not qualify. */
if (compare_icons_vertical_first (container,
candidate,
start_icon) <= 0) {
return FALSE;
}
return TRUE; return TRUE;
} }
...@@ -3358,7 +3373,6 @@ keyboard_home (NautilusIconContainer *container, ...@@ -3358,7 +3373,6 @@ keyboard_home (NautilusIconContainer *container,
NULL); NULL);
to = find_best_icon (container, NULL, leftmost_in_top_row, NULL); to = find_best_icon (container, NULL, leftmost_in_top_row, NULL);
container->details->arrow_key_axis = AXIS_NONE;
keyboard_move_to (container, to, from, event); keyboard_move_to (container, to, from, event);
} }
...@@ -3381,7 +3395,6 @@ keyboard_end (NautilusIconContainer *container, ...@@ -3381,7 +3395,6 @@ keyboard_end (NautilusIconContainer *container,
rightmost_in_bottom_row, rightmost_in_bottom_row,
NULL); NULL);
container->details->arrow_key_axis = AXIS_NONE;
keyboard_move_to (container, to, from, event); keyboard_move_to (container, to, from, event);
} }
...@@ -3399,23 +3412,7 @@ record_arrow_key_start (NautilusIconContainer *container, ...@@ -3399,23 +3412,7 @@ record_arrow_key_start (NautilusIconContainer *container,
get_cmp_point_y (container, world_rect), get_cmp_point_y (container, world_rect),
&container->details->arrow_key_start_x, &container->details->arrow_key_start_x,
&container->details->arrow_key_start_y); &container->details->arrow_key_start_y);
container->details->arrow_key_direction = direction; container->details->arrow_key_direction = direction;
switch (container->details->arrow_key_direction) {
case GTK_DIR_UP:
case GTK_DIR_DOWN:
container->details->arrow_key_axis = AXIS_VERTICAL;
container->details->arrow_key_start = container->details->arrow_key_start_x;
break;
case GTK_DIR_LEFT:
case GTK_DIR_RIGHT:
container->details->arrow_key_axis = AXIS_HORIZONTAL;
container->details->arrow_key_start = container->details->arrow_key_start_y;
break;
default:
g_assert_not_reached();
}
} }
static void static void
...@@ -3426,6 +3423,7 @@ keyboard_arrow_key (NautilusIconContainer *container, ...@@ -3426,6 +3423,7 @@ keyboard_arrow_key (NautilusIconContainer *container,
IsBetterIconFunction empty_start, IsBetterIconFunction empty_start,
IsBetterIconFunction better_destination, IsBetterIconFunction better_destination,
IsBetterIconFunction better_destination_fallback_if_no_a11y, IsBetterIconFunction better_destination_fallback_if_no_a11y,
IsBetterIconFunction better_destination_fallback_fallback,
IsBetterIconFunction better_destination_manual) IsBetterIconFunction better_destination_manual)
{ {
NautilusIcon *from; NautilusIcon *from;
...@@ -3460,11 +3458,9 @@ keyboard_arrow_key (NautilusIconContainer *container, ...@@ -3460,11 +3458,9 @@ keyboard_arrow_key (NautilusIconContainer *container,
* If there is an icon, select the next icon based on the arrow direction. * If there is an icon, select the next icon based on the arrow direction.
*/ */
if (from == NULL) { if (from == NULL) {
container->details->arrow_key_axis = AXIS_NONE;
to = from = find_best_icon to = from = find_best_icon
(container, NULL, (container, NULL,
empty_start, NULL); empty_start, NULL);
} else { } else {
record_arrow_key_start (container, from, direction); record_arrow_key_start (container, from, direction);
...@@ -3484,7 +3480,33 @@ keyboard_arrow_key (NautilusIconContainer *container, ...@@ -3484,7 +3480,33 @@ keyboard_arrow_key (NautilusIconContainer *container,
better_destination_fallback_if_no_a11y, better_destination_fallback_if_no_a11y,
&data); &data);
} }
/* With a layout like
* 1 2 3
* 4
* (horizontal layout)
*
* or
*
* 1 4
* 2
* 3
* (vertical layout)
*
* * pressing down for any of 1,2,3 (horizontal layout)
* * pressing right for any of 1,2,3 (vertical layout)
*
* Should select 4.
*/
if (to == NULL &&
container->details->auto_layout &&
better_destination_fallback_fallback != NULL) {
to = find_best_icon
(container, from,
better_destination_fallback_fallback,
&data);
}
if (to == NULL) { if (to == NULL) {
to = from; to = from;
} }
...@@ -3506,6 +3528,7 @@ keyboard_right (NautilusIconContainer *container, ...@@ -3506,6 +3528,7 @@ keyboard_right (NautilusIconContainer *container,
GdkEventKey *event) GdkEventKey *event)
{ {
IsBetterIconFunction no_a11y; IsBetterIconFunction no_a11y;
IsBetterIconFunction next_column_fallback;
no_a11y = NULL; no_a11y = NULL;
if (container->details->auto_layout && if (container->details->auto_layout &&
...@@ -3514,6 +3537,11 @@ keyboard_right (NautilusIconContainer *container, ...@@ -3514,6 +3537,11 @@ keyboard_right (NautilusIconContainer *container,
no_a11y = next_row_leftmost; no_a11y = next_row_leftmost;
} }
next_column_fallback = NULL;
if (nautilus_icon_container_is_layout_vertical (container)) {
next_column_fallback = next_column_bottommost;
}
/* Right selects the next icon in the same row. /* Right selects the next icon in the same row.
* Control-Right sets the keyboard focus to the next icon in the same row. * Control-Right sets the keyboard focus to the next icon in the same row.
*/ */
...@@ -3524,6 +3552,7 @@ keyboard_right (NautilusIconContainer *container, ...@@ -3524,6 +3552,7 @@ keyboard_right (NautilusIconContainer *container,
leftmost_in_top_row, leftmost_in_top_row,
same_row_right_side_leftmost, same_row_right_side_leftmost,
no_a11y, no_a11y,
next_column_fallback,
closest_in_90_degrees); closest_in_90_degrees);
} }
...@@ -3550,6 +3579,7 @@ keyboard_left (NautilusIconContainer *container, ...@@ -3550,6 +3579,7 @@ keyboard_left (NautilusIconContainer *container,
rightmost_in_bottom_row, rightmost_in_bottom_row,
same_row_left_side_rightmost, same_row_left_side_rightmost,
no_a11y, no_a11y,
NULL, /* TODO RTL */
closest_in_90_degrees); closest_in_90_degrees);
} }
...@@ -3558,6 +3588,7 @@ keyboard_down (NautilusIconContainer *container, ...@@ -3558,6 +3588,7 @@ keyboard_down (NautilusIconContainer *container,
GdkEventKey *event) GdkEventKey *event)
{ {
IsBetterIconFunction no_a11y; IsBetterIconFunction no_a11y;
IsBetterIconFunction next_row_fallback;
no_a11y = NULL; no_a11y = NULL;
if (container->details->auto_layout && if (container->details->auto_layout &&
...@@ -3566,6 +3597,11 @@ keyboard_down (NautilusIconContainer *container, ...@@ -3566,6 +3597,11 @@ keyboard_down (NautilusIconContainer *container,
no_a11y = next_column_highest; no_a11y = next_column_highest;
} }
next_row_fallback = NULL;
if (!nautilus_icon_container_is_layout_vertical (container)) {
next_row_fallback = next_row_rightmost;
}
/* Down selects the next icon in the same column. /* Down selects the next icon in the same column.
* Control-Down sets the keyboard focus to the next icon in the same column. * Control-Down sets the keyboard focus to the next icon in the same column.
*/ */
...@@ -3576,6 +3612,7 @@ keyboard_down (NautilusIconContainer *container, ...@@ -3576,6 +3612,7 @@ keyboard_down (NautilusIconContainer *container,
leftmost_in_top_row, leftmost_in_top_row,
same_column_below_highest, same_column_below_highest,
no_a11y, no_a11y,
next_row_fallback, /* TODO RTL */
closest_in_90_degrees); closest_in_90_degrees);
} }
...@@ -3602,6 +3639,7 @@ keyboard_up (NautilusIconContainer *container, ...@@ -3602,6 +3639,7 @@ keyboard_up (NautilusIconContainer *container,
rightmost_in_bottom_row, rightmost_in_bottom_row,
same_column_above_lowest, same_column_above_lowest,
no_a11y, no_a11y,
NULL,
closest_in_90_degrees); closest_in_90_degrees);
} }
...@@ -3920,9 +3958,6 @@ button_press_event (GtkWidget *widget, ...@@ -3920,9 +3958,6 @@ button_press_event (GtkWidget *widget,
clear_keyboard_focus (container); clear_keyboard_focus (container);
clear_keyboard_rubberband_start (container); clear_keyboard_rubberband_start (container);
/* Forget about where we began with the arrow keys now that we're mousing. */
container->details->arrow_key_axis = AXIS_NONE;
if (event->type == GDK_2BUTTON_PRESS || event->type == GDK_3BUTTON_PRESS) { if (event->type == GDK_2BUTTON_PRESS || event->type == GDK_3BUTTON_PRESS) {
/* We use our own double-click detection. */ /* We use our own double-click detection. */
return TRUE; return TRUE;
......
...@@ -214,10 +214,7 @@ struct NautilusIconContainerDetails { ...@@ -214,10 +214,7 @@ struct NautilusIconContainerDetails {
GdkColor label_colors [LAST_LABEL_COLOR]; GdkColor label_colors [LAST_LABEL_COLOR];
/* State used so arrow keys don't wander if icons aren't lined up. /* State used so arrow keys don't wander if icons aren't lined up.
* Keeps track of last axis arrow key was used on.
*/ */
Axis arrow_key_axis;
int arrow_key_start;
int arrow_key_start_x; int arrow_key_start_x;
int arrow_key_start_y; int arrow_key_start_y;
GtkDirectionType arrow_key_direction; GtkDirectionType arrow_key_direction;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment