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 <View.h>
class BMenu;
class BMenuBar;
class BMenuItem;
+2 -2
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();
+1 -1
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);
}
+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");
}
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();
}
+11 -11
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);
}
@@ -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
+24 -27
View File
@@ -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);
}
}
@@ -308,7 +308,7 @@ BMenuItem::IsEnabled() const
if (!fEnabled)
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)
*width = (float)ceil(fCachedWidth);
if (height) {
if (height)
*height = MenuPrivate(fSuper).FontHeight();
}
}
void
@@ -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());
}
@@ -516,8 +514,7 @@ BMenuItem::ContentLocation() const
{
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);
}
@@ -577,9 +574,8 @@ BMenuItem::_InitMenuData(BMenu *menu)
void
BMenuItem::Install(BWindow* window)
{
if (fSubmenu) {
if (fSubmenu != NULL)
MenuPrivate(fSubmenu).Install(window);
}
fWindow = window;
@@ -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,16 +629,16 @@ 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;
}
@@ -651,13 +647,14 @@ BMenuItem::Uninstall()
void
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();
+2 -2
View File
@@ -147,8 +147,8 @@ 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);
}