diff --git a/headers/libs/alm/ALMLayout.h b/headers/libs/alm/ALMLayout.h index 140e67de64..9447e1cfc5 100644 --- a/headers/libs/alm/ALMLayout.h +++ b/headers/libs/alm/ALMLayout.h @@ -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 @@ public: 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 @@ public: 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, diff --git a/headers/libs/alm/Area.h b/headers/libs/alm/Area.h index dd99241940..8c431ef91a 100644 --- a/headers/libs/alm/Area.h +++ b/headers/libs/alm/Area.h @@ -15,8 +15,7 @@ #include "Column.h" #include "LinearSpec.h" #include "Row.h" -#include "XTab.h" -#include "YTab.h" +#include "Tab.h" class Constraint; diff --git a/headers/libs/alm/XTab.h b/headers/libs/alm/Tab.h similarity index 55% rename from headers/libs/alm/XTab.h rename to headers/libs/alm/Tab.h index 7dd708c790..3c79cb1be1 100644 --- a/headers/libs/alm/XTab.h +++ b/headers/libs/alm/Tab.h @@ -18,25 +18,37 @@ namespace BALM { */ class XTab : public Variable { protected: - XTab(LinearSpec* ls); - -protected: - /** - * Property signifying if there is a constraint which relates - * this tab to a different tab that is further to the left. - * Only used for reverse engineering. - */ - bool fLeftLink; + XTab(LinearSpec* ls) + : + Variable(ls) + { + + } public: - friend class Area; - friend class Column; - friend class BALMLayout; - + 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 diff --git a/headers/libs/alm/YTab.h b/headers/libs/alm/YTab.h deleted file mode 100644 index 25f76f02c0..0000000000 --- a/headers/libs/alm/YTab.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2006 - 2010, Haiku, Inc. All rights reserved. - * Distributed under the terms of the MIT License. - */ -#ifndef Y_TAB_H -#define Y_TAB_H - - -#include "LinearSpec.h" -#include "Variable.h" - - -namespace BALM { - - -/** - * Horizontal grid line (y-tab). - */ -class YTab : public Variable { -protected: - YTab(LinearSpec* ls); - -protected: - /** - * Property signifying if there is a constraint which relates - * this tab to a different tab that is further to the top. - * Only used for reverse engineering. - */ - bool fTopLink; - -public: - friend class Area; - friend class Row; - friend class BALMLayout; - -}; - -} // namespace BALM - -using BALM::YTab; - -#endif // Y_TAB_H diff --git a/src/libs/alm/ALMLayout.cpp b/src/libs/alm/ALMLayout.cpp index 14186ae66e..302869b395 100644 --- a/src/libs/alm/ALMLayout.cpp +++ b/src/libs/alm/ALMLayout.cpp @@ -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 @@ BALMLayout::SetCurrentArea(const BLayoutItem* item) } +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 @@ BALMLayout::AddItem(int32 index, BLayoutItem* item) // 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 @@ BALMLayout::AddItem(int32 index, BLayoutItem* item) 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 @@ Area* 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); diff --git a/src/libs/alm/Column.cpp b/src/libs/alm/Column.cpp index 54d366a9a9..83481b56c3 100644 --- a/src/libs/alm/Column.cpp +++ b/src/libs/alm/Column.cpp @@ -9,7 +9,7 @@ #include "ALMLayout.h" #include "OperatorType.h" -#include "XTab.h" +#include "Tab.h" #include diff --git a/src/libs/alm/Jamfile b/src/libs/alm/Jamfile index 594cc8f750..f1d4d0334a 100644 --- a/src/libs/alm/Jamfile +++ b/src/libs/alm/Jamfile @@ -12,8 +12,6 @@ SharedLibrary libalm.so : Column.cpp ALMLayout.cpp Row.cpp - XTab.cpp - YTab.cpp : be liblpsolve55.so liblinprog.so $(TARGET_LIBSUPC++) ; diff --git a/src/libs/alm/Row.cpp b/src/libs/alm/Row.cpp index 966e20f02a..7ed517568e 100644 --- a/src/libs/alm/Row.cpp +++ b/src/libs/alm/Row.cpp @@ -9,7 +9,7 @@ #include "ALMLayout.h" #include "OperatorType.h" -#include "YTab.h" +#include "Tab.h" #include diff --git a/src/libs/alm/XTab.cpp b/src/libs/alm/XTab.cpp deleted file mode 100644 index c2e55cfc4e..0000000000 --- a/src/libs/alm/XTab.cpp +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright 2007-2008, Christof Lutteroth, lutteroth@cs.auckland.ac.nz - * Copyright 2007-2008, James Kim, jkim202@ec.auckland.ac.nz - * Distributed under the terms of the MIT License. - */ - - -#include "XTab.h" - - -/** - * Constructor. - */ -XTab::XTab(LinearSpec* ls) - : Variable(ls) -{ - fLeftLink = false; -} - diff --git a/src/libs/alm/YTab.cpp b/src/libs/alm/YTab.cpp deleted file mode 100644 index 23b67bf324..0000000000 --- a/src/libs/alm/YTab.cpp +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright 2007-2008, Christof Lutteroth, lutteroth@cs.auckland.ac.nz - * Copyright 2007-2008, James Kim, jkim202@ec.auckland.ac.nz - * Distributed under the terms of the MIT License. - */ - -#include "YTab.h" - - -/** - * Constructor. - */ -YTab::YTab(LinearSpec* ls) - : Variable(ls) -{ - fTopLink = false; -} - diff --git a/src/tests/libs/alm/Jamfile b/src/tests/libs/alm/Jamfile index 0576d8b683..77ca180dec 100644 --- a/src/tests/libs/alm/Jamfile +++ b/src/tests/libs/alm/Jamfile @@ -12,8 +12,8 @@ Application ALMHelloWorld : 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++) ; diff --git a/src/tests/libs/alm/TwoViews.cpp b/src/tests/libs/alm/TwoViews.cpp deleted file mode 100644 index e195cf063e..0000000000 --- a/src/tests/libs/alm/TwoViews.cpp +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2007-2008, Christof Lutteroth, lutteroth@cs.auckland.ac.nz - * Copyright 2007-2008, James Kim, jkim202@ec.auckland.ac.nz - * Copyright 2010, Clemens Zeidler - * Distributed under the terms of the MIT License. - */ - -#include -#include -#include -#include -#include - -#include "ALMLayout.h" - - -class TwoViewsWindow : public BWindow { -public: - TwoViewsWindow(BRect frame) - : - BWindow(frame, "ALM Two Views", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE) - { - button1 = new BButton("View 1"); - button1->SetExplicitMinSize(BSize(0, 0)); - button1->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED)); - - textView1 = new BTextView("textView1"); - textView1->SetText("View 2"); - - // create a new BALMLayout and use it for this window - BALMLayout* layout = new BALMLayout(); - SetLayout(layout); - - // create an extra tab - XTab* x1 = layout->AddXTab(); - - layout->AddView(button1, layout->Left(), layout->Top(), x1, - layout->Bottom()); - layout->AddView(textView1, x1, layout->Top(), layout->Right(), - layout->Bottom()); - - // add a constraint: 2*x1 == right - // i.e. x1 is in the middle of the layout - layout->Solver()->AddConstraint(2, x1, -1, layout->Right(), - OperatorType(EQ), 0); - } - -private: - BButton* button1; - BTextView* textView1; -}; - - -class TwoViews : public BApplication { -public: - TwoViews() - : - BApplication("application/x-vnd.haiku.TwoViews") - { - BRect frameRect; - frameRect.Set(100, 100, 300, 300); - TwoViewsWindow* window = new TwoViewsWindow(frameRect); - window->Show(); - } -}; - - -int -main() -{ - TwoViews app; - app.Run(); - return 0; -} - diff --git a/src/tests/libs/alm/Views.cpp b/src/tests/libs/alm/Views.cpp new file mode 100644 index 0000000000..29da0b1d62 --- /dev/null +++ b/src/tests/libs/alm/Views.cpp @@ -0,0 +1,113 @@ +/* + * Copyright 2007-2008, Christof Lutteroth, lutteroth@cs.auckland.ac.nz + * Copyright 2007-2008, James Kim, jkim202@ec.auckland.ac.nz + * Copyright 2010, Clemens Zeidler + * Distributed under the terms of the MIT License. + */ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#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; +} +