Style fixes to BMenu and related classes.

This commit is contained in:
John Scipione 2013-05-06 16:50:23 -04:00
parent 3f5d1e7825
commit d97b434060
7 changed files with 75 additions and 77 deletions

View File

@ -10,6 +10,7 @@
#include <List.h>
#include <View.h>
class BMenu;
class BMenuBar;
class BMenuItem;
@ -216,7 +217,7 @@ private:
void _ComputeColumnLayout(int32 index, bool bestFit,
bool moveItems, BRect* override, BRect& outRect);
void _ComputeRowLayout(int32 index, bool bestFit,
bool moveItems, BRect& outRect);
bool moveItems, BRect& outRect);
void _ComputeMatrixLayout(BRect& outRect);
BRect _CalcFrame(BPoint where, bool* scrollOn);

View File

@ -35,7 +35,7 @@ public:
virtual status_t Archive(BMessage* archive,
bool deep = true) const;
virtual void Draw(BRect update);
virtual void Draw(BRect updateRect);
virtual void AttachedToWindow();
virtual void AllAttached();
virtual void MouseDown(BPoint where);
@ -121,7 +121,7 @@ private:
void InitObject(const char* label);
void InitObject2();
void DrawLabel(BRect bounds, BRect update);
void DrawLabel(BRect bounds, BRect updateRect);
static void InitMenu(BMenu* menu);
int32 _MenuTask();

View File

@ -271,7 +271,6 @@ _BMCMenuBar_::FrameResized(float width, float height)
dirty = Bounds();
dirty.left = dirty.right - diff - 12;
Invalidate(dirty);
} else if (diff < 0) {
// clean up the dirty right line of
// the menu field when shrinking
@ -295,6 +294,7 @@ _BMCMenuBar_::FrameResized(float width, float height)
diff = Frame().right + 2 - fMenuField->Bounds().right;
fMenuField->ResizeBy(diff, 0.0);
}
BMenuBar::FrameResized(width, height);
}

View File

@ -733,7 +733,7 @@ BMenu::AddItem(BMenuItem* item, BRect frame)
"be called if the menu layout is B_ITEMS_IN_MATRIX");
}
if (!item)
if (item == NULL)
return false;
item->fBounds = frame;
@ -758,7 +758,7 @@ bool
BMenu::AddItem(BMenu* submenu)
{
BMenuItem* item = new (nothrow) BMenuItem(submenu);
if (!item)
if (item == NULL)
return false;
if (!AddItem(item, CountItems())) {
@ -780,7 +780,7 @@ BMenu::AddItem(BMenu* submenu, int32 index)
}
BMenuItem* item = new (nothrow) BMenuItem(submenu);
if (!item)
if (item == NULL)
return false;
if (!AddItem(item, index)) {
@ -802,7 +802,7 @@ BMenu::AddItem(BMenu* submenu, BRect frame)
}
BMenuItem* item = new (nothrow) BMenuItem(submenu);
if (!item)
if (item == NULL)
return false;
if (!AddItem(item, frame)) {
@ -2848,7 +2848,8 @@ BMenu::_UpdateWindowViewSize(const bool &move)
return;
bool scroll = false;
const BPoint screenLocation = move ? ScreenLocation() : window->Frame().LeftTop();
const BPoint screenLocation = move ? ScreenLocation()
: window->Frame().LeftTop();
BRect frame = _CalcFrame(screenLocation, &scroll);
ResizeTo(frame.Width(), frame.Height());
@ -3024,4 +3025,3 @@ B_IF_GCC_2(InvalidateLayout__5BMenub,_ZN5BMenu16InvalidateLayoutEb)(
{
menu->InvalidateLayout();
}

View File

@ -353,12 +353,12 @@ BMenuField::AllUnarchived(const BMessage* from)
void
BMenuField::Draw(BRect update)
BMenuField::Draw(BRect updateRect)
{
BRect bounds(Bounds());
bool active = IsFocus() && Window()->IsActive();
DrawLabel(bounds, update);
DrawLabel(bounds, updateRect);
BRect frame(fMenuBar->Frame());
@ -370,7 +370,7 @@ BMenuField::Draw(BRect update)
flags |= BControlLook::B_DISABLED;
if (active)
flags |= BControlLook::B_FOCUSED;
be_control_look->DrawMenuFieldFrame(this, frame, update, base,
be_control_look->DrawMenuFieldFrame(this, frame, updateRect, base,
background, flags);
}
@ -423,7 +423,7 @@ BMenuField::MouseDown(BPoint where)
fMenuBar->StartMenuBar(-1, false, true, &bounds);
fMenuTaskID = spawn_thread((thread_func)_thread_entry,
"_m_task_", B_NORMAL_PRIORITY, this);
"_m_task_", B_NORMAL_PRIORITY, this);
if (fMenuTaskID >= 0)
resume_thread(fMenuTaskID);
}
@ -473,9 +473,9 @@ BMenuField::MakeFocus(bool state)
void
BMenuField::MessageReceived(BMessage* msg)
BMenuField::MessageReceived(BMessage* message)
{
BView::MessageReceived(msg);
BView::MessageReceived(message);
}
@ -980,7 +980,7 @@ BMenuField::InitObject2()
void
BMenuField::DrawLabel(BRect bounds, BRect update)
BMenuField::DrawLabel(BRect bounds, BRect updateRect)
{
CALLED();
@ -1107,8 +1107,8 @@ BMenuField::_InitMenuBar(BMenu* menu, BRect frame, bool fixedSize)
fMenu = menu;
InitMenu(menu);
if ((Flags() & B_SUPPORTS_LAYOUT)) {
fMenuBar = new _BMCMenuBar_(fixedSize, this);
if ((Flags() & B_SUPPORTS_LAYOUT) != 0) {
fMenuBar = new _BMCMenuBar_(this);
} else {
frame.left = _MenuBarOffset();
frame.top = kVMargin;
@ -1147,7 +1147,7 @@ BMenuField::_InitMenuBar(const BMessage* archive)
fFixedSizeMB = fixed;
fMenuBar = (BMenuBar*)FindView("_mc_mb_");
if (!fMenuBar) {
if (fMenuBar == NULL) {
_InitMenuBar(new BMenu(""), BRect(0, 0, 100, 15), fFixedSizeMB);
InitObject2();
} else {
@ -1194,8 +1194,8 @@ BMenuField::_ValidateLayoutData()
divider = fLayoutData->label_width + 5;
// If we shan't do real layout, we let the current divider take influence.
if (!(Flags() & B_SUPPORTS_LAYOUT))
divider = max_c(divider, fDivider);
if ((Flags() & B_SUPPORTS_LAYOUT) == 0)
divider = std::max(divider, fDivider);
// get the minimal (== preferred) menu bar size
// TODO: BMenu::MinSize() is using the ResizeMode() to decide the

View File

@ -55,8 +55,8 @@ const char *kUTF8ControlMap[] = {
using BPrivate::MenuPrivate;
BMenuItem::BMenuItem(const char *label, BMessage *message, char shortcut,
uint32 modifiers)
BMenuItem::BMenuItem(const char* label, BMessage* message, char shortcut,
uint32 modifiers)
{
_InitData();
if (label != NULL)
@ -73,7 +73,7 @@ BMenuItem::BMenuItem(const char *label, BMessage *message, char shortcut,
}
BMenuItem::BMenuItem(BMenu *menu, BMessage *message)
BMenuItem::BMenuItem(BMenu* menu, BMessage* message)
{
_InitData();
SetMessage(message);
@ -81,7 +81,7 @@ BMenuItem::BMenuItem(BMenu *menu, BMessage *message)
}
BMenuItem::BMenuItem(BMessage *data)
BMenuItem::BMenuItem(BMessage* data)
{
_InitData();
@ -121,9 +121,9 @@ BMenuItem::BMenuItem(BMessage *data)
BMessage subMessage;
if (data->FindMessage("_submenu", &subMessage) == B_OK) {
BArchivable *object = instantiate_object(&subMessage);
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);
}
@ -131,8 +131,8 @@ BMenuItem::BMenuItem(BMessage *data)
}
BArchivable *
BMenuItem::Instantiate(BMessage *data)
BArchivable*
BMenuItem::Instantiate(BMessage* data)
{
if (validate_instantiation(data, "BMenuItem"))
return new BMenuItem(data);
@ -142,7 +142,7 @@ BMenuItem::Instantiate(BMessage *data)
status_t
BMenuItem::Archive(BMessage *data, bool deep) const
BMenuItem::Archive(BMessage* data, bool deep) const
{
status_t ret = BArchivable::Archive(data, deep);
@ -217,7 +217,7 @@ BMenuItem::SetEnabled(bool state)
if (fSubmenu != NULL)
fSubmenu->SetEnabled(state);
BMenu *menu = Menu();
BMenu* menu = fSuper;
if (menu != NULL && menu->LockLooper()) {
menu->Invalidate(fBounds);
menu->UnlockLooper();
@ -230,8 +230,8 @@ BMenuItem::SetMarked(bool state)
{
fMark = state;
if (state && Menu() != NULL) {
MenuPrivate priv(Menu());
if (state && fSuper != NULL) {
MenuPrivate priv(fSuper);
priv.ItemMarked(this);
}
}
@ -292,7 +292,7 @@ BMenuItem::SetShortcut(char ch, uint32 modifiers)
}
const char *
const char*
BMenuItem::Label() const
{
return fLabel;
@ -308,7 +308,7 @@ BMenuItem::IsEnabled() const
if (!fEnabled)
return false;
return fSuper ? fSuper->IsEnabled() : true;
return fSuper != NULL ? fSuper->IsEnabled() : true;
}
@ -327,7 +327,7 @@ BMenuItem::Trigger() const
char
BMenuItem::Shortcut(uint32 *modifiers) const
BMenuItem::Shortcut(uint32* modifiers) const
{
if (modifiers)
*modifiers = fModifiers;
@ -336,14 +336,14 @@ BMenuItem::Shortcut(uint32 *modifiers) const
}
BMenu *
BMenu*
BMenuItem::Submenu() const
{
return fSubmenu;
}
BMenu *
BMenu*
BMenuItem::Menu() const
{
return fSuper;
@ -369,9 +369,8 @@ BMenuItem::GetContentSize(float* width, float* height)
if (width)
*width = (float)ceil(fCachedWidth);
if (height) {
if (height)
*height = MenuPrivate(fSuper).FontHeight();
}
}
@ -452,8 +451,7 @@ BMenuItem::Draw()
bool selected = IsSelected();
// set low color and fill background if selected
bool activated = selected && (enabled || Submenu())
/*&& fSuper->fRedrawAfterSticky*/;
bool activated = selected && (enabled || Submenu());
if (activated) {
if (be_control_look != NULL) {
BRect rect = Frame();
@ -500,7 +498,7 @@ BMenuItem::Draw()
void
BMenuItem::Highlight(bool flag)
{
Menu()->Invalidate(Frame());
fSuper->Invalidate(Frame());
}
@ -514,10 +512,9 @@ BMenuItem::IsSelected() const
BPoint
BMenuItem::ContentLocation() const
{
const BRect &padding = MenuPrivate(fSuper).Padding();
const BRect& padding = MenuPrivate(fSuper).Padding();
return BPoint(fBounds.left + padding.left,
fBounds.top + padding.top);
return BPoint(fBounds.left + padding.left, fBounds.top + padding.top);
}
@ -532,7 +529,7 @@ BMenuItem::BMenuItem(const BMenuItem &)
}
BMenuItem &
BMenuItem&
BMenuItem::operator=(const BMenuItem &)
{
return *this;
@ -559,13 +556,13 @@ BMenuItem::_InitData()
void
BMenuItem::_InitMenuData(BMenu *menu)
BMenuItem::_InitMenuData(BMenu* menu)
{
fSubmenu = menu;
MenuPrivate(fSubmenu).SetSuperItem(this);
BMenuItem *item = menu->FindMarked();
BMenuItem* item = menu->FindMarked();
if (menu->IsRadioMode() && menu->IsLabelFromMarked() && item != NULL)
SetLabel(item->Label());
@ -575,11 +572,10 @@ BMenuItem::_InitMenuData(BMenu *menu)
void
BMenuItem::Install(BWindow *window)
BMenuItem::Install(BWindow* window)
{
if (fSubmenu) {
if (fSubmenu != NULL)
MenuPrivate(fSubmenu).Install(window);
}
fWindow = window;
@ -592,7 +588,7 @@ BMenuItem::Install(BWindow *window)
status_t
BMenuItem::Invoke(BMessage *message)
BMenuItem::Invoke(BMessage* message)
{
if (!IsEnabled())
return B_ERROR;
@ -606,21 +602,21 @@ BMenuItem::Invoke(BMessage *message)
BMessage clone(kind);
status_t err = B_BAD_VALUE;
if (!message && !notify)
if (message == NULL && !notify)
message = Message();
if (!message) {
if (message == NULL) {
if (!fSuper->IsWatched())
return err;
} else
clone = *message;
clone.AddInt32("index", Menu()->IndexOf(this));
clone.AddInt32("index", fSuper->IndexOf(this));
clone.AddInt64("when", (int64)system_time());
clone.AddPointer("source", this);
clone.AddMessenger("be:sender", BMessenger(fSuper));
if (message)
if (message != NULL)
err = BInvoker::Invoke(&clone);
// TODO: assynchronous messaging
@ -633,31 +629,32 @@ BMenuItem::Invoke(BMessage *message)
void
BMenuItem::Uninstall()
{
if (fSubmenu != NULL) {
if (fSubmenu != NULL)
MenuPrivate(fSubmenu).Uninstall();
}
if (Target() == fWindow)
SetTarget(BMessenger());
if (fShortcutChar != 0 && (fModifiers & B_COMMAND_KEY) != 0
&& fWindow != NULL)
&& fWindow != NULL) {
fWindow->RemoveShortcut(fShortcutChar, fModifiers);
}
fWindow = NULL;
}
void
BMenuItem::SetSuper(BMenu *super)
BMenuItem::SetSuper(BMenu* super)
{
if (fSuper != NULL && super != NULL)
debugger("Error - can't add menu or menu item to more than 1 container (either menu or menubar).");
if (fSubmenu != NULL) {
MenuPrivate(fSubmenu).SetSuper(super);
if (fSuper != NULL && super != NULL) {
debugger("Error - can't add menu or menu item to more than 1 container"
" (either menu or menubar).");
}
if (fSubmenu != NULL)
MenuPrivate(fSubmenu).SetSuper(super);
fSuper = super;
}
@ -668,7 +665,7 @@ BMenuItem::Select(bool selected)
if (fSelected == selected)
return;
if (Submenu() || IsEnabled()) {
if (Submenu() != NULL || IsEnabled()) {
fSelected = selected;
Highlight(selected);
}
@ -717,7 +714,7 @@ BMenuItem::_DrawMarkSymbol()
void
BMenuItem::_DrawShortcutSymbol()
{
BMenu *menu = Menu();
BMenu* menu = fSuper;
BFont font;
menu->GetFont(&font);
BPoint where = ContentLocation();

View File

@ -97,7 +97,7 @@ BBitmap* MenuPrivate::sMenuItemAlt;
BBitmap* MenuPrivate::sMenuItemMenu;
MenuPrivate::MenuPrivate(BMenu *menu)
MenuPrivate::MenuPrivate(BMenu* menu)
:
fMenu(menu)
{
@ -147,22 +147,22 @@ MenuPrivate::Padding() const
void
MenuPrivate::GetItemMargins(float *left, float *top,
float *right, float *bottom) const
MenuPrivate::GetItemMargins(float* left, float* top, float* right,
float* bottom) const
{
fMenu->GetItemMargins(left, top, right, bottom);
}
int
MenuPrivate::State(BMenuItem **item) const
MenuPrivate::State(BMenuItem** item) const
{
return fMenu->_State(item);
}
void
MenuPrivate::Install(BWindow *window)
MenuPrivate::Install(BWindow* window)
{
fMenu->_Install(window);
}
@ -176,21 +176,21 @@ MenuPrivate::Uninstall()
void
MenuPrivate::SetSuper(BMenu *menu)
MenuPrivate::SetSuper(BMenu* menu)
{
fMenu->fSuper = menu;
}
void
MenuPrivate::SetSuperItem(BMenuItem *item)
MenuPrivate::SetSuperItem(BMenuItem* item)
{
fMenu->fSuperitem = item;
}
void
MenuPrivate::InvokeItem(BMenuItem *item, bool now)
MenuPrivate::InvokeItem(BMenuItem* item, bool now)
{
fMenu->_InvokeItem(item, now);
}