wxRichTextCtrl not Working through wxFormBuilder

I’ve used wxFormBuilder to put a wxRichTextCtrl on my form. After doing
this, I run xrcise and try to use the control. The variable for the rich
text control is a FixNum. On examination, I saw that the class name in
the xrc file is “unknown”.

Is there no way to use this control without manually laying out the
controls - or writing this routine in C++? Does anyone know a
workaround?

Thanks in advance.
—Michael

Hi

On 12/08/2010 02:46, Michael S. wrote:

I’ve used wxFormBuilder to put a wxRichTextCtrl on my form. After doing
this, I run xrcise and try to use the control. The variable for the rich
text control is a FixNum. On examination, I saw that the class name in
the xrc file is “unknown”.

Is there no way to use this control without manually laying out the
controls - or writing this routine in C++? Does anyone know a
workaround?

I worked around it by designing the XRC with a bog-standard
Wx::TextCtrl, then in the initialise method of the inheriting Ruby
class, replacing it with a RichTextCtrl.

I wrote a convenience method to handle it properly. It’s called like
this (assuming a TextCtrl mapped to the instance var @text_box)

rtc = Wx::RichTextCtrl.new(…)
replace_xrc(:text_box, rtc)

The replace_xrc method looks like this:

class Wx::Window

Convenience function to replace one Window with another. Useful

because there are elements which are not available or convenient in

XRC, but a placeholder can be used with a real child created in

ruby.

Expects a symbol (eg :@child by which the old can be got) and a new

child to replace it. The instance variable’s value is overwritten.

def replace_xrc(old_sym, new_win)
old_win = instance_variable_get(“@#{old_sym}”)
old_win.containing_sizer.replace( old_win, new_win )
old_win.destroy
instance_variable_set(“@#{old_sym}”, new_win)
new_win.containing_sizer.layout
end
end

(from
http://weft-qda.rubyforge.org/svn/trunk/weft-qda/lib/weft/wxgui/utilities.rb)

hth
alex

I wrote a convenience method to handle it properly. It’s called like
this (assuming a TextCtrl mapped to the instance var @text_box)

thanks, that worked fine for me, too.

One thing to note is that, strangely, it doesn’t work if the RTC is the
only control in the sizer. So make sure that there is at least one more
control in the same sizer with your edit control.

Cheers,
Tony