xref: /haiku/src/tests/libs/alm/Views.cpp (revision b1f9962baedd642e3cd935a41561b6766b04b4bf)
170e20761SClemens Zeidler /*
270e20761SClemens Zeidler  * Copyright 2007-2008, Christof Lutteroth, lutteroth@cs.auckland.ac.nz
370e20761SClemens Zeidler  * Copyright 2007-2008, James Kim, jkim202@ec.auckland.ac.nz
470e20761SClemens Zeidler  * Copyright 2010, Clemens Zeidler <haiku@clemens-zeidler.de>
570e20761SClemens Zeidler  * Distributed under the terms of the MIT License.
670e20761SClemens Zeidler  */
770e20761SClemens Zeidler 
870e20761SClemens Zeidler 
970e20761SClemens Zeidler #include <Application.h>
1070e20761SClemens Zeidler #include <Button.h>
1170e20761SClemens Zeidler #include <MenuField.h>
1270e20761SClemens Zeidler #include <PopUpMenu.h>
1370e20761SClemens Zeidler #include <RadioButton.h>
1470e20761SClemens Zeidler #include <SpaceLayoutItem.h>
1570e20761SClemens Zeidler #include <StatusBar.h>
1670e20761SClemens Zeidler #include <StringView.h>
1770e20761SClemens Zeidler #include <TextView.h>
1870e20761SClemens Zeidler #include <Window.h>
1970e20761SClemens Zeidler 
2070e20761SClemens Zeidler #include "ALMLayout.h"
2170e20761SClemens Zeidler 
2270e20761SClemens Zeidler 
23*b1f9962bSClemens Zeidler using namespace LinearProgramming;
24*b1f9962bSClemens Zeidler 
25*b1f9962bSClemens Zeidler 
2670e20761SClemens Zeidler class ViewsWindow : public BWindow {
2770e20761SClemens Zeidler public:
2870e20761SClemens Zeidler 	ViewsWindow(BRect frame)
2970e20761SClemens Zeidler 		:
3037344020SClemens Zeidler 		BWindow(frame, "ALM Views", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE)
3170e20761SClemens Zeidler 	{
3270e20761SClemens Zeidler 		BButton* button1 = new BButton("BButton");
3370e20761SClemens Zeidler 		BRadioButton* radioButton = new BRadioButton("BRadioButton", NULL);
3470e20761SClemens Zeidler 		BButton* button3 = new BButton("3");
3570e20761SClemens Zeidler 		BButton* button4 = new BButton("4");
3670e20761SClemens Zeidler 		button4->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
3770e20761SClemens Zeidler 			B_ALIGN_VERTICAL_CENTER));
3870e20761SClemens Zeidler 		BButton* button5 = new BButton("5");
3970e20761SClemens Zeidler 		BButton* button6 = new BButton("6");
4070e20761SClemens Zeidler 		BTextView* textView1 = new BTextView("textView1");
4170e20761SClemens Zeidler 		textView1->SetText("BTextView");
4270e20761SClemens Zeidler 		BStatusBar* statusBar = new BStatusBar("BStatusBar", "label",
4370e20761SClemens Zeidler 			"trailing label");
4470e20761SClemens Zeidler 		statusBar->Update(50);
4570e20761SClemens Zeidler 
4670e20761SClemens Zeidler 		BMenu* menu = new BMenu("Menu 1");
4770e20761SClemens Zeidler 		BMenuField* menu1 = new BMenuField("MenuField 1", menu);
4870e20761SClemens Zeidler 		menu->AddItem(new BPopUpMenu("Menu 1"));
4970e20761SClemens Zeidler 		BStringView* stringView1 = new BStringView("string 1", "string 1");
5070e20761SClemens Zeidler 
5170e20761SClemens Zeidler 		menu = new BMenu("Menu 2  + long text");
5270e20761SClemens Zeidler 		BMenuField* menu2 = new BMenuField("MenuField 2", menu);
5370e20761SClemens Zeidler 		menu->AddItem(new BPopUpMenu("Menu 2"));
5470e20761SClemens Zeidler 		BStringView* stringView2 = new BStringView("string 2", "string 2");
5570e20761SClemens Zeidler 
5670e20761SClemens Zeidler 		// create a new BALMLayout and use  it for this window
5770e20761SClemens Zeidler 		BALMLayout* layout = new BALMLayout(10);
5870e20761SClemens Zeidler 		SetLayout(layout);
5970e20761SClemens Zeidler 		layout->SetInset(10.);
6070e20761SClemens Zeidler 
6170e20761SClemens Zeidler 		layout->AddView(button1);
6270e20761SClemens Zeidler 		layout->AddViewToRight(radioButton);
6370e20761SClemens Zeidler 		layout->AddItemToRight(BSpaceLayoutItem::CreateGlue());
6470e20761SClemens Zeidler 		Area* a3 = layout->AddViewToRight(button3);
6570e20761SClemens Zeidler 		layout->SetCurrentArea(radioButton);
6670e20761SClemens Zeidler 		layout->AddViewToBottom(textView1, NULL, NULL, a3->Right());
6770e20761SClemens Zeidler 		layout->AddViewToBottom(button4);
6870e20761SClemens Zeidler 		layout->AddViewToRight(button5, layout->Right());
6970e20761SClemens Zeidler 		layout->AddViewToBottom(button6);
7070e20761SClemens Zeidler 
7170e20761SClemens Zeidler 		layout->AddView(menu1, layout->Left(), layout->BottomOf(button6));
7270e20761SClemens Zeidler 		layout->AddViewToRight(stringView1);
7370e20761SClemens Zeidler 		layout->AddItemToRight(BSpaceLayoutItem::CreateGlue(), layout->Right());
7470e20761SClemens Zeidler 
7570e20761SClemens Zeidler 		layout->AddViewToBottom(statusBar, NULL, layout->Left(),
7670e20761SClemens Zeidler 			layout->Right());
7770e20761SClemens Zeidler 
7870e20761SClemens Zeidler 		layout->AddView(menu2, layout->Left(), layout->BottomOf(statusBar),
7970e20761SClemens Zeidler 			layout->RightOf(menu1), layout->Bottom());
8070e20761SClemens Zeidler 		layout->AddViewToRight(stringView2);
8170e20761SClemens Zeidler 		layout->AddItemToRight(BSpaceLayoutItem::CreateGlue(), layout->Right());
8270e20761SClemens Zeidler 
8370e20761SClemens Zeidler 		layout->Solver()->AddConstraint(2, layout->TopOf(menu1), -1,
84*b1f9962bSClemens Zeidler 			layout->Bottom(), OperatorType(kEQ), 0);
8570e20761SClemens Zeidler 
8670e20761SClemens Zeidler 		// test size limits
8770e20761SClemens Zeidler 		BSize min = layout->MinSize();
8870e20761SClemens Zeidler 		BSize max = layout->MaxSize();
8970e20761SClemens Zeidler 		SetSizeLimits(min.Width(), max.Width(), min.Height(), max.Height());
9070e20761SClemens Zeidler 	}
9170e20761SClemens Zeidler 
9270e20761SClemens Zeidler };
9370e20761SClemens Zeidler 
9470e20761SClemens Zeidler 
9570e20761SClemens Zeidler class Views : public BApplication {
9670e20761SClemens Zeidler public:
9770e20761SClemens Zeidler 	Views()
9870e20761SClemens Zeidler 		:
9970e20761SClemens Zeidler 		BApplication("application/x-vnd.haiku.Views")
10070e20761SClemens Zeidler 	{
10170e20761SClemens Zeidler 		BRect frameRect;
10270e20761SClemens Zeidler 		frameRect.Set(100, 100, 300, 300);
10370e20761SClemens Zeidler 		ViewsWindow* window = new ViewsWindow(frameRect);
10470e20761SClemens Zeidler 		window->Show();
10570e20761SClemens Zeidler 	}
10670e20761SClemens Zeidler };
10770e20761SClemens Zeidler 
10870e20761SClemens Zeidler 
10970e20761SClemens Zeidler int
11070e20761SClemens Zeidler main()
11170e20761SClemens Zeidler {
11270e20761SClemens Zeidler 	Views app;
11370e20761SClemens Zeidler 	app.Run();
11470e20761SClemens Zeidler 	return 0;
11570e20761SClemens Zeidler }
11670e20761SClemens Zeidler 
117