BTextView: Use document colors on AdoptSystemColors()

AdoptSystemColors() tints document background color to match panel
color if uneditable.

Calling MakeEditable() will automatically apply or unapply uneditable
background tint if you have previously called AdoptSystemColors().

Parent BView::AdoptSystemColors() sets panel colors, we want document
colors here. Do not alter text color - only view, low and high colors
are changed.

Document AdoptSystemColors() and MakeEditable() in BTextView docs.

Change-Id: Ib215735f27bb01fc2f95fcf2fee0185e5fc83f70
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8263
Haiku-Format: Haiku-format Bot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
Tested-by: Commit checker robot <[email protected]>
This commit is contained in:
John Scipione
2025-01-17 16:57:38 +00:00
committed by waddlesplash
parent 13553050f9
commit 9105063938
3 changed files with 78 additions and 3 deletions
+37 -2
View File
@@ -1589,8 +1589,20 @@ BTextView::GetSelection(int32* _start, int32* _end) const
void
BTextView::SetFontAndColor(const BFont* font, uint32 mode,
const rgb_color* color)
BTextView::AdoptSystemColors()
{
if (IsEditable())
SetViewUIColor(B_DOCUMENT_BACKGROUND_COLOR);
else
SetViewUIColor(B_DOCUMENT_BACKGROUND_COLOR, _UneditableTint());
SetLowUIColor(ViewUIColor());
SetHighUIColor(B_DOCUMENT_TEXT_COLOR);
}
void
BTextView::SetFontAndColor(const BFont* font, uint32 mode, const rgb_color* color)
{
SetFontAndColor(fSelStart, fSelEnd, font, mode, color);
}
@@ -2371,6 +2383,11 @@ BTextView::MakeEditable(bool editable)
return;
fEditable = editable;
// apply uneditable colors or unapply them
if (_UsesSystemColors())
AdoptSystemColors();
// TextControls change the color of the text when
// they are made editable, so we need to invalidate
// the NULL style here
@@ -6093,6 +6110,24 @@ BTextView::_TextRect()
}
float
BTextView::_UneditableTint()
{
return ui_color(B_DOCUMENT_BACKGROUND_COLOR).IsLight() ? B_DARKEN_1_TINT : 0.853;
}
bool
BTextView::_UsesSystemColors()
{
float tint = B_NO_TINT;
return ViewUIColor(&tint) == B_DOCUMENT_BACKGROUND_COLOR
&& LowUIColor(&tint) == B_DOCUMENT_BACKGROUND_COLOR
&& HighUIColor() == B_DOCUMENT_TEXT_COLOR;
}
// #pragma mark - BTextView::TextTrackState