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
26namespace BLayoutBuilder {
27
28template<typename ParentBuilder> class Base;
29template<typename ParentBuilder = void*> class Group;
30template<typename ParentBuilder = void*> class Grid;
31template<typename ParentBuilder = void*> class Split;
32template<typename ParentBuilder = void*> class Cards;
33template<typename ParentBuilder = void*> class Menu;
34template<typename ParentBuilder = void*> class MenuItem;
35
36
37template<typename ParentBuilder>
38class Base {
39protected:
40	inline						Base();
41
42public:
43	inline	void				SetParent(ParentBuilder* parent);
44		// conceptually private
45	inline	ParentBuilder&		End();
46
47protected:
48			ParentBuilder*		fParent;
49};
50
51
52template<typename ParentBuilder>
53class Group : public Base<ParentBuilder> {
54public:
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
61public:
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
127private:
128			BGroupLayout*		fLayout;
129};
130
131
132template<typename ParentBuilder>
133class Grid : public Base<ParentBuilder> {
134public:
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
141public:
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
237private:
238			BGridLayout*		fLayout;
239};
240
241
242template<typename ParentBuilder>
243class Split : public Base<ParentBuilder> {
244public:
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
251public:
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
306private:
307			BSplitView*			fView;
308};
309
310template<typename ParentBuilder>
311class Cards : public Base<ParentBuilder> {
312public:
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
319public:
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
362private:
363			BCardLayout*		fLayout;
364};
365
366
367template<typename ParentBuilder>
368class Menu : public Base<ParentBuilder> {
369public:
370	typedef Menu<ParentBuilder>		ThisBuilder;
371	typedef MenuItem<ParentBuilder>	ItemBuilder;
372	typedef Menu<ThisBuilder>		MenuBuilder;
373
374public:
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
392private:
393			BMenu*				fMenu;
394};
395
396
397template<typename ParentBuilder>
398class MenuItem : public Menu<ParentBuilder> {
399public:
400	typedef MenuItem<ParentBuilder>	ThisBuilder;
401
402public:
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
410private:
411			BMenuItem*			fMenuItem;
412};
413
414
415// #pragma mark - Base
416
417
418template<typename ParentBuilder>
419Base<ParentBuilder>::Base()
420	:
421	fParent(NULL)
422{
423}
424
425
426template<typename ParentBuilder>
427void
428Base<ParentBuilder>::SetParent(ParentBuilder* parent)
429{
430	fParent = parent;
431}
432
433
434template<typename ParentBuilder>
435ParentBuilder&
436Base<ParentBuilder>::End()
437{
438	return *fParent;
439}
440
441
442// #pragma mark - Group
443
444
445template<typename ParentBuilder>
446Group<ParentBuilder>::Group(orientation orientation, float spacing)
447	:
448	fLayout((new BGroupView(orientation, spacing))->GroupLayout())
449{
450}
451
452
453template<typename ParentBuilder>
454Group<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
464template<typename ParentBuilder>
465Group<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
478template<typename ParentBuilder>
479Group<ParentBuilder>::Group(BGroupLayout* layout)
480	:
481	fLayout(layout)
482{
483}
484
485
486template<typename ParentBuilder>
487Group<ParentBuilder>::Group(BGroupView* view)
488	:
489	fLayout(view->GroupLayout())
490{
491}
492
493
494template<typename ParentBuilder>
495BGroupLayout*
496Group<ParentBuilder>::Layout() const
497{
498	return fLayout;
499}
500
501
502template<typename ParentBuilder>
503BView*
504Group<ParentBuilder>::View() const
505{
506	return fLayout->Owner();
507}
508
509
510template<typename ParentBuilder>
511typename Group<ParentBuilder>::ThisBuilder&
512Group<ParentBuilder>::GetLayout(BGroupLayout** _layout)
513{
514	*_layout = fLayout;
515	return *this;
516}
517
518
519template<typename ParentBuilder>
520typename Group<ParentBuilder>::ThisBuilder&
521Group<ParentBuilder>::GetView(BView** _view)
522{
523	*_view = fLayout->Owner();
524	return *this;
525}
526
527
528template<typename ParentBuilder>
529typename Group<ParentBuilder>::ThisBuilder&
530Group<ParentBuilder>::Add(BView* view)
531{
532	fLayout->AddView(view);
533	return *this;
534}
535
536
537template<typename ParentBuilder>
538typename Group<ParentBuilder>::ThisBuilder&
539Group<ParentBuilder>::Add(BView* view, float weight)
540{
541	fLayout->AddView(view, weight);
542	return *this;
543}
544
545
546template<typename ParentBuilder>
547typename Group<ParentBuilder>::ThisBuilder&
548Group<ParentBuilder>::Add(BLayoutItem* item)
549{
550	fLayout->AddItem(item);
551	return *this;
552}
553
554
555template<typename ParentBuilder>
556typename Group<ParentBuilder>::ThisBuilder&
557Group<ParentBuilder>::Add(BLayoutItem* item, float weight)
558{
559	fLayout->AddItem(item, weight);
560	return *this;
561}
562
563
564template<typename ParentBuilder>
565typename Group<ParentBuilder>::GroupBuilder
566Group<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
576template<typename ParentBuilder>
577typename Group<ParentBuilder>::GroupBuilder
578Group<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
587template<typename ParentBuilder>
588typename Group<ParentBuilder>::GroupBuilder
589Group<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
598template<typename ParentBuilder>
599typename Group<ParentBuilder>::GridBuilder
600Group<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
610template<typename ParentBuilder>
611typename Group<ParentBuilder>::GridBuilder
612Group<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
621template<typename ParentBuilder>
622typename Group<ParentBuilder>::GridBuilder
623Group<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
632template<typename ParentBuilder>
633typename Group<ParentBuilder>::SplitBuilder
634Group<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
644template<typename ParentBuilder>
645typename Group<ParentBuilder>::SplitBuilder
646Group<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
655template<typename ParentBuilder>
656typename Group<ParentBuilder>::CardBuilder
657Group<ParentBuilder>::AddCards(float weight)
658{
659	CardBuilder builder;
660	builder.SetParent(this);
661	fLayout->AddView(builder.View(), weight);
662	return builder;
663}
664
665
666template<typename ParentBuilder>
667typename Group<ParentBuilder>::CardBuilder
668Group<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
677template<typename ParentBuilder>
678typename Group<ParentBuilder>::CardBuilder
679Group<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
688template<typename ParentBuilder>
689typename Group<ParentBuilder>::ThisBuilder&
690Group<ParentBuilder>::AddGlue(float weight)
691{
692	fLayout->AddItem(BSpaceLayoutItem::CreateGlue(), weight);
693	return *this;
694}
695
696
697template<typename ParentBuilder>
698typename Group<ParentBuilder>::ThisBuilder&
699Group<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
710template<typename ParentBuilder>
711typename Group<ParentBuilder>::ThisBuilder&
712Group<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
720template<typename ParentBuilder>
721typename Group<ParentBuilder>::ThisBuilder&
722Group<ParentBuilder>::SetInsets(float horizontal, float vertical)
723{
724	fLayout->SetInsets(horizontal, vertical);
725	return *this;
726}
727
728
729template<typename ParentBuilder>
730typename Group<ParentBuilder>::ThisBuilder&
731Group<ParentBuilder>::SetInsets(float insets)
732{
733	fLayout->SetInsets(insets);
734	return *this;
735}
736
737
738template<typename ParentBuilder>
739typename Group<ParentBuilder>::ThisBuilder&
740Group<ParentBuilder>::SetExplicitMinSize(BSize size)
741{
742	fLayout->SetExplicitMinSize(size);
743	return *this;
744}
745
746
747template<typename ParentBuilder>
748typename Group<ParentBuilder>::ThisBuilder&
749Group<ParentBuilder>::SetExplicitMaxSize(BSize size)
750{
751	fLayout->SetExplicitMaxSize(size);
752	return *this;
753}
754
755
756template<typename ParentBuilder>
757typename Group<ParentBuilder>::ThisBuilder&
758Group<ParentBuilder>::SetExplicitPreferredSize(BSize size)
759{
760	fLayout->SetExplicitPreferredSize(size);
761	return *this;
762}
763
764
765template<typename ParentBuilder>
766typename Group<ParentBuilder>::ThisBuilder&
767Group<ParentBuilder>::SetExplicitAlignment(BAlignment alignment)
768{
769	fLayout->SetExplicitAlignment(alignment);
770	return *this;
771}
772
773
774template<typename ParentBuilder>
775Group<ParentBuilder>::operator BGroupLayout*()
776{
777	return fLayout;
778}
779
780
781// #pragma mark - Grid
782
783
784template<typename ParentBuilder>
785Grid<ParentBuilder>::Grid(float horizontalSpacing, float verticalSpacing)
786	:
787	fLayout((new BGridView(horizontalSpacing, verticalSpacing))->GridLayout())
788{
789}
790
791
792template<typename ParentBuilder>
793Grid<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
803template<typename ParentBuilder>
804Grid<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
816template<typename ParentBuilder>
817Grid<ParentBuilder>::Grid(BGridLayout* layout)
818	:
819	fLayout(layout)
820{
821}
822
823
824template<typename ParentBuilder>
825Grid<ParentBuilder>::Grid(BGridView* view)
826	:
827	fLayout(view->GridLayout())
828{
829}
830
831
832template<typename ParentBuilder>
833BGridLayout*
834Grid<ParentBuilder>::Layout() const
835{
836	return fLayout;
837}
838
839
840template<typename ParentBuilder>
841BView*
842Grid<ParentBuilder>::View() const
843{
844	return fLayout->Owner();
845}
846
847
848template<typename ParentBuilder>
849typename Grid<ParentBuilder>::ThisBuilder&
850Grid<ParentBuilder>::GetLayout(BGridLayout** _layout)
851{
852	*_layout = fLayout;
853	return *this;
854}
855
856
857template<typename ParentBuilder>
858typename Grid<ParentBuilder>::ThisBuilder&
859Grid<ParentBuilder>::GetView(BView** _view)
860{
861	*_view = fLayout->Owner();
862	return *this;
863}
864
865
866template<typename ParentBuilder>
867typename Grid<ParentBuilder>::ThisBuilder&
868Grid<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
876template<typename ParentBuilder>
877typename Grid<ParentBuilder>::ThisBuilder&
878Grid<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
886template<typename ParentBuilder>
887typename Grid<ParentBuilder>::ThisBuilder&
888Grid<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
902template<typename ParentBuilder>
903typename Grid<ParentBuilder>::ThisBuilder&
904Grid<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
918template<typename ParentBuilder>
919typename Grid<ParentBuilder>::GroupBuilder
920Grid<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
930template<typename ParentBuilder>
931typename Grid<ParentBuilder>::GroupBuilder
932Grid<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
942template<typename ParentBuilder>
943typename Grid<ParentBuilder>::GroupBuilder
944Grid<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
954template<typename ParentBuilder>
955typename Grid<ParentBuilder>::GridBuilder
956Grid<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
966template<typename ParentBuilder>
967typename Grid<ParentBuilder>::GridBuilder
968Grid<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
978template<typename ParentBuilder>
979typename Grid<ParentBuilder>::SplitBuilder
980Grid<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
990template<typename ParentBuilder>
991typename Grid<ParentBuilder>::SplitBuilder
992Grid<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
1002template<typename ParentBuilder>
1003typename Grid<ParentBuilder>::CardBuilder
1004Grid<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
1014template<typename ParentBuilder>
1015typename Grid<ParentBuilder>::CardBuilder
1016Grid<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
1026template<typename ParentBuilder>
1027typename Grid<ParentBuilder>::CardBuilder
1028Grid<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
1038template<typename ParentBuilder>
1039typename Grid<ParentBuilder>::ThisBuilder&
1040Grid<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
1049template<typename ParentBuilder>
1050typename Grid<ParentBuilder>::ThisBuilder&
1051Grid<ParentBuilder>::SetHorizontalSpacing(float spacing)
1052{
1053	fLayout->SetHorizontalSpacing(spacing);
1054	return *this;
1055}
1056
1057
1058template<typename ParentBuilder>
1059typename Grid<ParentBuilder>::ThisBuilder&
1060Grid<ParentBuilder>::SetVerticalSpacing(float spacing)
1061{
1062	fLayout->SetVerticalSpacing(spacing);
1063	return *this;
1064}
1065
1066
1067template<typename ParentBuilder>
1068typename Grid<ParentBuilder>::ThisBuilder&
1069Grid<ParentBuilder>::SetSpacing(float horizontal, float vertical)
1070{
1071	fLayout->SetSpacing(horizontal, vertical);
1072	return *this;
1073}
1074
1075
1076template<typename ParentBuilder>
1077typename Grid<ParentBuilder>::ThisBuilder&
1078Grid<ParentBuilder>::SetColumnWeight(int32 column, float weight)
1079{
1080	fLayout->SetColumnWeight(column, weight);
1081	return *this;
1082}
1083
1084
1085template<typename ParentBuilder>
1086typename Grid<ParentBuilder>::ThisBuilder&
1087Grid<ParentBuilder>::SetRowWeight(int32 row, float weight)
1088{
1089	fLayout->SetRowWeight(row, weight);
1090	return *this;
1091}
1092
1093
1094template<typename ParentBuilder>
1095typename Grid<ParentBuilder>::ThisBuilder&
1096Grid<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
1104template<typename ParentBuilder>
1105typename Grid<ParentBuilder>::ThisBuilder&
1106Grid<ParentBuilder>::SetInsets(float horizontal, float vertical)
1107{
1108	fLayout->SetInsets(horizontal, vertical);
1109	return *this;
1110}
1111
1112
1113template<typename ParentBuilder>
1114typename Grid<ParentBuilder>::ThisBuilder&
1115Grid<ParentBuilder>::SetInsets(float insets)
1116{
1117	fLayout->SetInsets(insets);
1118	return *this;
1119}
1120
1121
1122template<typename ParentBuilder>
1123typename Grid<ParentBuilder>::ThisBuilder&
1124Grid<ParentBuilder>::SetExplicitMinSize(BSize size)
1125{
1126	fLayout->SetExplicitMinSize(size);
1127	return *this;
1128}
1129
1130
1131template<typename ParentBuilder>
1132typename Grid<ParentBuilder>::ThisBuilder&
1133Grid<ParentBuilder>::SetExplicitMaxSize(BSize size)
1134{
1135	fLayout->SetExplicitMaxSize(size);
1136	return *this;
1137}
1138
1139
1140template<typename ParentBuilder>
1141typename Grid<ParentBuilder>::ThisBuilder&
1142Grid<ParentBuilder>::SetExplicitPreferredSize(BSize size)
1143{
1144	fLayout->SetExplicitPreferredSize(size);
1145	return *this;
1146}
1147
1148
1149template<typename ParentBuilder>
1150typename Grid<ParentBuilder>::ThisBuilder&
1151Grid<ParentBuilder>::SetExplicitAlignment(BAlignment alignment)
1152{
1153	fLayout->SetExplicitAlignment(alignment);
1154	return *this;
1155}
1156
1157
1158template<typename ParentBuilder>
1159Grid<ParentBuilder>::operator BGridLayout*()
1160{
1161	return fLayout;
1162}
1163
1164
1165// #pragma mark - Split
1166
1167
1168template<typename ParentBuilder>
1169Split<ParentBuilder>::Split(orientation orientation, float spacing)
1170	:
1171	fView(new BSplitView(orientation, spacing))
1172{
1173}
1174
1175
1176template<typename ParentBuilder>
1177Split<ParentBuilder>::Split(BSplitView* view)
1178	:
1179	fView(view)
1180{
1181}
1182
1183
1184template<typename ParentBuilder>
1185BSplitView*
1186Split<ParentBuilder>::View() const
1187{
1188	return fView;
1189}
1190
1191
1192template<typename ParentBuilder>
1193typename Split<ParentBuilder>::ThisBuilder&
1194Split<ParentBuilder>::GetView(BView** _view)
1195{
1196	*_view = fView;
1197	return *this;
1198}
1199
1200
1201template<typename ParentBuilder>
1202typename Split<ParentBuilder>::ThisBuilder&
1203Split<ParentBuilder>::GetSplitView(BSplitView** _view)
1204{
1205	*_view = fView;
1206	return *this;
1207}
1208
1209
1210template<typename ParentBuilder>
1211typename Split<ParentBuilder>::ThisBuilder&
1212Split<ParentBuilder>::Add(BView* view)
1213{
1214	fView->AddChild(view);
1215	return *this;
1216}
1217
1218
1219template<typename ParentBuilder>
1220typename Split<ParentBuilder>::ThisBuilder&
1221Split<ParentBuilder>::Add(BView* view, float weight)
1222{
1223	fView->AddChild(view, weight);
1224	return *this;
1225}
1226
1227
1228template<typename ParentBuilder>
1229typename Split<ParentBuilder>::ThisBuilder&
1230Split<ParentBuilder>::Add(BLayoutItem* item)
1231{
1232	fView->AddChild(item);
1233	return *this;
1234}
1235
1236
1237template<typename ParentBuilder>
1238typename Split<ParentBuilder>::ThisBuilder&
1239Split<ParentBuilder>::Add(BLayoutItem* item, float weight)
1240{
1241	fView->AddChild(item, weight);
1242	return *this;
1243}
1244
1245
1246template<typename ParentBuilder>
1247typename Split<ParentBuilder>::GroupBuilder
1248Split<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
1258template<typename ParentBuilder>
1259typename Split<ParentBuilder>::GroupBuilder
1260Split<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
1269template<typename ParentBuilder>
1270typename Split<ParentBuilder>::GroupBuilder
1271Split<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
1280template<typename ParentBuilder>
1281typename Split<ParentBuilder>::GridBuilder
1282Split<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
1292template<typename ParentBuilder>
1293typename Split<ParentBuilder>::GridBuilder
1294Split<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
1303template<typename ParentBuilder>
1304typename Split<ParentBuilder>::GridBuilder
1305Split<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
1314template<typename ParentBuilder>
1315typename Split<ParentBuilder>::SplitBuilder
1316Split<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
1326template<typename ParentBuilder>
1327typename Split<ParentBuilder>::CardBuilder
1328Split<ParentBuilder>::AddCards(float weight)
1329{
1330	CardBuilder builder;
1331	builder.SetParent(this);
1332	fView->AddChild(builder.View(), weight);
1333	return builder;
1334}
1335
1336
1337template<typename ParentBuilder>
1338typename Split<ParentBuilder>::CardBuilder
1339Split<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
1348template<typename ParentBuilder>
1349typename Split<ParentBuilder>::CardBuilder
1350Split<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
1359template<typename ParentBuilder>
1360typename Split<ParentBuilder>::ThisBuilder&
1361Split<ParentBuilder>::SetCollapsible(bool collapsible)
1362{
1363	fView->SetCollapsible(collapsible);
1364	return *this;
1365}
1366
1367
1368template<typename ParentBuilder>
1369typename Split<ParentBuilder>::ThisBuilder&
1370Split<ParentBuilder>::SetCollapsible(int32 index, bool collapsible)
1371{
1372	fView->SetCollapsible(index, collapsible);
1373	return *this;
1374}
1375
1376
1377template<typename ParentBuilder>
1378typename Split<ParentBuilder>::ThisBuilder&
1379Split<ParentBuilder>::SetCollapsible(int32 first, int32 last, bool collapsible)
1380{
1381	fView->SetCollapsible(first, last, collapsible);
1382	return *this;
1383}
1384
1385
1386template<typename ParentBuilder>
1387typename Split<ParentBuilder>::ThisBuilder&
1388Split<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
1396template<typename ParentBuilder>
1397typename Split<ParentBuilder>::ThisBuilder&
1398Split<ParentBuilder>::SetInsets(float horizontal, float vertical)
1399{
1400	fView->SetInsets(horizontal, vertical);
1401	return *this;
1402}
1403
1404
1405template<typename ParentBuilder>
1406typename Split<ParentBuilder>::ThisBuilder&
1407Split<ParentBuilder>::SetInsets(float insets)
1408{
1409	fView->SetInsets(insets);
1410	return *this;
1411}
1412
1413
1414template<typename ParentBuilder>
1415Split<ParentBuilder>::operator BSplitView*()
1416{
1417	return fView;
1418}
1419
1420
1421// #pragma mark - Cards
1422
1423
1424template<typename ParentBuilder>
1425Cards<ParentBuilder>::Cards()
1426	:
1427	fLayout((new BCardView())->CardLayout())
1428{
1429}
1430
1431
1432template<typename ParentBuilder>
1433Cards<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
1443template<typename ParentBuilder>
1444Cards<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
1453template<typename ParentBuilder>
1454Cards<ParentBuilder>::Cards(BCardLayout* layout)
1455	:
1456	fLayout(layout)
1457{
1458}
1459
1460
1461template<typename ParentBuilder>
1462Cards<ParentBuilder>::Cards(BCardView* view)
1463	:
1464	fLayout(view->CardLayout())
1465{
1466}
1467
1468
1469template<typename ParentBuilder>
1470BCardLayout*
1471Cards<ParentBuilder>::Layout() const
1472{
1473	return fLayout;
1474}
1475
1476
1477template<typename ParentBuilder>
1478BView*
1479Cards<ParentBuilder>::View() const
1480{
1481	return fLayout->Owner();
1482}
1483
1484
1485template<typename ParentBuilder>
1486typename Cards<ParentBuilder>::ThisBuilder&
1487Cards<ParentBuilder>::GetLayout(BCardLayout** _layout)
1488{
1489	*_layout = fLayout;
1490	return *this;
1491}
1492
1493
1494template<typename ParentBuilder>
1495typename Cards<ParentBuilder>::ThisBuilder&
1496Cards<ParentBuilder>::GetView(BView** _view)
1497{
1498	*_view = fLayout->Owner();
1499	return *this;
1500}
1501
1502
1503template<typename ParentBuilder>
1504typename Cards<ParentBuilder>::ThisBuilder&
1505Cards<ParentBuilder>::Add(BView* view)
1506{
1507	fLayout->AddView(view);
1508	return *this;
1509}
1510
1511
1512template<typename ParentBuilder>
1513typename Cards<ParentBuilder>::ThisBuilder&
1514Cards<ParentBuilder>::Add(BLayoutItem* item)
1515{
1516	fLayout->AddItem(item);
1517	return *this;
1518}
1519
1520
1521template<typename ParentBuilder>
1522typename Cards<ParentBuilder>::GroupBuilder
1523Cards<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
1532template<typename ParentBuilder>
1533typename Cards<ParentBuilder>::GroupBuilder
1534Cards<ParentBuilder>::AddGroup(BGroupView* groupView)
1535{
1536	GroupBuilder builder(groupView);
1537	builder.SetParent(this);
1538	fLayout->AddItem(builder.Layout());
1539	return builder;
1540}
1541
1542
1543template<typename ParentBuilder>
1544typename Cards<ParentBuilder>::GroupBuilder
1545Cards<ParentBuilder>::AddGroup(BGroupLayout* groupLayout)
1546{
1547	GroupBuilder builder(groupLayout);
1548	builder.SetParent(this);
1549	fLayout->AddItem(builder.Layout());
1550	return builder;
1551}
1552
1553
1554template<typename ParentBuilder>
1555typename Cards<ParentBuilder>::GridBuilder
1556Cards<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
1565template<typename ParentBuilder>
1566typename Cards<ParentBuilder>::GridBuilder
1567Cards<ParentBuilder>::AddGrid(BGridLayout* gridLayout)
1568{
1569	GridBuilder builder(gridLayout);
1570	builder.SetParent(this);
1571	fLayout->AddItem(builder.Layout());
1572	return builder;
1573}
1574
1575
1576template<typename ParentBuilder>
1577typename Cards<ParentBuilder>::GridBuilder
1578Cards<ParentBuilder>::AddGrid(BGridView* gridView)
1579{
1580	GridBuilder builder(gridView);
1581	builder.SetParent(this);
1582	fLayout->AddItem(builder.Layout());
1583	return builder;
1584}
1585
1586
1587template<typename ParentBuilder>
1588typename Cards<ParentBuilder>::SplitBuilder
1589Cards<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
1598template<typename ParentBuilder>
1599typename Cards<ParentBuilder>::SplitBuilder
1600Cards<ParentBuilder>::AddSplit(BSplitView* splitView)
1601{
1602	SplitBuilder builder(splitView);
1603	builder.SetParent(this);
1604	fLayout->AddView(builder.View());
1605	return builder;
1606}
1607
1608
1609template<typename ParentBuilder>
1610typename Cards<ParentBuilder>::CardBuilder
1611Cards<ParentBuilder>::AddCards()
1612{
1613	CardBuilder builder;
1614	builder.SetParent(this);
1615	fLayout->AddView(builder.View());
1616	return builder;
1617}
1618
1619
1620template<typename ParentBuilder>
1621typename Cards<ParentBuilder>::CardBuilder
1622Cards<ParentBuilder>::AddCards(BCardLayout* cardLayout)
1623{
1624	CardBuilder builder(cardLayout);
1625	builder.SetParent(this);
1626	fLayout->AddView(builder.View());
1627	return builder;
1628}
1629
1630template<typename ParentBuilder>
1631typename Cards<ParentBuilder>::CardBuilder
1632Cards<ParentBuilder>::AddCards(BCardView* cardView)
1633{
1634	CardBuilder builder(cardView);
1635	builder.SetParent(this);
1636	fLayout->AddView(builder.View());
1637	return builder;
1638}
1639
1640
1641template<typename ParentBuilder>
1642typename Cards<ParentBuilder>::ThisBuilder&
1643Cards<ParentBuilder>::SetExplicitMinSize(BSize size)
1644{
1645	fLayout->SetExplicitMinSize(size);
1646	return *this;
1647}
1648
1649
1650template<typename ParentBuilder>
1651typename Cards<ParentBuilder>::ThisBuilder&
1652Cards<ParentBuilder>::SetExplicitMaxSize(BSize size)
1653{
1654	fLayout->SetExplicitMaxSize(size);
1655	return *this;
1656}
1657
1658
1659template<typename ParentBuilder>
1660typename Cards<ParentBuilder>::ThisBuilder&
1661Cards<ParentBuilder>::SetExplicitPreferredSize(BSize size)
1662{
1663	fLayout->SetExplicitPreferredSize(size);
1664	return *this;
1665}
1666
1667
1668template<typename ParentBuilder>
1669typename Cards<ParentBuilder>::ThisBuilder&
1670Cards<ParentBuilder>::SetExplicitAlignment(BAlignment alignment)
1671{
1672	fLayout->SetExplicitAlignment(alignment);
1673	return *this;
1674}
1675
1676
1677template<typename ParentBuilder>
1678typename Cards<ParentBuilder>::ThisBuilder&
1679Cards<ParentBuilder>::SetVisibleItem(int32 item)
1680{
1681	fLayout->SetVisibleItem(item);
1682	return *this;
1683}
1684
1685
1686template<typename ParentBuilder>
1687Cards<ParentBuilder>::operator BCardLayout*()
1688{
1689	return fLayout;
1690}
1691
1692
1693// #pragma mark - Menu
1694
1695
1696template<typename ParentBuilder>
1697Menu<ParentBuilder>::Menu(BMenu* menu)
1698	:
1699	fMenu(menu)
1700{
1701}
1702
1703
1704template<typename ParentBuilder>
1705typename Menu<ParentBuilder>::ThisBuilder&
1706Menu<ParentBuilder>::GetMenu(BMenu*& _menu)
1707{
1708	_menu = fMenu;
1709	return *this;
1710}
1711
1712
1713template<typename ParentBuilder>
1714typename Menu<ParentBuilder>::ItemBuilder
1715Menu<ParentBuilder>::AddItem(BMenuItem* item)
1716{
1717	fMenu->AddItem(item);
1718	return MenuItem<ParentBuilder>(this->fParent, fMenu, item);
1719}
1720
1721
1722template<typename ParentBuilder>
1723typename Menu<ParentBuilder>::ItemBuilder
1724Menu<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
1734template<typename ParentBuilder>
1735typename Menu<ParentBuilder>::ItemBuilder
1736Menu<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
1743	return MenuItem<ParentBuilder>(this->fParent, fMenu, item);
1744}
1745
1746
1747template<typename ParentBuilder>
1748typename Menu<ParentBuilder>::ItemBuilder
1749Menu<ParentBuilder>::AddItem(const char* label, uint32 messageWhat,
1750	char shortcut, uint32 modifiers)
1751{
1752	BMessage* message = new BMessage(messageWhat);
1753	BMenuItem* item;
1754	try {
1755		item = new BMenuItem(label, message, shortcut, modifiers);
1756	} catch (...) {
1757		delete message;
1758		throw;
1759	}
1760
1761	if (!fMenu->AddItem(item))
1762		delete item;
1763
1764	return MenuItem<ParentBuilder>(this->fParent, fMenu, item);
1765}
1766
1767
1768template<typename ParentBuilder>
1769typename Menu<ParentBuilder>::ThisBuilder&
1770Menu<ParentBuilder>::AddSeparator()
1771{
1772	fMenu->AddSeparatorItem();
1773	return *this;
1774}
1775
1776
1777template<typename ParentBuilder>
1778typename Menu<ParentBuilder>::MenuBuilder
1779Menu<ParentBuilder>::AddMenu(BMenu* menu)
1780{
1781	if (!fMenu->AddItem(menu))
1782		throw std::bad_alloc();
1783
1784	MenuBuilder builder(menu);
1785	builder.SetParent(this);
1786	return builder;
1787}
1788
1789
1790template<typename ParentBuilder>
1791typename Menu<ParentBuilder>::MenuBuilder
1792Menu<ParentBuilder>::AddMenu(const char* title, menu_layout layout)
1793{
1794	BMenu* menu = new BMenu(title, layout);
1795	if (!fMenu->AddItem(menu)) {
1796		delete menu;
1797		throw std::bad_alloc();
1798	}
1799
1800	MenuBuilder builder(menu);
1801	builder.SetParent(this);
1802	return builder;
1803}
1804
1805
1806// #pragma mark - MenuItem
1807
1808
1809template<typename ParentBuilder>
1810MenuItem<ParentBuilder>::MenuItem(ParentBuilder* parentBuilder, BMenu* menu,
1811	BMenuItem* item)
1812	:
1813	Menu<ParentBuilder>(menu),
1814	fMenuItem(item)
1815{
1816	this->SetParent(parentBuilder);
1817}
1818
1819
1820template<typename ParentBuilder>
1821typename MenuItem<ParentBuilder>::ThisBuilder&
1822MenuItem<ParentBuilder>::GetItem(BMenuItem*& _item)
1823{
1824	_item = fMenuItem;
1825	return *this;
1826}
1827
1828
1829template<typename ParentBuilder>
1830typename MenuItem<ParentBuilder>::ThisBuilder&
1831MenuItem<ParentBuilder>::SetEnabled(bool enabled)
1832{
1833	fMenuItem->SetEnabled(enabled);
1834	return *this;
1835}
1836
1837
1838}	// namespace BLayoutBuilder
1839
1840
1841#endif	// _LAYOUT_BUILDER_H
1842