xref: /haiku/src/tests/libs/alm/Pinwheel.cpp (revision 541ff51a6ef4c47f8ab105ba6ff895cdbba83aca)
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  */
7 
8 #include <Application.h>
9 #include <Button.h>
10 #include <TextView.h>
11 #include <List.h>
12 #include <Window.h>
13 
14 // include this for ALM
15 #include "ALMLayout.h"
16 
17 
18 class PinwheelWindow : public BWindow {
19 public:
20 	PinwheelWindow(BRect frame)
21 		:
22 		BWindow(frame, "ALM Pinwheel", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE)
23 	{
24 		button1 = new BButton("1");
25 		button2 = new BButton("2");
26 		button3 = new BButton("3");
27 		button4 = new BButton("4");
28 		textView1 = new BTextView("textView1");
29 		textView1->SetText("5");
30 
31 		button1->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED));
32 		button2->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED));
33 		button3->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED));
34 		button4->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED));
35 
36 		// create a new BALMLayout and use  it for this window
37 		BALMLayout* layout = new BALMLayout(10.);
38 		SetLayout(layout);
39 
40 		layout->SetInset(5.);
41 
42 		// create extra tabs
43 		BReference<XTab> x1 = layout->AddXTab();
44 		BReference<XTab> x2 = layout->AddXTab();
45 		BReference<YTab> y1 = layout->AddYTab();
46 		BReference<YTab> y2 = layout->AddYTab();
47 
48 		layout->AddView(button1, layout->Left(), layout->Top(), x2,
49 			y1);
50 		layout->AddView(button2, x2, layout->Top(), layout->Right(), y2);
51 		layout->AddView(button3, x1, y2, layout->Right(),
52 			layout->Bottom());
53 		layout->AddView(button4, layout->Left(), y1, x1, layout->Bottom());
54 		layout->AddView(textView1, x1, y1, x2, y2);
55 
56 		// alternative setup
57 		/*
58 		layout->AddView(button1);
59 		Area* a1 = layout->AreaOf(button1);
60 		Area* a2 = layout->AddViewToRight(button2, a1, layout->Right(), NULL,
61 			layout->AddYTab());
62 		Area* a3 = layout->AddViewToBottom(button3, a2, layout->Bottom(),
63 			layout->AddXTab(), NULL);
64 		Area* a4 = layout->AddViewToLeft(button4, a3, layout->Left(),
65 			a1->Bottom());
66 
67 		layout->AddView(textView1, a4->Right(), a1->Bottom(), a2->Left(),
68 			a3->Top());
69 		a1->SetWidthAs(a3);
70 		a1->SetHeightAs(a3);
71 		*/
72 
73 		// test size limits
74 		BSize min = layout->MinSize();
75 		BSize max = layout->MaxSize();
76 		SetSizeLimits(min.Width(), max.Width(), min.Height(), max.Height());
77 	}
78 
79 private:
80 	BButton* button1;
81 	BButton* button2;
82 	BButton* button3;
83 	BButton* button4;
84 	BTextView* textView1;
85 };
86 
87 
88 class Pinwheel : public BApplication {
89 public:
90 	Pinwheel()
91 		:
92 		BApplication("application/x-vnd.haiku.Pinwheel")
93 	{
94 		BRect frameRect;
95 		frameRect.Set(100, 100, 300, 300);
96 		PinwheelWindow* window = new PinwheelWindow(frameRect);
97 		window->Show();
98 	}
99 };
100 
101 
102 int
103 main()
104 {
105 	Pinwheel app;
106 	app.Run();
107 	return 0;
108 }
109 
110