From 9a8540fb4ec52052c97b8bffa92c68d3ea7420ac Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Mon, 3 Jan 2005 11:34:14 +0000 Subject: [PATCH] Now menuitems are highlighted correctly, and submenus open, at least. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10570 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/interface/Menu.cpp | 64 ++++++++++++++++++++++------------ src/kits/interface/MenuBar.cpp | 44 +++++++++++++---------- 2 files changed, 67 insertions(+), 41 deletions(-) diff --git a/src/kits/interface/Menu.cpp b/src/kits/interface/Menu.cpp index 53a4c32ec1..7fb024bd54 100644 --- a/src/kits/interface/Menu.cpp +++ b/src/kits/interface/Menu.cpp @@ -1,5 +1,5 @@ //------------------------------------------------------------------------------ -// Copyright (c) 2001-2004, Haiku, Inc. +// Copyright (c) 2001-2005, Haiku, Inc. // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), @@ -117,7 +117,7 @@ BMenu::BMenu(const char *name, menu_layout layout) fStickyMode(false), fIgnoreHidden(true), fTriggerEnabled(true), - fRedrawAfterSticky(true), + fRedrawAfterSticky(false), fAttachAborted(false) { InitData(NULL); @@ -151,7 +151,7 @@ BMenu::BMenu(const char *name, float width, float height) fStickyMode(false), fIgnoreHidden(true), fTriggerEnabled(true), - fRedrawAfterSticky(true), + fRedrawAfterSticky(false), fAttachAborted(false) { InitData(NULL); @@ -239,7 +239,7 @@ BMenu::AttachedToWindow() { BView::AttachedToWindow(); - LayoutItems(0); + InvalidateLayout(); } @@ -268,8 +268,10 @@ BMenu::AddItem(BMenuItem *item, int32 index) return err; // Make sure we update the layout in case we are already attached. - if (Window() && fResizeToFit) + if (Window() && fResizeToFit) { LayoutItems(index); + Invalidate(); + } // Find the root menu window, so we can install this item. BMenu *root = this; @@ -720,6 +722,7 @@ BMenu::InvalidateLayout() { CacheFontInfo(); LayoutItems(0); + Invalidate(); } @@ -847,7 +850,7 @@ BMenu::BMenu(BRect frame, const char *name, uint32 resizingMode, uint32 flags, fStickyMode(false), fIgnoreHidden(true), fTriggerEnabled(true), - fRedrawAfterSticky(true), + fRedrawAfterSticky(false), fAttachAborted(false) { InitData(NULL); @@ -997,15 +1000,16 @@ BMenu::operator=(const BMenu &) void BMenu::InitData(BMessage *data) { + // TODO: Get _color, _fname, _fflt from the message, if present BFont font; font.SetFamilyAndStyle(sMenuInfo.f_family, sMenuInfo.f_style); font.SetSize(sMenuInfo.font_size); - SetFont(&font); + SetFont(&font, B_FONT_FAMILY_AND_STYLE | B_FONT_SIZE); - SetDrawingMode(B_OP_COPY); + SetLowColor(sMenuInfo.background_color); SetViewColor(sMenuInfo.background_color); - - if (data) { + + if (data != NULL) { data->FindInt32("_layout", (int32 *)&fLayout); data->FindBool("_rsize_to_fit", &fResizeToFit); data->FindBool("_disable", &fEnabled); @@ -1051,7 +1055,7 @@ BMenu::_hide() BMenuItem * BMenu::_track(int *action, long start) { - // TODO: Take Sticky mode into account + // TODO: Take Sticky mode into account, handle submenus BPoint location; ulong buttons; BMenuItem *item = NULL; @@ -1064,12 +1068,15 @@ BMenu::_track(int *action, long start) UnlockLooper(); break; } - - SelectItem(item); - Draw(Bounds()); + if (item != fSelected) { + SelectItem(item); + Invalidate(); + } + UnlockLooper(); - } + } + snooze(50000); } while (buttons != 0); @@ -1080,6 +1087,11 @@ BMenu::_track(int *action, long start) *action = 5; } + if (LockLooper()) { + SelectItem(NULL); + UnlockLooper(); + } + return item; } @@ -1123,7 +1135,7 @@ BMenu::RemoveItems(int32 index, int32 count, BMenuItem *_item, bool del) } } - LayoutItems(0); + InvalidateLayout(); return result; } @@ -1138,8 +1150,6 @@ BMenu::LayoutItems(int32 index) ComputeLayout(index, true, true, &width, &height); ResizeTo(width, height); - - Invalidate(); } @@ -1402,12 +1412,20 @@ BMenu::Uninstall() void BMenu::SelectItem(BMenuItem *menuItem, uint32 showSubmenu, bool selectFirstItem) { - if (menuItem != fSelected) { - if (fSelected != NULL) - fSelected->Select(false); - menuItem->Select(true); - fSelected = menuItem; + // TODO: make use of "showSubmenu" and "selectFirstItem". + if (fSelected != NULL) { + fSelected->Select(false); + if (fSelected->Submenu() != NULL) + fSelected->Submenu()->_hide(); } + + if (menuItem != NULL) + menuItem->Select(true); + + fSelected = menuItem; + if (fSelected != NULL && fSelected->Submenu() != NULL) + fSelected->Submenu()->_show(); + } diff --git a/src/kits/interface/MenuBar.cpp b/src/kits/interface/MenuBar.cpp index 7dabcb5e34..0e52206ac1 100644 --- a/src/kits/interface/MenuBar.cpp +++ b/src/kits/interface/MenuBar.cpp @@ -1,5 +1,5 @@ //------------------------------------------------------------------------------ -// Copyright (c) 2001-2004, Haiku, Inc. +// Copyright (c) 2001-2005, Haiku, Inc. // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), @@ -137,21 +137,21 @@ void BMenuBar::Draw(BRect updateRect) { // TODO: implement additional border styles - // Fix this function, the BMenuBar isn't drawn correctly - if (!IsEnabled()) { - LayoutItems(0); - Sync(); - Invalidate(); - } else { + if (IsEnabled()) { BRect bounds(Bounds()); - + PushState(); - + + // Restore the background color in case a menuitem + // was selected. + SetHighColor(ui_color(B_MENU_BACKGROUND_COLOR)); + FillRect(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_DARKEN_1_TINT)); + 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)); @@ -160,8 +160,13 @@ BMenuBar::Draw(BRect updateRect) StrokeLine(BPoint(bounds.right, 0.0f), BPoint(bounds.right, bounds.bottom)); PopState(); - - DrawItems(updateRect); + + DrawItems(updateRect); + + } else { + LayoutItems(0); + Sync(); + Invalidate(); } } @@ -398,14 +403,17 @@ BMenuBar::Track(int32 *action, int32 startIndex, bool showMenu) BPoint where; ulong buttons; do { + snooze(40000); printf("BMenuBar: tracking...\n"); GetMouse(&where, &buttons); BMenuItem *menuItem = HitTestItems(where, B_ORIGIN); if (menuItem) { + SelectItem(menuItem); + // TODO: Actually, this test shouldn't be needed, as + // all BMenuBar's BMenuItems are BMenus. BMenu *menu = menuItem->Submenu(); if (menu) { printf("BMenuBar: showing menu %s\n", menu->Name()); - menu->Show(); do { snooze(40000); GetMouse(&where, &buttons); @@ -414,7 +422,7 @@ BMenuBar::Track(int32 *action, int32 startIndex, bool showMenu) BMenuItem *testItem = HitTestItems(where, B_ORIGIN); if (testItem != NULL && testItem != menuItem) break; - + resultItem = menu->_track((int *)action, startIndex); printf("BMenuBar: menu %s: action: %ld\n", menu->Name(), *action); @@ -422,10 +430,10 @@ BMenuBar::Track(int32 *action, int32 startIndex, bool showMenu) } while (*action != 5); printf("BMenuBar: hiding menu %s\n", menu->Name()); - menu->_hide(); - } - } - snooze(40000); + } + SelectItem(NULL); + Invalidate(); + } } while (buttons != 0); window->Unlock();