libroot/posix/stdio: Remove unused portions.
[haiku.git] / src / apps / deskbar / ShowHideMenuItem.cpp
blob28f7a09f7b0a6bec9d64577fbc25e00118a8f44f
1 /*
2 Open Tracker License
4 Terms and Conditions
6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
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:
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.
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.
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.
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.
37 #include "ShowHideMenuItem.h"
39 #include <Debug.h>
40 #include <Roster.h>
41 #include <WindowInfo.h>
43 #include "WindowMenuItem.h"
44 #include "tracker_private.h"
47 const int32 kDesktopWindow = 4;
48 const float kHPad = 10.0f;
49 const float kVPad = 2.0f;
52 TShowHideMenuItem::TShowHideMenuItem(const char* title, const BList* teams,
53 uint32 action)
55 BMenuItem(title, NULL),
56 fTeams(teams),
57 fAction(action)
59 BFont font(be_plain_font);
60 fTitleWidth = ceilf(font.StringWidth(title));
61 font_height fontHeight;
62 font.GetHeight(&fontHeight);
63 fTitleAscent = ceilf(fontHeight.ascent);
64 fTitleDescent = ceilf(fontHeight.descent + fontHeight.leading);
68 void
69 TShowHideMenuItem::GetContentSize(float* width, float* height)
71 *width = kHPad + fTitleWidth + kHPad;
72 *height = fTitleAscent + fTitleDescent;
73 *height += kVPad * 2;
77 void
78 TShowHideMenuItem::DrawContent()
80 BRect frame(Frame());
81 float labelHeight = fTitleAscent + fTitleDescent;
82 BPoint drawLoc;
83 drawLoc.x = kHPad;
84 drawLoc.y = ((frame.Height() - labelHeight) / 2);
85 Menu()->MovePenBy(drawLoc.x, drawLoc.y);
86 BMenuItem::DrawContent();
90 status_t
91 TShowHideMenuItem::Invoke(BMessage*)
93 bool doZoom = false;
94 BRect zoomRect(0, 0, 0, 0);
95 BMenuItem* item = Menu()->Superitem();
97 if (item->Menu()->Window() != NULL) {
98 zoomRect = item->Menu()->ConvertToScreen(item->Frame());
99 doZoom = true;
101 return TeamShowHideCommon(static_cast<int32>(fAction), fTeams, zoomRect,
102 doZoom);
106 status_t
107 TShowHideMenuItem::TeamShowHideCommon(int32 action, const BList* teamList,
108 BRect zoomRect, bool doZoom)
110 if (teamList == NULL)
111 return B_BAD_VALUE;
113 for (int32 i = teamList->CountItems() - 1; i >= 0; i--) {
114 team_id team = (addr_t)teamList->ItemAt(i);
116 switch (action) {
117 case B_MINIMIZE_WINDOW:
118 do_minimize_team(zoomRect, team, doZoom && i == 0);
119 break;
121 case B_BRING_TO_FRONT:
122 do_bring_to_front_team(zoomRect, team, doZoom && i == 0);
123 break;
125 case B_QUIT_REQUESTED:
127 BMessenger messenger((char*)NULL, team);
128 uint32 command = B_QUIT_REQUESTED;
129 app_info aInfo;
130 be_roster->GetRunningAppInfo(team, &aInfo);
132 if (strcasecmp(aInfo.signature, kTrackerSignature) == 0)
133 command = 'Tall';
135 messenger.SendMessage(command);
136 break;
141 return B_OK;