vfs: check userland buffers before reading them.
[haiku.git] / src / tests / libs / alm / HelloWorld.cpp
blob58f1e7c8563e7b56588223ebac15d82703220825
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 * Distributed under the terms of the MIT License.
6 */
8 #include <Application.h>
9 #include <Button.h>
10 #include <GroupLayout.h>
11 #include <List.h>
12 #include <StringView.h>
13 #include <Window.h>
15 // include this for ALM
16 #include "ALMLayout.h"
19 const uint32 kMsgClone = 'clne';
22 class HelloWorldWindow : public BWindow {
23 public:
24 HelloWorldWindow(BRect frame)
26 BWindow(frame, "ALM Hello World", B_TITLED_WINDOW,
27 B_QUIT_ON_WINDOW_CLOSE)
29 button1 = new BButton("Hello World!");
31 // create a new BALMLayout and use it for this window
32 fLayout = new BALMLayout();
33 BView* view = new BView("alm view", 0, fLayout);
34 fLayout->SetExplicitAlignment(BAlignment(B_ALIGN_USE_FULL_WIDTH,
35 B_ALIGN_USE_FULL_HEIGHT));
36 SetLayout(new BGroupLayout(B_VERTICAL));
37 AddChild(view);
39 // add an area containing the button
40 // use the borders of the layout as the borders for the area
41 fLayout->AddView(button1, fLayout->Left(), fLayout->Top(),
42 fLayout->Right(), fLayout->Bottom());
43 button1->SetExplicitMinSize(BSize(0, 50));
44 button1->SetExplicitMaxSize(BSize(500, 500));
45 button1->SetExplicitAlignment(BAlignment(B_ALIGN_USE_FULL_WIDTH,
46 B_ALIGN_USE_FULL_HEIGHT));
48 // test size limits
49 BSize min = fLayout->MinSize();
50 BSize max = fLayout->MaxSize();
51 SetSizeLimits(min.Width(), max.Width(), min.Height(), max.Height());
53 AddShortcut('c', B_COMMAND_KEY, new BMessage(kMsgClone));
56 void MessageReceived(BMessage* message)
58 switch (message->what) {
59 case kMsgClone:
61 BView* view = fLayout->View();
62 BMessage archive;
63 view->Archive(&archive, true);
64 BWindow* window = new BWindow(BRect(30, 30, 100, 100),
65 "ALM HelloWorld Clone", B_TITLED_WINDOW,
66 B_QUIT_ON_WINDOW_CLOSE | B_AUTO_UPDATE_SIZE_LIMITS);
67 window->SetLayout(new BGroupLayout(B_VERTICAL));
68 BView* clone;
69 status_t err = BUnarchiver::InstantiateObject(&archive, clone);
70 if (err != B_OK)
71 window->AddChild(new BStringView("", "An error occurred!"));
72 else
73 window->AddChild(clone);
74 window->Show();
76 break;
78 default:
79 BWindow::MessageReceived(message);
83 private:
85 BALMLayout* fLayout;
86 BButton* button1;
90 class HelloWorld : public BApplication {
91 public:
92 HelloWorld()
94 BApplication("application/x-vnd.haiku.HelloWorld")
96 BRect frameRect;
97 frameRect.Set(100, 100, 300, 300);
98 HelloWorldWindow* window = new HelloWorldWindow(frameRect);
99 window->Show();
105 main()
107 HelloWorld app;
108 app.Run();
109 return 0;