wxCrafter generated code using variables (wxSpinCtrl)?

Post here wxCrafter related issues / features / bugs
imalipusram
CodeLite Enthusiast
Posts: 16
Joined: Sat Sep 04, 2010 2:02 am
Genuine User: Yes
IDE Question: C++
Location: DE
Contact:

wxCrafter generated code using variables (wxSpinCtrl)?

Post by imalipusram »

Dear experts,

I am trying to set up a wxSpinCtrl where the minimum, maximum and default values are set by variables (g_default, g_min, g_max, see the code snippet below. I currently have them in a file global.cpp, later they will be read from a configuration file). wxCrafter is accepting the variables, but in order to compile the generated code, I manually have to edit wxcrafter.cpp (which I am not supposed to do ;) ) and insert a line pointing to the header file to be included ("#include global.h") to make it compile and work. Of course, after the next edit of the GUI, this will be gone.

For illustration, the code generated by wxCrafter looks like this:

Code: Select all

m_spinCtrl = new wxSpinCtrl(m_panel, wxID_ANY, wxT("g_default"), wxDefaultPosition, wxSize(-1,-1), wxSP_ARROW_KEYS);
    m_spinCtrl->SetRange(g_min, g_max);
    m_spinCtrl->SetValue(0); 
In addition (as wxT("g_default") already might suggest), the default value is not taken from the variable g_default, but instead "1" is used.

Any suggestions how one could solve these problems, e.g. is there a way to make wxCrafter automatically include some lines of user code into generated code for the GUI? Or do I simply follow the wrong approach (being still pretty new to C++, wxWidgets, CodeLite and wxCrafter).

Many thanks for your help and suggestions!
User avatar
eranif
CodeLite Plugin
Posts: 6367
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: wxCrafter generated code using variables (wxSpinCtrl)?

Post by eranif »

imalipusram wrote:I am trying to set up a wxSpinCtrl where the minimum, maximum and default values are set by variables (g_default, g_min, g_max, see the code snippet below. I currently have them in a file global.cpp, later they will be read from a configuration file). wxCrafter is accepting the variables, but in order to compile the generated code, I manually have to edit wxcrafter.cpp (which I am not supposed to do ) and insert a line pointing to the header file to be included ("#include global.h") to make it compile and work. Of course, after the next edit of the GUI, this will be gone.
What you should be doing is sublcassing wxSpinCtrl (e.g MySpin) note that your subclass should have the same ctor signature as descrbibed in wxWidgets docs http://docs.wxwidgets.org/stable/classw ... 583fa13c0f

Once you did this, in wxCrafter you should be using the "Subclass" field to set the your subclass name and include file.
See attached screenshot to see how I did similar thing with relacing wxAuiNotebook -> Notebook
sublcass.png
In your sublclass write all your custom code that you need

Eran
You do not have the required permissions to view the files attached to this post.
Make sure you have read the HOW TO POST thread
imalipusram
CodeLite Enthusiast
Posts: 16
Joined: Sat Sep 04, 2010 2:02 am
Genuine User: Yes
IDE Question: C++
Location: DE
Contact:

Re: wxCrafter generated code using variables (wxSpinCtrl)?

Post by imalipusram »

Thanks, eranif!

Just found a rather quick (and probably becoming rather dirty when used more than once in a project, as the same header file would be included several times then) workaround is simply to include "global.h" (in my example) in the subclass section and use the abovementioned variable names as min an max in the control specific settings.


Best regards!
imalipusram
CodeLite Enthusiast
Posts: 16
Joined: Sat Sep 04, 2010 2:02 am
Genuine User: Yes
IDE Question: C++
Location: DE
Contact:

Re: wxCrafter generated code using variables (wxSpinCtrl)?

Post by imalipusram »

Dear Experts,

despite the previously posted workaround, I am trying to make it work the orthodox way, i.e. deriving a class from wxSpinCtrl. I have spent two days now fighting with the internet and lots of c++ resources, but I simply don't get any clue: I've been searching for advice on "subclassing wxSpinCtrl", "cpp inheritance", "derived class example" etc. and I am getting lost in the the lots of information I get: There are so many examples with and without header files and so many flavors of programming that I simply "can't see the see the forest because of the many trees" (German proverb).

Would anybody please be so inclined to point me to a resource that is teaching me what I really need to do to derive my own class from wxSpinCtrl and how I can tell it that I want to set the min, max and default values to my desires (with separate .h and .cpp files) or maybe just giving me an example?

Sorry, I am completely confused now, lots of thanks for your efforts!

Thank you!
jfouche
CodeLite Guru
Posts: 351
Joined: Mon Oct 20, 2008 7:26 pm
Genuine User: Yes
IDE Question: C++
Location: France
Contact:

Re: wxCrafter generated code using variables (wxSpinCtrl)?

Post by jfouche »

Hi
wxWidgets Component Writing forum is probably a good place to post your question.
Jérémie
Post Reply