vfs: check userland buffers before reading them.
[haiku.git] / src / tests / libs / alm / BadLayout.cpp
blobd50b57340d8019db10ff091d98eb868829d95795
1 /*
2 * Copyright 2007-2008, Christof Lutteroth, lutteroth@cs.auckland.ac.nz
3 * Copyright 2007-2008, James Kim, jkim202@ec.auckland.ac.nz
4 * Copyright 2010, Clemens Zeidler <haiku@clemens-zeidler.de>
5 * Copyright 2012, Haiku, Inc.
6 * Distributed under the terms of the MIT License.
7 */
9 #include <Alert.h>
10 #include <Application.h>
11 #include <Button.h>
12 #include <Window.h>
14 #include <stdio.h>
16 // include this for ALM
17 #include "ALMLayout.h"
20 class BAlertPolicy : public BALMLayout::BadLayoutPolicy {
21 virtual bool OnBadLayout(BALMLayout* layout, ResultType result,
22 BLayoutContext* context)
24 BAlert* alert = new BAlert("layout failure", "layout failed!",
25 "sure");
26 alert->Go();
27 return true;
32 class BadLayoutWindow : public BWindow {
33 public:
34 BadLayoutWindow(BRect frame)
36 BWindow(frame, "ALM Bad Layout", B_TITLED_WINDOW,
37 B_QUIT_ON_WINDOW_CLOSE)
39 button1 = new BButton("Bad Layout!");
41 // create a new BALMLayout and use it for this window
42 fLayout = new BALMLayout();
43 SetLayout(fLayout);
45 // add an area containing the button
46 // use the borders of the layout as the borders for the area
47 fLayout->AddView(button1, fLayout->Left(), fLayout->Top(),
48 fLayout->Right(), fLayout->Bottom());
49 button1->SetExplicitMinSize(BSize(50, 50));
50 button1->SetExplicitMaxSize(BSize(500, 500));
51 button1->SetExplicitAlignment(BAlignment(B_ALIGN_USE_FULL_WIDTH,
52 B_ALIGN_USE_FULL_HEIGHT));
55 BButton* button2 = new BButton("can't fit!");
56 fLayout->AddView(button2, fLayout->RightOf(button1), fLayout->Top(),
57 fLayout->Right(), fLayout->Bottom());
58 button2->SetExplicitMinSize(BSize(50, 50));
60 fLayout->SetBadLayoutPolicy(new BAlertPolicy());
61 // test size limits
62 BSize min = fLayout->MinSize();
63 BSize max = fLayout->MaxSize();
64 SetSizeLimits(min.Width(), max.Width(), min.Height(), max.Height());
66 printf("moving to standard BALMLayout BadLayoutPolicy\n");
67 fLayout->SetBadLayoutPolicy(NULL);
70 private:
71 BALMLayout* fLayout;
72 BButton* button1;
76 class BadLayout : public BApplication {
77 public:
78 BadLayout()
80 BApplication("application/x-vnd.haiku.BadLayout")
82 BRect frameRect;
83 frameRect.Set(100, 100, 300, 300);
84 BadLayoutWindow* window = new BadLayoutWindow(frameRect);
85 window->Show();
90 int
91 main()
93 BadLayout app;
94 app.Run();
95 return 0;