1 /* 2 Open Tracker License 3 4 Terms and Conditions 5 6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved. 7 8 Permission is hereby granted, free of charge, to any person obtaining a copy of 9 this software and associated documentation files (the "Software"), to deal in 10 the Software without restriction, including without limitation the rights to 11 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 12 of the Software, and to permit persons to whom the Software is furnished to do 13 so, subject to the following conditions: 14 15 The above copyright notice and this permission notice applies to all licensees 16 and shall be included in all copies or substantial portions of the Software. 17 18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY, 20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION 23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 25 Except as contained in this notice, the name of Be Incorporated shall not be 26 used in advertising or otherwise to promote the sale, use or other dealings in 27 this Software without prior written authorization from Be Incorporated. 28 29 Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered 30 trademarks of Be Incorporated in the United States and other countries. Other 31 brand product names are registered trademarks or trademarks of their respective 32 holders. 33 All rights reserved. 34 */ 35 36 37 #include "TeamMenu.h" 38 39 #include <strings.h> 40 41 #include <Application.h> 42 #include <Debug.h> 43 #include <Roster.h> 44 45 #include "BarApp.h" 46 #include "BarMenuBar.h" 47 #include "BarView.h" 48 #include "DeskbarUtils.h" 49 #include "StatusView.h" 50 #include "TeamMenuItem.h" 51 52 53 // #pragma mark - TTeamMenuItem 54 55 56 TTeamMenu::TTeamMenu() 57 : 58 BMenu("Team Menu") 59 { 60 SetItemMargins(0.0f, 0.0f, 0.0f, 0.0f); 61 SetFont(be_plain_font); 62 } 63 64 65 int 66 TTeamMenu::CompareByName(const void* first, const void* second) 67 { 68 return strcasecmp((*(static_cast<BarTeamInfo* const*>(first)))->name, 69 (*(static_cast<BarTeamInfo* const*>(second)))->name); 70 } 71 72 73 void 74 TTeamMenu::AttachedToWindow() 75 { 76 RemoveItems(0, CountItems(), true); 77 // remove all items 78 79 BMessenger self(this); 80 BList teamList; 81 TBarApp::Subscribe(self, &teamList); 82 83 TBarView* barview = (dynamic_cast<TBarApp*>(be_app))->BarView(); 84 bool dragging = barview && barview->Dragging(); 85 int32 iconSize = static_cast<TBarApp*>(be_app)->IconSize(); 86 desk_settings* settings = ((TBarApp*)be_app)->Settings(); 87 88 float width = gMinimumWindowWidth - iconSize - 4; 89 90 if (settings->sortRunningApps) 91 teamList.SortItems(CompareByName); 92 93 int32 count = teamList.CountItems(); 94 for (int32 i = 0; i < count; i++) { 95 // add items back 96 BarTeamInfo* barInfo = (BarTeamInfo*)teamList.ItemAt(i); 97 TTeamMenuItem* item = new TTeamMenuItem(barInfo->teams, 98 barInfo->icon, barInfo->name, barInfo->sig, width, -1); 99 100 if (settings->trackerAlwaysFirst 101 && strcasecmp(barInfo->sig, kTrackerSignature) == 0) { 102 AddItem(item, 0); 103 } else 104 AddItem(item); 105 106 if (dragging && item != NULL) { 107 bool canhandle = (dynamic_cast<TBarApp*>(be_app))->BarView()-> 108 AppCanHandleTypes(item->Signature()); 109 if (item->IsEnabled() != canhandle) 110 item->SetEnabled(canhandle); 111 112 BMenu* menu = item->Submenu(); 113 if (menu != NULL) { 114 menu->SetTrackingHook(barview->MenuTrackingHook, 115 barview->GetTrackingHookData()); 116 } 117 } 118 } 119 120 if (CountItems() == 0) { 121 BMenuItem* item = new BMenuItem("no application running", NULL); 122 item->SetEnabled(false); 123 AddItem(item); 124 } 125 126 if (dragging && barview->LockLooper()) { 127 SetTrackingHook(barview->MenuTrackingHook, 128 barview->GetTrackingHookData()); 129 barview->DragStart(); 130 barview->UnlockLooper(); 131 } 132 133 BMenu::AttachedToWindow(); 134 } 135 136 137 void 138 TTeamMenu::DetachedFromWindow() 139 { 140 TBarView* barView = (dynamic_cast<TBarApp*>(be_app))->BarView(); 141 if (barView != NULL) { 142 BLooper* looper = barView->Looper(); 143 if (looper != NULL && looper->Lock()) { 144 barView->DragStop(); 145 looper->Unlock(); 146 } 147 } 148 149 BMenu::DetachedFromWindow(); 150 151 BMessenger self(this); 152 TBarApp::Unsubscribe(self); 153 } 154