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
This commit is contained in:
Stefano Ceccherini
2006-01-11 09:31:27 +00:00
parent 0838a93037
commit f9f970d98c
3 changed files with 103 additions and 68 deletions
+1
View File
@@ -97,6 +97,7 @@ virtual void Draw(BRect updateRect);
virtual void FrameResized(float width, float height); virtual void FrameResized(float width, float height);
virtual void MessageReceived(BMessage* msg); virtual void MessageReceived(BMessage* msg);
virtual void MakeFocus(bool focused = true); virtual void MakeFocus(bool focused = true);
virtual void MouseDown(BPoint where);
private: private:
_BMCMenuBar_&operator=(const _BMCMenuBar_ &); _BMCMenuBar_&operator=(const _BMCMenuBar_ &);
+96 -63
View File
@@ -24,9 +24,6 @@
// Description: The BMCPrivate classes are used by BMenuField. // Description: The BMCPrivate classes are used by BMenuField.
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Standard Includes -----------------------------------------------------------
// System Includes -------------------------------------------------------------
#include <BMCPrivate.h> #include <BMCPrivate.h>
#include <MenuField.h> #include <MenuField.h>
#include <MenuItem.h> #include <MenuItem.h>
@@ -34,45 +31,48 @@
#include <Region.h> #include <Region.h>
#include <Window.h> #include <Window.h>
// Project Includes ------------------------------------------------------------
// Local Includes --------------------------------------------------------------
// Local Defines ---------------------------------------------------------------
// Globals ---------------------------------------------------------------------
//------------------------------------------------------------------------------
_BMCItem_::_BMCItem_(BMenu *menu) _BMCItem_::_BMCItem_(BMenu *menu)
: BMenuItem(menu), : BMenuItem(menu),
fShowPopUpMarker(true) fShowPopUpMarker(true)
{ {
} }
//------------------------------------------------------------------------------
_BMCItem_::_BMCItem_(BMessage *message) _BMCItem_::_BMCItem_(BMessage *message)
: BMenuItem(message), : BMenuItem(message),
fShowPopUpMarker(true) fShowPopUpMarker(true)
{ {
} }
//------------------------------------------------------------------------------
_BMCItem_::~_BMCItem_() _BMCItem_::~_BMCItem_()
{ {
} }
//------------------------------------------------------------------------------
BArchivable *_BMCItem_::Instantiate(BMessage *data)
BArchivable *
_BMCItem_::Instantiate(BMessage *data)
{ {
if (validate_instantiation(data, "_BMCItem_")) if (validate_instantiation(data, "_BMCItem_"))
return new _BMCItem_(data); return new _BMCItem_(data);
else else
return NULL; return NULL;
} }
//------------------------------------------------------------------------------
void _BMCItem_::Draw()
void
_BMCItem_::Draw()
{ {
BMenu *menu = Menu(); BMenu *menu = Menu();
// Copy / pasted from BMenuItem::Draw(). We can't use it directly // Copy / pasted from BMenuItem::Draw(). We can't use it directly
// because we want to skip the Submenu symbol and the rest // 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()); menu->MovePenTo(ContentLocation());
DrawContent(); DrawContent();
@@ -99,29 +99,39 @@ void _BMCItem_::Draw()
menu->StrokeLine(BPoint(rect.left + 2.0f, rect.bottom), menu->StrokeLine(BPoint(rect.left + 2.0f, rect.bottom),
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); BMenuItem::GetContentSize(width, height);
} }
//------------------------------------------------------------------------------
/*_BMCFilter_::_BMCFilter_(BMenuField *menuField, uint32)
/*
_BMCFilter_::_BMCFilter_(BMenuField *menuField, uint32)
{ {
} }
//------------------------------------------------------------------------------
_BMCFilter_::~_BMCFilter_() _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; return *this;
}*/ }*/
//------------------------------------------------------------------------------
_BMCMenuBar_::_BMCMenuBar_(BRect frame, bool fixed_size, BMenuField *menuField) _BMCMenuBar_::_BMCMenuBar_(BRect frame, bool fixed_size, BMenuField *menuField)
: BMenuBar(frame, "_mc_mb_", B_FOLLOW_LEFT | B_FOLLOW_TOP, B_ITEMS_IN_COLUMN, : BMenuBar(frame, "_mc_mb_", B_FOLLOW_LEFT | B_FOLLOW_TOP, B_ITEMS_IN_COLUMN,
!fixed_size) !fixed_size)
@@ -129,7 +139,6 @@ _BMCMenuBar_::_BMCMenuBar_(BRect frame, bool fixed_size, BMenuField *menuField)
SetFlags(Flags() | B_FRAME_EVENTS); SetFlags(Flags() | B_FRAME_EVENTS);
SetBorder(B_BORDER_CONTENTS); SetBorder(B_BORDER_CONTENTS);
fMenuField = menuField; fMenuField = menuField;
fFixedSize = fixed_size; fFixedSize = fixed_size;
fRunner = NULL; fRunner = NULL;
@@ -141,7 +150,8 @@ _BMCMenuBar_::_BMCMenuBar_(BRect frame, bool fixed_size, BMenuField *menuField)
SetMaxContentWidth(frame.Width() - (left + right)); SetMaxContentWidth(frame.Width() - (left + right));
} }
//------------------------------------------------------------------------------
_BMCMenuBar_::_BMCMenuBar_(BMessage *data) _BMCMenuBar_::_BMCMenuBar_(BMessage *data)
: BMenuBar(data) : BMenuBar(data)
{ {
@@ -154,20 +164,25 @@ _BMCMenuBar_::_BMCMenuBar_(BMessage *data)
else else
fFixedSize = true; fFixedSize = true;
} }
//------------------------------------------------------------------------------
_BMCMenuBar_::~_BMCMenuBar_() _BMCMenuBar_::~_BMCMenuBar_()
{ {
} }
//------------------------------------------------------------------------------
BArchivable *_BMCMenuBar_::Instantiate(BMessage *data)
BArchivable *
_BMCMenuBar_::Instantiate(BMessage *data)
{ {
if (validate_instantiation(data, "_BMCMenuBar_")) if (validate_instantiation(data, "_BMCMenuBar_"))
return new _BMCMenuBar_(data); return new _BMCMenuBar_(data);
else else
return NULL; return NULL;
} }
//------------------------------------------------------------------------------
void _BMCMenuBar_::AttachedToWindow()
void
_BMCMenuBar_::AttachedToWindow()
{ {
fMenuField = (BMenuField*)Parent(); fMenuField = (BMenuField*)Parent();
@@ -175,8 +190,10 @@ void _BMCMenuBar_::AttachedToWindow()
BMenuBar::AttachedToWindow(); BMenuBar::AttachedToWindow();
Window()->SetKeyMenuBar(menuBar); Window()->SetKeyMenuBar(menuBar);
} }
//------------------------------------------------------------------------------
void _BMCMenuBar_::Draw(BRect updateRect)
void
_BMCMenuBar_::Draw(BRect updateRect)
{ {
// draw the right and bottom line here in a darker tint // draw the right and bottom line here in a darker tint
BRect bounds(Bounds()); BRect bounds(Bounds());
@@ -204,8 +221,10 @@ void _BMCMenuBar_::Draw(BRect updateRect)
StrokeLine(BPoint(bounds.right - 1, bounds.bottom - 1), StrokeLine(BPoint(bounds.right - 1, bounds.bottom - 1),
BPoint(bounds.right - 1, bounds.top + 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 // we need to take care of resizing and cleaning up
// the parent menu field // the parent menu field
@@ -236,44 +255,48 @@ void _BMCMenuBar_::FrameResized(float width, float height)
} }
BMenuBar::FrameResized(width, height); BMenuBar::FrameResized(width, height);
} }
//------------------------------------------------------------------------------
void _BMCMenuBar_::MessageReceived(BMessage *msg)
void
_BMCMenuBar_::MessageReceived(BMessage *msg)
{ {
if (msg->what == 'TICK') switch (msg->what) {
{ case 'TICK':
BMenuItem *item = ItemAt(0);
if (item && item->Submenu() && item->Submenu()->Window())
{ {
BMessage message(B_KEY_DOWN); BMenuItem *item = ItemAt(0);
message.AddInt8("byte", B_ESCAPE); if (item && item->Submenu() && item->Submenu()->Window()) {
message.AddInt8("key", B_ESCAPE); BMessage message(B_KEY_DOWN);
message.AddInt32("modifiers", 0);
message.AddInt8("raw_char", B_ESCAPE);
Window()->PostMessage(&message, this, NULL); 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) if (IsFocus() == focused)
return; return;
BMenuBar::MakeFocus(focused); BMenuBar::MakeFocus(focused);
if (focused) if (focused) {
{
BMessage message('TICK'); BMessage message('TICK');
//fRunner = new BMessageRunner(BMessenger(this, NULL, NULL), &message, //fRunner = new BMessageRunner(BMessenger(this, NULL, NULL), &message,
// 50000, -1); // 50000, -1);
} } else if (fRunner) {
else if (fRunner)
{
//delete fRunner; //delete fRunner;
fRunner = NULL; fRunner = NULL;
} }
@@ -289,9 +312,19 @@ void _BMCMenuBar_::MakeFocus(bool focused)
fMenuField->Invalidate(BRect(bounds.left, bounds.top, fMenuField->fDivider, fMenuField->Invalidate(BRect(bounds.left, bounds.top, fMenuField->fDivider,
bounds.bottom)); 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; return *this;
} }
//------------------------------------------------------------------------------
+5 -4
View File
@@ -6,8 +6,6 @@
* Marc Flerackers ([email protected]) * Marc Flerackers ([email protected])
*/ */
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@@ -36,7 +34,7 @@ BMenuField::BMenuField(BRect frame, const char *name, const char *label,
false, this); false, this);
AddChild(fMenuBar); AddChild(fMenuBar);
fMenuBar->AddItem(menu); fMenuBar->AddItem(new _BMCItem_(menu));
fMenuBar->SetFont(be_plain_font); fMenuBar->SetFont(be_plain_font);
@@ -223,7 +221,7 @@ BMenuField::AllAttached()
void void
BMenuField::MouseDown(BPoint where) BMenuField::MouseDown(BPoint where)
{ {
if (where.x > fDivider && !fMenuBar->Frame().Contains(where)) if (!IsEnabled() || (where.x > fDivider && !fMenuBar->Frame().Contains(where)))
return; return;
BRect bounds = fMenuBar->ConvertFromParent(Bounds()); BRect bounds = fMenuBar->ConvertFromParent(Bounds());
@@ -245,6 +243,9 @@ BMenuField::KeyDown(const char *bytes, int32 numBytes)
case B_RIGHT_ARROW: case B_RIGHT_ARROW:
case B_DOWN_ARROW: case B_DOWN_ARROW:
{ {
if (!IsEnabled())
break;
BRect bounds = fMenuBar->ConvertFromParent(Bounds()); BRect bounds = fMenuBar->ConvertFromParent(Bounds());
fMenuBar->StartMenuBar(0, true, true, &bounds); fMenuBar->StartMenuBar(0, true, true, &bounds);