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 trademarks 30 of Be Incorporated in the United States and other countries. Other brand product 31 names are registered trademarks or trademarks of their respective holders. 32 All rights reserved. 33 */ 34 35 #include <Debug.h> 36 #include <string.h> 37 #include <Application.h> 38 #include <Roster.h> 39 40 #include "BarApp.h" 41 #include "BarMenuBar.h" 42 #include "DeskBarUtils.h" 43 #include "TeamMenuItem.h" 44 #include "TeamMenu.h" 45 46 47 TTeamMenu::TTeamMenu() 48 : BMenu("Team Menu") 49 { 50 SetItemMargins(0.0f, 0.0f, 0.0f, 0.0f); 51 SetFont(be_plain_font); 52 } 53 54 55 int 56 TTeamMenu::CompareByName(const void *first, const void *second) 57 { 58 return strcasecmp((*(static_cast<BarTeamInfo * const*>(first)))->name, 59 (*(static_cast<BarTeamInfo * const*>(second)))->name); 60 } 61 62 63 void 64 TTeamMenu::AttachedToWindow() 65 { 66 RemoveItems(0, CountItems(), true); 67 68 BMessenger self(this); 69 BList teamList; 70 TBarApp::Subscribe(self, &teamList); 71 72 TBarView *barview = (dynamic_cast<TBarApp *>(be_app))->BarView(); 73 bool dragging = barview && barview->Dragging(); 74 75 desk_settings *settings = ((TBarApp *)be_app)->Settings(); 76 77 if (settings->sortRunningApps) 78 teamList.SortItems(CompareByName); 79 80 int32 count = teamList.CountItems(); 81 for (int32 i = 0; i < count; i++) { 82 BarTeamInfo *barInfo = (BarTeamInfo *)teamList.ItemAt(i); 83 84 if (((barInfo->flags & B_BACKGROUND_APP) == 0) 85 && (strcasecmp(barInfo->sig, kDeskbarSignature) != 0)) { 86 TTeamMenuItem *item = new TTeamMenuItem(barInfo->teams, barInfo->icon, 87 barInfo->name, barInfo->sig, -1, -1, true, true); 88 89 if ((settings->trackerAlwaysFirst) 90 && (strcmp(barInfo->sig, kTrackerSignature) == 0)) 91 AddItem(item, 0); 92 else 93 AddItem(item); 94 95 if (dragging && item) { 96 bool canhandle = (dynamic_cast<TBarApp *>(be_app))->BarView()-> 97 AppCanHandleTypes(item->Signature()); 98 if (item->IsEnabled() != canhandle) 99 item->SetEnabled(canhandle); 100 101 BMenu *menu = item->Submenu(); 102 if (menu) 103 menu->SetTrackingHook(barview->MenuTrackingHook, 104 barview->GetTrackingHookData()); 105 } 106 107 barInfo->teams = NULL; 108 barInfo->icon = NULL; 109 barInfo->name = NULL; 110 barInfo->sig = NULL; 111 } 112 delete barInfo; 113 } 114 115 if (CountItems() == 0) { 116 BMenuItem *item = new BMenuItem("no application running", NULL); 117 item->SetEnabled(false); 118 AddItem(item); 119 } 120 121 if (dragging && barview->LockLooper()) { 122 SetTrackingHook(barview->MenuTrackingHook, barview->GetTrackingHookData()); 123 barview->DragStart(); 124 barview->UnlockLooper(); 125 } 126 127 BMenu::AttachedToWindow(); 128 } 129 130 131 void 132 TTeamMenu::DetachedFromWindow() 133 { 134 TBarView *barView = (dynamic_cast<TBarApp *>(be_app))->BarView(); 135 if (barView) { 136 BLooper *looper = barView->Looper(); 137 if (looper->Lock()) { 138 barView->DragStop(); 139 looper->Unlock(); 140 } 141 } 142 143 BMenu::DetachedFromWindow(); 144 145 BMessenger self(this); 146 TBarApp::Unsubscribe(self); 147 } 148 149 150 void 151 TTeamMenu::DrawBackground(BRect) 152 { 153 } 154