Chad Johnson wrote:

I can't figure out how to change the background color of a range of text. I've tried and tried and tried and tried and tried and it just does not work at all. Could somebody give me an example of how to do this or if it's not possible just tell me.
  I really need a response.


While it sounds like you are having a rough time, it would help if you gave some context... what approaches have you tried, what *did* happen even if they didn't work the way you want, etc.

As it happens, I can see that you made a "Scintilla Feature Request" that is presumably talking about this too.

Anyway, offhand (and assuming you are not writing or working with a lexer), the way I would do this would be pretty much like setting up Scintilla to work with a lexer: define the display and font attributes of a style or styles using SCI_STYLESETFORE, SCI_STYLESETBACK, SCI_STYLESETBOLD, etc. Then just do a SCI_STARTSTYLING followed by some number of SCI_SETSTYLING calls using "styles" you have defined above.

I have not tried doing "raw" use of the styling machinery like this, but this is about what it should look like. A refinement if you are going to define more than a couple of styles would be to define "common" attributes for the "magic" STYLE_DEFAULT, and then do a SCI_STYLECLEARALL to set all styles to these values - then use the "SCI_STYLESET*" calls to set the differences.


Robert Roessler
[EMAIL PROTECTED]
http://www.rftp.com



I forgot to set it so I receive the e-mails, so I didn't see the response till I visited the site - so that's why this is in a new thread.

So I was trying to figure out how to change the background color of a range of text in a scintilla text control - namely the wxStyledTextCtrl for wxWidgets. I'm making a Bible program and I want to highlight specified verses.

Today I tried the following:

StyleSetBackground(0, wxColour(255, 255, 0);
StartStyling(10, 0);
SetStyling(5, 0);

to style 5 characters starting at position 10 in yellow. However, all text became yellow (but the background of the control stayed white).

I also tried using SCI_STYLESETBACK directly with no luck.

I even tried defining my own styles using style indexes above and below 32:

StyleSetBackground(5, wxColour(255, 255, 0);
StartStyling(10, 0);
SetStyling(5, 5);

and

StyleSetBackground(100, wxColour(255, 255, 0);
StartStyling(10, 0);
SetStyling(5, 100);

to no avail. It just does not work. I'm lost and I really want this to work - if I can't get this to work I basically have to scrap my application - http://aletheia.sourceforge.net. Can you give me some example code please? I'll try what Robert suggested in the meantime.

OK, a few more details: the "styleset*" stuff is setting attributes of "styles", which are really just integer ids of collections of... drawing attributes - fonts, colors, etc. :)

These integers are what goes into the style bytes that are paired with every text byte in a Scintilla buffer. So, a typical "coloring" operation might be (AFTER your style(s) are defined with the styleset* calls):

1) do a SCI_STARTSTYLING with the POSITION of the first char you want to color and the MASK specifying which style bits you want to allow to change - for you, this should probably ALWAYS be 31 (or 0x1f).

2) do a SCI_SETSTYLING with the COUNT of chars to color and the STYLE to set this number of style bytes to

3) ... choose a new position and style and go back to 1) ... that's it

It is IMPORTANT to NOT set the mask to 0 - since that will not allow ANY style info to change. :)

Note that in real life, there are times when the styling mask will be something other than 31 (0x1f)... but that is for another day.

Robert Roessler
[EMAIL PROTECTED]
http://www.rftp.com
_______________________________________________
Scintilla-interest mailing list
[email protected]
http://mailman.lyra.org/mailman/listinfo/scintilla-interest

Reply via email to