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.
8 #include <Application.h>
10 #include <GroupLayout.h>
12 #include <StringView.h>
15 // include this for ALM
16 #include "ALMLayout.h"
19 const uint32 kMsgClone
= 'clne';
22 class HelloWorldWindow
: public BWindow
{
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
));
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
));
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
) {
61 BView
* view
= fLayout
->View();
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
));
69 status_t err
= BUnarchiver::InstantiateObject(&archive
, clone
);
71 window
->AddChild(new BStringView("", "An error occurred!"));
73 window
->AddChild(clone
);
79 BWindow::MessageReceived(message
);
90 class HelloWorld
: public BApplication
{
94 BApplication("application/x-vnd.haiku.HelloWorld")
97 frameRect
.Set(100, 100, 300, 300);
98 HelloWorldWindow
* window
= new HelloWorldWindow(frameRect
);