Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: kathbeau on December 01, 2014, 06:37:14 pm

Title: How to implement inheritance of custom frames (wxSmith MDI app)
Post by: kathbeau on December 01, 2014, 06:37:14 pm
I am new to Code::Blocks, and am using wxSmith to develop a test MDI application.

I want to create a form hierarchy such as this:

BaseChildFrame (derives from wxMDIChildFrame)

It will also contain code that can be invoked from forms that derive from it.

Here's where I went off the rails:

From the wxSmith tab, I selected Add wxFrame, and opened the Advanced options. Changed Base class name to my BaseChildFrame, but otherwise left everything unchanged.

Then I clicked OK. I modified the constructor to take BaseChildFrame* for the parent argument, and hoped to see that my sizer and panel had been brought into the new form/frame as inherited objects. This did not happen, and of course the whole mess does not compile. (I come from long years using the Borland Visual Component Library, which is where I got my expectations.)

I don't see the matter of inheritance for forms covered in the wxSmith tutorials, nor was online searching for combinations of keywords "wxWidgets", "wxSmith", "frame", "inheritance" fruitful.

Hoping somebody can point me to documentation (would love a tutorial or example).

Thanks,
Kathleen


Title: Re: How to implement inheritance of custom frames (wxSmith MDI app)
Post by: boya on December 02, 2014, 01:04:53 pm
You did not state your compiling error, so I am not sure how you have modified the constructor of the derived class. Let me guess the compiling error is something like this:
Quote
error: expected class-name before '{' token|
or
Quote
In constructor 'NewFrame::NewFrame(BaseChildFrame*, wxWindowID, const wxPoint&, const wxSize&)':
error: no matching function for call to 'BaseChildFrame::BaseChildFrame()'

If the first situation exists, then you should include the header file of the class BaseChildFrame in NewFrame.h;
If the second does, you should correct NewFrame.cpp as below:
Code
NewFrame::NewFrame(wxWindow*, wxWindowID, const wxPoint&, const wxSize&)
    : BaseChildFrame(parent)
Moreover, the call to "Create()" in this constructor, which is generated by wxSmith, should be removed (e.g. add //), otherwise application does not quit on closing this frame.

Then you can call this NewFrame like this:
Code
NewFrame* Frame = new NewFrame(0);
Frame->Show();
or in an existing window:
Code
NewFrame* Frame = new NewFrame(this);
Frame->Show();
My test case is OK through these modifications, on Windows 7 with CodeBlocks svn 10035.

The cause of the second situation is that the base class does not have a default constructor, and that it does not get initialised explicitly.
Title: Re: How to implement inheritance of custom frames (wxSmith MDI app)
Post by: kathbeau on December 02, 2014, 07:41:17 pm
Thank you, Boya!

Following your guidelines, I now have a wxMDIParentFrame with a menu, where I have added a menu item to create a new wxMDIChildFrame. That child window follows this hierarchy:

class BasicFrame : public wxMDIChildFrame

class BasicMenuFrame : BasicFrame

When I build and run the app, and invoke the menu item, I see the form has my color-modified panel (first child feature) and a menu (second child feature), so the inheritance is working.

Unfortunately, this inheritance does not display in the C::B IDE. That is, if I want to start adding sizers and widgets to the wxPanel that was inherited from the first child frame, it is not represented in the second (derived) child.

Oh, and now I've totally trashed my project. (heavy sigh)

Anyway, I do thank you so much for getting me this far! If you can help me with the IDE issue, I should be able to go off on my own for a little while.

Kathleen
Title: Re: How to implement inheritance of custom frames (wxSmith MDI app)
Post by: kathbeau on December 02, 2014, 07:59:03 pm
If the second does, you should correct NewFrame.cpp as below:
Code
NewFrame::NewFrame(wxWindow*, wxWindowID, const wxPoint&, const wxSize&)
    : BaseChildFrame(parent)
Moreover, the call to "Create()" in this constructor, which is generated by wxSmith, should be removed (e.g. add //), otherwise application does not quit on closing this frame.

Another problem: Each time I modify the inherited .wxs, the "Create(..." is uncommented. Obviously, I can just comment it out again, but in a large and changing project this could get to be really annoying.
Title: Re: How to implement inheritance of custom frames (wxSmith MDI app)
Post by: oBFusCATed on December 02, 2014, 11:15:13 pm
Probably there is a bug in wxSmith. Patches welcome.
Title: Re: How to implement inheritance of custom frames (wxSmith MDI app)
Post by: boya on December 03, 2014, 02:57:39 pm
Another problem: Each time I modify the inherited .wxs, the "Create(..." is uncommented. Obviously, I can just comment it out again, but in a large and changing project this could get to be really annoying.

I think both the IDE issue and the uncommented "Create(..." are wxSmith-related limitations.

On adding a new frame derived from an existing frame, e.g. BaseChildFrame, we can see that actually wxSmith does not understand the base class. It only replaces "wxFrame" with the specified name. Therefore in the constructor "Create()" is called redundantly; Also wxSmith would not load the GUI of the base class in the designer. And the generated code is refreshed automatically (getting uncommented) when you modify .wxs file, just because wxSmith takes control of it in case you change the layout. So this is a dilemma unless this plug-in can distinguish two situations.
Title: Re: How to implement inheritance of custom frames (wxSmith MDI app)
Post by: kathbeau on December 03, 2014, 05:02:56 pm
Another problem: Each time I modify the inherited .wxs, the "Create(..." is uncommented. Obviously, I can just comment it out again, but in a large and changing project this could get to be really annoying.

I think both the IDE issue and the uncommented "Create(..." are wxSmith-related limitations.

Then I need to change my question. I'm going to start a new thread for that.

Thank you,
Kathleen