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