Author Topic: [wxSmith] created panels does not take as many parameters as their ancestor  (Read 4286 times)

Offline Freem

  • Almost regular
  • **
  • Posts: 219
I am not very used to use RAD tools (I does not really think good things about them in general), but I wanted to try it since the window I am creating is not really interesting to draw (it's only a front-end for a tool I already have made).
So, my problem might be really easy to solve, but I did not see anything related to code generation in wxSmith's settings.

When you create a panel/window/... with wxSmith, the constructor does not have all parameters the ancestor have.
The problem is that when using a wxPanel somewhere else, and then change the ClassName field, parameters does not fit. So, each time I modify it, I have to remove those default parameters.
I tryed to simply add parameters to constructor, but the resulting code is dirty, because wxSmith uses and control the Create() method to generate the ancestor, instead of simply putting it in code and let the programer manage his constructor. (Also, it could use the constructor... result is the same finally, but it sounds cleaner to me?)
I think the worse is that wxSmith add parameters which are simply useles: they are the default values :/

I guess there could be 2 way to solve this in code:
_ creating constructors with as many parameters as the ancestor class
_ do not adding parameters when they are the default values
But perhaps things are already done and I did not found them. It would not be the first time   :-[
« Last Edit: August 27, 2012, 11:17:01 pm by Freem »

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9673
But perhaps things are already done and I did not found them. It would not be the first time   :-[
Yes, it is. In the properties of the main window(s) you can select what parameters to provide, including to "outsource" the initialisation code to an own method. This is also show, if you add another top-level-window and expand the wizard to the "advanced settings".

See the attached image...
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual:

Offline cacb

  • Lives here!
  • ****
  • Posts: 520
Hi, I have a very similar problem to this, hope you can assist. I am on Windows using Nightly Build 8248, using MSVC 2010 Express compiler.

I am designing a small Frame GUI application using wxSmith and using wxAuiManager to manage the main panels in the GUI, as I want the docking features etc.

I prefer to create separate panels deriving from wxPanel using wxSmith -> Add wxPanel (because then any events for the panel generated by wxSmith get handlers in my derived class). This "Add wxPanel" feature has a very similar dialog as you showed for wxDialog above, and I clicked all the options in the advanced section to get all the constructor parameters. It gives me up to 4 constructor parameters for my derived panel class, but no more. Let us assume my derived class is called GraphicsPanel:

class GraphicsPanel: public wxPanel

GraphicsPanel(wxWindow* parent,
                                      wxWindowID id=wxID_ANY,
                                      const wxPoint& pos=wxDefaultPosition,
                                      const wxSize& size=wxDefaultSize);


Now I want to use 'GraphicsPanel' in my wxAuiManager instance and again I used wxSmith to insert a wxPanel into wxAuiManager  (by clicking a wxPanel icon from the "Standard" tab). In the resource editor I for that panel, I changed the class name to 'GraphicsPanel', and added the proper #includes as necessary in the code.

This is all very well (?), but when I compile the code, I get this error
error C2661: 'GraphicsPanel::GraphicsPanel' : no overloaded function takes 6 arguments

The obvious explanation for this problem is that a wxPanel takes up to 6 constructor parameters (long style and const wxString& name, both with default values), and wxSmith generates code to pass all 6 constructor parameters to a wxPanel, but will not allow you to derive a wxPanel taking more than 4  constructor parameters, and then you get the problem above.

A work-around is to manually add the missing 2 constructor parameters to the GraphicsPanel constructor (so it becomes compatible with the auto-generated call), but it is tedious to have to do this every time.

Am I missing something obvious, or is there a way to tell wxSmith to generate a wxPanel derivative taking all 6 constructor parameters?