News:

As usual while waiting for the next release - don't forget to check the nightly builds in the forum.

Main Menu

wxSmith : add option for Create function in inhereited cases

Started by LR83, January 23, 2026, 03:04:10 PM

Previous topic - Next topic

LR83

I have a problem when I want to inherit from my custom panel. wxSmith add automatically this Create function:
Create(parent, id, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("id"));
But my constructor is:
myNewPanel::myNewPanel(wxWindow* parent, wxWindowID id): myPanel(parent, id)
so I need each time to comment the bad Create line.

Is it possible to add an option to prevent this line from being added automatically, such as the "Lay-out the window" option?

And another point, is it possible to add another option for the "Lay-out the window" option to have the choice beetwen SetSizeHints(this) and Fit(this) ?

LR83

I try to add the option.
- Add m_Create property in wxsBaseProperties
- wxsItem::GetCreatePrefix, test the m_Create property. If false, I just add '//' before the Create function. So we can always see the parameters of the Create function (may be usefull).
Work for my project but I don't know if my solution is always good.
See the corrected files in the attachment.

ollydbg

Hi, I use some my own defined wxWidgets control from time to time. When I try to add this custom control in the wxSmith GUI designer, you can select the "Custom" control, and define the constructor yourself.

Is this the case I describe above?
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

LR83

Not exactly, in my case it's about inherited classes.
For example, we have a first class that inherits from wxPanel: wxMyPanel. Then a second class that inherits from wxMyPanel with different parameters. For this second class, we don't want to use the Create function but inheritance directly in the constructor.
This is also possible with first class. For example:
Header:
class wxMyPanel: public wxPanel
{
  public:

    wxMyPanel(wxWindow* parent, wxWindowID id);
    virtual ~wxMyPanel();

  protected:
     // Other declarations
};

Code:
wxMyPanel::wxMyPanel(wxWindow* parent, wxWindowID id)
{
  //(*Initialize(wxMyPanel)

  Create(parent, id, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("id"));
  // Other declarations
}


Or directly:
wxMyPanel::wxMyPanel(wxWindow* parent, wxWindowID id): wxPanel(parent, id)
{
  //(*Initialize(wxMyPanel)

  // Other declarations
}


LR83

Is my proposition posted above on January 24, 2026 work for everybody and could be added on next release ?

ollydbg

Quote from: LR83 on March 28, 2026, 02:57:59 PM
Is my proposition posted above on January 24, 2026 work for everybody and could be added on next release ?

So, you want an option to enable/disable the usage of "Create" function? Sorry I'm still not quite understand your idea, and I'm not quite familiar with wxSmith's source code.

I just copy your code in the attachment to the local code repo, and I see it does not change much. And can you modify your code to a patch file, which is against the last code base?

I hope some devs who are more familiar with wxSmith will review your patch file.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

LR83

Yes, the change is very slight and does not disrupt normal behavior.
We now just have a new option to call or not the Create() function (the default value is true in order to keep the old generation code).
I introduced this because when you call the parent in the constructor, you should not use the Create() function.

I don't know how to create a "patch file". Do I need a special environment?

ollydbg

Quote from: LR83 on March 29, 2026, 09:20:07 AM
I don't know how to create a "patch file". Do I need a special environment?

Well. A patch file or a diff file can be obtained by some version control tool. For example, svn or git. For C::B source, it has svn code repo, and git code mirrors. You can fetch the code from svn code repo or clone the code from git repo, and make some modification to the source code, and later generate patch file.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.


ollydbg

Quote from: LR83 on April 06, 2026, 08:53:24 AM
Ok, I try with my Github with the C::B mirror:  codeblocks_sfmirror

You can see the diff in this page : https://github.com/GitHubLionel/codeblocks_sfmirror/commit/9307e9b2852532796914b218042194578831f59b

Oh, I just noticed that you are the author of GitHubLionel/wxMathPlot: An enhanced version of the wxMathPlot component for wxWidgets. Welcome to the C::B forum.

I think I will take some to learn your patch, thanks. But not very soon, because I'm a bit busy those days.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

ollydbg

It is in our svn now, thanks.

BTW: I think comment out the "Create" function could be changed to "remove this line" if the option is "false". But I'm not sure how to do that.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

LR83

Great :)
Removing the line instead of simply replacing it with a comment requires more work. We need to remove all the code that builds this line and it is not so easy.
That's why I simply add a "//" at the beginning of the line to comment it.