xref: /haiku/src/tests/libs/alm/Pinwheel.cpp (revision 25a7b01d15612846f332751841da3579db313082)
18d9b6ef4SClemens Zeidler /*
28d9b6ef4SClemens Zeidler  * Copyright 2007-2008, Christof Lutteroth, lutteroth@cs.auckland.ac.nz
38d9b6ef4SClemens Zeidler  * Copyright 2007-2008, James Kim, jkim202@ec.auckland.ac.nz
48d9b6ef4SClemens Zeidler  * Copyright 2010, Clemens Zeidler <haiku@clemens-zeidler.de>
58d9b6ef4SClemens Zeidler  * Distributed under the terms of the MIT License.
68d9b6ef4SClemens Zeidler  */
78d9b6ef4SClemens Zeidler 
8ea607d6fSAxel Dörfler #include <Application.h>
9ea607d6fSAxel Dörfler #include <Button.h>
10ea607d6fSAxel Dörfler #include <TextView.h>
11ea607d6fSAxel Dörfler #include <List.h>
12ea607d6fSAxel Dörfler #include <Window.h>
13ea607d6fSAxel Dörfler 
14ea607d6fSAxel Dörfler // include this for ALM
158d9b6ef4SClemens Zeidler #include "ALMLayout.h"
16*2bf5ded1SAlex Wilson #include "ALMLayoutBuilder.h"
17ea607d6fSAxel Dörfler 
18ea607d6fSAxel Dörfler 
19ea607d6fSAxel Dörfler class PinwheelWindow : public BWindow {
20ea607d6fSAxel Dörfler public:
PinwheelWindow(BRect frame)21ea607d6fSAxel Dörfler 	PinwheelWindow(BRect frame)
22f5dc380dSClemens Zeidler 		:
23f5dc380dSClemens Zeidler 		BWindow(frame, "ALM Pinwheel", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE)
24ea607d6fSAxel Dörfler 	{
25ea607d6fSAxel Dörfler 		button1 = new BButton("1");
26ea607d6fSAxel Dörfler 		button2 = new BButton("2");
27ea607d6fSAxel Dörfler 		button3 = new BButton("3");
28ea607d6fSAxel Dörfler 		button4 = new BButton("4");
29ea607d6fSAxel Dörfler 		textView1 = new BTextView("textView1");
30ea607d6fSAxel Dörfler 		textView1->SetText("5");
31ea607d6fSAxel Dörfler 
32c87bbc39SClemens Zeidler 		button1->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED));
33c87bbc39SClemens Zeidler 		button2->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED));
34c87bbc39SClemens Zeidler 		button3->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED));
35c87bbc39SClemens Zeidler 		button4->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED));
36c87bbc39SClemens Zeidler 
37ea607d6fSAxel Dörfler 		// create a new BALMLayout and use  it for this window
38*2bf5ded1SAlex Wilson 		BALMLayout* layout = new BALMLayout(10, 10);
39*2bf5ded1SAlex Wilson 
40*2bf5ded1SAlex Wilson 		BReference<XTab> xTabs[2];
41*2bf5ded1SAlex Wilson 		BReference<YTab> yTabs[2];
42*2bf5ded1SAlex Wilson 		layout->AddXTabs(xTabs, 2);
43*2bf5ded1SAlex Wilson 		layout->AddYTabs(yTabs, 2);
44*2bf5ded1SAlex Wilson 
45*2bf5ded1SAlex Wilson 		BALM::BALMLayoutBuilder(this, layout)
46*2bf5ded1SAlex Wilson 			.SetInsets(5)
47*2bf5ded1SAlex Wilson 			.Add(textView1, xTabs[0], yTabs[0], xTabs[1], yTabs[1])
48*2bf5ded1SAlex Wilson 			.StartingAt(textView1)
49*2bf5ded1SAlex Wilson 				.AddAbove(button1, layout->Top(), layout->Left())
50*2bf5ded1SAlex Wilson 				.AddToRight(button2, layout->Right(), NULL, yTabs[1])
51*2bf5ded1SAlex Wilson 				.AddBelow(button3, layout->Bottom(), xTabs[0])
52*2bf5ded1SAlex Wilson 				.AddToLeft(button4, layout->Left(),  yTabs[0]);
53*2bf5ded1SAlex Wilson 
54*2bf5ded1SAlex Wilson 		// alternative setup
55*2bf5ded1SAlex Wilson 		/*
56ea607d6fSAxel Dörfler 		SetLayout(layout);
57ea607d6fSAxel Dörfler 
589b0221fdSAlex Wilson 		layout->SetInsets(5.);
5996e2013eSClemens Zeidler 
60ea607d6fSAxel Dörfler 		// create extra tabs
615693bf2fSczeidler 		BReference<XTab> x1 = layout->AddXTab();
625693bf2fSczeidler 		BReference<XTab> x2 = layout->AddXTab();
635693bf2fSczeidler 		BReference<YTab> y1 = layout->AddYTab();
645693bf2fSczeidler 		BReference<YTab> y2 = layout->AddYTab();
65ea607d6fSAxel Dörfler 
6681c40be9SClemens Zeidler 		layout->AddView(button1, layout->Left(), layout->Top(), x2,
679576365dSClemens Zeidler 			y1);
689576365dSClemens Zeidler 		layout->AddView(button2, x2, layout->Top(), layout->Right(), y2);
6981c40be9SClemens Zeidler 		layout->AddView(button3, x1, y2, layout->Right(),
709576365dSClemens Zeidler 			layout->Bottom());
719576365dSClemens Zeidler 		layout->AddView(button4, layout->Left(), y1, x1, layout->Bottom());
729576365dSClemens Zeidler 		layout->AddView(textView1, x1, y1, x2, y2);
73*2bf5ded1SAlex Wilson 		*/
74ea607d6fSAxel Dörfler 
75cad0c434SClemens Zeidler 		// test size limits
76cad0c434SClemens Zeidler 		BSize min = layout->MinSize();
77cad0c434SClemens Zeidler 		BSize max = layout->MaxSize();
78cad0c434SClemens Zeidler 		SetSizeLimits(min.Width(), max.Width(), min.Height(), max.Height());
79ea607d6fSAxel Dörfler 	}
80ea607d6fSAxel Dörfler 
81ea607d6fSAxel Dörfler private:
82ea607d6fSAxel Dörfler 	BButton* button1;
83ea607d6fSAxel Dörfler 	BButton* button2;
84ea607d6fSAxel Dörfler 	BButton* button3;
85ea607d6fSAxel Dörfler 	BButton* button4;
86ea607d6fSAxel Dörfler 	BTextView* textView1;
87ea607d6fSAxel Dörfler };
88ea607d6fSAxel Dörfler 
89ea607d6fSAxel Dörfler 
90ea607d6fSAxel Dörfler class Pinwheel : public BApplication {
91ea607d6fSAxel Dörfler public:
Pinwheel()92ea607d6fSAxel Dörfler 	Pinwheel()
93f5dc380dSClemens Zeidler 		:
94f5dc380dSClemens Zeidler 		BApplication("application/x-vnd.haiku.Pinwheel")
95ea607d6fSAxel Dörfler 	{
96ea607d6fSAxel Dörfler 		BRect frameRect;
97ea607d6fSAxel Dörfler 		frameRect.Set(100, 100, 300, 300);
98ea607d6fSAxel Dörfler 		PinwheelWindow* window = new PinwheelWindow(frameRect);
99ea607d6fSAxel Dörfler 		window->Show();
100ea607d6fSAxel Dörfler 	}
101ea607d6fSAxel Dörfler };
102ea607d6fSAxel Dörfler 
103ea607d6fSAxel Dörfler 
104ea607d6fSAxel Dörfler int
main()105ea607d6fSAxel Dörfler main()
106ea607d6fSAxel Dörfler {
107ea607d6fSAxel Dörfler 	Pinwheel app;
108ea607d6fSAxel Dörfler 	app.Run();
109ea607d6fSAxel Dörfler 	return 0;
110ea607d6fSAxel Dörfler }
111ea607d6fSAxel Dörfler 
112