Seperating wxAuiToolBar object into a seperate view and control class Topic is solved

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
escanor
Earned a small fee
Earned a small fee
Posts: 13
Joined: Sun Jun 10, 2018 1:57 am

Seperating wxAuiToolBar object into a seperate view and control class

Post by escanor » Sun May 17, 2020 4:06 pm

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?

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2387
Joined: Sun Jan 03, 2010 5:45 pm

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

Post by PB » Sun May 17, 2020 8:30 pm

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.

escanor
Earned a small fee
Earned a small fee
Posts: 13
Joined: Sun Jun 10, 2018 1:57 am

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

Post by escanor » Sun May 17, 2020 9:09 pm

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?

Kvaz1r
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 207
Joined: Tue Jun 07, 2016 1:07 pm

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

Post by Kvaz1r » Sun May 17, 2020 9:38 pm

There is topic for MVC in wxWidgets discussion, maybe it will be helpful for you.

escanor
Earned a small fee
Earned a small fee
Posts: 13
Joined: Sun Jun 10, 2018 1:57 am

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

Post by escanor » Sun May 17, 2020 11:45 pm

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 :)

Post Reply