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 <Collator.h> 43 #include <Debug.h> 44 #include <Roster.h> 45 46 #include "BarApp.h" 47 #include "BarMenuBar.h" 48 #include "BarView.h" 49 #include "DeskbarUtils.h" 50 #include "StatusView.h" 51 #include "TeamMenuItem.h" 52 53 54 // #pragma mark - TTeamMenuItem 55 56 57 TTeamMenu::TTeamMenu() 58 : 59 BMenu("Team Menu") 60 { 61 SetItemMargins(0.0f, 0.0f, 0.0f, 0.0f); 62 SetFont(be_plain_font); 63 } 64 65 66 int 67 TTeamMenu::CompareByName(const void* first, const void* second) 68 { 69 BCollator collator; 70 BLocale::Default()->GetCollator(&collator); 71 72 return collator.Compare( 73 (*(static_cast<BarTeamInfo* const*>(first)))->name, 74 (*(static_cast<BarTeamInfo* const*>(second)))->name); 75 } 76 77 78 void 79 TTeamMenu::AttachedToWindow() 80 { 81 RemoveItems(0, CountItems(), true); 82 // remove all items 83 84 BMessenger self(this); 85 BList teamList; 86 TBarApp::Subscribe(self, &teamList); 87 88 TBarView* barview = (dynamic_cast<TBarApp*>(be_app))->BarView(); 89 bool dragging = barview && barview->Dragging(); 90 int32 iconSize = static_cast<TBarApp*>(be_app)->IconSize(); 91 desk_settings* settings = ((TBarApp*)be_app)->Settings(); 92 93 float width = gMinimumWindowWidth - iconSize - 4; 94 95 if (settings->sortRunningApps) 96 teamList.SortItems(TTeamMenu::CompareByName); 97 98 int32 count = teamList.CountItems(); 99 for (int32 i = 0; i < count; i++) { 100 // add items back 101 BarTeamInfo* barInfo = (BarTeamInfo*)teamList.ItemAt(i); 102 TTeamMenuItem* item = new TTeamMenuItem(barInfo->teams, 103 barInfo->icon, barInfo->name, barInfo->sig, width, -1); 104 105 if (settings->trackerAlwaysFirst 106 && strcasecmp(barInfo->sig, kTrackerSignature) == 0) { 107 AddItem(item, 0); 108 } else 109 AddItem(item); 110 111 if (dragging && item != NULL) { 112 bool canhandle = (dynamic_cast<TBarApp*>(be_app))->BarView()-> 113 AppCanHandleTypes(item->Signature()); 114 if (item->IsEnabled() != canhandle) 115 item->SetEnabled(canhandle); 116 117 BMenu* menu = item->Submenu(); 118 if (menu != NULL) { 119 menu->SetTrackingHook(barview->MenuTrackingHook, 120 barview->GetTrackingHookData()); 121 } 122 } 123 } 124 125 if (CountItems() == 0) { 126 BMenuItem* item = new BMenuItem("no application running", NULL); 127 item->SetEnabled(false); 128 AddItem(item); 129 } 130 131 if (dragging && barview->LockLooper()) { 132 SetTrackingHook(barview->MenuTrackingHook, 133 barview->GetTrackingHookData()); 134 barview->DragStart(); 135 barview->UnlockLooper(); 136 } 137 138 BMenu::AttachedToWindow(); 139 } 140 141 142 void 143 TTeamMenu::DetachedFromWindow() 144 { 145 TBarView* barView = (dynamic_cast<TBarApp*>(be_app))->BarView(); 146 if (barView != NULL) { 147 BLooper* looper = barView->Looper(); 148 if (looper != NULL && looper->Lock()) { 149 barView->DragStop(); 150 looper->Unlock(); 151 } 152 } 153 154 BMenu::DetachedFromWindow(); 155 156 BMessenger self(this); 157 TBarApp::Unsubscribe(self); 158 } 159