How to copy ("clone", "duplicate") wxControls?

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
User avatar
Parduz
I live to help wx-kind
I live to help wx-kind
Posts: 188
Joined: Fri Jan 30, 2015 1:48 pm
Location: Bologna, Italy

How to copy ("clone", "duplicate") wxControls?

Post by Parduz »

I have to dinamically fill a panel with wxStaticText and custom buttons (derived from wxWindow), one of each for each file i found in a directory.
They have to act and looks all the same with the exception of the "caption" text. "Building" them property by property when i new() them is tedious: i'd like more to have an original (designed in a IDE) and use it as a model.

There's a (safe, advisable) way to copy (or clone, or duplicate) an existing wxSomething? If yes, could it works also for event binding?
DavidHart
Site Admin
Site Admin
Posts: 4252
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Re: How to copy ("clone", "duplicate") wxControls?

Post by DavidHart »

Hi,

It sounds as if you're trying to reinvent the wheel ;) . Just use a form-designer.

I use wxCrafter (and I'm pleased to say it has just been open-sourced) which is part of the CodeLite IDE; I'd expect other form-designers will do the same sort of thing though. In it, you'd create a wxStaticText, optionally setting its text. You can tell wxCrafter to duplicate it several times, then you change the text of each where needed. Similarly for other controls/sizers and their events.

You save that frame/panel/whatever as a 'base' class. Finally you derive your real class from that base class.

If you later want to change part of the design...no problem, just reopen wxCrafter, make the edits and export the base-class code again. Recompile and it's changed.

Regards,

David
User avatar
Parduz
I live to help wx-kind
I live to help wx-kind
Posts: 188
Joined: Fri Jan 30, 2015 1:48 pm
Location: Bologna, Italy

Re: How to copy ("clone", "duplicate") wxControls?

Post by Parduz »

DavidHart wrote: Tue Mar 05, 2019 3:33 pm I use wxCrafter (and I'm pleased to say it has just been open-sourced) which is part of the CodeLite IDE; I'd expect other form-designers will do the same sort of thing though. In it, you'd create a wxStaticText, optionally setting its text. You can tell wxCrafter to duplicate it several times, then you change the text of each where needed. Similarly for other controls/sizers and their events.
I'm using wxCrafter, and i don't see how your solution can expand dinamically (i mean: at runtime) depending on the content of a directory (just to use my case as example).
DavidHart
Site Admin
Site Admin
Posts: 4252
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Re: How to copy ("clone", "duplicate") wxControls?

Post by DavidHart »

My apologies: I didn't read your question carefully enough.
There's a (safe, advisable) way to copy (or clone, or duplicate) an existing wxSomething?
wxGenericDirCtrl displays the contents of a dir dynamically. However it doesn't use any sort of custom button.

Alternatively you could use wxListCtrl or (better) one of the wxDataViewCtrl variants. See the relevant samples.
User avatar
Parduz
I live to help wx-kind
I live to help wx-kind
Posts: 188
Joined: Fri Jan 30, 2015 1:48 pm
Location: Bologna, Italy

Re: How to copy ("clone", "duplicate") wxControls?

Post by Parduz »

DavidHart wrote: Tue Mar 05, 2019 4:47 pm My apologies: I didn't read your question carefully enough.
There's a (safe, advisable) way to copy (or clone, or duplicate) an existing wxSomething?
wxGenericDirCtrl displays the contents of a dir dynamically. However it doesn't use any sort of custom button.

Alternatively you could use wxListCtrl or (better) one of the wxDataViewCtrl variants. See the relevant samples.
I have no problem in listing the files and create controls at runtime. I'd just like to avoid to set all properties one by one. :)
That's why I would like to "ignore" the reason i mentioned as an example and stay on the question:
there's a way to "clone" an already existing control?
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to copy ("clone", "duplicate") wxControls?

Post by doublemax »

there's a way to "clone" an already existing control?
No.
Use the source, Luke!
Post Reply