int GetAdjustedIndex (Keys key)
{
int result = -1;
if (View == View.Details) {
switch (key) {
case Keys.Up:
result = FocusedItem.DisplayIndex - 1;
break;
case Keys.Down:
result = FocusedItem.DisplayIndex + 1;
if (result == items.Count)
result = -1;
break;
case Keys.PageDown:
int last_index = LastVisibleIndex;
Rectangle item_rect = new Rectangle (GetItemLocation (last_index), ItemSize);
if (item_rect.Bottom > item_control.ClientRectangle.Bottom)
last_index--;
if (FocusedItem.DisplayIndex == last_index) {
if (FocusedItem.DisplayIndex < Items.Count - 1) {
int page_size = item_control.Height / ItemSize.Height - 1;
result = FocusedItem.DisplayIndex + page_size - 1;
if (result >= Items.Count)
result = Items.Count - 1;
}
} else
result = last_index;
break;
case Keys.PageUp:
int first_index = FirstVisibleIndex;
if (GetItemLocation (first_index).Y < 0)
first_index++;
if (FocusedItem.DisplayIndex == first_index) {
if (first_index > 0) {
int page_size = item_control.Height / ItemSize.Height - 1;
result = first_index - page_size + 1;
if (result < 0)
result = 0;
}
} else
result = first_index;
break;
}
return result;
}
if (virtual_mode)
return GetFixedAdjustedIndex (key);
ItemMatrixLocation item_matrix_location = items_matrix_location [FocusedItem.DisplayIndex];
int row = item_matrix_location.Row;
int col = item_matrix_location.Col;
int adjusted_index = -1;
switch (key) {
case Keys.Left:
if (col == 0)
return -1;
adjusted_index = item_index_matrix [row, col - 1];
break;
case Keys.Right:
if (col == (cols - 1))
return -1;
while (item_index_matrix [row, col + 1] == 0) {
row--;
if (row < 0)
return -1;
}
adjusted_index = item_index_matrix [row, col + 1];
break;
case Keys.Up:
if (row == 0)
return -1;
while (item_index_matrix [row - 1, col] == 0 && row != 1) {
col--;
if (col < 0)
return -1;
}
adjusted_index = item_index_matrix [row - 1, col];
break;
case Keys.Down:
if (row == (rows - 1) || row == Items.Count - 1)
return -1;
while (item_index_matrix [row + 1, col] == 0) {
col--;
if (col < 0)
return -1;
}
adjusted_index = item_index_matrix [row + 1, col];
break;
default:
return -1;
}
return items [adjusted_index].DisplayIndex;
}