103adc8c7SAlex Wilson /*
203adc8c7SAlex Wilson * Copyright 2007-2008, Christof Lutteroth, lutteroth@cs.auckland.ac.nz
303adc8c7SAlex Wilson * Copyright 2007-2008, James Kim, jkim202@ec.auckland.ac.nz
403adc8c7SAlex Wilson * Copyright 2010, Clemens Zeidler <haiku@clemens-zeidler.de>
503adc8c7SAlex Wilson * Copyright 2012, Haiku, Inc.
603adc8c7SAlex Wilson * Distributed under the terms of the MIT License.
703adc8c7SAlex Wilson */
803adc8c7SAlex Wilson
903adc8c7SAlex Wilson #include <Alert.h>
1003adc8c7SAlex Wilson #include <Application.h>
1103adc8c7SAlex Wilson #include <Button.h>
1203adc8c7SAlex Wilson #include <Window.h>
1303adc8c7SAlex Wilson
1403adc8c7SAlex Wilson #include <stdio.h>
1503adc8c7SAlex Wilson
1603adc8c7SAlex Wilson // include this for ALM
1703adc8c7SAlex Wilson #include "ALMLayout.h"
1803adc8c7SAlex Wilson
1903adc8c7SAlex Wilson
2003adc8c7SAlex Wilson class BAlertPolicy : public BALMLayout::BadLayoutPolicy {
OnBadLayout(BALMLayout * layout,ResultType result,BLayoutContext * context)21*ac843625SAlex Wilson virtual bool OnBadLayout(BALMLayout* layout, ResultType result,
22*ac843625SAlex Wilson BLayoutContext* context)
2303adc8c7SAlex Wilson {
2403adc8c7SAlex Wilson BAlert* alert = new BAlert("layout failure", "layout failed!",
2503adc8c7SAlex Wilson "sure");
2603adc8c7SAlex Wilson alert->Go();
2703adc8c7SAlex Wilson return true;
2803adc8c7SAlex Wilson }
2903adc8c7SAlex Wilson };
3003adc8c7SAlex Wilson
3103adc8c7SAlex Wilson
3203adc8c7SAlex Wilson class BadLayoutWindow : public BWindow {
3303adc8c7SAlex Wilson public:
BadLayoutWindow(BRect frame)3403adc8c7SAlex Wilson BadLayoutWindow(BRect frame)
3503adc8c7SAlex Wilson :
3603adc8c7SAlex Wilson BWindow(frame, "ALM Bad Layout", B_TITLED_WINDOW,
3703adc8c7SAlex Wilson B_QUIT_ON_WINDOW_CLOSE)
3803adc8c7SAlex Wilson {
3903adc8c7SAlex Wilson button1 = new BButton("Bad Layout!");
4003adc8c7SAlex Wilson
4103adc8c7SAlex Wilson // create a new BALMLayout and use it for this window
4203adc8c7SAlex Wilson fLayout = new BALMLayout();
4303adc8c7SAlex Wilson SetLayout(fLayout);
4403adc8c7SAlex Wilson
4503adc8c7SAlex Wilson // add an area containing the button
4603adc8c7SAlex Wilson // use the borders of the layout as the borders for the area
4703adc8c7SAlex Wilson fLayout->AddView(button1, fLayout->Left(), fLayout->Top(),
4803adc8c7SAlex Wilson fLayout->Right(), fLayout->Bottom());
4903adc8c7SAlex Wilson button1->SetExplicitMinSize(BSize(50, 50));
5003adc8c7SAlex Wilson button1->SetExplicitMaxSize(BSize(500, 500));
5103adc8c7SAlex Wilson button1->SetExplicitAlignment(BAlignment(B_ALIGN_USE_FULL_WIDTH,
5203adc8c7SAlex Wilson B_ALIGN_USE_FULL_HEIGHT));
5303adc8c7SAlex Wilson
5403adc8c7SAlex Wilson
5503adc8c7SAlex Wilson BButton* button2 = new BButton("can't fit!");
5603adc8c7SAlex Wilson fLayout->AddView(button2, fLayout->RightOf(button1), fLayout->Top(),
5703adc8c7SAlex Wilson fLayout->Right(), fLayout->Bottom());
5803adc8c7SAlex Wilson button2->SetExplicitMinSize(BSize(50, 50));
5903adc8c7SAlex Wilson
6003adc8c7SAlex Wilson fLayout->SetBadLayoutPolicy(new BAlertPolicy());
6103adc8c7SAlex Wilson // test size limits
6203adc8c7SAlex Wilson BSize min = fLayout->MinSize();
6303adc8c7SAlex Wilson BSize max = fLayout->MaxSize();
6403adc8c7SAlex Wilson SetSizeLimits(min.Width(), max.Width(), min.Height(), max.Height());
6503adc8c7SAlex Wilson
6603adc8c7SAlex Wilson printf("moving to standard BALMLayout BadLayoutPolicy\n");
6703adc8c7SAlex Wilson fLayout->SetBadLayoutPolicy(NULL);
6803adc8c7SAlex Wilson }
6903adc8c7SAlex Wilson
7003adc8c7SAlex Wilson private:
7103adc8c7SAlex Wilson BALMLayout* fLayout;
7203adc8c7SAlex Wilson BButton* button1;
7303adc8c7SAlex Wilson };
7403adc8c7SAlex Wilson
7503adc8c7SAlex Wilson
7603adc8c7SAlex Wilson class BadLayout : public BApplication {
7703adc8c7SAlex Wilson public:
BadLayout()7803adc8c7SAlex Wilson BadLayout()
7903adc8c7SAlex Wilson :
8003adc8c7SAlex Wilson BApplication("application/x-vnd.haiku.BadLayout")
8103adc8c7SAlex Wilson {
8203adc8c7SAlex Wilson BRect frameRect;
8303adc8c7SAlex Wilson frameRect.Set(100, 100, 300, 300);
8403adc8c7SAlex Wilson BadLayoutWindow* window = new BadLayoutWindow(frameRect);
8503adc8c7SAlex Wilson window->Show();
8603adc8c7SAlex Wilson }
8703adc8c7SAlex Wilson };
8803adc8c7SAlex Wilson
8903adc8c7SAlex Wilson
9003adc8c7SAlex Wilson int
main()9103adc8c7SAlex Wilson main()
9203adc8c7SAlex Wilson {
9303adc8c7SAlex Wilson BadLayout app;
9403adc8c7SAlex Wilson app.Run();
9503adc8c7SAlex Wilson return 0;
9603adc8c7SAlex Wilson }
9703adc8c7SAlex Wilson
98