There is no reason ComputeLayout() needs a parent/window - in fact, it should always

work correctly (for GetPreferredSize()).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14789 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2005-11-09 15:37:58 +00:00
parent edeb640ab0
commit 86343dcbcf
+21 -39
View File
@@ -1,29 +1,13 @@
//------------------------------------------------------------------------------
// Copyright (c) 2001-2005, Haiku, Inc.
//
// 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: Menu.cpp
// Authors: Marc Flerackers ([email protected])
// Stefano Ceccherini ([email protected])
// Description: BMenu display a menu of selectable items.
//------------------------------------------------------------------------------
/*
* Copyright 2001-2005, Haiku, Inc.
* Distributed under the terms of the MIT License.
*
* Authors:
* Marc Flerackers ([email protected])
* Stefano Ceccherini ([email protected])
*/
#include <Debug.h>
#include <File.h>
#include <FindDirectory.h>
@@ -37,6 +21,7 @@
#include <MenuPrivate.h>
#include <MenuWindow.h>
class _ExtraMenuData_ {
public:
menu_tracking_hook trackingHook;
@@ -734,9 +719,9 @@ BMenu::Draw(BRect updateRect)
void
BMenu::GetPreferredSize(float *width, float *height)
BMenu::GetPreferredSize(float *_width, float *_height)
{
ComputeLayout(0, true, false, width, height);
ComputeLayout(0, true, false, _width, _height);
}
@@ -1264,11 +1249,8 @@ BMenu::LayoutItems(int32 index)
void
BMenu::ComputeLayout(int32 index, bool bestFit, bool moveItems,
float* width, float* height)
float* _width, float* _height)
{
if (Window() == NULL && Parent() == NULL)
return;
// TODO: Take "bestFit", "moveItems", "index" into account,
// Recalculate only the needed items,
// not the whole layout every time
@@ -1354,15 +1336,15 @@ BMenu::ComputeLayout(int32 index, bool bestFit, bool moveItems,
// This is for BMenuBar.
if ((ResizingMode() & B_FOLLOW_LEFT_RIGHT) == B_FOLLOW_LEFT_RIGHT) {
if (Parent())
*width = Parent()->Frame().Width() + 1;
*_width = Parent()->Frame().Width() + 1;
else if (Window())
*_width = Window()->Frame().Width() + 1;
else
*width = Window()->Frame().Width() + 1;
*_width = Bounds().Width();
} else
*_width = frame.Width();
*height = frame.Height();
} else {
*width = frame.Width();
*height = frame.Height();
}
*_height = frame.Height();
}