/* * Copyright 2001-2006, Haiku, Inc. * Distributed under the terms of the MIT License. * * Authors: * Marc Flerackers (mflerackers@androme.be) * Stefano Ceccherini (burton666@libero.it) */ //! BMenuWindow is a custom BWindow for BMenus. // TODO: Add scrollers #include #include #include #include // This draws the frame around the BMenu class BMenuFrame : public BView { public: BMenuFrame(BMenu *menu); virtual void AttachedToWindow(); virtual void Draw(BRect updateRect); private: BMenu *fMenu; }; BMenuWindow::BMenuWindow(const char *name, BMenu *menu) // 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, B_NOT_ZOOMABLE | B_AVOID_FOCUS), fUpperScroller(NULL), fLowerScroller(NULL) { SetMenu(menu); } BMenuWindow::~BMenuWindow() { } void BMenuWindow::SetMenu(BMenu *menu) { if (CountChildren() > 0) RemoveChild(ChildAt(0)); BMenuFrame *menuFrame = new BMenuFrame(menu); AddChild(menuFrame); } // #pragma mark - BMenuFrame::BMenuFrame(BMenu *menu) : BView(BRect(0, 0, 1, 1), "menu frame", B_FOLLOW_ALL_SIDES, B_WILL_DRAW), fMenu(menu) { } void BMenuFrame::AttachedToWindow() { BView::AttachedToWindow(); ResizeTo(Window()->Bounds().Width(), Window()->Bounds().Height()); if (fMenu != NULL) { BFont font; fMenu->GetFont(&font); SetFont(&font); } } void BMenuFrame::Draw(BRect updateRect) { if (fMenu->CountItems() == 0) { // TODO: Review this as it's a bit hacky. // Menu has a size of 0, 0, since there are no items in it. // So the BMenuFrame class has to fake it and draw an empty item. // Note that we can't add a real "empty" item because then we couldn't // tell if the item was added by us or not. // See also BMenu::UpdateWindowViewSize() SetHighColor(ui_color(B_MENU_BACKGROUND_COLOR)); SetLowColor(HighColor()); FillRect(updateRect); font_height height; GetFontHeight(&height); SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), B_DISABLED_LABEL_TINT)); DrawString(kEmptyMenuLabel, BPoint(3, ceilf(height.ascent + 2))); } SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), B_DARKEN_2_TINT)); BRect bounds(Bounds()); StrokeLine(BPoint(bounds.right, bounds.top), BPoint(bounds.right, bounds.bottom - 1)); StrokeLine(BPoint(bounds.left + 1, bounds.bottom), BPoint(bounds.right, bounds.bottom)); }