Author: axeld Date: 2009-10-28 10:00:14 +0100 (Wed, 28 Oct 2009) New Revision: 33805 Changeset: http://dev.haiku-os.org/changeset/33805/haiku Added: haiku/trunk/src/tests/libs/alm/Areas.cpp haiku/trunk/src/tests/libs/alm/HelloWorld.cpp haiku/trunk/src/tests/libs/alm/Pinwheel.cpp haiku/trunk/src/tests/libs/alm/TableDemo.cpp haiku/trunk/src/tests/libs/alm/TwoViews.cpp Removed: haiku/trunk/src/tests/libs/alm/SimpleTest.cpp haiku/trunk/src/tests/libs/alm/TableTest.cpp haiku/trunk/src/tests/libs/alm/Test1.cpp haiku/trunk/src/tests/libs/alm/Test2.cpp Modified: haiku/trunk/headers/libs/alm/Area.h haiku/trunk/headers/libs/alm/BALMLayout.h haiku/trunk/src/libs/alm/Area.cpp haiku/trunk/src/libs/alm/BALMLayout.cpp haiku/trunk/src/tests/libs/alm/Jamfile Log: * Applied a patch by Christof Lutteroth that updates ALM, and brings new test apps. Modified: haiku/trunk/headers/libs/alm/Area.h =================================================================== --- haiku/trunk/headers/libs/alm/Area.h 2009-10-28 08:56:53 UTC (rev 33804) +++ haiku/trunk/headers/libs/alm/Area.h 2009-10-28 09:00:14 UTC (rev 33805) @@ -7,22 +7,23 @@ #ifndef AREA_H #define AREA_H -#include "Constraint.h" - #include <Alignment.h> #include <List.h> #include <Size.h> #include <SupportDefs.h> #include <View.h> +#include "XTab.h" +#include "YTab.h" +#include "Area.h" +#include "Row.h" +#include "Column.h" +#include "Constraint.h" + namespace BALM { -class Column; class BALMLayout; -class Row; -class XTab; -class YTab; /** * Rectangular area in the GUI, defined by a tab on each side. @@ -30,9 +31,6 @@ class Area { public: - bool AutoPrefContentSize() const; - void SetAutoPrefContentSize(bool value); - XTab* Left() const; void SetLeft(XTab* left); XTab* Right() const; @@ -57,18 +55,21 @@ void SetMinContentSize(BSize min); BSize MaxContentSize() const; void SetMaxContentSize(BSize max); - BSize PrefContentSize() const; - void SetPrefContentSize(BSize pref); - BSize ShrinkRigidity() const; - void SetShrinkRigidity(BSize shrink); - BSize ExpandRigidity() const; - void SetExpandRigidity(BSize expand); + BSize PreferredContentSize() const; + void SetPreferredContentSize(BSize preferred); double ContentAspectRatio() const; void SetContentAspectRatio(double ratio); + + BSize ShrinkPenalties() const; + void SetShrinkPenalties(BSize shrink); + BSize GrowPenalties() const; + void SetGrowPenalties(BSize grow); + BAlignment Alignment() const; void SetAlignment(BAlignment alignment); - void SetHAlignment(alignment horizontal); - void SetVAlignment(vertical_alignment vertical); + void SetHorizontalAlignment(alignment horizontal); + void SetVerticalAlignment(vertical_alignment vertical); + int32 LeftInset() const; void SetLeftInset(int32 left); int32 TopInset() const; @@ -77,12 +78,18 @@ void SetRightInset(int32 right); int32 BottomInset() const; void SetBottomInset(int32 bottom); - void SetDefaultPrefContentSize(); - //~ string ToString(); + void SetDefaultBehavior(); + bool AutoPreferredContentSize() const; + void SetAutoPreferredContentSize(bool value); + + BString* ToBString(); + const char* ToString(); + Constraint* HasSameWidthAs(Area* area); Constraint* HasSameHeightAs(Area* area); - BList* HasSameSizetAs(Area* area); + BList* HasSameSizeAs(Area* area); + ~Area(); protected: @@ -127,14 +134,14 @@ Constraint* fMaxContentWidth; Constraint* fMinContentHeight; Constraint* fMaxContentHeight; - BSize fPrefContentSize; - BSize fShrinkRigidity; - BSize fExpandRigidity; + BSize fPreferredContentSize; + BSize fShrinkPenalties; + BSize fGrowPenalties; double fContentAspectRatio; Constraint* fContentAspectRatioC; - bool fAutoPrefContentSize; - Constraint* fPrefContentWidth; - Constraint* fPrefContentHeight; + bool fAutoPreferredContentSize; + Constraint* fPreferredContentWidth; + Constraint* fPreferredContentHeight; Area* fChildArea; BAlignment fAlignment; int32 fLeftInset; @@ -147,7 +154,7 @@ Constraint* fBottomConstraint; public: - friend class BALMLayout; + friend class BALMLayout; }; Modified: haiku/trunk/headers/libs/alm/BALMLayout.h =================================================================== --- haiku/trunk/headers/libs/alm/BALMLayout.h 2009-10-28 08:56:53 UTC (rev 33804) +++ haiku/trunk/headers/libs/alm/BALMLayout.h 2009-10-28 09:00:14 UTC (rev 33805) @@ -15,16 +15,16 @@ #include <View.h> #include "LayoutStyleType.h" +#include "XTab.h" +#include "YTab.h" +#include "Area.h" +#include "Row.h" +#include "Column.h" +#include "Constraint.h" #include "LinearSpec.h" namespace BALM { - -class Area; -class Column; -class Row; -class XTab; -class YTab; /** * A GUI layout engine using the ALM. Modified: haiku/trunk/src/libs/alm/Area.cpp =================================================================== --- haiku/trunk/src/libs/alm/Area.cpp 2009-10-28 08:56:53 UTC (rev 33804) +++ haiku/trunk/src/libs/alm/Area.cpp 2009-10-28 09:00:14 UTC (rev 33805) @@ -34,9 +34,9 @@ * @return the auto preferred content size */ bool -Area::AutoPrefContentSize() const +Area::AutoPreferredContentSize() const { - return fAutoPrefContentSize; + return fAutoPreferredContentSize; } @@ -46,9 +46,9 @@ * @param value the auto preferred content size */ void -Area::SetAutoPrefContentSize(bool value) +Area::SetAutoPreferredContentSize(bool value) { - fAutoPrefContentSize = value; + fAutoPreferredContentSize = value; } @@ -360,38 +360,42 @@ * Gets Preferred size of the area's content. */ BSize -Area::PrefContentSize() const +Area::PreferredContentSize() const { - return (fChildArea == NULL) ? fPrefContentSize : fChildArea->fPrefContentSize; + return (fChildArea == NULL) ? fPreferredContentSize + : fChildArea->fPreferredContentSize; } /** * Sets Preferred size of the area's content. * May be different from the preferred size of the area. - * Manual changes of PrefContentSize are ignored unless autoPrefContentSize is set to false. + * Manual changes of PreferredContentSize are ignored unless + * autoPreferredContentSize is set to false. */ void -Area::SetPrefContentSize(BSize pref) +Area::SetPreferredContentSize(BSize preferred) { if (fChildArea == NULL) { - fPrefContentSize = pref; - if (fPrefContentWidth == NULL) { - fPrefContentWidth = fLS->AddConstraint(-1.0, fLeft, 1.0, fRight, OperatorType(EQ), - fPrefContentSize.Width(), fShrinkRigidity.Width(), - fExpandRigidity.Width()); - fConstraints->AddItem(fPrefContentWidth); + fPreferredContentSize = preferred; + if (fPreferredContentWidth == NULL) { + fPreferredContentWidth = fLS->AddConstraint( + -1.0, fLeft, 1.0, fRight, OperatorType(EQ), + fPreferredContentSize.Width(), fShrinkPenalties.Width(), + fGrowPenalties.Width()); + fConstraints->AddItem(fPreferredContentWidth); - fPrefContentHeight = fLS->AddConstraint(-1.0, fTop, 1.0, fBottom, OperatorType(EQ), - fPrefContentSize.Height(), fShrinkRigidity.Height(), - fExpandRigidity.Height()); - fConstraints->AddItem(fPrefContentHeight); + fPreferredContentHeight = fLS->AddConstraint( + -1.0, fTop, 1.0, fBottom, OperatorType(EQ), + fPreferredContentSize.Height(), fShrinkPenalties.Height(), + fGrowPenalties.Height()); + fConstraints->AddItem(fPreferredContentHeight); } else { - fPrefContentWidth->SetRightSide(pref.Width()); - fPrefContentHeight->SetRightSide(pref.Height()); + fPreferredContentWidth->SetRightSide(preferred.Width()); + fPreferredContentHeight->SetRightSide(preferred.Height()); } } else - fChildArea->SetPrefContentSize(pref); + fChildArea->SetPreferredContentSize(preferred); fLS->InvalidateLayout(); } @@ -401,47 +405,47 @@ * The bigger the less likely is such shrinking. */ BSize -Area::ShrinkRigidity() const +Area::ShrinkPenalties() const { - return (fChildArea == NULL) ? fShrinkRigidity : fChildArea->fShrinkRigidity; + return (fChildArea == NULL) ? fShrinkPenalties : fChildArea->fShrinkPenalties; } -void Area::SetShrinkRigidity(BSize shrink) { +void Area::SetShrinkPenalties(BSize shrink) { if (fChildArea == NULL) { - fShrinkRigidity = shrink; - if (fPrefContentWidth != NULL) { - fPrefContentWidth->SetPenaltyNeg(shrink.Width()); - fPrefContentHeight->SetPenaltyNeg(shrink.Height()); + fShrinkPenalties = shrink; + if (fPreferredContentWidth != NULL) { + fPreferredContentWidth->SetPenaltyNeg(shrink.Width()); + fPreferredContentHeight->SetPenaltyNeg(shrink.Height()); } } else - fChildArea->SetShrinkRigidity(shrink); + fChildArea->SetShrinkPenalties(shrink); fLS->InvalidateLayout(); } /** - * The reluctance with which the area's content expands over its preferred size. - * The bigger the less likely is such expansion. + * The reluctance with which the area's content grows over its preferred size. + * The bigger the less likely is such growth. */ BSize -Area::ExpandRigidity() const +Area::GrowPenalties() const { - return (fChildArea == NULL) ? fExpandRigidity : fChildArea->fExpandRigidity; + return (fChildArea == NULL) ? fGrowPenalties : fChildArea->fGrowPenalties; } void -Area::SetExpandRigidity(BSize expand) +Area::SetGrowPenalties(BSize grow) { if (fChildArea == NULL) { - fExpandRigidity = expand; - if (fPrefContentWidth != NULL) { - fPrefContentWidth->SetPenaltyPos(expand.Width()); - fPrefContentHeight->SetPenaltyPos(expand.Height()); + fGrowPenalties = grow; + if (fPreferredContentWidth != NULL) { + fPreferredContentWidth->SetPenaltyPos(grow.Width()); + fPreferredContentHeight->SetPenaltyPos(grow.Height()); } } else - fChildArea->SetExpandRigidity(expand); + fChildArea->SetGrowPenalties(grow); fLS->InvalidateLayout(); } @@ -506,7 +510,7 @@ /** * Sets horizontal alignment of the content in its area. */ -void Area::SetHAlignment(alignment horizontal) { +void Area::SetHorizontalAlignment(alignment horizontal) { fAlignment.SetHorizontal(horizontal); UpdateHorizontal(); fLS->InvalidateLayout(); @@ -517,7 +521,7 @@ * Sets vertical alignment of the content in its area. */ void -Area::SetVAlignment(vertical_alignment vertical) +Area::SetVerticalAlignment(vertical_alignment vertical) { fAlignment.SetVertical(vertical); UpdateVertical(); @@ -613,20 +617,20 @@ /** * Sets the preferred size according to the content's PreferredSize method, - * and the rigidities according to heuristics. + * and the penalties according to heuristics. */ void -Area::SetDefaultPrefContentSize() +Area::SetDefaultBehavior() { if (Content() == NULL) { - SetPrefContentSize(BSize(0, 0)); - SetShrinkRigidity(BSize(0, 0)); - SetExpandRigidity(BSize(0, 0)); + SetPreferredContentSize(BSize(0, 0)); + SetShrinkPenalties(BSize(0, 0)); + SetGrowPenalties(BSize(0, 0)); return; } - if (PrefContentSize() != Content()->PreferredSize()){ - SetPrefContentSize(Content()->PreferredSize()); + if (PreferredContentSize() != Content()->PreferredSize()){ + SetPreferredContentSize(Content()->PreferredSize()); fLS->InvalidateLayout(); } @@ -636,21 +640,44 @@ || dynamic_cast<BStringView*>(Content()) != NULL || dynamic_cast<BPictureButton*>(Content()) != NULL || dynamic_cast<BStatusBar*>(Content()) != NULL) { - //~ || Content is LinkLabel - //~ || Content is NumericUpDown) { - fShrinkRigidity = BSize(4, 4); - fExpandRigidity = BSize(3, 3); + fShrinkPenalties = BSize(4, 4); + fGrowPenalties = BSize(3, 3); } else { - fShrinkRigidity = BSize(2, 2); - fExpandRigidity = BSize(1, 1); + fShrinkPenalties = BSize(2, 2); + fGrowPenalties = BSize(1, 1); } } -//~ string Area::ToString() { - //~ return "Area(" + fLeft->ToString() + "," + fTop->ToString() + "," - //~ + fRight->ToString() + "," + fBottom->ToString() + ")"; -//~ } +BString* +Area::ToBString() +{ + BString* str = new BString(); + BString* leftStr = fLeft->ToBString(); + BString* topStr = fTop->ToBString(); + BString* rightStr = fRight->ToBString(); + BString* bottomStr = fBottom->ToBString(); + *str << "Area(" << *leftStr << ", " + << *topStr << ", " + << *rightStr << ", " + << *bottomStr << ")"; + delete leftStr; + delete topStr; + delete rightStr; + delete bottomStr; + return str; +} + + +const char* +Area::ToString() +{ + BString* str = new BString(); + char* result = (char*) malloc(str->Length() + 1); + str->CopyInto(result, 0, str->Length()); + delete str; + return result; +} /** @@ -690,7 +717,7 @@ * @return a list containing a same-width and same-height constraint */ BList* -Area::HasSameSizetAs(Area* area) +Area::HasSameSizeAs(Area* area) { BList* constraints = new BList(2); constraints->AddItem(this->HasSameWidthAs(area)); @@ -752,16 +779,16 @@ fMaxContentWidth = NULL; fMaxContentHeight = NULL; - fPrefContentSize = kUndefinedSize; - fShrinkRigidity = BSize(2, 2); - fExpandRigidity = BSize(1, 1); + fPreferredContentSize = kUndefinedSize; + fShrinkPenalties = BSize(2, 2); + fGrowPenalties = BSize(1, 1); fContentAspectRatio = 0; fContentAspectRatioC = NULL; - fAutoPrefContentSize = false; + fAutoPreferredContentSize = false; - fPrefContentWidth = NULL; - fPrefContentHeight = NULL; + fPreferredContentWidth = NULL; + fPreferredContentHeight = NULL; fChildArea = NULL; @@ -855,25 +882,29 @@ fChildArea->fMaxContentSize = fMaxContentSize; fChildArea->fMaxContentWidth = fMaxContentWidth; - fMaxContentWidth->SetLeftSide(-1.0, fChildArea->Left(), 1.0, fChildArea->Right()); + fMaxContentWidth->SetLeftSide( + -1.0, fChildArea->Left(), 1.0, fChildArea->Right()); fChildArea->fMaxContentHeight = fMaxContentHeight; - fMaxContentHeight->SetLeftSide(-1.0, fChildArea->Top(), 1.0, fChildArea->Bottom()); + fMaxContentHeight->SetLeftSide( + -1.0, fChildArea->Top(), 1.0, fChildArea->Bottom()); } // if there are preferred content size constraints on this area, // change them so that they refer to the tabs of the childArea // and copy the preferred content size settings to the childArea - if (fPrefContentHeight != NULL) { - fChildArea->fPrefContentSize = fPrefContentSize; - fChildArea->fShrinkRigidity = fShrinkRigidity; - fChildArea->fExpandRigidity = fExpandRigidity; + if (fPreferredContentHeight != NULL) { + fChildArea->fPreferredContentSize = fPreferredContentSize; + fChildArea->fShrinkPenalties = fShrinkPenalties; + fChildArea->fGrowPenalties = fGrowPenalties; - fChildArea->fPrefContentWidth = fPrefContentWidth; - fPrefContentWidth->SetLeftSide(-1.0, fChildArea->Left(), 1.0, fChildArea->Right()); + fChildArea->fPreferredContentWidth = fPreferredContentWidth; + fPreferredContentWidth->SetLeftSide( + -1.0, fChildArea->Left(), 1.0, fChildArea->Right()); - fChildArea->fPrefContentHeight = fPrefContentHeight; - fPrefContentHeight->SetLeftSide(-1.0, fChildArea->Top(), 1.0, fChildArea->Bottom()); + fChildArea->fPreferredContentHeight = fPreferredContentHeight; + fPreferredContentHeight->SetLeftSide( + -1.0, fChildArea->Top(), 1.0, fChildArea->Bottom()); } } Modified: haiku/trunk/src/libs/alm/BALMLayout.cpp =================================================================== --- haiku/trunk/src/libs/alm/BALMLayout.cpp 2009-10-28 08:56:53 UTC (rev 33804) +++ haiku/trunk/src/libs/alm/BALMLayout.cpp 2009-10-28 09:00:14 UTC (rev 33805) @@ -52,14 +52,14 @@ void BALMLayout::SolveLayout() { - // if autoPrefContentSize is set on an area, readjust its prefContentSize and - // rigidity settings + // if autoPreferredContentSize is set on an area, + // readjust its preferredContentSize and penalties settings int32 sizeAreas = fAreas->CountItems(); Area* currentArea; for (int32 i = 0; i < sizeAreas; i++) { currentArea = (Area*)fAreas->ItemAt(i); - if (currentArea->AutoPrefContentSize()) - currentArea->SetDefaultPrefContentSize(); + if (currentArea->AutoPreferredContentSize()) + currentArea->SetDefaultBehavior(); } // try to solve the layout until the result is OPTIMAL or INFEASIBLE, maximally @@ -229,8 +229,8 @@ if (content != NULL) View()->AddChild(content); Area* area = new Area(this, left, top, right, bottom, content, BSize(0, 0)); - area->SetDefaultPrefContentSize(); - area->SetAutoPrefContentSize(false); + area->SetDefaultBehavior(); + area->SetAutoPreferredContentSize(false); fAreas->AddItem(area); return area; } @@ -251,8 +251,8 @@ if (content != NULL) View()->AddChild(content); Area* area = new Area(this, row, column, content, BSize(0, 0)); - area->SetDefaultPrefContentSize(); - area->SetAutoPrefContentSize(false); + area->SetDefaultBehavior(); + area->SetAutoPreferredContentSize(false); fAreas->AddItem(area); return area; } Added: haiku/trunk/src/tests/libs/alm/Areas.cpp =================================================================== --- haiku/trunk/src/tests/libs/alm/Areas.cpp (rev 0) +++ haiku/trunk/src/tests/libs/alm/Areas.cpp 2009-10-28 09:00:14 UTC (rev 33805) @@ -0,0 +1,85 @@ +#include <Application.h> +#include <Button.h> +#include <List.h> +#include <Window.h> + +#include "BALMLayout.h" + + +class AreasWindow : public BWindow { +public: + AreasWindow(BRect frame) + : BWindow(frame, "ALM Areas", + B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE) + { + button1 = new BButton("1"); + button2 = new BButton("2"); + button3 = new BButton("3"); + button4 = new BButton("4"); + + // create a new BALMLayout and use it for this window + BALMLayout* layout = new BALMLayout(); + SetLayout(layout); + + // create extra tabs + YTab* y1 = layout->AddYTab(); + YTab* y2 = layout->AddYTab(); + YTab* y3 = layout->AddYTab(); + + Area* a1 = layout->AddArea( + layout->Left(), layout->Top(), + layout->Right(), y1, + button1); + a1->SetTopInset(10); + a1->SetLeftInset(10); + a1->SetRightInset(10); + + Area* a2 = layout->AddArea( + layout->Left(), y1, + layout->Right(), y2, + button2); + a2->SetHorizontalAlignment(B_ALIGN_LEFT); + + Area* a3 = layout->AddArea( + layout->Left(), y2, + layout->Right(), y3, + button3); + a3->SetHorizontalAlignment(B_ALIGN_HORIZONTAL_CENTER); + a3->HasSameHeightAs(a1); + + Area* a4 = layout->AddArea( + layout->Left(), y3, + layout->Right(), layout->Bottom(), + button4); + a4->SetHorizontalAlignment(B_ALIGN_RIGHT); + } + +private: + BButton* button1; + BButton* button2; + BButton* button3; + BButton* button4; +}; + + +class Areas : public BApplication { +public: + Areas() + : BApplication("application/x-vnd.haiku.Areas") + { + BRect frameRect; + frameRect.Set(100, 100, 300, 300); + AreasWindow* window = new AreasWindow(frameRect); + window->Show(); + } +}; + + +int +main() +{ + Areas app; + app.Run(); + return 0; +} + Added: haiku/trunk/src/tests/libs/alm/HelloWorld.cpp =================================================================== --- haiku/trunk/src/tests/libs/alm/HelloWorld.cpp (rev 0) +++ haiku/trunk/src/tests/libs/alm/HelloWorld.cpp 2009-10-28 09:00:14 UTC (rev 33805) @@ -0,0 +1,58 @@ +#include <Application.h> +#include <Button.h> +#include <List.h> +#include <Window.h> + +// include this for ALM +#include "XTab.h" +#include "YTab.h" +#include "Area.h" +#include "BALMLayout.h" + + +class HelloWorldWindow : public BWindow { +public: + HelloWorldWindow(BRect frame) + : BWindow(frame, "ALM Hello World", + B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE) + { + button1 = new BButton("Hello World!"); + + // create a new BALMLayout and use it for this window + fLayout = new BALMLayout(); + SetLayout(fLayout); + + // add an area containing the button + // use the borders of the layout as the borders for the area + Area* a = fLayout->AddArea( + fLayout->Left(), fLayout->Top(), + fLayout->Right(), fLayout->Bottom(), + button1); + } + +private: + BALMLayout* fLayout; + BButton* button1; +}; + + +class HelloWorld : public BApplication { +public: + HelloWorld() + : BApplication("application/x-vnd.haiku.HelloWorld") + { + BRect frameRect; + frameRect.Set(100, 100, 300, 300); + HelloWorldWindow* window = new HelloWorldWindow(frameRect); + window->Show(); + } +}; + + +int +main() +{ + HelloWorld app; + app.Run(); + return 0; +} Modified: haiku/trunk/src/tests/libs/alm/Jamfile =================================================================== --- haiku/trunk/src/tests/libs/alm/Jamfile 2009-10-28 08:56:53 UTC (rev 33804) +++ haiku/trunk/src/tests/libs/alm/Jamfile 2009-10-28 09:00:14 UTC (rev 33805) @@ -4,27 +4,33 @@ UseLibraryHeaders lp_solve linprog alm ; -Application ALMTableTest : - TableTest.cpp +Application ALMHelloWorld : + HelloWorld.cpp : be liblpsolve55.so liblinprog.so libalm.so $(TARGET_LIBSUPC++) ; -Application ALMTest1 : - Test1.cpp +Application ALMTwoViews : + TwoViews.cpp : be liblpsolve55.so be liblinprog.so libalm.so $(TARGET_LIBSUPC++) ; -Application ALMTest2 : - Test2.cpp +Application ALMPinwheel : + Pinwheel.cpp : be liblpsolve55.so be liblinprog.so libalm.so $(TARGET_LIBSUPC++) ; -Application ALMSimpleTest : - SimpleTest.cpp +Application ALMAreas : + Areas.cpp : be liblpsolve55.so be liblinprog.so libalm.so $(TARGET_LIBSUPC++) ; +Application ALMTableDemo : + TableDemo.cpp + : + be liblpsolve55.so be liblinprog.so libalm.so $(TARGET_LIBSUPC++) +; + Added: haiku/trunk/src/tests/libs/alm/Pinwheel.cpp =================================================================== --- haiku/trunk/src/tests/libs/alm/Pinwheel.cpp (rev 0) +++ haiku/trunk/src/tests/libs/alm/Pinwheel.cpp 2009-10-28 09:00:14 UTC (rev 33805) @@ -0,0 +1,90 @@ +#include <Application.h> +#include <Button.h> +#include <TextView.h> +#include <List.h> +#include <Window.h> + +// include this for ALM +#include "XTab.h" +#include "YTab.h" +#include "Area.h" +#include "BALMLayout.h" + + +class PinwheelWindow : public BWindow { +public: + PinwheelWindow(BRect frame) + : BWindow(frame, "ALM Pinwheel", + B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE) + { + button1 = new BButton("1"); + button2 = new BButton("2"); + button3 = new BButton("3"); + button4 = new BButton("4"); + textView1 = new BTextView("textView1"); + textView1->SetText("5"); + + // create a new BALMLayout and use it for this window + BALMLayout* layout = new BALMLayout(); + SetLayout(layout); + + // create extra tabs + XTab* x1 = layout->AddXTab(); + XTab* x2 = layout->AddXTab(); + YTab* y1 = layout->AddYTab(); + YTab* y2 = layout->AddYTab(); + + Area* a1 = layout->AddArea( + layout->Left(), layout->Top(), + x2, y1, + button1); + Area* a2 = layout->AddArea( + x2, layout->Top(), + layout->Right(), y2, + button2); + Area* a3 = layout->AddArea( + x1, y2, + layout->Right(), layout->Bottom(), + button3); + Area* a4 = layout->AddArea( + layout->Left(), y1, + x1, layout->Bottom(), + button4); + Area* a5 = layout->AddArea( + x1, y1, + x2, y2, + textView1); + + a1->HasSameSizeAs(a3); + } + +private: + BButton* button1; + BButton* button2; + BButton* button3; + BButton* button4; + BTextView* textView1; +}; + + +class Pinwheel : public BApplication { +public: + Pinwheel() + : BApplication("application/x-vnd.haiku.Pinwheel") + { + BRect frameRect; + frameRect.Set(100, 100, 300, 300); + PinwheelWindow* window = new PinwheelWindow(frameRect); + window->Show(); + } +}; + + +int +main() +{ + Pinwheel app; + app.Run(); + return 0; +} + Added: haiku/trunk/src/tests/libs/alm/TableDemo.cpp =================================================================== --- haiku/trunk/src/tests/libs/alm/TableDemo.cpp (rev 0) +++ haiku/trunk/src/tests/libs/alm/TableDemo.cpp 2009-10-28 09:00:14 UTC (rev 33805) @@ -0,0 +1,72 @@ +/* + * Copyright 2007-2008, Christof Lutteroth, lutteroth@xxxxxxxxxxxxxxxxx + * Copyright 2007-2008, James Kim, jkim202@xxxxxxxxxxxxxxxxx + * Distributed under the terms of the MIT License. + */ + +#include <Application.h> +#include <File.h> +#include <Button.h> +#include <Window.h> + +#include "BALMLayout.h" + + +class TableDemoWindow : public BWindow { +public: + TableDemoWindow(BRect frame) + : BWindow(frame, "ALM Table Demo", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE) + { + // create a new BALMLayout and use it for this window + BALMLayout* layout = new BALMLayout(); + SetLayout(layout); + + Column* c1 = layout->AddColumn(layout->Left(), layout->Right()); + Row* r1 = layout->AddRow(layout->Top(), NULL); + Row* r3 = layout->AddRow(NULL, layout->Bottom()); + r1->SetNext(r3); + Row* r2 = layout->AddRow(); + r2->InsertAfter(r1); + + BButton* b1 = new BButton("A1"); + Area* a1 = layout->AddArea(r1, c1, b1); + a1->SetHorizontalAlignment(B_ALIGN_LEFT); + a1->SetVerticalAlignment(B_ALIGN_TOP); + + BButton* b2 = new BButton("A2"); + Area* a2 = layout->AddArea(r2, c1, b2); + a2->SetHorizontalAlignment(B_ALIGN_HORIZONTAL_CENTER); + a2->SetVerticalAlignment(B_ALIGN_VERTICAL_CENTER); + + BButton* b3 = new BButton("A3"); + Area* a3 = layout->AddArea(r3, c1, b3); + a3->SetHorizontalAlignment(B_ALIGN_RIGHT); + a3->SetVerticalAlignment(B_ALIGN_BOTTOM); + + r2->HasSameHeightAs(r1); + r3->HasSameHeightAs(r1); + } +}; + + +class TableDemo : public BApplication { +public: + TableDemo() + : BApplication("application/x-vnd.haiku.table-demo") + { + BRect frameRect; + frameRect.Set(100, 100, 400, 400); + TableDemoWindow* window = new TableDemoWindow(frameRect); + window->Show(); + } +}; + + +int +main() +{ + TableDemo app; + app.Run(); + return 0; +} + Added: haiku/trunk/src/tests/libs/alm/TwoViews.cpp =================================================================== --- haiku/trunk/src/tests/libs/alm/TwoViews.cpp (rev 0) +++ haiku/trunk/src/tests/libs/alm/TwoViews.cpp 2009-10-28 09:00:14 UTC (rev 33805) @@ -0,0 +1,68 @@ +#include <Application.h> +#include <Button.h> +#include <TextView.h> +#include <List.h> +#include <Window.h> + +#include "BALMLayout.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"); + 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(); + + Area* a1 = layout->AddArea( + layout->Left(), layout->Top(), + x1, layout->Bottom(), + button1); + Area* a2 = layout->AddArea( + x1, layout->Top(), + layout->Right(), layout->Bottom(), + textView1); + + // add a constraint: 2*x1 == right + // i.e. x1 is in the middle of the layout + layout->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; +} +