Fixed a bug in menu tracking: in some cases you had a goal of 1 pixel when trying to enter a submenu ( http://flickr.com/photos/johndrinkwater/131805244 )

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17181 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2006-04-20 20:56:57 +00:00
parent a445243cff
commit 48688dcd5f
+60 -31
View File
@@ -187,7 +187,34 @@ BMenu::~BMenu()
BMenu::BMenu(BMessage *archive) BMenu::BMenu(BMessage *archive)
: BView(archive) : BView(archive),
fChosenItem(NULL),
fPad(14.0f, 2.0f, 20.0f, 0.0f),
fSelected(NULL),
fCachedMenuWindow(NULL),
fSuper(NULL),
fSuperitem(NULL),
fAscent(-1.0f),
fDescent(-1.0f),
fFontHeight(-1.0f),
fState(0),
fLayout(B_ITEMS_IN_ROW),
fExtraRect(NULL),
fMaxContentWidth(0.0f),
fInitMatrixSize(NULL),
fExtraMenuData(NULL),
fTrigger(0),
fResizeToFit(true),
fUseCachedMenuLayout(false),
fEnabled(true),
fDynamicName(false),
fRadioMode(false),
fTrackNewBounds(false),
fStickyMode(false),
fIgnoreHidden(true),
fTriggerEnabled(true),
fRedrawAfterSticky(false),
fAttachAborted(false)
{ {
InitData(archive); InitData(archive);
} }
@@ -1144,8 +1171,6 @@ BMenu::_track(int *action, bigtime_t trackTime, long start)
{ {
// TODO: cleanup // TODO: cleanup
BMenuItem *item = NULL; BMenuItem *item = NULL;
int localAction = MENU_ACT_NONE;
bigtime_t openTime = system_time(); bigtime_t openTime = system_time();
bigtime_t closeTime = openTime; bigtime_t closeTime = openTime;
@@ -1159,7 +1184,7 @@ BMenu::_track(int *action, bigtime_t trackTime, long start)
bigtime_t snoozeAmount = 50000; bigtime_t snoozeAmount = 50000;
BPoint location; BPoint location;
ulong buttons; ulong buttons;
GetMouse(&location, &buttons, false); GetMouse(&location, &buttons, true);
BPoint screenLocation = ConvertToScreen(location); BPoint screenLocation = ConvertToScreen(location);
item = HitTestItems(location, B_ORIGIN); item = HitTestItems(location, B_ORIGIN);
@@ -1179,10 +1204,30 @@ BMenu::_track(int *action, bigtime_t trackTime, long start)
fState = MENU_ACT_SUBMENU; fState = MENU_ACT_SUBMENU;
closeTime = system_time(); closeTime = system_time();
} }
} else { }
// Track the submenu
if (fSelected != NULL && OverSubmenu(fSelected, screenLocation)) {
UnlockLooper();
locked = false;
int submenuAction = MENU_ACT_NONE;
if (IsStickyMode())
fSelected->Submenu()->SetStickyMode(true);
BMenuItem *submenuItem = fSelected->Submenu()->_track(&submenuAction, trackTime);
if (submenuAction == MENU_ACT_CLOSE) {
item = submenuItem;
fState = submenuAction;
break;
}
locked = LockLooper();
if (!locked)
break;
}
if (item == NULL) {
if (OverSuper(screenLocation)) { if (OverSuper(screenLocation)) {
localAction = MENU_ACT_NONE; fState = MENU_ACT_NONE;
item = NULL;
UnlockLooper(); UnlockLooper();
break; break;
} }
@@ -1193,43 +1238,27 @@ BMenu::_track(int *action, bigtime_t trackTime, long start)
} }
} }
if (fSelected != NULL && OverSubmenu(fSelected, screenLocation)) {
UnlockLooper();
locked = false;
int submenuAction = MENU_ACT_NONE;
if (IsStickyMode())
fSelected->Submenu()->SetStickyMode(true);
BMenuItem *submenuItem = fSelected->Submenu()->_track(&submenuAction, trackTime);
if (submenuAction == MENU_ACT_CLOSE) {
item = submenuItem;
localAction = submenuAction;
break;
}
}
if (locked) if (locked)
UnlockLooper(); UnlockLooper();
snooze(snoozeAmount); snooze(snoozeAmount);
if (buttons != 0 && IsStickyMode()) { if (buttons != 0 && IsStickyMode()) {
localAction = MENU_ACT_CLOSE; fState = MENU_ACT_CLOSE;
break; break;
} else if (buttons == 0 && !IsStickyMode()) { } else if (buttons == 0 && !IsStickyMode()) {
if (system_time() < trackTime + 1000000 if (system_time() < trackTime + 1000000
|| (fExtraRect != NULL && fExtraRect->Contains(location))) || (fExtraRect != NULL && fExtraRect->Contains(location)))
SetStickyMode(true); SetStickyMode(true);
else { else {
localAction = MENU_ACT_CLOSE; fState = MENU_ACT_CLOSE;
break; break;
} }
} }
} }
fState = MENU_ACT_CLOSE;
if (action != NULL) if (action != NULL)
*action = localAction; *action = fState;
if (LockLooper()) { if (LockLooper()) {
SelectItem(NULL); SelectItem(NULL);
@@ -1375,7 +1404,7 @@ BMenu::ComputeLayout(int32 index, bool bestFit, bool moveItems,
case B_ITEMS_IN_COLUMN: case B_ITEMS_IN_COLUMN:
{ {
for (int32 i = 0; i < fItems.CountItems(); i++) { for (int32 i = 0; i < fItems.CountItems(); i++) {
item = ItemAt(i); item = ItemAt(i);
if (item != NULL) { if (item != NULL) {
item->GetContentSize(&iWidth, &iHeight); item->GetContentSize(&iWidth, &iHeight);
@@ -1393,10 +1422,10 @@ BMenu::ComputeLayout(int32 index, bool bestFit, bool moveItems,
if (fMaxContentWidth > 0) if (fMaxContentWidth > 0)
frame.right = min_c(frame.right, fMaxContentWidth); frame.right = min_c(frame.right, fMaxContentWidth);
if (moveItems) { //if (moveItems) {
for (int32 i = 0; i < fItems.CountItems(); i++) for (int32 i = 0; i < fItems.CountItems(); i++)
ItemAt(i)->fBounds.right = frame.right; ItemAt(i)->fBounds.right = frame.right;
} //}
frame.right = ceilf(frame.right); frame.right = ceilf(frame.right);
frame.bottom--; frame.bottom--;
break; break;
@@ -1422,10 +1451,10 @@ BMenu::ComputeLayout(int32 index, bool bestFit, bool moveItems,
} }
} }
if (moveItems) { //if (moveItems) {
for (int32 i = 0; i < fItems.CountItems(); i++) for (int32 i = 0; i < fItems.CountItems(); i++)
ItemAt(i)->fBounds.bottom = frame.bottom; ItemAt(i)->fBounds.bottom = frame.bottom;
} //}
frame.right = ceilf(frame.right); frame.right = ceilf(frame.right);
break; break;