Mail: Make read-only/disabled fields navigable and selectable
Always MakeSelectable(), MakeEditable() in SetEnabled(). Get rid of fEditable and fWindowActive. Get rid of IsEditable(), SetEditable(), IsSelectable and SetSelectable(). Change-Id: Iab07097b2692ef6d9d7ed41b0fab45a2df99e261 Reviewed-on: https://review.haiku-os.org/c/haiku/+/10009 Reviewed-by: John Scipione <[email protected]> Tested-by: Commit checker robot <[email protected]>
This commit is contained in:
committed by
waddlesplash
parent
adce07dae3
commit
eb506aedcd
@@ -610,12 +610,11 @@ AddressTextControl::PopUpMenu::_AddPersonItem(const entry_ref *ref, ino_t node,
|
||||
AddressTextControl::AddressTextControl(const char* name, BMessage* message)
|
||||
:
|
||||
BControl(name, NULL, message, B_WILL_DRAW),
|
||||
fRefDropMenu(NULL),
|
||||
fWindowActive(false),
|
||||
fEditable(true)
|
||||
fRefDropMenu(NULL)
|
||||
{
|
||||
fTextView = new TextView(this);
|
||||
fTextView->SetExplicitMinSize(BSize(100, B_SIZE_UNSET));
|
||||
fTextView->SetFlags(B_WILL_DRAW | B_NAVIGABLE);
|
||||
|
||||
fPopUpButton = new PopUpButton();
|
||||
|
||||
@@ -630,9 +629,6 @@ AddressTextControl::AddressTextControl(const char* name, BMessage* message)
|
||||
|
||||
SetExplicitAlignment(BAlignment(B_ALIGN_USE_FULL_WIDTH,
|
||||
B_ALIGN_VERTICAL_CENTER));
|
||||
|
||||
SetEnabled(fEditable);
|
||||
// Sets the B_NAVIGABLE flag on the TextView
|
||||
}
|
||||
|
||||
|
||||
@@ -645,34 +641,23 @@ void
|
||||
AddressTextControl::AttachedToWindow()
|
||||
{
|
||||
BControl::AttachedToWindow();
|
||||
fWindowActive = Window()->IsActive();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AddressTextControl::WindowActivated(bool active)
|
||||
{
|
||||
BControl::WindowActivated(active);
|
||||
if (fWindowActive != active) {
|
||||
fWindowActive = active;
|
||||
Invalidate();
|
||||
}
|
||||
fTextView->MakeSelectable(true);
|
||||
_UpdateTextViewColors();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AddressTextControl::Draw(BRect updateRect)
|
||||
{
|
||||
if (!IsEditable())
|
||||
if (!IsEnabled())
|
||||
return;
|
||||
|
||||
BRect rect = Bounds();
|
||||
rgb_color base = LowColor();
|
||||
|
||||
uint32 flags = 0;
|
||||
if (!IsEnabled())
|
||||
flags |= BControlLook::B_DISABLED;
|
||||
if (fWindowActive && fTextView->IsFocus())
|
||||
if (Window()->IsActive() && fTextView->IsFocus())
|
||||
flags |= BControlLook::B_FOCUSED;
|
||||
|
||||
be_control_look->DrawTextControlBorder(this, rect, updateRect, base, flags);
|
||||
@@ -690,16 +675,23 @@ AddressTextControl::MakeFocus(bool focus)
|
||||
void
|
||||
AddressTextControl::SetEnabled(bool enabled)
|
||||
{
|
||||
BControl::SetEnabled(enabled);
|
||||
fTextView->MakeEditable(enabled && fEditable);
|
||||
if (enabled)
|
||||
fTextView->SetFlags(fTextView->Flags() | B_NAVIGABLE);
|
||||
else
|
||||
fTextView->SetFlags(fTextView->Flags() & ~B_NAVIGABLE);
|
||||
if (enabled == IsEnabled())
|
||||
return;
|
||||
|
||||
fTextView->MakeEditable(enabled);
|
||||
_UpdateTextViewColors();
|
||||
|
||||
if (enabled && fPopUpButton->IsHidden(this))
|
||||
fPopUpButton->Show();
|
||||
else if (!enabled && !fPopUpButton->IsHidden(this))
|
||||
fPopUpButton->Hide();
|
||||
|
||||
fPopUpButton->SetEnabled(enabled);
|
||||
|
||||
_UpdateTextViewColors();
|
||||
BControl::SetEnabled(enabled);
|
||||
|
||||
// override BControl and always set B_NAVIGABLE
|
||||
SetFlags(Flags() | B_NAVIGABLE);
|
||||
}
|
||||
|
||||
|
||||
@@ -847,27 +839,6 @@ AddressTextControl::SetModificationMessage(BMessage* message)
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
AddressTextControl::IsEditable() const
|
||||
{
|
||||
return fEditable;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AddressTextControl::SetEditable(bool editable)
|
||||
{
|
||||
fTextView->MakeEditable(IsEnabled() && editable);
|
||||
fTextView->MakeSelectable(IsEnabled() && editable);
|
||||
fEditable = editable;
|
||||
|
||||
if (editable && fPopUpButton->IsHidden(this))
|
||||
fPopUpButton->Show();
|
||||
else if (!editable && !fPopUpButton->IsHidden(this))
|
||||
fPopUpButton->Hide();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AddressTextControl::SetText(const char* text)
|
||||
{
|
||||
@@ -941,7 +912,7 @@ AddressTextControl::_UpdateTextViewColors()
|
||||
fTextView->GetFontAndColor(0, &font);
|
||||
|
||||
rgb_color textColor;
|
||||
if (!IsEditable() || IsEnabled())
|
||||
if (!fTextView->IsEditable() || IsEnabled())
|
||||
textColor = ui_color(B_DOCUMENT_TEXT_COLOR);
|
||||
else {
|
||||
textColor = tint_color(ui_color(B_PANEL_BACKGROUND_COLOR),
|
||||
@@ -951,7 +922,7 @@ AddressTextControl::_UpdateTextViewColors()
|
||||
fTextView->SetFontAndColor(&font, B_FONT_ALL, &textColor);
|
||||
|
||||
rgb_color color;
|
||||
if (!IsEditable())
|
||||
if (!fTextView->IsEditable())
|
||||
color = ui_color(B_PANEL_BACKGROUND_COLOR);
|
||||
else if (IsEnabled())
|
||||
color = ui_color(B_DOCUMENT_BACKGROUND_COLOR);
|
||||
|
||||
@@ -21,7 +21,6 @@ public:
|
||||
virtual ~AddressTextControl();
|
||||
|
||||
virtual void AttachedToWindow();
|
||||
virtual void WindowActivated(bool active);
|
||||
virtual void Draw(BRect updateRect);
|
||||
virtual void MakeFocus(bool focus = true);
|
||||
virtual void SetEnabled(bool enabled);
|
||||
@@ -30,9 +29,6 @@ public:
|
||||
const BMessage* ModificationMessage() const;
|
||||
void SetModificationMessage(BMessage* message);
|
||||
|
||||
bool IsEditable() const;
|
||||
void SetEditable(bool editable);
|
||||
|
||||
void SetText(const char* text);
|
||||
const char* Text() const;
|
||||
int32 TextLength() const;
|
||||
@@ -53,8 +49,6 @@ private:
|
||||
TextView* fTextView;
|
||||
PopUpButton* fPopUpButton;
|
||||
BPopUpMenu* fRefDropMenu;
|
||||
bool fWindowActive;
|
||||
bool fEditable;
|
||||
};
|
||||
|
||||
|
||||
|
||||
+38
-47
@@ -171,6 +171,7 @@ HeaderTextControl::HeaderTextControl(const char* label, const char* name, BMessa
|
||||
:
|
||||
BTextControl(label, name, message)
|
||||
{
|
||||
TextView()->SetFlags(B_WILL_DRAW | B_NAVIGABLE);
|
||||
}
|
||||
|
||||
|
||||
@@ -180,6 +181,7 @@ HeaderTextControl::AttachedToWindow()
|
||||
BTextControl::AttachedToWindow();
|
||||
|
||||
_UpdateTextViewColors();
|
||||
TextView()->MakeSelectable(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -194,38 +196,35 @@ HeaderTextControl::SetEnabled(bool enabled)
|
||||
void
|
||||
HeaderTextControl::Draw(BRect updateRect)
|
||||
{
|
||||
bool enabled = IsEnabled();
|
||||
bool active = TextView()->IsFocus() && Window()->IsActive();
|
||||
|
||||
BRect rect = TextView()->Frame();
|
||||
rect.InsetBy(-2, -2);
|
||||
|
||||
uint32 flags = 0;
|
||||
if (!IsEnabled())
|
||||
flags |= BControlLook::B_DISABLED;
|
||||
else if (TextView()->IsFocus() && Window()->IsActive())
|
||||
flags |= BControlLook::B_FOCUSED;
|
||||
|
||||
if (IsEnabled()) {
|
||||
rgb_color base = ViewColor();
|
||||
be_control_look->DrawTextControlBorder(this, rect, updateRect, base, flags);
|
||||
}
|
||||
|
||||
if (Label() == NULL)
|
||||
return;
|
||||
|
||||
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
|
||||
rgb_color text = ui_color(B_PANEL_TEXT_COLOR);
|
||||
uint32 flags = 0;
|
||||
if (!enabled)
|
||||
flags = BControlLook::B_DISABLED;
|
||||
|
||||
if (enabled) {
|
||||
if (active)
|
||||
flags |= BControlLook::B_FOCUSED;
|
||||
rect = CreateLabelLayoutItem()->Frame().OffsetByCopy(-Frame().left, -Frame().top);
|
||||
// TODO: solve this better (alignment of label and text)
|
||||
rect.InsetBy(1, 1);
|
||||
|
||||
be_control_look->DrawTextControlBorder(this, rect, updateRect, base,
|
||||
flags);
|
||||
}
|
||||
alignment labelAlignment;
|
||||
GetAlignment(&labelAlignment, NULL);
|
||||
|
||||
if (Label() != NULL) {
|
||||
rect = CreateLabelLayoutItem()->Frame().OffsetByCopy(-Frame().left,
|
||||
-Frame().top);
|
||||
// TODO: solve this better (alignment of label and text)
|
||||
rect.top++;
|
||||
|
||||
alignment labelAlignment;
|
||||
GetAlignment(&labelAlignment, NULL);
|
||||
|
||||
be_control_look->DrawLabel(this, Label(), rect, updateRect,
|
||||
base, flags, BAlignment(labelAlignment, B_ALIGN_MIDDLE), &text);
|
||||
}
|
||||
be_control_look->DrawLabel(this, Label(), rect, updateRect,
|
||||
base, flags, BAlignment(labelAlignment, B_ALIGN_MIDDLE), &text);
|
||||
}
|
||||
|
||||
|
||||
@@ -355,13 +354,9 @@ THeaderView::THeaderView(bool incoming, bool resending, int32 defaultAccount)
|
||||
|
||||
// To
|
||||
fToLabel = new LabelView(B_TRANSLATE("To:"));
|
||||
fToControl = new AddressTextControl(B_TRANSLATE("To:"),
|
||||
new BMessage(TO_FIELD));
|
||||
if (fIncoming || fResending) {
|
||||
fToLabel->SetEnabled(false);
|
||||
fToControl->SetEditable(false);
|
||||
fToControl->SetEnabled(false);
|
||||
}
|
||||
fToControl = new AddressTextControl("to", new BMessage(TO_FIELD));
|
||||
fToLabel->SetEnabled(!(fIncoming || fResending));
|
||||
fToControl->SetEnabled(!(fIncoming || fResending));
|
||||
|
||||
BMessage* msg = new BMessage(FIELD_CHANGED);
|
||||
msg->AddInt32("bitmask", FIELD_TO);
|
||||
@@ -370,10 +365,9 @@ THeaderView::THeaderView(bool incoming, bool resending, int32 defaultAccount)
|
||||
// Carbon copy
|
||||
fCcLabel = new LabelView(B_TRANSLATE("Cc:"));
|
||||
fCcControl = new AddressTextControl("cc", new BMessage(CC_FIELD));
|
||||
fCcLabel->SetEnabled(!fIncoming);
|
||||
fCcControl->SetEnabled(!fIncoming);
|
||||
if (fIncoming) {
|
||||
fCcLabel->SetEnabled(false);
|
||||
fCcControl->SetEditable(false);
|
||||
fCcControl->SetEnabled(false);
|
||||
fCcControl->Hide();
|
||||
fCcLabel->Hide();
|
||||
}
|
||||
@@ -388,6 +382,7 @@ THeaderView::THeaderView(bool incoming, bool resending, int32 defaultAccount)
|
||||
msg = new BMessage(FIELD_CHANGED);
|
||||
msg->AddInt32("bitmask", FIELD_BCC);
|
||||
fBccControl->SetModificationMessage(msg);
|
||||
fBccControl->SetEnabled(true);
|
||||
}
|
||||
|
||||
// Subject
|
||||
@@ -397,8 +392,7 @@ THeaderView::THeaderView(bool incoming, bool resending, int32 defaultAccount)
|
||||
msg->AddInt32("bitmask", FIELD_SUBJECT);
|
||||
fSubjectControl->SetModificationMessage(msg);
|
||||
fSubjectControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);
|
||||
if (fIncoming || fResending)
|
||||
fSubjectControl->SetEnabled(false);
|
||||
fSubjectControl->SetEnabled(!fIncoming);
|
||||
|
||||
// Date
|
||||
if (fIncoming) {
|
||||
@@ -438,7 +432,7 @@ THeaderView::THeaderView(bool incoming, bool resending, int32 defaultAccount)
|
||||
layout->AddItem(fDateControl->CreateTextViewLayoutItem(), 1, row);
|
||||
}
|
||||
|
||||
if (fIncoming && (fCcControl != NULL)) {
|
||||
if (fIncoming) {
|
||||
layout->AddView(fCcLabel, 2, row);
|
||||
layout->AddView(fCcControl, 3, row++);
|
||||
} else {
|
||||
@@ -504,7 +498,7 @@ THeaderView::IsCcEmpty() const
|
||||
const char*
|
||||
THeaderView::Cc() const
|
||||
{
|
||||
return fCcControl != NULL ? fCcControl->Text() : NULL;
|
||||
return fCcControl->Text();
|
||||
}
|
||||
|
||||
|
||||
@@ -514,12 +508,10 @@ THeaderView::SetCc(const char* cc)
|
||||
fCcControl->SetText(cc);
|
||||
|
||||
if (fIncoming) {
|
||||
if (cc != NULL && cc[0] != '\0') {
|
||||
if (fCcControl->IsHidden(this)) {
|
||||
fCcControl->Show();
|
||||
fCcLabel->Show();
|
||||
}
|
||||
} else if (!fCcControl->IsHidden(this)) {
|
||||
if (fCcControl->IsHidden(this)) {
|
||||
fCcControl->Show();
|
||||
fCcLabel->Show();
|
||||
} else {
|
||||
fCcControl->Hide();
|
||||
fCcLabel->Hide();
|
||||
}
|
||||
@@ -694,9 +686,8 @@ THeaderView::MessageReceived(BMessage* msg)
|
||||
case B_SIMPLE_DATA:
|
||||
{
|
||||
BTextView* textView = dynamic_cast<BTextView*>(Window()->CurrentFocus());
|
||||
if (dynamic_cast<AddressTextControl *>(textView->Parent()) != NULL)
|
||||
BMessage message(*msg);
|
||||
textView->Parent()->MessageReceived(msg);
|
||||
if (dynamic_cast<AddressTextControl*>(textView->Parent()) != NULL)
|
||||
Window()->PostMessage(msg, textView->Parent());
|
||||
break;
|
||||
}
|
||||
case B_REFS_RECEIVED:
|
||||
|
||||
Reference in New Issue
Block a user