Style fixes to BMenu and related classes.

This commit is contained in:
John Scipione
2013-05-06 17:15:17 -04:00
parent 3f5d1e7825
commit d97b434060
7 changed files with 75 additions and 77 deletions
+1
View File
@@ -10,6 +10,7 @@
#include <List.h> #include <List.h>
#include <View.h> #include <View.h>
class BMenu; class BMenu;
class BMenuBar; class BMenuBar;
class BMenuItem; class BMenuItem;
+2 -2
View File
@@ -35,7 +35,7 @@ public:
virtual status_t Archive(BMessage* archive, virtual status_t Archive(BMessage* archive,
bool deep = true) const; bool deep = true) const;
virtual void Draw(BRect update); virtual void Draw(BRect updateRect);
virtual void AttachedToWindow(); virtual void AttachedToWindow();
virtual void AllAttached(); virtual void AllAttached();
virtual void MouseDown(BPoint where); virtual void MouseDown(BPoint where);
@@ -121,7 +121,7 @@ private:
void InitObject(const char* label); void InitObject(const char* label);
void InitObject2(); void InitObject2();
void DrawLabel(BRect bounds, BRect update); void DrawLabel(BRect bounds, BRect updateRect);
static void InitMenu(BMenu* menu); static void InitMenu(BMenu* menu);
int32 _MenuTask(); int32 _MenuTask();
+1 -1
View File
@@ -271,7 +271,6 @@ _BMCMenuBar_::FrameResized(float width, float height)
dirty = Bounds(); dirty = Bounds();
dirty.left = dirty.right - diff - 12; dirty.left = dirty.right - diff - 12;
Invalidate(dirty); Invalidate(dirty);
} else if (diff < 0) { } else if (diff < 0) {
// clean up the dirty right line of // clean up the dirty right line of
// the menu field when shrinking // the menu field when shrinking
@@ -295,6 +294,7 @@ _BMCMenuBar_::FrameResized(float width, float height)
diff = Frame().right + 2 - fMenuField->Bounds().right; diff = Frame().right + 2 - fMenuField->Bounds().right;
fMenuField->ResizeBy(diff, 0.0); fMenuField->ResizeBy(diff, 0.0);
} }
BMenuBar::FrameResized(width, height); BMenuBar::FrameResized(width, height);
} }
+6 -6
View File
@@ -733,7 +733,7 @@ BMenu::AddItem(BMenuItem* item, BRect frame)
"be called if the menu layout is B_ITEMS_IN_MATRIX"); "be called if the menu layout is B_ITEMS_IN_MATRIX");
} }
if (!item) if (item == NULL)
return false; return false;
item->fBounds = frame; item->fBounds = frame;
@@ -758,7 +758,7 @@ bool
BMenu::AddItem(BMenu* submenu) BMenu::AddItem(BMenu* submenu)
{ {
BMenuItem* item = new (nothrow) BMenuItem(submenu); BMenuItem* item = new (nothrow) BMenuItem(submenu);
if (!item) if (item == NULL)
return false; return false;
if (!AddItem(item, CountItems())) { if (!AddItem(item, CountItems())) {
@@ -780,7 +780,7 @@ BMenu::AddItem(BMenu* submenu, int32 index)
} }
BMenuItem* item = new (nothrow) BMenuItem(submenu); BMenuItem* item = new (nothrow) BMenuItem(submenu);
if (!item) if (item == NULL)
return false; return false;
if (!AddItem(item, index)) { if (!AddItem(item, index)) {
@@ -802,7 +802,7 @@ BMenu::AddItem(BMenu* submenu, BRect frame)
} }
BMenuItem* item = new (nothrow) BMenuItem(submenu); BMenuItem* item = new (nothrow) BMenuItem(submenu);
if (!item) if (item == NULL)
return false; return false;
if (!AddItem(item, frame)) { if (!AddItem(item, frame)) {
@@ -2848,7 +2848,8 @@ BMenu::_UpdateWindowViewSize(const bool &move)
return; return;
bool scroll = false; bool scroll = false;
const BPoint screenLocation = move ? ScreenLocation() : window->Frame().LeftTop(); const BPoint screenLocation = move ? ScreenLocation()
: window->Frame().LeftTop();
BRect frame = _CalcFrame(screenLocation, &scroll); BRect frame = _CalcFrame(screenLocation, &scroll);
ResizeTo(frame.Width(), frame.Height()); ResizeTo(frame.Width(), frame.Height());
@@ -3024,4 +3025,3 @@ B_IF_GCC_2(InvalidateLayout__5BMenub,_ZN5BMenu16InvalidateLayoutEb)(
{ {
menu->InvalidateLayout(); menu->InvalidateLayout();
} }
+11 -11
View File
@@ -353,12 +353,12 @@ BMenuField::AllUnarchived(const BMessage* from)
void void
BMenuField::Draw(BRect update) BMenuField::Draw(BRect updateRect)
{ {
BRect bounds(Bounds()); BRect bounds(Bounds());
bool active = IsFocus() && Window()->IsActive(); bool active = IsFocus() && Window()->IsActive();
DrawLabel(bounds, update); DrawLabel(bounds, updateRect);
BRect frame(fMenuBar->Frame()); BRect frame(fMenuBar->Frame());
@@ -370,7 +370,7 @@ BMenuField::Draw(BRect update)
flags |= BControlLook::B_DISABLED; flags |= BControlLook::B_DISABLED;
if (active) if (active)
flags |= BControlLook::B_FOCUSED; flags |= BControlLook::B_FOCUSED;
be_control_look->DrawMenuFieldFrame(this, frame, update, base, be_control_look->DrawMenuFieldFrame(this, frame, updateRect, base,
background, flags); background, flags);
} }
@@ -473,9 +473,9 @@ BMenuField::MakeFocus(bool state)
void void
BMenuField::MessageReceived(BMessage* msg) BMenuField::MessageReceived(BMessage* message)
{ {
BView::MessageReceived(msg); BView::MessageReceived(message);
} }
@@ -980,7 +980,7 @@ BMenuField::InitObject2()
void void
BMenuField::DrawLabel(BRect bounds, BRect update) BMenuField::DrawLabel(BRect bounds, BRect updateRect)
{ {
CALLED(); CALLED();
@@ -1107,8 +1107,8 @@ BMenuField::_InitMenuBar(BMenu* menu, BRect frame, bool fixedSize)
fMenu = menu; fMenu = menu;
InitMenu(menu); InitMenu(menu);
if ((Flags() & B_SUPPORTS_LAYOUT)) { if ((Flags() & B_SUPPORTS_LAYOUT) != 0) {
fMenuBar = new _BMCMenuBar_(fixedSize, this); fMenuBar = new _BMCMenuBar_(this);
} else { } else {
frame.left = _MenuBarOffset(); frame.left = _MenuBarOffset();
frame.top = kVMargin; frame.top = kVMargin;
@@ -1147,7 +1147,7 @@ BMenuField::_InitMenuBar(const BMessage* archive)
fFixedSizeMB = fixed; fFixedSizeMB = fixed;
fMenuBar = (BMenuBar*)FindView("_mc_mb_"); fMenuBar = (BMenuBar*)FindView("_mc_mb_");
if (!fMenuBar) { if (fMenuBar == NULL) {
_InitMenuBar(new BMenu(""), BRect(0, 0, 100, 15), fFixedSizeMB); _InitMenuBar(new BMenu(""), BRect(0, 0, 100, 15), fFixedSizeMB);
InitObject2(); InitObject2();
} else { } else {
@@ -1194,8 +1194,8 @@ BMenuField::_ValidateLayoutData()
divider = fLayoutData->label_width + 5; divider = fLayoutData->label_width + 5;
// If we shan't do real layout, we let the current divider take influence. // If we shan't do real layout, we let the current divider take influence.
if (!(Flags() & B_SUPPORTS_LAYOUT)) if ((Flags() & B_SUPPORTS_LAYOUT) == 0)
divider = max_c(divider, fDivider); divider = std::max(divider, fDivider);
// get the minimal (== preferred) menu bar size // get the minimal (== preferred) menu bar size
// TODO: BMenu::MinSize() is using the ResizeMode() to decide the // TODO: BMenu::MinSize() is using the ResizeMode() to decide the
+24 -27
View File
@@ -217,7 +217,7 @@ BMenuItem::SetEnabled(bool state)
if (fSubmenu != NULL) if (fSubmenu != NULL)
fSubmenu->SetEnabled(state); fSubmenu->SetEnabled(state);
BMenu *menu = Menu(); BMenu* menu = fSuper;
if (menu != NULL && menu->LockLooper()) { if (menu != NULL && menu->LockLooper()) {
menu->Invalidate(fBounds); menu->Invalidate(fBounds);
menu->UnlockLooper(); menu->UnlockLooper();
@@ -230,8 +230,8 @@ BMenuItem::SetMarked(bool state)
{ {
fMark = state; fMark = state;
if (state && Menu() != NULL) { if (state && fSuper != NULL) {
MenuPrivate priv(Menu()); MenuPrivate priv(fSuper);
priv.ItemMarked(this); priv.ItemMarked(this);
} }
} }
@@ -308,7 +308,7 @@ BMenuItem::IsEnabled() const
if (!fEnabled) if (!fEnabled)
return false; return false;
return fSuper ? fSuper->IsEnabled() : true; return fSuper != NULL ? fSuper->IsEnabled() : true;
} }
@@ -369,10 +369,9 @@ BMenuItem::GetContentSize(float* width, float* height)
if (width) if (width)
*width = (float)ceil(fCachedWidth); *width = (float)ceil(fCachedWidth);
if (height) { if (height)
*height = MenuPrivate(fSuper).FontHeight(); *height = MenuPrivate(fSuper).FontHeight();
} }
}
void void
@@ -452,8 +451,7 @@ BMenuItem::Draw()
bool selected = IsSelected(); bool selected = IsSelected();
// set low color and fill background if selected // set low color and fill background if selected
bool activated = selected && (enabled || Submenu()) bool activated = selected && (enabled || Submenu());
/*&& fSuper->fRedrawAfterSticky*/;
if (activated) { if (activated) {
if (be_control_look != NULL) { if (be_control_look != NULL) {
BRect rect = Frame(); BRect rect = Frame();
@@ -500,7 +498,7 @@ BMenuItem::Draw()
void void
BMenuItem::Highlight(bool flag) BMenuItem::Highlight(bool flag)
{ {
Menu()->Invalidate(Frame()); fSuper->Invalidate(Frame());
} }
@@ -516,8 +514,7 @@ BMenuItem::ContentLocation() const
{ {
const BRect& padding = MenuPrivate(fSuper).Padding(); const BRect& padding = MenuPrivate(fSuper).Padding();
return BPoint(fBounds.left + padding.left, return BPoint(fBounds.left + padding.left, fBounds.top + padding.top);
fBounds.top + padding.top);
} }
@@ -577,9 +574,8 @@ BMenuItem::_InitMenuData(BMenu *menu)
void void
BMenuItem::Install(BWindow* window) BMenuItem::Install(BWindow* window)
{ {
if (fSubmenu) { if (fSubmenu != NULL)
MenuPrivate(fSubmenu).Install(window); MenuPrivate(fSubmenu).Install(window);
}
fWindow = window; fWindow = window;
@@ -606,21 +602,21 @@ BMenuItem::Invoke(BMessage *message)
BMessage clone(kind); BMessage clone(kind);
status_t err = B_BAD_VALUE; status_t err = B_BAD_VALUE;
if (!message && !notify) if (message == NULL && !notify)
message = Message(); message = Message();
if (!message) { if (message == NULL) {
if (!fSuper->IsWatched()) if (!fSuper->IsWatched())
return err; return err;
} else } else
clone = *message; clone = *message;
clone.AddInt32("index", Menu()->IndexOf(this)); clone.AddInt32("index", fSuper->IndexOf(this));
clone.AddInt64("when", (int64)system_time()); clone.AddInt64("when", (int64)system_time());
clone.AddPointer("source", this); clone.AddPointer("source", this);
clone.AddMessenger("be:sender", BMessenger(fSuper)); clone.AddMessenger("be:sender", BMessenger(fSuper));
if (message) if (message != NULL)
err = BInvoker::Invoke(&clone); err = BInvoker::Invoke(&clone);
// TODO: assynchronous messaging // TODO: assynchronous messaging
@@ -633,16 +629,16 @@ BMenuItem::Invoke(BMessage *message)
void void
BMenuItem::Uninstall() BMenuItem::Uninstall()
{ {
if (fSubmenu != NULL) { if (fSubmenu != NULL)
MenuPrivate(fSubmenu).Uninstall(); MenuPrivate(fSubmenu).Uninstall();
}
if (Target() == fWindow) if (Target() == fWindow)
SetTarget(BMessenger()); SetTarget(BMessenger());
if (fShortcutChar != 0 && (fModifiers & B_COMMAND_KEY) != 0 if (fShortcutChar != 0 && (fModifiers & B_COMMAND_KEY) != 0
&& fWindow != NULL) && fWindow != NULL) {
fWindow->RemoveShortcut(fShortcutChar, fModifiers); fWindow->RemoveShortcut(fShortcutChar, fModifiers);
}
fWindow = NULL; fWindow = NULL;
} }
@@ -651,13 +647,14 @@ BMenuItem::Uninstall()
void void
BMenuItem::SetSuper(BMenu* super) BMenuItem::SetSuper(BMenu* super)
{ {
if (fSuper != NULL && super != NULL) if (fSuper != NULL && super != NULL) {
debugger("Error - can't add menu or menu item to more than 1 container (either menu or menubar)."); 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 (fSubmenu != NULL)
MenuPrivate(fSubmenu).SetSuper(super);
fSuper = super; fSuper = super;
} }
@@ -668,7 +665,7 @@ BMenuItem::Select(bool selected)
if (fSelected == selected) if (fSelected == selected)
return; return;
if (Submenu() || IsEnabled()) { if (Submenu() != NULL || IsEnabled()) {
fSelected = selected; fSelected = selected;
Highlight(selected); Highlight(selected);
} }
@@ -717,7 +714,7 @@ BMenuItem::_DrawMarkSymbol()
void void
BMenuItem::_DrawShortcutSymbol() BMenuItem::_DrawShortcutSymbol()
{ {
BMenu *menu = Menu(); BMenu* menu = fSuper;
BFont font; BFont font;
menu->GetFont(&font); menu->GetFont(&font);
BPoint where = ContentLocation(); BPoint where = ContentLocation();
+2 -2
View File
@@ -147,8 +147,8 @@ MenuPrivate::Padding() const
void void
MenuPrivate::GetItemMargins(float *left, float *top, MenuPrivate::GetItemMargins(float* left, float* top, float* right,
float *right, float *bottom) const float* bottom) const
{ {
fMenu->GetItemMargins(left, top, right, bottom); fMenu->GetItemMargins(left, top, right, bottom);
} }