From f9f970d98c9d5c3dfb544bdedf0561f83f76f1e8 Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Wed, 11 Jan 2006 09:31:27 +0000 Subject: [PATCH] Yesterday's commit triggered some other visual bugs: hopefully fixed them all. A disabled menufield now doesn't open its associated menu anymore. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15906 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/interface/BMCPrivate.h | 1 + src/kits/interface/BMCPrivate.cpp | 161 +++++++++++++++---------- src/kits/interface/MenuField.cpp | 9 +- 3 files changed, 103 insertions(+), 68 deletions(-) diff --git a/headers/private/interface/BMCPrivate.h b/headers/private/interface/BMCPrivate.h index d804c4407c..df60e7a3c7 100644 --- a/headers/private/interface/BMCPrivate.h +++ b/headers/private/interface/BMCPrivate.h @@ -97,6 +97,7 @@ virtual void Draw(BRect updateRect); virtual void FrameResized(float width, float height); virtual void MessageReceived(BMessage* msg); virtual void MakeFocus(bool focused = true); +virtual void MouseDown(BPoint where); private: _BMCMenuBar_&operator=(const _BMCMenuBar_ &); diff --git a/src/kits/interface/BMCPrivate.cpp b/src/kits/interface/BMCPrivate.cpp index 93d87e15ff..491f0ce33e 100644 --- a/src/kits/interface/BMCPrivate.cpp +++ b/src/kits/interface/BMCPrivate.cpp @@ -24,9 +24,6 @@ // Description: The BMCPrivate classes are used by BMenuField. //------------------------------------------------------------------------------ -// Standard Includes ----------------------------------------------------------- - -// System Includes ------------------------------------------------------------- #include #include #include @@ -34,45 +31,48 @@ #include #include -// Project Includes ------------------------------------------------------------ -// Local Includes -------------------------------------------------------------- - -// Local Defines --------------------------------------------------------------- - -// Globals --------------------------------------------------------------------- - -//------------------------------------------------------------------------------ _BMCItem_::_BMCItem_(BMenu *menu) : BMenuItem(menu), fShowPopUpMarker(true) { } -//------------------------------------------------------------------------------ + + _BMCItem_::_BMCItem_(BMessage *message) : BMenuItem(message), fShowPopUpMarker(true) { } -//------------------------------------------------------------------------------ + + _BMCItem_::~_BMCItem_() { } -//------------------------------------------------------------------------------ -BArchivable *_BMCItem_::Instantiate(BMessage *data) + + +BArchivable * +_BMCItem_::Instantiate(BMessage *data) { if (validate_instantiation(data, "_BMCItem_")) return new _BMCItem_(data); else return NULL; } -//------------------------------------------------------------------------------ -void _BMCItem_::Draw() + + +void +_BMCItem_::Draw() { BMenu *menu = Menu(); // Copy / pasted from BMenuItem::Draw(). We can't use it directly // because we want to skip the Submenu symbol and the rest + if (IsEnabled()) + menu->SetHighColor(ui_color(B_MENU_ITEM_TEXT_COLOR)); + else + menu->SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), + B_DISABLED_LABEL_TINT)); menu->MovePenTo(ContentLocation()); DrawContent(); @@ -99,29 +99,39 @@ void _BMCItem_::Draw() menu->StrokeLine(BPoint(rect.left + 2.0f, rect.bottom), BPoint(rect.left + 2.0f, rect.bottom)); } -//------------------------------------------------------------------------------ -void _BMCItem_::GetContentSize(float *width, float *height) + + +void +_BMCItem_::GetContentSize(float *width, float *height) { BMenuItem::GetContentSize(width, height); } -//------------------------------------------------------------------------------ -/*_BMCFilter_::_BMCFilter_(BMenuField *menuField, uint32) + + +/* +_BMCFilter_::_BMCFilter_(BMenuField *menuField, uint32) { } -//------------------------------------------------------------------------------ + + _BMCFilter_::~_BMCFilter_() { } -//------------------------------------------------------------------------------ -filter_result _BMCFilter_::Filter(BMessage *message, BHandler **handler) + + +filter_result +_BMCFilter_::Filter(BMessage *message, BHandler **handler) { } -//------------------------------------------------------------------------------ -_BMCFilter_ &_BMCFilter_::operator=(const _BMCFilter_ &) + + +_BMCFilter_ & +_BMCFilter_::operator=(const _BMCFilter_ &) { return *this; }*/ -//------------------------------------------------------------------------------ + + _BMCMenuBar_::_BMCMenuBar_(BRect frame, bool fixed_size, BMenuField *menuField) : BMenuBar(frame, "_mc_mb_", B_FOLLOW_LEFT | B_FOLLOW_TOP, B_ITEMS_IN_COLUMN, !fixed_size) @@ -129,7 +139,6 @@ _BMCMenuBar_::_BMCMenuBar_(BRect frame, bool fixed_size, BMenuField *menuField) SetFlags(Flags() | B_FRAME_EVENTS); SetBorder(B_BORDER_CONTENTS); - fMenuField = menuField; fFixedSize = fixed_size; fRunner = NULL; @@ -141,7 +150,8 @@ _BMCMenuBar_::_BMCMenuBar_(BRect frame, bool fixed_size, BMenuField *menuField) SetMaxContentWidth(frame.Width() - (left + right)); } -//------------------------------------------------------------------------------ + + _BMCMenuBar_::_BMCMenuBar_(BMessage *data) : BMenuBar(data) { @@ -154,20 +164,25 @@ _BMCMenuBar_::_BMCMenuBar_(BMessage *data) else fFixedSize = true; } -//------------------------------------------------------------------------------ + + _BMCMenuBar_::~_BMCMenuBar_() { } -//------------------------------------------------------------------------------ -BArchivable *_BMCMenuBar_::Instantiate(BMessage *data) + + +BArchivable * +_BMCMenuBar_::Instantiate(BMessage *data) { if (validate_instantiation(data, "_BMCMenuBar_")) return new _BMCMenuBar_(data); else return NULL; } -//------------------------------------------------------------------------------ -void _BMCMenuBar_::AttachedToWindow() + + +void +_BMCMenuBar_::AttachedToWindow() { fMenuField = (BMenuField*)Parent(); @@ -175,8 +190,10 @@ void _BMCMenuBar_::AttachedToWindow() BMenuBar::AttachedToWindow(); Window()->SetKeyMenuBar(menuBar); } -//------------------------------------------------------------------------------ -void _BMCMenuBar_::Draw(BRect updateRect) + + +void +_BMCMenuBar_::Draw(BRect updateRect) { // draw the right and bottom line here in a darker tint BRect bounds(Bounds()); @@ -204,8 +221,10 @@ void _BMCMenuBar_::Draw(BRect updateRect) StrokeLine(BPoint(bounds.right - 1, bounds.bottom - 1), BPoint(bounds.right - 1, bounds.top + 1)); } -//------------------------------------------------------------------------------ -void _BMCMenuBar_::FrameResized(float width, float height) + + +void +_BMCMenuBar_::FrameResized(float width, float height) { // we need to take care of resizing and cleaning up // the parent menu field @@ -236,44 +255,48 @@ void _BMCMenuBar_::FrameResized(float width, float height) } BMenuBar::FrameResized(width, height); } -//------------------------------------------------------------------------------ -void _BMCMenuBar_::MessageReceived(BMessage *msg) + + +void +_BMCMenuBar_::MessageReceived(BMessage *msg) { - if (msg->what == 'TICK') - { - BMenuItem *item = ItemAt(0); - - if (item && item->Submenu() && item->Submenu()->Window()) + switch (msg->what) { + case 'TICK': { - BMessage message(B_KEY_DOWN); + BMenuItem *item = ItemAt(0); - message.AddInt8("byte", B_ESCAPE); - message.AddInt8("key", B_ESCAPE); - message.AddInt32("modifiers", 0); - message.AddInt8("raw_char", B_ESCAPE); - - Window()->PostMessage(&message, this, NULL); + if (item && item->Submenu() && item->Submenu()->Window()) { + BMessage message(B_KEY_DOWN); + + message.AddInt8("byte", B_ESCAPE); + message.AddInt8("key", B_ESCAPE); + message.AddInt32("modifiers", 0); + message.AddInt8("raw_char", B_ESCAPE); + + Window()->PostMessage(&message, this, NULL); + } } + // fall through + default: + BMenuBar::MessageReceived(msg); + break; } - - BMenuBar::MessageReceived(msg); } -//------------------------------------------------------------------------------ -void _BMCMenuBar_::MakeFocus(bool focused) + + +void +_BMCMenuBar_::MakeFocus(bool focused) { if (IsFocus() == focused) return; BMenuBar::MakeFocus(focused); - if (focused) - { + if (focused) { BMessage message('TICK'); //fRunner = new BMessageRunner(BMessenger(this, NULL, NULL), &message, // 50000, -1); - } - else if (fRunner) - { + } else if (fRunner) { //delete fRunner; fRunner = NULL; } @@ -289,9 +312,19 @@ void _BMCMenuBar_::MakeFocus(bool focused) fMenuField->Invalidate(BRect(bounds.left, bounds.top, fMenuField->fDivider, bounds.bottom)); } -//------------------------------------------------------------------------------ -_BMCMenuBar_ &_BMCMenuBar_::operator=(const _BMCMenuBar_ &) + + +void +_BMCMenuBar_::MouseDown(BPoint where) +{ + // Don't show the associated menu if it's disabled + if (fMenuField->IsEnabled() && SubmenuAt(0)->IsEnabled()) + BMenuBar::MouseDown(where); +} + + +_BMCMenuBar_ +&_BMCMenuBar_::operator=(const _BMCMenuBar_ &) { return *this; } -//------------------------------------------------------------------------------ diff --git a/src/kits/interface/MenuField.cpp b/src/kits/interface/MenuField.cpp index 535caad2f4..54ce97e40a 100644 --- a/src/kits/interface/MenuField.cpp +++ b/src/kits/interface/MenuField.cpp @@ -6,8 +6,6 @@ * Marc Flerackers (mflerackers@androme.be) */ - -#include #include #include @@ -36,7 +34,7 @@ BMenuField::BMenuField(BRect frame, const char *name, const char *label, false, this); AddChild(fMenuBar); - fMenuBar->AddItem(menu); + fMenuBar->AddItem(new _BMCItem_(menu)); fMenuBar->SetFont(be_plain_font); @@ -223,7 +221,7 @@ BMenuField::AllAttached() void BMenuField::MouseDown(BPoint where) { - if (where.x > fDivider && !fMenuBar->Frame().Contains(where)) + if (!IsEnabled() || (where.x > fDivider && !fMenuBar->Frame().Contains(where))) return; BRect bounds = fMenuBar->ConvertFromParent(Bounds()); @@ -245,6 +243,9 @@ BMenuField::KeyDown(const char *bytes, int32 numBytes) case B_RIGHT_ARROW: case B_DOWN_ARROW: { + if (!IsEnabled()) + break; + BRect bounds = fMenuBar->ConvertFromParent(Bounds()); fMenuBar->StartMenuBar(0, true, true, &bounds);