1 /* 2 * Copyright 2011, Axel Dörfler, axeld@pinc-software.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 #include "ApplicationsView.h" 8 9 #include "LaunchButton.h" 10 #include "Switcher.h" 11 12 13 static const uint32 kMsgActivateApp = 'AcAp'; 14 15 16 ApplicationsView::ApplicationsView(uint32 location) 17 : 18 BGroupView((location & (kTopEdge | kBottomEdge)) != 0 19 ? B_HORIZONTAL : B_VERTICAL) 20 { 21 } 22 23 24 ApplicationsView::~ApplicationsView() 25 { 26 } 27 28 29 void 30 ApplicationsView::AttachedToWindow() 31 { 32 // TODO: make this dynamic! 33 34 BList teamList; 35 be_roster->GetAppList(&teamList); 36 37 for (int32 i = 0; i < teamList.CountItems(); i++) { 38 app_info appInfo; 39 team_id team = (uintptr_t)teamList.ItemAt(i); 40 if (be_roster->GetRunningAppInfo(team, &appInfo) == B_OK) 41 _AddTeam(appInfo); 42 } 43 } 44 45 46 void 47 ApplicationsView::MessageReceived(BMessage* message) 48 { 49 switch (message->what) { 50 case kMsgActivateApp: 51 be_roster->ActivateApp(message->FindInt32("team")); 52 break; 53 54 default: 55 BGroupView::MessageReceived(message); 56 break; 57 } 58 } 59 60 61 void 62 ApplicationsView::_AddTeam(app_info& info) 63 { 64 if ((info.flags & B_BACKGROUND_APP) != 0) 65 return; 66 67 BMessage* message = new BMessage(kMsgActivateApp); 68 message->AddInt32("team", info.team); 69 70 LaunchButton* button = new LaunchButton(info.signature, NULL, message, 71 this); 72 button->SetTo(&info.ref); 73 AddChild(button); 74 } 75