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:
+21
-39
@@ -1,29 +1,13 @@
|
|||||||
//------------------------------------------------------------------------------
|
/*
|
||||||
// Copyright (c) 2001-2005, Haiku, Inc.
|
* Copyright 2001-2005, 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,
|
* Stefano Ceccherini ([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: Menu.cpp
|
|
||||||
// Authors: Marc Flerackers ([email protected])
|
|
||||||
// Stefano Ceccherini ([email protected])
|
|
||||||
// Description: BMenu display a menu of selectable items.
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
#include <Debug.h>
|
#include <Debug.h>
|
||||||
#include <File.h>
|
#include <File.h>
|
||||||
#include <FindDirectory.h>
|
#include <FindDirectory.h>
|
||||||
@@ -37,6 +21,7 @@
|
|||||||
#include <MenuPrivate.h>
|
#include <MenuPrivate.h>
|
||||||
#include <MenuWindow.h>
|
#include <MenuWindow.h>
|
||||||
|
|
||||||
|
|
||||||
class _ExtraMenuData_ {
|
class _ExtraMenuData_ {
|
||||||
public:
|
public:
|
||||||
menu_tracking_hook trackingHook;
|
menu_tracking_hook trackingHook;
|
||||||
@@ -734,9 +719,9 @@ BMenu::Draw(BRect updateRect)
|
|||||||
|
|
||||||
|
|
||||||
void
|
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
|
void
|
||||||
BMenu::ComputeLayout(int32 index, bool bestFit, bool moveItems,
|
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,
|
// TODO: Take "bestFit", "moveItems", "index" into account,
|
||||||
// Recalculate only the needed items,
|
// Recalculate only the needed items,
|
||||||
// not the whole layout every time
|
// not the whole layout every time
|
||||||
@@ -1354,15 +1336,15 @@ BMenu::ComputeLayout(int32 index, bool bestFit, bool moveItems,
|
|||||||
// This is for BMenuBar.
|
// This is for BMenuBar.
|
||||||
if ((ResizingMode() & B_FOLLOW_LEFT_RIGHT) == B_FOLLOW_LEFT_RIGHT) {
|
if ((ResizingMode() & B_FOLLOW_LEFT_RIGHT) == B_FOLLOW_LEFT_RIGHT) {
|
||||||
if (Parent())
|
if (Parent())
|
||||||
*width = Parent()->Frame().Width() + 1;
|
*_width = Parent()->Frame().Width() + 1;
|
||||||
|
else if (Window())
|
||||||
|
*_width = Window()->Frame().Width() + 1;
|
||||||
else
|
else
|
||||||
*width = Window()->Frame().Width() + 1;
|
*_width = Bounds().Width();
|
||||||
|
} else
|
||||||
|
*_width = frame.Width();
|
||||||
|
|
||||||
*height = frame.Height();
|
*_height = frame.Height();
|
||||||
} else {
|
|
||||||
*width = frame.Width();
|
|
||||||
*height = frame.Height();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user