BMenu::InvalidateLayout() now just marks the cached layout as invalid, instead of recalculating it. This results in less computations. Reorganized the layout calculation due to that. Now it's done once in AttachedToWindow(), and in Draw(), only if needed
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16848 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+37
-22
@@ -14,6 +14,7 @@
|
|||||||
#include <File.h>
|
#include <File.h>
|
||||||
#include <FindDirectory.h>
|
#include <FindDirectory.h>
|
||||||
#include <Menu.h>
|
#include <Menu.h>
|
||||||
|
#include <MenuBar.h>
|
||||||
#include <MenuItem.h>
|
#include <MenuItem.h>
|
||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
#include <PropertyInfo.h>
|
#include <PropertyInfo.h>
|
||||||
@@ -275,8 +276,10 @@ BMenu::AttachedToWindow()
|
|||||||
} while (AddDynamicItem(B_PROCESSING));
|
} while (AddDynamicItem(B_PROCESSING));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fAttachAborted)
|
if (!fAttachAborted) {
|
||||||
InvalidateLayout();
|
LayoutItems(0);
|
||||||
|
UpdateWindowViewSize();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -567,6 +570,7 @@ void
|
|||||||
BMenu::SetMaxContentWidth(float width)
|
BMenu::SetMaxContentWidth(float width)
|
||||||
{
|
{
|
||||||
fMaxContentWidth = width;
|
fMaxContentWidth = width;
|
||||||
|
InvalidateLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -731,6 +735,13 @@ BMenu::KeyDown(const char *bytes, int32 numBytes)
|
|||||||
void
|
void
|
||||||
BMenu::Draw(BRect updateRect)
|
BMenu::Draw(BRect updateRect)
|
||||||
{
|
{
|
||||||
|
if (!fUseCachedMenuLayout) {
|
||||||
|
LayoutItems(0);
|
||||||
|
UpdateWindowViewSize(true);
|
||||||
|
Sync();
|
||||||
|
Invalidate();
|
||||||
|
return;
|
||||||
|
}
|
||||||
DrawBackground(updateRect);
|
DrawBackground(updateRect);
|
||||||
DrawItems(updateRect);
|
DrawItems(updateRect);
|
||||||
}
|
}
|
||||||
@@ -767,9 +778,10 @@ BMenu::FrameResized(float new_width, float new_height)
|
|||||||
void
|
void
|
||||||
BMenu::InvalidateLayout()
|
BMenu::InvalidateLayout()
|
||||||
{
|
{
|
||||||
CacheFontInfo();
|
/*CacheFontInfo();
|
||||||
LayoutItems(0);
|
LayoutItems(0);
|
||||||
Invalidate();
|
Invalidate();*/
|
||||||
|
fUseCachedMenuLayout = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1077,7 +1089,7 @@ BMenu::_show(bool selectFirstItem)
|
|||||||
if (fSuper != NULL)
|
if (fSuper != NULL)
|
||||||
fSuperbounds = fSuper->ConvertToScreen(fSuper->Bounds());
|
fSuperbounds = fSuper->ConvertToScreen(fSuper->Bounds());
|
||||||
|
|
||||||
UpdateWindowViewSize();
|
//UpdateWindowViewSize();
|
||||||
window->Show();
|
window->Show();
|
||||||
|
|
||||||
if (window->IsLocked())
|
if (window->IsLocked())
|
||||||
@@ -1210,12 +1222,7 @@ BMenu::_AddItem(BMenuItem *item, int32 index)
|
|||||||
|
|
||||||
item->SetSuper(this);
|
item->SetSuper(this);
|
||||||
|
|
||||||
// Make sure we update the layout in case we are already attached.
|
InvalidateLayout();
|
||||||
if (fResizeToFit && locked && Window() != NULL /*&& !Window()->IsHidden()*/) {
|
|
||||||
LayoutItems(index);
|
|
||||||
//UpdateWindowViewSize();
|
|
||||||
Invalidate();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find the root menu window, so we can install this item.
|
// Find the root menu window, so we can install this item.
|
||||||
// ToDo: this shouldn't be necessary - the first supermenu is
|
// ToDo: this shouldn't be necessary - the first supermenu is
|
||||||
@@ -1283,7 +1290,7 @@ BMenu::RemoveItems(int32 index, int32 count, BMenuItem *item, bool del)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (invalidateLayout && Window() != NULL && fResizeToFit)
|
if (invalidateLayout)
|
||||||
InvalidateLayout();
|
InvalidateLayout();
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
@@ -1293,13 +1300,17 @@ BMenu::RemoveItems(int32 index, int32 count, BMenuItem *item, bool del)
|
|||||||
void
|
void
|
||||||
BMenu::LayoutItems(int32 index)
|
BMenu::LayoutItems(int32 index)
|
||||||
{
|
{
|
||||||
CalcTriggers();
|
if (!fUseCachedMenuLayout && CountItems() > 0) {
|
||||||
|
fUseCachedMenuLayout = true;
|
||||||
float width, height;
|
if (fLayout != B_ITEMS_IN_MATRIX) {
|
||||||
ComputeLayout(index, true, true, &width, &height);
|
CalcTriggers();
|
||||||
|
|
||||||
ResizeTo(width, height);
|
float width, height;
|
||||||
|
ComputeLayout(index, fResizeToFit, true, &width, &height);
|
||||||
|
if (fResizeToFit)
|
||||||
|
ResizeTo(width, height);
|
||||||
|
}
|
||||||
|
}
|
||||||
// Move the BMenu to 1, 1, if it's attached to a BMenuWindow,
|
// Move the BMenu to 1, 1, if it's attached to a BMenuWindow,
|
||||||
// (that means it's a BMenu, BMenuBars are attached to regular BWindows).
|
// (that means it's a BMenu, BMenuBars are attached to regular BWindows).
|
||||||
// This is needed to be able to draw the frame around the BMenu.
|
// This is needed to be able to draw the frame around the BMenu.
|
||||||
@@ -1312,7 +1323,7 @@ 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)
|
||||||
{
|
{
|
||||||
// TODO: Take "bestFit", "moveItems", "index" into account,
|
// TODO: Take "bestFit", "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
|
||||||
|
|
||||||
@@ -1398,8 +1409,6 @@ BMenu::ComputeLayout(int32 index, bool bestFit, bool moveItems,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is for BMenuBar
|
|
||||||
|
|
||||||
if (_width) {
|
if (_width) {
|
||||||
if ((ResizingMode() & B_FOLLOW_LEFT_RIGHT) == B_FOLLOW_LEFT_RIGHT) {
|
if ((ResizingMode() & B_FOLLOW_LEFT_RIGHT) == B_FOLLOW_LEFT_RIGHT) {
|
||||||
if (Parent())
|
if (Parent())
|
||||||
@@ -1821,6 +1830,12 @@ BMenu::ChooseTrigger(const char *title, BList *chars)
|
|||||||
void
|
void
|
||||||
BMenu::UpdateWindowViewSize(bool upWind)
|
BMenu::UpdateWindowViewSize(bool upWind)
|
||||||
{
|
{
|
||||||
|
// BMenuBar doesn't need to do anything.
|
||||||
|
// TODO: another not_so_great hack: BMenu shouldn't know
|
||||||
|
// about his inherited BMenuBar class.
|
||||||
|
if (dynamic_cast<BMenuBar *>(this) != NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
BWindow *window = Window();
|
BWindow *window = Window();
|
||||||
bool scroll;
|
bool scroll;
|
||||||
BRect frame = CalcFrame(ScreenLocation(), &scroll);
|
BRect frame = CalcFrame(ScreenLocation(), &scroll);
|
||||||
|
|||||||
Reference in New Issue
Block a user