BTextView: Fixup AdoptSystemColors() and HasSystemColors()

Replace private _UsesSystemColors() with public HasSystemColors()
and make sure to consider the tints when checking if system colors
are used or not.

Document HasSytemColors() in the Haiku Book.

Change-Id: I78de4904d5ddb24b98ad27eb93d4e5ccb330d76a
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8897
Haiku-Format: Haiku-format Bot <[email protected]>
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
John Scipione
2025-02-03 00:14:52 +00:00
committed by waddlesplash
parent 74ef92bc55
commit 16c6cc4418
3 changed files with 40 additions and 16 deletions
+22 -1
View File
@@ -1363,11 +1363,32 @@
- \c B_DOCUMENT_BACKGROUND_COLOR for LowUIColor() - \c B_DOCUMENT_BACKGROUND_COLOR for LowUIColor()
- \c B_DOCUMENT_TEXT_COLOR for HighUIColor() - \c B_DOCUMENT_TEXT_COLOR for HighUIColor()
This is reimplemented from BView which uses panel colors.
View and low colors tinted \c B_DARKEN_1_TINT (inverse on dark) if uneditable. View and low colors tinted \c B_DARKEN_1_TINT (inverse on dark) if uneditable.
Does not alter text color. Does not alter text color.
\see BView::AdoptSystemColors(), MakeEditable() \see BView::AdoptSystemColors(), MakeEditable(), HasSystemColors()
\since Haiku R1
*/
/*!
\fn bool BTextView::HasSystemColors() const
\brief Tests whether or not the text view is using system colors.
- \c B_DOCUMENT_BACKGROUND_COLOR for ViewUIColor() either untinted or \c B_DARKEN_1_TINT
- \c B_DOCUMENT_BACKGROUND_COLOR for LowUIColor() either untinted or \c B_DARKEN_1_TINT
- \c B_DOCUMENT_TEXT_COLOR for HighUIColor() untinted
Does not consider text color.
\returns \c true if using system colors either untinted or using uneditable tint
\c false otherwise.
\see AdoptSystemColors(), MakeEditable()
\since Haiku R1 \since Haiku R1
*/ */
+2 -2
View File
@@ -132,6 +132,7 @@ public:
void GetSelection(int32* _start, int32* _end) const; void GetSelection(int32* _start, int32* _end) const;
void AdoptSystemColors(); void AdoptSystemColors();
bool HasSystemColors() const;
void SetFontAndColor(const BFont* font, void SetFontAndColor(const BFont* font,
uint32 mode = B_FONT_ALL, uint32 mode = B_FONT_ALL,
@@ -428,8 +429,7 @@ private:
float _TextHeight(); float _TextHeight();
BRect _TextRect(); BRect _TextRect();
float _UneditableTint(); float _UneditableTint() const;
bool _UsesSystemColors();
private: private:
BPrivate::TextGapBuffer* fText; BPrivate::TextGapBuffer* fText;
+16 -13
View File
@@ -1601,6 +1601,20 @@ BTextView::AdoptSystemColors()
} }
bool
BTextView::HasSystemColors() const
{
float tint = B_NO_TINT;
float uneditableTint = _UneditableTint();
return ViewUIColor(&tint) == B_DOCUMENT_BACKGROUND_COLOR
&& (tint == B_NO_TINT || tint == uneditableTint)
&& LowUIColor(&tint) == B_DOCUMENT_BACKGROUND_COLOR
&& (tint == B_NO_TINT || tint == uneditableTint)
&& HighUIColor(&tint) == B_DOCUMENT_TEXT_COLOR && tint == B_NO_TINT;
}
void void
BTextView::SetFontAndColor(const BFont* font, uint32 mode, const rgb_color* color) BTextView::SetFontAndColor(const BFont* font, uint32 mode, const rgb_color* color)
{ {
@@ -2385,7 +2399,7 @@ BTextView::MakeEditable(bool editable)
fEditable = editable; fEditable = editable;
// apply uneditable colors or unapply them // apply uneditable colors or unapply them
if (_UsesSystemColors()) if (HasSystemColors())
AdoptSystemColors(); AdoptSystemColors();
// TextControls change the color of the text when // TextControls change the color of the text when
@@ -6226,23 +6240,12 @@ BTextView::_TextRect()
float float
BTextView::_UneditableTint() BTextView::_UneditableTint() const
{ {
return ui_color(B_DOCUMENT_BACKGROUND_COLOR).IsLight() ? B_DARKEN_1_TINT : 0.853; 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 // #pragma mark - BTextView::TextTrackState