mirror of
https://review.haiku-os.org/haiku
synced 2025-02-22 13:38:56 +01:00
Mail: change look of disabled text controls.
* Added HeaderTextControl that draws the text in black, and uses the panel background without a frame when it's disabled. Only the label is still drawn as disabled. * Changed AddressTextControl to behave in the same way. * The date view is now a HeaderTextControl, too. * Unfortunately, the label is not vertically aligned with the contents.
This commit is contained in:
parent
7bdee8beab
commit
4182c53bc4
@ -36,7 +36,6 @@
|
||||
|
||||
|
||||
static const uint32 kMsgAddAddress = 'adad';
|
||||
static const float kHorizontalTextRectInset = 4.0;
|
||||
static const float kVerticalTextRectInset = 2.0;
|
||||
|
||||
|
||||
@ -393,9 +392,9 @@ AddressTextControl::TextView::_AlignTextRect()
|
||||
textRect.left = 0.0;
|
||||
float vInset = max_c(1,
|
||||
floorf((textRect.Height() - LineHeight(0)) / 2.0 + 0.5));
|
||||
float hInset = kHorizontalTextRectInset;
|
||||
|
||||
if (be_control_look)
|
||||
float hInset = 0;
|
||||
if (be_control_look != NULL)
|
||||
hInset = be_control_look->DefaultLabelSpacing();
|
||||
|
||||
textRect.InsetBy(hInset, vInset);
|
||||
@ -692,6 +691,9 @@ AddressTextControl::WindowActivated(bool active)
|
||||
void
|
||||
AddressTextControl::Draw(BRect updateRect)
|
||||
{
|
||||
if (!IsEditable())
|
||||
return;
|
||||
|
||||
BRect bounds(Bounds());
|
||||
rgb_color base(LowColor());
|
||||
uint32 flags = 0;
|
||||
@ -724,7 +726,7 @@ AddressTextControl::SetEnabled(bool enabled)
|
||||
|
||||
fPopUpButton->SetEnabled(enabled);
|
||||
|
||||
_UpdateTextViewColors(enabled);
|
||||
_UpdateTextViewColors();
|
||||
}
|
||||
|
||||
|
||||
@ -959,13 +961,13 @@ AddressTextControl::_AddAddress(const char* text)
|
||||
|
||||
|
||||
void
|
||||
AddressTextControl::_UpdateTextViewColors(bool enabled)
|
||||
AddressTextControl::_UpdateTextViewColors()
|
||||
{
|
||||
BFont font;
|
||||
fTextView->GetFontAndColor(0, &font);
|
||||
|
||||
rgb_color textColor;
|
||||
if (enabled)
|
||||
if (!IsEditable() || IsEnabled())
|
||||
textColor = ui_color(B_DOCUMENT_TEXT_COLOR);
|
||||
else {
|
||||
textColor = tint_color(ui_color(B_PANEL_BACKGROUND_COLOR),
|
||||
@ -975,7 +977,9 @@ AddressTextControl::_UpdateTextViewColors(bool enabled)
|
||||
fTextView->SetFontAndColor(&font, B_FONT_ALL, &textColor);
|
||||
|
||||
rgb_color color;
|
||||
if (enabled)
|
||||
if (!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),
|
||||
|
@ -44,7 +44,7 @@ public:
|
||||
|
||||
private:
|
||||
void _AddAddress(const char* text);
|
||||
void _UpdateTextViewColors(bool enabled);
|
||||
void _UpdateTextViewColors();
|
||||
|
||||
private:
|
||||
class TextView;
|
||||
|
@ -104,6 +104,20 @@ private:
|
||||
};
|
||||
|
||||
|
||||
class HeaderTextControl : public BTextControl {
|
||||
public:
|
||||
HeaderTextControl(const char* label,
|
||||
const char* name, BMessage* message);
|
||||
|
||||
virtual void AttachedToWindow();
|
||||
virtual void SetEnabled(bool enabled);
|
||||
virtual void Draw(BRect updateRect);
|
||||
|
||||
private:
|
||||
void _UpdateTextViewColors();
|
||||
};
|
||||
|
||||
|
||||
// #pragma mark - LabelView
|
||||
|
||||
|
||||
@ -143,6 +157,101 @@ LabelView::Draw(BRect updateRect)
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark - HeaderTextControl
|
||||
|
||||
|
||||
HeaderTextControl::HeaderTextControl(const char* label, const char* name,
|
||||
BMessage* message)
|
||||
:
|
||||
BTextControl(label, name, message)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
HeaderTextControl::AttachedToWindow()
|
||||
{
|
||||
BTextControl::AttachedToWindow();
|
||||
_UpdateTextViewColors();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
HeaderTextControl::SetEnabled(bool enabled)
|
||||
{
|
||||
BTextControl::SetEnabled(enabled);
|
||||
_UpdateTextViewColors();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
HeaderTextControl::Draw(BRect updateRect)
|
||||
{
|
||||
bool enabled = IsEnabled();
|
||||
bool active = TextView()->IsFocus() && Window()->IsActive();
|
||||
|
||||
BRect rect = TextView()->Frame();
|
||||
rect.InsetBy(-2, -2);
|
||||
|
||||
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
|
||||
uint32 flags = 0;
|
||||
if (!enabled)
|
||||
flags = BControlLook::B_DISABLED;
|
||||
|
||||
if (enabled) {
|
||||
if (active)
|
||||
flags |= BControlLook::B_FOCUSED;
|
||||
|
||||
be_control_look->DrawTextControlBorder(this, rect, updateRect, base,
|
||||
flags);
|
||||
}
|
||||
|
||||
if (Label() != NULL) {
|
||||
rect = CreateLabelLayoutItem()->Frame().OffsetByCopy(-Frame().left,
|
||||
-Frame().top);
|
||||
|
||||
alignment labelAlignment;
|
||||
GetAlignment(&labelAlignment, NULL);
|
||||
|
||||
be_control_look->DrawLabel(this, Label(), rect, updateRect,
|
||||
base, flags, BAlignment(labelAlignment, B_ALIGN_MIDDLE));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
HeaderTextControl::_UpdateTextViewColors()
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark - THeaderView
|
||||
|
||||
|
||||
@ -152,13 +261,13 @@ THeaderView::THeaderView(bool incoming, bool resending, int32 defaultAccount)
|
||||
fAccountID(defaultAccount),
|
||||
fFromControl(NULL),
|
||||
fBccControl(NULL),
|
||||
fDateView(NULL),
|
||||
fDateControl(NULL),
|
||||
fIncoming(incoming),
|
||||
fResending(resending)
|
||||
{
|
||||
// From
|
||||
if (fIncoming) {
|
||||
fFromControl = new BTextControl(B_TRANSLATE("From:"), NULL, NULL);
|
||||
fFromControl = new HeaderTextControl(B_TRANSLATE("From:"), NULL, NULL);
|
||||
fFromControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);
|
||||
fFromControl->SetEnabled(false);
|
||||
}
|
||||
@ -251,7 +360,7 @@ THeaderView::THeaderView(bool incoming, bool resending, int32 defaultAccount)
|
||||
}
|
||||
|
||||
// Subject
|
||||
fSubjectControl = new BTextControl(B_TRANSLATE("Subject:"), NULL,
|
||||
fSubjectControl = new HeaderTextControl(B_TRANSLATE("Subject:"), NULL,
|
||||
new BMessage(SUBJECT_FIELD));
|
||||
msg = new BMessage(FIELD_CHANGED);
|
||||
msg->AddInt32("bitmask", FIELD_SUBJECT);
|
||||
@ -261,17 +370,17 @@ THeaderView::THeaderView(bool incoming, bool resending, int32 defaultAccount)
|
||||
fSubjectControl->SetEnabled(false);
|
||||
|
||||
// Date
|
||||
LabelView* dateLabel = NULL;
|
||||
if (fIncoming) {
|
||||
dateLabel = new LabelView(B_TRANSLATE("Date:"));
|
||||
dateLabel->SetEnabled(false);
|
||||
fDateView = new BStringView("", "");
|
||||
fDateView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
|
||||
fDateControl = new HeaderTextControl(B_TRANSLATE("Date:"), NULL, NULL);
|
||||
fDateControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);
|
||||
fDateControl->SetEnabled(false);
|
||||
}
|
||||
|
||||
BGridLayout* layout = GridLayout();
|
||||
|
||||
layout->SetInsets(B_USE_DEFAULT_SPACING);
|
||||
if (fIncoming)
|
||||
layout->SetHorizontalSpacing(0);
|
||||
layout->SetVerticalSpacing(B_USE_HALF_ITEM_SPACING);
|
||||
|
||||
int32 row = 0;
|
||||
@ -297,9 +406,10 @@ THeaderView::THeaderView(bool incoming, bool resending, int32 defaultAccount)
|
||||
layout->AddItem(fSubjectControl->CreateTextViewLayoutItem(), 1, row++,
|
||||
3, 1);
|
||||
|
||||
if (fDateView != NULL) {
|
||||
layout->AddView(dateLabel, 0, row);
|
||||
layout->AddView(fDateView, 1, row++, 3, 1);
|
||||
if (fDateControl != NULL) {
|
||||
layout->AddItem(fDateControl->CreateLabelLayoutItem(), 0, row);
|
||||
layout->AddItem(fDateControl->CreateTextViewLayoutItem(), 1, row++,
|
||||
3, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -426,7 +536,7 @@ THeaderView::IsDateEmpty() const
|
||||
const char*
|
||||
THeaderView::Date() const
|
||||
{
|
||||
return fDateView != NULL ? fDateView->Text() : NULL;
|
||||
return fDateControl != NULL ? fDateControl->Text() : NULL;
|
||||
}
|
||||
|
||||
|
||||
@ -435,7 +545,7 @@ THeaderView::SetDate(time_t date)
|
||||
{
|
||||
fDate = date;
|
||||
|
||||
if (fDateView != NULL) {
|
||||
if (fDateControl != NULL) {
|
||||
BDateTimeFormat formatter;
|
||||
|
||||
BString string;
|
||||
@ -449,8 +559,8 @@ THeaderView::SetDate(time_t date)
|
||||
void
|
||||
THeaderView::SetDate(const char* date)
|
||||
{
|
||||
if (fDateView != NULL)
|
||||
fDateView->SetText(date);
|
||||
if (fDateControl != NULL)
|
||||
fDateControl->SetText(date);
|
||||
}
|
||||
|
||||
|
||||
|
@ -37,7 +37,6 @@ All rights reserved.
|
||||
|
||||
#include <GridView.h>
|
||||
#include <NodeInfo.h>
|
||||
#include <TextControl.h>
|
||||
|
||||
#include "AddressTextControl.h"
|
||||
|
||||
@ -48,6 +47,7 @@ class BMenuField;
|
||||
class BMenuItem;
|
||||
class BPopUpMenu;
|
||||
class BStringView;
|
||||
class HeaderTextControl;
|
||||
class LabelView;
|
||||
|
||||
|
||||
@ -95,14 +95,14 @@ public:
|
||||
private:
|
||||
BPopUpMenu* fAccountMenu;
|
||||
int32 fAccountID;
|
||||
BTextControl* fFromControl;
|
||||
HeaderTextControl* fFromControl;
|
||||
LabelView* fToLabel;
|
||||
AddressTextControl* fToControl;
|
||||
LabelView* fCcLabel;
|
||||
AddressTextControl* fCcControl;
|
||||
AddressTextControl* fBccControl;
|
||||
BTextControl* fSubjectControl;
|
||||
BStringView* fDateView;
|
||||
HeaderTextControl* fSubjectControl;
|
||||
HeaderTextControl* fDateControl;
|
||||
time_t fDate;
|
||||
bool fIncoming;
|
||||
bool fResending;
|
||||
|
Loading…
x
Reference in New Issue
Block a user