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