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