Added some code to draw "empty" in empty menus. Not working for the
moment, but committing since it's too late to continue working, and at least the window is resized correctly... git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16142 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -34,9 +34,10 @@ class BMenuScroller;
|
|||||||
|
|
||||||
class BMenuWindow : public BWindow {
|
class BMenuWindow : public BWindow {
|
||||||
public:
|
public:
|
||||||
BMenuWindow(const char *name);
|
BMenuWindow(const char *name, BMenu *menu);
|
||||||
virtual ~BMenuWindow();
|
virtual ~BMenuWindow();
|
||||||
|
|
||||||
|
void SetMenu(BMenu *menu);
|
||||||
void UpdateScrollers();
|
void UpdateScrollers();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -1044,15 +1044,17 @@ BMenu::_show(bool selectFirstItem)
|
|||||||
// See if the supermenu has a cached menuwindow,
|
// See if the supermenu has a cached menuwindow,
|
||||||
// and use that one if possible.
|
// and use that one if possible.
|
||||||
BMenuWindow *window = NULL;
|
BMenuWindow *window = NULL;
|
||||||
if (fSuper != NULL)
|
if (fSuper != NULL) {
|
||||||
window = fSuper->MenuWindow();
|
window = fSuper->MenuWindow();
|
||||||
|
if (window != NULL)
|
||||||
|
window->SetMenu(this);
|
||||||
|
}
|
||||||
// Otherwise, create a new one
|
// Otherwise, create a new one
|
||||||
// Actually, I think this can only happen for
|
// Actually, I think this can only happen for
|
||||||
// "stand alone" BPopUpMenus (i.e. not within a BMenuField)
|
// "stand alone" BPopUpMenus (i.e. not within a BMenuField)
|
||||||
if (window == NULL) {
|
if (window == NULL) {
|
||||||
// Menu windows get the BMenu's handler name
|
// Menu windows get the BMenu's handler name
|
||||||
window = new BMenuWindow(Name());
|
window = new BMenuWindow(Name(), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
@@ -1572,7 +1574,7 @@ BMenu::MenuWindow()
|
|||||||
if (fCachedMenuWindow == NULL) {
|
if (fCachedMenuWindow == NULL) {
|
||||||
char windowName[64];
|
char windowName[64];
|
||||||
snprintf(windowName, 64, "%s cached menuwindow\n", Name());
|
snprintf(windowName, 64, "%s cached menuwindow\n", Name());
|
||||||
fCachedMenuWindow = new BMenuWindow(windowName);
|
fCachedMenuWindow = new BMenuWindow(windowName, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
return fCachedMenuWindow;
|
return fCachedMenuWindow;
|
||||||
@@ -1807,7 +1809,12 @@ BMenu::UpdateWindowViewSize(bool upWind)
|
|||||||
BRect frame = CalcFrame(ScreenLocation(), &scroll);
|
BRect frame = CalcFrame(ScreenLocation(), &scroll);
|
||||||
ResizeTo(frame.Width(), frame.Height());
|
ResizeTo(frame.Width(), frame.Height());
|
||||||
|
|
||||||
window->ResizeTo(Bounds().Width() + 2, Bounds().Height() + 2);
|
if (fItems.CountItems() > 0)
|
||||||
|
window->ResizeTo(Bounds().Width() + 2, Bounds().Height() + 2);
|
||||||
|
else {
|
||||||
|
CacheFontInfo();
|
||||||
|
window->ResizeTo(StringWidth("<empty>") + 4, fFontHeight + 6);
|
||||||
|
}
|
||||||
window->MoveTo(frame.LeftTop());
|
window->MoveTo(frame.LeftTop());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,14 +36,17 @@ const window_feel kMenuWindowFeel = (window_feel)1025;
|
|||||||
// This draws the frame around the BMenu
|
// This draws the frame around the BMenu
|
||||||
class BMenuFrame : public BView {
|
class BMenuFrame : public BView {
|
||||||
public:
|
public:
|
||||||
BMenuFrame() ;
|
BMenuFrame(BMenu *menu) ;
|
||||||
|
|
||||||
virtual void AttachedToWindow();
|
virtual void AttachedToWindow();
|
||||||
virtual void Draw(BRect updateRect);
|
virtual void Draw(BRect updateRect);
|
||||||
|
|
||||||
|
private:
|
||||||
|
BMenu *fMenu;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
BMenuWindow::BMenuWindow(const char *name)
|
BMenuWindow::BMenuWindow(const char *name, BMenu *menu)
|
||||||
:
|
:
|
||||||
// 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_BORDERED_WINDOW_LOOK, kMenuWindowFeel,
|
//BWindow(BRect(0, 0, 0, 0), name, B_BORDERED_WINDOW_LOOK, kMenuWindowFeel,
|
||||||
@@ -53,8 +56,7 @@ BMenuWindow::BMenuWindow(const char *name)
|
|||||||
fUpperScroller(NULL),
|
fUpperScroller(NULL),
|
||||||
fLowerScroller(NULL)
|
fLowerScroller(NULL)
|
||||||
{
|
{
|
||||||
BMenuFrame *menuFrame = new BMenuFrame();
|
SetMenu(menu);
|
||||||
AddChild(menuFrame);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -63,10 +65,21 @@ BMenuWindow::~BMenuWindow()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
BMenuWindow::SetMenu(BMenu *menu)
|
||||||
|
{
|
||||||
|
if (CountChildren() > 0)
|
||||||
|
RemoveChild(ChildAt(0));
|
||||||
|
BMenuFrame *menuFrame = new BMenuFrame(menu);
|
||||||
|
AddChild(menuFrame);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// BMenuFrame
|
// BMenuFrame
|
||||||
BMenuFrame::BMenuFrame()
|
BMenuFrame::BMenuFrame(BMenu *menu)
|
||||||
:
|
:
|
||||||
BView(BRect(0, 0, 1, 1), "menu frame", B_FOLLOW_ALL_SIDES, B_WILL_DRAW)
|
BView(BRect(0, 0, 1, 1), "menu frame", B_FOLLOW_ALL_SIDES, B_WILL_DRAW),
|
||||||
|
fMenu(menu)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,9 +95,18 @@ BMenuFrame::AttachedToWindow()
|
|||||||
void
|
void
|
||||||
BMenuFrame::Draw(BRect updateRect)
|
BMenuFrame::Draw(BRect updateRect)
|
||||||
{
|
{
|
||||||
|
if (fMenu->CountItems() == 0) {
|
||||||
|
SetHighColor(ui_color(B_MENU_BACKGROUND_COLOR));
|
||||||
|
FillRect(updateRect);
|
||||||
|
font_height height;
|
||||||
|
fMenu->GetFontHeight(&height);
|
||||||
|
fMenu->SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), B_DISABLED_LABEL_TINT));
|
||||||
|
// TODO: This doesn't get drawn for some reason
|
||||||
|
fMenu->DrawString("<empty>", BPoint(2, ceilf(height.ascent + 2)));
|
||||||
|
}
|
||||||
|
|
||||||
|
SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), B_DARKEN_2_TINT));
|
||||||
BRect bounds(Bounds());
|
BRect bounds(Bounds());
|
||||||
|
|
||||||
SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), B_DARKEN_2_TINT));
|
|
||||||
StrokeLine(BPoint(bounds.right, bounds.top),
|
StrokeLine(BPoint(bounds.right, bounds.top),
|
||||||
BPoint(bounds.right, bounds.bottom - 1));
|
BPoint(bounds.right, bounds.bottom - 1));
|
||||||
StrokeLine(BPoint(bounds.left + 1, bounds.bottom),
|
StrokeLine(BPoint(bounds.left + 1, bounds.bottom),
|
||||||
|
|||||||
Reference in New Issue
Block a user