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:
@@ -274,6 +274,17 @@ Gets the normal item image.
|
||||
|
||||
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}
|
||||
|
||||
\constfunc{wxTreeItemId}{GetNextChild}{\param{const wxTreeItemId\&}{ item}, \param{long\& }{cookie}}
|
||||
|
@@ -333,6 +333,8 @@ public:
|
||||
wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& cookie) const;
|
||||
// get the next child
|
||||
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
|
||||
wxTreeItemId GetNextSibling(const wxTreeItemId& item) const;
|
||||
|
@@ -264,8 +264,10 @@ public:
|
||||
|
||||
// get the first child of this item
|
||||
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;
|
||||
// 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
|
||||
wxTreeItemId GetNextSibling(const wxTreeItemId& item) const;
|
||||
|
@@ -264,8 +264,10 @@ public:
|
||||
|
||||
// get the first child of this item
|
||||
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;
|
||||
// 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
|
||||
wxTreeItemId GetNextSibling(const wxTreeItemId& item) const;
|
||||
|
@@ -299,6 +299,8 @@ public:
|
||||
wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& _cookie) const;
|
||||
// get the next child
|
||||
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
|
||||
wxTreeItemId GetNextSibling(const wxTreeItemId& item) const;
|
||||
|
@@ -366,8 +366,8 @@ void wxTreeCtrl::Init()
|
||||
bool wxTreeCtrl::Create(wxWindow *parent, wxWindowID id,
|
||||
const wxPoint& pos, const wxSize& size,
|
||||
long style,
|
||||
const wxValidator &validator,
|
||||
const wxString& name )
|
||||
const wxValidator &validator,
|
||||
const wxString& name )
|
||||
{
|
||||
Init();
|
||||
|
||||
@@ -556,7 +556,7 @@ wxTreeItemId wxTreeCtrl::GetNextChild(const wxTreeItemId& item, long& cookie) co
|
||||
wxArrayTreeItems& children = item.m_pItem->GetChildren();
|
||||
if ( (size_t)cookie < children.Count() )
|
||||
{
|
||||
return item.m_pItem->GetChildren().Item(cookie++);
|
||||
return children.Item(cookie++);
|
||||
}
|
||||
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
|
||||
{
|
||||
wxCHECK_MSG( item.IsOk(), wxTreeItemId(), "invalid tree item" );
|
||||
@@ -910,7 +918,7 @@ void wxTreeCtrl::EnsureVisible(const wxTreeItemId& item)
|
||||
m_anchor->GetSize( x, y );
|
||||
y += 2*m_lineHeight;
|
||||
int x_pos = GetScrollPos( wxHORIZONTAL );
|
||||
SetScrollbars( 10, 10, x/10, y/10, x_pos, (item_y-client_h/2)/10 );
|
||||
SetScrollbars( 10, 10, x/10, y/10, x_pos, (item_y-client_h/2)/10 );
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1136,9 +1144,9 @@ void wxTreeCtrl::PaintLevel( wxGenericTreeItem *item, wxDC &dc, int level, int &
|
||||
dc.DrawLine( horizX+13, y, horizX+18, y );
|
||||
|
||||
if (!item->IsExpanded())
|
||||
{
|
||||
{
|
||||
dc.DrawLine( horizX+15, y-2, horizX+15, y+3 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (item->HasHilight())
|
||||
@@ -1226,141 +1234,174 @@ void wxTreeCtrl::OnKillFocus( wxFocusEvent &WXUNUSED(event) )
|
||||
|
||||
void wxTreeCtrl::OnChar( wxKeyEvent &event )
|
||||
{
|
||||
wxTreeEvent te( wxEVT_COMMAND_TREE_KEY_DOWN, GetId() );
|
||||
te.m_code = event.KeyCode();
|
||||
te.SetEventObject( this );
|
||||
GetEventHandler()->ProcessEvent( te );
|
||||
wxTreeEvent te( wxEVT_COMMAND_TREE_KEY_DOWN, GetId() );
|
||||
te.m_code = event.KeyCode();
|
||||
te.SetEventObject( this );
|
||||
GetEventHandler()->ProcessEvent( te );
|
||||
|
||||
if (m_current == 0)
|
||||
{
|
||||
event.Skip();
|
||||
return;
|
||||
}
|
||||
if (m_current == 0)
|
||||
{
|
||||
event.Skip();
|
||||
return;
|
||||
}
|
||||
|
||||
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))
|
||||
{
|
||||
long cookie = 0;
|
||||
wxTreeItemId child = GetFirstChild( m_current, cookie );
|
||||
SelectItem( child );
|
||||
EnsureVisible( child );
|
||||
}
|
||||
else
|
||||
{
|
||||
wxTreeItemId next = GetNextSibling( m_current );
|
||||
if (next == 0)
|
||||
{
|
||||
wxTreeItemId current = m_current;
|
||||
while (current && !next)
|
||||
switch (event.KeyCode())
|
||||
{
|
||||
case '+':
|
||||
case WXK_ADD:
|
||||
if (m_current->HasPlus() && !IsExpanded(m_current))
|
||||
{
|
||||
current = GetParent( current );
|
||||
if (current) next = GetNextSibling( current );
|
||||
Expand(m_current);
|
||||
}
|
||||
}
|
||||
if (next != 0)
|
||||
{
|
||||
SelectItem( next );
|
||||
EnsureVisible( next );
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
break;
|
||||
|
||||
default:
|
||||
event.Skip();
|
||||
}
|
||||
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_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;
|
||||
|
||||
// left arrow goes to the parent
|
||||
case WXK_LEFT:
|
||||
{
|
||||
wxTreeItemId 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))
|
||||
{
|
||||
long cookie = 0;
|
||||
wxTreeItemId child = GetFirstChild( m_current, cookie );
|
||||
SelectItem( child );
|
||||
EnsureVisible( child );
|
||||
}
|
||||
else
|
||||
{
|
||||
wxTreeItemId next = GetNextSibling( m_current );
|
||||
if (next == 0)
|
||||
{
|
||||
wxTreeItemId current = m_current;
|
||||
while (current && !next)
|
||||
{
|
||||
current = GetParent( current );
|
||||
if (current) next = GetNextSibling( current );
|
||||
}
|
||||
}
|
||||
if (next != 0)
|
||||
{
|
||||
SelectItem( next );
|
||||
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 );
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
// <Home> selects the root item
|
||||
case WXK_HOME:
|
||||
{
|
||||
wxTreeItemId prev = GetRootItem();
|
||||
if (prev)
|
||||
{
|
||||
EnsureVisible( prev );
|
||||
SelectItem( prev );
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
event.Skip();
|
||||
}
|
||||
}
|
||||
|
||||
wxTreeItemId wxTreeCtrl::HitTest(const wxPoint& point, int& WXUNUSED(flags))
|
||||
|
@@ -6,7 +6,7 @@
|
||||
// Created: 07/05/98
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Denis Pershin
|
||||
// Licence: wxWindows licence
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
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 {
|
||||
GtkTreeItem *p = (GtkTreeItem *)item;
|
||||
GtkWidget *parent = GTK_WIDGET(p)->parent;
|
||||
@@ -469,13 +479,13 @@ wxTreeItemId wxTreeCtrl::InsertItem(const wxTreeItemId& parent,
|
||||
|
||||
wxTreeItemId wxTreeCtrl::AppendItem(const wxTreeItemId& parent,
|
||||
const wxString& text, int image, int selectedImage,
|
||||
wxTreeItemData *data) {
|
||||
wxTreeItemData *data) {
|
||||
return p_InsertItem(parent, text, image, selectedImage, data);
|
||||
}
|
||||
|
||||
wxTreeItemId wxTreeCtrl::p_InsertItem(GtkTreeItem *p,
|
||||
const wxString& text, int image, int selectedImage,
|
||||
wxTreeItemData *data) {
|
||||
wxTreeItemData *data) {
|
||||
GtkTreeItem *item;
|
||||
|
||||
printf("begin insert\n");
|
||||
|
@@ -6,7 +6,7 @@
|
||||
// Created: 07/05/98
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Denis Pershin
|
||||
// Licence: wxWindows licence
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
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 {
|
||||
GtkTreeItem *p = (GtkTreeItem *)item;
|
||||
GtkWidget *parent = GTK_WIDGET(p)->parent;
|
||||
@@ -469,13 +479,13 @@ wxTreeItemId wxTreeCtrl::InsertItem(const wxTreeItemId& parent,
|
||||
|
||||
wxTreeItemId wxTreeCtrl::AppendItem(const wxTreeItemId& parent,
|
||||
const wxString& text, int image, int selectedImage,
|
||||
wxTreeItemData *data) {
|
||||
wxTreeItemData *data) {
|
||||
return p_InsertItem(parent, text, image, selectedImage, data);
|
||||
}
|
||||
|
||||
wxTreeItemId wxTreeCtrl::p_InsertItem(GtkTreeItem *p,
|
||||
const wxString& text, int image, int selectedImage,
|
||||
wxTreeItemData *data) {
|
||||
wxTreeItemData *data) {
|
||||
GtkTreeItem *item;
|
||||
|
||||
printf("begin insert\n");
|
||||
|
@@ -457,6 +457,22 @@ wxTreeItemId wxTreeCtrl::GetNextChild(const wxTreeItemId& WXUNUSED(item),
|
||||
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
|
||||
{
|
||||
return wxTreeItemId((WXHTREEITEM) TreeView_GetNextSibling(wxhWnd, (HTREEITEM) (WXHTREEITEM) item));
|
||||
|
Reference in New Issue
Block a user