Page 1 of 1

Connecting wxRibbonButtonBar Events

Posted: Fri Mar 22, 2013 11:17 pm
by iwbnwif
I feel connecting wxRibbonButtonBar events is a little bit counter-intuitive in WC.

Although you need to right-click on the button in the tree view and select "Connect Events" for each button, actually it is the button bar that has the event connected.

It doesn't matter what method you connect the first n buttons to, they all end up connected to the method set by the last button.

It is then necessary to use event.GetID() inside the method to get the ID of the clicked button (don't leave the buttons all as wxID_ANY ;) )

I appreciate that this is because of the way in which the ribbon control handles button events, and the ID situation will be slightly improved in 2.9.5 with the GetButton() method.

I think it would be better to "connect" the event for the button bar object in the tree and the code that is generated connects all buttons within that bar.

Sorry if my explanation isn't clear or if I have misunderstood how this is meant to be used.

Re: Connecting wxRibbonButtonBar Events

Posted: Sat Mar 23, 2013 1:53 pm
by eranif
iwbnwif wrote:It is then necessary to use event.GetID() inside the method to get the ID of the clicked button (don't leave the buttons all as wxID_ANY )
The buttons don't have real class representing them, for visualization, I made it as if there is a real object behind it.
At the end, a button is just a call to wxRibbonBarButton::AddButton
So yes, you must make sure that you don't use wxID_ANY

I had similar situation when I implemented wxToolBar, however, for wxToolBar I could allocate a wxToolBarItem which there is no equivalent in the wxRibbonBar family (at least in the released wx2.9.4)
The API suggests that this will change - once it will, I will probably adjust the event handling code

Eran