Page 1 of 1

Custom Control

Posted: Sun Dec 04, 2016 2:18 am
by coder99
I would like to add the MyRichTextCtrl class - as given in the richtext example in the wxWidgets samples to a project, whose GUI code is built using wxCrafter.
It seems I would have to use a custom control, but since I am not at all familiar with how such a control is intended to be used, I am am struggling what would be the simplest way to add it.

I have played just a bit with this feature - wxCrafter 2.6 - and it looks like I have to be pretty sure what code I need to add to this custom class when I start, as there seems to be no easy way to edit/modify this code once it is started other than to perhaps create the code in an editor and then delete and recreate the custom control code over and over till it comes out right.

Am I missing some tutorial or other document. It seems I ran into this once before and it looks like I gave up on it and added the code manually to my derived main frame directly.

An additional wrinkle is that in this project I am also trying to get to know & use the AUI manager etc
TIA for any thoughts or pointers

Re: Custom Control

Posted: Sun Dec 04, 2016 1:59 pm
by eranif
The easiest way to use custom control in wxCrafter is by making a ctor with the exact same signature as the parent class.

If you use the default wxRichTextCtrl in wxCrafter, the generated code would be something like this:

Code: Select all

m_richTextCtrl91 = new wxRichTextCtrl(this, wxID_ANY, wxT("wxRichTextCtrl!"), wxDefaultPosition, wxDLG_UNIT(this, wxSize(-1,-1)), wxTE_MULTILINE|wxTE_PROCESS_TAB|wxTE_PROCESS_ENTER|wxWANTS_CHARS);
Which corresponds to this signature of wxRichTextCtrl:

Code: Select all

wxRichTextCtrl::wxRichTextCtrl	(	wxWindow * 	parent,
wxWindowID 	id = -1,
const wxString & 	value = wxEmptyString,
const wxPoint & 	pos = wxDefaultPosition,
const wxSize & 	size = wxDefaultSize,
long 	style = wxRE_MULTILINE,
const wxValidator & 	validator = wxDefaultValidator,
const wxString & 	name = wxTextCtrlNameStr 
)	
(notice that wxCrafter does not even pass the validator & name arguments)

To conclude:

1. Create new class MyRichTextCtrl class with this signature:

Code: Select all

MyRichTextCtrl::MyRichTextCtrl	(	wxWindow * 	parent,
wxWindowID 	id = -1,
const wxString & 	value = wxEmptyString,
const wxPoint & 	pos = wxDefaultPosition,
const wxSize & 	size = wxDefaultSize,
long 	style = wxRE_MULTILINE
)	
2. Add to your wxCrafter form a 'wxRichTextCtrl' control
3. To tell wxCrafter to use MyRichTextCtrl instead of wxRichTextCtrl, in the Subclass category of your newly added wxRichTextCtrl control, set the "Class name" field to "MyRichTextCtrl" and the "include file" to the header file containing this class

Generate your code...

Eran
and set its name in the "subclass"

Re: Custom Control

Posted: Mon Dec 05, 2016 7:06 am
by coder99
Thank you very much, Eran.
Following your detailed instructions, really did the trick.
I'll be sure to record this for myself for future reference.