Page 1 of 1

Scintilla - Style Only Selected Text

Posted: Wed Jun 03, 2015 9:32 pm
by DarkRookie
Tried looking at the Scintilla site and here as well but could not find what I am looking for.
I want to be able to change color, boldness, italics, and stuff like that only for text I have selected.

I managed to program it to do the whole gadget but never the selected text.

Thanks in advance


PS: Since, I will prolly ask this once the above is answered, how would I know what text has been change so I could do something like convert the text to HTML

Re: Scintilla - Style Only Selected Text

Posted: Wed Jun 03, 2015 10:53 pm
by kenmo
Here are some quick tips (I'm on my way out the door!)

You can use ScintillaSendMessage() with #SCI_GETSELECTIONSTART and #SCI_GETSELECTIONEND to get the selected text range.

Then use #SCI_STARTSTYLING and #SCI_SETSTYLING to change the style for a range of bytes.

(Of course you need to set up your styles with #SCI_STYLESETFORE, #SCI_STYLESETBOLD, etc.)



To detect when the text has changed, use a Scintilla Callback function and watch for the #SCN_MODIFIED event.


The Scintilla documentation page is a critical resource!
http://www.scintilla.org/ScintillaDoc.html

Re: Scintilla - Style Only Selected Text

Posted: Wed Jun 03, 2015 11:09 pm
by Tenaja
DarkRookie wrote:Tried looking at the Scintilla site and here as well but could not find what I am looking for.
I want to be able to change color, boldness, italics, and stuff like that only for text I have selected.

I managed to program it to do the whole gadget but never the selected text.

PS: Since, I will prolly ask this once the above is answered, how would I know what text has been change so I could do something like convert the text to HTML
In Scintilla, a text "Style" is a numbered predefined collection of text/font options:
http://www.scintilla.org/ScintillaDoc.h ... Definition

To set a selection of text to a style, first, you need to get the start and end of the selection:
http://www.scintilla.org/ScintillaDoc.h ... nformation

Then, using that information, set the style with SetStyling:
http://www.scintilla.org/ScintillaDoc.html#Styling
something like this:
ScintillaSendMessage(*this\id, #SCI_SETSTYLING, numBytesToStyle, styleToUse)

Obviously, you will need to calculate the numBytesToStyle, and it will vary if you use non-ascii characters.

If you are trying to use this like a word processor, I would encourage you to reconsider. It has fixed line height (to the largest font/size), and is not suited to much more than software text editing.

Kenmo beat me to Submit, but I'll post it anyway.