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
This commit is contained in:
+41
-23
@@ -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
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
// copy of this software and associated documentation files (the "Software"),
|
// copy of this software and associated documentation files (the "Software"),
|
||||||
@@ -117,7 +117,7 @@ BMenu::BMenu(const char *name, menu_layout layout)
|
|||||||
fStickyMode(false),
|
fStickyMode(false),
|
||||||
fIgnoreHidden(true),
|
fIgnoreHidden(true),
|
||||||
fTriggerEnabled(true),
|
fTriggerEnabled(true),
|
||||||
fRedrawAfterSticky(true),
|
fRedrawAfterSticky(false),
|
||||||
fAttachAborted(false)
|
fAttachAborted(false)
|
||||||
{
|
{
|
||||||
InitData(NULL);
|
InitData(NULL);
|
||||||
@@ -151,7 +151,7 @@ BMenu::BMenu(const char *name, float width, float height)
|
|||||||
fStickyMode(false),
|
fStickyMode(false),
|
||||||
fIgnoreHidden(true),
|
fIgnoreHidden(true),
|
||||||
fTriggerEnabled(true),
|
fTriggerEnabled(true),
|
||||||
fRedrawAfterSticky(true),
|
fRedrawAfterSticky(false),
|
||||||
fAttachAborted(false)
|
fAttachAborted(false)
|
||||||
{
|
{
|
||||||
InitData(NULL);
|
InitData(NULL);
|
||||||
@@ -239,7 +239,7 @@ BMenu::AttachedToWindow()
|
|||||||
{
|
{
|
||||||
BView::AttachedToWindow();
|
BView::AttachedToWindow();
|
||||||
|
|
||||||
LayoutItems(0);
|
InvalidateLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -268,8 +268,10 @@ BMenu::AddItem(BMenuItem *item, int32 index)
|
|||||||
return err;
|
return err;
|
||||||
|
|
||||||
// Make sure we update the layout in case we are already attached.
|
// Make sure we update the layout in case we are already attached.
|
||||||
if (Window() && fResizeToFit)
|
if (Window() && fResizeToFit) {
|
||||||
LayoutItems(index);
|
LayoutItems(index);
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
// Find the root menu window, so we can install this item.
|
// Find the root menu window, so we can install this item.
|
||||||
BMenu *root = this;
|
BMenu *root = this;
|
||||||
@@ -720,6 +722,7 @@ BMenu::InvalidateLayout()
|
|||||||
{
|
{
|
||||||
CacheFontInfo();
|
CacheFontInfo();
|
||||||
LayoutItems(0);
|
LayoutItems(0);
|
||||||
|
Invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -847,7 +850,7 @@ BMenu::BMenu(BRect frame, const char *name, uint32 resizingMode, uint32 flags,
|
|||||||
fStickyMode(false),
|
fStickyMode(false),
|
||||||
fIgnoreHidden(true),
|
fIgnoreHidden(true),
|
||||||
fTriggerEnabled(true),
|
fTriggerEnabled(true),
|
||||||
fRedrawAfterSticky(true),
|
fRedrawAfterSticky(false),
|
||||||
fAttachAborted(false)
|
fAttachAborted(false)
|
||||||
{
|
{
|
||||||
InitData(NULL);
|
InitData(NULL);
|
||||||
@@ -997,15 +1000,16 @@ BMenu::operator=(const BMenu &)
|
|||||||
void
|
void
|
||||||
BMenu::InitData(BMessage *data)
|
BMenu::InitData(BMessage *data)
|
||||||
{
|
{
|
||||||
|
// TODO: Get _color, _fname, _fflt from the message, if present
|
||||||
BFont font;
|
BFont font;
|
||||||
font.SetFamilyAndStyle(sMenuInfo.f_family, sMenuInfo.f_style);
|
font.SetFamilyAndStyle(sMenuInfo.f_family, sMenuInfo.f_style);
|
||||||
font.SetSize(sMenuInfo.font_size);
|
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);
|
SetViewColor(sMenuInfo.background_color);
|
||||||
|
|
||||||
if (data) {
|
if (data != NULL) {
|
||||||
data->FindInt32("_layout", (int32 *)&fLayout);
|
data->FindInt32("_layout", (int32 *)&fLayout);
|
||||||
data->FindBool("_rsize_to_fit", &fResizeToFit);
|
data->FindBool("_rsize_to_fit", &fResizeToFit);
|
||||||
data->FindBool("_disable", &fEnabled);
|
data->FindBool("_disable", &fEnabled);
|
||||||
@@ -1051,7 +1055,7 @@ BMenu::_hide()
|
|||||||
BMenuItem *
|
BMenuItem *
|
||||||
BMenu::_track(int *action, long start)
|
BMenu::_track(int *action, long start)
|
||||||
{
|
{
|
||||||
// TODO: Take Sticky mode into account
|
// TODO: Take Sticky mode into account, handle submenus
|
||||||
BPoint location;
|
BPoint location;
|
||||||
ulong buttons;
|
ulong buttons;
|
||||||
BMenuItem *item = NULL;
|
BMenuItem *item = NULL;
|
||||||
@@ -1064,12 +1068,15 @@ BMenu::_track(int *action, long start)
|
|||||||
UnlockLooper();
|
UnlockLooper();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
SelectItem(item);
|
|
||||||
|
|
||||||
Draw(Bounds());
|
if (item != fSelected) {
|
||||||
|
SelectItem(item);
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
UnlockLooper();
|
UnlockLooper();
|
||||||
}
|
}
|
||||||
|
|
||||||
snooze(50000);
|
snooze(50000);
|
||||||
} while (buttons != 0);
|
} while (buttons != 0);
|
||||||
|
|
||||||
@@ -1080,6 +1087,11 @@ BMenu::_track(int *action, long start)
|
|||||||
*action = 5;
|
*action = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (LockLooper()) {
|
||||||
|
SelectItem(NULL);
|
||||||
|
UnlockLooper();
|
||||||
|
}
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1123,7 +1135,7 @@ BMenu::RemoveItems(int32 index, int32 count, BMenuItem *_item, bool del)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LayoutItems(0);
|
InvalidateLayout();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -1138,8 +1150,6 @@ BMenu::LayoutItems(int32 index)
|
|||||||
ComputeLayout(index, true, true, &width, &height);
|
ComputeLayout(index, true, true, &width, &height);
|
||||||
|
|
||||||
ResizeTo(width, height);
|
ResizeTo(width, height);
|
||||||
|
|
||||||
Invalidate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1402,12 +1412,20 @@ BMenu::Uninstall()
|
|||||||
void
|
void
|
||||||
BMenu::SelectItem(BMenuItem *menuItem, uint32 showSubmenu, bool selectFirstItem)
|
BMenu::SelectItem(BMenuItem *menuItem, uint32 showSubmenu, bool selectFirstItem)
|
||||||
{
|
{
|
||||||
if (menuItem != fSelected) {
|
// TODO: make use of "showSubmenu" and "selectFirstItem".
|
||||||
if (fSelected != NULL)
|
if (fSelected != NULL) {
|
||||||
fSelected->Select(false);
|
fSelected->Select(false);
|
||||||
menuItem->Select(true);
|
if (fSelected->Submenu() != NULL)
|
||||||
fSelected = menuItem;
|
fSelected->Submenu()->_hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (menuItem != NULL)
|
||||||
|
menuItem->Select(true);
|
||||||
|
|
||||||
|
fSelected = menuItem;
|
||||||
|
if (fSelected != NULL && fSelected->Submenu() != NULL)
|
||||||
|
fSelected->Submenu()->_show();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
// copy of this software and associated documentation files (the "Software"),
|
// copy of this software and associated documentation files (the "Software"),
|
||||||
@@ -137,21 +137,21 @@ void
|
|||||||
BMenuBar::Draw(BRect updateRect)
|
BMenuBar::Draw(BRect updateRect)
|
||||||
{
|
{
|
||||||
// TODO: implement additional border styles
|
// TODO: implement additional border styles
|
||||||
// Fix this function, the BMenuBar isn't drawn correctly
|
if (IsEnabled()) {
|
||||||
if (!IsEnabled()) {
|
|
||||||
LayoutItems(0);
|
|
||||||
Sync();
|
|
||||||
Invalidate();
|
|
||||||
} else {
|
|
||||||
BRect bounds(Bounds());
|
BRect bounds(Bounds());
|
||||||
|
|
||||||
PushState();
|
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));
|
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(0.0f, bounds.bottom - 2.0f), BPoint(0.0f, 0.0f));
|
||||||
StrokeLine(BPoint(bounds.right, 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),
|
StrokeLine(BPoint(1.0f, bounds.bottom - 1.0f),
|
||||||
BPoint(bounds.right, 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));
|
StrokeLine(BPoint(bounds.right, 0.0f), BPoint(bounds.right, bounds.bottom));
|
||||||
|
|
||||||
PopState();
|
PopState();
|
||||||
|
|
||||||
DrawItems(updateRect);
|
DrawItems(updateRect);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
LayoutItems(0);
|
||||||
|
Sync();
|
||||||
|
Invalidate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -398,14 +403,17 @@ BMenuBar::Track(int32 *action, int32 startIndex, bool showMenu)
|
|||||||
BPoint where;
|
BPoint where;
|
||||||
ulong buttons;
|
ulong buttons;
|
||||||
do {
|
do {
|
||||||
|
snooze(40000);
|
||||||
printf("BMenuBar: tracking...\n");
|
printf("BMenuBar: tracking...\n");
|
||||||
GetMouse(&where, &buttons);
|
GetMouse(&where, &buttons);
|
||||||
BMenuItem *menuItem = HitTestItems(where, B_ORIGIN);
|
BMenuItem *menuItem = HitTestItems(where, B_ORIGIN);
|
||||||
if (menuItem) {
|
if (menuItem) {
|
||||||
|
SelectItem(menuItem);
|
||||||
|
// TODO: Actually, this test shouldn't be needed, as
|
||||||
|
// all BMenuBar's BMenuItems are BMenus.
|
||||||
BMenu *menu = menuItem->Submenu();
|
BMenu *menu = menuItem->Submenu();
|
||||||
if (menu) {
|
if (menu) {
|
||||||
printf("BMenuBar: showing menu %s\n", menu->Name());
|
printf("BMenuBar: showing menu %s\n", menu->Name());
|
||||||
menu->Show();
|
|
||||||
do {
|
do {
|
||||||
snooze(40000);
|
snooze(40000);
|
||||||
GetMouse(&where, &buttons);
|
GetMouse(&where, &buttons);
|
||||||
@@ -414,7 +422,7 @@ BMenuBar::Track(int32 *action, int32 startIndex, bool showMenu)
|
|||||||
BMenuItem *testItem = HitTestItems(where, B_ORIGIN);
|
BMenuItem *testItem = HitTestItems(where, B_ORIGIN);
|
||||||
if (testItem != NULL && testItem != menuItem)
|
if (testItem != NULL && testItem != menuItem)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
resultItem = menu->_track((int *)action, startIndex);
|
resultItem = menu->_track((int *)action, startIndex);
|
||||||
printf("BMenuBar: menu %s: action: %ld\n", menu->Name(), *action);
|
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);
|
} while (*action != 5);
|
||||||
|
|
||||||
printf("BMenuBar: hiding menu %s\n", menu->Name());
|
printf("BMenuBar: hiding menu %s\n", menu->Name());
|
||||||
menu->_hide();
|
}
|
||||||
}
|
SelectItem(NULL);
|
||||||
}
|
Invalidate();
|
||||||
snooze(40000);
|
}
|
||||||
} while (buttons != 0);
|
} while (buttons != 0);
|
||||||
|
|
||||||
window->Unlock();
|
window->Unlock();
|
||||||
|
|||||||
Reference in New Issue
Block a user