MenuWindow's look is now B_BORDERED_WINDOW_LOOK, so we can avoid drawing the border ourselves.
Now BMenu caches its windows instead of creating a new one every time. This last change could be reverted, though, as we could end up keeping around too many windows. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12782 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+29
-14
@@ -185,7 +185,8 @@ BMenu::~BMenu()
|
|||||||
{
|
{
|
||||||
RemoveItems(0, CountItems(), true);
|
RemoveItems(0, CountItems(), true);
|
||||||
|
|
||||||
delete fCachedMenuWindow;
|
DeleteMenuWindow();
|
||||||
|
|
||||||
delete fInitMatrixSize;
|
delete fInitMatrixSize;
|
||||||
delete fExtraMenuData;
|
delete fExtraMenuData;
|
||||||
}
|
}
|
||||||
@@ -892,7 +893,7 @@ BMenu::ScreenLocation()
|
|||||||
if (superMenu->Layout() == B_ITEMS_IN_COLUMN)
|
if (superMenu->Layout() == B_ITEMS_IN_COLUMN)
|
||||||
point = superItem->Frame().RightTop();
|
point = superItem->Frame().RightTop();
|
||||||
else
|
else
|
||||||
point = superItem->Frame().LeftBottom() + BPoint(0.0f, 1.0f);
|
point = superItem->Frame().LeftBottom() + BPoint(1.0f, 1.0f);
|
||||||
|
|
||||||
superMenu->ConvertToScreen(&point);
|
superMenu->ConvertToScreen(&point);
|
||||||
|
|
||||||
@@ -1052,19 +1053,21 @@ BMenu::InitData(BMessage *data)
|
|||||||
bool
|
bool
|
||||||
BMenu::_show(bool selectFirstItem)
|
BMenu::_show(bool selectFirstItem)
|
||||||
{
|
{
|
||||||
// Menu windows get the BMenu's handler name
|
BWindow *menuWindow = MenuWindow();
|
||||||
fCachedMenuWindow = new BMenuWindow(Name());
|
|
||||||
|
|
||||||
fCachedMenuWindow->ChildAt(0)->AddChild(this);
|
menuWindow->Lock();
|
||||||
|
menuWindow->ChildAt(0)->AddChild(this);
|
||||||
|
|
||||||
// We're doing this here because ConvertToScreen() needs:
|
// We're doing this here because ConvertToScreen() needs:
|
||||||
// 1. The BView to be attached (see the above line).
|
// 1. The BView to be attached (see the above line).
|
||||||
// 2. The looper locked or not running (the Show() call below starts the looper)
|
// 2. The looper locked or not running (the Show() call below starts the looper)
|
||||||
if (fSuper != NULL)
|
if (fSuper != NULL)
|
||||||
fSuperbounds = fSuper->ConvertToScreen(fSuper->Bounds());
|
fSuperbounds = fSuper->ConvertToScreen(fSuper->Bounds());
|
||||||
fCachedMenuWindow->ResizeTo(Bounds().Width() + 4, Bounds().Height() + 4);
|
|
||||||
fCachedMenuWindow->MoveTo(ScreenLocation());
|
UpdateWindowViewSize();
|
||||||
fCachedMenuWindow->Show();
|
|
||||||
|
menuWindow->Unlock();
|
||||||
|
menuWindow->Show();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1076,8 +1079,8 @@ BMenu::_hide()
|
|||||||
if (fCachedMenuWindow != NULL) {
|
if (fCachedMenuWindow != NULL) {
|
||||||
fCachedMenuWindow->Lock();
|
fCachedMenuWindow->Lock();
|
||||||
fCachedMenuWindow->ChildAt(0)->RemoveChild(this);
|
fCachedMenuWindow->ChildAt(0)->RemoveChild(this);
|
||||||
fCachedMenuWindow->Quit();
|
fCachedMenuWindow->Hide();
|
||||||
fCachedMenuWindow = NULL;
|
fCachedMenuWindow->Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1236,11 +1239,11 @@ BMenu::LayoutItems(int32 index)
|
|||||||
|
|
||||||
ResizeTo(width, height);
|
ResizeTo(width, height);
|
||||||
|
|
||||||
// Move the BMenu to 2, 2, 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.
|
||||||
if (dynamic_cast<BMenuWindow *>(Window()) != NULL)
|
if (dynamic_cast<BMenuWindow *>(Window()) != NULL)
|
||||||
MoveTo(2, 2);
|
MoveTo(1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1431,6 +1434,12 @@ BMenu::OverSubmenu(BMenuItem *item, BPoint loc)
|
|||||||
BMenuWindow *
|
BMenuWindow *
|
||||||
BMenu::MenuWindow()
|
BMenu::MenuWindow()
|
||||||
{
|
{
|
||||||
|
if (fCachedMenuWindow == NULL) {
|
||||||
|
// Menu windows get the BMenu's handler name
|
||||||
|
fCachedMenuWindow = new BMenuWindow(Name());
|
||||||
|
UpdateWindowViewSize();
|
||||||
|
}
|
||||||
|
|
||||||
return fCachedMenuWindow;
|
return fCachedMenuWindow;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1438,8 +1447,11 @@ BMenu::MenuWindow()
|
|||||||
void
|
void
|
||||||
BMenu::DeleteMenuWindow()
|
BMenu::DeleteMenuWindow()
|
||||||
{
|
{
|
||||||
delete fCachedMenuWindow;
|
if (fCachedMenuWindow != NULL) {
|
||||||
fCachedMenuWindow = NULL;
|
fCachedMenuWindow->Lock();
|
||||||
|
fCachedMenuWindow->Quit();
|
||||||
|
fCachedMenuWindow = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1633,6 +1645,9 @@ BMenu::ChooseTrigger(const char *title, BList *chars)
|
|||||||
void
|
void
|
||||||
BMenu::UpdateWindowViewSize(bool upWind)
|
BMenu::UpdateWindowViewSize(bool upWind)
|
||||||
{
|
{
|
||||||
|
ASSERT(fCachedMenuWindow != NULL);
|
||||||
|
fCachedMenuWindow->ResizeTo(Bounds().Width() + 2, Bounds().Height() + 2);
|
||||||
|
fCachedMenuWindow->MoveTo(ScreenLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -51,17 +51,11 @@ public:
|
|||||||
{
|
{
|
||||||
BRect bounds(Bounds());
|
BRect bounds(Bounds());
|
||||||
|
|
||||||
SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), B_DARKEN_4_TINT));
|
|
||||||
StrokeRect(bounds);
|
|
||||||
SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), B_DARKEN_2_TINT));
|
SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), B_DARKEN_2_TINT));
|
||||||
StrokeLine(BPoint(bounds.left + 2, bounds.bottom - 1),
|
StrokeLine(BPoint(bounds.right, bounds.top),
|
||||||
BPoint(bounds.right - 1, bounds.bottom - 1));
|
BPoint(bounds.right, bounds.bottom - 1));
|
||||||
StrokeLine(BPoint(bounds.right - 1, bounds.top + 1),
|
StrokeLine(BPoint(bounds.left + 1, bounds.bottom),
|
||||||
BPoint(bounds.right - 1, bounds.bottom - 1));
|
BPoint(bounds.right, bounds.bottom));
|
||||||
SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), B_LIGHTEN_2_TINT));
|
|
||||||
StrokeLine(BPoint(bounds.left + 1, bounds.top + 1),
|
|
||||||
BPoint(bounds.right - 2, bounds.top + 1));
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -70,7 +64,7 @@ public:
|
|||||||
BMenuWindow::BMenuWindow(const char *name)
|
BMenuWindow::BMenuWindow(const char *name)
|
||||||
:
|
:
|
||||||
// The window will be resized by BMenu, so just pass a dummy rect
|
// The window will be resized by BMenu, so just pass a dummy rect
|
||||||
BWindow(BRect(0, 0, 0, 0), name, B_NO_BORDER_WINDOW_LOOK, kMenuWindowFeel,
|
BWindow(BRect(0, 0, 0, 0), name, B_BORDERED_WINDOW_LOOK, kMenuWindowFeel,
|
||||||
B_NOT_ZOOMABLE),
|
B_NOT_ZOOMABLE),
|
||||||
fUpperScroller(NULL),
|
fUpperScroller(NULL),
|
||||||
fLowerScroller(NULL)
|
fLowerScroller(NULL)
|
||||||
|
|||||||
Reference in New Issue
Block a user