[wx-dev] tree control & drawing

Robert Roebling robert at roebling.de
Tue Oct 3 04:38:13 PDT 2006


> I am working on the tree control under OSX and currently looking at 
> the highlight. I have added support for bitmap highlights so it is 
> possible to have a gradient highlight that you get in the left had 
> column of Finder windows and many Apple applications. To do this I 
> have added some new methods to the tree control
> 
>      virtual void SetHighlightImage(const wxImage &);
>      virtual void SetUnfocusedHighlightImage(const wxImage &);

We'd generally use wxBitmap or wxIcon for such an interface.

> 
> There is some tom-foolery to cache a correctly scaled bitmap within 
> in the tree control (wxImage and wxBitmap make it easy). The results 
> don't look bad (heres a screeny)
> 
>    http://users.softpress.com/alan/Resources/treetest1.png
> 
> One of the things is that has become apparent to me that it is 
> impossible to write a subclass or hook into any events to make it 
> possible to override drawing behaviour in the base-class.
> 
> The drawing of an individual item is achieved through 'PaintItem'. 
> This method is not virtual and there are no events that I can hook 
> into. For me the only way to work with it is to modify the 
> 'wxGenericTreeCtrl' its self. To my mind the code could easily be 
> split across a few methods that could themselves be virtual. What I 
> am thinking is that painting an item could be done though
> 
>   PaintItemBackground
>   PaintItemHighlight
>   PaintItemContents
> 
> Or something like this. Obviously it would be possible to create a 
> set of events etc.

I'd say virtual methods are more appropriate here, but keep in mind
that the wxTreeCtrl under Windows is the native control and it
probably cannot be custmoized like that.
 
  Robert






More information about the wx-dev mailing list