Menu and friends: Style fixes, no functional
... changes intended. * 80 char limit fixes * Indentation fixes * Braces style fixes * Use ternary operator where appropriate * Rename menuItem to just item and declare it once outside the loop * Omit 3rd param of GetMouse() because it is default * Rename variables eg state => focused and menu => submenu * Indent comments below line they apply to * Reword some comments * Add some #pragmas
This commit is contained in:
+40
-38
@@ -476,7 +476,7 @@ BMenu::MessageReceived(BMessage* msg)
|
||||
void
|
||||
BMenu::KeyDown(const char* bytes, int32 numBytes)
|
||||
{
|
||||
// TODO: Test how it works on beos and implement it correctly
|
||||
// TODO: Test how it works on BeOS R5 and implement this correctly
|
||||
switch (bytes[0]) {
|
||||
case B_UP_ARROW:
|
||||
if (fLayout == B_ITEMS_IN_COLUMN)
|
||||
@@ -484,16 +484,16 @@ BMenu::KeyDown(const char* bytes, int32 numBytes)
|
||||
break;
|
||||
|
||||
case B_DOWN_ARROW:
|
||||
{
|
||||
BMenuBar* bar = dynamic_cast<BMenuBar*>(Supermenu());
|
||||
if (bar != NULL && fState == MENU_STATE_CLOSED) {
|
||||
// tell MenuBar's _Track:
|
||||
bar->fState = MENU_STATE_KEY_TO_SUBMENU;
|
||||
}
|
||||
{
|
||||
BMenuBar* bar = dynamic_cast<BMenuBar*>(Supermenu());
|
||||
if (bar != NULL && fState == MENU_STATE_CLOSED) {
|
||||
// tell MenuBar's _Track:
|
||||
bar->fState = MENU_STATE_KEY_TO_SUBMENU;
|
||||
}
|
||||
if (fLayout == B_ITEMS_IN_COLUMN)
|
||||
_SelectNextItem(fSelected, true);
|
||||
break;
|
||||
}
|
||||
|
||||
case B_LEFT_ARROW:
|
||||
if (fLayout == B_ITEMS_IN_ROW)
|
||||
@@ -520,7 +520,7 @@ BMenu::KeyDown(const char* bytes, int32 numBytes)
|
||||
if (fLayout == B_ITEMS_IN_ROW)
|
||||
_SelectNextItem(fSelected, true);
|
||||
else {
|
||||
if (fSelected && fSelected->Submenu()) {
|
||||
if (fSelected != NULL && fSelected->Submenu() != NULL) {
|
||||
fSelected->Submenu()->_SetStickyMode(true);
|
||||
// fix me: this shouldn't be needed but dynamic menus
|
||||
// aren't getting it set correctly when keyboard
|
||||
@@ -555,19 +555,20 @@ BMenu::KeyDown(const char* bytes, int32 numBytes)
|
||||
|
||||
case B_ENTER:
|
||||
case B_SPACE:
|
||||
if (fSelected) {
|
||||
// preserve for exit handling
|
||||
if (fSelected != NULL) {
|
||||
fChosenItem = fSelected;
|
||||
// preserve for exit handling
|
||||
_QuitTracking(false);
|
||||
}
|
||||
break;
|
||||
|
||||
case B_ESCAPE:
|
||||
_SelectItem(NULL);
|
||||
if (fState == MENU_STATE_CLOSED && dynamic_cast<BMenuBar*>(Supermenu())) {
|
||||
if (fState == MENU_STATE_CLOSED
|
||||
&& dynamic_cast<BMenuBar*>(Supermenu())) {
|
||||
// Keyboard may show menu without tracking it
|
||||
BMessenger msgr(Supermenu());
|
||||
msgr.SendMessage(Window()->CurrentMessage());
|
||||
BMessenger messenger(Supermenu());
|
||||
messenger.SendMessage(Window()->CurrentMessage());
|
||||
} else
|
||||
_QuitTracking(false);
|
||||
break;
|
||||
@@ -1585,11 +1586,10 @@ BMenu::_Hide()
|
||||
else
|
||||
#endif
|
||||
window->Quit();
|
||||
// it's our window, quit it
|
||||
// it's our window, quit it
|
||||
|
||||
|
||||
// Delete the menu window used by our submenus
|
||||
_DeleteMenuWindow();
|
||||
// Delete the menu window used by our submenus
|
||||
}
|
||||
|
||||
|
||||
@@ -1611,8 +1611,8 @@ BMenu::_Track(int* action, long start)
|
||||
bigtime_t navigationAreaTime = 0;
|
||||
|
||||
fState = MENU_STATE_TRACKING;
|
||||
// we will use this for keyboard selection:
|
||||
fChosenItem = NULL;
|
||||
// we will use this for keyboard selection
|
||||
|
||||
BPoint location;
|
||||
uint32 buttons = 0;
|
||||
@@ -1642,7 +1642,7 @@ BMenu::_Track(int* action, long start)
|
||||
// then if the mouse is inside this menu,
|
||||
// then if it's over a super menu.
|
||||
if (_OverSubmenu(fSelected, screenLocation)
|
||||
|| fState == MENU_STATE_KEY_TO_SUBMENU) {
|
||||
|| fState == MENU_STATE_KEY_TO_SUBMENU) {
|
||||
if (fState == MENU_STATE_TRACKING) {
|
||||
// not if from R.Arrow
|
||||
fState = MENU_STATE_TRACKING_SUBMENU;
|
||||
@@ -1669,7 +1669,7 @@ BMenu::_Track(int* action, long start)
|
||||
fState = MENU_STATE_CLOSED;
|
||||
} else if (submenuAction == MENU_STATE_KEY_LEAVE_SUBMENU) {
|
||||
if (LockLooper()) {
|
||||
BMenuItem *temp = fSelected;
|
||||
BMenuItem* temp = fSelected;
|
||||
// close the submenu:
|
||||
_SelectItem(NULL);
|
||||
// but reselect the item itself for user:
|
||||
@@ -1686,14 +1686,16 @@ BMenu::_Track(int* action, long start)
|
||||
_UpdateStateOpenSelect(item, location, navAreaRectAbove,
|
||||
navAreaRectBelow, selectedTime, navigationAreaTime);
|
||||
releasedOnce = true;
|
||||
} else if (_OverSuper(screenLocation) && fSuper->fState != MENU_STATE_KEY_TO_SUBMENU) {
|
||||
} else if (_OverSuper(screenLocation)
|
||||
&& fSuper->fState != MENU_STATE_KEY_TO_SUBMENU) {
|
||||
fState = MENU_STATE_TRACKING;
|
||||
UnlockLooper();
|
||||
break;
|
||||
} else if (fState == MENU_STATE_KEY_LEAVE_SUBMENU) {
|
||||
UnlockLooper();
|
||||
break;
|
||||
} else if (fSuper == NULL || fSuper->fState != MENU_STATE_KEY_TO_SUBMENU) {
|
||||
} else if (fSuper == NULL
|
||||
|| fSuper->fState != MENU_STATE_KEY_TO_SUBMENU) {
|
||||
// Mouse pointer outside menu:
|
||||
// If there's no other submenu opened,
|
||||
// deselect the current selected item
|
||||
@@ -1733,7 +1735,7 @@ BMenu::_Track(int* action, long start)
|
||||
UnlockLooper();
|
||||
} while (newLocation == location && newButtons == buttons
|
||||
&& !(item != NULL && item->Submenu() != NULL
|
||||
&& item->Submenu()->Window() == NULL)
|
||||
&& item->Submenu()->Window() == NULL)
|
||||
&& fState == MENU_STATE_TRACKING);
|
||||
|
||||
if (newLocation != location || newButtons != buttons) {
|
||||
@@ -1754,9 +1756,10 @@ BMenu::_Track(int* action, long start)
|
||||
// keyboard Enter will set this
|
||||
if (fChosenItem != NULL)
|
||||
item = fChosenItem;
|
||||
else if (fSelected == NULL)
|
||||
else if (fSelected == NULL) {
|
||||
// needed to cover (rare) mouse/ESC combination
|
||||
item = NULL;
|
||||
}
|
||||
|
||||
if (fSelected != NULL && LockLooper()) {
|
||||
_SelectItem(NULL);
|
||||
@@ -2591,12 +2594,12 @@ BMenu::_Uninstall()
|
||||
|
||||
|
||||
void
|
||||
BMenu::_SelectItem(BMenuItem* menuItem, bool showSubmenu,
|
||||
bool selectFirstItem, bool keyDown)
|
||||
BMenu::_SelectItem(BMenuItem* item, bool showSubmenu, bool selectFirstItem,
|
||||
bool keyDown)
|
||||
{
|
||||
// Avoid deselecting and then reselecting the same item
|
||||
// which would cause flickering
|
||||
if (menuItem != fSelected) {
|
||||
if (item != fSelected) {
|
||||
if (fSelected != NULL) {
|
||||
fSelected->Select(false);
|
||||
BMenu* subMenu = fSelected->Submenu();
|
||||
@@ -2604,7 +2607,7 @@ BMenu::_SelectItem(BMenuItem* menuItem, bool showSubmenu,
|
||||
subMenu->_Hide();
|
||||
}
|
||||
|
||||
fSelected = menuItem;
|
||||
fSelected = item;
|
||||
if (fSelected != NULL)
|
||||
fSelected->Select(true);
|
||||
}
|
||||
@@ -2632,10 +2635,8 @@ BMenu::_SelectNextItem(BMenuItem* item, bool forward)
|
||||
if (nextItem == NULL)
|
||||
return false;
|
||||
|
||||
bool openMenu = false;
|
||||
if (dynamic_cast<BMenuBar*>(this) != NULL)
|
||||
openMenu = true;
|
||||
_SelectItem(nextItem, openMenu);
|
||||
_SelectItem(nextItem, dynamic_cast<BMenuBar*>(this) != NULL);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2688,15 +2689,15 @@ BMenu::_SetStickyMode(bool on)
|
||||
|
||||
fStickyMode = on;
|
||||
|
||||
// If we are switching to sticky mode, propagate the status
|
||||
// back to the super menu
|
||||
if (fSuper != NULL)
|
||||
if (fSuper != NULL) {
|
||||
// propagate the status to the super menu
|
||||
fSuper->_SetStickyMode(on);
|
||||
else {
|
||||
// TODO: Ugly hack, but it needs to be done right here in this method
|
||||
} else {
|
||||
// TODO: Ugly hack, but it needs to be done in this method
|
||||
BMenuBar* menuBar = dynamic_cast<BMenuBar*>(this);
|
||||
if (on && menuBar != NULL && menuBar->LockLooper()) {
|
||||
// Steal the focus from the current focus view
|
||||
// If we are switching to sticky mode,
|
||||
// steal the focus from the current focus view
|
||||
// (needed to handle keyboard navigation)
|
||||
menuBar->_StealFocus();
|
||||
menuBar->UnlockLooper();
|
||||
@@ -2946,8 +2947,9 @@ BMenu::_OkToProceed(BMenuItem* item, bool keyDown)
|
||||
if ((buttons != 0 && stickyMode)
|
||||
|| ((dynamic_cast<BMenuBar*>(this) == NULL
|
||||
&& (buttons == 0 && !stickyMode))
|
||||
|| ((_HitTestItems(where) != item) && !keyDown)))
|
||||
|| ((_HitTestItems(where) != item) && !keyDown))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user