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:
parent
e229fcb239
commit
cd39decc44
@ -1,58 +1,32 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 2001-2002, OpenBeOS
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// 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 (mflerackers@androme.be)
|
||||
// Description: The BMCPrivate classes are used by BMenuField.
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
* Copyright 2001-2006, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Marc Flerackers (mflerackers@androme.be)
|
||||
* Stephan Aßmus <superstippi@gmx.de>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _BMC_PRIVATE_H
|
||||
#define _BMC_PRIVATE_H
|
||||
|
||||
// Standard Includes -----------------------------------------------------------
|
||||
|
||||
// System Includes -------------------------------------------------------------
|
||||
#include <BeBuild.h>
|
||||
#include <MenuBar.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 {
|
||||
@ -70,14 +44,17 @@ 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);
|
||||
|
||||
void TogglePopUpMarker(bool show) { fShowPopUpMarker = show; }
|
||||
bool IsPopUpMarkerShown() const { return fShowPopUpMarker; }
|
||||
|
||||
private:
|
||||
_BMCMenuBar_&operator=(const _BMCMenuBar_ &);
|
||||
|
||||
BMenuField *fMenuField;
|
||||
bool fFixedSize;
|
||||
BMessageRunner *fRunner;
|
||||
bool fShowPopUpMarker;
|
||||
};
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
@ -16,8 +16,11 @@
|
||||
#include <Region.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
|
||||
_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_ &)
|
||||
{
|
||||
return *this;
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
_BMCMenuBar_::_BMCMenuBar_(BRect frame, bool fixed_size, BMenuField *menuField)
|
||||
@ -50,6 +64,7 @@ _BMCMenuBar_::_BMCMenuBar_(BRect frame, bool fixed_size, BMenuField *menuField)
|
||||
fMenuField = menuField;
|
||||
fFixedSize = fixed_size;
|
||||
fRunner = NULL;
|
||||
fShowPopUpMarker = true;
|
||||
|
||||
float left, top, right, bottom;
|
||||
|
||||
@ -106,6 +121,11 @@ _BMCMenuBar_::AttachedToWindow()
|
||||
void
|
||||
_BMCMenuBar_::Draw(BRect updateRect)
|
||||
{
|
||||
if (!fShowPopUpMarker) {
|
||||
BMenuBar::Draw(updateRect);
|
||||
return;
|
||||
}
|
||||
|
||||
// draw the right side with the popup marker
|
||||
|
||||
// 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_::operator=(const _BMCMenuBar_ &)
|
||||
{
|
||||
|
@ -495,7 +495,7 @@ BMenuBar::StealFocus()
|
||||
BWindow *window = Window();
|
||||
if (window != NULL && window->Lock()) {
|
||||
BView *focus = window->CurrentFocus();
|
||||
if (focus != NULL)
|
||||
if (focus != NULL && focus != this)
|
||||
fPrevFocusToken = _get_object_token_(focus);
|
||||
MakeFocus();
|
||||
window->Unlock();
|
||||
|
@ -95,17 +95,11 @@ BMenuField::BMenuField(BMessage *data)
|
||||
if (data->FindBool("be:fixeds", &fixed) == B_OK)
|
||||
fFixedSizeMB = fixed;
|
||||
|
||||
// BMenuItem *item = fMenuBar->ItemAt(0);
|
||||
// if (!item)
|
||||
// return;
|
||||
//
|
||||
// _BMCItem_ *bmcitem = dynamic_cast<_BMCItem_*>(item);
|
||||
// if (!bmcitem)
|
||||
// return;
|
||||
//
|
||||
// bool dmark;
|
||||
// if (data->FindBool("be:dmark", &dmark))
|
||||
// bmcitem->fShowPopUpMarker = dmark;
|
||||
bool dmark = false;
|
||||
data->FindBool("be:dmark", &dmark);
|
||||
if (_BMCMenuBar_ *menuBar = dynamic_cast<_BMCMenuBar_ *>(fMenuBar)) {
|
||||
menuBar->TogglePopUpMarker(dmark);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -148,13 +142,11 @@ BMenuField::Archive(BMessage *data, bool deep) const
|
||||
if (ret == B_OK && fFixedSizeMB)
|
||||
ret = data->AddBool("be:fixeds", true);
|
||||
|
||||
// BMenuItem *item = fMenuBar->ItemAt(0);
|
||||
// if (!item)
|
||||
// return B_OK;
|
||||
//
|
||||
// _BMCItem_ *bmcitem = dynamic_cast<_BMCItem_*>(item);
|
||||
// if (bmcitem && !bmcitem->fShowPopUpMarker)
|
||||
// data->AddBool("be:dmark", false);
|
||||
bool dmark = false;
|
||||
if (_BMCMenuBar_ *menuBar = dynamic_cast<_BMCMenuBar_ *>(fMenuBar)) {
|
||||
dmark = menuBar->IsPopUpMarkerShown();
|
||||
}
|
||||
data->AddBool("be:dmark", dmark);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -225,7 +217,7 @@ BMenuField::AllAttached()
|
||||
void
|
||||
BMenuField::MouseDown(BPoint where)
|
||||
{
|
||||
if (!IsEnabled() || (where.x > fDivider && !fMenuBar->Frame().Contains(where)))
|
||||
if (!fMenuBar->Frame().Contains(where))
|
||||
return;
|
||||
|
||||
BRect bounds = fMenuBar->ConvertFromParent(Bounds());
|
||||
@ -453,14 +445,20 @@ BMenuField::Divider() const
|
||||
void
|
||||
BMenuField::ShowPopUpMarker()
|
||||
{
|
||||
// TODO:
|
||||
if (_BMCMenuBar_ *menuBar = dynamic_cast<_BMCMenuBar_ *>(fMenuBar)) {
|
||||
menuBar->TogglePopUpMarker(true);
|
||||
menuBar->Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
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
|
||||
BMenuField::InitObject2()
|
||||
{
|
||||
// TODO set filter
|
||||
|
||||
font_height fontHeight;
|
||||
GetFontHeight(&fontHeight);
|
||||
|
||||
@ -582,6 +578,7 @@ BMenuField::InitObject2()
|
||||
+ fontHeight.leading) + 7;
|
||||
|
||||
fMenuBar->ResizeTo(Bounds().Width() - fDivider, height);
|
||||
fMenuBar->AddFilter(new _BMCFilter_(this, B_MOUSE_DOWN));
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user