xref: /haiku/src/tests/libs/alm/Views.cpp (revision 70e207613508fb5b562405c4edc33ddfe77fbfdf)
1*70e20761SClemens Zeidler /*
2*70e20761SClemens Zeidler  * Copyright 2007-2008, Christof Lutteroth, lutteroth@cs.auckland.ac.nz
3*70e20761SClemens Zeidler  * Copyright 2007-2008, James Kim, jkim202@ec.auckland.ac.nz
4*70e20761SClemens Zeidler  * Copyright 2010, Clemens Zeidler <haiku@clemens-zeidler.de>
5*70e20761SClemens Zeidler  * Distributed under the terms of the MIT License.
6*70e20761SClemens Zeidler  */
7*70e20761SClemens Zeidler 
8*70e20761SClemens Zeidler 
9*70e20761SClemens Zeidler #include <Application.h>
10*70e20761SClemens Zeidler #include <Button.h>
11*70e20761SClemens Zeidler #include <MenuField.h>
12*70e20761SClemens Zeidler #include <PopUpMenu.h>
13*70e20761SClemens Zeidler #include <RadioButton.h>
14*70e20761SClemens Zeidler #include <SpaceLayoutItem.h>
15*70e20761SClemens Zeidler #include <StatusBar.h>
16*70e20761SClemens Zeidler #include <StringView.h>
17*70e20761SClemens Zeidler #include <TextView.h>
18*70e20761SClemens Zeidler #include <Window.h>
19*70e20761SClemens Zeidler 
20*70e20761SClemens Zeidler #include "ALMLayout.h"
21*70e20761SClemens Zeidler 
22*70e20761SClemens Zeidler 
23*70e20761SClemens Zeidler class ViewsWindow : public BWindow {
24*70e20761SClemens Zeidler public:
25*70e20761SClemens Zeidler 	ViewsWindow(BRect frame)
26*70e20761SClemens Zeidler 		:
27*70e20761SClemens Zeidler 		BWindow(frame, "ALM Two Views", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE)
28*70e20761SClemens Zeidler 	{
29*70e20761SClemens Zeidler 		BButton* button1 = new BButton("BButton");
30*70e20761SClemens Zeidler 		BRadioButton* radioButton = new BRadioButton("BRadioButton", NULL);
31*70e20761SClemens Zeidler 		BButton* button3 = new BButton("3");
32*70e20761SClemens Zeidler 		BButton* button4 = new BButton("4");
33*70e20761SClemens Zeidler 		button4->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
34*70e20761SClemens Zeidler 			B_ALIGN_VERTICAL_CENTER));
35*70e20761SClemens Zeidler 		BButton* button5 = new BButton("5");
36*70e20761SClemens Zeidler 		BButton* button6 = new BButton("6");
37*70e20761SClemens Zeidler 		BTextView* textView1 = new BTextView("textView1");
38*70e20761SClemens Zeidler 		textView1->SetText("BTextView");
39*70e20761SClemens Zeidler 		BStatusBar* statusBar = new BStatusBar("BStatusBar", "label",
40*70e20761SClemens Zeidler 			"trailing label");
41*70e20761SClemens Zeidler 		statusBar->Update(50);
42*70e20761SClemens Zeidler 
43*70e20761SClemens Zeidler 		BMenu* menu = new BMenu("Menu 1");
44*70e20761SClemens Zeidler 		BMenuField* menu1 = new BMenuField("MenuField 1", menu);
45*70e20761SClemens Zeidler 		menu->AddItem(new BPopUpMenu("Menu 1"));
46*70e20761SClemens Zeidler 		BStringView* stringView1 = new BStringView("string 1", "string 1");
47*70e20761SClemens Zeidler 
48*70e20761SClemens Zeidler 		menu = new BMenu("Menu 2  + long text");
49*70e20761SClemens Zeidler 		BMenuField* menu2 = new BMenuField("MenuField 2", menu);
50*70e20761SClemens Zeidler 		menu->AddItem(new BPopUpMenu("Menu 2"));
51*70e20761SClemens Zeidler 		BStringView* stringView2 = new BStringView("string 2", "string 2");
52*70e20761SClemens Zeidler 
53*70e20761SClemens Zeidler 		// create a new BALMLayout and use  it for this window
54*70e20761SClemens Zeidler 		BALMLayout* layout = new BALMLayout(10);
55*70e20761SClemens Zeidler 		SetLayout(layout);
56*70e20761SClemens Zeidler 		layout->SetInset(10.);
57*70e20761SClemens Zeidler 
58*70e20761SClemens Zeidler 		layout->AddView(button1);
59*70e20761SClemens Zeidler 		layout->AddViewToRight(radioButton);
60*70e20761SClemens Zeidler 		layout->AddItemToRight(BSpaceLayoutItem::CreateGlue());
61*70e20761SClemens Zeidler 		Area* a3 = layout->AddViewToRight(button3);
62*70e20761SClemens Zeidler 		layout->SetCurrentArea(radioButton);
63*70e20761SClemens Zeidler 		layout->AddViewToBottom(textView1, NULL, NULL, a3->Right());
64*70e20761SClemens Zeidler 		layout->AddViewToBottom(button4);
65*70e20761SClemens Zeidler 		layout->AddViewToRight(button5, layout->Right());
66*70e20761SClemens Zeidler 		layout->AddViewToBottom(button6);
67*70e20761SClemens Zeidler 
68*70e20761SClemens Zeidler 		layout->AddView(menu1, layout->Left(), layout->BottomOf(button6));
69*70e20761SClemens Zeidler 		layout->AddViewToRight(stringView1);
70*70e20761SClemens Zeidler 		layout->AddItemToRight(BSpaceLayoutItem::CreateGlue(), layout->Right());
71*70e20761SClemens Zeidler 
72*70e20761SClemens Zeidler 		layout->AddViewToBottom(statusBar, NULL, layout->Left(),
73*70e20761SClemens Zeidler 			layout->Right());
74*70e20761SClemens Zeidler 
75*70e20761SClemens Zeidler 		layout->AddView(menu2, layout->Left(), layout->BottomOf(statusBar),
76*70e20761SClemens Zeidler 			layout->RightOf(menu1), layout->Bottom());
77*70e20761SClemens Zeidler 		layout->AddViewToRight(stringView2);
78*70e20761SClemens Zeidler 		layout->AddItemToRight(BSpaceLayoutItem::CreateGlue(), layout->Right());
79*70e20761SClemens Zeidler 
80*70e20761SClemens Zeidler 		layout->Solver()->AddConstraint(2, layout->TopOf(menu1), -1,
81*70e20761SClemens Zeidler 			layout->Bottom(), OperatorType(EQ), 0);
82*70e20761SClemens Zeidler 
83*70e20761SClemens Zeidler 		// test size limits
84*70e20761SClemens Zeidler 		BSize min = layout->MinSize();
85*70e20761SClemens Zeidler 		BSize max = layout->MaxSize();
86*70e20761SClemens Zeidler 		SetSizeLimits(min.Width(), max.Width(), min.Height(), max.Height());
87*70e20761SClemens Zeidler 	}
88*70e20761SClemens Zeidler 
89*70e20761SClemens Zeidler };
90*70e20761SClemens Zeidler 
91*70e20761SClemens Zeidler 
92*70e20761SClemens Zeidler class Views : public BApplication {
93*70e20761SClemens Zeidler public:
94*70e20761SClemens Zeidler 	Views()
95*70e20761SClemens Zeidler 		:
96*70e20761SClemens Zeidler 		BApplication("application/x-vnd.haiku.Views")
97*70e20761SClemens Zeidler 	{
98*70e20761SClemens Zeidler 		BRect frameRect;
99*70e20761SClemens Zeidler 		frameRect.Set(100, 100, 300, 300);
100*70e20761SClemens Zeidler 		ViewsWindow* window = new ViewsWindow(frameRect);
101*70e20761SClemens Zeidler 		window->Show();
102*70e20761SClemens Zeidler 	}
103*70e20761SClemens Zeidler };
104*70e20761SClemens Zeidler 
105*70e20761SClemens Zeidler 
106*70e20761SClemens Zeidler int
107*70e20761SClemens Zeidler main()
108*70e20761SClemens Zeidler {
109*70e20761SClemens Zeidler 	Views app;
110*70e20761SClemens Zeidler 	app.Run();
111*70e20761SClemens Zeidler 	return 0;
112*70e20761SClemens Zeidler }
113*70e20761SClemens Zeidler 
114