1/* 2Open Tracker License 3 4Terms and Conditions 5 6Copyright (c) 1991-2000, Be Incorporated. All rights reserved. 7 8Permission is hereby granted, free of charge, to any person obtaining a copy of 9this software and associated documentation files (the "Software"), to deal in 10the Software without restriction, including without limitation the rights to 11use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 12of the Software, and to permit persons to whom the Software is furnished to do 13so, subject to the following conditions: 14 15The above copyright notice and this permission notice applies to all licensees 16and shall be included in all copies or substantial portions of the Software. 17 18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY, 20FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 22AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION 23WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 25Except as contained in this notice, the name of Be Incorporated shall not be 26used in advertising or otherwise to promote the sale, use or other dealings in 27this Software without prior written authorization from Be Incorporated. 28 29Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered 30trademarks of Be Incorporated in the United States and other countries. Other 31brand product names are registered trademarks or trademarks of their respective 32holders. 33All rights reserved. 34*/ 35 36 37#include "ShowHideMenuItem.h" 38 39#include <malloc.h> 40#include <stdio.h> 41#include <string.h> 42 43#include <Debug.h> 44#include <Roster.h> 45 46#include "WindowMenuItem.h" 47#include "tracker_private.h" 48 49 50const int32 kDesktopWindow = 4; 51const float kHPad = 10.0f; 52const float kVPad = 2.0f; 53 54 55TShowHideMenuItem::TShowHideMenuItem(const char* title, const BList* teams, 56 uint32 action) 57 : 58 BMenuItem(title, NULL), 59 fTeams(teams), 60 fAction(action) 61{ 62 BFont font(be_plain_font); 63 fTitleWidth = ceilf(font.StringWidth(title)); 64 font_height fontHeight; 65 font.GetHeight(&fontHeight); 66 fTitleAscent = ceilf(fontHeight.ascent); 67 fTitleDescent = ceilf(fontHeight.descent + fontHeight.leading); 68} 69 70 71void 72TShowHideMenuItem::GetContentSize(float* width, float* height) 73{ 74 *width = kHPad + fTitleWidth + kHPad; 75 *height = fTitleAscent + fTitleDescent; 76 *height += kVPad * 2; 77} 78 79 80void 81TShowHideMenuItem::DrawContent() 82{ 83 BRect frame(Frame()); 84 float labelHeight = fTitleAscent + fTitleDescent; 85 BPoint drawLoc; 86 drawLoc.x = kHPad; 87 drawLoc.y = ((frame.Height() - labelHeight) / 2); 88 Menu()->MovePenBy(drawLoc.x, drawLoc.y); 89 BMenuItem::DrawContent(); 90} 91 92 93status_t 94TShowHideMenuItem::Invoke(BMessage*) 95{ 96 bool doZoom = false; 97 BRect zoomRect(0, 0, 0, 0); 98 BMenuItem* item = Menu()->Superitem(); 99 100 if (item->Menu()->Window() != NULL) { 101 zoomRect = item->Menu()->ConvertToScreen(item->Frame()); 102 doZoom = true; 103 } 104 return TeamShowHideCommon(static_cast<int32>(fAction), fTeams, zoomRect, 105 doZoom); 106} 107 108 109status_t 110TShowHideMenuItem::TeamShowHideCommon(int32 action, const BList* teamList, 111 BRect zoomRect, bool doZoom) 112{ 113 if (teamList == NULL) 114 return B_BAD_VALUE; 115 116 int32 count = teamList->CountItems(); 117 for (int32 index = 0; index < count; index++) { 118 team_id team = (addr_t)teamList->ItemAt(index); 119 120 switch (action) { 121 case B_MINIMIZE_WINDOW: 122 do_minimize_team(zoomRect, team, doZoom && index == 0); 123 break; 124 125 case B_BRING_TO_FRONT: 126 do_bring_to_front_team(zoomRect, team, doZoom && index == 0); 127 break; 128 129 case B_QUIT_REQUESTED: 130 { 131 BMessenger messenger((char*)NULL, team); 132 uint32 command = B_QUIT_REQUESTED; 133 app_info aInfo; 134 be_roster->GetRunningAppInfo(team, &aInfo); 135 136 if (strcasecmp(aInfo.signature, kTrackerSignature) == 0) 137 command = 'Tall'; 138 139 messenger.SendMessage(command); 140 break; 141 } 142 } 143 } 144 145 return B_OK; 146} 147