I got a BTextView “fFadeText” in a BWindow. When creating the BTextView, I use the c’tor specifying font and colour to use italics and a colour. And this works.
Now I want to adjust the text colour when the user changes the system colours. So in the BWindow’s MessageReceived() I check on the B_COLORS_UPDATED message and use SetFontAndColor(). Only: the text colour won’t change!
For debugging, instead of just one call to SetFontAndColor(), do this now:
Setting a breakpoint in Debugger, I check those values. And well… “before” and “after” are the same original colours set in the c’tor!
What do I miss here?
I don’t know why that doesn’t work but I’m updating the color in both Mail and AboutSystem that way and it works. You may have to set the font too for it to set the color and you definitely have to set the font flags to either 0 or B_FONT_ALL which is silly but true.
The fine print says that version of SetFontAndColor changes the attributes of the current selection. Is there a selection? Does it include position 0, which is the one from which you are reading them?
I have a patch set in the works that will allow you to assign a color which (e.g. B_DOCUMENT_TEXT_COLOR) instead of an explicit color to a BTextView which should alleviate the need to update it in the B_COLORS_UDPATED message, but alas, my patch doesn’t work yet. Maybe this is why it doesn’t work. I am not sure why this doesn’t work in the meantime. I guess you could try passing 0 and TextLength() - 1 in for the beginning and ending selection indexes to select the whole string, but you really shouldn’t have to do this.
You don’t need a selection. The other SetFontAndColor method takes offsets to apply the change. And you don’t even need that unless you’ve set the stylable mode. With the default false, there’s only one format for all the string and SetFontAndColor changes it.
And here is where I went wrong. I wrongly applied SetStylable(true) to my BTextView, with the wrong assumption that this is needed to get italic text. I’ve now removed that, and the colour change with fFadeText->SetFontAndColor(NULL, B_FONT_ALL, &infoColor); works as intended.
I don’t blame you. That’s the interpretation I find reasonable given the method name. Only when you pay close attention to the documentation or find a problem like this do you learn it really means “set the view to manage runs of text with differing styles”.