1/* 2Open Tracker License 3 4Terms and Conditions 5 6Copyright (c) 1991-2000, Be Incorporated. All rights reserved. 7 8Permission is hereby granted, free of charge, to any person obtaining a copy of 9this software and associated documentation files (the "Software"), to deal in 10the Software without restriction, including without limitation the rights to 11use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 12of the Software, and to permit persons to whom the Software is furnished to do 13so, subject to the following conditions: 14 15The above copyright notice and this permission notice applies to all licensees 16and shall be included in all copies or substantial portions of the Software. 17 18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY, 20FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 22AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION 23WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 25Except as contained in this notice, the name of Be Incorporated shall not be 26used in advertising or otherwise to promote the sale, use or other dealings in 27this Software without prior written authorization from Be Incorporated. 28 29Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks 30of Be Incorporated in the United States and other countries. Other brand product 31names are registered trademarks or trademarks of their respective holders. 32All 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 45MiniMenuField::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 55MiniMenuField::~MiniMenuField() 56{ 57 delete fMenu; 58} 59 60 61void 62MiniMenuField::AttachedToWindow() 63{ 64 AdoptParentColors(); 65 SetHighColor(0, 0, 0); 66} 67 68 69void 70MiniMenuField::MakeFocus(bool on) 71{ 72 Invalidate(); 73 BView::MakeFocus(on); 74} 75 76 77void 78MiniMenuField::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 95void 96MiniMenuField::Draw(BRect) 97{ 98 BRect bounds(Bounds()); 99 bounds.OffsetBy(1, 2); 100 bounds.right--; 101 bounds.bottom -= 2; 102 if (IsFocus()) { 103 // draw the focus indicator border 104 SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR)); 105 StrokeRect(bounds); 106 } 107 bounds.right--; 108 bounds.bottom--; 109 BRect rect(bounds); 110 rect.InsetBy(1, 1); 111 112 rgb_color darkest = tint_color(kBlack, 0.6f); 113 rgb_color dark = tint_color(kBlack, 0.4f); 114 rgb_color medium = dark; 115 rgb_color light = tint_color(kBlack, 0.03f); 116 117 SetHighColor(medium); 118 119 // draw frame and shadow 120 BeginLineArray(10); 121 AddLine(rect.RightTop(), rect.RightBottom(), darkest); 122 AddLine(rect.RightBottom(), rect.LeftBottom(), darkest); 123 AddLine(rect.LeftBottom(), rect.LeftTop(), medium); 124 AddLine(rect.LeftTop(), rect.RightTop(), medium); 125 AddLine(bounds.LeftBottom() + BPoint(2, 0), bounds.RightBottom(), dark); 126 AddLine(bounds.RightTop() + BPoint(0, 1), bounds.RightBottom(), dark); 127 rect.InsetBy(1, 1); 128 AddLine(rect.RightTop(), rect.RightBottom(), medium); 129 AddLine(rect.RightBottom(), rect.LeftBottom(), medium); 130 AddLine(rect.LeftBottom(), rect.LeftTop(), light); 131 AddLine(rect.LeftTop(), rect.RightTop(), light); 132 EndLineArray(); 133 134 // draw triangle 135 rect = BRect(0, 0, 12, 12); 136 rect.OffsetBy(4, 4); 137 const rgb_color arrowColor = {150, 150, 150, 255}; 138 float tint = Window()->IsActive() ? B_DARKEN_3_TINT : B_DARKEN_1_TINT; 139 140 SetDrawingMode(B_OP_COPY); 141 be_control_look->DrawArrowShape(this, rect, rect, arrowColor, 142 BControlLook::B_RIGHT_ARROW, 0, tint); 143} 144 145 146void 147MiniMenuField::MouseDown(BPoint) 148{ 149 fMenu->Go(ConvertToScreen(BPoint(4, 4)), true); 150} 151