BMenu and friends: style fixes

BMenuBar: style fix: msg => message

MenuPrivate: style fixes

MenuItem: 80 char limit style fix

MenuBar: tiny style fix

Menu: tiny style fix, indentation

Menu: Small refactor

Implement _SetIgnoreHidden() in header
Change on to ignoreHidden
Change on in _SetStickyMode to sticky

_BMCItem_: tiny whitespace style fix

Menu: style fixes, rename msgr => messenger

BMenu: style fix, pointer != NULL

BMenu::Archive rename ret to status

Also check pointer against NULL explicitly

BMenuItem style fixes: rename abbreviation, pointer style
This commit is contained in:
John Scipione
2016-07-31 19:42:39 -07:00
parent 17954f2e22
commit 61dfdec415
9 changed files with 64 additions and 62 deletions
+2 -1
View File
@@ -244,7 +244,8 @@ private:
bool keyDown = false);
bool _SelectNextItem(BMenuItem* item, bool forward);
BMenuItem* _NextItem(BMenuItem* item, bool forward) const;
void _SetIgnoreHidden(bool on);
void _SetIgnoreHidden(bool ignoreHidden)
{ fIgnoreHidden = ignoreHidden; };
void _SetStickyMode(bool on);
bool _IsStickyMode() const;
+1 -1
View File
@@ -63,7 +63,7 @@ public:
virtual void Draw(BRect updateRect);
virtual void MessageReceived(BMessage *message);
virtual void MessageReceived(BMessage* message);
virtual void MouseDown(BPoint where);
virtual void MouseUp(BPoint where);
+2 -2
View File
@@ -4,17 +4,17 @@
*/
#ifndef _MENU_ITEM_H
#define _MENU_ITEM_H
#include <Archivable.h>
#include <InterfaceDefs.h>
#include <Invoker.h>
#include <Menu.h>
class BMessage;
class BWindow;
class BMenuItem : public BArchivable, public BInvoker {
public:
BMenuItem(const char* label, BMessage* message,
+1
View File
@@ -70,4 +70,5 @@ private:
float fPreviousWidth;
};
#endif // _BMC_PRIVATE_H
+4 -3
View File
@@ -39,9 +39,9 @@ public:
_BMCItem_::_BMCItem_(BMessage* data)
: BMenuItem(data)
:
BMenuItem(data)
{
}
@@ -255,7 +255,8 @@ _BMCMenuBar_::MessageReceived(BMessage* message)
{
BMenuItem* item = ItemAt(0);
if (item && item->Submenu() && item->Submenu()->Window()) {
if (item != NULL && item->Submenu() != NULL
&& item->Submenu()->Window() != NULL) {
BMessage message(B_KEY_DOWN);
message.AddInt8("byte", B_ESCAPE);
+12 -19
View File
@@ -500,8 +500,8 @@ BMenu::KeyDown(const char* bytes, int32 numBytes)
// If we're at the top menu below the menu bar, pass
// the keypress to the menu bar so we can move to
// another top level menu.
BMessenger msgr(Supermenu());
msgr.SendMessage(Window()->CurrentMessage());
BMessenger messenger(Supermenu());
messenger.SendMessage(Window()->CurrentMessage());
} else {
// tell _Track
fState = MENU_STATE_KEY_LEAVE_SUBMENU;
@@ -526,8 +526,8 @@ BMenu::KeyDown(const char* bytes, int32 numBytes)
// item in the top menu below the menubar,
// pass the keypress to the menubar
// so you can use the keypress to switch menus.
BMessenger msgr(Supermenu());
msgr.SendMessage(Window()->CurrentMessage());
BMessenger messenger(Supermenu());
messenger.SendMessage(Window()->CurrentMessage());
}
}
break;
@@ -704,7 +704,7 @@ BMenu::AddItem(BMenuItem* item, int32 index)
"be called if the menu layout is not B_ITEMS_IN_MATRIX");
}
if (!item || !_AddItem(item, index))
if (item == NULL || !_AddItem(item, index))
return false;
InvalidateLayout();
@@ -2604,7 +2604,7 @@ BMenu::_ItemMarked(BMenuItem* item)
}
}
if (IsLabelFromMarked() && Superitem())
if (IsLabelFromMarked() && Superitem() != NULL)
Superitem()->SetLabel(item->Label());
}
@@ -2712,27 +2712,20 @@ BMenu::_NextItem(BMenuItem* item, bool forward) const
void
BMenu::_SetIgnoreHidden(bool on)
BMenu::_SetStickyMode(bool sticky)
{
fIgnoreHidden = on;
}
void
BMenu::_SetStickyMode(bool on)
{
if (fStickyMode == on)
if (fStickyMode == sticky)
return;
fStickyMode = on;
fStickyMode = sticky;
if (fSuper != NULL) {
// propagate the status to the super menu
fSuper->_SetStickyMode(on);
fSuper->_SetStickyMode(sticky);
} 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()) {
if (sticky && menuBar != NULL && menuBar->LockLooper()) {
// If we are switching to sticky mode,
// steal the focus from the current focus view
// (needed to handle keyboard navigation)
@@ -2938,7 +2931,7 @@ BMenu::_UpdateWindowViewSize(const bool &move)
} else {
_CacheFontInfo();
window->ResizeTo(StringWidth(BPrivate::kEmptyMenuLabel)
+ fPad.left + fPad.right,
+ fPad.left + fPad.right,
fFontHeight + fPad.top + fPad.bottom);
}
+4 -4
View File
@@ -297,9 +297,9 @@ BMenuBar::Draw(BRect updateRect)
void
BMenuBar::MessageReceived(BMessage* msg)
BMenuBar::MessageReceived(BMessage* message)
{
BMenu::MessageReceived(msg);
BMenu::MessageReceived(message);
}
@@ -460,7 +460,7 @@ void BMenuBar::_ReservedMenuBar3() {}
void BMenuBar::_ReservedMenuBar4() {}
BMenuBar &
BMenuBar&
BMenuBar::operator=(const BMenuBar &)
{
return *this;
@@ -743,7 +743,7 @@ BMenuBar::_InitData(menu_layout layout)
{
fBorders = BControlLook::B_ALL_BORDERS;
fLastBounds = new BRect(Bounds());
SetItemMargins(8, 2, 8, 2);
SetItemMargins(8.0f, 2.0f, 8.0f, 2.0f);
_SetIgnoreHidden(true);
SetLowUIColor(B_MENU_BACKGROUND_COLOR);
SetViewColor(B_TRANSPARENT_COLOR);
+28 -26
View File
@@ -27,11 +27,12 @@
#include "utf8_functions.h"
const float kLightBGTint = (B_LIGHTEN_1_TINT + B_LIGHTEN_1_TINT + B_NO_TINT) / 3.0;
const float kLightBGTint
= (B_LIGHTEN_1_TINT + B_LIGHTEN_1_TINT + B_NO_TINT) / 3.0;
// map control key shortcuts to drawable Unicode characters
// cf. http://unicode.org/charts/PDF/U2190.pdf
const char *kUTF8ControlMap[] = {
const char* kUTF8ControlMap[] = {
NULL,
"\xe2\x86\xb8", /* B_HOME U+21B8 */
NULL, NULL,
@@ -53,6 +54,7 @@ const char *kUTF8ControlMap[] = {
"\xe2\x86\x93", /* B_DOWN_ARROW */
};
using BPrivate::MenuPrivate;
BMenuItem::BMenuItem(const char* label, BMessage* message, char shortcut,
@@ -86,7 +88,7 @@ BMenuItem::BMenuItem(BMessage* data)
_InitData();
if (data->HasString("_label")) {
const char *string;
const char* string;
data->FindString("_label", &string);
SetLabel(string);
@@ -114,16 +116,16 @@ BMenuItem::BMenuItem(BMessage* data)
}
if (data->HasMessage("_msg")) {
BMessage *msg = new BMessage;
data->FindMessage("_msg", msg);
SetMessage(msg);
BMessage* message = new BMessage;
data->FindMessage("_msg", message);
SetMessage(message);
}
BMessage subMessage;
if (data->FindMessage("_submenu", &subMessage) == B_OK) {
BArchivable* object = instantiate_object(&subMessage);
if (object != NULL) {
BMenu* menu = dynamic_cast<BMenu *>(object);
BMenu* menu = dynamic_cast<BMenu*>(object);
if (menu != NULL)
_InitMenuData(menu);
}
@@ -144,36 +146,36 @@ BMenuItem::Instantiate(BMessage* data)
status_t
BMenuItem::Archive(BMessage* data, bool deep) const
{
status_t ret = BArchivable::Archive(data, deep);
status_t status = BArchivable::Archive(data, deep);
if (ret == B_OK && fLabel)
ret = data->AddString("_label", Label());
if (status == B_OK && fLabel)
status = data->AddString("_label", Label());
if (ret == B_OK && !IsEnabled())
ret = data->AddBool("_disable", true);
if (status == B_OK && !IsEnabled())
status = data->AddBool("_disable", true);
if (ret == B_OK && IsMarked())
ret = data->AddBool("_marked", true);
if (status == B_OK && IsMarked())
status = data->AddBool("_marked", true);
if (ret == B_OK && fUserTrigger)
ret = data->AddInt32("_user_trig", fUserTrigger);
if (status == B_OK && fUserTrigger)
status = data->AddInt32("_user_trig", fUserTrigger);
if (ret == B_OK && fShortcutChar) {
ret = data->AddInt32("_shortcut", fShortcutChar);
if (ret == B_OK)
ret = data->AddInt32("_mods", fModifiers);
if (status == B_OK && fShortcutChar) {
status = data->AddInt32("_shortcut", fShortcutChar);
if (status == B_OK)
status = data->AddInt32("_mods", fModifiers);
}
if (ret == B_OK && Message())
ret = data->AddMessage("_msg", Message());
if (status == B_OK && Message() != NULL)
status = data->AddMessage("_msg", Message());
if (ret == B_OK && deep && fSubmenu) {
if (status == B_OK && deep && fSubmenu) {
BMessage submenu;
if (fSubmenu->Archive(&submenu, true) == B_OK)
ret = data->AddMessage("_submenu", &submenu);
status = data->AddMessage("_submenu", &submenu);
}
return ret;
return status;
}
@@ -488,7 +490,7 @@ BMenuItem::Draw()
if (fShortcutChar)
_DrawShortcutSymbol();
if (Submenu())
if (Submenu() != NULL)
_DrawSubmenuSymbol();
}
+10 -6
View File
@@ -119,7 +119,7 @@ MenuPrivate::SetLayout(menu_layout layout)
void
MenuPrivate::ItemMarked(BMenuItem *item)
MenuPrivate::ItemMarked(BMenuItem* item)
{
fMenu->_ItemMarked(item);
}
@@ -214,14 +214,15 @@ MenuPrivate::QuitTracking(bool thisMenuOnly)
status_t
MenuPrivate::CreateBitmaps()
{
BRect smallRect(0, 0, 16, 10);
BRect smallRect(0.0f, 0.0f, 16.0f, 10.0f);
try {
sMenuItemShift = new BBitmap(BRect(0, 0, 23, 10), B_CMAP8);
sMenuItemControl = new BBitmap(BRect(0, 0, 21, 10), B_CMAP8);
sMenuItemShift = new BBitmap(BRect(0.0f, 0.0f, 23.0f, 10.0f), B_CMAP8);
sMenuItemControl = new BBitmap(BRect(0.0f, 0.0f, 21.0f, 10.0f),
B_CMAP8);
sMenuItemOption = new BBitmap(smallRect, B_CMAP8);
sMenuItemAlt = new BBitmap(smallRect, B_CMAP8);
sMenuItemMenu = new BBitmap(BRect(0, 0, 22, 10), B_CMAP8);
sMenuItemMenu = new BBitmap(BRect(0.0f, 0.0f, 22.0f, 10.0f), B_CMAP8);
} catch (...) {
return B_NO_MEMORY;
}
@@ -236,7 +237,7 @@ MenuPrivate::CreateBitmaps()
17, 0, B_CMAP8);
sMenuItemMenu->ImportBits(kMenuBits, sizeof(kMenuBits),
23, 0, B_CMAP8);
return B_OK;
}
@@ -269,6 +270,7 @@ MenuPrivate::MenuItemControl()
case 0x5d:
case 0x5f:
return sMenuItemAlt;
case 0x66:
case 0x67:
return sMenuItemOption;
@@ -286,6 +288,7 @@ MenuPrivate::MenuItemOption()
case 0x5c:
case 0x60:
return sMenuItemControl;
case 0x66:
case 0x67:
return sMenuItemOption;
@@ -303,6 +306,7 @@ MenuPrivate::MenuItemCommand()
case 0x5c:
case 0x60:
return sMenuItemControl;
case 0x66:
case 0x67:
return sMenuItemOption;