DefaultMediaTheme: implement BTextParameter handling for BParameterWeb
These changes add text parameters support to DefaultMediaTheme for the BParameterWeb class. Change-Id: I6ec04109af73011f84bb7c1fd5210c5c8842c2cb Reviewed-on: https://review.haiku-os.org/c/haiku/+/3828 Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>
This commit is contained in:
parent
02dabf4bd9
commit
1ab6200126
@ -108,6 +108,18 @@ class ChannelSlider : public BChannelSlider {
|
||||
BContinuousParameter &fParameter;
|
||||
};
|
||||
|
||||
class TextControl : public BTextControl {
|
||||
public:
|
||||
TextControl(const char* name, const char* label,
|
||||
BTextParameter ¶meter);
|
||||
virtual ~TextControl();
|
||||
|
||||
virtual void AttachedToWindow();
|
||||
virtual void DetachedFromWindow();
|
||||
private:
|
||||
BTextParameter &fParameter;
|
||||
};
|
||||
|
||||
class MessageFilter : public BMessageFilter {
|
||||
public:
|
||||
static MessageFilter *FilterFor(BView *view, BParameter ¶meter);
|
||||
@ -142,6 +154,17 @@ class DiscreteMessageFilter : public MessageFilter {
|
||||
BDiscreteParameter &fParameter;
|
||||
};
|
||||
|
||||
class TextMessageFilter : public MessageFilter {
|
||||
public:
|
||||
TextMessageFilter(BControl *control, BTextParameter ¶meter);
|
||||
virtual ~TextMessageFilter();
|
||||
|
||||
virtual filter_result Filter(BMessage *message, BHandler **target);
|
||||
|
||||
private:
|
||||
BTextParameter &fParameter;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
using namespace DefaultMediaControls;
|
||||
@ -414,6 +437,36 @@ ChannelSlider::DetachedFromWindow()
|
||||
}
|
||||
|
||||
|
||||
TextControl::TextControl(const char* name, const char* label,
|
||||
BTextParameter ¶meter)
|
||||
: BTextControl(name, label, "", NULL),
|
||||
fParameter(parameter)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TextControl::~TextControl()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TextControl::AttachedToWindow()
|
||||
{
|
||||
BTextControl::AttachedToWindow();
|
||||
|
||||
SetTarget(this);
|
||||
start_watching_for_parameter_changes(this, fParameter);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TextControl::DetachedFromWindow()
|
||||
{
|
||||
stop_watching_for_parameter_changes(this, fParameter);
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
@ -439,6 +492,10 @@ MessageFilter::FilterFor(BView *view, BParameter ¶meter)
|
||||
return new DiscreteMessageFilter(control,
|
||||
static_cast<BDiscreteParameter &>(parameter));
|
||||
|
||||
case BParameter::B_TEXT_PARAMETER:
|
||||
return new TextMessageFilter(control,
|
||||
static_cast<BTextParameter &>(parameter));
|
||||
|
||||
case BParameter::B_NULL_PARAMETER: /* fall through */
|
||||
default:
|
||||
return NULL;
|
||||
@ -652,6 +709,100 @@ DiscreteMessageFilter::Filter(BMessage *message, BHandler **target)
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
TextMessageFilter::TextMessageFilter(BControl *control,
|
||||
BTextParameter ¶meter)
|
||||
: MessageFilter(),
|
||||
fParameter(parameter)
|
||||
{
|
||||
// initialize view for us
|
||||
control->SetMessage(new BMessage(kMsgParameterChanged));
|
||||
|
||||
// set initial value
|
||||
if (BTextControl *textControl = dynamic_cast<BTextControl *>(control)) {
|
||||
size_t valueSize = parameter.MaxBytes();
|
||||
char* value = new char[valueSize + 1];
|
||||
|
||||
if (parameter.GetValue((void *)value, &valueSize, NULL) < B_OK) {
|
||||
ERROR("TextMessageFilter: Could not get value for text "
|
||||
"parameter %p (name '%s', node %d)\n", ¶meter,
|
||||
parameter.Name(), (int)(parameter.Web()->Node().node));
|
||||
} else {
|
||||
textControl->SetText(value);
|
||||
}
|
||||
|
||||
delete[] value;
|
||||
}
|
||||
|
||||
ERROR("TextMessageFilter: unknown text parameter view\n");
|
||||
}
|
||||
|
||||
|
||||
TextMessageFilter::~TextMessageFilter()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
filter_result
|
||||
TextMessageFilter::Filter(BMessage *message, BHandler **target)
|
||||
{
|
||||
BControl *control;
|
||||
|
||||
if ((control = dynamic_cast<BControl *>(*target)) == NULL)
|
||||
return B_DISPATCH_MESSAGE;
|
||||
|
||||
if (message->what == B_MEDIA_NEW_PARAMETER_VALUE) {
|
||||
TRACE("TextMessageFilter::Filter: Got a new parameter value\n");
|
||||
const media_node* node;
|
||||
int32 parameterID;
|
||||
ssize_t size;
|
||||
if (message->FindInt32("parameter", ¶meterID) != B_OK
|
||||
|| fParameter.ID() != parameterID
|
||||
|| message->FindData("node", B_RAW_TYPE, (const void**)&node,
|
||||
&size) != B_OK
|
||||
|| fParameter.Web()->Node() != *node)
|
||||
return B_DISPATCH_MESSAGE;
|
||||
|
||||
if (BTextControl *textControl = dynamic_cast<BTextControl *>(control)) {
|
||||
size_t valueSize = fParameter.MaxBytes();
|
||||
char* value = new char[valueSize + 1];
|
||||
if (fParameter.GetValue((void *)value, &valueSize, NULL) < B_OK) {
|
||||
ERROR("TextMessageFilter: Could not get value for text "
|
||||
"parameter %p (name '%s', node %d)\n", &fParameter,
|
||||
fParameter.Name(), (int)(fParameter.Web()->Node().node));
|
||||
} else {
|
||||
textControl->SetText(value);
|
||||
}
|
||||
|
||||
delete[] value;
|
||||
|
||||
return B_SKIP_MESSAGE;
|
||||
}
|
||||
|
||||
return B_DISPATCH_MESSAGE;
|
||||
}
|
||||
|
||||
if (message->what != kMsgParameterChanged)
|
||||
return B_DISPATCH_MESSAGE;
|
||||
|
||||
// update parameter value
|
||||
|
||||
if (BTextControl *textControl = dynamic_cast<BTextControl *>(control)) {
|
||||
TRACE("TextMessageFilter::Filter: update view %s, value = %"
|
||||
B_PRId32 "\n", control->Name(), value);
|
||||
BString value = textControl->Text();
|
||||
if (fParameter.SetValue((void *)value.String(), value.Length() + 1, -1) < B_OK) {
|
||||
ERROR("TextMessageFilter::Filter: Could not set parameter value for %p\n", &fParameter);
|
||||
return B_DISPATCH_MESSAGE;
|
||||
}
|
||||
}
|
||||
|
||||
return B_SKIP_MESSAGE;
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
DefaultMediaTheme::DefaultMediaTheme()
|
||||
: BMediaTheme("Haiku theme", "Haiku built-in theme version 0.1")
|
||||
{
|
||||
@ -890,6 +1041,13 @@ DefaultMediaTheme::MakeViewFor(BParameter *parameter)
|
||||
return slider;
|
||||
}
|
||||
|
||||
case BParameter::B_TEXT_PARAMETER:
|
||||
{
|
||||
BTextParameter &text
|
||||
= static_cast<BTextParameter &>(*parameter);
|
||||
return new TextControl(text.Name(), text.Name(), text);
|
||||
}
|
||||
|
||||
default:
|
||||
ERROR("BMediaTheme: Don't know parameter type: 0x%x\n",
|
||||
parameter->Type());
|
||||
|
Loading…
Reference in New Issue
Block a user