Custom style for wxRichTextCtrl

149 views
Skip to first unread message

Eric Jensen

unread,
Nov 13, 2015, 2:16:48 PM11/13/15
to wx-u...@googlegroups.com
Hello,

let's say i wanted to add a spellchecker to wxRichTextCtrl and needed
to add these "wiggly" lines under some words.

Is this theoretically possible with wxRichTextCtrl and where would i
have to "hook" into?

Thanks.

Eric

Iwbnwif Yiw

unread,
Nov 13, 2015, 3:03:39 PM11/13/15
to wx-users, m...@j-dev.de
AFAIK it isn't possible unfortunately.

I suggested this as a possible GSOC 2015 project and you can find some suggestions how it might be implemented here:


Though not necessarily for wxRichTextCtrl.

 

Catalin

unread,
Nov 13, 2015, 5:51:32 PM11/13/15
to wx-u...@googlegroups.com
For the actual painting you can override wxRichTextCtrl::PaintAboveContent(). You only need to find the position of the words as they are laid out on the wxDC, and by the time PaintAboveContent() is called the content layout would have already taken place.

HTH,
C




--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+unsub...@googlegroups.com
or visit http://groups.google.com/group/wx-users


Julian Smart

unread,
Nov 14, 2015, 9:53:28 AM11/14/15
to wx-u...@googlegroups.com
Or, add another text effect style to wxTextAttrEffects in wx/textctrl.h,
and also some functions to wxRichTextRenderer (a place to put common
drawing functions) to draw the effect using an application-overridable
colour.

It could also be hard-wired into the text-drawing code but using a
renderer, you could supply a new renderer for your application and apply
colour without having to complicate wxRichTextAttr with further members
and attributes (and changing a lot of functions that deal with them)
apart from the text effect style. There could be a default colour set
with a static member of wxRichTextRenderer, so if you only need one
colour, you wouldn't have to supply a new renderer in your application.

The tricky bit would be maintaining the correct attributes for the
pertinent words. You could use a custom wxRichTextDrawingHandler handler
to supply virtual attributes; do the spell check, maintain a list of
words in the current document that should be highlighted, then in your
wxRichTextDrawingHandler::HasVirtualAttributes/GetVirtualAttributes/GetVirtualSubobjectAttributes
functions, test whether the current text object and positions within it
require highlighting, if so adding the text effect style. To use
different colours, you could maybe set a property in the text objects
and query that in the renderer code, or the renderer code could access
your list of words to be highlighted.

With the above, you wouldn't need to calculate text object positions on
the screen, and some of the work would be done by wxRTC instead of your
application.

BTW I recently replaced MySpell with Hunspell in one of my applications
and it was much easier than I thought since the API is largely the same
as MySpell's. I use wxSpellChecker and added new HunspellInterface.cpp/h
file to replace MySpellInterface.cpp/h.

Regards,

Julian
> To unsubscribe, send email to wx-users+u...@googlegroups.com
> <mailto:unsub...@googlegroups.com>
> or visit http://groups.google.com/group/wx-users
>
>
> --
> Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
>
> To unsubscribe, send email to wx-users+u...@googlegroups.com
> or visit http://groups.google.com/group/wx-users

Eric Jensen

unread,
Nov 14, 2015, 5:19:49 PM11/14/15
to Julian Smart
Hello Julian,

Saturday, November 14, 2015, 3:53:21 PM, you wrote:

JS> Or, add another text effect style to wxTextAttrEffects in wx/textctrl.h,
JS> and also some functions to wxRichTextRenderer (a place to put common
JS> drawing functions) to draw the effect using an application-overridable
JS> colour.

JS> It could also be hard-wired into the text-drawing code but using a
JS> renderer, you could supply a new renderer for your application and apply
JS> colour without having to complicate wxRichTextAttr with further members
JS> and attributes (and changing a lot of functions that deal with them)
JS> apart from the text effect style. There could be a default colour set
JS> with a static member of wxRichTextRenderer, so if you only need one
JS> colour, you wouldn't have to supply a new renderer in your application.

JS> The tricky bit would be maintaining the correct attributes for the
JS> pertinent words. You could use a custom wxRichTextDrawingHandler handler
JS> to supply virtual attributes; do the spell check, maintain a list of
JS> words in the current document that should be highlighted, then in your
JS> wxRichTextDrawingHandler::HasVirtualAttributes/GetVirtualAttributes/GetVirtualSubobjectAttributes
JS> functions, test whether the current text object and positions within it
JS> require highlighting, if so adding the text effect style. To use
JS> different colours, you could maybe set a property in the text objects
JS> and query that in the renderer code, or the renderer code could access
JS> your list of words to be highlighted.

JS> With the above, you wouldn't need to calculate text object positions on
JS> the screen, and some of the work would be done by wxRTC instead of your
JS> application.

JS> BTW I recently replaced MySpell with Hunspell in one of my applications
JS> and it was much easier than I thought since the API is largely the same
JS> as MySpell's. I use wxSpellChecker and added new HunspellInterface.cpp/h
JS> file to replace MySpellInterface.cpp/h.

JS> Regards,

JS> Julian

Thanks Julian, now i have a general idea what i have to do ;)

Eric

Reply all
Reply to author
Forward
0 new messages