Added a filter to MenuField, so that mousedown messages caught by the inner menubar are redirected to the BMenuField's MouseDown() like happens on beos. That way we can track and invalidate correctly. Implemented Show/HidePopUpMarker

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17613 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2006-05-28 07:48:53 +00:00
parent e229fcb239
commit cd39decc44
4 changed files with 68 additions and 83 deletions
+24 -47
View File
@@ -1,58 +1,32 @@
//------------------------------------------------------------------------------ /*
// Copyright (c) 2001-2002, OpenBeOS * Copyright 2001-2006, Haiku, Inc.
// * Distributed under the terms of the MIT License.
// Permission is hereby granted, free of charge, to any person obtaining a *
// copy of this software and associated documentation files (the "Software"), * Authors:
// to deal in the Software without restriction, including without limitation * Marc Flerackers ([email protected])
// the rights to use, copy, modify, merge, publish, distribute, sublicense, * Stephan Aßmus <[email protected]>
// and/or sell copies of the Software, and to permit persons to whom the */
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// File Name: BMCPrivate.h
// Author: Marc Flerackers ([email protected])
// Description: The BMCPrivate classes are used by BMenuField.
//------------------------------------------------------------------------------
#ifndef _BMC_PRIVATE_H #ifndef _BMC_PRIVATE_H
#define _BMC_PRIVATE_H #define _BMC_PRIVATE_H
// Standard Includes -----------------------------------------------------------
// System Includes -------------------------------------------------------------
#include <BeBuild.h> #include <BeBuild.h>
#include <MenuBar.h> #include <MenuBar.h>
#include <MenuItem.h> #include <MenuItem.h>
#include <MessageFilter.h>
class _BMCFilter_ : public BMessageFilter {
public:
_BMCFilter_(BMenuField *menuField, uint32 what);
~_BMCFilter_();
filter_result Filter(BMessage *message, BHandler **handler);
private:
_BMCFilter_ &operator=(const _BMCFilter_ &);
BMenuField *fMenuField;
};
/*//------------------------------------------------------------------------------
_BMCFilter_::_BMCFilter_(BMenuField *menuField, uint32)
{
}
//------------------------------------------------------------------------------
_BMCFilter_::~_BMCFilter_()
{
}
//------------------------------------------------------------------------------
filter_result _BMCFilter_::Filter(BMessage *message, BHandler **handler)
{
}
//------------------------------------------------------------------------------
_BMCFilter_ &_BMCFilter_::operator=(const _BMCFilter_ &)
{
return *this;
}
//------------------------------------------------------------------------------*/
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
class _BMCMenuBar_ : public BMenuBar { class _BMCMenuBar_ : public BMenuBar {
@@ -70,7 +44,9 @@ 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);
void TogglePopUpMarker(bool show) { fShowPopUpMarker = show; }
bool IsPopUpMarkerShown() const { return fShowPopUpMarker; }
private: private:
_BMCMenuBar_&operator=(const _BMCMenuBar_ &); _BMCMenuBar_&operator=(const _BMCMenuBar_ &);
@@ -78,6 +54,7 @@ private:
BMenuField *fMenuField; BMenuField *fMenuField;
bool fFixedSize; bool fFixedSize;
BMessageRunner *fRunner; BMessageRunner *fRunner;
bool fShowPopUpMarker;
}; };
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
+23 -12
View File
@@ -16,8 +16,11 @@
#include <Region.h> #include <Region.h>
#include <Window.h> #include <Window.h>
/*
_BMCFilter_::_BMCFilter_(BMenuField *menuField, uint32) _BMCFilter_::_BMCFilter_(BMenuField *menuField, uint32 what)
:
BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE, what),
fMenuField(menuField)
{ {
} }
@@ -30,6 +33,17 @@ _BMCFilter_::~_BMCFilter_()
filter_result filter_result
_BMCFilter_::Filter(BMessage *message, BHandler **handler) _BMCFilter_::Filter(BMessage *message, BHandler **handler)
{ {
if (message->what == B_MOUSE_DOWN) {
if (BView *view = dynamic_cast<BView *>(*handler)) {
BPoint point;
message->FindPoint("be:view_where", &point);
view->ConvertToParent(&point);
message->ReplacePoint("be:view_where", point);
*handler = fMenuField;
}
}
return B_DISPATCH_MESSAGE;
} }
@@ -37,7 +51,7 @@ _BMCFilter_ &
_BMCFilter_::operator=(const _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)
@@ -50,6 +64,7 @@ _BMCMenuBar_::_BMCMenuBar_(BRect frame, bool fixed_size, BMenuField *menuField)
fMenuField = menuField; fMenuField = menuField;
fFixedSize = fixed_size; fFixedSize = fixed_size;
fRunner = NULL; fRunner = NULL;
fShowPopUpMarker = true;
float left, top, right, bottom; float left, top, right, bottom;
@@ -106,6 +121,11 @@ _BMCMenuBar_::AttachedToWindow()
void void
_BMCMenuBar_::Draw(BRect updateRect) _BMCMenuBar_::Draw(BRect updateRect)
{ {
if (!fShowPopUpMarker) {
BMenuBar::Draw(updateRect);
return;
}
// draw the right side with the popup marker // draw the right side with the popup marker
// prevent the original BMenuBar's Draw from // prevent the original BMenuBar's Draw from
@@ -301,15 +321,6 @@ _BMCMenuBar_::MakeFocus(bool focused)
} }
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_
&_BMCMenuBar_::operator=(const _BMCMenuBar_ &) &_BMCMenuBar_::operator=(const _BMCMenuBar_ &)
{ {
+1 -1
View File
@@ -495,7 +495,7 @@ BMenuBar::StealFocus()
BWindow *window = Window(); BWindow *window = Window();
if (window != NULL && window->Lock()) { if (window != NULL && window->Lock()) {
BView *focus = window->CurrentFocus(); BView *focus = window->CurrentFocus();
if (focus != NULL) if (focus != NULL && focus != this)
fPrevFocusToken = _get_object_token_(focus); fPrevFocusToken = _get_object_token_(focus);
MakeFocus(); MakeFocus();
window->Unlock(); window->Unlock();
+20 -23
View File
@@ -95,17 +95,11 @@ BMenuField::BMenuField(BMessage *data)
if (data->FindBool("be:fixeds", &fixed) == B_OK) if (data->FindBool("be:fixeds", &fixed) == B_OK)
fFixedSizeMB = fixed; fFixedSizeMB = fixed;
// BMenuItem *item = fMenuBar->ItemAt(0); bool dmark = false;
// if (!item) data->FindBool("be:dmark", &dmark);
// return; if (_BMCMenuBar_ *menuBar = dynamic_cast<_BMCMenuBar_ *>(fMenuBar)) {
// menuBar->TogglePopUpMarker(dmark);
// _BMCItem_ *bmcitem = dynamic_cast<_BMCItem_*>(item); }
// if (!bmcitem)
// return;
//
// bool dmark;
// if (data->FindBool("be:dmark", &dmark))
// bmcitem->fShowPopUpMarker = dmark;
} }
@@ -148,13 +142,11 @@ BMenuField::Archive(BMessage *data, bool deep) const
if (ret == B_OK && fFixedSizeMB) if (ret == B_OK && fFixedSizeMB)
ret = data->AddBool("be:fixeds", true); ret = data->AddBool("be:fixeds", true);
// BMenuItem *item = fMenuBar->ItemAt(0); bool dmark = false;
// if (!item) if (_BMCMenuBar_ *menuBar = dynamic_cast<_BMCMenuBar_ *>(fMenuBar)) {
// return B_OK; dmark = menuBar->IsPopUpMarkerShown();
// }
// _BMCItem_ *bmcitem = dynamic_cast<_BMCItem_*>(item); data->AddBool("be:dmark", dmark);
// if (bmcitem && !bmcitem->fShowPopUpMarker)
// data->AddBool("be:dmark", false);
return ret; return ret;
} }
@@ -225,7 +217,7 @@ BMenuField::AllAttached()
void void
BMenuField::MouseDown(BPoint where) BMenuField::MouseDown(BPoint where)
{ {
if (!IsEnabled() || (where.x > fDivider && !fMenuBar->Frame().Contains(where))) if (!fMenuBar->Frame().Contains(where))
return; return;
BRect bounds = fMenuBar->ConvertFromParent(Bounds()); BRect bounds = fMenuBar->ConvertFromParent(Bounds());
@@ -453,14 +445,20 @@ BMenuField::Divider() const
void void
BMenuField::ShowPopUpMarker() BMenuField::ShowPopUpMarker()
{ {
// TODO: if (_BMCMenuBar_ *menuBar = dynamic_cast<_BMCMenuBar_ *>(fMenuBar)) {
menuBar->TogglePopUpMarker(true);
menuBar->Invalidate();
}
} }
void void
BMenuField::HidePopUpMarker() BMenuField::HidePopUpMarker()
{ {
// TODO: if (_BMCMenuBar_ *menuBar = dynamic_cast<_BMCMenuBar_ *>(fMenuBar)) {
menuBar->TogglePopUpMarker(false);
menuBar->Invalidate();
}
} }
@@ -572,8 +570,6 @@ BMenuField::InitObject(const char *label)
void void
BMenuField::InitObject2() BMenuField::InitObject2()
{ {
// TODO set filter
font_height fontHeight; font_height fontHeight;
GetFontHeight(&fontHeight); GetFontHeight(&fontHeight);
@@ -582,6 +578,7 @@ BMenuField::InitObject2()
+ fontHeight.leading) + 7; + fontHeight.leading) + 7;
fMenuBar->ResizeTo(Bounds().Width() - fDivider, height); fMenuBar->ResizeTo(Bounds().Width() - fDivider, height);
fMenuBar->AddFilter(new _BMCFilter_(this, B_MOUSE_DOWN));
} }