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 <malloc.h> 37 #include <stdio.h> 38 #include <string.h> 39 #include <Roster.h> 40 41 #include "ShowHideMenuItem.h" 42 #include "WindowMenuItem.h" 43 #include "tracker_private.h" 44 45 46 const int32 kDesktopWindow = 4; 47 const float kHPad = 10.0f; 48 const float kVPad = 2.0f; 49 50 51 TShowHideMenuItem::TShowHideMenuItem(const char *title, const BList *teams, uint32 action) 52 : BMenuItem(title, NULL), 53 fTeams(teams), 54 fAction(action) 55 { 56 BFont font(be_plain_font); 57 fTitleWidth = ceilf(font.StringWidth(title)); 58 font_height fontHeight; 59 font.GetHeight(&fontHeight); 60 fTitleAscent = ceilf(fontHeight.ascent); 61 fTitleDescent = ceilf(fontHeight.descent + fontHeight.leading); 62 } 63 64 65 void 66 TShowHideMenuItem::GetContentSize(float *width, float *height) 67 { 68 *width = kHPad + fTitleWidth + kHPad; 69 *height = fTitleAscent + fTitleDescent; 70 *height += kVPad * 2; 71 } 72 73 74 void 75 TShowHideMenuItem::DrawContent() 76 { 77 BRect frame(Frame()); 78 float labelHeight = fTitleAscent + fTitleDescent; 79 BPoint drawLoc; 80 drawLoc.x = kHPad; 81 drawLoc.y = ((frame.Height() - labelHeight) / 2); 82 Menu()->MovePenBy(drawLoc.x, drawLoc.y); 83 BMenuItem::DrawContent(); 84 } 85 86 87 status_t 88 TShowHideMenuItem::Invoke(BMessage *) 89 { 90 bool doZoom = false; 91 BRect zoomRect(0, 0, 0, 0); 92 BMenuItem *item = Menu()->Superitem(); 93 94 if (item->Menu()->Window() != NULL) { 95 zoomRect = item->Menu()->ConvertToScreen(item->Frame()); 96 doZoom = true; 97 } 98 return TeamShowHideCommon(static_cast<int32>(fAction), fTeams, zoomRect, doZoom); 99 } 100 101 102 status_t 103 TShowHideMenuItem::TeamShowHideCommon(int32 action, const BList *teamList, 104 BRect zoomRect, bool doZoom) 105 { 106 if (teamList == NULL) 107 return B_BAD_VALUE; 108 109 int32 count = teamList->CountItems(); 110 for (int32 index = 0; index < count; index++) { 111 team_id team = (team_id)teamList->ItemAt(index); 112 113 switch (action) { 114 case B_MINIMIZE_WINDOW: 115 do_minimize_team(zoomRect, team, doZoom && index == 0); 116 break; 117 118 case B_BRING_TO_FRONT: 119 do_bring_to_front_team(zoomRect, team, doZoom && index == 0); 120 break; 121 122 case B_QUIT_REQUESTED: 123 { 124 BMessenger messenger((char *)NULL, team); 125 uint32 command = B_QUIT_REQUESTED; 126 app_info aInfo; 127 be_roster->GetRunningAppInfo(team, &aInfo); 128 129 if (strcasecmp(aInfo.signature, kTrackerSignature) == 0) 130 command = 'Tall'; 131 132 messenger.SendMessage(command); 133 break; 134 } 135 } 136 } 137 138 return B_OK; 139 } 140 141