LayoutBuilder.h revision 52c07497
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
461	fLayout->Owner()->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
462		// TODO: we get a white background if we don't do this
463}
464
465
466template<typename ParentBuilder>
467Group<ParentBuilder>::Group(BView* view, orientation orientation,
468		float spacing)
469	:
470	fLayout(new BGroupLayout(orientation, spacing))
471{
472	view->SetLayout(fLayout);
473	view->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
474		// TODO: we get a white background if we don't do this
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
800	fLayout->Owner()->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
801		// TODO: we get a white background if we don't do this
802}
803
804
805template<typename ParentBuilder>
806Grid<ParentBuilder>::Grid(BView* view, float horizontalSpacing,
807	float verticalSpacing)
808	:
809	fLayout(new BGridLayout(horizontalSpacing, verticalSpacing))
810{
811	view->SetLayout(fLayout);
812	view->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
813		// TODO: we get a white background if we don't do this
814}
815
816
817template<typename ParentBuilder>
818Grid<ParentBuilder>::Grid(BGridLayout* layout)
819	:
820	fLayout(layout)
821{
822}
823
824
825template<typename ParentBuilder>
826Grid<ParentBuilder>::Grid(BGridView* view)
827	:
828	fLayout(view->GridLayout())
829{
830}
831
832
833template<typename ParentBuilder>
834BGridLayout*
835Grid<ParentBuilder>::Layout() const
836{
837	return fLayout;
838}
839
840
841template<typename ParentBuilder>
842BView*
843Grid<ParentBuilder>::View() const
844{
845	return fLayout->Owner();
846}
847
848
849template<typename ParentBuilder>
850typename Grid<ParentBuilder>::ThisBuilder&
851Grid<ParentBuilder>::GetLayout(BGridLayout** _layout)
852{
853	*_layout = fLayout;
854	return *this;
855}
856
857
858template<typename ParentBuilder>
859typename Grid<ParentBuilder>::ThisBuilder&
860Grid<ParentBuilder>::GetView(BView** _view)
861{
862	*_view = fLayout->Owner();
863	return *this;
864}
865
866
867template<typename ParentBuilder>
868typename Grid<ParentBuilder>::ThisBuilder&
869Grid<ParentBuilder>::Add(BView* view, int32 column, int32 row,
870	int32 columnCount, int32 rowCount)
871{
872	fLayout->AddView(view, column, row, columnCount, rowCount);
873	return *this;
874}
875
876
877template<typename ParentBuilder>
878typename Grid<ParentBuilder>::ThisBuilder&
879Grid<ParentBuilder>::Add(BLayoutItem* item, int32 column, int32 row,
880	int32 columnCount, int32 rowCount)
881{
882	fLayout->AddItem(item, column, row, columnCount, rowCount);
883	return *this;
884}
885
886
887template<typename ParentBuilder>
888typename Grid<ParentBuilder>::ThisBuilder&
889Grid<ParentBuilder>::AddMenuField(BMenuField* menuField, int32 column,
890	int32 row, alignment labelAlignment, int32 labelColumnCount,
891	int32 fieldColumnCount, int32 rowCount)
892{
893	BLayoutItem* item = menuField->CreateLabelLayoutItem();
894	item->SetExplicitAlignment(
895		BAlignment(labelAlignment, B_ALIGN_VERTICAL_UNSET));
896	fLayout->AddItem(item, column, row, labelColumnCount, rowCount);
897	fLayout->AddItem(menuField->CreateMenuBarLayoutItem(),
898		column + labelColumnCount, row, fieldColumnCount, rowCount);
899	return *this;
900}
901
902
903template<typename ParentBuilder>
904typename Grid<ParentBuilder>::ThisBuilder&
905Grid<ParentBuilder>::AddTextControl(BTextControl* textControl, int32 column,
906	int32 row, alignment labelAlignment, int32 labelColumnCount,
907	int32 textColumnCount, int32 rowCount)
908{
909	BLayoutItem* item = textControl->CreateLabelLayoutItem();
910	item->SetExplicitAlignment(
911		BAlignment(labelAlignment, B_ALIGN_VERTICAL_UNSET));
912	fLayout->AddItem(item, column, row, labelColumnCount, rowCount);
913	fLayout->AddItem(textControl->CreateTextViewLayoutItem(),
914		column + labelColumnCount, row, textColumnCount, rowCount);
915	return *this;
916}
917
918
919template<typename ParentBuilder>
920typename Grid<ParentBuilder>::GroupBuilder
921Grid<ParentBuilder>::AddGroup(orientation orientation, float spacing,
922		int32 column, int32 row, int32 columnCount, int32 rowCount)
923{
924	GroupBuilder builder(new BGroupLayout(orientation, spacing));
925	builder.SetParent(this);
926	fLayout->AddItem(builder.Layout(), column, row, columnCount, rowCount);
927	return builder;
928}
929
930
931template<typename ParentBuilder>
932typename Grid<ParentBuilder>::GroupBuilder
933Grid<ParentBuilder>::AddGroup(BGroupView* groupView, int32 column, int32 row,
934	int32 columnCount, int32 rowCount)
935{
936	GroupBuilder builder(groupView);
937	builder.SetParent(this);
938	fLayout->AddItem(builder.Layout(), column, row, columnCount, rowCount);
939	return builder;
940}
941
942
943template<typename ParentBuilder>
944typename Grid<ParentBuilder>::GroupBuilder
945Grid<ParentBuilder>::AddGroup(BGroupLayout* groupLayout, int32 column,
946	int32 row, int32 columnCount, int32 rowCount)
947{
948	GroupBuilder builder(groupLayout);
949	builder.SetParent(this);
950	fLayout->AddItem(builder.Layout(), column, row, columnCount, rowCount);
951	return builder;
952}
953
954
955template<typename ParentBuilder>
956typename Grid<ParentBuilder>::GridBuilder
957Grid<ParentBuilder>::AddGrid(float horizontalSpacing, float verticalSpacing,
958	int32 column, int32 row, int32 columnCount, int32 rowCount)
959{
960	GridBuilder builder(new BGridLayout(horizontalSpacing, verticalSpacing));
961	builder.SetParent(this);
962	fLayout->AddItem(builder.Layout(), column, row, columnCount, rowCount);
963	return builder;
964}
965
966
967template<typename ParentBuilder>
968typename Grid<ParentBuilder>::GridBuilder
969Grid<ParentBuilder>::AddGrid(BGridView* gridView, int32 column, int32 row,
970	int32 columnCount, int32 rowCount)
971{
972	GridBuilder builder(gridView);
973	builder.SetParent(this);
974	fLayout->AddView(builder.View(), column, row, columnCount, rowCount);
975	return builder;
976}
977
978
979template<typename ParentBuilder>
980typename Grid<ParentBuilder>::SplitBuilder
981Grid<ParentBuilder>::AddSplit(orientation orientation, float spacing,
982	int32 column, int32 row, int32 columnCount, int32 rowCount)
983{
984	SplitBuilder builder(orientation, spacing);
985	builder.SetParent(this);
986	fLayout->AddView(builder.View(), column, row, columnCount, rowCount);
987	return builder;
988}
989
990
991template<typename ParentBuilder>
992typename Grid<ParentBuilder>::SplitBuilder
993Grid<ParentBuilder>::AddSplit(BSplitView* splitView, int32 column, int32 row,
994	int32 columnCount, int32 rowCount)
995{
996	SplitBuilder builder(splitView);
997	builder.SetParent(this);
998	fLayout->AddView(builder.View(), column, row, columnCount, rowCount);
999	return builder;
1000}
1001
1002
1003template<typename ParentBuilder>
1004typename Grid<ParentBuilder>::CardBuilder
1005Grid<ParentBuilder>::AddCards(int32 column, int32 row, int32 columnCount,
1006	int32 rowCount)
1007{
1008	CardBuilder builder;
1009	builder.SetParent(this);
1010	fLayout->AddView(builder.View(), column, row, columnCount, rowCount);
1011	return builder;
1012}
1013
1014
1015template<typename ParentBuilder>
1016typename Grid<ParentBuilder>::CardBuilder
1017Grid<ParentBuilder>::AddCards(BCardLayout* cardLayout, int32 column, int32 row,
1018	int32 columnCount, int32 rowCount)
1019{
1020	CardBuilder builder(cardLayout);
1021	builder.SetParent(this);
1022	fLayout->AddView(builder.View(), column, row, columnCount, rowCount);
1023	return builder;
1024}
1025
1026
1027template<typename ParentBuilder>
1028typename Grid<ParentBuilder>::CardBuilder
1029Grid<ParentBuilder>::AddCards(BCardView* cardView, int32 column, int32 row,
1030	int32 columnCount, int32 rowCount)
1031{
1032	CardBuilder builder(cardView);
1033	builder.SetParent(this);
1034	fLayout->AddView(builder.View(), column, row, columnCount, rowCount);
1035	return builder;
1036}
1037
1038
1039template<typename ParentBuilder>
1040typename Grid<ParentBuilder>::ThisBuilder&
1041Grid<ParentBuilder>::AddGlue(int32 column, int32 row, int32 columnCount,
1042	int32 rowCount)
1043{
1044	fLayout->AddItem(BSpaceLayoutItem::CreateGlue(), column, row, columnCount,
1045		rowCount);
1046	return *this;
1047}
1048
1049
1050template<typename ParentBuilder>
1051typename Grid<ParentBuilder>::ThisBuilder&
1052Grid<ParentBuilder>::SetHorizontalSpacing(float spacing)
1053{
1054	fLayout->SetHorizontalSpacing(spacing);
1055	return *this;
1056}
1057
1058
1059template<typename ParentBuilder>
1060typename Grid<ParentBuilder>::ThisBuilder&
1061Grid<ParentBuilder>::SetVerticalSpacing(float spacing)
1062{
1063	fLayout->SetVerticalSpacing(spacing);
1064	return *this;
1065}
1066
1067
1068template<typename ParentBuilder>
1069typename Grid<ParentBuilder>::ThisBuilder&
1070Grid<ParentBuilder>::SetSpacing(float horizontal, float vertical)
1071{
1072	fLayout->SetSpacing(horizontal, vertical);
1073	return *this;
1074}
1075
1076
1077template<typename ParentBuilder>
1078typename Grid<ParentBuilder>::ThisBuilder&
1079Grid<ParentBuilder>::SetColumnWeight(int32 column, float weight)
1080{
1081	fLayout->SetColumnWeight(column, weight);
1082	return *this;
1083}
1084
1085
1086template<typename ParentBuilder>
1087typename Grid<ParentBuilder>::ThisBuilder&
1088Grid<ParentBuilder>::SetRowWeight(int32 row, float weight)
1089{
1090	fLayout->SetRowWeight(row, weight);
1091	return *this;
1092}
1093
1094
1095template<typename ParentBuilder>
1096typename Grid<ParentBuilder>::ThisBuilder&
1097Grid<ParentBuilder>::SetInsets(float left, float top, float right,
1098	float bottom)
1099{
1100	fLayout->SetInsets(left, top, right, bottom);
1101	return *this;
1102}
1103
1104
1105template<typename ParentBuilder>
1106typename Grid<ParentBuilder>::ThisBuilder&
1107Grid<ParentBuilder>::SetInsets(float horizontal, float vertical)
1108{
1109	fLayout->SetInsets(horizontal, vertical);
1110	return *this;
1111}
1112
1113
1114template<typename ParentBuilder>
1115typename Grid<ParentBuilder>::ThisBuilder&
1116Grid<ParentBuilder>::SetInsets(float insets)
1117{
1118	fLayout->SetInsets(insets);
1119	return *this;
1120}
1121
1122
1123template<typename ParentBuilder>
1124typename Grid<ParentBuilder>::ThisBuilder&
1125Grid<ParentBuilder>::SetExplicitMinSize(BSize size)
1126{
1127	fLayout->SetExplicitMinSize(size);
1128	return *this;
1129}
1130
1131
1132template<typename ParentBuilder>
1133typename Grid<ParentBuilder>::ThisBuilder&
1134Grid<ParentBuilder>::SetExplicitMaxSize(BSize size)
1135{
1136	fLayout->SetExplicitMaxSize(size);
1137	return *this;
1138}
1139
1140
1141template<typename ParentBuilder>
1142typename Grid<ParentBuilder>::ThisBuilder&
1143Grid<ParentBuilder>::SetExplicitPreferredSize(BSize size)
1144{
1145	fLayout->SetExplicitPreferredSize(size);
1146	return *this;
1147}
1148
1149
1150template<typename ParentBuilder>
1151typename Grid<ParentBuilder>::ThisBuilder&
1152Grid<ParentBuilder>::SetExplicitAlignment(BAlignment alignment)
1153{
1154	fLayout->SetExplicitAlignment(alignment);
1155	return *this;
1156}
1157
1158
1159template<typename ParentBuilder>
1160Grid<ParentBuilder>::operator BGridLayout*()
1161{
1162	return fLayout;
1163}
1164
1165
1166// #pragma mark - Split
1167
1168
1169template<typename ParentBuilder>
1170Split<ParentBuilder>::Split(orientation orientation, float spacing)
1171	:
1172	fView(new BSplitView(orientation, spacing))
1173{
1174}
1175
1176
1177template<typename ParentBuilder>
1178Split<ParentBuilder>::Split(BSplitView* view)
1179	:
1180	fView(view)
1181{
1182}
1183
1184
1185template<typename ParentBuilder>
1186BSplitView*
1187Split<ParentBuilder>::View() const
1188{
1189	return fView;
1190}
1191
1192
1193template<typename ParentBuilder>
1194typename Split<ParentBuilder>::ThisBuilder&
1195Split<ParentBuilder>::GetView(BView** _view)
1196{
1197	*_view = fView;
1198	return *this;
1199}
1200
1201
1202template<typename ParentBuilder>
1203typename Split<ParentBuilder>::ThisBuilder&
1204Split<ParentBuilder>::GetSplitView(BSplitView** _view)
1205{
1206	*_view = fView;
1207	return *this;
1208}
1209
1210
1211template<typename ParentBuilder>
1212typename Split<ParentBuilder>::ThisBuilder&
1213Split<ParentBuilder>::Add(BView* view)
1214{
1215	fView->AddChild(view);
1216	return *this;
1217}
1218
1219
1220template<typename ParentBuilder>
1221typename Split<ParentBuilder>::ThisBuilder&
1222Split<ParentBuilder>::Add(BView* view, float weight)
1223{
1224	fView->AddChild(view, weight);
1225	return *this;
1226}
1227
1228
1229template<typename ParentBuilder>
1230typename Split<ParentBuilder>::ThisBuilder&
1231Split<ParentBuilder>::Add(BLayoutItem* item)
1232{
1233	fView->AddChild(item);
1234	return *this;
1235}
1236
1237
1238template<typename ParentBuilder>
1239typename Split<ParentBuilder>::ThisBuilder&
1240Split<ParentBuilder>::Add(BLayoutItem* item, float weight)
1241{
1242	fView->AddChild(item, weight);
1243	return *this;
1244}
1245
1246
1247template<typename ParentBuilder>
1248typename Split<ParentBuilder>::GroupBuilder
1249Split<ParentBuilder>::AddGroup(orientation orientation, float spacing,
1250		float weight)
1251{
1252	GroupBuilder builder(new BGroupLayout(orientation, spacing));
1253	builder.SetParent(this);
1254	fView->AddChild(builder.Layout(), weight);
1255	return builder;
1256}
1257
1258
1259template<typename ParentBuilder>
1260typename Split<ParentBuilder>::GroupBuilder
1261Split<ParentBuilder>::AddGroup(BGroupView* groupView, float weight)
1262{
1263	GroupBuilder builder(groupView);
1264	builder.SetParent(this);
1265	fView->AddChild(builder.Layout(), weight);
1266	return builder;
1267}
1268
1269
1270template<typename ParentBuilder>
1271typename Split<ParentBuilder>::GroupBuilder
1272Split<ParentBuilder>::AddGroup(BGroupLayout* groupLayout, float weight)
1273{
1274	GroupBuilder builder(groupLayout);
1275	builder.SetParent(this);
1276	fView->AddChild(builder.Layout(), weight);
1277	return builder;
1278}
1279
1280
1281template<typename ParentBuilder>
1282typename Split<ParentBuilder>::GridBuilder
1283Split<ParentBuilder>::AddGrid(float horizontalSpacing, float verticalSpacing,
1284	float weight)
1285{
1286	GridBuilder builder(new BGridLayout(horizontalSpacing, verticalSpacing));
1287	builder.SetParent(this);
1288	fView->AddChild(builder.Layout(), weight);
1289	return builder;
1290}
1291
1292
1293template<typename ParentBuilder>
1294typename Split<ParentBuilder>::GridBuilder
1295Split<ParentBuilder>::AddGrid(BGridView* gridView, float weight)
1296{
1297	GridBuilder builder(gridView);
1298	builder.SetParent(this);
1299	fView->AddChild(builder.Layout(), weight);
1300	return builder;
1301}
1302
1303
1304template<typename ParentBuilder>
1305typename Split<ParentBuilder>::GridBuilder
1306Split<ParentBuilder>::AddGrid(BGridLayout* layout, float weight)
1307{
1308	GridBuilder builder(layout);
1309	builder.SetParent(this);
1310	fView->AddChild(builder.Layout(), weight);
1311	return builder;
1312}
1313
1314
1315template<typename ParentBuilder>
1316typename Split<ParentBuilder>::SplitBuilder
1317Split<ParentBuilder>::AddSplit(orientation orientation, float spacing,
1318		float weight)
1319{
1320	SplitBuilder builder(orientation, spacing);
1321	builder.SetParent(this);
1322	fView->AddChild(builder.View(), weight);
1323	return builder;
1324}
1325
1326
1327template<typename ParentBuilder>
1328typename Split<ParentBuilder>::CardBuilder
1329Split<ParentBuilder>::AddCards(float weight)
1330{
1331	CardBuilder builder;
1332	builder.SetParent(this);
1333	fView->AddChild(builder.View(), weight);
1334	return builder;
1335}
1336
1337
1338template<typename ParentBuilder>
1339typename Split<ParentBuilder>::CardBuilder
1340Split<ParentBuilder>::AddCards(BCardLayout* cardLayout, float weight)
1341{
1342	CardBuilder builder(cardLayout);
1343	builder.SetParent(this);
1344	fView->AddChild(builder.View(), weight);
1345	return builder;
1346}
1347
1348
1349template<typename ParentBuilder>
1350typename Split<ParentBuilder>::CardBuilder
1351Split<ParentBuilder>::AddCards(BCardView* cardView, float weight)
1352{
1353	CardBuilder builder(cardView);
1354	builder.SetParent(this);
1355	fView->AddChild(builder.View(), weight);
1356	return builder;
1357}
1358
1359
1360template<typename ParentBuilder>
1361typename Split<ParentBuilder>::ThisBuilder&
1362Split<ParentBuilder>::SetCollapsible(bool collapsible)
1363{
1364	fView->SetCollapsible(collapsible);
1365	return *this;
1366}
1367
1368
1369template<typename ParentBuilder>
1370typename Split<ParentBuilder>::ThisBuilder&
1371Split<ParentBuilder>::SetCollapsible(int32 index, bool collapsible)
1372{
1373	fView->SetCollapsible(index, collapsible);
1374	return *this;
1375}
1376
1377
1378template<typename ParentBuilder>
1379typename Split<ParentBuilder>::ThisBuilder&
1380Split<ParentBuilder>::SetCollapsible(int32 first, int32 last, bool collapsible)
1381{
1382	fView->SetCollapsible(first, last, collapsible);
1383	return *this;
1384}
1385
1386
1387template<typename ParentBuilder>
1388typename Split<ParentBuilder>::ThisBuilder&
1389Split<ParentBuilder>::SetInsets(float left, float top, float right,
1390	float bottom)
1391{
1392	fView->SetInsets(left, top, right, bottom);
1393	return *this;
1394}
1395
1396
1397template<typename ParentBuilder>
1398typename Split<ParentBuilder>::ThisBuilder&
1399Split<ParentBuilder>::SetInsets(float horizontal, float vertical)
1400{
1401	fView->SetInsets(horizontal, vertical);
1402	return *this;
1403}
1404
1405
1406template<typename ParentBuilder>
1407typename Split<ParentBuilder>::ThisBuilder&
1408Split<ParentBuilder>::SetInsets(float insets)
1409{
1410	fView->SetInsets(insets);
1411	return *this;
1412}
1413
1414
1415template<typename ParentBuilder>
1416Split<ParentBuilder>::operator BSplitView*()
1417{
1418	return fView;
1419}
1420
1421
1422// #pragma mark - Cards
1423
1424
1425template<typename ParentBuilder>
1426Cards<ParentBuilder>::Cards()
1427	:
1428	fLayout((new BCardView())->CardLayout())
1429{
1430}
1431
1432
1433template<typename ParentBuilder>
1434Cards<ParentBuilder>::Cards(BWindow* window)
1435	:
1436	fLayout(new BCardLayout())
1437{
1438	window->SetLayout(fLayout);
1439
1440	fLayout->Owner()->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
1441}
1442
1443
1444template<typename ParentBuilder>
1445Cards<ParentBuilder>::Cards(BView* view)
1446	:
1447	fLayout(new BCardLayout())
1448{
1449	view->SetLayout(fLayout);
1450	view->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
1451}
1452
1453
1454template<typename ParentBuilder>
1455Cards<ParentBuilder>::Cards(BCardLayout* layout)
1456	:
1457	fLayout(layout)
1458{
1459}
1460
1461
1462template<typename ParentBuilder>
1463Cards<ParentBuilder>::Cards(BCardView* view)
1464	:
1465	fLayout(view->CardLayout())
1466{
1467}
1468
1469
1470template<typename ParentBuilder>
1471BCardLayout*
1472Cards<ParentBuilder>::Layout() const
1473{
1474	return fLayout;
1475}
1476
1477
1478template<typename ParentBuilder>
1479BView*
1480Cards<ParentBuilder>::View() const
1481{
1482	return fLayout->Owner();
1483}
1484
1485
1486template<typename ParentBuilder>
1487typename Cards<ParentBuilder>::ThisBuilder&
1488Cards<ParentBuilder>::GetLayout(BCardLayout** _layout)
1489{
1490	*_layout = fLayout;
1491	return *this;
1492}
1493
1494
1495template<typename ParentBuilder>
1496typename Cards<ParentBuilder>::ThisBuilder&
1497Cards<ParentBuilder>::GetView(BView** _view)
1498{
1499	*_view = fLayout->Owner();
1500	return *this;
1501}
1502
1503
1504template<typename ParentBuilder>
1505typename Cards<ParentBuilder>::ThisBuilder&
1506Cards<ParentBuilder>::Add(BView* view)
1507{
1508	fLayout->AddView(view);
1509	return *this;
1510}
1511
1512
1513template<typename ParentBuilder>
1514typename Cards<ParentBuilder>::ThisBuilder&
1515Cards<ParentBuilder>::Add(BLayoutItem* item)
1516{
1517	fLayout->AddItem(item);
1518	return *this;
1519}
1520
1521
1522template<typename ParentBuilder>
1523typename Cards<ParentBuilder>::GroupBuilder
1524Cards<ParentBuilder>::AddGroup(orientation orientation, float spacing)
1525{
1526	GroupBuilder builder(new BGroupLayout(orientation, spacing));
1527	builder.SetParent(this);
1528	fLayout->AddItem(builder.Layout());
1529	return builder;
1530}
1531
1532
1533template<typename ParentBuilder>
1534typename Cards<ParentBuilder>::GroupBuilder
1535Cards<ParentBuilder>::AddGroup(BGroupView* groupView)
1536{
1537	GroupBuilder builder(groupView);
1538	builder.SetParent(this);
1539	fLayout->AddItem(builder.Layout());
1540	return builder;
1541}
1542
1543
1544template<typename ParentBuilder>
1545typename Cards<ParentBuilder>::GroupBuilder
1546Cards<ParentBuilder>::AddGroup(BGroupLayout* groupLayout)
1547{
1548	GroupBuilder builder(groupLayout);
1549	builder.SetParent(this);
1550	fLayout->AddItem(builder.Layout());
1551	return builder;
1552}
1553
1554
1555template<typename ParentBuilder>
1556typename Cards<ParentBuilder>::GridBuilder
1557Cards<ParentBuilder>::AddGrid(float horizontal, float vertical)
1558{
1559	GridBuilder builder(horizontal, vertical);
1560	builder.SetParent(this);
1561	fLayout->AddItem(builder.Layout());
1562	return builder;
1563}
1564
1565
1566template<typename ParentBuilder>
1567typename Cards<ParentBuilder>::GridBuilder
1568Cards<ParentBuilder>::AddGrid(BGridLayout* gridLayout)
1569{
1570	GridBuilder builder(gridLayout);
1571	builder.SetParent(this);
1572	fLayout->AddItem(builder.Layout());
1573	return builder;
1574}
1575
1576
1577template<typename ParentBuilder>
1578typename Cards<ParentBuilder>::GridBuilder
1579Cards<ParentBuilder>::AddGrid(BGridView* gridView)
1580{
1581	GridBuilder builder(gridView);
1582	builder.SetParent(this);
1583	fLayout->AddItem(builder.Layout());
1584	return builder;
1585}
1586
1587
1588template<typename ParentBuilder>
1589typename Cards<ParentBuilder>::SplitBuilder
1590Cards<ParentBuilder>::AddSplit(orientation orientation, float spacing)
1591{
1592	SplitBuilder builder(orientation, spacing);
1593	builder.SetParent(this);
1594	fLayout->AddView(builder.View());
1595	return builder;
1596}
1597
1598
1599template<typename ParentBuilder>
1600typename Cards<ParentBuilder>::SplitBuilder
1601Cards<ParentBuilder>::AddSplit(BSplitView* splitView)
1602{
1603	SplitBuilder builder(splitView);
1604	builder.SetParent(this);
1605	fLayout->AddView(builder.View());
1606	return builder;
1607}
1608
1609
1610template<typename ParentBuilder>
1611typename Cards<ParentBuilder>::CardBuilder
1612Cards<ParentBuilder>::AddCards()
1613{
1614	CardBuilder builder;
1615	builder.SetParent(this);
1616	fLayout->AddView(builder.View());
1617	return builder;
1618}
1619
1620
1621template<typename ParentBuilder>
1622typename Cards<ParentBuilder>::CardBuilder
1623Cards<ParentBuilder>::AddCards(BCardLayout* cardLayout)
1624{
1625	CardBuilder builder(cardLayout);
1626	builder.SetParent(this);
1627	fLayout->AddView(builder.View());
1628	return builder;
1629}
1630
1631template<typename ParentBuilder>
1632typename Cards<ParentBuilder>::CardBuilder
1633Cards<ParentBuilder>::AddCards(BCardView* cardView)
1634{
1635	CardBuilder builder(cardView);
1636	builder.SetParent(this);
1637	fLayout->AddView(builder.View());
1638	return builder;
1639}
1640
1641
1642template<typename ParentBuilder>
1643typename Cards<ParentBuilder>::ThisBuilder&
1644Cards<ParentBuilder>::SetExplicitMinSize(BSize size)
1645{
1646	fLayout->SetExplicitMinSize(size);
1647	return *this;
1648}
1649
1650
1651template<typename ParentBuilder>
1652typename Cards<ParentBuilder>::ThisBuilder&
1653Cards<ParentBuilder>::SetExplicitMaxSize(BSize size)
1654{
1655	fLayout->SetExplicitMaxSize(size);
1656	return *this;
1657}
1658
1659
1660template<typename ParentBuilder>
1661typename Cards<ParentBuilder>::ThisBuilder&
1662Cards<ParentBuilder>::SetExplicitPreferredSize(BSize size)
1663{
1664	fLayout->SetExplicitPreferredSize(size);
1665	return *this;
1666}
1667
1668
1669template<typename ParentBuilder>
1670typename Cards<ParentBuilder>::ThisBuilder&
1671Cards<ParentBuilder>::SetExplicitAlignment(BAlignment alignment)
1672{
1673	fLayout->SetExplicitAlignment(alignment);
1674	return *this;
1675}
1676
1677
1678template<typename ParentBuilder>
1679typename Cards<ParentBuilder>::ThisBuilder&
1680Cards<ParentBuilder>::SetVisibleItem(int32 item)
1681{
1682	fLayout->SetVisibleItem(item);
1683	return *this;
1684}
1685
1686
1687template<typename ParentBuilder>
1688Cards<ParentBuilder>::operator BCardLayout*()
1689{
1690	return fLayout;
1691}
1692
1693
1694// #pragma mark - Menu
1695
1696
1697template<typename ParentBuilder>
1698Menu<ParentBuilder>::Menu(BMenu* menu)
1699	:
1700	fMenu(menu)
1701{
1702}
1703
1704
1705template<typename ParentBuilder>
1706typename Menu<ParentBuilder>::ThisBuilder&
1707Menu<ParentBuilder>::GetMenu(BMenu*& _menu)
1708{
1709	_menu = fMenu;
1710	return *this;
1711}
1712
1713
1714template<typename ParentBuilder>
1715typename Menu<ParentBuilder>::ItemBuilder
1716Menu<ParentBuilder>::AddItem(BMenuItem* item)
1717{
1718	fMenu->AddItem(item);
1719	return MenuItem<ParentBuilder>(this->fParent, fMenu, item);
1720}
1721
1722
1723template<typename ParentBuilder>
1724typename Menu<ParentBuilder>::ItemBuilder
1725Menu<ParentBuilder>::AddItem(BMenu* menu)
1726{
1727	if (!fMenu->AddItem(menu))
1728		throw std::bad_alloc();
1729
1730	return MenuItem<ParentBuilder>(this->fParent, fMenu,
1731		fMenu->ItemAt(fMenu->CountItems() - 1));
1732}
1733
1734
1735template<typename ParentBuilder>
1736typename Menu<ParentBuilder>::ItemBuilder
1737Menu<ParentBuilder>::AddItem(const char* label, BMessage* message,
1738	char shortcut, uint32 modifiers)
1739{
1740	BMenuItem* item = new BMenuItem(label, message, shortcut, modifiers);
1741	if (!fMenu->AddItem(item))
1742		delete item;
1743
1744	return MenuItem<ParentBuilder>(this->fParent, fMenu, item);
1745}
1746
1747
1748template<typename ParentBuilder>
1749typename Menu<ParentBuilder>::ItemBuilder
1750Menu<ParentBuilder>::AddItem(const char* label, uint32 messageWhat,
1751	char shortcut, uint32 modifiers)
1752{
1753	BMessage* message = new BMessage(messageWhat);
1754	BMenuItem* item;
1755	try {
1756		item = new BMenuItem(label, message, shortcut, modifiers);
1757	} catch (...) {
1758		delete message;
1759		throw;
1760	}
1761
1762	if (!fMenu->AddItem(item))
1763		delete item;
1764
1765	return MenuItem<ParentBuilder>(this->fParent, fMenu, item);
1766}
1767
1768
1769template<typename ParentBuilder>
1770typename Menu<ParentBuilder>::ThisBuilder&
1771Menu<ParentBuilder>::AddSeparator()
1772{
1773	fMenu->AddSeparatorItem();
1774	return *this;
1775}
1776
1777
1778template<typename ParentBuilder>
1779typename Menu<ParentBuilder>::MenuBuilder
1780Menu<ParentBuilder>::AddMenu(BMenu* menu)
1781{
1782	if (!fMenu->AddItem(menu))
1783		throw std::bad_alloc();
1784
1785	MenuBuilder builder(menu);
1786	builder.SetParent(this);
1787	return builder;
1788}
1789
1790
1791template<typename ParentBuilder>
1792typename Menu<ParentBuilder>::MenuBuilder
1793Menu<ParentBuilder>::AddMenu(const char* title, menu_layout layout)
1794{
1795	BMenu* menu = new BMenu(title, layout);
1796	if (!fMenu->AddItem(menu)) {
1797		delete menu;
1798		throw std::bad_alloc();
1799	}
1800
1801	MenuBuilder builder(menu);
1802	builder.SetParent(this);
1803	return builder;
1804}
1805
1806
1807// #pragma mark - MenuItem
1808
1809
1810template<typename ParentBuilder>
1811MenuItem<ParentBuilder>::MenuItem(ParentBuilder* parentBuilder, BMenu* menu,
1812	BMenuItem* item)
1813	:
1814	Menu<ParentBuilder>(menu),
1815	fMenuItem(item)
1816{
1817	this->SetParent(parentBuilder);
1818}
1819
1820
1821template<typename ParentBuilder>
1822typename MenuItem<ParentBuilder>::ThisBuilder&
1823MenuItem<ParentBuilder>::GetItem(BMenuItem*& _item)
1824{
1825	_item = fMenuItem;
1826	return *this;
1827}
1828
1829
1830template<typename ParentBuilder>
1831typename MenuItem<ParentBuilder>::ThisBuilder&
1832MenuItem<ParentBuilder>::SetEnabled(bool enabled)
1833{
1834	fMenuItem->SetEnabled(enabled);
1835	return *this;
1836}
1837
1838
1839}	// namespace BLayoutBuilder
1840
1841
1842#endif	// _LAYOUT_BUILDER_H
1843