public void HandleArrowKey(int dir)
{
int index = this.selectedIndex;
if (index == -1)
return;
switch (dir)
{
case 1://up
if (_layout == ListLayoutType.SingleColumn || _layout == ListLayoutType.FlowVertical)
{
index--;
if (index >= 0)
{
ClearSelection();
AddSelection(index, true);
}
}
else if (_layout == ListLayoutType.FlowHorizontal || _layout == ListLayoutType.Pagination)
{
GObject current = _children[index];
int k = 0;
int i;
for (i = index - 1; i >= 0; i--)
{
GObject obj = _children[i];
if (obj.y != current.y)
{
current = obj;
break;
}
k++;
}
for (; i >= 0; i--)
{
GObject obj = _children[i];
if (obj.y != current.y)
{
ClearSelection();
AddSelection(i + k + 1, true);
break;
}
}
}
break;
case 3://right
if (_layout == ListLayoutType.SingleRow || _layout == ListLayoutType.FlowHorizontal || _layout == ListLayoutType.Pagination)
{
index++;
if (index < _children.Count)
{
ClearSelection();
AddSelection(index, true);
}
}
else if (_layout == ListLayoutType.FlowVertical)
{
GObject current = _children[index];
int k = 0;
int cnt = _children.Count;
int i;
for (i = index + 1; i < cnt; i++)
{
GObject obj = _children[i];
if (obj.x != current.x)
{
current = obj;
break;
}
k++;
}
for (; i < cnt; i++)
{
GObject obj = _children[i];
if (obj.x != current.x)
{
ClearSelection();
AddSelection(i - k - 1, true);
break;
}
}
}
break;
case 5://down
if (_layout == ListLayoutType.SingleColumn || _layout == ListLayoutType.FlowVertical)
{
index++;
if (index < _children.Count)
{
ClearSelection();
AddSelection(index, true);
}
}
else if (_layout == ListLayoutType.FlowHorizontal || _layout == ListLayoutType.Pagination)
{
GObject current = _children[index];
int k = 0;
int cnt = _children.Count;
int i;
for (i = index + 1; i < cnt; i++)
{
GObject obj = _children[i];
if (obj.y != current.y)
{
current = obj;
break;
}
k++;
}
for (; i < cnt; i++)
{
GObject obj = _children[i];
if (obj.y != current.y)
{
ClearSelection();
AddSelection(i - k - 1, true);
break;
}
}
}
break;
case 7://left
if (_layout == ListLayoutType.SingleRow || _layout == ListLayoutType.FlowHorizontal || _layout == ListLayoutType.Pagination)
{
index--;
if (index >= 0)
{
ClearSelection();
AddSelection(index, true);
}
}
else if (_layout == ListLayoutType.FlowVertical)
{
GObject current = _children[index];
int k = 0;
int i;
for (i = index - 1; i >= 0; i--)
{
GObject obj = _children[i];
if (obj.x != current.x)
{
current = obj;
break;
}
k++;
}
for (; i >= 0; i--)
{
GObject obj = _children[i];
if (obj.x != current.x)
{
ClearSelection();
AddSelection(i + k + 1, true);
break;
}
}
}
break;
}
}