1*03adc8c7SAlex Wilson /* 2*03adc8c7SAlex Wilson * Copyright 2007-2008, Christof Lutteroth, lutteroth@cs.auckland.ac.nz 3*03adc8c7SAlex Wilson * Copyright 2007-2008, James Kim, jkim202@ec.auckland.ac.nz 4*03adc8c7SAlex Wilson * Copyright 2010, Clemens Zeidler <haiku@clemens-zeidler.de> 5*03adc8c7SAlex Wilson * Copyright 2012, Haiku, Inc. 6*03adc8c7SAlex Wilson * Distributed under the terms of the MIT License. 7*03adc8c7SAlex Wilson */ 8*03adc8c7SAlex Wilson 9*03adc8c7SAlex Wilson #include <Alert.h> 10*03adc8c7SAlex Wilson #include <Application.h> 11*03adc8c7SAlex Wilson #include <Button.h> 12*03adc8c7SAlex Wilson #include <Window.h> 13*03adc8c7SAlex Wilson 14*03adc8c7SAlex Wilson #include <stdio.h> 15*03adc8c7SAlex Wilson 16*03adc8c7SAlex Wilson // include this for ALM 17*03adc8c7SAlex Wilson #include "ALMLayout.h" 18*03adc8c7SAlex Wilson 19*03adc8c7SAlex Wilson 20*03adc8c7SAlex Wilson class BAlertPolicy : public BALMLayout::BadLayoutPolicy { 21*03adc8c7SAlex Wilson virtual bool OnBadLayout(BALMLayout* layout) 22*03adc8c7SAlex Wilson { 23*03adc8c7SAlex Wilson BAlert* alert = new BAlert("layout failure", "layout failed!", 24*03adc8c7SAlex Wilson "sure"); 25*03adc8c7SAlex Wilson alert->Go(); 26*03adc8c7SAlex Wilson return true; 27*03adc8c7SAlex Wilson } 28*03adc8c7SAlex Wilson }; 29*03adc8c7SAlex Wilson 30*03adc8c7SAlex Wilson 31*03adc8c7SAlex Wilson class BadLayoutWindow : public BWindow { 32*03adc8c7SAlex Wilson public: 33*03adc8c7SAlex Wilson BadLayoutWindow(BRect frame) 34*03adc8c7SAlex Wilson : 35*03adc8c7SAlex Wilson BWindow(frame, "ALM Bad Layout", B_TITLED_WINDOW, 36*03adc8c7SAlex Wilson B_QUIT_ON_WINDOW_CLOSE) 37*03adc8c7SAlex Wilson { 38*03adc8c7SAlex Wilson button1 = new BButton("Bad Layout!"); 39*03adc8c7SAlex Wilson 40*03adc8c7SAlex Wilson // create a new BALMLayout and use it for this window 41*03adc8c7SAlex Wilson fLayout = new BALMLayout(); 42*03adc8c7SAlex Wilson SetLayout(fLayout); 43*03adc8c7SAlex Wilson 44*03adc8c7SAlex Wilson // add an area containing the button 45*03adc8c7SAlex Wilson // use the borders of the layout as the borders for the area 46*03adc8c7SAlex Wilson fLayout->AddView(button1, fLayout->Left(), fLayout->Top(), 47*03adc8c7SAlex Wilson fLayout->Right(), fLayout->Bottom()); 48*03adc8c7SAlex Wilson button1->SetExplicitMinSize(BSize(50, 50)); 49*03adc8c7SAlex Wilson button1->SetExplicitMaxSize(BSize(500, 500)); 50*03adc8c7SAlex Wilson button1->SetExplicitAlignment(BAlignment(B_ALIGN_USE_FULL_WIDTH, 51*03adc8c7SAlex Wilson B_ALIGN_USE_FULL_HEIGHT)); 52*03adc8c7SAlex Wilson 53*03adc8c7SAlex Wilson 54*03adc8c7SAlex Wilson BButton* button2 = new BButton("can't fit!"); 55*03adc8c7SAlex Wilson fLayout->AddView(button2, fLayout->RightOf(button1), fLayout->Top(), 56*03adc8c7SAlex Wilson fLayout->Right(), fLayout->Bottom()); 57*03adc8c7SAlex Wilson button2->SetExplicitMinSize(BSize(50, 50)); 58*03adc8c7SAlex Wilson 59*03adc8c7SAlex Wilson fLayout->SetBadLayoutPolicy(new BAlertPolicy()); 60*03adc8c7SAlex Wilson // test size limits 61*03adc8c7SAlex Wilson BSize min = fLayout->MinSize(); 62*03adc8c7SAlex Wilson BSize max = fLayout->MaxSize(); 63*03adc8c7SAlex Wilson SetSizeLimits(min.Width(), max.Width(), min.Height(), max.Height()); 64*03adc8c7SAlex Wilson 65*03adc8c7SAlex Wilson printf("moving to standard BALMLayout BadLayoutPolicy\n"); 66*03adc8c7SAlex Wilson fLayout->SetBadLayoutPolicy(NULL); 67*03adc8c7SAlex Wilson } 68*03adc8c7SAlex Wilson 69*03adc8c7SAlex Wilson private: 70*03adc8c7SAlex Wilson BALMLayout* fLayout; 71*03adc8c7SAlex Wilson BButton* button1; 72*03adc8c7SAlex Wilson }; 73*03adc8c7SAlex Wilson 74*03adc8c7SAlex Wilson 75*03adc8c7SAlex Wilson class BadLayout : public BApplication { 76*03adc8c7SAlex Wilson public: 77*03adc8c7SAlex Wilson BadLayout() 78*03adc8c7SAlex Wilson : 79*03adc8c7SAlex Wilson BApplication("application/x-vnd.haiku.BadLayout") 80*03adc8c7SAlex Wilson { 81*03adc8c7SAlex Wilson BRect frameRect; 82*03adc8c7SAlex Wilson frameRect.Set(100, 100, 300, 300); 83*03adc8c7SAlex Wilson BadLayoutWindow* window = new BadLayoutWindow(frameRect); 84*03adc8c7SAlex Wilson window->Show(); 85*03adc8c7SAlex Wilson } 86*03adc8c7SAlex Wilson }; 87*03adc8c7SAlex Wilson 88*03adc8c7SAlex Wilson 89*03adc8c7SAlex Wilson int 90*03adc8c7SAlex Wilson main() 91*03adc8c7SAlex Wilson { 92*03adc8c7SAlex Wilson BadLayout app; 93*03adc8c7SAlex Wilson app.Run(); 94*03adc8c7SAlex Wilson return 0; 95*03adc8c7SAlex Wilson } 96*03adc8c7SAlex Wilson 97