diff --git a/src/tests/libs/alm/BadLayout.cpp b/src/tests/libs/alm/BadLayout.cpp new file mode 100644 index 0000000000..aed87429c1 --- /dev/null +++ b/src/tests/libs/alm/BadLayout.cpp @@ -0,0 +1,96 @@ +/* + * Copyright 2007-2008, Christof Lutteroth, lutteroth@cs.auckland.ac.nz + * Copyright 2007-2008, James Kim, jkim202@ec.auckland.ac.nz + * Copyright 2010, Clemens Zeidler + * Copyright 2012, Haiku, Inc. + * Distributed under the terms of the MIT License. + */ + +#include +#include +#include +#include + +#include + +// include this for ALM +#include "ALMLayout.h" + + +class BAlertPolicy : public BALMLayout::BadLayoutPolicy { + virtual bool OnBadLayout(BALMLayout* layout) + { + BAlert* alert = new BAlert("layout failure", "layout failed!", + "sure"); + alert->Go(); + return true; + } +}; + + +class BadLayoutWindow : public BWindow { +public: + BadLayoutWindow(BRect frame) + : + BWindow(frame, "ALM Bad Layout", B_TITLED_WINDOW, + B_QUIT_ON_WINDOW_CLOSE) + { + button1 = new BButton("Bad Layout!"); + + // 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 + fLayout->AddView(button1, fLayout->Left(), fLayout->Top(), + fLayout->Right(), fLayout->Bottom()); + button1->SetExplicitMinSize(BSize(50, 50)); + button1->SetExplicitMaxSize(BSize(500, 500)); + button1->SetExplicitAlignment(BAlignment(B_ALIGN_USE_FULL_WIDTH, + B_ALIGN_USE_FULL_HEIGHT)); + + + BButton* button2 = new BButton("can't fit!"); + fLayout->AddView(button2, fLayout->RightOf(button1), fLayout->Top(), + fLayout->Right(), fLayout->Bottom()); + button2->SetExplicitMinSize(BSize(50, 50)); + + fLayout->SetBadLayoutPolicy(new BAlertPolicy()); + // test size limits + BSize min = fLayout->MinSize(); + BSize max = fLayout->MaxSize(); + SetSizeLimits(min.Width(), max.Width(), min.Height(), max.Height()); + + printf("moving to standard BALMLayout BadLayoutPolicy\n"); + fLayout->SetBadLayoutPolicy(NULL); + } + +private: + BALMLayout* fLayout; + BButton* button1; +}; + + +class BadLayout : public BApplication { +public: + BadLayout() + : + BApplication("application/x-vnd.haiku.BadLayout") + { + BRect frameRect; + frameRect.Set(100, 100, 300, 300); + BadLayoutWindow* window = new BadLayoutWindow(frameRect); + window->Show(); + } +}; + + +int +main() +{ + BadLayout app; + app.Run(); + return 0; +} + diff --git a/src/tests/libs/alm/Jamfile b/src/tests/libs/alm/Jamfile index 68937e2bca..af90a7f670 100644 --- a/src/tests/libs/alm/Jamfile +++ b/src/tests/libs/alm/Jamfile @@ -51,3 +51,10 @@ Application ALMComplexButtons : : be libalm.so $(TARGET_LIBSTDC++) ; + + +Application ALMBadLayout : + BadLayout.cpp + : + be liblpsolve55.so libalm.so $(TARGET_LIBSTDC++) +;