wxTreeCtrl Event handling

Are you writing your own components and need help with how to set them up or have questions about the components you are deriving from ? Ask them here.
Post Reply
SalmonsSteve
Knows some wx things
Knows some wx things
Posts: 27
Joined: Sun Jun 24, 2012 6:00 pm

wxTreeCtrl Event handling

Post by SalmonsSteve » Sun Jun 24, 2012 6:52 pm

I am working on a project which has a wxtreectrl displayed as a panel in an aui frame. I have added a context menu to the items in the tree and am able to handle the wxCommandEvent created by the menu items from within the the tree control but I am not able to skip the event and make the parent frame process the event also. My Code looks something like this...

Code: Select all

BEGIN_EVENT_TABLE(myAuiFrame, wxFrame)
    EVT_CLOSE(myAuiFrame::OnClose)
    EVT_MENU(idMenuQuit, myAuiFrame::OnQuit)
    EVT_MENU(idMenuNew, myAuiFrame::OnNew)
    EVT_MENU(idMenuAbout, myAuiFrame::OnAbout)
    EVT_MENU(OPENBEAMFILE, myAuiFrame::DisplayResults)
END_EVENT_TABLE()

BEGIN_EVENT_TABLE(myTreeCtrl, wxTreeCtrl)
    ...
    EVT_MENU(OPENBEAMFILE, myTreeCtrl::RunBeamFile)
END_EVENT_TABLE()


void myTreeCtrl::RunBeamFile(wxCommandEvent &event)
{
    BeamInput *CalcBeamFile;
    CalcBeamFile = new BeamInput((wxChar*)CurrentFile.c_str());
    delete CalcBeamFile;
    // event.Skip();         <--- if I leave this line uncommented I get a segmentation fault and myAuiFrame does not receive event
                                           // if I comment it out the event handling ends here
}
a bit more explanation on what I am trying to do:
When the user selects "View Results" from the tree item's context menu an instance of the BeamInput class is created. Within this class a file is read and a calculation dll is called. The calculation dll creates a text file with the resulting input and output. After the file is created I need to be able to create a new panel to display the output. As far as I know, this should be done in the AuiFrame and it should be added to the AuiManager. Once the text file is on screen I need to delete the temporary file created by the dll. I have not made the AuiFrame or the AuiManager global so I can not access them from myTreeCtrl and if possible I would prefer to avoid globals.

I have set a breakpoint inside myAuiFrame::DisplayResults(wxCommandEvent& event) and have stepped through the debugger to verify that this function is never called. Have I done something wrong here? At this point I haven't even begun to create the new panel to display the text file because I can't figure out how to let the AuiFrame know that there is an output file there to be displayed.

A note about myself since I haven't posted before... I have been toying with writing simple projects with wxWidgets, off and on, for a few years now. I took a class that covered many of the basics of wxWidgets at the local community college a few years back when I was deciding which API to use when developing the project I am currently writing. At the time I was doing program development and maintenance for my company however, in the time since then, my work duties have shifted away from programming and I have unfortunately not made as much time as I should to learn the more intricate details of programming with wxWidgets. Unfortunately the devil is in the detail.

User avatar
doublemax
Moderator
Moderator
Posts: 14626
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxTreeCtrl Event handling

Post by doublemax » Sun Jun 24, 2012 7:48 pm

Code: Select all

BEGIN_EVENT_TABLE(myTreeCtrl, wxTreeCtrl)
    ...
    EVT_MENU(OPENBEAMFILE, myTreeCtrl::RunBeamFile)
END_EVENT_TABLE()
I'm surprised this works at all, shouldn't the event type be EVT_TREE_ITEM_RIGHT_CLICK?
Use the source, Luke!

SalmonsSteve
Knows some wx things
Knows some wx things
Posts: 27
Joined: Sun Jun 24, 2012 6:00 pm

Re: wxTreeCtrl Event handling

Post by SalmonsSteve » Sun Jun 24, 2012 9:37 pm

No, when the item is right clicked the menu is built appropriately using a proper even handler, that is not where the problem exists. I have clearly only shown the line in my event table that is processing the menu event. The wxTreeCtrl catches the event but the AuiFrame never sees it. Again, this is for the event that is fired when the menu item is selected from the context menu not the right click event.

User avatar
doublemax
Moderator
Moderator
Posts: 14626
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxTreeCtrl Event handling

Post by doublemax » Tue Jun 26, 2012 8:43 am

I see. I tried it with a slightly modified "treectrl" sample and it works there. Maybe it's one of these small details where wxAUI components don't behave like standard wxWidgets controls. If you could create a patch to the "aui" sample that shows the problem, i could take another look.
Use the source, Luke!

SalmonsSteve
Knows some wx things
Knows some wx things
Posts: 27
Joined: Sun Jun 24, 2012 6:00 pm

Re: wxTreeCtrl Event handling

Post by SalmonsSteve » Tue Jun 26, 2012 9:24 pm

Thank you, I will try to put something together this evening using the "aui" sample for you to take a look at. As a side note, I may have changed my mind about which window I want to have as the parent of the text file display window I am going to spawn. The convenient solution would be to have the treectrl's panel become the parent of the text file display window (as I can create the window from the same event handler that is currently doing the rest of the work). The more I think about doing it this way the more it makes sense to me (assuming a managed aui panel can be a parent of another panel/window. The tree control is essentially a project browser holding all files related to a project. If the project closes then all windows related to that project should close also so it makes sense to me to have the treectrl as the parent....

I'll have to take a look into that a bit more when I go home this evening. Thank you again and I will post some code as soon as I am able to.

Post Reply