From f1eb42958fcb9daf687ca270a94531691f8c0551 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Thu, 18 Jul 2013 03:22:45 -0400 Subject: [PATCH] BMenuField: Check if Frame() is valid, refactor --- src/kits/interface/MenuField.cpp | 55 ++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/src/kits/interface/MenuField.cpp b/src/kits/interface/MenuField.cpp index d87cdc066f..83f75ebf2f 100644 --- a/src/kits/interface/MenuField.cpp +++ b/src/kits/interface/MenuField.cpp @@ -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) - divider = fLayoutData->label_width + 5; - } + } else if (fLayoutData->label_width > 0) + divider = fLayoutData->label_width + 5; // menu bar BRect dirty(fMenuBar->Frame()); @@ -1093,25 +1094,31 @@ BMenuField::_UpdateFrame() { CALLED(); - if (fLayoutData->label_layout_item && fLayoutData->menu_bar_layout_item) { - BRect labelFrame = fLayoutData->label_layout_item->Frame(); - BRect menuFrame = fLayoutData->menu_bar_layout_item->Frame(); - - // update divider - fDivider = menuFrame.left - labelFrame.left; - - // update our frame - MoveTo(labelFrame.left, labelFrame.top); - BSize oldSize = Bounds().Size(); - ResizeTo(menuFrame.left + menuFrame.Width() - labelFrame.left, - menuFrame.top + menuFrame.Height() - labelFrame.top); - BSize newSize = Bounds().Size(); - - // If the size changes, ResizeTo() will trigger a relayout, otherwise - // we need to do that explicitly. - if (newSize != oldSize) - Relayout(); + 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; + + // update our frame + MoveTo(labelFrame.left, labelFrame.top); + BSize oldSize = Bounds().Size(); + ResizeTo(menuFrame.left + menuFrame.Width() - labelFrame.left, + menuFrame.top + menuFrame.Height() - labelFrame.top); + BSize newSize = Bounds().Size(); + + // If the size changes, ResizeTo() will trigger a relayout, otherwise + // we need to do that explicitly. + if (newSize != oldSize) + Relayout(); }