From cb6670b49015fe9d5ea5636a3a90a36127830167 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Sun, 6 Jul 2003 14:08:26 +0000 Subject: [PATCH] The groups are now put into special GroupViews which not only set the target of its members correctly, but will also add scroll bars as needed. Implemented basic message filters for discrete/continuous parameter views. The views are now set to the correct parameter value and vice versa. BContinuousParameter::{Get|Set}Response() is not yet supported, though. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3874 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/media/DefaultMediaTheme.cpp | 245 ++++++++++++++++++++++++++- 1 file changed, 239 insertions(+), 6 deletions(-) diff --git a/src/kits/media/DefaultMediaTheme.cpp b/src/kits/media/DefaultMediaTheme.cpp index 22c10037b1..c6255b8831 100644 --- a/src/kits/media/DefaultMediaTheme.cpp +++ b/src/kits/media/DefaultMediaTheme.cpp @@ -19,6 +19,7 @@ #include #include #include +#include using namespace BPrivate; @@ -26,6 +27,16 @@ using namespace BPrivate; namespace BPrivate { +class GroupView : public BView { + public: + GroupView(BRect frame, const char *name); + virtual ~GroupView(); + + virtual void AttachedToWindow(); + + private: +}; + class SeparatorView : public BView { public: SeparatorView(BRect frame); @@ -49,9 +60,42 @@ class TitleView : public BView { const char *fTitle; }; +class MessageFilter : public BMessageFilter { + public: + static MessageFilter *FilterFor(BView *view, BParameter ¶meter); + + protected: + MessageFilter(); +}; + +class ContinuousMessageFilter : public MessageFilter { + public: + ContinuousMessageFilter(BControl *control, BContinuousParameter ¶meter); + virtual ~ContinuousMessageFilter(); + + virtual filter_result Filter(BMessage *message, BHandler **target); + + private: + BContinuousParameter &fParameter; +}; + +class DiscreteMessageFilter : public MessageFilter { + public: + DiscreteMessageFilter(BControl *control, BDiscreteParameter ¶meter); + virtual ~DiscreteMessageFilter(); + + virtual filter_result Filter(BMessage *message, BHandler **target); + + private: + BDiscreteParameter &fParameter; +}; + } // namespace BPrivate +const uint32 kMsgParameterChanged = '_mPC'; + + static bool parameter_should_be_hidden(BParameter ¶meter) { @@ -74,6 +118,36 @@ parameter_should_be_hidden(BParameter ¶meter) // #pragma mark - +GroupView::GroupView(BRect frame, const char *name) + : BView(frame, name, B_FOLLOW_NONE, B_WILL_DRAW) +{ + SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + + // ToDo: show scroll bars if necessary! +} + + +GroupView::~GroupView() +{ +} + + +void +GroupView::AttachedToWindow() +{ + for (int32 i = CountChildren(); i-- > 0;) { + BControl *control = dynamic_cast(ChildAt(i)); + if (control == NULL) + continue; + + control->SetTarget(control); + } +} + + +// #pragma mark - + + SeparatorView::SeparatorView(BRect frame) : BView(frame, "-", B_FOLLOW_NONE, B_WILL_DRAW) { @@ -137,9 +211,6 @@ TitleView::Draw(BRect updateRect) SetDrawingMode(B_OP_OVER); SetHighColor(80, 20, 20); DrawString(fTitle, BPoint(rect.left, rect.bottom - 8)); - - //SetHighColor(tint_color(ViewColor(), B_DARKEN_1_TINT)); - //StrokeLine(BPoint(rect.left, rect.bottom), BPoint(rect.right, rect.bottom)); } @@ -161,6 +232,167 @@ TitleView::GetPreferredSize(float *_width, float *_height) // #pragma mark - +MessageFilter::MessageFilter() + : BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE) +{ +} + + +MessageFilter * +MessageFilter::FilterFor(BView *view, BParameter ¶meter) +{ + BControl *control = dynamic_cast(view); + if (control == NULL) + return NULL; + + switch (parameter.Type()) { + case BParameter::B_CONTINUOUS_PARAMETER: + return new ContinuousMessageFilter(control, static_cast(parameter)); + + case BParameter::B_DISCRETE_PARAMETER: + return new DiscreteMessageFilter(control, static_cast(parameter)); + } + + return NULL; +} + + +// #pragma mark - + + +ContinuousMessageFilter::ContinuousMessageFilter(BControl *control, BContinuousParameter ¶meter) + : MessageFilter(), + fParameter(parameter) +{ + // initialize view for us + control->SetMessage(new BMessage(kMsgParameterChanged)); + + // set initial value + // ToDo: response support! + + float value[fParameter.CountChannels()]; + size_t size = sizeof(value); + if (parameter.GetValue((void *)&value, &size, NULL) < B_OK) { + ERROR("Could not get parameter value for %p\n", ¶meter); + return; + } + + if (BSlider *slider = dynamic_cast(control)) { + slider->SetValue((int32)value[0]); + slider->SetModificationMessage(new BMessage(kMsgParameterChanged)); + } else if (BChannelSlider *slider = dynamic_cast(control)) { + for (int32 i = 0; i < fParameter.CountChannels(); i++) + slider->SetValueFor(i, (int32)value[i]); + + slider->SetModificationMessage(new BMessage(kMsgParameterChanged)); + } else + printf("unknown discrete parameter view\n"); +} + + +ContinuousMessageFilter::~ContinuousMessageFilter() +{ +} + + +filter_result +ContinuousMessageFilter::Filter(BMessage *message, BHandler **target) +{ + BControl *control; + + if (message->what != kMsgParameterChanged + || (control = dynamic_cast(*target)) == NULL) + return B_DISPATCH_MESSAGE; + + // update view + // ToDo: support for response! + + float value[fParameter.CountChannels()]; + + if (BSlider *slider = dynamic_cast(control)) { + value[0] = (float)slider->Value(); + } else if (BChannelSlider *slider = dynamic_cast(control)) { + for (int32 i = 0; i < fParameter.CountChannels(); i++) + value[i] = (float)slider->ValueFor(i); + } + + printf("update view %s, %ld channels\n", control->Name(), fParameter.CountChannels()); + + if (fParameter.SetValue((void *)value, sizeof(value), system_time()) < B_OK) { + ERROR("Could not set parameter value for %p\n", &fParameter); + return B_DISPATCH_MESSAGE; + } + + return B_SKIP_MESSAGE; +} + + +// #pragma mark - + + +DiscreteMessageFilter::DiscreteMessageFilter(BControl *control, BDiscreteParameter ¶meter) + : MessageFilter(), + fParameter(parameter) +{ + // initialize view for us + control->SetMessage(new BMessage(kMsgParameterChanged)); + + // set initial value + + size_t size = sizeof(int32); + int32 value; + if (parameter.GetValue((void *)&value, &size, NULL) < B_OK) { + ERROR("Could not get parameter value for %p\n", ¶meter); + return; + } + + if (BCheckBox *checkBox = dynamic_cast(control)) { + checkBox->SetValue(value); + } else if (BOptionPopUp *popUp = dynamic_cast(control)) { + popUp->SelectOptionFor(value); + } else + printf("unknown discrete parameter view\n"); +} + + +DiscreteMessageFilter::~DiscreteMessageFilter() +{ +} + + +filter_result +DiscreteMessageFilter::Filter(BMessage *message, BHandler **target) +{ + BControl *control; + + if (message->what != kMsgParameterChanged + || (control = dynamic_cast(*target)) == NULL) + return B_DISPATCH_MESSAGE; + + // update view + + int32 value = 0; + + if (BCheckBox *checkBox = dynamic_cast(control)) { + value = checkBox->Value(); + } else if (BOptionPopUp *popUp = dynamic_cast(control)) { + popUp->SelectedOption(NULL, &value); + } + + printf("update view %s, value = %ld\n", control->Name(), value); + + if (fParameter.SetValue((void *)&value, sizeof(value), system_time()) < B_OK) { + ERROR("Could not set parameter value for %p\n", &fParameter); + return B_DISPATCH_MESSAGE; + } + + return B_SKIP_MESSAGE; +} + + +// #pragma mark - + + DefaultMediaTheme::DefaultMediaTheme() : BMediaTheme("BeOS Theme", "BeOS built-in theme version 0.1") { @@ -251,8 +483,7 @@ DefaultMediaTheme::MakeViewFor(BParameterGroup &group, const BRect &hintRect) return NULL; BRect rect(hintRect); - BView *view = new BView(rect, group.Name(), B_FOLLOW_NONE, B_WILL_DRAW); - view->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + BView *view = new GroupView(rect, group.Name()); // Create the parameter views - but don't add them yet @@ -415,7 +646,9 @@ DefaultMediaTheme::MakeSelfHostingViewFor(BParameter ¶meter, const BRect &hi return NULL; } - // ToDo: create message filters for this view! + MessageFilter *filter = MessageFilter::FilterFor(view, parameter); + if (filter != NULL) + view->AddFilter(filter); return view; }