Reverted to r16487 due to various problems. I'll recommit the code once it's fully working.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16850 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2006-03-21 16:06:46 +00:00
parent 8c86105b9a
commit 7a2c9b35cd
+22 -37
View File
@@ -14,7 +14,6 @@
#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>
@@ -276,10 +275,8 @@ BMenu::AttachedToWindow()
} while (AddDynamicItem(B_PROCESSING)); } while (AddDynamicItem(B_PROCESSING));
} }
if (!fAttachAborted) { if (!fAttachAborted)
LayoutItems(0); InvalidateLayout();
UpdateWindowViewSize();
}
} }
@@ -570,7 +567,6 @@ void
BMenu::SetMaxContentWidth(float width) BMenu::SetMaxContentWidth(float width)
{ {
fMaxContentWidth = width; fMaxContentWidth = width;
InvalidateLayout();
} }
@@ -735,13 +731,6 @@ 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);
} }
@@ -778,10 +767,9 @@ BMenu::FrameResized(float new_width, float new_height)
void void
BMenu::InvalidateLayout() BMenu::InvalidateLayout()
{ {
/*CacheFontInfo(); CacheFontInfo();
LayoutItems(0); LayoutItems(0);
Invalidate();*/ Invalidate();
fUseCachedMenuLayout = false;
} }
@@ -1089,7 +1077,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())
@@ -1222,7 +1210,12 @@ BMenu::_AddItem(BMenuItem *item, int32 index)
item->SetSuper(this); item->SetSuper(this);
InvalidateLayout(); // Make sure we update the layout in case we are already attached.
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
@@ -1290,7 +1283,7 @@ BMenu::RemoveItems(int32 index, int32 count, BMenuItem *item, bool del)
} }
} }
if (invalidateLayout) if (invalidateLayout && Window() != NULL && fResizeToFit)
InvalidateLayout(); InvalidateLayout();
return success; return success;
@@ -1300,17 +1293,13 @@ BMenu::RemoveItems(int32 index, int32 count, BMenuItem *item, bool del)
void void
BMenu::LayoutItems(int32 index) BMenu::LayoutItems(int32 index)
{ {
if (!fUseCachedMenuLayout && CountItems() > 0) { CalcTriggers();
fUseCachedMenuLayout = true;
if (fLayout != B_ITEMS_IN_MATRIX) { float width, height;
CalcTriggers(); ComputeLayout(index, true, true, &width, &height);
float width, height; ResizeTo(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.
@@ -1323,7 +1312,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", "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
@@ -1409,6 +1398,8 @@ 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())
@@ -1830,12 +1821,6 @@ 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);