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