- case WXK_UP:
- {
- wxTreeItemId prev = GetPrevSibling( m_current );
- if (!prev)
- {
- prev = GetParent( m_current );
- long cockie = 0;
- wxTreeItemId current = m_current;
- if (current == GetFirstChild( prev, cockie ))
- {
- // otherwise we return to where we came from
- SelectItem( prev );
- EnsureVisible( prev );
- break;
- }
- }
- if (prev)
- {
- while (IsExpanded(prev))
- {
- int c = (int)GetChildrenCount( prev, FALSE );
- long cockie = 0;
- prev = GetFirstChild( prev, cockie );
- for (int i = 0; i < c-1; i++)
- prev = GetNextSibling( prev );
- }
- SelectItem( prev );
- EnsureVisible( prev );
- }
- }
- break;
- case WXK_LEFT:
- {
- wxTreeItemId prev = GetPrevSibling( m_current );
- if (prev != 0)
- {
- SelectItem( prev );
- EnsureVisible( prev );
- }
- else
- {
- prev = GetParent( m_current );
- if (prev)
- {
- EnsureVisible( prev );
- SelectItem( prev );
- }
- }
- }
- break;
+ // up goes to the previous sibling or to the last of its children if
+ // it's expanded
+ case WXK_UP:
+ {
+ wxTreeItemId prev = GetPrevSibling( m_current );
+ if (!prev)
+ {
+ prev = GetParent( m_current );
+ if (prev)
+ {
+ long cockie = 0;
+ wxTreeItemId current = m_current;
+ if (current == GetFirstChild( prev, cockie ))
+ {
+ // otherwise we return to where we came from
+ SelectItem( prev );
+ EnsureVisible( prev );
+ break;
+ }
+ }
+ }
+ if (prev)
+ {
+ while ( IsExpanded(prev) && HasChildren(prev) )
+ {
+ wxTreeItemId child = GetLastChild(prev);
+ if ( child )
+ {
+ prev = child;
+ }
+ }
+
+ SelectItem( prev );
+ EnsureVisible( prev );
+ }
+ }
+ break;