1. added wxTreeCtrl::GetLastChild (modified MSW, GTK, generic and docs)

2. added more kbd logic to the generic tree ctrl (Home, End are now
   understood, Left does the same thing as under Windows and not the same
   thing as Up arrow)


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1496 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
1999-01-27 15:28:48 +00:00
parent cce4b3fe2b
commit 978f38c238
9 changed files with 271 additions and 175 deletions

View File

@@ -274,6 +274,17 @@ Gets the normal item image.
Returns the item label. Returns the item label.
\membersection{wxTreeCtrl::GetLastChild}\label{wxtreectrlgetlastchild}
\constfunc{wxTreeItemId}{GetLastChild}{\param{const wxTreeItemId\&}{ item}}
Returns the last child of the item (or 0 if this item has no children).
\wxheading{See also}
\helpref{GetFirstChild}{wxtreectrlgetfirstchild},
\helpref{GetLastChild}{wxtreectrlgetlastchild}
\membersection{wxTreeCtrl::GetNextChild}\label{wxtreectrlgetnextchild} \membersection{wxTreeCtrl::GetNextChild}\label{wxtreectrlgetnextchild}
\constfunc{wxTreeItemId}{GetNextChild}{\param{const wxTreeItemId\&}{ item}, \param{long\& }{cookie}} \constfunc{wxTreeItemId}{GetNextChild}{\param{const wxTreeItemId\&}{ item}, \param{long\& }{cookie}}

View File

@@ -333,6 +333,8 @@ public:
wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& cookie) const; wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& cookie) const;
// get the next child // get the next child
wxTreeItemId GetNextChild(const wxTreeItemId& item, long& cookie) const; wxTreeItemId GetNextChild(const wxTreeItemId& item, long& cookie) const;
// get the last child of this item - this method doesn't use cookies
wxTreeItemId GetLastChild(const wxTreeItemId& item) const;
// get the next sibling of this item // get the next sibling of this item
wxTreeItemId GetNextSibling(const wxTreeItemId& item) const; wxTreeItemId GetNextSibling(const wxTreeItemId& item) const;

View File

@@ -264,8 +264,10 @@ public:
// get the first child of this item // get the first child of this item
wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& cookie) const; wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& cookie) const;
// get the next child // get the next child (after GetFirstChild or GetNextChild)
wxTreeItemId GetNextChild(const wxTreeItemId& item, long& cookie) const; wxTreeItemId GetNextChild(const wxTreeItemId& item, long& cookie) const;
// get the last child of this item - this method doesn't use cookies
wxTreeItemId GetLastChild(const wxTreeItemId& item) const;
// get the next sibling of this item // get the next sibling of this item
wxTreeItemId GetNextSibling(const wxTreeItemId& item) const; wxTreeItemId GetNextSibling(const wxTreeItemId& item) const;

View File

@@ -264,8 +264,10 @@ public:
// get the first child of this item // get the first child of this item
wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& cookie) const; wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& cookie) const;
// get the next child // get the next child (after GetFirstChild or GetNextChild)
wxTreeItemId GetNextChild(const wxTreeItemId& item, long& cookie) const; wxTreeItemId GetNextChild(const wxTreeItemId& item, long& cookie) const;
// get the last child of this item - this method doesn't use cookies
wxTreeItemId GetLastChild(const wxTreeItemId& item) const;
// get the next sibling of this item // get the next sibling of this item
wxTreeItemId GetNextSibling(const wxTreeItemId& item) const; wxTreeItemId GetNextSibling(const wxTreeItemId& item) const;

View File

@@ -299,6 +299,8 @@ public:
wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& _cookie) const; wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& _cookie) const;
// get the next child // get the next child
wxTreeItemId GetNextChild(const wxTreeItemId& item, long& _cookie) const; wxTreeItemId GetNextChild(const wxTreeItemId& item, long& _cookie) const;
// get the last child of this item - this method doesn't use cookies
wxTreeItemId GetLastChild(const wxTreeItemId& item) const;
// get the next sibling of this item // get the next sibling of this item
wxTreeItemId GetNextSibling(const wxTreeItemId& item) const; wxTreeItemId GetNextSibling(const wxTreeItemId& item) const;

View File

@@ -556,7 +556,7 @@ wxTreeItemId wxTreeCtrl::GetNextChild(const wxTreeItemId& item, long& cookie) co
wxArrayTreeItems& children = item.m_pItem->GetChildren(); wxArrayTreeItems& children = item.m_pItem->GetChildren();
if ( (size_t)cookie < children.Count() ) if ( (size_t)cookie < children.Count() )
{ {
return item.m_pItem->GetChildren().Item(cookie++); return children.Item(cookie++);
} }
else else
{ {
@@ -565,6 +565,14 @@ wxTreeItemId wxTreeCtrl::GetNextChild(const wxTreeItemId& item, long& cookie) co
} }
} }
wxTreeItemId wxTreeCtrl::GetLastChild(const wxTreeItemId& item) const
{
wxCHECK_MSG( item.IsOk(), wxTreeItemId(), "invalid tree item" );
wxArrayTreeItems& children = item.m_pItem->GetChildren();
return children.IsEmpty() ? wxTreeItemId() : children.Last();
}
wxTreeItemId wxTreeCtrl::GetNextSibling(const wxTreeItemId& item) const wxTreeItemId wxTreeCtrl::GetNextSibling(const wxTreeItemId& item) const
{ {
wxCHECK_MSG( item.IsOk(), wxTreeItemId(), "invalid tree item" ); wxCHECK_MSG( item.IsOk(), wxTreeItemId(), "invalid tree item" );
@@ -1271,6 +1279,8 @@ void wxTreeCtrl::OnChar( wxKeyEvent &event )
} }
break; break;
// up goes to the previous sibling or to the last of its children if
// it's expanded
case WXK_UP: case WXK_UP:
{ {
wxTreeItemId prev = GetPrevSibling( m_current ); wxTreeItemId prev = GetPrevSibling( m_current );
@@ -1302,24 +1312,17 @@ void wxTreeCtrl::OnChar( wxKeyEvent &event )
} }
} }
break; break;
// left arrow goes to the parent
case WXK_LEFT: case WXK_LEFT:
{ {
wxTreeItemId prev = GetPrevSibling( m_current ); wxTreeItemId prev = GetParent( m_current );
if (prev != 0)
{
SelectItem( prev );
EnsureVisible( prev );
}
else
{
prev = GetParent( m_current );
if (prev) if (prev)
{ {
EnsureVisible( prev ); EnsureVisible( prev );
SelectItem( prev ); SelectItem( prev );
} }
} }
}
break; break;
case WXK_RIGHT: case WXK_RIGHT:
@@ -1358,6 +1361,44 @@ void wxTreeCtrl::OnChar( wxKeyEvent &event )
} }
break; 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 );
}
}
break;
// <Home> selects the root item
case WXK_HOME:
{
wxTreeItemId prev = GetRootItem();
if (prev)
{
EnsureVisible( prev );
SelectItem( prev );
}
}
break;
default: default:
event.Skip(); event.Skip();
} }

View File

@@ -348,6 +348,16 @@ wxTreeItemId wxTreeCtrl::GetNextChild(const wxTreeItemId& item, long& cookie) co
return GTK_TREE_ITEM(g_list_nth(GTK_TREE(parent)->children, cookie)->data); return GTK_TREE_ITEM(g_list_nth(GTK_TREE(parent)->children, cookie)->data);
} }
wxTreeItemId wxTreeCtrl::GetLastChild(const wxTreeItemId& item) const
{
GtkTreeItem *p = (GtkTreeItem *)item;
GtkWidget *parent = GTK_WIDGET(p)->parent;
wxCHECK_MSG( GTK_IS_TREE(parent), NULL, "invalid tree item" );
return GTK_TREE_ITEM(g_list_last(GTK_TREE(parent)->children)->data);
}
wxTreeItemId wxTreeCtrl::GetNextSibling(const wxTreeItemId& item) const { wxTreeItemId wxTreeCtrl::GetNextSibling(const wxTreeItemId& item) const {
GtkTreeItem *p = (GtkTreeItem *)item; GtkTreeItem *p = (GtkTreeItem *)item;
GtkWidget *parent = GTK_WIDGET(p)->parent; GtkWidget *parent = GTK_WIDGET(p)->parent;

View File

@@ -348,6 +348,16 @@ wxTreeItemId wxTreeCtrl::GetNextChild(const wxTreeItemId& item, long& cookie) co
return GTK_TREE_ITEM(g_list_nth(GTK_TREE(parent)->children, cookie)->data); return GTK_TREE_ITEM(g_list_nth(GTK_TREE(parent)->children, cookie)->data);
} }
wxTreeItemId wxTreeCtrl::GetLastChild(const wxTreeItemId& item) const
{
GtkTreeItem *p = (GtkTreeItem *)item;
GtkWidget *parent = GTK_WIDGET(p)->parent;
wxCHECK_MSG( GTK_IS_TREE(parent), NULL, "invalid tree item" );
return GTK_TREE_ITEM(g_list_last(GTK_TREE(parent)->children)->data);
}
wxTreeItemId wxTreeCtrl::GetNextSibling(const wxTreeItemId& item) const { wxTreeItemId wxTreeCtrl::GetNextSibling(const wxTreeItemId& item) const {
GtkTreeItem *p = (GtkTreeItem *)item; GtkTreeItem *p = (GtkTreeItem *)item;
GtkWidget *parent = GTK_WIDGET(p)->parent; GtkWidget *parent = GTK_WIDGET(p)->parent;

View File

@@ -457,6 +457,22 @@ wxTreeItemId wxTreeCtrl::GetNextChild(const wxTreeItemId& WXUNUSED(item),
return l; return l;
} }
wxTreeItemId wxTreeCtrl::GetLastChild(const wxTreeItemId& item) const
{
// can this be done more efficiently?
long cookie;
wxTreeItemId childLast,
child = GetFirstChild(last, cookie);
while ( child.IsOk() )
{
childLast = child;
child = GetNextChild(last, cookie);
}
return childLast;
}
wxTreeItemId wxTreeCtrl::GetNextSibling(const wxTreeItemId& item) const wxTreeItemId wxTreeCtrl::GetNextSibling(const wxTreeItemId& item) const
{ {
return wxTreeItemId((WXHTREEITEM) TreeView_GetNextSibling(wxhWnd, (HTREEITEM) (WXHTREEITEM) item)); return wxTreeItemId((WXHTREEITEM) TreeView_GetNextSibling(wxhWnd, (HTREEITEM) (WXHTREEITEM) item));