Ticket #190: diff.txt

File diff.txt, 11.5 KB (added by jalopeura, 15 years ago)

Patch

Line 
1Index: ../../../src/kits/media/DefaultMediaTheme.cpp
2===================================================================
3--- ../../../src/kits/media/DefaultMediaTheme.cpp (revision 29867)
4+++ ../../../src/kits/media/DefaultMediaTheme.cpp (working copy)
5@@ -22,6 +22,9 @@
6 #include <MenuField.h>
7 #include <MessageFilter.h>
8 #include <Window.h>
9+#include <GroupView.h>
10+#include <LayoutUtils.h>
11+#include <SpaceLayoutItem.h>
12
13
14 using namespace BPrivate;
15@@ -51,24 +54,10 @@
16 bool fIsDocumentScroller;
17 };
18
19-class GroupView : public BView {
20+class GroupView : public BGroupView {
21 public:
22- GroupView(BRect frame, const char *name);
23+ GroupView(const char *name, enum orientation orientation, float spacing);
24 virtual ~GroupView();
25-
26- virtual void AttachedToWindow();
27- virtual void AllAttached();
28- virtual void GetPreferredSize(float *_width, float *_height);
29-
30- virtual BSize MinSize();
31- virtual BSize MaxSize();
32- virtual BSize PreferredSize();
33-
34- void SetContentBounds(BRect bounds);
35- BRect ContentBounds() const { return fContentBounds; }
36-
37- private:
38- BRect fContentBounds;
39 };
40
41 class TabView : public BTabView {
42@@ -87,6 +76,8 @@
43 virtual ~SeparatorView();
44
45 virtual void Draw(BRect updateRect);
46+ virtual void GetPreferredSize(float *width, float *height);
47+ virtual BSize MaxSize();
48
49 private:
50 bool fVertical;
51@@ -94,11 +85,12 @@
52
53 class TitleView : public BView {
54 public:
55- TitleView(BRect frame, const char *title);
56+ TitleView(const char *title);
57 virtual ~TitleView();
58
59 virtual void Draw(BRect updateRect);
60 virtual void GetPreferredSize(float *width, float *height);
61+ virtual BSize MaxSize();
62
63 private:
64 const char *fTitle;
65@@ -350,10 +342,10 @@
66
67 // #pragma mark -
68
69-
70-GroupView::GroupView(BRect frame, const char *name)
71- : BView(frame, name, B_FOLLOW_NONE, B_WILL_DRAW)
72+GroupView::GroupView(const char *name, enum orientation orientation, float spacing)
73+ : BGroupView(orientation, spacing)
74 {
75+ SetName(name);
76 SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
77 }
78
79@@ -363,66 +355,6 @@
80 }
81
82
83-void
84-GroupView::AttachedToWindow()
85-{
86- for (int32 i = CountChildren(); i-- > 0;) {
87- BControl *control = dynamic_cast<BControl *>(ChildAt(i));
88- if (control == NULL)
89- continue;
90-
91- control->SetTarget(control);
92- }
93-}
94-
95-
96-void
97-GroupView::AllAttached()
98-{
99-}
100-
101-
102-void
103-GroupView::GetPreferredSize(float *_width, float *_height)
104-{
105- if (_width)
106- *_width = fContentBounds.Width();
107-
108- if (_height)
109- *_height = fContentBounds.Height();
110-}
111-
112-
113-BSize
114-GroupView::MinSize()
115-{
116- return BSize(100, 100);
117-}
118-
119-
120-BSize
121-GroupView::PreferredSize()
122-{
123- return MinSize();
124-}
125-
126-
127-BSize
128-GroupView::MaxSize()
129-{
130- BSize max;
131- GetPreferredSize(&max.width, &max.height);
132- return max;
133-}
134-
135-
136-void
137-GroupView::SetContentBounds(BRect bounds)
138-{
139- fContentBounds = bounds;
140-}
141-
142-
143 // #pragma mark -
144
145
146@@ -501,11 +433,33 @@
147 }
148
149
150+void
151+SeparatorView::GetPreferredSize(float *_width, float *_height)
152+{
153+ if (_width)
154+ *_width = 0;
155+
156+ if (_height)
157+ *_height = fVertical;
158+}
159+
160+
161+BSize
162+SeparatorView::MaxSize()
163+{
164+ float width, height;
165+ GetPreferredSize(&width, &height);
166+
167+ return BLayoutUtils::ComposeSize(BSize(width, height),
168+ BSize(width, height));
169+}
170+
171+
172 // #pragma mark -
173
174
175-TitleView::TitleView(BRect frame, const char *title)
176- : BView(frame, title, B_FOLLOW_LEFT_RIGHT, B_WILL_DRAW)
177+TitleView::TitleView(const char *title)
178+ : BView(title, B_WILL_DRAW)
179 {
180 fTitle = strdup(title);
181 SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
182@@ -550,6 +504,17 @@
183 }
184
185
186+BSize
187+TitleView::MaxSize()
188+{
189+ float height;
190+ GetPreferredSize(NULL, &height);
191+
192+ return BLayoutUtils::ComposeSize(BSize(B_SIZE_UNLIMITED, height),
193+ BSize(B_SIZE_UNLIMITED, height));
194+}
195+
196+
197 // #pragma mark -
198
199
200@@ -774,7 +739,7 @@
201 if (groupView == NULL)
202 continue;
203
204- if (GroupView *view = dynamic_cast<GroupView *>(groupView)) {
205+ if (BGroupView *view = dynamic_cast<BGroupView *>(groupView)) {
206 // the top-level group views must not be larger than their hintRect,
207 // but unlike their children, they should follow all sides when
208 // their parent is resized
209@@ -826,25 +791,20 @@
210 if (group.Flags() & B_HIDDEN_PARAMETER)
211 return NULL;
212
213- BRect rect;
214- if (hintRect != NULL)
215- rect = *hintRect;
216+ BGroupView *view = new GroupView(group.Name(), B_VERTICAL, 5);
217+
218+ BGroupLayout* viewLayout = view->GroupLayout();
219+ viewLayout->SetInsets(5,5,5,5);
220
221- GroupView *view = new GroupView(rect, group.Name());
222-
223 // Create the parameter views - but don't add them yet
224
225- rect.OffsetTo(B_ORIGIN);
226- rect.InsetBySelf(5, 5);
227-
228 BList views;
229 for (int32 i = 0; i < group.CountParameters(); i++) {
230 BParameter *parameter = group.ParameterAt(i);
231 if (parameter == NULL)
232 continue;
233
234- BView *parameterView = MakeSelfHostingViewFor(*parameter,
235- hintRect ? &rect : NULL);
236+ BView *parameterView = MakeSelfHostingViewFor(*parameter);
237 if (parameterView == NULL)
238 continue;
239
240@@ -859,22 +819,17 @@
241
242 TitleView *titleView = dynamic_cast<TitleView *>((BView *)views.ItemAt(0));
243 if (titleView != NULL) {
244- view->AddChild(titleView);
245- rect.OffsetBy(0, titleView->Bounds().Height());
246+ viewLayout->AddView(titleView);
247 }
248
249 // Add the sub-group views
250
251- rect.right = rect.left + 20;
252- rect.bottom = rect.top + 20;
253- float lastHeight = 0;
254-
255 for (int32 i = 0; i < group.CountGroups(); i++) {
256 BParameterGroup *subGroup = group.GroupAt(i);
257 if (subGroup == NULL)
258 continue;
259
260- BView *groupView = MakeViewFor(*subGroup, &rect);
261+ BView *groupView = MakeViewFor(*subGroup);
262 if (groupView == NULL)
263 continue;
264
265@@ -883,42 +838,23 @@
266 BRect separatorRect(groupView->Frame());
267 separatorRect.left -= 3;
268 separatorRect.right = separatorRect.left + 1;
269- if (lastHeight > separatorRect.Height())
270- separatorRect.bottom = separatorRect.top + lastHeight;
271
272- view->AddChild(new SeparatorView(separatorRect));
273+ viewLayout->AddView(new SeparatorView(separatorRect));
274 }
275
276- view->AddChild(groupView);
277-
278- rect.OffsetBy(groupView->Bounds().Width() + 5, 0);
279-
280- lastHeight = groupView->Bounds().Height();
281- if (lastHeight > rect.Height())
282- rect.bottom = rect.top + lastHeight - 1;
283+ viewLayout->AddView(groupView);
284 }
285
286- view->ResizeTo(rect.left + 10, rect.bottom + 5);
287- view->SetContentBounds(view->Bounds());
288-
289 if (group.CountParameters() == 0)
290 return view;
291
292 // add the parameter views part of the group
293
294- if (group.CountGroups() > 0) {
295- rect.top = rect.bottom + 10;
296- rect.bottom = rect.top + 20;
297- }
298-
299 bool center = false;
300
301 for (int32 i = 0; i < views.CountItems(); i++) {
302 BView *parameterView = static_cast<BView *>(views.ItemAt(i));
303
304- if (parameterView->Bounds().Width() + 5 > rect.Width())
305- rect.right = parameterView->Bounds().Width() + rect.left + 5;
306-
307 // we don't need to add the title view again
308 if (parameterView == titleView)
309 continue;
310@@ -928,33 +864,10 @@
311 if (dynamic_cast<BChannelSlider *>(parameterView) != NULL)
312 center = true;
313
314- parameterView->MoveTo(parameterView->Frame().left, rect.top);
315- view->AddChild(parameterView);
316-
317- rect.OffsetBy(0, parameterView->Bounds().Height() + 5);
318+ viewLayout->AddView(parameterView);
319 }
320
321- if (views.CountItems() > (titleView != NULL ? 1 : 0))
322- view->ResizeTo(rect.right + 5, rect.top + 5);
323-
324- // center the parameter views if needed, and tweak some views
325-
326- float width = view->Bounds().Width();
327-
328- for (int32 i = 0; i < views.CountItems(); i++) {
329- BView *subView = static_cast<BView *>(views.ItemAt(i));
330- BRect frame = subView->Frame();
331-
332- if (center)
333- subView->MoveTo((width - frame.Width()) / 2, frame.top);
334- else {
335- // tweak the PopUp views to look better
336- if (dynamic_cast<BOptionPopUp *>(subView) != NULL)
337- subView->ResizeTo(width, frame.Height());
338- }
339- }
340-
341- view->SetContentBounds(view->Bounds());
342+ viewLayout->AddItem(BSpaceLayoutItem::CreateGlue());
343 return view;
344 }
345
346@@ -970,7 +883,7 @@
347 || parameter_should_be_hidden(parameter))
348 return NULL;
349
350- BView *view = MakeViewFor(&parameter, hintRect);
351+ BView *view = MakeViewFor(&parameter);
352 if (view == NULL) {
353 // The MakeViewFor() method above returns a BControl - which we
354 // don't need for a null parameter; that's why it returns NULL.
355@@ -981,15 +894,13 @@
356 // this is the first parameter in this group, so
357 // let's use a nice title view
358
359- TitleView *titleView = new TitleView(BRect(0, 0, 10, 10), parameter.Name());
360- titleView->ResizeToPreferred();
361+ TitleView *titleView = new TitleView(parameter.Name());
362
363 return titleView;
364 }
365- BStringView *stringView = new BStringView(BRect(0, 0, 10, 10),
366- parameter.Name(), parameter.Name());
367+ BStringView *stringView = new BStringView(parameter.Name(),
368+ parameter.Name());
369 stringView->SetAlignment(B_ALIGN_CENTER);
370- stringView->ResizeToPreferred();
371
372 return stringView;
373 }
374@@ -1009,10 +920,7 @@
375 DefaultMediaTheme::MakeViewFor(BParameter *parameter, const BRect *hintRect)
376 {
377 BRect rect;
378- if (hintRect)
379- rect = *hintRect;
380- else
381- rect.Set(0, 0, 50, 100);
382+ rect.Set(0, 0, 50, 100);
383
384 switch (parameter->Type()) {
385 case BParameter::B_NULL_PARAMETER:
386@@ -1028,9 +936,8 @@
387 || discrete.CountItems() == 0) {
388 // create a checkbox item
389
390- BCheckBox *checkBox = new BCheckBox(rect, discrete.Name(),
391+ BCheckBox *checkBox = new BCheckBox(discrete.Name(),
392 discrete.Name(), NULL);
393- checkBox->ResizeToPreferred();
394
395 return checkBox;
396 } else {
397@@ -1051,14 +958,13 @@
398 rect.right = rect.left + width;
399
400 BOptionPopUp *popUp = new BOptionPopUp(rect, discrete.Name(),
401+ //BOptionPopUp *popUp = new BOptionPopUp(discrete.Name(),
402 discrete.Name(), NULL);
403
404 for (int32 i = 0; i < discrete.CountItems(); i++) {
405 popUp->AddOption(discrete.ItemNameAt(i), discrete.ItemValueAt(i));
406 }
407
408- popUp->ResizeToPreferred();
409-
410 return popUp;
411 }
412 }
413@@ -1069,7 +975,8 @@
414
415 if (!strcmp(continuous.Kind(), B_MASTER_GAIN)
416 || !strcmp(continuous.Kind(), B_GAIN)) {
417- BChannelSlider *slider = new BChannelSlider(rect, continuous.Name(),
418+ //BChannelSlider *slider = new BChannelSlider(rect, continuous.Name(),
419+ BChannelSlider *slider = new BChannelSlider(continuous.Name(),
420 continuous.Name(), NULL, B_VERTICAL, continuous.CountChannels());
421
422 char minLabel[64], maxLabel[64];
423@@ -1085,10 +992,6 @@
424 }
425 slider->SetLimitLabels(minLabel, maxLabel);
426
427- float width, height;
428- slider->GetPreferredSize(&width, &height);
429- slider->ResizeTo(width, 190);
430-
431 // ToDo: take BContinuousParameter::GetResponse() & ValueStep() into account!
432
433 for (int32 i = 0; i < continuous.CountChannels(); i++) {
434@@ -1100,12 +1003,9 @@
435 }
436
437 BSlider *slider = new BSlider(rect, parameter->Name(), parameter->Name(),
438+ //BSlider *slider = new BSlider(parameter->Name(), parameter->Name(),
439 NULL, 0, 100);
440
441- float width, height;
442- slider->GetPreferredSize(&width, &height);
443- slider->ResizeTo(100, height);
444-
445 return slider;
446 }
447
448Index: ../../../headers/private/media/DefaultMediaTheme.h
449===================================================================
450--- ../../../headers/private/media/DefaultMediaTheme.h (revision 29867)
451+++ ../../../headers/private/media/DefaultMediaTheme.h (working copy)
452@@ -27,8 +27,8 @@
453 virtual BView* MakeViewFor(BParameterWeb* web, const BRect* hintRect = NULL);
454
455 private:
456- BView* MakeViewFor(BParameterGroup& group, const BRect* hintRect);
457- BView* MakeSelfHostingViewFor(BParameter& parameter, const BRect* hintRect);
458+ BView* MakeViewFor(BParameterGroup& group, const BRect* hintRect = NULL);
459+ BView* MakeSelfHostingViewFor(BParameter& parameter, const BRect* hintRect = NULL);
460 };
461
462 } // namespace BPrivate