Index: ../../../src/kits/media/DefaultMediaTheme.cpp =================================================================== --- ../../../src/kits/media/DefaultMediaTheme.cpp (revision 29867) +++ ../../../src/kits/media/DefaultMediaTheme.cpp (working copy) @@ -22,6 +22,9 @@ #include #include #include +#include +#include +#include using namespace BPrivate; @@ -51,24 +54,10 @@ bool fIsDocumentScroller; }; -class GroupView : public BView { +class GroupView : public BGroupView { public: - GroupView(BRect frame, const char *name); + GroupView(const char *name, enum orientation orientation, float spacing); virtual ~GroupView(); - - virtual void AttachedToWindow(); - virtual void AllAttached(); - virtual void GetPreferredSize(float *_width, float *_height); - - virtual BSize MinSize(); - virtual BSize MaxSize(); - virtual BSize PreferredSize(); - - void SetContentBounds(BRect bounds); - BRect ContentBounds() const { return fContentBounds; } - - private: - BRect fContentBounds; }; class TabView : public BTabView { @@ -87,6 +76,8 @@ virtual ~SeparatorView(); virtual void Draw(BRect updateRect); + virtual void GetPreferredSize(float *width, float *height); + virtual BSize MaxSize(); private: bool fVertical; @@ -94,11 +85,12 @@ class TitleView : public BView { public: - TitleView(BRect frame, const char *title); + TitleView(const char *title); virtual ~TitleView(); virtual void Draw(BRect updateRect); virtual void GetPreferredSize(float *width, float *height); + virtual BSize MaxSize(); private: const char *fTitle; @@ -350,10 +342,10 @@ // #pragma mark - - -GroupView::GroupView(BRect frame, const char *name) - : BView(frame, name, B_FOLLOW_NONE, B_WILL_DRAW) +GroupView::GroupView(const char *name, enum orientation orientation, float spacing) + : BGroupView(orientation, spacing) { + SetName(name); SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); } @@ -363,66 +355,6 @@ } -void -GroupView::AttachedToWindow() -{ - for (int32 i = CountChildren(); i-- > 0;) { - BControl *control = dynamic_cast(ChildAt(i)); - if (control == NULL) - continue; - - control->SetTarget(control); - } -} - - -void -GroupView::AllAttached() -{ -} - - -void -GroupView::GetPreferredSize(float *_width, float *_height) -{ - if (_width) - *_width = fContentBounds.Width(); - - if (_height) - *_height = fContentBounds.Height(); -} - - -BSize -GroupView::MinSize() -{ - return BSize(100, 100); -} - - -BSize -GroupView::PreferredSize() -{ - return MinSize(); -} - - -BSize -GroupView::MaxSize() -{ - BSize max; - GetPreferredSize(&max.width, &max.height); - return max; -} - - -void -GroupView::SetContentBounds(BRect bounds) -{ - fContentBounds = bounds; -} - - // #pragma mark - @@ -501,11 +433,33 @@ } +void +SeparatorView::GetPreferredSize(float *_width, float *_height) +{ + if (_width) + *_width = 0; + + if (_height) + *_height = fVertical; +} + + +BSize +SeparatorView::MaxSize() +{ + float width, height; + GetPreferredSize(&width, &height); + + return BLayoutUtils::ComposeSize(BSize(width, height), + BSize(width, height)); +} + + // #pragma mark - -TitleView::TitleView(BRect frame, const char *title) - : BView(frame, title, B_FOLLOW_LEFT_RIGHT, B_WILL_DRAW) +TitleView::TitleView(const char *title) + : BView(title, B_WILL_DRAW) { fTitle = strdup(title); SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); @@ -550,6 +504,17 @@ } +BSize +TitleView::MaxSize() +{ + float height; + GetPreferredSize(NULL, &height); + + return BLayoutUtils::ComposeSize(BSize(B_SIZE_UNLIMITED, height), + BSize(B_SIZE_UNLIMITED, height)); +} + + // #pragma mark - @@ -774,7 +739,7 @@ if (groupView == NULL) continue; - if (GroupView *view = dynamic_cast(groupView)) { + if (BGroupView *view = dynamic_cast(groupView)) { // the top-level group views must not be larger than their hintRect, // but unlike their children, they should follow all sides when // their parent is resized @@ -826,25 +791,20 @@ if (group.Flags() & B_HIDDEN_PARAMETER) return NULL; - BRect rect; - if (hintRect != NULL) - rect = *hintRect; + BGroupView *view = new GroupView(group.Name(), B_VERTICAL, 5); + + BGroupLayout* viewLayout = view->GroupLayout(); + viewLayout->SetInsets(5,5,5,5); - GroupView *view = new GroupView(rect, group.Name()); - // Create the parameter views - but don't add them yet - rect.OffsetTo(B_ORIGIN); - rect.InsetBySelf(5, 5); - BList views; for (int32 i = 0; i < group.CountParameters(); i++) { BParameter *parameter = group.ParameterAt(i); if (parameter == NULL) continue; - BView *parameterView = MakeSelfHostingViewFor(*parameter, - hintRect ? &rect : NULL); + BView *parameterView = MakeSelfHostingViewFor(*parameter); if (parameterView == NULL) continue; @@ -859,22 +819,17 @@ TitleView *titleView = dynamic_cast((BView *)views.ItemAt(0)); if (titleView != NULL) { - view->AddChild(titleView); - rect.OffsetBy(0, titleView->Bounds().Height()); + viewLayout->AddView(titleView); } // Add the sub-group views - rect.right = rect.left + 20; - rect.bottom = rect.top + 20; - float lastHeight = 0; - for (int32 i = 0; i < group.CountGroups(); i++) { BParameterGroup *subGroup = group.GroupAt(i); if (subGroup == NULL) continue; - BView *groupView = MakeViewFor(*subGroup, &rect); + BView *groupView = MakeViewFor(*subGroup); if (groupView == NULL) continue; @@ -883,42 +838,23 @@ BRect separatorRect(groupView->Frame()); separatorRect.left -= 3; separatorRect.right = separatorRect.left + 1; - if (lastHeight > separatorRect.Height()) - separatorRect.bottom = separatorRect.top + lastHeight; - view->AddChild(new SeparatorView(separatorRect)); + viewLayout->AddView(new SeparatorView(separatorRect)); } - view->AddChild(groupView); - - rect.OffsetBy(groupView->Bounds().Width() + 5, 0); - - lastHeight = groupView->Bounds().Height(); - if (lastHeight > rect.Height()) - rect.bottom = rect.top + lastHeight - 1; + viewLayout->AddView(groupView); } - view->ResizeTo(rect.left + 10, rect.bottom + 5); - view->SetContentBounds(view->Bounds()); - if (group.CountParameters() == 0) return view; // add the parameter views part of the group - if (group.CountGroups() > 0) { - rect.top = rect.bottom + 10; - rect.bottom = rect.top + 20; - } - bool center = false; for (int32 i = 0; i < views.CountItems(); i++) { BView *parameterView = static_cast(views.ItemAt(i)); - if (parameterView->Bounds().Width() + 5 > rect.Width()) - rect.right = parameterView->Bounds().Width() + rect.left + 5; - // we don't need to add the title view again if (parameterView == titleView) continue; @@ -928,33 +864,10 @@ if (dynamic_cast(parameterView) != NULL) center = true; - parameterView->MoveTo(parameterView->Frame().left, rect.top); - view->AddChild(parameterView); - - rect.OffsetBy(0, parameterView->Bounds().Height() + 5); + viewLayout->AddView(parameterView); } - if (views.CountItems() > (titleView != NULL ? 1 : 0)) - view->ResizeTo(rect.right + 5, rect.top + 5); - - // center the parameter views if needed, and tweak some views - - float width = view->Bounds().Width(); - - for (int32 i = 0; i < views.CountItems(); i++) { - BView *subView = static_cast(views.ItemAt(i)); - BRect frame = subView->Frame(); - - if (center) - subView->MoveTo((width - frame.Width()) / 2, frame.top); - else { - // tweak the PopUp views to look better - if (dynamic_cast(subView) != NULL) - subView->ResizeTo(width, frame.Height()); - } - } - - view->SetContentBounds(view->Bounds()); + viewLayout->AddItem(BSpaceLayoutItem::CreateGlue()); return view; } @@ -970,7 +883,7 @@ || parameter_should_be_hidden(parameter)) return NULL; - BView *view = MakeViewFor(¶meter, hintRect); + BView *view = MakeViewFor(¶meter); if (view == NULL) { // The MakeViewFor() method above returns a BControl - which we // don't need for a null parameter; that's why it returns NULL. @@ -981,15 +894,13 @@ // this is the first parameter in this group, so // let's use a nice title view - TitleView *titleView = new TitleView(BRect(0, 0, 10, 10), parameter.Name()); - titleView->ResizeToPreferred(); + TitleView *titleView = new TitleView(parameter.Name()); return titleView; } - BStringView *stringView = new BStringView(BRect(0, 0, 10, 10), - parameter.Name(), parameter.Name()); + BStringView *stringView = new BStringView(parameter.Name(), + parameter.Name()); stringView->SetAlignment(B_ALIGN_CENTER); - stringView->ResizeToPreferred(); return stringView; } @@ -1009,10 +920,7 @@ DefaultMediaTheme::MakeViewFor(BParameter *parameter, const BRect *hintRect) { BRect rect; - if (hintRect) - rect = *hintRect; - else - rect.Set(0, 0, 50, 100); + rect.Set(0, 0, 50, 100); switch (parameter->Type()) { case BParameter::B_NULL_PARAMETER: @@ -1028,9 +936,8 @@ || discrete.CountItems() == 0) { // create a checkbox item - BCheckBox *checkBox = new BCheckBox(rect, discrete.Name(), + BCheckBox *checkBox = new BCheckBox(discrete.Name(), discrete.Name(), NULL); - checkBox->ResizeToPreferred(); return checkBox; } else { @@ -1051,14 +958,13 @@ rect.right = rect.left + width; BOptionPopUp *popUp = new BOptionPopUp(rect, discrete.Name(), + //BOptionPopUp *popUp = new BOptionPopUp(discrete.Name(), discrete.Name(), NULL); for (int32 i = 0; i < discrete.CountItems(); i++) { popUp->AddOption(discrete.ItemNameAt(i), discrete.ItemValueAt(i)); } - popUp->ResizeToPreferred(); - return popUp; } } @@ -1069,7 +975,8 @@ if (!strcmp(continuous.Kind(), B_MASTER_GAIN) || !strcmp(continuous.Kind(), B_GAIN)) { - BChannelSlider *slider = new BChannelSlider(rect, continuous.Name(), + //BChannelSlider *slider = new BChannelSlider(rect, continuous.Name(), + BChannelSlider *slider = new BChannelSlider(continuous.Name(), continuous.Name(), NULL, B_VERTICAL, continuous.CountChannels()); char minLabel[64], maxLabel[64]; @@ -1085,10 +992,6 @@ } slider->SetLimitLabels(minLabel, maxLabel); - float width, height; - slider->GetPreferredSize(&width, &height); - slider->ResizeTo(width, 190); - // ToDo: take BContinuousParameter::GetResponse() & ValueStep() into account! for (int32 i = 0; i < continuous.CountChannels(); i++) { @@ -1100,12 +1003,9 @@ } BSlider *slider = new BSlider(rect, parameter->Name(), parameter->Name(), + //BSlider *slider = new BSlider(parameter->Name(), parameter->Name(), NULL, 0, 100); - float width, height; - slider->GetPreferredSize(&width, &height); - slider->ResizeTo(100, height); - return slider; } Index: ../../../headers/private/media/DefaultMediaTheme.h =================================================================== --- ../../../headers/private/media/DefaultMediaTheme.h (revision 29867) +++ ../../../headers/private/media/DefaultMediaTheme.h (working copy) @@ -27,8 +27,8 @@ virtual BView* MakeViewFor(BParameterWeb* web, const BRect* hintRect = NULL); private: - BView* MakeViewFor(BParameterGroup& group, const BRect* hintRect); - BView* MakeSelfHostingViewFor(BParameter& parameter, const BRect* hintRect); + BView* MakeViewFor(BParameterGroup& group, const BRect* hintRect = NULL); + BView* MakeSelfHostingViewFor(BParameter& parameter, const BRect* hintRect = NULL); }; } // namespace BPrivate