From dd180e63784033715c13b58a3be4df7b1bf5d474 Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Mon, 16 Jan 2006 21:42:57 +0000 Subject: [PATCH] SetEnabled() enables or disables the parent menu too, SetRadioMode() and SetLabelFromMarked() call each other if needed, BMenuBar::Draw() doesn't make a difference if the menubar is disabled or not, should even fix bug #87 as it was calling LayoutItems() every cycle. Work done by John Drinkwater and me git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15988 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/interface/Menu.cpp | 14 +++++++++++- src/kits/interface/MenuBar.cpp | 40 +++++++++++++++------------------- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/src/kits/interface/Menu.cpp b/src/kits/interface/Menu.cpp index 8bd7c5b2c9..28144eb2cc 100644 --- a/src/kits/interface/Menu.cpp +++ b/src/kits/interface/Menu.cpp @@ -530,6 +530,14 @@ BMenu::SetEnabled(bool enabled) { fEnabled = enabled; + + if (fSuper) { + // Can't use fSuper->SetEnabled() here, as + // it would call SetEnabled() on us again, thus + // entering an infinite loop + fSuper->fEnabled = enabled; + } + for (int32 i = 0; i < CountItems(); i++) ItemAt(i)->SetEnabled(enabled); } @@ -539,6 +547,8 @@ void BMenu::SetRadioMode(bool flag) { fRadioMode = flag; + if (!flag) + SetLabelFromMarked(false); } @@ -560,6 +570,8 @@ void BMenu::SetLabelFromMarked(bool flag) { fDynamicName = flag; + if (flag) + SetRadioMode(true); } @@ -935,7 +947,7 @@ BMenu::Hide() BMenuItem * BMenu::Track(bool openAnyway, BRect *clickToOpenRect) { - if (IsStickyPrefOn()) + if (!IsStickyPrefOn()) openAnyway = false; SetStickyMode(openAnyway); diff --git a/src/kits/interface/MenuBar.cpp b/src/kits/interface/MenuBar.cpp index fd2798eb70..ac6e724b11 100644 --- a/src/kits/interface/MenuBar.cpp +++ b/src/kits/interface/MenuBar.cpp @@ -136,34 +136,28 @@ void BMenuBar::Draw(BRect updateRect) { // TODO: implement additional border styles - if (IsEnabled()) { - rgb_color color = HighColor(); + rgb_color color = HighColor(); + + BRect bounds(Bounds()); + // Restore the background of the previously selected menuitem + DrawBackground(bounds & updateRect); - BRect bounds(Bounds()); - // Restore the background of the previously selected menuitem - DrawBackground(bounds & updateRect); + SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), B_LIGHTEN_2_TINT)); + StrokeLine(BPoint(0.0f, bounds.bottom - 2.0f), BPoint(0.0f, 0.0f)); + StrokeLine(BPoint(bounds.right, 0.0f)); - SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), B_LIGHTEN_2_TINT)); - StrokeLine(BPoint(0.0f, bounds.bottom - 2.0f), BPoint(0.0f, 0.0f)); - StrokeLine(BPoint(bounds.right, 0.0f)); + SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), B_DARKEN_1_TINT)); + StrokeLine(BPoint(1.0f, bounds.bottom - 1.0f), + BPoint(bounds.right, bounds.bottom - 1.0f)); - SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), B_DARKEN_1_TINT)); - StrokeLine(BPoint(1.0f, bounds.bottom - 1.0f), - BPoint(bounds.right, bounds.bottom - 1.0f)); + SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), B_DARKEN_2_TINT)); + StrokeLine(BPoint(0.0f, bounds.bottom), BPoint(bounds.right, bounds.bottom)); + StrokeLine(BPoint(bounds.right, 0.0f), BPoint(bounds.right, bounds.bottom)); - SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), B_DARKEN_2_TINT)); - StrokeLine(BPoint(0.0f, bounds.bottom), BPoint(bounds.right, bounds.bottom)); - StrokeLine(BPoint(bounds.right, 0.0f), BPoint(bounds.right, bounds.bottom)); + SetHighColor(color); + // revert to previous used color (cheap PushState()/PopState()) - SetHighColor(color); - // revert to previous used color (cheap PushState()/PopState()) - - DrawItems(updateRect); - } else { - LayoutItems(0); - Sync(); - Invalidate(); - } + DrawItems(updateRect); }