Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wxTreeCtrl doesn't SetItemImage #80

Closed
NetWielder opened this issue Jan 9, 2015 · 3 comments
Closed

wxTreeCtrl doesn't SetItemImage #80

NetWielder opened this issue Jan 9, 2015 · 3 comments

Comments

@NetWielder
Copy link

Perhaps I am not calling SetItemImage() with expected parameters? Is there caching? The following code prints out to the console the expected information and bolds the item's text when expanded and removes the bold style when collapsed however the image doesn't change from open to closed when SetItemImage() is called.

class ApplicationFrame extends wxFrame {

    public $menubar;
    public $statusbar;
    public $tree;

    function __construct( $parent=null ){
        parent::__construct ( $parent, wxID_ANY, "wxDoctrine", wxDefaultPosition, new wxSize( 500,300 ), wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL );

        $this->SetSizeHints( wxDefaultSize, wxDefaultSize );

        $this->statusbar = $this->CreateStatusBar( 1, wxST_SIZEGRIP, wxID_ANY );
        $this->menubar = new wxMenuBar( 0 );
        $this->SetMenuBar( $this->menubar );

        $sizer = new wxGridSizer( 1, 2, 0, 0 );

        $this->tree = new wxTreeCtrl( $this, wxID_ANY, wxDefaultPosition, new wxSize(500, 300),  wxTR_DEFAULT_STYLE );

        $this->imagelist = new wxImageList(16, 15);
        $closed_image = new wxBitmap('theme/glyphicons/16x16/glyphicons-441-folder-closed.png', wxBITMAP_TYPE_PNG); 
        $index = $this->imagelist->add($closed_image);
        print 'Folder Closed: ' . $index . PHP_EOL;
        $open_image = new wxBitmap('theme/glyphicons/16x16/glyphicons-145-folder-open.png', wxBITMAP_TYPE_PNG); 
        $index = $this->imagelist->add($open_image);
        print 'Folder Open: ' . $index . PHP_EOL;

        $this->tree->SetImageList($this->imagelist);
        print 'ImageList Count: ' . $this->imagelist->GetImageCount() . PHP_EOL;

        $rootId = $this->tree->AddRoot('Entity', $index, $index);
        $currentId = $this->tree->AppendItem($rootId, 'User'); 
        $currentId = $this->tree->AppendItem($rootId, 'Role'); 
        $currentId = $this->tree->AppendItem($rootId, 'Privilige'); 

        $this->tree->Connect(wxEVT_COMMAND_TREE_ITEM_EXPANDED, [$this, 'onItemExpanded']);
        $this->tree->Connect(wxEVT_COMMAND_TREE_ITEM_COLLAPSED, [$this, 'onItemCollapsed']);

        $sizer->Add( $this->tree, 0, wxALL, 5 );

        $this->SetSizer( $sizer );
        $this->Layout();

        $this->Centre( wxBOTH );

    }

    public function onItemExpanded($event)
    {
        # Following method call doesn't work
        $this->tree->SetItemImage($this->tree->GetRootItem(), 1, wxTreeItemIcon_Expanded);

        $this->tree->SetItemBold($this->tree->GetRootItem(), true);  # Bold style is applied
        print 'Item Expanded' . PHP_EOL;
    }

    public function onItemCollapsed($event)
    {
        # Following method call doesn't work
        $this->tree->SetItemImage($this->tree->GetRootItem(), 0, wxTreeItemIcon_Normal);

        $this->tree->SetItemBold($this->tree->GetRootItem(), false);   # Bold style is removed
        print 'Item Collapsed' . PHP_EOL;
    }


    function __destruct( ){
    }

}

Below is the output from the console:

Folder Closed: 0
Folder Open: 1
ImageList Count: 2
Item Expanded
Item Collapsed
Item Expanded
Item Collapsed
Item Expanded
Item Collapsed
@NetWielder
Copy link
Author

If I do not pass the index of the images to AddRoot() I am able to use SetItemImage()

$rootId = $this->tree->AddRoot('Entity');

Are the index image parameters to AddRoot() considered "default" values and should SetItemImage() take precedence and override the previously established image index values?

It's easy enough to workaround however perhaps this is not the intended behavior?

@NetWielder
Copy link
Author

Am I using the AddRoot() method as intended? Thank you for your feedback. :-)

@jgmdev
Copy link
Member

jgmdev commented Jan 21, 2015

More appropriate documentation about wxTreeCtrl::AddRoot from wxWidgets docs:

The image and selImage parameters are an index within the normal image list specifying the image to use for unselected and selected items, respectively. If image -1 and selImage is -1, the same image is used for both selected and unselected items.

http://docs.wxwidgets.org/trunk/classwx_tree_ctrl.html#a1fa4eecee7fca8ea6d69903be8e6c285

I have to improve the reference generator to also extract the large description. I think I already did that on the new code generator, I just need to implement code generation of classes to start using it for wxPHP.

Sorry for the delay on this response.

@jgmdev jgmdev closed this as completed May 25, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants