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.
9 #include <Application.h>
11 #include <LayoutBuilder.h>
14 #include <StringView.h>
17 // include this for ALM
18 #include "ALMLayout.h"
19 #include "ALMLayoutBuilder.h"
20 #include "LinearProgrammingTypes.h"
23 class FriendWindow
: public BWindow
{
25 FriendWindow(BRect frame
)
27 BWindow(frame
, "ALM Friend Test", B_TITLED_WINDOW
,
28 B_QUIT_ON_WINDOW_CLOSE
| B_AUTO_UPDATE_SIZE_LIMITS
),
36 BButton
* button1
= _MakeButton("friends!");
37 BButton
* button2
= _MakeButton("friends!");
38 BButton
* button3
= _MakeButton("friends!");
40 BButton
* button4
= _MakeButton("friends!");
41 BButton
* button5
= _MakeButton("friends!");
42 BButton
* button6
= _MakeButton("friends!");
44 BALMLayout
* layout1
= new BALMLayout(10, 10);
45 BView
* almView1
= _MakeALMView(layout1
);
47 BReference
<XTab
> xTabs
[2];
48 layout1
->AddXTabs(xTabs
, 2);
50 BALM::BALMLayoutBuilder(layout1
)
51 .Add(button1
, layout1
->Left(), layout1
->Top(),
52 xTabs
[0], layout1
->Bottom())
54 .AddToRight(button2
, xTabs
[1])
55 .AddToRight(button3
, layout1
->Right());
57 fLayout2
= new BALMLayout(10, 10, layout1
);
58 BView
* almView2
= _MakeALMView(fLayout2
);
60 BALM::BALMLayoutBuilder(fLayout2
)
61 .Add(button4
, fLayout2
->Left(), fLayout2
->Top(), xTabs
[0])
63 .AddBelow(button5
, NULL
, xTabs
[1], fLayout2
->Right())
64 .AddBelow(button6
, fLayout2
->Bottom(), xTabs
[0]);
66 fLeft
= fLayout2
->Left();
67 fBottom
= fLayout2
->BottomOf(button5
);
68 fTop
= fLayout2
->BottomOf(button4
);
71 layout1
->AreaFor(button2
)->SetContentAspectRatio(1.0f
);
72 fLayout2
->Solver()->AddConstraint(-1.0f
, layout1
->Left(), 1.0f
, xTabs
[0],
73 LinearProgramming::kLE
, 90.0f
);
75 BButton
* archiveButton
= new BButton("clone", new BMessage('arcv'));
76 archiveButton
->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED
,
78 BLayoutBuilder::Group
<>(this, B_VERTICAL
)
79 .Add(almView1
->GetLayout())
80 .Add(almView2
->GetLayout())
85 void MessageReceived(BMessage
* message
)
87 switch (message
->what
) {
90 fBoom
= _MakeButton("BOOM");
91 fLayout2
->AddView(fBoom
, fLeft
, fTop
,
94 if (fBoom
->IsHidden(fBoom
))
101 BView
* view
= GetLayout()->View();
103 status_t err
= view
->Archive(&archive
, true);
104 BWindow
* window
= new BWindow(BRect(30, 30, 400, 400),
105 "ALM Friend Test Clone", B_TITLED_WINDOW
,
106 B_QUIT_ON_WINDOW_CLOSE
| B_AUTO_UPDATE_SIZE_LIMITS
);
107 window
->SetLayout(new BGroupLayout(B_VERTICAL
));
110 err
= BUnarchiver::InstantiateObject(&archive
, clone
);
112 window
->AddChild(new BStringView("", "An error occurred!"));
114 window
->AddChild(clone
);
121 BWindow::MessageReceived(message
);
126 BButton
* _MakeButton(const char* label
)
128 BButton
* button
= new BButton(label
, new BMessage('BOOM'));
129 button
->SetExplicitMinSize(BSize(10, 50));
130 button
->SetExplicitMaxSize(BSize(500, 500));
131 button
->SetExplicitAlignment(BAlignment(B_ALIGN_USE_FULL_WIDTH
,
132 B_ALIGN_USE_FULL_HEIGHT
));
136 BView
* _MakeALMView(BALMLayout
* layout
)
138 BView
* view
= new BView(NULL
, 0, layout
);
139 view
->SetViewUIColor(B_PANEL_BACKGROUND_COLOR
);
143 BALMLayout
* fLayout2
;
152 class Friend
: public BApplication
{
156 BApplication("application/x-vnd.haiku.Friend")
159 frameRect
.Set(100, 100, 300, 300);
160 FriendWindow
* window
= new FriendWindow(frameRect
);