xref: /haiku/headers/os/interface/LayoutBuilder.h (revision cb5156f08199a66a2bb4813f9ae1aea9598721c4)
1 /*
2  * Copyright 2009-2015, Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef	_LAYOUT_BUILDER_H
6 #define	_LAYOUT_BUILDER_H
7 
8 
9 #include <new>
10 
11 #include <CardLayout.h>
12 #include <CardView.h>
13 #include <GridLayout.h>
14 #include <GridView.h>
15 #include <GroupLayout.h>
16 #include <GroupView.h>
17 #include <Menu.h>
18 #include <MenuField.h>
19 #include <MenuItem.h>
20 #include <SpaceLayoutItem.h>
21 #include <SplitView.h>
22 #include <TextControl.h>
23 #include <Window.h>
24 
25 
26 namespace BLayoutBuilder {
27 
28 template<typename ParentBuilder> class Base;
29 template<typename ParentBuilder = void*> class Group;
30 template<typename ParentBuilder = void*> class Grid;
31 template<typename ParentBuilder = void*> class Split;
32 template<typename ParentBuilder = void*> class Cards;
33 template<typename ParentBuilder = void*> class Menu;
34 template<typename ParentBuilder = void*> class MenuItem;
35 
36 
37 template<typename ParentBuilder>
38 class Base {
39 protected:
40 	inline						Base();
41 
42 public:
43 	inline	void				SetParent(ParentBuilder* parent);
44 		// conceptually private
45 	inline	ParentBuilder&		End();
46 
47 protected:
48 			ParentBuilder*		fParent;
49 };
50 
51 
52 template<typename ParentBuilder>
53 class Group : public Base<ParentBuilder> {
54 public:
55 	typedef Group<ParentBuilder>	ThisBuilder;
56 	typedef Group<ThisBuilder>		GroupBuilder;
57 	typedef Grid<ThisBuilder>		GridBuilder;
58 	typedef Split<ThisBuilder>		SplitBuilder;
59 	typedef Cards<ThisBuilder>		CardBuilder;
60 
61 public:
62 	inline						Group(orientation orientation = B_HORIZONTAL,
63 									float spacing = B_USE_DEFAULT_SPACING);
64 	inline						Group(BWindow* window,
65 									orientation orientation = B_HORIZONTAL,
66 									float spacing = B_USE_DEFAULT_SPACING);
67 	inline						Group(BView* view,
68 									orientation orientation = B_HORIZONTAL,
69 									float spacing = B_USE_DEFAULT_SPACING);
70 	inline						Group(BGroupLayout* layout);
71 	inline						Group(BGroupView* view);
72 
73 	inline	BGroupLayout*		Layout() const;
74 	inline	BView*				View() const;
75 	inline	ThisBuilder&		GetLayout(BGroupLayout** _layout);
76 	inline	ThisBuilder&		GetView(BView** _view);
77 
78 	inline	ThisBuilder&		Add(BView* view);
79 	inline	ThisBuilder&		Add(BView* view, float weight);
80 	inline	ThisBuilder&		Add(BLayoutItem* item);
81 	inline	ThisBuilder&		Add(BLayoutItem* item, float weight);
82 
83 	inline	GroupBuilder		AddGroup(orientation orientation,
84 									float spacing = B_USE_DEFAULT_SPACING,
85 									float weight = 1.0f);
86 	inline	GroupBuilder		AddGroup(BGroupView* groupView,
87 									float weight = 1.0f);
88 	inline	GroupBuilder		AddGroup(BGroupLayout* groupLayout,
89 									float weight = 1.0f);
90 
91 	inline	GridBuilder			AddGrid(float horizontal
92 										= B_USE_DEFAULT_SPACING,
93 									float vertical = B_USE_DEFAULT_SPACING,
94 									float weight = 1.0f);
95 	inline	GridBuilder			AddGrid(BGridLayout* gridLayout,
96 									float weight = 1.0f);
97 	inline	GridBuilder			AddGrid(BGridView* gridView,
98 									float weight = 1.0f);
99 
100 	inline	SplitBuilder		AddSplit(orientation orientation,
101 									float spacing = B_USE_DEFAULT_SPACING,
102 									float weight = 1.0f);
103 	inline	SplitBuilder		AddSplit(BSplitView* splitView,
104 									float weight = 1.0f);
105 
106 	inline	CardBuilder			AddCards(float weight = 1.0f);
107 	inline	CardBuilder			AddCards(BCardLayout* cardLayout,
108 									float weight = 1.0f);
109 	inline	CardBuilder			AddCards(BCardView* cardView,
110 									float weight = 1.0f);
111 
112 	inline	ThisBuilder&		AddGlue(float weight = 1.0f);
113 	inline	ThisBuilder&		AddStrut(float size);
114 
115 	inline	ThisBuilder&		SetInsets(float left, float top, float right,
116 									float bottom);
117 	inline	ThisBuilder&		SetInsets(float horizontal, float vertical);
118 	inline	ThisBuilder&		SetInsets(float insets);
119 
120 	inline	ThisBuilder&		SetExplicitMinSize(BSize size);
121 	inline	ThisBuilder&		SetExplicitMaxSize(BSize size);
122 	inline	ThisBuilder&		SetExplicitPreferredSize(BSize size);
123 	inline	ThisBuilder&		SetExplicitAlignment(BAlignment alignment);
124 
125 	inline						operator BGroupLayout*();
126 
127 private:
128 			BGroupLayout*		fLayout;
129 };
130 
131 
132 template<typename ParentBuilder>
133 class Grid : public Base<ParentBuilder> {
134 public:
135 	typedef Grid<ParentBuilder>		ThisBuilder;
136 	typedef Group<ThisBuilder>		GroupBuilder;
137 	typedef Grid<ThisBuilder>		GridBuilder;
138 	typedef Split<ThisBuilder>		SplitBuilder;
139 	typedef Cards<ThisBuilder>		CardBuilder;
140 
141 public:
142 	inline						Grid(float horizontal
143 										= B_USE_DEFAULT_SPACING,
144 									float vertical = B_USE_DEFAULT_SPACING);
145 	inline						Grid(BWindow* window,
146 									float horizontal = B_USE_DEFAULT_SPACING,
147 									float vertical = B_USE_DEFAULT_SPACING);
148 	inline						Grid(BView* view,
149 									float horizontal = B_USE_DEFAULT_SPACING,
150 									float vertical = B_USE_DEFAULT_SPACING);
151 	inline						Grid(BGridLayout* layout);
152 	inline						Grid(BGridView* view);
153 
154 	inline	BGridLayout*		Layout() const;
155 	inline	BView*				View() const;
156 	inline	ThisBuilder&		GetLayout(BGridLayout** _layout);
157 	inline	ThisBuilder&		GetView(BView** _view);
158 
159 	inline	ThisBuilder&		Add(BView* view, int32 column, int32 row,
160 									int32 columnCount = 1, int32 rowCount = 1);
161 	inline	ThisBuilder&		Add(BLayoutItem* item, int32 column, int32 row,
162 									int32 columnCount = 1, int32 rowCount = 1);
163 	inline	ThisBuilder&		AddMenuField(BMenuField* menuField,
164 									int32 column, int32 row,
165 									alignment labelAlignment
166 										= B_ALIGN_HORIZONTAL_UNSET,
167 									int32 labelColumnCount = 1,
168 									int32 fieldColumnCount = 1,
169 									int32 rowCount = 1);
170 	inline	ThisBuilder&		AddTextControl(BTextControl* textControl,
171 									int32 column, int32 row,
172 									alignment labelAlignment
173 										= B_ALIGN_HORIZONTAL_UNSET,
174 									int32 labelColumnCount = 1,
175 									int32 textColumnCount = 1,
176 									int32 rowCount = 1);
177 
178 	inline	GroupBuilder		AddGroup(orientation orientation,
179 									float spacing, int32 column, int32 row,
180 									int32 columnCount = 1, int32 rowCount = 1);
181 	inline	GroupBuilder		AddGroup(BGroupView* groupView,	int32 column,
182 									int32 row, int32 columnCount = 1,
183 									int32 rowCount = 1);
184 	inline	GroupBuilder		AddGroup(BGroupLayout* groupLayout,
185 									int32 column, int32 row,
186 									int32 columnCount = 1, int32 rowCount = 1);
187 
188 	inline	GridBuilder			AddGrid(float horizontalSpacing,
189 									float verticalSpacing, int32 column,
190 									int32 row, int32 columnCount = 1,
191 									int32 rowCount = 1);
192 	inline	GridBuilder			AddGrid(BGridLayout* gridLayout,
193 									int32 column, int32 row,
194 									int32 columnCount = 1, int32 rowCount = 1);
195 	inline	GridBuilder			AddGrid(BGridView* gridView,
196 									int32 column, int32 row,
197 									int32 columnCount = 1, int32 rowCount = 1);
198 
199 	inline	SplitBuilder		AddSplit(orientation orientation,
200 									float spacing, int32 column, int32 row,
201 									int32 columnCount = 1, int32 rowCount = 1);
202 	inline	SplitBuilder		AddSplit(BSplitView* splitView, int32 column,
203 									int32 row, int32 columnCount = 1,
204 									int32 rowCount = 1);
205 
206 	inline	CardBuilder			AddCards(int32 column, int32 row,
207 									int32 columnCount = 1, int32 rowCount = 1);
208 	inline	CardBuilder			AddCards(BCardLayout* cardLayout, int32 column,
209 									int32 row, int32 columnCount = 1,
210 									int32 rowCount = 1);
211 	inline	CardBuilder			AddCards(BCardView* cardView, int32 column,
212 									int32 row, int32 columnCount = 1,
213 									int32 rowCount = 1);
214 
215 	inline	ThisBuilder&		AddGlue(int32 column, int32 row,
216 									int32 columnCount = 1, int32 rowCount = 1);
217 
218 	inline	ThisBuilder&		SetHorizontalSpacing(float spacing);
219 	inline	ThisBuilder&		SetVerticalSpacing(float spacing);
220 	inline	ThisBuilder&		SetSpacing(float horizontal, float vertical);
221 
222 	inline	ThisBuilder&		SetColumnWeight(int32 column, float weight);
223 	inline	ThisBuilder&		SetRowWeight(int32 row, float weight);
224 
225 	inline	ThisBuilder&		SetInsets(float left, float top, float right,
226 									float bottom);
227 	inline	ThisBuilder&		SetInsets(float horizontal, float vertical);
228 	inline	ThisBuilder&		SetInsets(float insets);
229 
230 	inline	ThisBuilder&		SetExplicitMinSize(BSize size);
231 	inline	ThisBuilder&		SetExplicitMaxSize(BSize size);
232 	inline	ThisBuilder&		SetExplicitPreferredSize(BSize size);
233 	inline	ThisBuilder&		SetExplicitAlignment(BAlignment alignment);
234 
235 	inline						operator BGridLayout*();
236 
237 private:
238 			BGridLayout*		fLayout;
239 };
240 
241 
242 template<typename ParentBuilder>
243 class Split : public Base<ParentBuilder> {
244 public:
245 	typedef Split<ParentBuilder>	ThisBuilder;
246 	typedef Group<ThisBuilder>		GroupBuilder;
247 	typedef Grid<ThisBuilder>		GridBuilder;
248 	typedef Split<ThisBuilder>		SplitBuilder;
249 	typedef Cards<ThisBuilder>		CardBuilder;
250 
251 public:
252 	inline						Split(orientation orientation = B_HORIZONTAL,
253 									float spacing = B_USE_DEFAULT_SPACING);
254 	inline						Split(BSplitView* view);
255 
256 	inline	BSplitView*			View() const;
257 	inline	ThisBuilder&		GetView(BView** _view);
258 	inline	ThisBuilder&		GetSplitView(BSplitView** _view);
259 
260 	inline	ThisBuilder&		Add(BView* view);
261 	inline	ThisBuilder&		Add(BView* view, float weight);
262 	inline	ThisBuilder&		Add(BLayoutItem* item);
263 	inline	ThisBuilder&		Add(BLayoutItem* item, float weight);
264 
265 	inline	GroupBuilder		AddGroup(orientation orientation,
266 									float spacing = B_USE_DEFAULT_SPACING,
267 									float weight = 1.0f);
268 	inline	GroupBuilder		AddGroup(BGroupView* groupView,
269 									float weight = 1.0f);
270 	inline	GroupBuilder		AddGroup(BGroupLayout* groupLayout,
271 									float weight = 1.0f);
272 
273 	inline	GridBuilder			AddGrid(float horizontal
274 											= B_USE_DEFAULT_SPACING,
275 									float vertical = B_USE_DEFAULT_SPACING,
276 									float weight = 1.0f);
277 	inline	GridBuilder			AddGrid(BGridView* gridView,
278 									float weight = 1.0f);
279 	inline	GridBuilder			AddGrid(BGridLayout* gridLayout,
280 									float weight = 1.0f);
281 
282 	inline	SplitBuilder		AddSplit(orientation orientation,
283 									float spacing = B_USE_DEFAULT_SPACING,
284 									float weight = 1.0f);
285 	inline	SplitBuilder		AddSplit(BSplitView* splitView,
286 									float weight = 1.0f);
287 
288 	inline	CardBuilder			AddCards(float weight = 1.0f);
289 	inline	CardBuilder			AddCards(BCardLayout* cardLayout,
290 									float weight = 1.0f);
291 	inline	CardBuilder			AddCards(BCardView* cardView,
292 									float weight = 1.0f);
293 
294 	inline	ThisBuilder&		SetCollapsible(bool collapsible);
295 	inline	ThisBuilder&		SetCollapsible(int32 index, bool collapsible);
296 	inline	ThisBuilder&		SetCollapsible(int32 first, int32 last,
297 									bool collapsible);
298 
299 	inline	ThisBuilder&		SetInsets(float left, float top, float right,
300 									float bottom);
301 	inline	ThisBuilder&		SetInsets(float horizontal, float vertical);
302 	inline	ThisBuilder&		SetInsets(float insets);
303 
304 	inline						operator BSplitView*();
305 
306 private:
307 			BSplitView*			fView;
308 };
309 
310 template<typename ParentBuilder>
311 class Cards : public Base<ParentBuilder> {
312 public:
313 	typedef Cards<ParentBuilder>	ThisBuilder;
314 	typedef Group<ThisBuilder>		GroupBuilder;
315 	typedef Grid<ThisBuilder>		GridBuilder;
316 	typedef Split<ThisBuilder>		SplitBuilder;
317 	typedef Cards<ThisBuilder>		CardBuilder;
318 
319 public:
320 	inline						Cards();
321 	inline						Cards(BWindow* window);
322 	inline						Cards(BView* view);
323 	inline						Cards(BCardLayout* layout);
324 	inline						Cards(BCardView* view);
325 
326 	inline	BCardLayout*		Layout() const;
327 	inline	BView*				View() const;
328 	inline	ThisBuilder&		GetLayout(BCardLayout** _layout);
329 	inline	ThisBuilder&		GetView(BView** _view);
330 
331 	inline	ThisBuilder&		Add(BView* view);
332 	inline	ThisBuilder&		Add(BLayoutItem* item);
333 
334 	inline	GroupBuilder		AddGroup(orientation orientation,
335 									float spacing = B_USE_DEFAULT_SPACING);
336 	inline	GroupBuilder		AddGroup(BGroupView* groupView);
337 	inline	GroupBuilder		AddGroup(BGroupLayout* groupLayout);
338 
339 	inline	GridBuilder			AddGrid(float horizontal
340 										= B_USE_DEFAULT_SPACING,
341 									float vertical = B_USE_DEFAULT_SPACING);
342 	inline	GridBuilder			AddGrid(BGridLayout* gridLayout);
343 	inline	GridBuilder			AddGrid(BGridView* gridView);
344 
345 	inline	SplitBuilder		AddSplit(orientation orientation,
346 									float spacing = B_USE_DEFAULT_SPACING);
347 	inline	SplitBuilder		AddSplit(BSplitView* splitView);
348 
349 	inline	CardBuilder			AddCards();
350 	inline	CardBuilder			AddCards(BCardLayout* cardLayout);
351 	inline	CardBuilder			AddCards(BCardView* cardView);
352 
353 	inline	ThisBuilder&		SetExplicitMinSize(BSize size);
354 	inline	ThisBuilder&		SetExplicitMaxSize(BSize size);
355 	inline	ThisBuilder&		SetExplicitPreferredSize(BSize size);
356 	inline	ThisBuilder&		SetExplicitAlignment(BAlignment alignment);
357 
358 	inline	ThisBuilder&		SetVisibleItem(int32 index);
359 
360 	inline						operator BCardLayout*();
361 
362 private:
363 			BCardLayout*		fLayout;
364 };
365 
366 
367 template<typename ParentBuilder>
368 class Menu : public Base<ParentBuilder> {
369 public:
370 	typedef Menu<ParentBuilder>		ThisBuilder;
371 	typedef MenuItem<ParentBuilder>	ItemBuilder;
372 	typedef Menu<ThisBuilder>		MenuBuilder;
373 
374 public:
375 	inline						Menu(BMenu* menu);
376 
377 	inline	ThisBuilder&		GetMenu(BMenu*& _menu);
378 
379 	inline	ItemBuilder			AddItem(BMenuItem* item);
380 	inline	ItemBuilder			AddItem(BMenu* menu);
381 	inline	ItemBuilder			AddItem(const char* label, BMessage* message,
382 									char shortcut = 0, uint32 modifiers = 0);
383 	inline	ItemBuilder			AddItem(const char* label, uint32 messageWhat,
384 									char shortcut = 0, uint32 modifiers = 0);
385 
386 	inline	MenuBuilder			AddMenu(BMenu* menu);
387 	inline	MenuBuilder			AddMenu(const char* title,
388 									menu_layout layout = B_ITEMS_IN_COLUMN);
389 
390 	inline	ThisBuilder&		AddSeparator();
391 
392 private:
393 			BMenu*				fMenu;
394 };
395 
396 
397 template<typename ParentBuilder>
398 class MenuItem : public Menu<ParentBuilder> {
399 public:
400 	typedef MenuItem<ParentBuilder>	ThisBuilder;
401 
402 public:
403 	inline						MenuItem(ParentBuilder* parentBuilder,
404 									BMenu* menu, BMenuItem* item);
405 
406 	inline	ThisBuilder&		GetItem(BMenuItem*& _item);
407 
408 	inline	ThisBuilder&		SetEnabled(bool enabled);
409 
410 private:
411 			BMenuItem*			fMenuItem;
412 };
413 
414 
415 // #pragma mark - Base
416 
417 
418 template<typename ParentBuilder>
Base()419 Base<ParentBuilder>::Base()
420 	:
421 	fParent(NULL)
422 {
423 }
424 
425 
426 template<typename ParentBuilder>
427 void
SetParent(ParentBuilder * parent)428 Base<ParentBuilder>::SetParent(ParentBuilder* parent)
429 {
430 	fParent = parent;
431 }
432 
433 
434 template<typename ParentBuilder>
435 ParentBuilder&
End()436 Base<ParentBuilder>::End()
437 {
438 	return *fParent;
439 }
440 
441 
442 // #pragma mark - Group
443 
444 
445 template<typename ParentBuilder>
Group(orientation orientation,float spacing)446 Group<ParentBuilder>::Group(orientation orientation, float spacing)
447 	:
448 	fLayout((new BGroupView(orientation, spacing))->GroupLayout())
449 {
450 }
451 
452 
453 template<typename ParentBuilder>
Group(BWindow * window,orientation orientation,float spacing)454 Group<ParentBuilder>::Group(BWindow* window, orientation orientation,
455 		float spacing)
456 	:
457 	fLayout(new BGroupLayout(orientation, spacing))
458 {
459 	window->SetLayout(fLayout);
460 	fLayout->Owner()->AdoptSystemColors();
461 }
462 
463 
464 template<typename ParentBuilder>
Group(BView * view,orientation orientation,float spacing)465 Group<ParentBuilder>::Group(BView* view, orientation orientation,
466 		float spacing)
467 	:
468 	fLayout(new BGroupLayout(orientation, spacing))
469 {
470 
471 	if (view->HasDefaultColors())
472 		view->AdoptSystemColors();
473 
474 	view->SetLayout(fLayout);
475 }
476 
477 
478 template<typename ParentBuilder>
Group(BGroupLayout * layout)479 Group<ParentBuilder>::Group(BGroupLayout* layout)
480 	:
481 	fLayout(layout)
482 {
483 }
484 
485 
486 template<typename ParentBuilder>
Group(BGroupView * view)487 Group<ParentBuilder>::Group(BGroupView* view)
488 	:
489 	fLayout(view->GroupLayout())
490 {
491 }
492 
493 
494 template<typename ParentBuilder>
495 BGroupLayout*
Layout()496 Group<ParentBuilder>::Layout() const
497 {
498 	return fLayout;
499 }
500 
501 
502 template<typename ParentBuilder>
503 BView*
View()504 Group<ParentBuilder>::View() const
505 {
506 	return fLayout->Owner();
507 }
508 
509 
510 template<typename ParentBuilder>
511 typename Group<ParentBuilder>::ThisBuilder&
GetLayout(BGroupLayout ** _layout)512 Group<ParentBuilder>::GetLayout(BGroupLayout** _layout)
513 {
514 	*_layout = fLayout;
515 	return *this;
516 }
517 
518 
519 template<typename ParentBuilder>
520 typename Group<ParentBuilder>::ThisBuilder&
GetView(BView ** _view)521 Group<ParentBuilder>::GetView(BView** _view)
522 {
523 	*_view = fLayout->Owner();
524 	return *this;
525 }
526 
527 
528 template<typename ParentBuilder>
529 typename Group<ParentBuilder>::ThisBuilder&
Add(BView * view)530 Group<ParentBuilder>::Add(BView* view)
531 {
532 	fLayout->AddView(view);
533 	return *this;
534 }
535 
536 
537 template<typename ParentBuilder>
538 typename Group<ParentBuilder>::ThisBuilder&
Add(BView * view,float weight)539 Group<ParentBuilder>::Add(BView* view, float weight)
540 {
541 	fLayout->AddView(view, weight);
542 	return *this;
543 }
544 
545 
546 template<typename ParentBuilder>
547 typename Group<ParentBuilder>::ThisBuilder&
Add(BLayoutItem * item)548 Group<ParentBuilder>::Add(BLayoutItem* item)
549 {
550 	fLayout->AddItem(item);
551 	return *this;
552 }
553 
554 
555 template<typename ParentBuilder>
556 typename Group<ParentBuilder>::ThisBuilder&
Add(BLayoutItem * item,float weight)557 Group<ParentBuilder>::Add(BLayoutItem* item, float weight)
558 {
559 	fLayout->AddItem(item, weight);
560 	return *this;
561 }
562 
563 
564 template<typename ParentBuilder>
565 typename Group<ParentBuilder>::GroupBuilder
AddGroup(orientation orientation,float spacing,float weight)566 Group<ParentBuilder>::AddGroup(orientation orientation, float spacing,
567 		float weight)
568 {
569 	GroupBuilder builder(new BGroupLayout(orientation, spacing));
570 	builder.SetParent(this);
571 	fLayout->AddItem(builder.Layout(), weight);
572 	return builder;
573 }
574 
575 
576 template<typename ParentBuilder>
577 typename Group<ParentBuilder>::GroupBuilder
AddGroup(BGroupView * groupView,float weight)578 Group<ParentBuilder>::AddGroup(BGroupView* groupView, float weight)
579 {
580 	GroupBuilder builder(groupView);
581 	builder.SetParent(this);
582 	fLayout->AddItem(builder.Layout(), weight);
583 	return builder;
584 }
585 
586 
587 template<typename ParentBuilder>
588 typename Group<ParentBuilder>::GroupBuilder
AddGroup(BGroupLayout * groupLayout,float weight)589 Group<ParentBuilder>::AddGroup(BGroupLayout* groupLayout, float weight)
590 {
591 	GroupBuilder builder(groupLayout);
592 	builder.SetParent(this);
593 	fLayout->AddItem(builder.Layout(), weight);
594 	return builder;
595 }
596 
597 
598 template<typename ParentBuilder>
599 typename Group<ParentBuilder>::GridBuilder
AddGrid(float horizontalSpacing,float verticalSpacing,float weight)600 Group<ParentBuilder>::AddGrid(float horizontalSpacing,
601 	float verticalSpacing, float weight)
602 {
603 	GridBuilder builder(new BGridLayout(horizontalSpacing, verticalSpacing));
604 	builder.SetParent(this);
605 	fLayout->AddItem(builder.Layout(), weight);
606 	return builder;
607 }
608 
609 
610 template<typename ParentBuilder>
611 typename Group<ParentBuilder>::GridBuilder
AddGrid(BGridLayout * gridLayout,float weight)612 Group<ParentBuilder>::AddGrid(BGridLayout* gridLayout, float weight)
613 {
614 	GridBuilder builder(gridLayout);
615 	builder.SetParent(this);
616 	fLayout->AddItem(builder.Layout(), weight);
617 	return builder;
618 }
619 
620 
621 template<typename ParentBuilder>
622 typename Group<ParentBuilder>::GridBuilder
AddGrid(BGridView * gridView,float weight)623 Group<ParentBuilder>::AddGrid(BGridView* gridView, float weight)
624 {
625 	GridBuilder builder(gridView);
626 	builder.SetParent(this);
627 	fLayout->AddItem(builder.Layout(), weight);
628 	return builder;
629 }
630 
631 
632 template<typename ParentBuilder>
633 typename Group<ParentBuilder>::SplitBuilder
AddSplit(orientation orientation,float spacing,float weight)634 Group<ParentBuilder>::AddSplit(orientation orientation, float spacing,
635 		float weight)
636 {
637 	SplitBuilder builder(orientation, spacing);
638 	builder.SetParent(this);
639 	fLayout->AddView(builder.View(), weight);
640 	return builder;
641 }
642 
643 
644 template<typename ParentBuilder>
645 typename Group<ParentBuilder>::SplitBuilder
AddSplit(BSplitView * splitView,float weight)646 Group<ParentBuilder>::AddSplit(BSplitView* splitView, float weight)
647 {
648 	SplitBuilder builder(splitView);
649 	builder.SetParent(this);
650 	fLayout->AddView(builder.View(), weight);
651 	return builder;
652 }
653 
654 
655 template<typename ParentBuilder>
656 typename Group<ParentBuilder>::CardBuilder
AddCards(float weight)657 Group<ParentBuilder>::AddCards(float weight)
658 {
659 	CardBuilder builder;
660 	builder.SetParent(this);
661 	fLayout->AddView(builder.View(), weight);
662 	return builder;
663 }
664 
665 
666 template<typename ParentBuilder>
667 typename Group<ParentBuilder>::CardBuilder
AddCards(BCardLayout * cardLayout,float weight)668 Group<ParentBuilder>::AddCards(BCardLayout* cardLayout, float weight)
669 {
670 	CardBuilder builder(cardLayout);
671 	builder.SetParent(this);
672 	fLayout->AddView(builder.View(), weight);
673 	return builder;
674 }
675 
676 
677 template<typename ParentBuilder>
678 typename Group<ParentBuilder>::CardBuilder
AddCards(BCardView * cardView,float weight)679 Group<ParentBuilder>::AddCards(BCardView* cardView, float weight)
680 {
681 	CardBuilder builder(cardView);
682 	builder.SetParent(this);
683 	fLayout->AddView(builder.View(), weight);
684 	return builder;
685 }
686 
687 
688 template<typename ParentBuilder>
689 typename Group<ParentBuilder>::ThisBuilder&
AddGlue(float weight)690 Group<ParentBuilder>::AddGlue(float weight)
691 {
692 	fLayout->AddItem(BSpaceLayoutItem::CreateGlue(), weight);
693 	return *this;
694 }
695 
696 
697 template<typename ParentBuilder>
698 typename Group<ParentBuilder>::ThisBuilder&
AddStrut(float size)699 Group<ParentBuilder>::AddStrut(float size)
700 {
701 	if (fLayout->Orientation() == B_HORIZONTAL)
702 		fLayout->AddItem(BSpaceLayoutItem::CreateHorizontalStrut(size));
703 	else
704 		fLayout->AddItem(BSpaceLayoutItem::CreateVerticalStrut(size));
705 
706 	return *this;
707 }
708 
709 
710 template<typename ParentBuilder>
711 typename Group<ParentBuilder>::ThisBuilder&
SetInsets(float left,float top,float right,float bottom)712 Group<ParentBuilder>::SetInsets(float left, float top, float right,
713 	float bottom)
714 {
715 	fLayout->SetInsets(left, top, right, bottom);
716 	return *this;
717 }
718 
719 
720 template<typename ParentBuilder>
721 typename Group<ParentBuilder>::ThisBuilder&
SetInsets(float horizontal,float vertical)722 Group<ParentBuilder>::SetInsets(float horizontal, float vertical)
723 {
724 	fLayout->SetInsets(horizontal, vertical);
725 	return *this;
726 }
727 
728 
729 template<typename ParentBuilder>
730 typename Group<ParentBuilder>::ThisBuilder&
SetInsets(float insets)731 Group<ParentBuilder>::SetInsets(float insets)
732 {
733 	fLayout->SetInsets(insets);
734 	return *this;
735 }
736 
737 
738 template<typename ParentBuilder>
739 typename Group<ParentBuilder>::ThisBuilder&
SetExplicitMinSize(BSize size)740 Group<ParentBuilder>::SetExplicitMinSize(BSize size)
741 {
742 	fLayout->SetExplicitMinSize(size);
743 	return *this;
744 }
745 
746 
747 template<typename ParentBuilder>
748 typename Group<ParentBuilder>::ThisBuilder&
SetExplicitMaxSize(BSize size)749 Group<ParentBuilder>::SetExplicitMaxSize(BSize size)
750 {
751 	fLayout->SetExplicitMaxSize(size);
752 	return *this;
753 }
754 
755 
756 template<typename ParentBuilder>
757 typename Group<ParentBuilder>::ThisBuilder&
SetExplicitPreferredSize(BSize size)758 Group<ParentBuilder>::SetExplicitPreferredSize(BSize size)
759 {
760 	fLayout->SetExplicitPreferredSize(size);
761 	return *this;
762 }
763 
764 
765 template<typename ParentBuilder>
766 typename Group<ParentBuilder>::ThisBuilder&
SetExplicitAlignment(BAlignment alignment)767 Group<ParentBuilder>::SetExplicitAlignment(BAlignment alignment)
768 {
769 	fLayout->SetExplicitAlignment(alignment);
770 	return *this;
771 }
772 
773 
774 template<typename ParentBuilder>
775 Group<ParentBuilder>::operator BGroupLayout*()
776 {
777 	return fLayout;
778 }
779 
780 
781 // #pragma mark - Grid
782 
783 
784 template<typename ParentBuilder>
Grid(float horizontalSpacing,float verticalSpacing)785 Grid<ParentBuilder>::Grid(float horizontalSpacing, float verticalSpacing)
786 	:
787 	fLayout((new BGridView(horizontalSpacing, verticalSpacing))->GridLayout())
788 {
789 }
790 
791 
792 template<typename ParentBuilder>
Grid(BWindow * window,float horizontalSpacing,float verticalSpacing)793 Grid<ParentBuilder>::Grid(BWindow* window, float horizontalSpacing,
794 	float verticalSpacing)
795 	:
796 	fLayout(new BGridLayout(horizontalSpacing, verticalSpacing))
797 {
798 	window->SetLayout(fLayout);
799 	fLayout->Owner()->AdoptSystemColors();
800 }
801 
802 
803 template<typename ParentBuilder>
Grid(BView * view,float horizontalSpacing,float verticalSpacing)804 Grid<ParentBuilder>::Grid(BView* view, float horizontalSpacing,
805 	float verticalSpacing)
806 	:
807 	fLayout(new BGridLayout(horizontalSpacing, verticalSpacing))
808 {
809 	if (view->HasDefaultColors())
810 		view->AdoptSystemColors();
811 
812 	view->SetLayout(fLayout);
813 }
814 
815 
816 template<typename ParentBuilder>
Grid(BGridLayout * layout)817 Grid<ParentBuilder>::Grid(BGridLayout* layout)
818 	:
819 	fLayout(layout)
820 {
821 }
822 
823 
824 template<typename ParentBuilder>
Grid(BGridView * view)825 Grid<ParentBuilder>::Grid(BGridView* view)
826 	:
827 	fLayout(view->GridLayout())
828 {
829 }
830 
831 
832 template<typename ParentBuilder>
833 BGridLayout*
Layout()834 Grid<ParentBuilder>::Layout() const
835 {
836 	return fLayout;
837 }
838 
839 
840 template<typename ParentBuilder>
841 BView*
View()842 Grid<ParentBuilder>::View() const
843 {
844 	return fLayout->Owner();
845 }
846 
847 
848 template<typename ParentBuilder>
849 typename Grid<ParentBuilder>::ThisBuilder&
GetLayout(BGridLayout ** _layout)850 Grid<ParentBuilder>::GetLayout(BGridLayout** _layout)
851 {
852 	*_layout = fLayout;
853 	return *this;
854 }
855 
856 
857 template<typename ParentBuilder>
858 typename Grid<ParentBuilder>::ThisBuilder&
GetView(BView ** _view)859 Grid<ParentBuilder>::GetView(BView** _view)
860 {
861 	*_view = fLayout->Owner();
862 	return *this;
863 }
864 
865 
866 template<typename ParentBuilder>
867 typename Grid<ParentBuilder>::ThisBuilder&
Add(BView * view,int32 column,int32 row,int32 columnCount,int32 rowCount)868 Grid<ParentBuilder>::Add(BView* view, int32 column, int32 row,
869 	int32 columnCount, int32 rowCount)
870 {
871 	fLayout->AddView(view, column, row, columnCount, rowCount);
872 	return *this;
873 }
874 
875 
876 template<typename ParentBuilder>
877 typename Grid<ParentBuilder>::ThisBuilder&
Add(BLayoutItem * item,int32 column,int32 row,int32 columnCount,int32 rowCount)878 Grid<ParentBuilder>::Add(BLayoutItem* item, int32 column, int32 row,
879 	int32 columnCount, int32 rowCount)
880 {
881 	fLayout->AddItem(item, column, row, columnCount, rowCount);
882 	return *this;
883 }
884 
885 
886 template<typename ParentBuilder>
887 typename Grid<ParentBuilder>::ThisBuilder&
AddMenuField(BMenuField * menuField,int32 column,int32 row,alignment labelAlignment,int32 labelColumnCount,int32 fieldColumnCount,int32 rowCount)888 Grid<ParentBuilder>::AddMenuField(BMenuField* menuField, int32 column,
889 	int32 row, alignment labelAlignment, int32 labelColumnCount,
890 	int32 fieldColumnCount, int32 rowCount)
891 {
892 	BLayoutItem* item = menuField->CreateLabelLayoutItem();
893 	item->SetExplicitAlignment(
894 		BAlignment(labelAlignment, B_ALIGN_VERTICAL_UNSET));
895 	fLayout->AddItem(item, column, row, labelColumnCount, rowCount);
896 	fLayout->AddItem(menuField->CreateMenuBarLayoutItem(),
897 		column + labelColumnCount, row, fieldColumnCount, rowCount);
898 	return *this;
899 }
900 
901 
902 template<typename ParentBuilder>
903 typename Grid<ParentBuilder>::ThisBuilder&
AddTextControl(BTextControl * textControl,int32 column,int32 row,alignment labelAlignment,int32 labelColumnCount,int32 textColumnCount,int32 rowCount)904 Grid<ParentBuilder>::AddTextControl(BTextControl* textControl, int32 column,
905 	int32 row, alignment labelAlignment, int32 labelColumnCount,
906 	int32 textColumnCount, int32 rowCount)
907 {
908 	BLayoutItem* item = textControl->CreateLabelLayoutItem();
909 	item->SetExplicitAlignment(
910 		BAlignment(labelAlignment, B_ALIGN_VERTICAL_UNSET));
911 	fLayout->AddItem(item, column, row, labelColumnCount, rowCount);
912 	fLayout->AddItem(textControl->CreateTextViewLayoutItem(),
913 		column + labelColumnCount, row, textColumnCount, rowCount);
914 	return *this;
915 }
916 
917 
918 template<typename ParentBuilder>
919 typename Grid<ParentBuilder>::GroupBuilder
AddGroup(orientation orientation,float spacing,int32 column,int32 row,int32 columnCount,int32 rowCount)920 Grid<ParentBuilder>::AddGroup(orientation orientation, float spacing,
921 		int32 column, int32 row, int32 columnCount, int32 rowCount)
922 {
923 	GroupBuilder builder(new BGroupLayout(orientation, spacing));
924 	builder.SetParent(this);
925 	fLayout->AddItem(builder.Layout(), column, row, columnCount, rowCount);
926 	return builder;
927 }
928 
929 
930 template<typename ParentBuilder>
931 typename Grid<ParentBuilder>::GroupBuilder
AddGroup(BGroupView * groupView,int32 column,int32 row,int32 columnCount,int32 rowCount)932 Grid<ParentBuilder>::AddGroup(BGroupView* groupView, int32 column, int32 row,
933 	int32 columnCount, int32 rowCount)
934 {
935 	GroupBuilder builder(groupView);
936 	builder.SetParent(this);
937 	fLayout->AddItem(builder.Layout(), column, row, columnCount, rowCount);
938 	return builder;
939 }
940 
941 
942 template<typename ParentBuilder>
943 typename Grid<ParentBuilder>::GroupBuilder
AddGroup(BGroupLayout * groupLayout,int32 column,int32 row,int32 columnCount,int32 rowCount)944 Grid<ParentBuilder>::AddGroup(BGroupLayout* groupLayout, int32 column,
945 	int32 row, int32 columnCount, int32 rowCount)
946 {
947 	GroupBuilder builder(groupLayout);
948 	builder.SetParent(this);
949 	fLayout->AddItem(builder.Layout(), column, row, columnCount, rowCount);
950 	return builder;
951 }
952 
953 
954 template<typename ParentBuilder>
955 typename Grid<ParentBuilder>::GridBuilder
AddGrid(float horizontalSpacing,float verticalSpacing,int32 column,int32 row,int32 columnCount,int32 rowCount)956 Grid<ParentBuilder>::AddGrid(float horizontalSpacing, float verticalSpacing,
957 	int32 column, int32 row, int32 columnCount, int32 rowCount)
958 {
959 	GridBuilder builder(new BGridLayout(horizontalSpacing, verticalSpacing));
960 	builder.SetParent(this);
961 	fLayout->AddItem(builder.Layout(), column, row, columnCount, rowCount);
962 	return builder;
963 }
964 
965 
966 template<typename ParentBuilder>
967 typename Grid<ParentBuilder>::GridBuilder
AddGrid(BGridView * gridView,int32 column,int32 row,int32 columnCount,int32 rowCount)968 Grid<ParentBuilder>::AddGrid(BGridView* gridView, int32 column, int32 row,
969 	int32 columnCount, int32 rowCount)
970 {
971 	GridBuilder builder(gridView);
972 	builder.SetParent(this);
973 	fLayout->AddView(builder.View(), column, row, columnCount, rowCount);
974 	return builder;
975 }
976 
977 
978 template<typename ParentBuilder>
979 typename Grid<ParentBuilder>::SplitBuilder
AddSplit(orientation orientation,float spacing,int32 column,int32 row,int32 columnCount,int32 rowCount)980 Grid<ParentBuilder>::AddSplit(orientation orientation, float spacing,
981 	int32 column, int32 row, int32 columnCount, int32 rowCount)
982 {
983 	SplitBuilder builder(orientation, spacing);
984 	builder.SetParent(this);
985 	fLayout->AddView(builder.View(), column, row, columnCount, rowCount);
986 	return builder;
987 }
988 
989 
990 template<typename ParentBuilder>
991 typename Grid<ParentBuilder>::SplitBuilder
AddSplit(BSplitView * splitView,int32 column,int32 row,int32 columnCount,int32 rowCount)992 Grid<ParentBuilder>::AddSplit(BSplitView* splitView, int32 column, int32 row,
993 	int32 columnCount, int32 rowCount)
994 {
995 	SplitBuilder builder(splitView);
996 	builder.SetParent(this);
997 	fLayout->AddView(builder.View(), column, row, columnCount, rowCount);
998 	return builder;
999 }
1000 
1001 
1002 template<typename ParentBuilder>
1003 typename Grid<ParentBuilder>::CardBuilder
AddCards(int32 column,int32 row,int32 columnCount,int32 rowCount)1004 Grid<ParentBuilder>::AddCards(int32 column, int32 row, int32 columnCount,
1005 	int32 rowCount)
1006 {
1007 	CardBuilder builder;
1008 	builder.SetParent(this);
1009 	fLayout->AddView(builder.View(), column, row, columnCount, rowCount);
1010 	return builder;
1011 }
1012 
1013 
1014 template<typename ParentBuilder>
1015 typename Grid<ParentBuilder>::CardBuilder
AddCards(BCardLayout * cardLayout,int32 column,int32 row,int32 columnCount,int32 rowCount)1016 Grid<ParentBuilder>::AddCards(BCardLayout* cardLayout, int32 column, int32 row,
1017 	int32 columnCount, int32 rowCount)
1018 {
1019 	CardBuilder builder(cardLayout);
1020 	builder.SetParent(this);
1021 	fLayout->AddView(builder.View(), column, row, columnCount, rowCount);
1022 	return builder;
1023 }
1024 
1025 
1026 template<typename ParentBuilder>
1027 typename Grid<ParentBuilder>::CardBuilder
AddCards(BCardView * cardView,int32 column,int32 row,int32 columnCount,int32 rowCount)1028 Grid<ParentBuilder>::AddCards(BCardView* cardView, int32 column, int32 row,
1029 	int32 columnCount, int32 rowCount)
1030 {
1031 	CardBuilder builder(cardView);
1032 	builder.SetParent(this);
1033 	fLayout->AddView(builder.View(), column, row, columnCount, rowCount);
1034 	return builder;
1035 }
1036 
1037 
1038 template<typename ParentBuilder>
1039 typename Grid<ParentBuilder>::ThisBuilder&
AddGlue(int32 column,int32 row,int32 columnCount,int32 rowCount)1040 Grid<ParentBuilder>::AddGlue(int32 column, int32 row, int32 columnCount,
1041 	int32 rowCount)
1042 {
1043 	fLayout->AddItem(BSpaceLayoutItem::CreateGlue(), column, row, columnCount,
1044 		rowCount);
1045 	return *this;
1046 }
1047 
1048 
1049 template<typename ParentBuilder>
1050 typename Grid<ParentBuilder>::ThisBuilder&
SetHorizontalSpacing(float spacing)1051 Grid<ParentBuilder>::SetHorizontalSpacing(float spacing)
1052 {
1053 	fLayout->SetHorizontalSpacing(spacing);
1054 	return *this;
1055 }
1056 
1057 
1058 template<typename ParentBuilder>
1059 typename Grid<ParentBuilder>::ThisBuilder&
SetVerticalSpacing(float spacing)1060 Grid<ParentBuilder>::SetVerticalSpacing(float spacing)
1061 {
1062 	fLayout->SetVerticalSpacing(spacing);
1063 	return *this;
1064 }
1065 
1066 
1067 template<typename ParentBuilder>
1068 typename Grid<ParentBuilder>::ThisBuilder&
SetSpacing(float horizontal,float vertical)1069 Grid<ParentBuilder>::SetSpacing(float horizontal, float vertical)
1070 {
1071 	fLayout->SetSpacing(horizontal, vertical);
1072 	return *this;
1073 }
1074 
1075 
1076 template<typename ParentBuilder>
1077 typename Grid<ParentBuilder>::ThisBuilder&
SetColumnWeight(int32 column,float weight)1078 Grid<ParentBuilder>::SetColumnWeight(int32 column, float weight)
1079 {
1080 	fLayout->SetColumnWeight(column, weight);
1081 	return *this;
1082 }
1083 
1084 
1085 template<typename ParentBuilder>
1086 typename Grid<ParentBuilder>::ThisBuilder&
SetRowWeight(int32 row,float weight)1087 Grid<ParentBuilder>::SetRowWeight(int32 row, float weight)
1088 {
1089 	fLayout->SetRowWeight(row, weight);
1090 	return *this;
1091 }
1092 
1093 
1094 template<typename ParentBuilder>
1095 typename Grid<ParentBuilder>::ThisBuilder&
SetInsets(float left,float top,float right,float bottom)1096 Grid<ParentBuilder>::SetInsets(float left, float top, float right,
1097 	float bottom)
1098 {
1099 	fLayout->SetInsets(left, top, right, bottom);
1100 	return *this;
1101 }
1102 
1103 
1104 template<typename ParentBuilder>
1105 typename Grid<ParentBuilder>::ThisBuilder&
SetInsets(float horizontal,float vertical)1106 Grid<ParentBuilder>::SetInsets(float horizontal, float vertical)
1107 {
1108 	fLayout->SetInsets(horizontal, vertical);
1109 	return *this;
1110 }
1111 
1112 
1113 template<typename ParentBuilder>
1114 typename Grid<ParentBuilder>::ThisBuilder&
SetInsets(float insets)1115 Grid<ParentBuilder>::SetInsets(float insets)
1116 {
1117 	fLayout->SetInsets(insets);
1118 	return *this;
1119 }
1120 
1121 
1122 template<typename ParentBuilder>
1123 typename Grid<ParentBuilder>::ThisBuilder&
SetExplicitMinSize(BSize size)1124 Grid<ParentBuilder>::SetExplicitMinSize(BSize size)
1125 {
1126 	fLayout->SetExplicitMinSize(size);
1127 	return *this;
1128 }
1129 
1130 
1131 template<typename ParentBuilder>
1132 typename Grid<ParentBuilder>::ThisBuilder&
SetExplicitMaxSize(BSize size)1133 Grid<ParentBuilder>::SetExplicitMaxSize(BSize size)
1134 {
1135 	fLayout->SetExplicitMaxSize(size);
1136 	return *this;
1137 }
1138 
1139 
1140 template<typename ParentBuilder>
1141 typename Grid<ParentBuilder>::ThisBuilder&
SetExplicitPreferredSize(BSize size)1142 Grid<ParentBuilder>::SetExplicitPreferredSize(BSize size)
1143 {
1144 	fLayout->SetExplicitPreferredSize(size);
1145 	return *this;
1146 }
1147 
1148 
1149 template<typename ParentBuilder>
1150 typename Grid<ParentBuilder>::ThisBuilder&
SetExplicitAlignment(BAlignment alignment)1151 Grid<ParentBuilder>::SetExplicitAlignment(BAlignment alignment)
1152 {
1153 	fLayout->SetExplicitAlignment(alignment);
1154 	return *this;
1155 }
1156 
1157 
1158 template<typename ParentBuilder>
1159 Grid<ParentBuilder>::operator BGridLayout*()
1160 {
1161 	return fLayout;
1162 }
1163 
1164 
1165 // #pragma mark - Split
1166 
1167 
1168 template<typename ParentBuilder>
Split(orientation orientation,float spacing)1169 Split<ParentBuilder>::Split(orientation orientation, float spacing)
1170 	:
1171 	fView(new BSplitView(orientation, spacing))
1172 {
1173 }
1174 
1175 
1176 template<typename ParentBuilder>
Split(BSplitView * view)1177 Split<ParentBuilder>::Split(BSplitView* view)
1178 	:
1179 	fView(view)
1180 {
1181 }
1182 
1183 
1184 template<typename ParentBuilder>
1185 BSplitView*
View()1186 Split<ParentBuilder>::View() const
1187 {
1188 	return fView;
1189 }
1190 
1191 
1192 template<typename ParentBuilder>
1193 typename Split<ParentBuilder>::ThisBuilder&
GetView(BView ** _view)1194 Split<ParentBuilder>::GetView(BView** _view)
1195 {
1196 	*_view = fView;
1197 	return *this;
1198 }
1199 
1200 
1201 template<typename ParentBuilder>
1202 typename Split<ParentBuilder>::ThisBuilder&
GetSplitView(BSplitView ** _view)1203 Split<ParentBuilder>::GetSplitView(BSplitView** _view)
1204 {
1205 	*_view = fView;
1206 	return *this;
1207 }
1208 
1209 
1210 template<typename ParentBuilder>
1211 typename Split<ParentBuilder>::ThisBuilder&
Add(BView * view)1212 Split<ParentBuilder>::Add(BView* view)
1213 {
1214 	fView->AddChild(view);
1215 	return *this;
1216 }
1217 
1218 
1219 template<typename ParentBuilder>
1220 typename Split<ParentBuilder>::ThisBuilder&
Add(BView * view,float weight)1221 Split<ParentBuilder>::Add(BView* view, float weight)
1222 {
1223 	fView->AddChild(view, weight);
1224 	return *this;
1225 }
1226 
1227 
1228 template<typename ParentBuilder>
1229 typename Split<ParentBuilder>::ThisBuilder&
Add(BLayoutItem * item)1230 Split<ParentBuilder>::Add(BLayoutItem* item)
1231 {
1232 	fView->AddChild(item);
1233 	return *this;
1234 }
1235 
1236 
1237 template<typename ParentBuilder>
1238 typename Split<ParentBuilder>::ThisBuilder&
Add(BLayoutItem * item,float weight)1239 Split<ParentBuilder>::Add(BLayoutItem* item, float weight)
1240 {
1241 	fView->AddChild(item, weight);
1242 	return *this;
1243 }
1244 
1245 
1246 template<typename ParentBuilder>
1247 typename Split<ParentBuilder>::GroupBuilder
AddGroup(orientation orientation,float spacing,float weight)1248 Split<ParentBuilder>::AddGroup(orientation orientation, float spacing,
1249 		float weight)
1250 {
1251 	GroupBuilder builder(new BGroupLayout(orientation, spacing));
1252 	builder.SetParent(this);
1253 	fView->AddChild(builder.Layout(), weight);
1254 	return builder;
1255 }
1256 
1257 
1258 template<typename ParentBuilder>
1259 typename Split<ParentBuilder>::GroupBuilder
AddGroup(BGroupView * groupView,float weight)1260 Split<ParentBuilder>::AddGroup(BGroupView* groupView, float weight)
1261 {
1262 	GroupBuilder builder(groupView);
1263 	builder.SetParent(this);
1264 	fView->AddChild(builder.Layout(), weight);
1265 	return builder;
1266 }
1267 
1268 
1269 template<typename ParentBuilder>
1270 typename Split<ParentBuilder>::GroupBuilder
AddGroup(BGroupLayout * groupLayout,float weight)1271 Split<ParentBuilder>::AddGroup(BGroupLayout* groupLayout, float weight)
1272 {
1273 	GroupBuilder builder(groupLayout);
1274 	builder.SetParent(this);
1275 	fView->AddChild(builder.Layout(), weight);
1276 	return builder;
1277 }
1278 
1279 
1280 template<typename ParentBuilder>
1281 typename Split<ParentBuilder>::GridBuilder
AddGrid(float horizontalSpacing,float verticalSpacing,float weight)1282 Split<ParentBuilder>::AddGrid(float horizontalSpacing, float verticalSpacing,
1283 	float weight)
1284 {
1285 	GridBuilder builder(new BGridLayout(horizontalSpacing, verticalSpacing));
1286 	builder.SetParent(this);
1287 	fView->AddChild(builder.Layout(), weight);
1288 	return builder;
1289 }
1290 
1291 
1292 template<typename ParentBuilder>
1293 typename Split<ParentBuilder>::GridBuilder
AddGrid(BGridView * gridView,float weight)1294 Split<ParentBuilder>::AddGrid(BGridView* gridView, float weight)
1295 {
1296 	GridBuilder builder(gridView);
1297 	builder.SetParent(this);
1298 	fView->AddChild(builder.Layout(), weight);
1299 	return builder;
1300 }
1301 
1302 
1303 template<typename ParentBuilder>
1304 typename Split<ParentBuilder>::GridBuilder
AddGrid(BGridLayout * layout,float weight)1305 Split<ParentBuilder>::AddGrid(BGridLayout* layout, float weight)
1306 {
1307 	GridBuilder builder(layout);
1308 	builder.SetParent(this);
1309 	fView->AddChild(builder.Layout(), weight);
1310 	return builder;
1311 }
1312 
1313 
1314 template<typename ParentBuilder>
1315 typename Split<ParentBuilder>::SplitBuilder
AddSplit(orientation orientation,float spacing,float weight)1316 Split<ParentBuilder>::AddSplit(orientation orientation, float spacing,
1317 		float weight)
1318 {
1319 	SplitBuilder builder(orientation, spacing);
1320 	builder.SetParent(this);
1321 	fView->AddChild(builder.View(), weight);
1322 	return builder;
1323 }
1324 
1325 
1326 template<typename ParentBuilder>
1327 typename Split<ParentBuilder>::CardBuilder
AddCards(float weight)1328 Split<ParentBuilder>::AddCards(float weight)
1329 {
1330 	CardBuilder builder;
1331 	builder.SetParent(this);
1332 	fView->AddChild(builder.View(), weight);
1333 	return builder;
1334 }
1335 
1336 
1337 template<typename ParentBuilder>
1338 typename Split<ParentBuilder>::CardBuilder
AddCards(BCardLayout * cardLayout,float weight)1339 Split<ParentBuilder>::AddCards(BCardLayout* cardLayout, float weight)
1340 {
1341 	CardBuilder builder(cardLayout);
1342 	builder.SetParent(this);
1343 	fView->AddChild(builder.View(), weight);
1344 	return builder;
1345 }
1346 
1347 
1348 template<typename ParentBuilder>
1349 typename Split<ParentBuilder>::CardBuilder
AddCards(BCardView * cardView,float weight)1350 Split<ParentBuilder>::AddCards(BCardView* cardView, float weight)
1351 {
1352 	CardBuilder builder(cardView);
1353 	builder.SetParent(this);
1354 	fView->AddChild(builder.View(), weight);
1355 	return builder;
1356 }
1357 
1358 
1359 template<typename ParentBuilder>
1360 typename Split<ParentBuilder>::ThisBuilder&
SetCollapsible(bool collapsible)1361 Split<ParentBuilder>::SetCollapsible(bool collapsible)
1362 {
1363 	fView->SetCollapsible(collapsible);
1364 	return *this;
1365 }
1366 
1367 
1368 template<typename ParentBuilder>
1369 typename Split<ParentBuilder>::ThisBuilder&
SetCollapsible(int32 index,bool collapsible)1370 Split<ParentBuilder>::SetCollapsible(int32 index, bool collapsible)
1371 {
1372 	fView->SetCollapsible(index, collapsible);
1373 	return *this;
1374 }
1375 
1376 
1377 template<typename ParentBuilder>
1378 typename Split<ParentBuilder>::ThisBuilder&
SetCollapsible(int32 first,int32 last,bool collapsible)1379 Split<ParentBuilder>::SetCollapsible(int32 first, int32 last, bool collapsible)
1380 {
1381 	fView->SetCollapsible(first, last, collapsible);
1382 	return *this;
1383 }
1384 
1385 
1386 template<typename ParentBuilder>
1387 typename Split<ParentBuilder>::ThisBuilder&
SetInsets(float left,float top,float right,float bottom)1388 Split<ParentBuilder>::SetInsets(float left, float top, float right,
1389 	float bottom)
1390 {
1391 	fView->SetInsets(left, top, right, bottom);
1392 	return *this;
1393 }
1394 
1395 
1396 template<typename ParentBuilder>
1397 typename Split<ParentBuilder>::ThisBuilder&
SetInsets(float horizontal,float vertical)1398 Split<ParentBuilder>::SetInsets(float horizontal, float vertical)
1399 {
1400 	fView->SetInsets(horizontal, vertical);
1401 	return *this;
1402 }
1403 
1404 
1405 template<typename ParentBuilder>
1406 typename Split<ParentBuilder>::ThisBuilder&
SetInsets(float insets)1407 Split<ParentBuilder>::SetInsets(float insets)
1408 {
1409 	fView->SetInsets(insets);
1410 	return *this;
1411 }
1412 
1413 
1414 template<typename ParentBuilder>
1415 Split<ParentBuilder>::operator BSplitView*()
1416 {
1417 	return fView;
1418 }
1419 
1420 
1421 // #pragma mark - Cards
1422 
1423 
1424 template<typename ParentBuilder>
Cards()1425 Cards<ParentBuilder>::Cards()
1426 	:
1427 	fLayout((new BCardView())->CardLayout())
1428 {
1429 }
1430 
1431 
1432 template<typename ParentBuilder>
Cards(BWindow * window)1433 Cards<ParentBuilder>::Cards(BWindow* window)
1434 	:
1435 	fLayout(new BCardLayout())
1436 {
1437 	window->SetLayout(fLayout);
1438 
1439 	fLayout->Owner()->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
1440 }
1441 
1442 
1443 template<typename ParentBuilder>
Cards(BView * view)1444 Cards<ParentBuilder>::Cards(BView* view)
1445 	:
1446 	fLayout(new BCardLayout())
1447 {
1448 	view->SetLayout(fLayout);
1449 	view->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
1450 }
1451 
1452 
1453 template<typename ParentBuilder>
Cards(BCardLayout * layout)1454 Cards<ParentBuilder>::Cards(BCardLayout* layout)
1455 	:
1456 	fLayout(layout)
1457 {
1458 }
1459 
1460 
1461 template<typename ParentBuilder>
Cards(BCardView * view)1462 Cards<ParentBuilder>::Cards(BCardView* view)
1463 	:
1464 	fLayout(view->CardLayout())
1465 {
1466 }
1467 
1468 
1469 template<typename ParentBuilder>
1470 BCardLayout*
Layout()1471 Cards<ParentBuilder>::Layout() const
1472 {
1473 	return fLayout;
1474 }
1475 
1476 
1477 template<typename ParentBuilder>
1478 BView*
View()1479 Cards<ParentBuilder>::View() const
1480 {
1481 	return fLayout->Owner();
1482 }
1483 
1484 
1485 template<typename ParentBuilder>
1486 typename Cards<ParentBuilder>::ThisBuilder&
GetLayout(BCardLayout ** _layout)1487 Cards<ParentBuilder>::GetLayout(BCardLayout** _layout)
1488 {
1489 	*_layout = fLayout;
1490 	return *this;
1491 }
1492 
1493 
1494 template<typename ParentBuilder>
1495 typename Cards<ParentBuilder>::ThisBuilder&
GetView(BView ** _view)1496 Cards<ParentBuilder>::GetView(BView** _view)
1497 {
1498 	*_view = fLayout->Owner();
1499 	return *this;
1500 }
1501 
1502 
1503 template<typename ParentBuilder>
1504 typename Cards<ParentBuilder>::ThisBuilder&
Add(BView * view)1505 Cards<ParentBuilder>::Add(BView* view)
1506 {
1507 	fLayout->AddView(view);
1508 	return *this;
1509 }
1510 
1511 
1512 template<typename ParentBuilder>
1513 typename Cards<ParentBuilder>::ThisBuilder&
Add(BLayoutItem * item)1514 Cards<ParentBuilder>::Add(BLayoutItem* item)
1515 {
1516 	fLayout->AddItem(item);
1517 	return *this;
1518 }
1519 
1520 
1521 template<typename ParentBuilder>
1522 typename Cards<ParentBuilder>::GroupBuilder
AddGroup(orientation orientation,float spacing)1523 Cards<ParentBuilder>::AddGroup(orientation orientation, float spacing)
1524 {
1525 	GroupBuilder builder(new BGroupLayout(orientation, spacing));
1526 	builder.SetParent(this);
1527 	fLayout->AddItem(builder.Layout());
1528 	return builder;
1529 }
1530 
1531 
1532 template<typename ParentBuilder>
1533 typename Cards<ParentBuilder>::GroupBuilder
AddGroup(BGroupView * groupView)1534 Cards<ParentBuilder>::AddGroup(BGroupView* groupView)
1535 {
1536 	GroupBuilder builder(groupView);
1537 	builder.SetParent(this);
1538 	fLayout->AddItem(builder.Layout());
1539 	return builder;
1540 }
1541 
1542 
1543 template<typename ParentBuilder>
1544 typename Cards<ParentBuilder>::GroupBuilder
AddGroup(BGroupLayout * groupLayout)1545 Cards<ParentBuilder>::AddGroup(BGroupLayout* groupLayout)
1546 {
1547 	GroupBuilder builder(groupLayout);
1548 	builder.SetParent(this);
1549 	fLayout->AddItem(builder.Layout());
1550 	return builder;
1551 }
1552 
1553 
1554 template<typename ParentBuilder>
1555 typename Cards<ParentBuilder>::GridBuilder
AddGrid(float horizontal,float vertical)1556 Cards<ParentBuilder>::AddGrid(float horizontal, float vertical)
1557 {
1558 	GridBuilder builder(horizontal, vertical);
1559 	builder.SetParent(this);
1560 	fLayout->AddItem(builder.Layout());
1561 	return builder;
1562 }
1563 
1564 
1565 template<typename ParentBuilder>
1566 typename Cards<ParentBuilder>::GridBuilder
AddGrid(BGridLayout * gridLayout)1567 Cards<ParentBuilder>::AddGrid(BGridLayout* gridLayout)
1568 {
1569 	GridBuilder builder(gridLayout);
1570 	builder.SetParent(this);
1571 	fLayout->AddItem(builder.Layout());
1572 	return builder;
1573 }
1574 
1575 
1576 template<typename ParentBuilder>
1577 typename Cards<ParentBuilder>::GridBuilder
AddGrid(BGridView * gridView)1578 Cards<ParentBuilder>::AddGrid(BGridView* gridView)
1579 {
1580 	GridBuilder builder(gridView);
1581 	builder.SetParent(this);
1582 	fLayout->AddItem(builder.Layout());
1583 	return builder;
1584 }
1585 
1586 
1587 template<typename ParentBuilder>
1588 typename Cards<ParentBuilder>::SplitBuilder
AddSplit(orientation orientation,float spacing)1589 Cards<ParentBuilder>::AddSplit(orientation orientation, float spacing)
1590 {
1591 	SplitBuilder builder(orientation, spacing);
1592 	builder.SetParent(this);
1593 	fLayout->AddView(builder.View());
1594 	return builder;
1595 }
1596 
1597 
1598 template<typename ParentBuilder>
1599 typename Cards<ParentBuilder>::SplitBuilder
AddSplit(BSplitView * splitView)1600 Cards<ParentBuilder>::AddSplit(BSplitView* splitView)
1601 {
1602 	SplitBuilder builder(splitView);
1603 	builder.SetParent(this);
1604 	fLayout->AddView(builder.View());
1605 	return builder;
1606 }
1607 
1608 
1609 template<typename ParentBuilder>
1610 typename Cards<ParentBuilder>::CardBuilder
AddCards()1611 Cards<ParentBuilder>::AddCards()
1612 {
1613 	CardBuilder builder;
1614 	builder.SetParent(this);
1615 	fLayout->AddView(builder.View());
1616 	return builder;
1617 }
1618 
1619 
1620 template<typename ParentBuilder>
1621 typename Cards<ParentBuilder>::CardBuilder
AddCards(BCardLayout * cardLayout)1622 Cards<ParentBuilder>::AddCards(BCardLayout* cardLayout)
1623 {
1624 	CardBuilder builder(cardLayout);
1625 	builder.SetParent(this);
1626 	fLayout->AddView(builder.View());
1627 	return builder;
1628 }
1629 
1630 template<typename ParentBuilder>
1631 typename Cards<ParentBuilder>::CardBuilder
AddCards(BCardView * cardView)1632 Cards<ParentBuilder>::AddCards(BCardView* cardView)
1633 {
1634 	CardBuilder builder(cardView);
1635 	builder.SetParent(this);
1636 	fLayout->AddView(builder.View());
1637 	return builder;
1638 }
1639 
1640 
1641 template<typename ParentBuilder>
1642 typename Cards<ParentBuilder>::ThisBuilder&
SetExplicitMinSize(BSize size)1643 Cards<ParentBuilder>::SetExplicitMinSize(BSize size)
1644 {
1645 	fLayout->SetExplicitMinSize(size);
1646 	return *this;
1647 }
1648 
1649 
1650 template<typename ParentBuilder>
1651 typename Cards<ParentBuilder>::ThisBuilder&
SetExplicitMaxSize(BSize size)1652 Cards<ParentBuilder>::SetExplicitMaxSize(BSize size)
1653 {
1654 	fLayout->SetExplicitMaxSize(size);
1655 	return *this;
1656 }
1657 
1658 
1659 template<typename ParentBuilder>
1660 typename Cards<ParentBuilder>::ThisBuilder&
SetExplicitPreferredSize(BSize size)1661 Cards<ParentBuilder>::SetExplicitPreferredSize(BSize size)
1662 {
1663 	fLayout->SetExplicitPreferredSize(size);
1664 	return *this;
1665 }
1666 
1667 
1668 template<typename ParentBuilder>
1669 typename Cards<ParentBuilder>::ThisBuilder&
SetExplicitAlignment(BAlignment alignment)1670 Cards<ParentBuilder>::SetExplicitAlignment(BAlignment alignment)
1671 {
1672 	fLayout->SetExplicitAlignment(alignment);
1673 	return *this;
1674 }
1675 
1676 
1677 template<typename ParentBuilder>
1678 typename Cards<ParentBuilder>::ThisBuilder&
SetVisibleItem(int32 item)1679 Cards<ParentBuilder>::SetVisibleItem(int32 item)
1680 {
1681 	fLayout->SetVisibleItem(item);
1682 	return *this;
1683 }
1684 
1685 
1686 template<typename ParentBuilder>
1687 Cards<ParentBuilder>::operator BCardLayout*()
1688 {
1689 	return fLayout;
1690 }
1691 
1692 
1693 // #pragma mark - Menu
1694 
1695 
1696 template<typename ParentBuilder>
Menu(BMenu * menu)1697 Menu<ParentBuilder>::Menu(BMenu* menu)
1698 	:
1699 	fMenu(menu)
1700 {
1701 }
1702 
1703 
1704 template<typename ParentBuilder>
1705 typename Menu<ParentBuilder>::ThisBuilder&
GetMenu(BMenu * & _menu)1706 Menu<ParentBuilder>::GetMenu(BMenu*& _menu)
1707 {
1708 	_menu = fMenu;
1709 	return *this;
1710 }
1711 
1712 
1713 template<typename ParentBuilder>
1714 typename Menu<ParentBuilder>::ItemBuilder
AddItem(BMenuItem * item)1715 Menu<ParentBuilder>::AddItem(BMenuItem* item)
1716 {
1717 	fMenu->AddItem(item);
1718 	return MenuItem<ParentBuilder>(this->fParent, fMenu, item);
1719 }
1720 
1721 
1722 template<typename ParentBuilder>
1723 typename Menu<ParentBuilder>::ItemBuilder
AddItem(BMenu * menu)1724 Menu<ParentBuilder>::AddItem(BMenu* menu)
1725 {
1726 	if (!fMenu->AddItem(menu))
1727 		throw std::bad_alloc();
1728 
1729 	return MenuItem<ParentBuilder>(this->fParent, fMenu,
1730 		fMenu->ItemAt(fMenu->CountItems() - 1));
1731 }
1732 
1733 
1734 template<typename ParentBuilder>
1735 typename Menu<ParentBuilder>::ItemBuilder
AddItem(const char * label,BMessage * message,char shortcut,uint32 modifiers)1736 Menu<ParentBuilder>::AddItem(const char* label, BMessage* message,
1737 	char shortcut, uint32 modifiers)
1738 {
1739 	BMenuItem* item = new BMenuItem(label, message, shortcut, modifiers);
1740 	if (!fMenu->AddItem(item)) {
1741 		delete item;
1742 		item = NULL;
1743 	}
1744 
1745 	return MenuItem<ParentBuilder>(this->fParent, fMenu, item);
1746 }
1747 
1748 
1749 template<typename ParentBuilder>
1750 typename Menu<ParentBuilder>::ItemBuilder
AddItem(const char * label,uint32 messageWhat,char shortcut,uint32 modifiers)1751 Menu<ParentBuilder>::AddItem(const char* label, uint32 messageWhat,
1752 	char shortcut, uint32 modifiers)
1753 {
1754 	BMessage* message = new BMessage(messageWhat);
1755 	BMenuItem* item;
1756 	try {
1757 		item = new BMenuItem(label, message, shortcut, modifiers);
1758 	} catch (...) {
1759 		delete message;
1760 		throw;
1761 	}
1762 
1763 	if (!fMenu->AddItem(item)) {
1764 		delete item;
1765 		item = NULL;
1766 	}
1767 
1768 	return MenuItem<ParentBuilder>(this->fParent, fMenu, item);
1769 }
1770 
1771 
1772 template<typename ParentBuilder>
1773 typename Menu<ParentBuilder>::ThisBuilder&
AddSeparator()1774 Menu<ParentBuilder>::AddSeparator()
1775 {
1776 	fMenu->AddSeparatorItem();
1777 	return *this;
1778 }
1779 
1780 
1781 template<typename ParentBuilder>
1782 typename Menu<ParentBuilder>::MenuBuilder
AddMenu(BMenu * menu)1783 Menu<ParentBuilder>::AddMenu(BMenu* menu)
1784 {
1785 	if (!fMenu->AddItem(menu))
1786 		throw std::bad_alloc();
1787 
1788 	MenuBuilder builder(menu);
1789 	builder.SetParent(this);
1790 	return builder;
1791 }
1792 
1793 
1794 template<typename ParentBuilder>
1795 typename Menu<ParentBuilder>::MenuBuilder
AddMenu(const char * title,menu_layout layout)1796 Menu<ParentBuilder>::AddMenu(const char* title, menu_layout layout)
1797 {
1798 	BMenu* menu = new BMenu(title, layout);
1799 	if (!fMenu->AddItem(menu)) {
1800 		delete menu;
1801 		throw std::bad_alloc();
1802 	}
1803 
1804 	MenuBuilder builder(menu);
1805 	builder.SetParent(this);
1806 	return builder;
1807 }
1808 
1809 
1810 // #pragma mark - MenuItem
1811 
1812 
1813 template<typename ParentBuilder>
MenuItem(ParentBuilder * parentBuilder,BMenu * menu,BMenuItem * item)1814 MenuItem<ParentBuilder>::MenuItem(ParentBuilder* parentBuilder, BMenu* menu,
1815 	BMenuItem* item)
1816 	:
1817 	Menu<ParentBuilder>(menu),
1818 	fMenuItem(item)
1819 {
1820 	this->SetParent(parentBuilder);
1821 }
1822 
1823 
1824 template<typename ParentBuilder>
1825 typename MenuItem<ParentBuilder>::ThisBuilder&
GetItem(BMenuItem * & _item)1826 MenuItem<ParentBuilder>::GetItem(BMenuItem*& _item)
1827 {
1828 	_item = fMenuItem;
1829 	return *this;
1830 }
1831 
1832 
1833 template<typename ParentBuilder>
1834 typename MenuItem<ParentBuilder>::ThisBuilder&
SetEnabled(bool enabled)1835 MenuItem<ParentBuilder>::SetEnabled(bool enabled)
1836 {
1837 	fMenuItem->SetEnabled(enabled);
1838 	return *this;
1839 }
1840 
1841 
1842 }	// namespace BLayoutBuilder
1843 
1844 
1845 #endif	// _LAYOUT_BUILDER_H
1846