btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / apps / processcontroller / IconMenuItem.cpp
blob06835bfe9b77b3ea638976e8b2ba066d754fbe6c
1 /*
3 IconMenuItem.cpp
5 ProcessController
6 (c) 2000, Georges-Edouard Berenger, All Rights Reserved.
7 Copyright (C) 2004 beunited.org
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 2.1 of the License, or (at your option) any later version.
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "IconMenuItem.h"
26 #include <Application.h>
27 #include <NodeInfo.h>
28 #include <Bitmap.h>
29 #include <Roster.h>
32 IconMenuItem::IconMenuItem(BBitmap* icon, const char* title,
33 BMessage* msg, bool drawText, bool purge)
34 : BMenuItem(title, msg),
35 fIcon(icon),
36 fDrawText(drawText),
37 fPurge(purge)
39 if (!fIcon)
40 DefaultIcon(NULL);
44 IconMenuItem::IconMenuItem(BBitmap* icon, BMenu* menu, bool drawText, bool purge)
45 : BMenuItem(menu),
46 fIcon(icon),
47 fDrawText(drawText),
48 fPurge(purge)
51 if (!fIcon)
52 DefaultIcon(NULL);
56 IconMenuItem::IconMenuItem(const char* mime, const char* title, BMessage* msg, bool drawText)
57 : BMenuItem(title, msg),
58 fIcon(NULL),
59 fDrawText(drawText)
61 DefaultIcon(mime);
65 IconMenuItem::~IconMenuItem()
67 if (fPurge && fIcon)
68 delete fIcon;
72 void IconMenuItem::DrawContent()
74 BPoint loc;
76 DrawIcon();
77 if (fDrawText) {
78 loc = ContentLocation();
79 loc.x += 20;
80 Menu()->MovePenTo(loc);
81 BMenuItem::DrawContent();
86 void
87 IconMenuItem::Highlight(bool hilited)
89 BMenuItem::Highlight(hilited);
90 DrawIcon();
94 void
95 IconMenuItem::DrawIcon()
97 // TODO: exact code duplication with TeamBarMenuItem::DrawIcon()
98 if (!fIcon)
99 return;
101 BPoint loc = ContentLocation();
102 BRect frame = Frame();
104 loc.y = frame.top + (frame.bottom - frame.top - 15) / 2;
106 BMenu* menu = Menu();
108 if (fIcon->ColorSpace() == B_RGBA32) {
109 menu->SetDrawingMode(B_OP_ALPHA);
110 menu->SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY);
111 } else
112 menu->SetDrawingMode(B_OP_OVER);
114 menu->DrawBitmap(fIcon, loc);
116 menu->SetDrawingMode(B_OP_COPY);
120 void
121 IconMenuItem::GetContentSize(float* width, float* height)
123 BMenuItem::GetContentSize(width, height);
124 int limit = IconMenuItem::MinHeight();
125 if (*height < limit)
126 *height = limit;
127 if (fDrawText)
128 *width += 20;
129 else
130 *width = 16;
134 void
135 IconMenuItem::DefaultIcon(const char* mime)
137 BRect rect(0, 0, 15, 15);
138 fIcon = new BBitmap(rect, B_COLOR_8_BIT);
139 if (mime) {
140 BMimeType mimeType(mime);
141 if (mimeType.GetIcon(fIcon, B_MINI_ICON) != B_OK)
142 fDrawText = true;
143 } else {
144 app_info info;
145 be_app->GetAppInfo(&info);
146 if (BNodeInfo::GetTrackerIcon(&info.ref, fIcon, B_MINI_ICON) != B_OK)
147 fDrawText = true;
149 fPurge = true;
153 int IconMenuItem::MinHeight()
155 static int minheight = -1;
156 if (minheight < 0)
157 minheight = 17;
158 return minheight;