#include <OptionControl.h>
#include <cstring>
BOptionControl::BOptionControl(BRect frame, const char *name, const char *label,
BMessage *message, uint32 resize, uint32 flags)
:
BControl(frame, name, label, message, resize, flags)
{
}
BOptionControl::BOptionControl(const char *name, const char *label,
BMessage *message, uint32 flags)
:
BControl(name, label, message, flags)
{
}
BOptionControl::~BOptionControl()
{
}
void
BOptionControl::MessageReceived(BMessage *message)
{
switch (message->what) {
case B_OPTION_CONTROL_VALUE:
{
int32 value;
if (message->FindInt32("be:value", &value) == B_OK) {
SetValue(value);
Invoke();
}
break;
}
default:
BControl::MessageReceived(message);
break;
}
}
status_t
BOptionControl::AddOption(const char *name, int32 value)
{
int32 numOptions = CountOptions();
return AddOptionAt(name, value, numOptions);
}
status_t
BOptionControl::SelectOptionFor(int32 value)
{
int32 numOptions = CountOptions();
for (int32 c = 0; c < numOptions; c++) {
const char *name = NULL;
int32 optionValue;
if (GetOptionAt(c, &name, &optionValue) && optionValue == value) {
SetValue(optionValue);
return B_OK;
}
}
return B_ERROR;
}
status_t
BOptionControl::SelectOptionFor(const char *name)
{
int32 numOptions = CountOptions();
for (int32 c = 0; c < numOptions; c++) {
const char *optionName = NULL;
int32 optionValue;
if (GetOptionAt(c, &optionName, &optionValue)
&& !strcmp(name, optionName)) {
SetValue(optionValue);
return B_OK;
}
}
return B_ERROR;
}
BMessage *
BOptionControl::MakeValueMessage(int32 value)
{
BMessage *message = new BMessage(B_OPTION_CONTROL_VALUE);
if (message->AddInt32("be:value", value) != B_OK) {
delete message;
message = NULL;
}
return message;
}
BOptionControl::BOptionControl()
:
BControl(BRect(), "", "", NULL, 0, 0)
{
}
BOptionControl::BOptionControl(const BOptionControl & clone)
:
BControl(BRect(), "", "", NULL, 0, 0)
{
}
BOptionControl &
BOptionControl::operator=(const BOptionControl & clone)
{
return *this;
}
status_t BOptionControl::_Reserved_OptionControl_0(void *, ...) { return B_ERROR; }
status_t BOptionControl::_Reserved_OptionControl_1(void *, ...) { return B_ERROR; }
status_t BOptionControl::_Reserved_OptionControl_2(void *, ...) { return B_ERROR; }
status_t BOptionControl::_Reserved_OptionControl_3(void *, ...) { return B_ERROR; }
status_t BOptionControl::_Reserved_OptionControl_4(void *, ...) { return B_ERROR; }
status_t BOptionControl::_Reserved_OptionControl_5(void *, ...) { return B_ERROR; }
status_t BOptionControl::_Reserved_OptionControl_6(void *, ...) { return B_ERROR; }
status_t BOptionControl::_Reserved_OptionControl_7(void *, ...) { return B_ERROR; }
status_t BOptionControl::_Reserved_OptionControl_8(void *, ...) { return B_ERROR; }
status_t BOptionControl::_Reserved_OptionControl_9(void *, ...) { return B_ERROR; }
status_t BOptionControl::_Reserved_OptionControl_10(void *, ...) { return B_ERROR; }
status_t BOptionControl::_Reserved_OptionControl_11(void *, ...) { return B_ERROR; }