Style changes, some more error checks, removed ifdeffed broken
behaviour. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40018 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2003-2007, Haiku, Inc.
|
* Copyright 2003-2010, Haiku, Inc.
|
||||||
* Distributed under the terms of the MIT license.
|
* Distributed under the terms of the MIT license.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -15,11 +15,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
// If enabled, behaves like in BeOS R5, in that when you call
|
|
||||||
// SelectOptionFor() or SetValue(), the selected item isn't marked, and
|
|
||||||
// so SelectedOption() will return -1. This is broken, IMHO.
|
|
||||||
#define BEHAVE_LIKE_R5 0
|
|
||||||
|
|
||||||
const float kLabelSpace = 8.0;
|
const float kLabelSpace = 8.0;
|
||||||
const float kWidthModifier = 25.0;
|
const float kWidthModifier = 25.0;
|
||||||
const float kHeightModifier = 10.0;
|
const float kHeightModifier = 10.0;
|
||||||
@@ -130,13 +125,8 @@ void
|
|||||||
BOptionPopUp::RemoveOptionAt(int32 index)
|
BOptionPopUp::RemoveOptionAt(int32 index)
|
||||||
{
|
{
|
||||||
BMenu* menu = fMenuField->Menu();
|
BMenu* menu = fMenuField->Menu();
|
||||||
if (menu != NULL) {
|
if (menu != NULL)
|
||||||
BMenuItem *item = menu->ItemAt(index);
|
delete menu->RemoveItem(index);
|
||||||
if (item != NULL) {
|
|
||||||
menu->RemoveItem(item);
|
|
||||||
delete item;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -179,7 +169,11 @@ BOptionPopUp::AddOptionAt(const char *name, int32 value, int32 index)
|
|||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
menu->AddItem(newItem, index);
|
if (!menu->AddItem(newItem, index)) {
|
||||||
|
delete newItem;
|
||||||
|
return B_NO_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
newItem->SetTarget(this);
|
newItem->SetTarget(this);
|
||||||
|
|
||||||
// We didnt' have any items before, so select the newly added one
|
// We didnt' have any items before, so select the newly added one
|
||||||
@@ -221,7 +215,7 @@ BOptionPopUp::SetLabel(const char *text)
|
|||||||
BControl::SetLabel(text);
|
BControl::SetLabel(text);
|
||||||
fMenuField->SetLabel(text);
|
fMenuField->SetLabel(text);
|
||||||
// We are not sure the menu can keep the whole
|
// We are not sure the menu can keep the whole
|
||||||
// string as label, so we ask it what label it's got
|
// string as label, so we check against the current label
|
||||||
float newWidth = fMenuField->StringWidth(fMenuField->Label());
|
float newWidth = fMenuField->StringWidth(fMenuField->Label());
|
||||||
fMenuField->SetDivider(newWidth + kLabelSpace);
|
fMenuField->SetDivider(newWidth + kLabelSpace);
|
||||||
}
|
}
|
||||||
@@ -247,11 +241,6 @@ BOptionPopUp::SetValue(int32 value)
|
|||||||
item->Message()->FindInt32("be:value", &itemValue);
|
item->Message()->FindInt32("be:value", &itemValue);
|
||||||
if (itemValue == value) {
|
if (itemValue == value) {
|
||||||
item->SetMarked(true);
|
item->SetMarked(true);
|
||||||
|
|
||||||
#if BEHAVE_LIKE_R5
|
|
||||||
item->SetMarked(false);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -320,9 +309,13 @@ int32
|
|||||||
BOptionPopUp::SelectedOption(const char** outName, int32* outValue) const
|
BOptionPopUp::SelectedOption(const char** outName, int32* outValue) const
|
||||||
{
|
{
|
||||||
BMenu* menu = fMenuField->Menu();
|
BMenu* menu = fMenuField->Menu();
|
||||||
if (menu != NULL) {
|
if (menu == NULL)
|
||||||
|
return B_ERROR;
|
||||||
|
|
||||||
BMenuItem* marked = menu->FindMarked();
|
BMenuItem* marked = menu->FindMarked();
|
||||||
if (marked != NULL) {
|
if (marked == NULL)
|
||||||
|
return -1;
|
||||||
|
|
||||||
if (outName != NULL)
|
if (outName != NULL)
|
||||||
*outName = marked->Label();
|
*outName = marked->Label();
|
||||||
if (outValue != NULL)
|
if (outValue != NULL)
|
||||||
@@ -330,10 +323,6 @@ BOptionPopUp::SelectedOption(const char **outName, int32 *outValue) const
|
|||||||
|
|
||||||
return menu->IndexOf(marked);
|
return menu->IndexOf(marked);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return B_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Private Unimplemented
|
// Private Unimplemented
|
||||||
|
|||||||
Reference in New Issue
Block a user