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