Author: czeidler Date: 2010-09-30 03:32:48 +0200 (Thu, 30 Sep 2010) New Revision: 38860 Changeset: http://dev.haiku-os.org/changeset/38860 Added: haiku/trunk/headers/libs/alm/Tab.h haiku/trunk/src/tests/libs/alm/Views.cpp Removed: haiku/trunk/headers/libs/alm/XTab.h haiku/trunk/headers/libs/alm/YTab.h haiku/trunk/src/libs/alm/XTab.cpp haiku/trunk/src/libs/alm/YTab.cpp haiku/trunk/src/tests/libs/alm/TwoViews.cpp Modified: haiku/trunk/headers/libs/alm/ALMLayout.h haiku/trunk/headers/libs/alm/Area.h haiku/trunk/src/libs/alm/ALMLayout.cpp haiku/trunk/src/libs/alm/Column.cpp haiku/trunk/src/libs/alm/Jamfile haiku/trunk/src/libs/alm/Row.cpp haiku/trunk/src/tests/libs/alm/Jamfile Log: - Add helper functions to get the tabs of a view or a layout item. - AddView only require the top, left tabs now. - Remove the TwoViews test and replace it with a slightly more complex test. - Merge XTab and YTab files into one header file. Modified: haiku/trunk/headers/libs/alm/ALMLayout.h =================================================================== --- haiku/trunk/headers/libs/alm/ALMLayout.h 2010-09-30 00:37:52 UTC (rev 38859) +++ haiku/trunk/headers/libs/alm/ALMLayout.h 2010-09-30 01:32:48 UTC (rev 38860) @@ -17,8 +17,7 @@ #include "Column.h" #include "LinearSpec.h" #include "Row.h" -#include "XTab.h" -#include "YTab.h" +#include "Tab.h" namespace BALM { @@ -54,17 +53,26 @@ void SetSpacing(float spacing); float Spacing() const; - Area* AreaFor(const BView* control) const; + Area* AreaFor(const BView* view) const; Area* AreaFor(const BLayoutItem* item) const; Area* CurrentArea() const; void SetCurrentArea(const Area* area); - void SetCurrentArea(const BView* control); + void SetCurrentArea(const BView* view); void SetCurrentArea(const BLayoutItem* item); + XTab* LeftOf(const BView* view) const; + XTab* LeftOf(const BLayoutItem* item) const; + XTab* RightOf(const BView* view) const; + XTab* RightOf(const BLayoutItem* item) const; + YTab* TopOf(const BView* view) const; + YTab* TopOf(const BLayoutItem* item) const; + YTab* BottomOf(const BView* view) const; + YTab* BottomOf(const BLayoutItem* item) const; + virtual BLayoutItem* AddView(BView* child); virtual BLayoutItem* AddView(int32 index, BView* child); virtual Area* AddView(BView* view, XTab* left, YTab* top, - XTab* right, YTab* bottom); + XTab* right = NULL, YTab* bottom = NULL); virtual Area* AddView(BView* view, Row* row, Column* column); virtual Area* AddViewToRight(BView* view, XTab* right = NULL, YTab* top = NULL, YTab* bottom = NULL); @@ -79,7 +87,8 @@ virtual bool AddItem(BLayoutItem* item); virtual bool AddItem(int32 index, BLayoutItem* item); virtual Area* AddItem(BLayoutItem* item, XTab* left, - YTab* top, XTab* right, YTab* bottom); + YTab* top, XTab* right = NULL, + YTab* bottom = NULL); virtual Area* AddItem(BLayoutItem* item, Row* row, Column* column); virtual Area* AddItemToRight(BLayoutItem* item, Modified: haiku/trunk/headers/libs/alm/Area.h =================================================================== --- haiku/trunk/headers/libs/alm/Area.h 2010-09-30 00:37:52 UTC (rev 38859) +++ haiku/trunk/headers/libs/alm/Area.h 2010-09-30 01:32:48 UTC (rev 38860) @@ -15,8 +15,7 @@ #include "Column.h" #include "LinearSpec.h" #include "Row.h" -#include "XTab.h" -#include "YTab.h" +#include "Tab.h" class Constraint; Added: haiku/trunk/headers/libs/alm/Tab.h =================================================================== --- haiku/trunk/headers/libs/alm/Tab.h (rev 0) +++ haiku/trunk/headers/libs/alm/Tab.h 2010-09-30 01:32:48 UTC (rev 38860) @@ -0,0 +1,54 @@ +/* + * Copyright 2006 - 2010, Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef X_TAB_H +#define X_TAB_H + + +#include "LinearSpec.h" +#include "Variable.h" + + +namespace BALM { + + +/** + * Vertical grid line (x-tab). + */ +class XTab : public Variable { +protected: + XTab(LinearSpec* ls) + : + Variable(ls) + { + + } + +public: + friend class BALMLayout; + friend class Column; +}; + + +class YTab : public Variable { +protected: + YTab(LinearSpec* ls) + : + Variable(ls) + { + + } + +public: + friend class BALMLayout; + friend class Row; +}; + + +} // namespace BALM + +using BALM::XTab; +using BALM::YTab; + +#endif // X_TAB_H Modified: haiku/trunk/src/libs/alm/ALMLayout.cpp =================================================================== --- haiku/trunk/src/libs/alm/ALMLayout.cpp 2010-09-30 00:37:52 UTC (rev 38859) +++ haiku/trunk/src/libs/alm/ALMLayout.cpp 2010-09-30 01:32:48 UTC (rev 38860) @@ -13,12 +13,7 @@ #include "ViewLayoutItem.h" -#include "Area.h" -#include "Column.h" #include "ResultType.h" -#include "Row.h" -#include "XTab.h" -#include "YTab.h" const BSize kUnsetSize(B_SIZE_UNSET, B_SIZE_UNSET); @@ -197,6 +192,62 @@ } +XTab* +BALMLayout::LeftOf(const BView* view) const +{ + return AreaFor(view)->Left(); +} + + +XTab* +BALMLayout::LeftOf(const BLayoutItem* item) const +{ + return AreaFor(item)->Left(); +} + + +XTab* +BALMLayout::RightOf(const BView* view) const +{ + return AreaFor(view)->Right(); +} + + +XTab* +BALMLayout::RightOf(const BLayoutItem* item) const +{ + return AreaFor(item)->Right(); +} + + +YTab* +BALMLayout::TopOf(const BView* view) const +{ + return AreaFor(view)->Top(); +} + + +YTab* +BALMLayout::TopOf(const BLayoutItem* item) const +{ + return AreaFor(item)->Top(); +} + + +YTab* +BALMLayout::BottomOf(const BView* view) const +{ + return AreaFor(view)->Bottom(); +} + + +YTab* +BALMLayout::BottomOf(const BLayoutItem* item) const +{ + return AreaFor(item)->Bottom(); +} + + BLayoutItem* BALMLayout::AddView(BView* child) { @@ -325,8 +376,6 @@ // TODO maybe find a more elegant solution XTab* left = Left(); YTab* top = Top(); - XTab* right = AddXTab(); - YTab* bottom = AddYTab(); // check range if (index < 0 || index > CountItems()) @@ -341,7 +390,7 @@ top = area->Top(); } } - Area* area = AddItem(item, left, top, right, bottom); + Area* area = AddItem(item, left, top); return area ? true : false; } @@ -350,6 +399,11 @@ BALMLayout::AddItem(BLayoutItem* item, XTab* left, YTab* top, XTab* right, YTab* bottom) { + if (!right) + right = AddXTab(); + if (!bottom) + bottom = AddYTab(); + if (!BAbstractLayout::AddItem(-1, item)) return NULL; Area* area = AreaFor(item); Modified: haiku/trunk/src/libs/alm/Column.cpp =================================================================== --- haiku/trunk/src/libs/alm/Column.cpp 2010-09-30 00:37:52 UTC (rev 38859) +++ haiku/trunk/src/libs/alm/Column.cpp 2010-09-30 01:32:48 UTC (rev 38860) @@ -9,7 +9,7 @@ #include "ALMLayout.h" #include "OperatorType.h" -#include "XTab.h" +#include "Tab.h" #include <SupportDefs.h> Modified: haiku/trunk/src/libs/alm/Jamfile =================================================================== --- haiku/trunk/src/libs/alm/Jamfile 2010-09-30 00:37:52 UTC (rev 38859) +++ haiku/trunk/src/libs/alm/Jamfile 2010-09-30 01:32:48 UTC (rev 38860) @@ -12,8 +12,6 @@ Column.cpp ALMLayout.cpp Row.cpp - XTab.cpp - YTab.cpp : be liblpsolve55.so liblinprog.so $(TARGET_LIBSUPC++) ; Modified: haiku/trunk/src/libs/alm/Row.cpp =================================================================== --- haiku/trunk/src/libs/alm/Row.cpp 2010-09-30 00:37:52 UTC (rev 38859) +++ haiku/trunk/src/libs/alm/Row.cpp 2010-09-30 01:32:48 UTC (rev 38860) @@ -9,7 +9,7 @@ #include "ALMLayout.h" #include "OperatorType.h" -#include "YTab.h" +#include "Tab.h" #include <SupportDefs.h> Modified: haiku/trunk/src/tests/libs/alm/Jamfile =================================================================== --- haiku/trunk/src/tests/libs/alm/Jamfile 2010-09-30 00:37:52 UTC (rev 38859) +++ haiku/trunk/src/tests/libs/alm/Jamfile 2010-09-30 01:32:48 UTC (rev 38860) @@ -12,8 +12,8 @@ be liblpsolve55.so liblinprog.so libalm.so $(TARGET_LIBSUPC++) ; -Application ALMTwoViews : - TwoViews.cpp +Application ALMViews : + Views.cpp : be liblpsolve55.so be liblinprog.so libalm.so $(TARGET_LIBSUPC++) ; Added: haiku/trunk/src/tests/libs/alm/Views.cpp =================================================================== --- haiku/trunk/src/tests/libs/alm/Views.cpp (rev 0) +++ haiku/trunk/src/tests/libs/alm/Views.cpp 2010-09-30 01:32:48 UTC (rev 38860) @@ -0,0 +1,113 @@ +/* + * Copyright 2007-2008, Christof Lutteroth, lutteroth@xxxxxxxxxxxxxxxxx + * Copyright 2007-2008, James Kim, jkim202@xxxxxxxxxxxxxxxxx + * Copyright 2010, Clemens Zeidler <haiku@xxxxxxxxxxxxxxxxxx> + * Distributed under the terms of the MIT License. + */ + + +#include <Application.h> +#include <Button.h> +#include <MenuField.h> +#include <PopUpMenu.h> +#include <RadioButton.h> +#include <SpaceLayoutItem.h> +#include <StatusBar.h> +#include <StringView.h> +#include <TextView.h> +#include <Window.h> + +#include "ALMLayout.h" + + +class ViewsWindow : public BWindow { +public: + ViewsWindow(BRect frame) + : + BWindow(frame, "ALM Two Views", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE) + { + BButton* button1 = new BButton("BButton"); + BRadioButton* radioButton = new BRadioButton("BRadioButton", NULL); + BButton* button3 = new BButton("3"); + BButton* button4 = new BButton("4"); + button4->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, + B_ALIGN_VERTICAL_CENTER)); + BButton* button5 = new BButton("5"); + BButton* button6 = new BButton("6"); + BTextView* textView1 = new BTextView("textView1"); + textView1->SetText("BTextView"); + BStatusBar* statusBar = new BStatusBar("BStatusBar", "label", + "trailing label"); + statusBar->Update(50); + + BMenu* menu = new BMenu("Menu 1"); + BMenuField* menu1 = new BMenuField("MenuField 1", menu); + menu->AddItem(new BPopUpMenu("Menu 1")); + BStringView* stringView1 = new BStringView("string 1", "string 1"); + + menu = new BMenu("Menu 2 + long text"); + BMenuField* menu2 = new BMenuField("MenuField 2", menu); + menu->AddItem(new BPopUpMenu("Menu 2")); + BStringView* stringView2 = new BStringView("string 2", "string 2"); + + // create a new BALMLayout and use it for this window + BALMLayout* layout = new BALMLayout(10); + SetLayout(layout); + layout->SetInset(10.); + + layout->AddView(button1); + layout->AddViewToRight(radioButton); + layout->AddItemToRight(BSpaceLayoutItem::CreateGlue()); + Area* a3 = layout->AddViewToRight(button3); + layout->SetCurrentArea(radioButton); + layout->AddViewToBottom(textView1, NULL, NULL, a3->Right()); + layout->AddViewToBottom(button4); + layout->AddViewToRight(button5, layout->Right()); + layout->AddViewToBottom(button6); + + layout->AddView(menu1, layout->Left(), layout->BottomOf(button6)); + layout->AddViewToRight(stringView1); + layout->AddItemToRight(BSpaceLayoutItem::CreateGlue(), layout->Right()); + + layout->AddViewToBottom(statusBar, NULL, layout->Left(), + layout->Right()); + + layout->AddView(menu2, layout->Left(), layout->BottomOf(statusBar), + layout->RightOf(menu1), layout->Bottom()); + layout->AddViewToRight(stringView2); + layout->AddItemToRight(BSpaceLayoutItem::CreateGlue(), layout->Right()); + + layout->Solver()->AddConstraint(2, layout->TopOf(menu1), -1, + layout->Bottom(), OperatorType(EQ), 0); + + // test size limits + BSize min = layout->MinSize(); + BSize max = layout->MaxSize(); + SetSizeLimits(min.Width(), max.Width(), min.Height(), max.Height()); + } + +}; + + +class Views : public BApplication { +public: + Views() + : + BApplication("application/x-vnd.haiku.Views") + { + BRect frameRect; + frameRect.Set(100, 100, 300, 300); + ViewsWindow* window = new ViewsWindow(frameRect); + window->Show(); + } +}; + + +int +main() +{ + Views app; + app.Run(); + return 0; +} +