- switch (event.KeyCode())
- {
- case '+':
- case WXK_ADD:
- if (m_current->HasPlus() && !IsExpanded(m_current))
- {
- Expand(m_current);
- }
- break;
-
- case '-':
- case WXK_SUBTRACT:
- if (IsExpanded(m_current))
- {
- Collapse(m_current);
- }
- break;
-
- case '*':
- case WXK_MULTIPLY:
- Toggle(m_current);
- break;
-
- case ' ':
- case WXK_RETURN:
- {
- wxTreeEvent event( wxEVT_COMMAND_TREE_ITEM_ACTIVATED, GetId() );
- event.m_item = m_current;
- event.m_code = 0;
- event.SetEventObject( this );
- GetEventHandler()->ProcessEvent( event );
- }
- break;
-
- 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;
-
- case WXK_RIGHT:
- // this works the same as the down arrow except that we also expand the
- // item if it wasn't expanded yet
- Expand(m_current);
- // fall through
-
- case WXK_DOWN:
- {
- if (IsExpanded(m_current))
+ // how should the selection work for this event?
+ bool is_multiple, extended_select, unselect_others;
+ EventFlagsToSelType(GetWindowStyleFlag(),
+ event.ShiftDown(),
+ event.ControlDown(),
+ is_multiple, extended_select, unselect_others);
+
+ // + : Expand
+ // - : Collaspe
+ // * : Toggle Expand/Collapse
+ // ' ' | return : activate
+ // up : go up (not last children!)
+ // down : go down
+ // left : go to parent
+ // right : open if parent and go next
+ // home : go to root
+ // end : go to last item without opening parents
+ switch (event.KeyCode())
+ {
+ case '+':
+ case WXK_ADD:
+ if (m_current->HasPlus() && !IsExpanded(m_current))
+ {
+ Expand(m_current);
+ }
+ break;
+
+ case '-':
+ case WXK_SUBTRACT:
+ if (IsExpanded(m_current))
+ {
+ Collapse(m_current);
+ }
+ break;
+
+ case '*':
+ case WXK_MULTIPLY:
+ Toggle(m_current);
+ break;
+
+ case ' ':
+ case WXK_RETURN:
+ {
+ wxTreeEvent event( wxEVT_COMMAND_TREE_ITEM_ACTIVATED, GetId() );
+ event.m_item = m_current;
+ event.m_code = 0;
+ event.SetEventObject( this );
+ GetEventHandler()->ProcessEvent( event );
+ }
+ 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_key_current );
+ if (!prev)
+ {
+ prev = GetParent( m_key_current );
+ if (prev)
+ {
+ long cockie = 0;
+ wxTreeItemId current = m_key_current;
+ if (current == GetFirstChild( prev, cockie ))
+ {
+ // otherwise we return to where we came from
+ SelectItem( prev, unselect_others, extended_select );
+ m_key_current=prev.m_pItem;
+ EnsureVisible( prev );
+ break;
+ }
+ }
+ }
+ if (prev)
+ {
+ while ( IsExpanded(prev) && HasChildren(prev) )
+ {
+ wxTreeItemId child = GetLastChild(prev);
+ if ( child )
+ {
+ prev = child;
+ }
+ }
+
+ SelectItem( prev, unselect_others, extended_select );
+ m_key_current=prev.m_pItem;
+ EnsureVisible( prev );
+ }
+ }
+ break;
+
+ // left arrow goes to the parent
+ case WXK_LEFT:
+ {
+ wxTreeItemId prev = GetParent( m_current );
+ if (prev)
+ {
+ EnsureVisible( prev );
+ SelectItem( prev, unselect_others, extended_select );
+ }
+ }
+ break;
+
+ case WXK_RIGHT:
+ // this works the same as the down arrow except that we also expand the
+ // item if it wasn't expanded yet
+ Expand(m_current);
+ // fall through
+
+ case WXK_DOWN:
+ {
+ if (IsExpanded(m_key_current) && HasChildren(m_key_current))
+ {
+ long cookie = 0;
+ wxTreeItemId child = GetFirstChild( m_key_current, cookie );
+ SelectItem( child, unselect_others, extended_select );
+ m_key_current=child.m_pItem;
+ EnsureVisible( child );
+ }
+ else
+ {
+ wxTreeItemId next = GetNextSibling( m_key_current );
+// if (next == 0)
+ if (!next)
+ {
+ wxTreeItemId current = m_key_current;
+ while (current && !next)
+ {
+ current = GetParent( current );
+ if (current) next = GetNextSibling( current );
+ }
+ }
+// if (next != 0)
+ if (next)
+ {
+ SelectItem( next, unselect_others, extended_select );
+ m_key_current=next.m_pItem;
+ EnsureVisible( next );
+ }
+ }
+ }
+ break;
+
+ // <End> selects the last visible tree item
+ case WXK_END:
+ {
+ wxTreeItemId last = GetRootItem();
+
+ while ( last.IsOk() && IsExpanded(last) )
+ {
+ wxTreeItemId lastChild = GetLastChild(last);
+
+ // it may happen if the item was expanded but then all of
+ // its children have been deleted - so IsExpanded() returned
+ // TRUE, but GetLastChild() returned invalid item
+ if ( !lastChild )
+ break;
+
+ last = lastChild;
+ }
+
+ if ( last.IsOk() )
+ {
+ EnsureVisible( last );
+ SelectItem( last, unselect_others, extended_select );
+ }
+ }
+ break;
+
+ // <Home> selects the root item
+ case WXK_HOME:
+ {
+ wxTreeItemId prev = GetRootItem();
+ if (prev)
+ {
+ EnsureVisible( prev );
+ SelectItem( prev, unselect_others, extended_select );
+ }
+ }
+ break;
+
+ default:
+ event.Skip();
+ }
+}
+
+wxTreeItemId wxTreeCtrl::HitTest(const wxPoint& point, int& flags)
+{
+ // We have to call this here because the label in
+ // question might just have been added and no screen
+ // update taken place.
+ if (m_dirty) wxYield();
+
+ wxClientDC dc(this);
+ PrepareDC(dc);
+ wxCoord x = dc.DeviceToLogicalX( point.x );
+ wxCoord y = dc.DeviceToLogicalY( point.y );
+ int w, h;
+ GetSize(&w, &h);
+
+ flags=0;
+ if (point.x<0) flags|=wxTREE_HITTEST_TOLEFT;
+ if (point.x>w) flags|=wxTREE_HITTEST_TORIGHT;
+ if (point.y<0) flags|=wxTREE_HITTEST_ABOVE;
+ if (point.y>h) flags|=wxTREE_HITTEST_BELOW;
+
+ return m_anchor->HitTest( wxPoint(x, y), this, flags);
+}
+
+/* **** */
+
+void wxTreeCtrl::Edit( const wxTreeItemId& item )
+{
+ if (!item.IsOk()) return;
+
+ m_currentEdit = item.m_pItem;
+
+ wxTreeEvent te( wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, GetId() );
+ te.m_item = m_currentEdit;
+ te.SetEventObject( this );
+ GetEventHandler()->ProcessEvent( te );
+
+ if (!te.IsAllowed()) return;
+
+ // We have to call this here because the label in
+ // question might just have been added and no screen
+ // update taken place.
+ if (m_dirty) wxYield();
+
+ wxString s = m_currentEdit->GetText();
+ int x = m_currentEdit->GetX();
+ int y = m_currentEdit->GetY();
+ int w = m_currentEdit->GetWidth();
+ int h = m_currentEdit->GetHeight();
+
+ int image_h = 0;
+ int image_w = 0;
+
+ int image = m_currentEdit->GetCurrentImage();
+ if ( image != NO_IMAGE )
+ {
+ if ( m_imageListNormal )