Mail: Update text control colors automatically.
Remove SetStylable() call making it false.
Update low and high colors in _UpdateTextViewColors().
Update colors when B_COLORS_UPDATED message is received.
Change-Id: Iad3e3d9f46b922c7cf68e20cd7788d0d0efcb0b5
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10010
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: John Scipione <jscipione@gmail.com>
Diff
src/apps/mail/AddressTextControl.cpp | 42 +++++++++++++++++++++++++-----------------
src/apps/mail/AddressTextControl.h | 2 +-
src/apps/mail/Header.cpp | 58 +++++++++++++++++++++++++++++++++++++++++-----------------
3 files changed, 47 insertions(+), 55 deletions(-)
@@ -191,7 +191,6 @@
fUpdateAutoCompleterChoices(true)
{
MakeResizable(true);
SetStylable(true);
fAutoCompleter->SetModificationsReported(true);
}
@@ -643,7 +642,7 @@
BControl::AttachedToWindow();
fTextView->MakeSelectable(true);
_UpdateTextViewColors();
_UpdateTextViewColors(IsEnabled());
}
@@ -679,7 +678,7 @@
return;
fTextView->MakeEditable(enabled);
_UpdateTextViewColors();
_UpdateTextViewColors(enabled);
if (enabled && fPopUpButton->IsHidden(this))
fPopUpButton->Show();
@@ -699,6 +698,16 @@
AddressTextControl::MessageReceived(BMessage* message)
{
switch (message->what) {
case B_COLORS_UPDATED:
if ((IsEnabled()
&& (message->HasColor(ui_color_name(B_DOCUMENT_BACKGROUND_COLOR))
|| message->HasColor(ui_color_name(B_DOCUMENT_TEXT_COLOR))))
|| message->HasColor(ui_color_name(B_PANEL_BACKGROUND_COLOR))
|| message->HasColor(ui_color_name(B_PANEL_TEXT_COLOR))) {
_UpdateTextViewColors(IsEnabled());
}
break;
case B_SIMPLE_DATA:
{
int32 buttons = -1;
@@ -906,31 +915,16 @@
void
AddressTextControl::_UpdateTextViewColors()
AddressTextControl::_UpdateTextViewColors(bool enabled)
{
BFont font;
fTextView->GetFontAndColor(0, &font);
rgb_color textColor;
if (!fTextView->IsEditable() || IsEnabled())
textColor = ui_color(B_DOCUMENT_TEXT_COLOR);
else {
textColor = tint_color(ui_color(B_PANEL_BACKGROUND_COLOR),
B_DISABLED_LABEL_TINT);
}
rgb_color textColor = ui_color(enabled ? B_DOCUMENT_TEXT_COLOR : B_PANEL_TEXT_COLOR);
fTextView->SetFontAndColor(&font, B_FONT_ALL, &textColor);
rgb_color color;
if (!fTextView->IsEditable())
color = ui_color(B_PANEL_BACKGROUND_COLOR);
else if (IsEnabled())
color = ui_color(B_DOCUMENT_BACKGROUND_COLOR);
else {
color = tint_color(ui_color(B_PANEL_BACKGROUND_COLOR),
B_LIGHTEN_2_TINT);
}
fTextView->SetViewColor(color);
fTextView->SetLowColor(color);
fTextView->SetLowUIColor(enabled ? B_DOCUMENT_BACKGROUND_COLOR : B_PANEL_BACKGROUND_COLOR);
fTextView->SetViewUIColor(fTextView->LowUIColor());
}
@@ -40,7 +40,7 @@
private:
void _AddAddress(const char* text);
void _UpdateTextViewColors();
void _UpdateTextViewColors(bool enabled);
private:
class TextView;
@@ -115,7 +115,7 @@
virtual void MessageReceived(BMessage* message);
private:
void _UpdateTextViewColors();
void _UpdateTextViewColors(bool enabled);
};
@@ -180,16 +180,21 @@
{
BTextControl::AttachedToWindow();
_UpdateTextViewColors();
TextView()->MakeSelectable(true);
_UpdateTextViewColors(IsEnabled());
}
void
HeaderTextControl::SetEnabled(bool enabled)
{
if (enabled == IsEnabled())
return;
TextView()->MakeEditable(enabled);
_UpdateTextViewColors(enabled);
BTextControl::SetEnabled(enabled);
_UpdateTextViewColors();
}
@@ -232,6 +237,16 @@
HeaderTextControl::MessageReceived(BMessage* message)
{
switch (message->what) {
case B_COLORS_UPDATED:
if ((IsEnabled()
&& (message->HasColor(ui_color_name(B_DOCUMENT_BACKGROUND_COLOR))
|| message->HasColor(ui_color_name(B_DOCUMENT_TEXT_COLOR))))
|| message->HasColor(ui_color_name(B_PANEL_BACKGROUND_COLOR))
|| message->HasColor(ui_color_name(B_PANEL_TEXT_COLOR))) {
_UpdateTextViewColors(IsEnabled());
}
break;
case M_SELECT:
{
BTextView* textView = TextView();
@@ -248,35 +263,18 @@
void
HeaderTextControl::_UpdateTextViewColors()
HeaderTextControl::_UpdateTextViewColors(bool enabled)
{
BTextView* textView = TextView();
BFont font;
textView->GetFontAndColor(0, &font);
rgb_color textColor;
if (!textView->IsEditable() || IsEnabled())
textColor = ui_color(B_DOCUMENT_TEXT_COLOR);
else {
textColor = tint_color(ui_color(B_PANEL_BACKGROUND_COLOR),
B_DISABLED_LABEL_TINT);
}
textView->SetFontAndColor(&font, B_FONT_ALL, &textColor);
rgb_color color;
if (!textView->IsEditable())
color = ui_color(B_PANEL_BACKGROUND_COLOR);
else if (IsEnabled())
color = ui_color(B_DOCUMENT_BACKGROUND_COLOR);
else {
color = tint_color(ui_color(B_PANEL_BACKGROUND_COLOR),
B_LIGHTEN_2_TINT);
}
textView->SetViewColor(color);
textView->SetLowColor(color);
TextView()->GetFontAndColor(0, &font);
rgb_color textColor = ui_color(enabled ? B_DOCUMENT_TEXT_COLOR : B_PANEL_TEXT_COLOR);
TextView()->SetFontAndColor(&font, B_FONT_ALL, &textColor);
TextView()->SetLowUIColor(enabled ? B_DOCUMENT_BACKGROUND_COLOR : B_PANEL_BACKGROUND_COLOR);
TextView()->SetViewUIColor(TextView()->LowUIColor());
}