Fix more class/struct mixups.
[haiku.git] / headers / os / interface / LayoutBuilder.h
blob4ba372c9d351eb884f7e928cdc9a0f9efbd45241
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
9 #include <new>
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>
26 namespace BLayoutBuilder {
28 template<typename ParentBuilder> class Base;
29 template<typename ParentBuilder = void*> class Group;
30 template<typename ParentBuilder = void*> class Grid;
31 template<typename ParentBuilder = void*> class Split;
32 template<typename ParentBuilder = void*> class Cards;
33 template<typename ParentBuilder = void*> class Menu;
34 template<typename ParentBuilder = void*> class MenuItem;
37 template<typename ParentBuilder>
38 class Base {
39 protected:
40 inline Base();
42 public:
43 inline void SetParent(ParentBuilder* parent);
44 // conceptually private
45 inline ParentBuilder& End();
47 protected:
48 ParentBuilder* fParent;
52 template<typename ParentBuilder>
53 class Group : public Base<ParentBuilder> {
54 public:
55 typedef Group<ParentBuilder> ThisBuilder;
56 typedef Group<ThisBuilder> GroupBuilder;
57 typedef Grid<ThisBuilder> GridBuilder;
58 typedef Split<ThisBuilder> SplitBuilder;
59 typedef Cards<ThisBuilder> CardBuilder;
61 public:
62 inline Group(orientation orientation = B_HORIZONTAL,
63 float spacing = B_USE_DEFAULT_SPACING);
64 inline Group(BWindow* window,
65 orientation orientation = B_HORIZONTAL,
66 float spacing = B_USE_DEFAULT_SPACING);
67 inline Group(BView* view,
68 orientation orientation = B_HORIZONTAL,
69 float spacing = B_USE_DEFAULT_SPACING);
70 inline Group(BGroupLayout* layout);
71 inline Group(BGroupView* view);
73 inline BGroupLayout* Layout() const;
74 inline BView* View() const;
75 inline ThisBuilder& GetLayout(BGroupLayout** _layout);
76 inline ThisBuilder& GetView(BView** _view);
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);
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);
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);
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);
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);
112 inline ThisBuilder& AddGlue(float weight = 1.0f);
113 inline ThisBuilder& AddStrut(float size);
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);
120 inline ThisBuilder& SetExplicitMinSize(BSize size);
121 inline ThisBuilder& SetExplicitMaxSize(BSize size);
122 inline ThisBuilder& SetExplicitPreferredSize(BSize size);
123 inline ThisBuilder& SetExplicitAlignment(BAlignment alignment);
125 inline operator BGroupLayout*();
127 private:
128 BGroupLayout* fLayout;
132 template<typename ParentBuilder>
133 class Grid : public Base<ParentBuilder> {
134 public:
135 typedef Grid<ParentBuilder> ThisBuilder;
136 typedef Group<ThisBuilder> GroupBuilder;
137 typedef Grid<ThisBuilder> GridBuilder;
138 typedef Split<ThisBuilder> SplitBuilder;
139 typedef Cards<ThisBuilder> CardBuilder;
141 public:
142 inline Grid(float horizontal
143 = B_USE_DEFAULT_SPACING,
144 float vertical = B_USE_DEFAULT_SPACING);
145 inline Grid(BWindow* window,
146 float horizontal = B_USE_DEFAULT_SPACING,
147 float vertical = B_USE_DEFAULT_SPACING);
148 inline Grid(BView* view,
149 float horizontal = B_USE_DEFAULT_SPACING,
150 float vertical = B_USE_DEFAULT_SPACING);
151 inline Grid(BGridLayout* layout);
152 inline Grid(BGridView* view);
154 inline BGridLayout* Layout() const;
155 inline BView* View() const;
156 inline ThisBuilder& GetLayout(BGridLayout** _layout);
157 inline ThisBuilder& GetView(BView** _view);
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);
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);
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);
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);
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);
215 inline ThisBuilder& AddGlue(int32 column, int32 row,
216 int32 columnCount = 1, int32 rowCount = 1);
218 inline ThisBuilder& SetHorizontalSpacing(float spacing);
219 inline ThisBuilder& SetVerticalSpacing(float spacing);
220 inline ThisBuilder& SetSpacing(float horizontal, float vertical);
222 inline ThisBuilder& SetColumnWeight(int32 column, float weight);
223 inline ThisBuilder& SetRowWeight(int32 row, float weight);
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);
230 inline ThisBuilder& SetExplicitMinSize(BSize size);
231 inline ThisBuilder& SetExplicitMaxSize(BSize size);
232 inline ThisBuilder& SetExplicitPreferredSize(BSize size);
233 inline ThisBuilder& SetExplicitAlignment(BAlignment alignment);
235 inline operator BGridLayout*();
237 private:
238 BGridLayout* fLayout;
242 template<typename ParentBuilder>
243 class Split : public Base<ParentBuilder> {
244 public:
245 typedef Split<ParentBuilder> ThisBuilder;
246 typedef Group<ThisBuilder> GroupBuilder;
247 typedef Grid<ThisBuilder> GridBuilder;
248 typedef Split<ThisBuilder> SplitBuilder;
249 typedef Cards<ThisBuilder> CardBuilder;
251 public:
252 inline Split(orientation orientation = B_HORIZONTAL,
253 float spacing = B_USE_DEFAULT_SPACING);
254 inline Split(BSplitView* view);
256 inline BSplitView* View() const;
257 inline ThisBuilder& GetView(BView** _view);
258 inline ThisBuilder& GetSplitView(BSplitView** _view);
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);
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);
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);
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);
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);
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);
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);
304 inline operator BSplitView*();
306 private:
307 BSplitView* fView;
310 template<typename ParentBuilder>
311 class Cards : public Base<ParentBuilder> {
312 public:
313 typedef Cards<ParentBuilder> ThisBuilder;
314 typedef Group<ThisBuilder> GroupBuilder;
315 typedef Grid<ThisBuilder> GridBuilder;
316 typedef Split<ThisBuilder> SplitBuilder;
317 typedef Cards<ThisBuilder> CardBuilder;
319 public:
320 inline Cards();
321 inline Cards(BWindow* window);
322 inline Cards(BView* view);
323 inline Cards(BCardLayout* layout);
324 inline Cards(BCardView* view);
326 inline BCardLayout* Layout() const;
327 inline BView* View() const;
328 inline ThisBuilder& GetLayout(BCardLayout** _layout);
329 inline ThisBuilder& GetView(BView** _view);
331 inline ThisBuilder& Add(BView* view);
332 inline ThisBuilder& Add(BLayoutItem* item);
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);
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);
345 inline SplitBuilder AddSplit(orientation orientation,
346 float spacing = B_USE_DEFAULT_SPACING);
347 inline SplitBuilder AddSplit(BSplitView* splitView);
349 inline CardBuilder AddCards();
350 inline CardBuilder AddCards(BCardLayout* cardLayout);
351 inline CardBuilder AddCards(BCardView* cardView);
353 inline ThisBuilder& SetExplicitMinSize(BSize size);
354 inline ThisBuilder& SetExplicitMaxSize(BSize size);
355 inline ThisBuilder& SetExplicitPreferredSize(BSize size);
356 inline ThisBuilder& SetExplicitAlignment(BAlignment alignment);
358 inline ThisBuilder& SetVisibleItem(int32 index);
360 inline operator BCardLayout*();
362 private:
363 BCardLayout* fLayout;
367 template<typename ParentBuilder>
368 class Menu : public Base<ParentBuilder> {
369 public:
370 typedef Menu<ParentBuilder> ThisBuilder;
371 typedef MenuItem<ParentBuilder> ItemBuilder;
372 typedef Menu<ThisBuilder> MenuBuilder;
374 public:
375 inline Menu(BMenu* menu);
377 inline ThisBuilder& GetMenu(BMenu*& _menu);
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);
386 inline MenuBuilder AddMenu(BMenu* menu);
387 inline MenuBuilder AddMenu(const char* title,
388 menu_layout layout = B_ITEMS_IN_COLUMN);
390 inline ThisBuilder& AddSeparator();
392 private:
393 BMenu* fMenu;
397 template<typename ParentBuilder>
398 class MenuItem : public Menu<ParentBuilder> {
399 public:
400 typedef MenuItem<ParentBuilder> ThisBuilder;
402 public:
403 inline MenuItem(ParentBuilder* parentBuilder,
404 BMenu* menu, BMenuItem* item);
406 inline ThisBuilder& GetItem(BMenuItem*& _item);
408 inline ThisBuilder& SetEnabled(bool enabled);
410 private:
411 BMenuItem* fMenuItem;
415 // #pragma mark - Base
418 template<typename ParentBuilder>
419 Base<ParentBuilder>::Base()
421 fParent(NULL)
426 template<typename ParentBuilder>
427 void
428 Base<ParentBuilder>::SetParent(ParentBuilder* parent)
430 fParent = parent;
434 template<typename ParentBuilder>
435 ParentBuilder&
436 Base<ParentBuilder>::End()
438 return *fParent;
442 // #pragma mark - Group
445 template<typename ParentBuilder>
446 Group<ParentBuilder>::Group(orientation orientation, float spacing)
448 fLayout((new BGroupView(orientation, spacing))->GroupLayout())
453 template<typename ParentBuilder>
454 Group<ParentBuilder>::Group(BWindow* window, orientation orientation,
455 float spacing)
457 fLayout(new BGroupLayout(orientation, spacing))
459 window->SetLayout(fLayout);
460 fLayout->Owner()->AdoptSystemColors();
464 template<typename ParentBuilder>
465 Group<ParentBuilder>::Group(BView* view, orientation orientation,
466 float spacing)
468 fLayout(new BGroupLayout(orientation, spacing))
471 if (view->HasDefaultColors())
472 view->AdoptSystemColors();
474 view->SetLayout(fLayout);
478 template<typename ParentBuilder>
479 Group<ParentBuilder>::Group(BGroupLayout* layout)
481 fLayout(layout)
486 template<typename ParentBuilder>
487 Group<ParentBuilder>::Group(BGroupView* view)
489 fLayout(view->GroupLayout())
494 template<typename ParentBuilder>
495 BGroupLayout*
496 Group<ParentBuilder>::Layout() const
498 return fLayout;
502 template<typename ParentBuilder>
503 BView*
504 Group<ParentBuilder>::View() const
506 return fLayout->Owner();
510 template<typename ParentBuilder>
511 typename Group<ParentBuilder>::ThisBuilder&
512 Group<ParentBuilder>::GetLayout(BGroupLayout** _layout)
514 *_layout = fLayout;
515 return *this;
519 template<typename ParentBuilder>
520 typename Group<ParentBuilder>::ThisBuilder&
521 Group<ParentBuilder>::GetView(BView** _view)
523 *_view = fLayout->Owner();
524 return *this;
528 template<typename ParentBuilder>
529 typename Group<ParentBuilder>::ThisBuilder&
530 Group<ParentBuilder>::Add(BView* view)
532 fLayout->AddView(view);
533 return *this;
537 template<typename ParentBuilder>
538 typename Group<ParentBuilder>::ThisBuilder&
539 Group<ParentBuilder>::Add(BView* view, float weight)
541 fLayout->AddView(view, weight);
542 return *this;
546 template<typename ParentBuilder>
547 typename Group<ParentBuilder>::ThisBuilder&
548 Group<ParentBuilder>::Add(BLayoutItem* item)
550 fLayout->AddItem(item);
551 return *this;
555 template<typename ParentBuilder>
556 typename Group<ParentBuilder>::ThisBuilder&
557 Group<ParentBuilder>::Add(BLayoutItem* item, float weight)
559 fLayout->AddItem(item, weight);
560 return *this;
564 template<typename ParentBuilder>
565 typename Group<ParentBuilder>::GroupBuilder
566 Group<ParentBuilder>::AddGroup(orientation orientation, float spacing,
567 float weight)
569 GroupBuilder builder(new BGroupLayout(orientation, spacing));
570 builder.SetParent(this);
571 fLayout->AddItem(builder.Layout(), weight);
572 return builder;
576 template<typename ParentBuilder>
577 typename Group<ParentBuilder>::GroupBuilder
578 Group<ParentBuilder>::AddGroup(BGroupView* groupView, float weight)
580 GroupBuilder builder(groupView);
581 builder.SetParent(this);
582 fLayout->AddItem(builder.Layout(), weight);
583 return builder;
587 template<typename ParentBuilder>
588 typename Group<ParentBuilder>::GroupBuilder
589 Group<ParentBuilder>::AddGroup(BGroupLayout* groupLayout, float weight)
591 GroupBuilder builder(groupLayout);
592 builder.SetParent(this);
593 fLayout->AddItem(builder.Layout(), weight);
594 return builder;
598 template<typename ParentBuilder>
599 typename Group<ParentBuilder>::GridBuilder
600 Group<ParentBuilder>::AddGrid(float horizontalSpacing,
601 float verticalSpacing, float weight)
603 GridBuilder builder(new BGridLayout(horizontalSpacing, verticalSpacing));
604 builder.SetParent(this);
605 fLayout->AddItem(builder.Layout(), weight);
606 return builder;
610 template<typename ParentBuilder>
611 typename Group<ParentBuilder>::GridBuilder
612 Group<ParentBuilder>::AddGrid(BGridLayout* gridLayout, float weight)
614 GridBuilder builder(gridLayout);
615 builder.SetParent(this);
616 fLayout->AddItem(builder.Layout(), weight);
617 return builder;
621 template<typename ParentBuilder>
622 typename Group<ParentBuilder>::GridBuilder
623 Group<ParentBuilder>::AddGrid(BGridView* gridView, float weight)
625 GridBuilder builder(gridView);
626 builder.SetParent(this);
627 fLayout->AddItem(builder.Layout(), weight);
628 return builder;
632 template<typename ParentBuilder>
633 typename Group<ParentBuilder>::SplitBuilder
634 Group<ParentBuilder>::AddSplit(orientation orientation, float spacing,
635 float weight)
637 SplitBuilder builder(orientation, spacing);
638 builder.SetParent(this);
639 fLayout->AddView(builder.View(), weight);
640 return builder;
644 template<typename ParentBuilder>
645 typename Group<ParentBuilder>::SplitBuilder
646 Group<ParentBuilder>::AddSplit(BSplitView* splitView, float weight)
648 SplitBuilder builder(splitView);
649 builder.SetParent(this);
650 fLayout->AddView(builder.View(), weight);
651 return builder;
655 template<typename ParentBuilder>
656 typename Group<ParentBuilder>::CardBuilder
657 Group<ParentBuilder>::AddCards(float weight)
659 CardBuilder builder;
660 builder.SetParent(this);
661 fLayout->AddView(builder.View(), weight);
662 return builder;
666 template<typename ParentBuilder>
667 typename Group<ParentBuilder>::CardBuilder
668 Group<ParentBuilder>::AddCards(BCardLayout* cardLayout, float weight)
670 CardBuilder builder(cardLayout);
671 builder.SetParent(this);
672 fLayout->AddView(builder.View(), weight);
673 return builder;
677 template<typename ParentBuilder>
678 typename Group<ParentBuilder>::CardBuilder
679 Group<ParentBuilder>::AddCards(BCardView* cardView, float weight)
681 CardBuilder builder(cardView);
682 builder.SetParent(this);
683 fLayout->AddView(builder.View(), weight);
684 return builder;
688 template<typename ParentBuilder>
689 typename Group<ParentBuilder>::ThisBuilder&
690 Group<ParentBuilder>::AddGlue(float weight)
692 fLayout->AddItem(BSpaceLayoutItem::CreateGlue(), weight);
693 return *this;
697 template<typename ParentBuilder>
698 typename Group<ParentBuilder>::ThisBuilder&
699 Group<ParentBuilder>::AddStrut(float size)
701 if (fLayout->Orientation() == B_HORIZONTAL)
702 fLayout->AddItem(BSpaceLayoutItem::CreateHorizontalStrut(size));
703 else
704 fLayout->AddItem(BSpaceLayoutItem::CreateVerticalStrut(size));
706 return *this;
710 template<typename ParentBuilder>
711 typename Group<ParentBuilder>::ThisBuilder&
712 Group<ParentBuilder>::SetInsets(float left, float top, float right,
713 float bottom)
715 fLayout->SetInsets(left, top, right, bottom);
716 return *this;
720 template<typename ParentBuilder>
721 typename Group<ParentBuilder>::ThisBuilder&
722 Group<ParentBuilder>::SetInsets(float horizontal, float vertical)
724 fLayout->SetInsets(horizontal, vertical);
725 return *this;
729 template<typename ParentBuilder>
730 typename Group<ParentBuilder>::ThisBuilder&
731 Group<ParentBuilder>::SetInsets(float insets)
733 fLayout->SetInsets(insets);
734 return *this;
738 template<typename ParentBuilder>
739 typename Group<ParentBuilder>::ThisBuilder&
740 Group<ParentBuilder>::SetExplicitMinSize(BSize size)
742 fLayout->SetExplicitMinSize(size);
743 return *this;
747 template<typename ParentBuilder>
748 typename Group<ParentBuilder>::ThisBuilder&
749 Group<ParentBuilder>::SetExplicitMaxSize(BSize size)
751 fLayout->SetExplicitMaxSize(size);
752 return *this;
756 template<typename ParentBuilder>
757 typename Group<ParentBuilder>::ThisBuilder&
758 Group<ParentBuilder>::SetExplicitPreferredSize(BSize size)
760 fLayout->SetExplicitPreferredSize(size);
761 return *this;
765 template<typename ParentBuilder>
766 typename Group<ParentBuilder>::ThisBuilder&
767 Group<ParentBuilder>::SetExplicitAlignment(BAlignment alignment)
769 fLayout->SetExplicitAlignment(alignment);
770 return *this;
774 template<typename ParentBuilder>
775 Group<ParentBuilder>::operator BGroupLayout*()
777 return fLayout;
781 // #pragma mark - Grid
784 template<typename ParentBuilder>
785 Grid<ParentBuilder>::Grid(float horizontalSpacing, float verticalSpacing)
787 fLayout((new BGridView(horizontalSpacing, verticalSpacing))->GridLayout())
792 template<typename ParentBuilder>
793 Grid<ParentBuilder>::Grid(BWindow* window, float horizontalSpacing,
794 float verticalSpacing)
796 fLayout(new BGridLayout(horizontalSpacing, verticalSpacing))
798 window->SetLayout(fLayout);
799 fLayout->Owner()->AdoptSystemColors();
803 template<typename ParentBuilder>
804 Grid<ParentBuilder>::Grid(BView* view, float horizontalSpacing,
805 float verticalSpacing)
807 fLayout(new BGridLayout(horizontalSpacing, verticalSpacing))
809 if (view->HasDefaultColors())
810 view->AdoptSystemColors();
812 view->SetLayout(fLayout);
816 template<typename ParentBuilder>
817 Grid<ParentBuilder>::Grid(BGridLayout* layout)
819 fLayout(layout)
824 template<typename ParentBuilder>
825 Grid<ParentBuilder>::Grid(BGridView* view)
827 fLayout(view->GridLayout())
832 template<typename ParentBuilder>
833 BGridLayout*
834 Grid<ParentBuilder>::Layout() const
836 return fLayout;
840 template<typename ParentBuilder>
841 BView*
842 Grid<ParentBuilder>::View() const
844 return fLayout->Owner();
848 template<typename ParentBuilder>
849 typename Grid<ParentBuilder>::ThisBuilder&
850 Grid<ParentBuilder>::GetLayout(BGridLayout** _layout)
852 *_layout = fLayout;
853 return *this;
857 template<typename ParentBuilder>
858 typename Grid<ParentBuilder>::ThisBuilder&
859 Grid<ParentBuilder>::GetView(BView** _view)
861 *_view = fLayout->Owner();
862 return *this;
866 template<typename ParentBuilder>
867 typename Grid<ParentBuilder>::ThisBuilder&
868 Grid<ParentBuilder>::Add(BView* view, int32 column, int32 row,
869 int32 columnCount, int32 rowCount)
871 fLayout->AddView(view, column, row, columnCount, rowCount);
872 return *this;
876 template<typename ParentBuilder>
877 typename Grid<ParentBuilder>::ThisBuilder&
878 Grid<ParentBuilder>::Add(BLayoutItem* item, int32 column, int32 row,
879 int32 columnCount, int32 rowCount)
881 fLayout->AddItem(item, column, row, columnCount, rowCount);
882 return *this;
886 template<typename ParentBuilder>
887 typename Grid<ParentBuilder>::ThisBuilder&
888 Grid<ParentBuilder>::AddMenuField(BMenuField* menuField, int32 column,
889 int32 row, alignment labelAlignment, int32 labelColumnCount,
890 int32 fieldColumnCount, int32 rowCount)
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;
902 template<typename ParentBuilder>
903 typename Grid<ParentBuilder>::ThisBuilder&
904 Grid<ParentBuilder>::AddTextControl(BTextControl* textControl, int32 column,
905 int32 row, alignment labelAlignment, int32 labelColumnCount,
906 int32 textColumnCount, int32 rowCount)
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;
918 template<typename ParentBuilder>
919 typename Grid<ParentBuilder>::GroupBuilder
920 Grid<ParentBuilder>::AddGroup(orientation orientation, float spacing,
921 int32 column, int32 row, int32 columnCount, int32 rowCount)
923 GroupBuilder builder(new BGroupLayout(orientation, spacing));
924 builder.SetParent(this);
925 fLayout->AddItem(builder.Layout(), column, row, columnCount, rowCount);
926 return builder;
930 template<typename ParentBuilder>
931 typename Grid<ParentBuilder>::GroupBuilder
932 Grid<ParentBuilder>::AddGroup(BGroupView* groupView, int32 column, int32 row,
933 int32 columnCount, int32 rowCount)
935 GroupBuilder builder(groupView);
936 builder.SetParent(this);
937 fLayout->AddItem(builder.Layout(), column, row, columnCount, rowCount);
938 return builder;
942 template<typename ParentBuilder>
943 typename Grid<ParentBuilder>::GroupBuilder
944 Grid<ParentBuilder>::AddGroup(BGroupLayout* groupLayout, int32 column,
945 int32 row, int32 columnCount, int32 rowCount)
947 GroupBuilder builder(groupLayout);
948 builder.SetParent(this);
949 fLayout->AddItem(builder.Layout(), column, row, columnCount, rowCount);
950 return builder;
954 template<typename ParentBuilder>
955 typename Grid<ParentBuilder>::GridBuilder
956 Grid<ParentBuilder>::AddGrid(float horizontalSpacing, float verticalSpacing,
957 int32 column, int32 row, int32 columnCount, int32 rowCount)
959 GridBuilder builder(new BGridLayout(horizontalSpacing, verticalSpacing));
960 builder.SetParent(this);
961 fLayout->AddItem(builder.Layout(), column, row, columnCount, rowCount);
962 return builder;
966 template<typename ParentBuilder>
967 typename Grid<ParentBuilder>::GridBuilder
968 Grid<ParentBuilder>::AddGrid(BGridView* gridView, int32 column, int32 row,
969 int32 columnCount, int32 rowCount)
971 GridBuilder builder(gridView);
972 builder.SetParent(this);
973 fLayout->AddView(builder.View(), column, row, columnCount, rowCount);
974 return builder;
978 template<typename ParentBuilder>
979 typename Grid<ParentBuilder>::SplitBuilder
980 Grid<ParentBuilder>::AddSplit(orientation orientation, float spacing,
981 int32 column, int32 row, int32 columnCount, int32 rowCount)
983 SplitBuilder builder(orientation, spacing);
984 builder.SetParent(this);
985 fLayout->AddView(builder.View(), column, row, columnCount, rowCount);
986 return builder;
990 template<typename ParentBuilder>
991 typename Grid<ParentBuilder>::SplitBuilder
992 Grid<ParentBuilder>::AddSplit(BSplitView* splitView, int32 column, int32 row,
993 int32 columnCount, int32 rowCount)
995 SplitBuilder builder(splitView);
996 builder.SetParent(this);
997 fLayout->AddView(builder.View(), column, row, columnCount, rowCount);
998 return builder;
1002 template<typename ParentBuilder>
1003 typename Grid<ParentBuilder>::CardBuilder
1004 Grid<ParentBuilder>::AddCards(int32 column, int32 row, int32 columnCount,
1005 int32 rowCount)
1007 CardBuilder builder;
1008 builder.SetParent(this);
1009 fLayout->AddView(builder.View(), column, row, columnCount, rowCount);
1010 return builder;
1014 template<typename ParentBuilder>
1015 typename Grid<ParentBuilder>::CardBuilder
1016 Grid<ParentBuilder>::AddCards(BCardLayout* cardLayout, int32 column, int32 row,
1017 int32 columnCount, int32 rowCount)
1019 CardBuilder builder(cardLayout);
1020 builder.SetParent(this);
1021 fLayout->AddView(builder.View(), column, row, columnCount, rowCount);
1022 return builder;
1026 template<typename ParentBuilder>
1027 typename Grid<ParentBuilder>::CardBuilder
1028 Grid<ParentBuilder>::AddCards(BCardView* cardView, int32 column, int32 row,
1029 int32 columnCount, int32 rowCount)
1031 CardBuilder builder(cardView);
1032 builder.SetParent(this);
1033 fLayout->AddView(builder.View(), column, row, columnCount, rowCount);
1034 return builder;
1038 template<typename ParentBuilder>
1039 typename Grid<ParentBuilder>::ThisBuilder&
1040 Grid<ParentBuilder>::AddGlue(int32 column, int32 row, int32 columnCount,
1041 int32 rowCount)
1043 fLayout->AddItem(BSpaceLayoutItem::CreateGlue(), column, row, columnCount,
1044 rowCount);
1045 return *this;
1049 template<typename ParentBuilder>
1050 typename Grid<ParentBuilder>::ThisBuilder&
1051 Grid<ParentBuilder>::SetHorizontalSpacing(float spacing)
1053 fLayout->SetHorizontalSpacing(spacing);
1054 return *this;
1058 template<typename ParentBuilder>
1059 typename Grid<ParentBuilder>::ThisBuilder&
1060 Grid<ParentBuilder>::SetVerticalSpacing(float spacing)
1062 fLayout->SetVerticalSpacing(spacing);
1063 return *this;
1067 template<typename ParentBuilder>
1068 typename Grid<ParentBuilder>::ThisBuilder&
1069 Grid<ParentBuilder>::SetSpacing(float horizontal, float vertical)
1071 fLayout->SetSpacing(horizontal, vertical);
1072 return *this;
1076 template<typename ParentBuilder>
1077 typename Grid<ParentBuilder>::ThisBuilder&
1078 Grid<ParentBuilder>::SetColumnWeight(int32 column, float weight)
1080 fLayout->SetColumnWeight(column, weight);
1081 return *this;
1085 template<typename ParentBuilder>
1086 typename Grid<ParentBuilder>::ThisBuilder&
1087 Grid<ParentBuilder>::SetRowWeight(int32 row, float weight)
1089 fLayout->SetRowWeight(row, weight);
1090 return *this;
1094 template<typename ParentBuilder>
1095 typename Grid<ParentBuilder>::ThisBuilder&
1096 Grid<ParentBuilder>::SetInsets(float left, float top, float right,
1097 float bottom)
1099 fLayout->SetInsets(left, top, right, bottom);
1100 return *this;
1104 template<typename ParentBuilder>
1105 typename Grid<ParentBuilder>::ThisBuilder&
1106 Grid<ParentBuilder>::SetInsets(float horizontal, float vertical)
1108 fLayout->SetInsets(horizontal, vertical);
1109 return *this;
1113 template<typename ParentBuilder>
1114 typename Grid<ParentBuilder>::ThisBuilder&
1115 Grid<ParentBuilder>::SetInsets(float insets)
1117 fLayout->SetInsets(insets);
1118 return *this;
1122 template<typename ParentBuilder>
1123 typename Grid<ParentBuilder>::ThisBuilder&
1124 Grid<ParentBuilder>::SetExplicitMinSize(BSize size)
1126 fLayout->SetExplicitMinSize(size);
1127 return *this;
1131 template<typename ParentBuilder>
1132 typename Grid<ParentBuilder>::ThisBuilder&
1133 Grid<ParentBuilder>::SetExplicitMaxSize(BSize size)
1135 fLayout->SetExplicitMaxSize(size);
1136 return *this;
1140 template<typename ParentBuilder>
1141 typename Grid<ParentBuilder>::ThisBuilder&
1142 Grid<ParentBuilder>::SetExplicitPreferredSize(BSize size)
1144 fLayout->SetExplicitPreferredSize(size);
1145 return *this;
1149 template<typename ParentBuilder>
1150 typename Grid<ParentBuilder>::ThisBuilder&
1151 Grid<ParentBuilder>::SetExplicitAlignment(BAlignment alignment)
1153 fLayout->SetExplicitAlignment(alignment);
1154 return *this;
1158 template<typename ParentBuilder>
1159 Grid<ParentBuilder>::operator BGridLayout*()
1161 return fLayout;
1165 // #pragma mark - Split
1168 template<typename ParentBuilder>
1169 Split<ParentBuilder>::Split(orientation orientation, float spacing)
1171 fView(new BSplitView(orientation, spacing))
1176 template<typename ParentBuilder>
1177 Split<ParentBuilder>::Split(BSplitView* view)
1179 fView(view)
1184 template<typename ParentBuilder>
1185 BSplitView*
1186 Split<ParentBuilder>::View() const
1188 return fView;
1192 template<typename ParentBuilder>
1193 typename Split<ParentBuilder>::ThisBuilder&
1194 Split<ParentBuilder>::GetView(BView** _view)
1196 *_view = fView;
1197 return *this;
1201 template<typename ParentBuilder>
1202 typename Split<ParentBuilder>::ThisBuilder&
1203 Split<ParentBuilder>::GetSplitView(BSplitView** _view)
1205 *_view = fView;
1206 return *this;
1210 template<typename ParentBuilder>
1211 typename Split<ParentBuilder>::ThisBuilder&
1212 Split<ParentBuilder>::Add(BView* view)
1214 fView->AddChild(view);
1215 return *this;
1219 template<typename ParentBuilder>
1220 typename Split<ParentBuilder>::ThisBuilder&
1221 Split<ParentBuilder>::Add(BView* view, float weight)
1223 fView->AddChild(view, weight);
1224 return *this;
1228 template<typename ParentBuilder>
1229 typename Split<ParentBuilder>::ThisBuilder&
1230 Split<ParentBuilder>::Add(BLayoutItem* item)
1232 fView->AddChild(item);
1233 return *this;
1237 template<typename ParentBuilder>
1238 typename Split<ParentBuilder>::ThisBuilder&
1239 Split<ParentBuilder>::Add(BLayoutItem* item, float weight)
1241 fView->AddChild(item, weight);
1242 return *this;
1246 template<typename ParentBuilder>
1247 typename Split<ParentBuilder>::GroupBuilder
1248 Split<ParentBuilder>::AddGroup(orientation orientation, float spacing,
1249 float weight)
1251 GroupBuilder builder(new BGroupLayout(orientation, spacing));
1252 builder.SetParent(this);
1253 fView->AddChild(builder.Layout(), weight);
1254 return builder;
1258 template<typename ParentBuilder>
1259 typename Split<ParentBuilder>::GroupBuilder
1260 Split<ParentBuilder>::AddGroup(BGroupView* groupView, float weight)
1262 GroupBuilder builder(groupView);
1263 builder.SetParent(this);
1264 fView->AddChild(builder.Layout(), weight);
1265 return builder;
1269 template<typename ParentBuilder>
1270 typename Split<ParentBuilder>::GroupBuilder
1271 Split<ParentBuilder>::AddGroup(BGroupLayout* groupLayout, float weight)
1273 GroupBuilder builder(groupLayout);
1274 builder.SetParent(this);
1275 fView->AddChild(builder.Layout(), weight);
1276 return builder;
1280 template<typename ParentBuilder>
1281 typename Split<ParentBuilder>::GridBuilder
1282 Split<ParentBuilder>::AddGrid(float horizontalSpacing, float verticalSpacing,
1283 float weight)
1285 GridBuilder builder(new BGridLayout(horizontalSpacing, verticalSpacing));
1286 builder.SetParent(this);
1287 fView->AddChild(builder.Layout(), weight);
1288 return builder;
1292 template<typename ParentBuilder>
1293 typename Split<ParentBuilder>::GridBuilder
1294 Split<ParentBuilder>::AddGrid(BGridView* gridView, float weight)
1296 GridBuilder builder(gridView);
1297 builder.SetParent(this);
1298 fView->AddChild(builder.Layout(), weight);
1299 return builder;
1303 template<typename ParentBuilder>
1304 typename Split<ParentBuilder>::GridBuilder
1305 Split<ParentBuilder>::AddGrid(BGridLayout* layout, float weight)
1307 GridBuilder builder(layout);
1308 builder.SetParent(this);
1309 fView->AddChild(builder.Layout(), weight);
1310 return builder;
1314 template<typename ParentBuilder>
1315 typename Split<ParentBuilder>::SplitBuilder
1316 Split<ParentBuilder>::AddSplit(orientation orientation, float spacing,
1317 float weight)
1319 SplitBuilder builder(orientation, spacing);
1320 builder.SetParent(this);
1321 fView->AddChild(builder.View(), weight);
1322 return builder;
1326 template<typename ParentBuilder>
1327 typename Split<ParentBuilder>::CardBuilder
1328 Split<ParentBuilder>::AddCards(float weight)
1330 CardBuilder builder;
1331 builder.SetParent(this);
1332 fView->AddChild(builder.View(), weight);
1333 return builder;
1337 template<typename ParentBuilder>
1338 typename Split<ParentBuilder>::CardBuilder
1339 Split<ParentBuilder>::AddCards(BCardLayout* cardLayout, float weight)
1341 CardBuilder builder(cardLayout);
1342 builder.SetParent(this);
1343 fView->AddChild(builder.View(), weight);
1344 return builder;
1348 template<typename ParentBuilder>
1349 typename Split<ParentBuilder>::CardBuilder
1350 Split<ParentBuilder>::AddCards(BCardView* cardView, float weight)
1352 CardBuilder builder(cardView);
1353 builder.SetParent(this);
1354 fView->AddChild(builder.View(), weight);
1355 return builder;
1359 template<typename ParentBuilder>
1360 typename Split<ParentBuilder>::ThisBuilder&
1361 Split<ParentBuilder>::SetCollapsible(bool collapsible)
1363 fView->SetCollapsible(collapsible);
1364 return *this;
1368 template<typename ParentBuilder>
1369 typename Split<ParentBuilder>::ThisBuilder&
1370 Split<ParentBuilder>::SetCollapsible(int32 index, bool collapsible)
1372 fView->SetCollapsible(index, collapsible);
1373 return *this;
1377 template<typename ParentBuilder>
1378 typename Split<ParentBuilder>::ThisBuilder&
1379 Split<ParentBuilder>::SetCollapsible(int32 first, int32 last, bool collapsible)
1381 fView->SetCollapsible(first, last, collapsible);
1382 return *this;
1386 template<typename ParentBuilder>
1387 typename Split<ParentBuilder>::ThisBuilder&
1388 Split<ParentBuilder>::SetInsets(float left, float top, float right,
1389 float bottom)
1391 fView->SetInsets(left, top, right, bottom);
1392 return *this;
1396 template<typename ParentBuilder>
1397 typename Split<ParentBuilder>::ThisBuilder&
1398 Split<ParentBuilder>::SetInsets(float horizontal, float vertical)
1400 fView->SetInsets(horizontal, vertical);
1401 return *this;
1405 template<typename ParentBuilder>
1406 typename Split<ParentBuilder>::ThisBuilder&
1407 Split<ParentBuilder>::SetInsets(float insets)
1409 fView->SetInsets(insets);
1410 return *this;
1414 template<typename ParentBuilder>
1415 Split<ParentBuilder>::operator BSplitView*()
1417 return fView;
1421 // #pragma mark - Cards
1424 template<typename ParentBuilder>
1425 Cards<ParentBuilder>::Cards()
1427 fLayout((new BCardView())->CardLayout())
1432 template<typename ParentBuilder>
1433 Cards<ParentBuilder>::Cards(BWindow* window)
1435 fLayout(new BCardLayout())
1437 window->SetLayout(fLayout);
1439 fLayout->Owner()->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
1443 template<typename ParentBuilder>
1444 Cards<ParentBuilder>::Cards(BView* view)
1446 fLayout(new BCardLayout())
1448 view->SetLayout(fLayout);
1449 view->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
1453 template<typename ParentBuilder>
1454 Cards<ParentBuilder>::Cards(BCardLayout* layout)
1456 fLayout(layout)
1461 template<typename ParentBuilder>
1462 Cards<ParentBuilder>::Cards(BCardView* view)
1464 fLayout(view->CardLayout())
1469 template<typename ParentBuilder>
1470 BCardLayout*
1471 Cards<ParentBuilder>::Layout() const
1473 return fLayout;
1477 template<typename ParentBuilder>
1478 BView*
1479 Cards<ParentBuilder>::View() const
1481 return fLayout->Owner();
1485 template<typename ParentBuilder>
1486 typename Cards<ParentBuilder>::ThisBuilder&
1487 Cards<ParentBuilder>::GetLayout(BCardLayout** _layout)
1489 *_layout = fLayout;
1490 return *this;
1494 template<typename ParentBuilder>
1495 typename Cards<ParentBuilder>::ThisBuilder&
1496 Cards<ParentBuilder>::GetView(BView** _view)
1498 *_view = fLayout->Owner();
1499 return *this;
1503 template<typename ParentBuilder>
1504 typename Cards<ParentBuilder>::ThisBuilder&
1505 Cards<ParentBuilder>::Add(BView* view)
1507 fLayout->AddView(view);
1508 return *this;
1512 template<typename ParentBuilder>
1513 typename Cards<ParentBuilder>::ThisBuilder&
1514 Cards<ParentBuilder>::Add(BLayoutItem* item)
1516 fLayout->AddItem(item);
1517 return *this;
1521 template<typename ParentBuilder>
1522 typename Cards<ParentBuilder>::GroupBuilder
1523 Cards<ParentBuilder>::AddGroup(orientation orientation, float spacing)
1525 GroupBuilder builder(new BGroupLayout(orientation, spacing));
1526 builder.SetParent(this);
1527 fLayout->AddItem(builder.Layout());
1528 return builder;
1532 template<typename ParentBuilder>
1533 typename Cards<ParentBuilder>::GroupBuilder
1534 Cards<ParentBuilder>::AddGroup(BGroupView* groupView)
1536 GroupBuilder builder(groupView);
1537 builder.SetParent(this);
1538 fLayout->AddItem(builder.Layout());
1539 return builder;
1543 template<typename ParentBuilder>
1544 typename Cards<ParentBuilder>::GroupBuilder
1545 Cards<ParentBuilder>::AddGroup(BGroupLayout* groupLayout)
1547 GroupBuilder builder(groupLayout);
1548 builder.SetParent(this);
1549 fLayout->AddItem(builder.Layout());
1550 return builder;
1554 template<typename ParentBuilder>
1555 typename Cards<ParentBuilder>::GridBuilder
1556 Cards<ParentBuilder>::AddGrid(float horizontal, float vertical)
1558 GridBuilder builder(horizontal, vertical);
1559 builder.SetParent(this);
1560 fLayout->AddItem(builder.Layout());
1561 return builder;
1565 template<typename ParentBuilder>
1566 typename Cards<ParentBuilder>::GridBuilder
1567 Cards<ParentBuilder>::AddGrid(BGridLayout* gridLayout)
1569 GridBuilder builder(gridLayout);
1570 builder.SetParent(this);
1571 fLayout->AddItem(builder.Layout());
1572 return builder;
1576 template<typename ParentBuilder>
1577 typename Cards<ParentBuilder>::GridBuilder
1578 Cards<ParentBuilder>::AddGrid(BGridView* gridView)
1580 GridBuilder builder(gridView);
1581 builder.SetParent(this);
1582 fLayout->AddItem(builder.Layout());
1583 return builder;
1587 template<typename ParentBuilder>
1588 typename Cards<ParentBuilder>::SplitBuilder
1589 Cards<ParentBuilder>::AddSplit(orientation orientation, float spacing)
1591 SplitBuilder builder(orientation, spacing);
1592 builder.SetParent(this);
1593 fLayout->AddView(builder.View());
1594 return builder;
1598 template<typename ParentBuilder>
1599 typename Cards<ParentBuilder>::SplitBuilder
1600 Cards<ParentBuilder>::AddSplit(BSplitView* splitView)
1602 SplitBuilder builder(splitView);
1603 builder.SetParent(this);
1604 fLayout->AddView(builder.View());
1605 return builder;
1609 template<typename ParentBuilder>
1610 typename Cards<ParentBuilder>::CardBuilder
1611 Cards<ParentBuilder>::AddCards()
1613 CardBuilder builder;
1614 builder.SetParent(this);
1615 fLayout->AddView(builder.View());
1616 return builder;
1620 template<typename ParentBuilder>
1621 typename Cards<ParentBuilder>::CardBuilder
1622 Cards<ParentBuilder>::AddCards(BCardLayout* cardLayout)
1624 CardBuilder builder(cardLayout);
1625 builder.SetParent(this);
1626 fLayout->AddView(builder.View());
1627 return builder;
1630 template<typename ParentBuilder>
1631 typename Cards<ParentBuilder>::CardBuilder
1632 Cards<ParentBuilder>::AddCards(BCardView* cardView)
1634 CardBuilder builder(cardView);
1635 builder.SetParent(this);
1636 fLayout->AddView(builder.View());
1637 return builder;
1641 template<typename ParentBuilder>
1642 typename Cards<ParentBuilder>::ThisBuilder&
1643 Cards<ParentBuilder>::SetExplicitMinSize(BSize size)
1645 fLayout->SetExplicitMinSize(size);
1646 return *this;
1650 template<typename ParentBuilder>
1651 typename Cards<ParentBuilder>::ThisBuilder&
1652 Cards<ParentBuilder>::SetExplicitMaxSize(BSize size)
1654 fLayout->SetExplicitMaxSize(size);
1655 return *this;
1659 template<typename ParentBuilder>
1660 typename Cards<ParentBuilder>::ThisBuilder&
1661 Cards<ParentBuilder>::SetExplicitPreferredSize(BSize size)
1663 fLayout->SetExplicitPreferredSize(size);
1664 return *this;
1668 template<typename ParentBuilder>
1669 typename Cards<ParentBuilder>::ThisBuilder&
1670 Cards<ParentBuilder>::SetExplicitAlignment(BAlignment alignment)
1672 fLayout->SetExplicitAlignment(alignment);
1673 return *this;
1677 template<typename ParentBuilder>
1678 typename Cards<ParentBuilder>::ThisBuilder&
1679 Cards<ParentBuilder>::SetVisibleItem(int32 item)
1681 fLayout->SetVisibleItem(item);
1682 return *this;
1686 template<typename ParentBuilder>
1687 Cards<ParentBuilder>::operator BCardLayout*()
1689 return fLayout;
1693 // #pragma mark - Menu
1696 template<typename ParentBuilder>
1697 Menu<ParentBuilder>::Menu(BMenu* menu)
1699 fMenu(menu)
1704 template<typename ParentBuilder>
1705 typename Menu<ParentBuilder>::ThisBuilder&
1706 Menu<ParentBuilder>::GetMenu(BMenu*& _menu)
1708 _menu = fMenu;
1709 return *this;
1713 template<typename ParentBuilder>
1714 typename Menu<ParentBuilder>::ItemBuilder
1715 Menu<ParentBuilder>::AddItem(BMenuItem* item)
1717 fMenu->AddItem(item);
1718 return MenuItem<ParentBuilder>(this->fParent, fMenu, item);
1722 template<typename ParentBuilder>
1723 typename Menu<ParentBuilder>::ItemBuilder
1724 Menu<ParentBuilder>::AddItem(BMenu* menu)
1726 if (!fMenu->AddItem(menu))
1727 throw std::bad_alloc();
1729 return MenuItem<ParentBuilder>(this->fParent, fMenu,
1730 fMenu->ItemAt(fMenu->CountItems() - 1));
1734 template<typename ParentBuilder>
1735 typename Menu<ParentBuilder>::ItemBuilder
1736 Menu<ParentBuilder>::AddItem(const char* label, BMessage* message,
1737 char shortcut, uint32 modifiers)
1739 BMenuItem* item = new BMenuItem(label, message, shortcut, modifiers);
1740 if (!fMenu->AddItem(item))
1741 delete item;
1743 return MenuItem<ParentBuilder>(this->fParent, fMenu, item);
1747 template<typename ParentBuilder>
1748 typename Menu<ParentBuilder>::ItemBuilder
1749 Menu<ParentBuilder>::AddItem(const char* label, uint32 messageWhat,
1750 char shortcut, uint32 modifiers)
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;
1761 if (!fMenu->AddItem(item))
1762 delete item;
1764 return MenuItem<ParentBuilder>(this->fParent, fMenu, item);
1768 template<typename ParentBuilder>
1769 typename Menu<ParentBuilder>::ThisBuilder&
1770 Menu<ParentBuilder>::AddSeparator()
1772 fMenu->AddSeparatorItem();
1773 return *this;
1777 template<typename ParentBuilder>
1778 typename Menu<ParentBuilder>::MenuBuilder
1779 Menu<ParentBuilder>::AddMenu(BMenu* menu)
1781 if (!fMenu->AddItem(menu))
1782 throw std::bad_alloc();
1784 MenuBuilder builder(menu);
1785 builder.SetParent(this);
1786 return builder;
1790 template<typename ParentBuilder>
1791 typename Menu<ParentBuilder>::MenuBuilder
1792 Menu<ParentBuilder>::AddMenu(const char* title, menu_layout layout)
1794 BMenu* menu = new BMenu(title, layout);
1795 if (!fMenu->AddItem(menu)) {
1796 delete menu;
1797 throw std::bad_alloc();
1800 MenuBuilder builder(menu);
1801 builder.SetParent(this);
1802 return builder;
1806 // #pragma mark - MenuItem
1809 template<typename ParentBuilder>
1810 MenuItem<ParentBuilder>::MenuItem(ParentBuilder* parentBuilder, BMenu* menu,
1811 BMenuItem* item)
1813 Menu<ParentBuilder>(menu),
1814 fMenuItem(item)
1816 this->SetParent(parentBuilder);
1820 template<typename ParentBuilder>
1821 typename MenuItem<ParentBuilder>::ThisBuilder&
1822 MenuItem<ParentBuilder>::GetItem(BMenuItem*& _item)
1824 _item = fMenuItem;
1825 return *this;
1829 template<typename ParentBuilder>
1830 typename MenuItem<ParentBuilder>::ThisBuilder&
1831 MenuItem<ParentBuilder>::SetEnabled(bool enabled)
1833 fMenuItem->SetEnabled(enabled);
1834 return *this;
1838 } // namespace BLayoutBuilder
1841 #endif // _LAYOUT_BUILDER_H