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 * Copyright 2012, Haiku, Inc. 6 * Distributed under the terms of the MIT License. 7 */ 8 9 #include <Application.h> 10 #include <Button.h> 11 #include <LayoutBuilder.h> 12 #include <List.h> 13 #include <Message.h> 14 #include <Window.h> 15 16 // include this for ALM 17 #include "ALMLayout.h" 18 #include "ALMLayoutBuilder.h" 19 20 21 class FriendWindow : public BWindow { 22 public: 23 FriendWindow(BRect frame) 24 : 25 BWindow(frame, "ALM Friend Test", B_TITLED_WINDOW, 26 B_QUIT_ON_WINDOW_CLOSE | B_AUTO_UPDATE_SIZE_LIMITS), 27 fLayout2(NULL), 28 fBoom(NULL), 29 fLeft(NULL), 30 fTop(NULL), 31 fRight(NULL), 32 fBottom(NULL) 33 { 34 BButton* button1 = _MakeButton("friends!"); 35 BButton* button2 = _MakeButton("friends!"); 36 BButton* button3 = _MakeButton("friends!"); 37 38 BButton* button4 = _MakeButton("friends!"); 39 BButton* button5 = _MakeButton("friends!"); 40 BButton* button6 = _MakeButton("friends!"); 41 42 BALMLayout* layout1 = new BALMLayout(10, 10); 43 BView* almView1 = _MakeALMView(layout1); 44 45 BReference<XTab> xTabs[2]; 46 layout1->AddXTabs(xTabs, 2); 47 48 BALM::BALMLayoutBuilder(layout1) 49 .Add(button1, layout1->Left(), layout1->Top(), 50 xTabs[0], layout1->Bottom()) 51 .StartingAt(button1) 52 .AddToRight(button2, xTabs[1]) 53 .AddToRight(button3, layout1->Right()); 54 55 fLayout2 = new BALMLayout(10, 10, layout1); 56 BView* almView2 = _MakeALMView(fLayout2); 57 58 BALM::BALMLayoutBuilder(fLayout2) 59 .Add(button4, fLayout2->Left(), fLayout2->Top(), xTabs[0]) 60 .StartingAt(button4) 61 .AddBelow(button5, NULL, xTabs[1], fLayout2->Right()) 62 .AddBelow(button6, fLayout2->Bottom(), xTabs[0]); 63 64 fLeft = fLayout2->Left(); 65 fBottom = fLayout2->BottomOf(button5); 66 fTop = fLayout2->BottomOf(button4); 67 fRight = xTabs[1]; 68 69 BLayoutBuilder::Group<>(this, B_VERTICAL) 70 .Add(almView1) 71 .Add(almView2); 72 } 73 74 75 void MessageReceived(BMessage* message) 76 { 77 switch (message->what) { 78 case 'BOOM': 79 if (!fBoom) { 80 fBoom = _MakeButton("BOOM"); 81 fLayout2->AddView(fBoom, fLeft, fTop, 82 fRight, fBottom); 83 } else { 84 if (fBoom->IsHidden(fBoom)) 85 fBoom->Show(); 86 else 87 fBoom->Hide(); 88 } 89 break; 90 default: 91 BWindow::MessageReceived(message); 92 } 93 } 94 95 private: 96 BButton* _MakeButton(const char* label) 97 { 98 BButton* button = new BButton(label, new BMessage('BOOM')); 99 button->SetExplicitMinSize(BSize(10, 50)); 100 button->SetExplicitMaxSize(BSize(500, 500)); 101 button->SetExplicitAlignment(BAlignment(B_ALIGN_USE_FULL_WIDTH, 102 B_ALIGN_USE_FULL_HEIGHT)); 103 return button; 104 } 105 106 BView* _MakeALMView(BALMLayout* layout) 107 { 108 BView* view = new BView(NULL, 0, layout); 109 view->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 110 return view; 111 } 112 113 BALMLayout* fLayout2; 114 BButton* fBoom; 115 XTab* fLeft; 116 YTab* fTop; 117 XTab* fRight; 118 YTab* fBottom; 119 }; 120 121 122 class Friend : public BApplication { 123 public: 124 Friend() 125 : 126 BApplication("application/x-vnd.haiku.Friend") 127 { 128 BRect frameRect; 129 frameRect.Set(100, 100, 300, 300); 130 FriendWindow* window = new FriendWindow(frameRect); 131 window->Show(); 132 } 133 }; 134 135 136 int 137 main() 138 { 139 Friend app; 140 app.Run(); 141 return 0; 142 } 143 144