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( 59 (*(static_cast<BarTeamInfo * const*>(first )))->name, 60 (*(static_cast<BarTeamInfo * const*>(second)))->name); 61 } 62 63 64 void 65 TTeamMenu::AttachedToWindow() 66 { 67 BMenuItem *item = NULL; 68 while ((item = RemoveItem((int32)0)) != NULL) 69 delete item; 70 71 BMessenger self(this); 72 BList teamList; 73 TBarApp::Subscribe(self, &teamList); 74 75 TBarView *barview = (dynamic_cast<TBarApp *>(be_app))->BarView(); 76 bool dragging = barview && barview->Dragging(); 77 78 desk_settings *settings = ((TBarApp *)be_app)->Settings(); 79 80 if (settings->sortRunningApps) 81 teamList.SortItems(CompareByName); 82 83 int32 count = teamList.CountItems(); 84 for (int32 i = 0; i < count; i++) { 85 BarTeamInfo *barInfo = (BarTeamInfo *)teamList.ItemAt(i); 86 87 if (((barInfo->flags & B_BACKGROUND_APP) == 0) 88 && (strcasecmp(barInfo->sig, kDeskbarSignature) != 0)) { 89 TTeamMenuItem *item = new TTeamMenuItem(barInfo->teams, barInfo->icon, 90 barInfo->name, barInfo->sig, -1, -1, true, true); 91 92 if ((settings->trackerAlwaysFirst) 93 && (strcmp(barInfo->sig, kTrackerSignature) == 0)) 94 AddItem(item, 0); 95 else 96 AddItem(item); 97 98 if (dragging && item) { 99 bool canhandle = (dynamic_cast<TBarApp *>(be_app))->BarView()-> 100 AppCanHandleTypes(item->Signature()); 101 if (item->IsEnabled() != canhandle) 102 item->SetEnabled(canhandle); 103 104 BMenu *menu = item->Submenu(); 105 if (menu) 106 menu->SetTrackingHook(barview->MenuTrackingHook, 107 barview->GetTrackingHookData()); 108 } 109 110 barInfo->teams = NULL; 111 barInfo->icon = NULL; 112 barInfo->name = NULL; 113 barInfo->sig = NULL; 114 } 115 delete barInfo; 116 } 117 118 if (dragging && barview->LockLooper()) { 119 SetTrackingHook(barview->MenuTrackingHook, barview->GetTrackingHookData()); 120 barview->DragStart(); 121 barview->UnlockLooper(); 122 } 123 124 BMenu::AttachedToWindow(); 125 } 126 127 128 void 129 TTeamMenu::DetachedFromWindow() 130 { 131 TBarView *barView = (dynamic_cast<TBarApp *>(be_app))->BarView(); 132 if (barView) { 133 BLooper *looper = barView->Looper(); 134 if (looper->Lock()) { 135 barView->DragStop(); 136 looper->Unlock(); 137 } 138 } 139 140 BMenu::DetachedFromWindow(); 141 142 BMessenger self(this); 143 TBarApp::Unsubscribe(self); 144 } 145 146 147 void 148 TTeamMenu::DrawBackground(BRect) 149 { 150 } 151