xref: /haiku/src/apps/deskbar/BarMenuTitle.cpp (revision 4f00613311d0bd6b70fa82ce19931c41f071ea4e)
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 <Bitmap.h>
37 
38 #include "BarApp.h"
39 #include "BarMenuTitle.h"
40 #include "BarView.h"
41 #include "BarWindow.h"
42 #include "ExpandoMenuBar.h"
43 
44 
45 TBarMenuTitle::TBarMenuTitle(float width, float height, const BBitmap *icon,
46 	BMenu *menu, bool inexpando)
47 	:	BMenuItem(menu, new BMessage(B_REFS_RECEIVED)),
48 		fWidth(width),
49 		fHeight(height),
50 		fInExpando(inexpando),
51 		fIcon(icon)
52 {
53 }
54 
55 
56 TBarMenuTitle::~TBarMenuTitle()
57 {
58 }
59 
60 
61 void
62 TBarMenuTitle::SetWidthHeight(float width, float height)
63 {
64 	fWidth = width;
65 	fHeight = height;
66 }
67 
68 
69 void
70 TBarMenuTitle::GetContentSize(float *width, float *height)
71 {
72 	*width = fWidth;
73 	*height = fHeight;
74 }
75 
76 
77 void
78 TBarMenuTitle::Draw()
79 {
80 	BMenuItem::Draw();
81 }
82 
83 
84 void
85 TBarMenuTitle::DrawContent()
86 {
87 	BMenu *menu = Menu();
88 	BRect frame(Frame());
89 	rgb_color menuColor = ui_color(B_MENU_BACKGROUND_COLOR);
90 	rgb_color dark = tint_color(menuColor, B_DARKEN_1_TINT);
91 	rgb_color light = tint_color(menuColor, B_LIGHTEN_2_TINT);
92 	rgb_color black = {0, 0, 0, 255};
93 
94 	bool inExpandoMode = dynamic_cast<TExpandoMenuBar*>(menu) != NULL;
95 
96 	BRect bounds(menu->Window()->Bounds());
97 	if (bounds.right < frame.right)
98 		frame.right = bounds.right;
99 
100 	menu->SetDrawingMode(B_OP_COPY);
101 
102 	if (!IsSelected() && !menu->IsRedrawAfterSticky()) {
103 		menu->BeginLineArray(8);
104 		menu->AddLine(frame.RightTop(), frame.LeftTop(), light);
105 		menu->AddLine(frame.LeftBottom(), frame.RightBottom(), dark);
106 		menu->AddLine(frame.LeftTop(),
107 			frame.LeftBottom()+BPoint(0, inExpandoMode ? 0 : -1), light);
108 		menu->AddLine(frame.RightBottom(), frame.RightTop(), dark);
109 		if (inExpandoMode) {
110 			frame.top += 1;
111 			menu->AddLine(frame.LeftTop(), frame.RightTop() + BPoint(-1, 0), light);
112 		}
113 
114 		menu->EndLineArray();
115 
116 		frame.InsetBy(1, 1);
117 		menu->SetHighColor(menuColor);
118 		menu->FillRect(frame);
119 		menu->SetHighColor(black);
120 		frame.InsetBy(-1, -1);
121 		if (inExpandoMode)
122 			frame.top -= 1;
123 	}
124 
125 	ASSERT(IsEnabled());
126 	if (IsSelected() && !menu->IsRedrawAfterSticky()) {
127 		menu->SetHighColor(tint_color(menuColor, B_HIGHLIGHT_BACKGROUND_TINT));
128 		menu->FillRect(frame);
129 
130 		if (menu->IndexOf(this) > 0) {
131 			menu->SetHighColor(tint_color(menuColor, B_DARKEN_4_TINT));
132 			menu->StrokeLine(frame.LeftTop(), frame.LeftBottom());
133 		}
134 
135 		menu->SetHighColor(black);
136 	}
137 
138 	menu->SetDrawingMode(B_OP_ALPHA);
139 
140 	if (fIcon != NULL) {
141 		BRect dstRect(fIcon->Bounds());
142 		dstRect.OffsetTo(frame.LeftTop());
143 		dstRect.OffsetBy(rintf(((frame.Width() - dstRect.Width()) / 2) - 1.0f),
144 			rintf(((frame.Height() - dstRect.Height()) / 2) - 0.0f));
145 
146 		menu->DrawBitmapAsync(fIcon, dstRect);
147 	}
148 }
149 
150 
151 status_t
152 TBarMenuTitle::Invoke(BMessage *message)
153 {
154 	TBarView *barview = dynamic_cast<TBarApp *>(be_app)->BarView();
155 	if (barview) {
156 		BLooper *looper = barview->Looper();
157 		if (looper->Lock()) {
158 			// tell barview to add the refs to the be menu
159 			barview->HandleBeMenu(NULL);
160 			looper->Unlock();
161 		}
162 	}
163 
164 	return BMenuItem::Invoke(message);
165 }
166