BMenuField: Check if Frame() is valid, refactor
This commit is contained in:
@@ -916,14 +916,15 @@ BMenuField::DoLayout()
|
||||
|
||||
// divider
|
||||
float divider = 0;
|
||||
if (fLayoutData->label_layout_item && fLayoutData->menu_bar_layout_item) {
|
||||
// We have layout items. They define the divider location.
|
||||
if (fLayoutData->label_layout_item != NULL
|
||||
&& fLayoutData->menu_bar_layout_item != NULL
|
||||
&& fLayoutData->label_layout_item->Frame().IsValid()
|
||||
&& fLayoutData->menu_bar_layout_item->Frame().IsValid()) {
|
||||
// We have valid layout items, they define the divider location.
|
||||
divider = fLayoutData->menu_bar_layout_item->Frame().left
|
||||
- fLayoutData->label_layout_item->Frame().left;
|
||||
} else {
|
||||
if (fLayoutData->label_width > 0)
|
||||
} else if (fLayoutData->label_width > 0)
|
||||
divider = fLayoutData->label_width + 5;
|
||||
}
|
||||
|
||||
// menu bar
|
||||
BRect dirty(fMenuBar->Frame());
|
||||
@@ -1093,10 +1094,17 @@ BMenuField::_UpdateFrame()
|
||||
{
|
||||
CALLED();
|
||||
|
||||
if (fLayoutData->label_layout_item && fLayoutData->menu_bar_layout_item) {
|
||||
if (fLayoutData->label_layout_item == NULL
|
||||
|| fLayoutData->menu_bar_layout_item == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
BRect labelFrame = fLayoutData->label_layout_item->Frame();
|
||||
BRect menuFrame = fLayoutData->menu_bar_layout_item->Frame();
|
||||
|
||||
if (!labelFrame.IsValid() || !menuFrame.IsValid())
|
||||
return;
|
||||
|
||||
// update divider
|
||||
fDivider = menuFrame.left - labelFrame.left;
|
||||
|
||||
@@ -1112,7 +1120,6 @@ BMenuField::_UpdateFrame()
|
||||
if (newSize != oldSize)
|
||||
Relayout();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user