xref: /haiku/src/kits/tracker/MiniMenuField.cpp (revision a07cdb6e9f8e484b6ba9f209fbeb144e906d3405)
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 
36 #include <ControlLook.h>
37 #include <InterfaceDefs.h>
38 #include <PopUpMenu.h>
39 #include <Window.h>
40 
41 #include "MiniMenuField.h"
42 #include "Utilities.h"
43 
44 
45 MiniMenuField::MiniMenuField(BRect frame, const char* name, BPopUpMenu* menu,
46 	uint32 resizeFlags, uint32 flags)
47 	:
48 	BView(frame, name, resizeFlags, flags),
49 	fMenu(menu)
50 {
51 	SetFont(be_plain_font, B_FONT_FAMILY_AND_STYLE | B_FONT_SIZE);
52 }
53 
54 
55 MiniMenuField::~MiniMenuField()
56 {
57 	delete fMenu;
58 }
59 
60 
61 void
62 MiniMenuField::AttachedToWindow()
63 {
64 	if (Parent() != NULL) {
65 		SetViewColor(Parent()->ViewColor());
66 		SetLowColor(Parent()->ViewColor());
67 	}
68 
69 	SetHighColor(0, 0, 0);
70 }
71 
72 
73 void
74 MiniMenuField::MakeFocus(bool on)
75 {
76 	Invalidate();
77 	BView::MakeFocus(on);
78 }
79 
80 
81 void
82 MiniMenuField::KeyDown(const char* bytes, int32 numBytes)
83 {
84 	switch (bytes[0]) {
85 		case B_SPACE:
86 		case B_DOWN_ARROW:
87 		case B_RIGHT_ARROW:
88 			// invoke from keyboard
89 			fMenu->Go(ConvertToScreen(BPoint(4, 4)), true, true);
90 			break;
91 
92 		default:
93 			BView::KeyDown(bytes, numBytes);
94 			break;
95 	}
96 }
97 
98 
99 void
100 MiniMenuField::Draw(BRect)
101 {
102 	BRect bounds(Bounds());
103 	bounds.OffsetBy(1, 2);
104 	bounds.right--;
105 	bounds.bottom -= 2;
106 	if (IsFocus()) {
107 		// draw the focus indicator border
108 		SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR));
109 		StrokeRect(bounds);
110 	}
111 	bounds.right--;
112 	bounds.bottom--;
113 	BRect rect(bounds);
114 	rect.InsetBy(1, 1);
115 
116 	rgb_color darkest = tint_color(kBlack, 0.6f);
117 	rgb_color dark = tint_color(kBlack, 0.4f);
118 	rgb_color medium = dark;
119 	rgb_color light = tint_color(kBlack, 0.03f);
120 
121 	SetHighColor(medium);
122 
123 	// draw frame and shadow
124 	BeginLineArray(10);
125 	AddLine(rect.RightTop(), rect.RightBottom(), darkest);
126 	AddLine(rect.RightBottom(), rect.LeftBottom(), darkest);
127 	AddLine(rect.LeftBottom(), rect.LeftTop(), medium);
128 	AddLine(rect.LeftTop(), rect.RightTop(), medium);
129 	AddLine(bounds.LeftBottom() + BPoint(2, 0), bounds.RightBottom(), dark);
130 	AddLine(bounds.RightTop() + BPoint(0, 1), bounds.RightBottom(), dark);
131 	rect.InsetBy(1, 1);
132 	AddLine(rect.RightTop(), rect.RightBottom(), medium);
133 	AddLine(rect.RightBottom(), rect.LeftBottom(), medium);
134 	AddLine(rect.LeftBottom(), rect.LeftTop(), light);
135 	AddLine(rect.LeftTop(), rect.RightTop(), light);
136 	EndLineArray();
137 
138 	// draw triangle
139 	rect = BRect(0, 0, 12, 12);
140 	rect.OffsetBy(4, 4);
141 	const rgb_color arrowColor = {150, 150, 150, 255};
142 	float tint = Window()->IsActive() ? B_DARKEN_3_TINT : B_DARKEN_1_TINT;
143 
144 	SetDrawingMode(B_OP_COPY);
145 	be_control_look->DrawArrowShape(this, rect, rect, arrowColor,
146 		BControlLook::B_RIGHT_ARROW, 0, tint);
147 }
148 
149 
150 void
151 MiniMenuField::MouseDown(BPoint)
152 {
153 	fMenu->Go(ConvertToScreen(BPoint(4, 4)), true);
154 }
155