Page 1 of 1

Seperating wxAuiToolBar object into a seperate view and control class

Posted: Sun May 17, 2020 4:06 pm
by escanor
I like to separate all my views, controls into separate classes for all the custom widgets I make.

However, unless I am missing something really trivial.. I am having trouble with the wxAuiToolBar class.

Say I have a class called CustomToolBarView that inherits from wxAuiToolBar, and in this class I create the toolbar and add all of its items.

I want to connect the event handlers for CustomToolBarView in another class called CustomToolBarControl.

CustomToolBarControl would normally inherit from wxControl, i'd setup my handlers in this class and everything would run smoothly....

However... the issue is that wxAuiToolBar itself inherits from wxControl... meaning it would want all the handlers to be specified in my CustomToolBarView class.

Is there anyway I can still separate the event handlers for my custom wxAuiToolBar object into another class?

Re: Seperating wxAuiToolBar object into a seperate view and control class

Posted: Sun May 17, 2020 8:30 pm
by PB
I must be missing something but I do not understand the purpose.

Why would you want to handle input from one control in another control created solely for the purpose of handling other controls events? To me, removing events from the control defeats the purpose of having a control where producing events are the main reason for its existence. You are talking about views and controls, but at least in the MVC and similar patterns, a "View" is not something that should handle specific events. In fact is should know nothing about those. Therefore, a control such as a toolbar is not a view.

A wxControl is a part of a GUI the user interacts with. How would CustomToolBarControl look in your application?

If you, for some reason, want to handle the events from one class in another class, you need to forward them there. It is usually done using an event handler. If you use the old ways (Connect() or message maps) the recipient class must derived from wxEvtHandler. If you use Bind(), anything goes. I do no think you can (easily) decouple a control and a class handling the control's events, and there is usually little reason to do that.

Re: Seperating wxAuiToolBar object into a seperate view and control class

Posted: Sun May 17, 2020 9:09 pm
by escanor
Thanks for getting back, I think I understand where my confusion is coming from, and if what I am thinking is right I believe I have totally misunderstood the MVC pattern.

I've viewed wxAuiToolbar as a view so far... and yes I agree a view does not handle any events.

So what I am trying to do is initialize all the wxAuiToolbar items in my view class, while the logic for what happens when an item is clicked is stored in my control class.

Is this the wrong approach?

Re: Seperating wxAuiToolBar object into a seperate view and control class

Posted: Sun May 17, 2020 9:38 pm
by Kvaz1r
There is topic for MVC in wxWidgets discussion, maybe it will be helpful for you.

Re: Seperating wxAuiToolBar object into a seperate view and control class

Posted: Sun May 17, 2020 11:45 pm
by escanor
I completely understand what you mean by it being pointless now, I feel so silly.

I was working on some badly nested custom widgets and it really made me overthink this toolbar, of course it can't be a view!
Thanks a bunch guys :)