wxDataViewTreeCtrl different icons for expanded and collapsed item

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2409
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania

wxDataViewTreeCtrl different icons for expanded and collapsed item

Post by evstevemd »

I have lived with this problem for many years now without bumping a solution. It have become annoyance to my application.
How can make AppendContainer show different icons? Here is the code I use:

Code: Select all

mTree->AppendContainer(parentNode, nodeName, iconClosed, iconOpen, data);
But it always shows iconOpen when expanded or collapsed.
I hope I miss something, and in that case I will appreciate your help!
TIA
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxDataViewTreeCtrl different icons for expanded and collapsed item

Post by doublemax »

I think this is a bug at least in the generic version of wxDVC that is used under Windows.

In /src/common/datavcmn.cpp comment out these two occurences of "if (HasImageList()) return".

However, as i don't understand what the initial purpose of these lines was, it might have some negative side effects somewhere else. Better open a bug report about this.

Code: Select all

void wxDataViewTreeCtrl::OnExpanded( wxDataViewEvent &event )
{
    //if (HasImageList()) return;

    wxDataViewTreeStoreContainerNode* container = GetStore()->FindContainerNode( event.GetItem() );
    if (!container) return;

    container->SetExpanded( true );

    GetStore()->ItemChanged( event.GetItem() );
}

void wxDataViewTreeCtrl::OnCollapsed( wxDataViewEvent &event )
{
    //if (HasImageList()) return;

    wxDataViewTreeStoreContainerNode* container = GetStore()->FindContainerNode( event.GetItem() );
    if (!container) return;

    container->SetExpanded( false );

    GetStore()->ItemChanged( event.GetItem() );
}
Use the source, Luke!
User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2409
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania

Re: wxDataViewTreeCtrl different icons for expanded and collapsed item

Post by evstevemd »

Thanks DM,
let me test it and see if there is any side effect.
I will then report the bug to tracker!
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxDataViewTreeCtrl different icons for expanded and collapsed item

Post by doublemax »

Some additional information:

The important line is "container->SetExpanded( false );". Without this (because HasImageList() returns true), the container is not marked as "expanded". But later, in wxDataViewTreeStore::GetValue() in /src/common/datavcmn.cpp, container->IsExpanded() is used to decide which icon to use.

Code: Select all

void
wxDataViewTreeStore::GetValue(wxVariant &variant,
                              const wxDataViewItem &item,
                              unsigned int WXUNUSED(col)) const
{
    // if (col != 0) return;

    wxDataViewTreeStoreNode *node = FindNode( item );
    if (!node) return;

    wxIcon icon( node->GetIcon());
    if (node->IsContainer())
    {
        wxDataViewTreeStoreContainerNode *container = (wxDataViewTreeStoreContainerNode*) node;
        if (container->IsExpanded() && container->GetExpandedIcon().IsOk())
           icon = container->GetExpandedIcon();
    }

    wxDataViewIconText data( node->GetText(), icon );

    variant << data;
}
Use the source, Luke!
Post Reply