Scintilla - Style Only Selected Text

Just starting out? Need help? Post your questions and find answers here.
User avatar
DarkRookie
User
User
Posts: 20
Joined: Wed Nov 24, 2010 5:47 pm

Scintilla - Style Only Selected Text

Post 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
It is better to have a dumb question than a wrong answer!
User avatar
kenmo
Addict
Addict
Posts: 2033
Joined: Tue Dec 23, 2003 3:54 am

Re: Scintilla - Style Only Selected Text

Post 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
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: Scintilla - Style Only Selected Text

Post 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.
Post Reply