150cc24b3SAlex Wilson /*
250cc24b3SAlex Wilson * Copyright 2012, Haiku, Inc. All rights reserved.
350cc24b3SAlex Wilson * Distributed under the terms of the MIT License.
450cc24b3SAlex Wilson */
5f0307e76SAlex Wilson
6f0307e76SAlex Wilson
750cc24b3SAlex Wilson #include "ALMLayoutBuilder.h"
850cc24b3SAlex Wilson
950cc24b3SAlex Wilson
1050cc24b3SAlex Wilson #include <Window.h>
1150cc24b3SAlex Wilson
12a25ffa4fSAlex Wilson #include "Area.h"
13a25ffa4fSAlex Wilson
1450cc24b3SAlex Wilson
1550cc24b3SAlex Wilson namespace BALM {
1650cc24b3SAlex Wilson
1750cc24b3SAlex Wilson
BALMLayoutBuilder(BView * view,float hSpacing,float vSpacing,BALMLayout * friendLayout)1850cc24b3SAlex Wilson BALMLayoutBuilder::BALMLayoutBuilder(BView* view, float hSpacing,
1950cc24b3SAlex Wilson float vSpacing, BALMLayout* friendLayout)
2050cc24b3SAlex Wilson {
2150cc24b3SAlex Wilson fLayout = new BALMLayout(hSpacing, vSpacing, friendLayout);
2250cc24b3SAlex Wilson view->SetLayout(fLayout);
2350cc24b3SAlex Wilson }
2450cc24b3SAlex Wilson
2550cc24b3SAlex Wilson
BALMLayoutBuilder(BView * view,BALMLayout * layout)2650cc24b3SAlex Wilson BALMLayoutBuilder::BALMLayoutBuilder(BView* view, BALMLayout* layout)
2750cc24b3SAlex Wilson {
2850cc24b3SAlex Wilson fLayout = layout;
2950cc24b3SAlex Wilson view->SetLayout(layout);
3050cc24b3SAlex Wilson }
3150cc24b3SAlex Wilson
3250cc24b3SAlex Wilson
BALMLayoutBuilder(BWindow * window,float hSpacing,float vSpacing,BALMLayout * friendLayout)3350cc24b3SAlex Wilson BALMLayoutBuilder::BALMLayoutBuilder(BWindow* window, float hSpacing,
3450cc24b3SAlex Wilson float vSpacing, BALMLayout* friendLayout)
3550cc24b3SAlex Wilson {
3650cc24b3SAlex Wilson fLayout = new BALMLayout(hSpacing, vSpacing, friendLayout);
3750cc24b3SAlex Wilson window->SetLayout(fLayout);
3850cc24b3SAlex Wilson
39*f696e88aSlooncraz fLayout->Owner()->SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
4050cc24b3SAlex Wilson // TODO: we get a white background if we don't do this
4150cc24b3SAlex Wilson }
4250cc24b3SAlex Wilson
4350cc24b3SAlex Wilson
BALMLayoutBuilder(BWindow * window,BALMLayout * layout)4450cc24b3SAlex Wilson BALMLayoutBuilder::BALMLayoutBuilder(BWindow* window, BALMLayout* layout)
4550cc24b3SAlex Wilson {
4650cc24b3SAlex Wilson fLayout = layout;
4750cc24b3SAlex Wilson window->SetLayout(fLayout);
4850cc24b3SAlex Wilson
49*f696e88aSlooncraz fLayout->Owner()->SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
5050cc24b3SAlex Wilson // TODO: we get a white background if we don't do this
5150cc24b3SAlex Wilson }
5250cc24b3SAlex Wilson
5350cc24b3SAlex Wilson
BALMLayoutBuilder(BALMLayout * layout)5450cc24b3SAlex Wilson BALMLayoutBuilder::BALMLayoutBuilder(BALMLayout* layout)
5550cc24b3SAlex Wilson {
5650cc24b3SAlex Wilson fLayout = layout;
5750cc24b3SAlex Wilson }
5850cc24b3SAlex Wilson
5950cc24b3SAlex Wilson
6050cc24b3SAlex Wilson BALMLayoutBuilder&
Add(BView * view,XTab * left,YTab * top,XTab * right,YTab * bottom)6150cc24b3SAlex Wilson BALMLayoutBuilder::Add(BView* view, XTab* left, YTab* top,
6250cc24b3SAlex Wilson XTab* right, YTab* bottom)
6350cc24b3SAlex Wilson {
645f4e71baSAlex Wilson Area* a = (fLayout->AddView(view, left, top, right, bottom));
655f4e71baSAlex Wilson _SetCurrentArea(a);
6650cc24b3SAlex Wilson return *this;
6750cc24b3SAlex Wilson }
6850cc24b3SAlex Wilson
6950cc24b3SAlex Wilson
7050cc24b3SAlex Wilson BALMLayoutBuilder&
Add(BView * view,Row * row,Column * column)7150cc24b3SAlex Wilson BALMLayoutBuilder::Add(BView* view, Row* row, Column* column)
7250cc24b3SAlex Wilson {
735f4e71baSAlex Wilson _SetCurrentArea(fLayout->AddView(view, row, column));
7450cc24b3SAlex Wilson return *this;
7550cc24b3SAlex Wilson }
7650cc24b3SAlex Wilson
7750cc24b3SAlex Wilson
7850cc24b3SAlex Wilson BALMLayoutBuilder&
Add(BLayoutItem * item,XTab * left,YTab * top,XTab * right,YTab * bottom)7950cc24b3SAlex Wilson BALMLayoutBuilder::Add(BLayoutItem* item, XTab* left, YTab* top,
8050cc24b3SAlex Wilson XTab* right, YTab* bottom)
8150cc24b3SAlex Wilson {
825f4e71baSAlex Wilson _SetCurrentArea(fLayout->AddItem(item, left, top, right, bottom));
8350cc24b3SAlex Wilson return *this;
8450cc24b3SAlex Wilson }
8550cc24b3SAlex Wilson
8650cc24b3SAlex Wilson
8750cc24b3SAlex Wilson BALMLayoutBuilder&
Add(BLayoutItem * item,Row * row,Column * column)8850cc24b3SAlex Wilson BALMLayoutBuilder::Add(BLayoutItem* item, Row* row, Column* column)
8950cc24b3SAlex Wilson {
9050cc24b3SAlex Wilson fLayout->AddItem(item, row, column);
9150cc24b3SAlex Wilson return *this;
9250cc24b3SAlex Wilson }
9350cc24b3SAlex Wilson
9450cc24b3SAlex Wilson
9550cc24b3SAlex Wilson
9650cc24b3SAlex Wilson BALMLayoutBuilder&
SetInsets(float insets)9750cc24b3SAlex Wilson BALMLayoutBuilder::SetInsets(float insets)
9850cc24b3SAlex Wilson {
9950cc24b3SAlex Wilson fLayout->SetInsets(insets);
10050cc24b3SAlex Wilson return *this;
10150cc24b3SAlex Wilson }
10250cc24b3SAlex Wilson
10350cc24b3SAlex Wilson
10450cc24b3SAlex Wilson BALMLayoutBuilder&
SetInsets(float horizontal,float vertical)10550cc24b3SAlex Wilson BALMLayoutBuilder::SetInsets(float horizontal, float vertical)
10650cc24b3SAlex Wilson {
10750cc24b3SAlex Wilson fLayout->SetInsets(horizontal, vertical);
10850cc24b3SAlex Wilson return *this;
10950cc24b3SAlex Wilson }
11050cc24b3SAlex Wilson
11150cc24b3SAlex Wilson
11250cc24b3SAlex Wilson BALMLayoutBuilder&
SetInsets(float left,float top,float right,float bottom)11350cc24b3SAlex Wilson BALMLayoutBuilder::SetInsets(float left, float top, float right,
11450cc24b3SAlex Wilson float bottom)
11550cc24b3SAlex Wilson {
11650cc24b3SAlex Wilson fLayout->SetInsets(left, top, right, bottom);
11750cc24b3SAlex Wilson return *this;
11850cc24b3SAlex Wilson }
11950cc24b3SAlex Wilson
12050cc24b3SAlex Wilson
12150cc24b3SAlex Wilson BALMLayoutBuilder&
SetSpacing(float horizontal,float vertical)12250cc24b3SAlex Wilson BALMLayoutBuilder::SetSpacing(float horizontal, float vertical)
12350cc24b3SAlex Wilson {
12450cc24b3SAlex Wilson fLayout->SetSpacing(horizontal, vertical);
12550cc24b3SAlex Wilson return *this;
12650cc24b3SAlex Wilson }
12750cc24b3SAlex Wilson
12850cc24b3SAlex Wilson
1295f4e71baSAlex Wilson BALMLayoutBuilder&
StartingAt(BView * view)13050cc24b3SAlex Wilson BALMLayoutBuilder::StartingAt(BView* view)
13150cc24b3SAlex Wilson {
1325f4e71baSAlex Wilson fAreaStack.MakeEmpty();
1335f4e71baSAlex Wilson fAreaStack.AddItem(fLayout->AreaFor(view));
13450cc24b3SAlex Wilson return *this;
13550cc24b3SAlex Wilson }
13650cc24b3SAlex Wilson
13750cc24b3SAlex Wilson
13850cc24b3SAlex Wilson BALMLayoutBuilder&
StartingAt(BLayoutItem * item)1395f4e71baSAlex Wilson BALMLayoutBuilder::StartingAt(BLayoutItem* item)
14050cc24b3SAlex Wilson {
1415f4e71baSAlex Wilson fAreaStack.MakeEmpty();
1425f4e71baSAlex Wilson fAreaStack.AddItem(fLayout->AreaFor(item));
1435f4e71baSAlex Wilson return *this;
14450cc24b3SAlex Wilson }
14550cc24b3SAlex Wilson
14650cc24b3SAlex Wilson
1475f4e71baSAlex Wilson BALMLayoutBuilder&
AddToLeft(BView * view,XTab * _left,YTab * top,YTab * bottom)1485f4e71baSAlex Wilson BALMLayoutBuilder::AddToLeft(BView* view, XTab* _left, YTab* top, YTab* bottom)
14950cc24b3SAlex Wilson {
1505f4e71baSAlex Wilson Area* currentArea = _CurrentArea();
1515f4e71baSAlex Wilson BReference<XTab> left = _left;
1525f4e71baSAlex Wilson if (_left == NULL)
1535f4e71baSAlex Wilson left = fLayout->AddXTab();
1545f4e71baSAlex Wilson XTab* right = currentArea->Left();
1555f4e71baSAlex Wilson if (!top)
1565f4e71baSAlex Wilson top = currentArea->Top();
1575f4e71baSAlex Wilson if (!bottom)
1585f4e71baSAlex Wilson bottom = currentArea->Bottom();
1595f4e71baSAlex Wilson
1605f4e71baSAlex Wilson return Add(view, left, top, right, bottom);
1615f4e71baSAlex Wilson }
1625f4e71baSAlex Wilson
1635f4e71baSAlex Wilson
1645f4e71baSAlex Wilson BALMLayoutBuilder&
AddToRight(BView * view,XTab * _right,YTab * top,YTab * bottom)1655f4e71baSAlex Wilson BALMLayoutBuilder::AddToRight(BView* view, XTab* _right, YTab* top,
1665f4e71baSAlex Wilson YTab* bottom)
1675f4e71baSAlex Wilson {
1685f4e71baSAlex Wilson Area* currentArea = _CurrentArea();
1695f4e71baSAlex Wilson XTab* left = currentArea->Right();
1705f4e71baSAlex Wilson BReference<XTab> right = _right;
1715f4e71baSAlex Wilson if (_right == NULL)
1725f4e71baSAlex Wilson right = fLayout->AddXTab();
1735f4e71baSAlex Wilson if (!top)
1745f4e71baSAlex Wilson top = currentArea->Top();
1755f4e71baSAlex Wilson if (!bottom)
1765f4e71baSAlex Wilson bottom = currentArea->Bottom();
1775f4e71baSAlex Wilson
1785f4e71baSAlex Wilson return Add(view, left, top, right, bottom);
1795f4e71baSAlex Wilson }
1805f4e71baSAlex Wilson
1815f4e71baSAlex Wilson
1825f4e71baSAlex Wilson BALMLayoutBuilder&
AddAbove(BView * view,YTab * _top,XTab * left,XTab * right)1835f4e71baSAlex Wilson BALMLayoutBuilder::AddAbove(BView* view, YTab* _top, XTab* left,
1845f4e71baSAlex Wilson XTab* right)
1855f4e71baSAlex Wilson {
1865f4e71baSAlex Wilson Area* currentArea = _CurrentArea();
1875f4e71baSAlex Wilson if (!left)
1885f4e71baSAlex Wilson left = currentArea->Left();
1895f4e71baSAlex Wilson if (!right)
1905f4e71baSAlex Wilson right = currentArea->Right();
1915f4e71baSAlex Wilson BReference<YTab> top = _top;
1925f4e71baSAlex Wilson if (_top == NULL)
1935f4e71baSAlex Wilson top = fLayout->AddYTab();
1945f4e71baSAlex Wilson YTab* bottom = currentArea->Top();
1955f4e71baSAlex Wilson
1965f4e71baSAlex Wilson return Add(view, left, top, right, bottom);
1975f4e71baSAlex Wilson }
1985f4e71baSAlex Wilson
1995f4e71baSAlex Wilson
2005f4e71baSAlex Wilson BALMLayoutBuilder&
AddBelow(BView * view,YTab * _bottom,XTab * left,XTab * right)2015f4e71baSAlex Wilson BALMLayoutBuilder::AddBelow(BView* view, YTab* _bottom, XTab* left,
2025f4e71baSAlex Wilson XTab* right)
2035f4e71baSAlex Wilson {
2045f4e71baSAlex Wilson Area* currentArea = _CurrentArea();
2055f4e71baSAlex Wilson if (!left)
2065f4e71baSAlex Wilson left = currentArea->Left();
2075f4e71baSAlex Wilson if (!right)
2085f4e71baSAlex Wilson right = currentArea->Right();
2095f4e71baSAlex Wilson YTab* top = currentArea->Bottom();
2105f4e71baSAlex Wilson BReference<YTab> bottom = _bottom;
2115f4e71baSAlex Wilson if (_bottom == NULL)
2125f4e71baSAlex Wilson bottom = fLayout->AddYTab();
2135f4e71baSAlex Wilson
2145f4e71baSAlex Wilson return Add(view, left, top, right, bottom);
2155f4e71baSAlex Wilson }
2165f4e71baSAlex Wilson
2175f4e71baSAlex Wilson
2185f4e71baSAlex Wilson BALMLayoutBuilder&
AddToLeft(BLayoutItem * item,XTab * _left,YTab * top,YTab * bottom)2195f4e71baSAlex Wilson BALMLayoutBuilder::AddToLeft(BLayoutItem* item, XTab* _left, YTab* top,
2205f4e71baSAlex Wilson YTab* bottom)
2215f4e71baSAlex Wilson {
2225f4e71baSAlex Wilson Area* currentArea = _CurrentArea();
2235f4e71baSAlex Wilson BReference<XTab> left = _left;
2245f4e71baSAlex Wilson if (_left == NULL)
2255f4e71baSAlex Wilson left = fLayout->AddXTab();
2265f4e71baSAlex Wilson XTab* right = currentArea->Left();
2275f4e71baSAlex Wilson if (!top)
2285f4e71baSAlex Wilson top = currentArea->Top();
2295f4e71baSAlex Wilson if (!bottom)
2305f4e71baSAlex Wilson bottom = currentArea->Bottom();
2315f4e71baSAlex Wilson
2325f4e71baSAlex Wilson return Add(item, left, top, right, bottom);
2335f4e71baSAlex Wilson }
2345f4e71baSAlex Wilson
2355f4e71baSAlex Wilson
2365f4e71baSAlex Wilson BALMLayoutBuilder&
AddToRight(BLayoutItem * item,XTab * _right,YTab * top,YTab * bottom)2375f4e71baSAlex Wilson BALMLayoutBuilder::AddToRight(BLayoutItem* item, XTab* _right, YTab* top,
2385f4e71baSAlex Wilson YTab* bottom)
2395f4e71baSAlex Wilson {
2405f4e71baSAlex Wilson Area* currentArea = _CurrentArea();
2415f4e71baSAlex Wilson XTab* left = currentArea->Right();
2425f4e71baSAlex Wilson BReference<XTab> right = _right;
2435f4e71baSAlex Wilson if (_right == NULL)
2445f4e71baSAlex Wilson right = fLayout->AddXTab();
2455f4e71baSAlex Wilson if (!top)
2465f4e71baSAlex Wilson top = currentArea->Top();
2475f4e71baSAlex Wilson if (!bottom)
2485f4e71baSAlex Wilson bottom = currentArea->Bottom();
2495f4e71baSAlex Wilson
2505f4e71baSAlex Wilson return Add(item, left, top, right, bottom);
2515f4e71baSAlex Wilson }
2525f4e71baSAlex Wilson
2535f4e71baSAlex Wilson
2545f4e71baSAlex Wilson BALMLayoutBuilder&
AddAbove(BLayoutItem * item,YTab * _top,XTab * left,XTab * right)2555f4e71baSAlex Wilson BALMLayoutBuilder::AddAbove(BLayoutItem* item, YTab* _top, XTab* left,
2565f4e71baSAlex Wilson XTab* right)
2575f4e71baSAlex Wilson {
2585f4e71baSAlex Wilson Area* currentArea = _CurrentArea();
2595f4e71baSAlex Wilson if (!left)
2605f4e71baSAlex Wilson left = currentArea->Left();
2615f4e71baSAlex Wilson if (!right)
2625f4e71baSAlex Wilson right = currentArea->Right();
2635f4e71baSAlex Wilson BReference<YTab> top = _top;
2645f4e71baSAlex Wilson if (_top == NULL)
2655f4e71baSAlex Wilson top = fLayout->AddYTab();
2665f4e71baSAlex Wilson YTab* bottom = currentArea->Top();
2675f4e71baSAlex Wilson
2685f4e71baSAlex Wilson return Add(item, left, top, right, bottom);
2695f4e71baSAlex Wilson }
2705f4e71baSAlex Wilson
2715f4e71baSAlex Wilson
2725f4e71baSAlex Wilson BALMLayoutBuilder&
AddBelow(BLayoutItem * item,YTab * _bottom,XTab * left,XTab * right)2735f4e71baSAlex Wilson BALMLayoutBuilder::AddBelow(BLayoutItem* item, YTab* _bottom, XTab* left,
2745f4e71baSAlex Wilson XTab* right)
2755f4e71baSAlex Wilson {
2765f4e71baSAlex Wilson Area* currentArea = _CurrentArea();
2775f4e71baSAlex Wilson if (!left)
2785f4e71baSAlex Wilson left = currentArea->Left();
2795f4e71baSAlex Wilson if (!right)
2805f4e71baSAlex Wilson right = currentArea->Right();
2815f4e71baSAlex Wilson YTab* top = currentArea->Bottom();
2825f4e71baSAlex Wilson BReference<YTab> bottom = _bottom;
2835f4e71baSAlex Wilson if (_bottom == NULL)
2845f4e71baSAlex Wilson bottom = fLayout->AddYTab();
2855f4e71baSAlex Wilson
2865f4e71baSAlex Wilson return Add(item, left, top, right, bottom);
2875f4e71baSAlex Wilson }
2885f4e71baSAlex Wilson
2895f4e71baSAlex Wilson
2905f4e71baSAlex Wilson BALMLayoutBuilder&
Push()2915f4e71baSAlex Wilson BALMLayoutBuilder::Push()
2925f4e71baSAlex Wilson {
2935f4e71baSAlex Wilson fAreaStack.AddItem(_CurrentArea());
2945f4e71baSAlex Wilson return *this;
2955f4e71baSAlex Wilson }
2965f4e71baSAlex Wilson
2975f4e71baSAlex Wilson
2985f4e71baSAlex Wilson BALMLayoutBuilder&
Pop()2995f4e71baSAlex Wilson BALMLayoutBuilder::Pop()
3005f4e71baSAlex Wilson {
3015f4e71baSAlex Wilson if (fAreaStack.CountItems() > 0)
3025f4e71baSAlex Wilson fAreaStack.RemoveItemAt(fAreaStack.CountItems() - 1);
3035f4e71baSAlex Wilson return *this;
3045f4e71baSAlex Wilson }
3055f4e71baSAlex Wilson
3065f4e71baSAlex Wilson
3075f4e71baSAlex Wilson void
_SetCurrentArea(Area * area)3085f4e71baSAlex Wilson BALMLayoutBuilder::_SetCurrentArea(Area* area)
3095f4e71baSAlex Wilson {
3105f4e71baSAlex Wilson if (fAreaStack.CountItems() > 0)
3115f4e71baSAlex Wilson fAreaStack.ReplaceItem(fAreaStack.CountItems() - 1, area);
3125f4e71baSAlex Wilson else
3135f4e71baSAlex Wilson fAreaStack.AddItem(area);
31450cc24b3SAlex Wilson }
31550cc24b3SAlex Wilson
31650cc24b3SAlex Wilson
31750cc24b3SAlex Wilson Area*
_CurrentArea() const3185f4e71baSAlex Wilson BALMLayoutBuilder::_CurrentArea() const
31950cc24b3SAlex Wilson {
3205f4e71baSAlex Wilson return fAreaStack.ItemAt(fAreaStack.CountItems() - 1);
32150cc24b3SAlex Wilson }
32250cc24b3SAlex Wilson
32350cc24b3SAlex Wilson
32450cc24b3SAlex Wilson };
325