wxGenericDirCtrl and events

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
wxuser
Knows some wx things
Knows some wx things
Posts: 29
Joined: Fri Feb 25, 2005 5:45 am
Location: India

wxGenericDirCtrl and events

Post by wxuser »

Hi all,

Is there any sample implementation or docs on wxGenericDirCtrl, I am building a file browser and want to add some basic events like double click and right click menu items.

thanks

Deez
benedicte
wxWorld Domination!
wxWorld Domination!
Posts: 1409
Joined: Wed Jan 19, 2005 3:44 pm
Location: Paris, France

Post by benedicte »

the documentation is here, and you can find the implementation in your wxWidgets local directory :
/src/generic/dirctrlg.cpp
jpcurrey
In need of some credit
In need of some credit
Posts: 2
Joined: Sat Feb 04, 2006 7:34 am

wxGenericDirCtrl mouse events not working

Post by jpcurrey »

I am using wxPython version of GenericDirCtrl and dont appear to be getting the events mentioned below, is there something special that I have to do to make it work??

"""
self.dirTree = wx.GenericDirCtrl(defaultFilter=0, dir='.',
filter='All files (*.*)|*.*|SConstruct files|SConstruct;SConscript|Make files|Makefile|Source files (*.cpp;*.c)|*.cpp;*.c|Header Files (*.hpp;*.h) |*.hpp;*.h',
id=wxID_MAINFRAMEDIRTREE, name='dirTree',
parent=self.spltTreeText, pos=wx.Point(0, 0), size=wx.Size(200,
650), style=wx.DIRCTRL_SHOW_FILTERS | wx.DIRCTRL_3D_INTERNAL)
self.dirTree.Bind(wx.EVT_LEFT_DCLICK, self.OnDirTreeLeftDclick)
self.dirTree.Bind(wx.EVT_RIGHT_DOWN, self.OnDirTreeRightDown)
"""
DavidHart
Site Admin
Site Admin
Posts: 4254
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Post by DavidHart »

Hi,

wxGenericDirCtrl is a composite control: there's a wxTreeCtrl buried inside it. Because mouse events don't propagate they never arrive at the wxGenericDirCtrl, so you can't get at treectrl mouse events in the usual way.
There are three possible solutions:

1) I've not tried it, but you can probably use the "Connect" method of grabbing events. I'd suggest trying this if there are only 1 or 2 events that you want to grab, and otherwise you are just using the wxGenericDirCtrl straight.
2) You should be able to push a new derived wxEvtHandler onto the treectrl, and use this to process or redirect as many events as you like.
3) If you are planning on doing lots of clever things to the wxGenericDirCtrl, you will probably want to subclass the treectrl anyway. This is now easy in wx2.6.2 as there is a new protected member function, wxGenericDirCtrl::CreateTreeCtrl(), that allows you to recreate the tree as you wish. So you subclass wxGenericDirCtrl (to allow you to use CreateTreeCtrl()) and replace the old tree with your own, subclassed version MyTreeCtrl. Within MyTreeCtrl you can use an event table to process events as usual.

BTW, I don't know wxPython, so it's just possible that some things may be different there.

HTH,

David
Post Reply