Menu

#538 SCI_SETSELBACK(FALSE) makes selection invisible

Bug
closed-works-for-me
Scintilla (812)
3
2007-03-06
2007-02-22
No

SCI_SETSELBACK(FALSE) is documented as restoring Scintilla's default selection color settings, but it doesn't actually do this - it instead just hides the selection permanently.

I think the problem is in scintilla/src/Editor.cxx, in Editor::WndProc(), at 'case SCI_SETSELBACK', around line 6927. The code there currently sets vs.selbackset to the wParam. This seems reasonable at first glance, since it's parallel to what SCI_SETSELFORE does, but from other uses in the code it appears that vs.selbackset actually has a rather different meaning - in particular, it looks like this member really means that you should draw or not draw the selection in a separate background color *at all*. For example, the 'Print' code uses it to hide the selection range during printing; and Editor::TextBackground() returns the selection color only if this member is set.

My tentative fix is to replace the current first two lines of 'case SCI_SETSELBACK' in Editor::WndProc with the following:

vs.selbackground.desired =
(wParam ? ColourDesired(lParam)
: ColourDesired(0xc0, 0xc0, 0xc0));

This has the documented effect, although it's not ideal in that it hard-codes #c0c0c0 as the background color. This same value is hard-coded in ViewStyle::Init() in scintilla/src/ViewStyle.cxx, so I didn't see a better solution within the context of the current code.

Discussion

  • Neil Hodgson

    Neil Hodgson - 2007-02-22
    • priority: 5 --> 3
    • assigned_to: nobody --> nyamatongwe
    • status: open --> open-works-for-me
     
  • Neil Hodgson

    Neil Hodgson - 2007-02-22

    Logged In: YES
    user_id=12579
    Originator: NO

    The effect of SCI_SETSELBACK(FALSE, x) is supposed to stop the display of the selection background colour, so that the selection can be shown just by modifying the foreground colour. Possibly I'm not understanding the point you are making.

     
  • Mike Roberts

    Mike Roberts - 2007-02-22

    Logged In: YES
    user_id=1723600
    Originator: YES

    Here's what the documentation for SCI_SETSELBACK says: "You can choose to override the default selection colouring with these two messages. The colour you provide is used if you set useSelection*Colour to true. If it is set to false, the default colour colouring is used and the colour argument has no effect."

    I interpreted "default selection coloring" to mean that the Scintilla defaults are restored - that is, the #c0c0c0 background and the styled text color foreground. It sounds like you're saying this actually means that the styled text background color is to be used for selected text.

    Part of the confusion might be that in the case of foreground text, the Scintilla default happens to be the styled text color, so the two interpretations coincide for SCI_SETSELFORE. But for the background, the Scintilla default and the current styled color are not the same, and to me the former interpretation makes more sense; but I can see how the latter would be useful too.

    If it really is meant to be the latter, then (a) I think the documentation should at least make it clear that it's not the Scintilla defaults that are restored but the current styled coloring, and (b) it would then be nice to have a separate call that restores the default Scintilla settings for background coloring. As it is, the only way for an application to restore the default Scintilla coloring is to explicitly call SCI_SETSELBACK(TRUE, #c0c0c0), which seems wrong in that the #c0c0c0 value isn't officially documented as the permanent and portable default setting. If you want, I can file a separate enhancement request for a call to restore the Scintilla defaults for selection foreground/background.

     
  • Neil Hodgson

    Neil Hodgson - 2007-02-23

    Logged In: YES
    user_id=12579
    Originator: NO

    The "default colour colouring" is pretty strange language. I suppose it could say "default styled colouring".

    #C0C0C0 is a backup in case the application hasn't chosen a selection colour. Its not a particularly valuable piece of information. SciTE uses black with an alpha of 30 and used #DADADA before translucency was available and I'd expect applications to copy SciTE or attempt a more platform-specific look with the equivalent of COLOR_HIGHLIGHT / COLOR_HIGHLIGHTTEXT.

     
  • Neil Hodgson

    Neil Hodgson - 2007-03-06
    • status: open-works-for-me --> closed-works-for-me
     

Log in to post a comment.