BMenu: style fixes

This commit is contained in:
John Scipione
2014-04-24 15:31:12 -04:00
parent a631719fb4
commit cb30cf1423
+65 -46
View File
@@ -207,7 +207,7 @@ struct BMenu::LayoutData {
}; };
// #pragma mark - // #pragma mark - BMenu
BMenu::BMenu(const char* name, menu_layout layout) BMenu::BMenu(const char* name, menu_layout layout)
@@ -326,9 +326,6 @@ BMenu::~BMenu()
} }
// #pragma mark -
BArchivable* BArchivable*
BMenu::Instantiate(BMessage* archive) BMenu::Instantiate(BMessage* archive)
{ {
@@ -377,9 +374,6 @@ BMenu::Archive(BMessage* data, bool deep) const
} }
// #pragma mark -
void void
BMenu::AttachedToWindow() BMenu::AttachedToWindow()
{ {
@@ -422,9 +416,6 @@ BMenu::AllDetached()
} }
// #pragma mark -
void void
BMenu::Draw(BRect updateRect) BMenu::Draw(BRect updateRect)
{ {
@@ -593,16 +584,14 @@ BMenu::KeyDown(const char* bytes, int32 numBytes)
} }
// #pragma mark -
BSize BSize
BMenu::MinSize() BMenu::MinSize()
{ {
_ValidatePreferredSize(); _ValidatePreferredSize();
BSize size = (GetLayout() ? GetLayout()->MinSize() BSize size = (GetLayout() != NULL ? GetLayout()->MinSize()
: fLayoutData->preferred); : fLayoutData->preferred);
return BLayoutUtils::ComposeSize(ExplicitMinSize(), size); return BLayoutUtils::ComposeSize(ExplicitMinSize(), size);
} }
@@ -612,8 +601,9 @@ BMenu::MaxSize()
{ {
_ValidatePreferredSize(); _ValidatePreferredSize();
BSize size = (GetLayout() ? GetLayout()->MaxSize() BSize size = (GetLayout() != NULL ? GetLayout()->MaxSize()
: fLayoutData->preferred); : fLayoutData->preferred);
return BLayoutUtils::ComposeSize(ExplicitMaxSize(), size); return BLayoutUtils::ComposeSize(ExplicitMaxSize(), size);
} }
@@ -623,8 +613,9 @@ BMenu::PreferredSize()
{ {
_ValidatePreferredSize(); _ValidatePreferredSize();
BSize size = (GetLayout() ? GetLayout()->PreferredSize() BSize size = (GetLayout() != NULL ? GetLayout()->PreferredSize()
: fLayoutData->preferred); : fLayoutData->preferred);
return BLayoutUtils::ComposeSize(ExplicitPreferredSize(), size); return BLayoutUtils::ComposeSize(ExplicitPreferredSize(), size);
} }
@@ -636,6 +627,7 @@ BMenu::GetPreferredSize(float* _width, float* _height)
if (_width) if (_width)
*_width = fLayoutData->preferred.width; *_width = fLayoutData->preferred.width;
if (_height) if (_height)
*_height = fLayoutData->preferred.height; *_height = fLayoutData->preferred.height;
} }
@@ -653,7 +645,7 @@ BMenu::DoLayout()
{ {
// If the user set a layout, we let the base class version call its // If the user set a layout, we let the base class version call its
// hook. // hook.
if (GetLayout()) { if (GetLayout() != NULL) {
BView::DoLayout(); BView::DoLayout();
return; return;
} }
@@ -688,9 +680,6 @@ BMenu::InvalidateLayout()
} }
// #pragma mark -
void void
BMenu::MakeFocus(bool focused) BMenu::MakeFocus(bool focused)
{ {
@@ -725,6 +714,7 @@ BMenu::AddItem(BMenuItem* item, int32 index)
} }
UnlockLooper(); UnlockLooper();
} }
return true; return true;
} }
@@ -1151,9 +1141,6 @@ BMenu::Superitem() const
} }
// #pragma mark -
BHandler* BHandler*
BMenu::ResolveSpecifier(BMessage* msg, int32 index, BMessage* specifier, BMenu::ResolveSpecifier(BMessage* msg, int32 index, BMessage* specifier,
int32 form, const char* property) int32 form, const char* property)
@@ -1228,22 +1215,27 @@ BMenu::Perform(perform_code code, void* _data)
((perform_data_min_size*)_data)->return_value ((perform_data_min_size*)_data)->return_value
= BMenu::MinSize(); = BMenu::MinSize();
return B_OK; return B_OK;
case PERFORM_CODE_MAX_SIZE: case PERFORM_CODE_MAX_SIZE:
((perform_data_max_size*)_data)->return_value ((perform_data_max_size*)_data)->return_value
= BMenu::MaxSize(); = BMenu::MaxSize();
return B_OK; return B_OK;
case PERFORM_CODE_PREFERRED_SIZE: case PERFORM_CODE_PREFERRED_SIZE:
((perform_data_preferred_size*)_data)->return_value ((perform_data_preferred_size*)_data)->return_value
= BMenu::PreferredSize(); = BMenu::PreferredSize();
return B_OK; return B_OK;
case PERFORM_CODE_LAYOUT_ALIGNMENT: case PERFORM_CODE_LAYOUT_ALIGNMENT:
((perform_data_layout_alignment*)_data)->return_value ((perform_data_layout_alignment*)_data)->return_value
= BMenu::LayoutAlignment(); = BMenu::LayoutAlignment();
return B_OK; return B_OK;
case PERFORM_CODE_HAS_HEIGHT_FOR_WIDTH: case PERFORM_CODE_HAS_HEIGHT_FOR_WIDTH:
((perform_data_has_height_for_width*)_data)->return_value ((perform_data_has_height_for_width*)_data)->return_value
= BMenu::HasHeightForWidth(); = BMenu::HasHeightForWidth();
return B_OK; return B_OK;
case PERFORM_CODE_GET_HEIGHT_FOR_WIDTH: case PERFORM_CODE_GET_HEIGHT_FOR_WIDTH:
{ {
perform_data_get_height_for_width* data perform_data_get_height_for_width* data
@@ -1252,12 +1244,14 @@ BMenu::Perform(perform_code code, void* _data)
&data->preferred); &data->preferred);
return B_OK; return B_OK;
} }
case PERFORM_CODE_SET_LAYOUT: case PERFORM_CODE_SET_LAYOUT:
{ {
perform_data_set_layout* data = (perform_data_set_layout*)_data; perform_data_set_layout* data = (perform_data_set_layout*)_data;
BMenu::SetLayout(data->layout); BMenu::SetLayout(data->layout);
return B_OK; return B_OK;
} }
case PERFORM_CODE_LAYOUT_INVALIDATED: case PERFORM_CODE_LAYOUT_INVALIDATED:
{ {
perform_data_layout_invalidated* data perform_data_layout_invalidated* data
@@ -1265,6 +1259,7 @@ BMenu::Perform(perform_code code, void* _data)
BMenu::LayoutInvalidated(data->descendants); BMenu::LayoutInvalidated(data->descendants);
return B_OK; return B_OK;
} }
case PERFORM_CODE_DO_LAYOUT: case PERFORM_CODE_DO_LAYOUT:
{ {
BMenu::DoLayout(); BMenu::DoLayout();
@@ -1276,6 +1271,9 @@ BMenu::Perform(perform_code code, void* _data)
} }
// #pragma mark - BMenu protected methods
BMenu::BMenu(BRect frame, const char* name, uint32 resizingMode, uint32 flags, BMenu::BMenu(BRect frame, const char* name, uint32 resizingMode, uint32 flags,
menu_layout layout, bool resizeToFit) menu_layout layout, bool resizeToFit)
: :
@@ -1324,10 +1322,13 @@ BMenu::GetItemMargins(float* _left, float* _top, float* _right,
{ {
if (_left != NULL) if (_left != NULL)
*_left = fPad.left; *_left = fPad.left;
if (_top != NULL) if (_top != NULL)
*_top = fPad.top; *_top = fPad.top;
if (_right != NULL) if (_right != NULL)
*_right = fPad.right; *_right = fPad.right;
if (_bottom != NULL) if (_bottom != NULL)
*_bottom = fPad.bottom; *_bottom = fPad.bottom;
} }
@@ -1389,6 +1390,9 @@ BMenu::Track(bool sticky, BRect* clickToOpenRect)
} }
// #pragma mark - BMenu private methods
bool bool
BMenu::AddDynamicItem(add_state state) BMenu::AddDynamicItem(add_state state)
{ {
@@ -1405,14 +1409,17 @@ BMenu::DrawBackground(BRect updateRect)
uint32 flags = 0; uint32 flags = 0;
if (!IsEnabled()) if (!IsEnabled())
flags |= BControlLook::B_DISABLED; flags |= BControlLook::B_DISABLED;
if (IsFocus()) if (IsFocus())
flags |= BControlLook::B_FOCUSED; flags |= BControlLook::B_FOCUSED;
BRect rect = Bounds(); BRect rect = Bounds();
uint32 borders = BControlLook::B_LEFT_BORDER uint32 borders = BControlLook::B_LEFT_BORDER
| BControlLook::B_RIGHT_BORDER; | BControlLook::B_RIGHT_BORDER;
if (Window() != NULL && Parent() != NULL) { if (Window() != NULL && Parent() != NULL) {
if (Parent()->Frame().top == Window()->Bounds().top) if (Parent()->Frame().top == Window()->Bounds().top)
borders |= BControlLook::B_TOP_BORDER; borders |= BControlLook::B_TOP_BORDER;
if (Parent()->Frame().bottom == Window()->Bounds().bottom) if (Parent()->Frame().bottom == Window()->Bounds().bottom)
borders |= BControlLook::B_BOTTOM_BORDER; borders |= BControlLook::B_BOTTOM_BORDER;
} else { } else {
@@ -1980,9 +1987,6 @@ BMenu::_UpdateStateClose(BMenuItem* item, const BPoint& where,
} }
// #pragma mark -
bool bool
BMenu::_AddItem(BMenuItem* item, int32 index) BMenu::_AddItem(BMenuItem* item, int32 index)
{ {
@@ -2128,7 +2132,6 @@ BMenu::_ComputeLayout(int32 index, bool bestFit, bool moveItems,
fLayoutData->lastResizingMode = ResizingMode(); fLayoutData->lastResizingMode = ResizingMode();
BRect frame; BRect frame;
switch (fLayout) { switch (fLayout) {
case B_ITEMS_IN_COLUMN: case B_ITEMS_IN_COLUMN:
{ {
@@ -2139,9 +2142,11 @@ BMenu::_ComputeLayout(int32 index, bool bestFit, bool moveItems,
overrideFrame = &parentFrame; overrideFrame = &parentFrame;
} }
_ComputeColumnLayout(index, bestFit, moveItems, overrideFrame, frame); _ComputeColumnLayout(index, bestFit, moveItems, overrideFrame,
frame);
break; break;
} }
case B_ITEMS_IN_ROW: case B_ITEMS_IN_ROW:
_ComputeRowLayout(index, bestFit, moveItems, frame); _ComputeRowLayout(index, bestFit, moveItems, frame);
break; break;
@@ -2188,34 +2193,40 @@ void
BMenu::_ComputeColumnLayout(int32 index, bool bestFit, bool moveItems, BMenu::_ComputeColumnLayout(int32 index, bool bestFit, bool moveItems,
BRect* overrideFrame, BRect& frame) BRect* overrideFrame, BRect& frame)
{ {
BFont font;
GetFont(&font);
bool command = false; bool command = false;
bool control = false; bool control = false;
bool shift = false; bool shift = false;
bool option = false; bool option = false;
if (index > 0) if (index > 0)
frame = ItemAt(index - 1)->Frame(); frame = ItemAt(index - 1)->Frame();
else if (overrideFrame != NULL) { else if (overrideFrame != NULL)
frame.Set(0, 0, overrideFrame->right, -1); frame.Set(0, 0, overrideFrame->right, -1);
} else else
frame.Set(0, 0, 0, -1); frame.Set(0, 0, 0, -1);
BFont font;
GetFont(&font);
for (; index < fItems.CountItems(); index++) { for (; index < fItems.CountItems(); index++) {
BMenuItem* item = ItemAt(index); BMenuItem* item = ItemAt(index);
float width, height; float width;
float height;
item->GetContentSize(&width, &height); item->GetContentSize(&width, &height);
if (item->fModifiers && item->fShortcutChar) { if (item->fModifiers && item->fShortcutChar) {
width += font.Size(); width += font.Size();
if (item->fModifiers & B_COMMAND_KEY) if ((item->fModifiers & B_COMMAND_KEY) != 0)
command = true; command = true;
if (item->fModifiers & B_CONTROL_KEY)
if ((item->fModifiers & B_CONTROL_KEY) != 0)
control = true; control = true;
if (item->fModifiers & B_SHIFT_KEY)
if ((item->fModifiers & B_SHIFT_KEY) != 0)
shift = true; shift = true;
if (item->fModifiers & B_OPTION_KEY)
if ((item->fModifiers & B_OPTION_KEY) != 0)
option = true; option = true;
} }
@@ -2231,14 +2242,22 @@ BMenu::_ComputeColumnLayout(int32 index, bool bestFit, bool moveItems,
frame.bottom = item->fBounds.bottom; frame.bottom = item->fBounds.bottom;
} }
if (command) if (command) {
frame.right += BPrivate::MenuPrivate::MenuItemCommand()->Bounds().Width() + 1; frame.right
if (control) += BPrivate::MenuPrivate::MenuItemCommand()->Bounds().Width() + 1;
frame.right += BPrivate::MenuPrivate::MenuItemControl()->Bounds().Width() + 1; }
if (option) if (control) {
frame.right += BPrivate::MenuPrivate::MenuItemOption()->Bounds().Width() + 1; frame.right
if (shift) += BPrivate::MenuPrivate::MenuItemControl()->Bounds().Width() + 1;
frame.right += BPrivate::MenuPrivate::MenuItemShift()->Bounds().Width() + 1; }
if (option) {
frame.right
+= BPrivate::MenuPrivate::MenuItemOption()->Bounds().Width() + 1;
}
if (shift) {
frame.right
+= BPrivate::MenuPrivate::MenuItemShift()->Bounds().Width() + 1;
}
if (fMaxContentWidth > 0) if (fMaxContentWidth > 0)
frame.right = min_c(frame.right, fMaxContentWidth); frame.right = min_c(frame.right, fMaxContentWidth);
@@ -3005,7 +3024,7 @@ BMenu::_QuitTracking(bool onlyThis)
} }
// #pragma mark - // #pragma mark - menu_info functions
// TODO: Maybe the following two methods would fit better into // TODO: Maybe the following two methods would fit better into