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 30 trademarks of Be Incorporated in the United States and other countries. Other 31 brand product names are registered trademarks or trademarks of their respective 32 holders. 33 All rights reserved. 34 */ 35 36 37 #include "BarMenuTitle.h" 38 39 #include <Bitmap.h> 40 #include <ControlLook.h> 41 #include <Debug.h> 42 43 #include "BarApp.h" 44 #include "BarView.h" 45 #include "BarWindow.h" 46 #include "ExpandoMenuBar.h" 47 48 49 TBarMenuTitle::TBarMenuTitle(float width, float height, const BBitmap* icon, 50 BMenu* menu, bool expando) 51 : 52 BMenuItem(menu, new BMessage(B_REFS_RECEIVED)), 53 fWidth(width), 54 fHeight(height), 55 fInExpando(expando), 56 fIcon(icon) 57 { 58 } 59 60 61 TBarMenuTitle::~TBarMenuTitle() 62 { 63 } 64 65 66 void 67 TBarMenuTitle::SetContentSize(float width, float height) 68 { 69 fWidth = width; 70 fHeight = height; 71 } 72 73 74 void 75 TBarMenuTitle::GetContentSize(float* width, float* height) 76 { 77 *width = fWidth; 78 *height = fHeight; 79 } 80 81 82 void 83 TBarMenuTitle::Draw() 84 { 85 if (be_control_look == NULL) { 86 BMenuItem::Draw(); 87 return; 88 } 89 90 // fill background if selected 91 rgb_color base = Menu()->LowColor(); 92 BRect rect = Frame(); 93 94 BRect windowBounds = Menu()->Window()->Bounds(); 95 if (rect.right > windowBounds.right) 96 rect.right = windowBounds.right; 97 98 if (IsSelected()) { 99 be_control_look->DrawMenuItemBackground(Menu(), rect, rect, base, 100 BControlLook::B_ACTIVATED); 101 } else { 102 be_control_look->DrawButtonBackground(Menu(), rect, rect, base); 103 } 104 105 // draw content 106 DrawContent(); 107 108 // make sure we restore state 109 Menu()->SetLowColor(base); 110 } 111 112 113 void 114 TBarMenuTitle::DrawContent() 115 { 116 BMenu* menu = Menu(); 117 BRect frame(Frame()); 118 119 if (be_control_look != NULL) { 120 menu->SetDrawingMode(B_OP_ALPHA); 121 122 if (fIcon != NULL) { 123 BRect dstRect(fIcon->Bounds()); 124 dstRect.OffsetTo(frame.LeftTop()); 125 dstRect.OffsetBy(rintf(((frame.Width() - dstRect.Width()) / 2) 126 - 1.0f), rintf(((frame.Height() - dstRect.Height()) / 2) 127 + 2.0f)); 128 129 menu->DrawBitmapAsync(fIcon, dstRect); 130 } 131 return; 132 } 133 134 rgb_color menuColor = menu->LowColor(); 135 rgb_color dark = tint_color(menuColor, B_DARKEN_1_TINT); 136 rgb_color light = tint_color(menuColor, B_LIGHTEN_2_TINT); 137 138 bool inExpandoMode = dynamic_cast<TExpandoMenuBar*>(menu) != NULL; 139 140 BRect bounds(menu->Window()->Bounds()); 141 if (bounds.right < frame.right) 142 frame.right = bounds.right; 143 144 menu->SetDrawingMode(B_OP_COPY); 145 146 if (!IsSelected() && !menu->IsRedrawAfterSticky()) { 147 menu->BeginLineArray(8); 148 menu->AddLine(frame.RightTop(), frame.LeftTop(), light); 149 menu->AddLine(frame.LeftBottom(), frame.RightBottom(), dark); 150 menu->AddLine(frame.LeftTop(), 151 frame.LeftBottom()+BPoint(0, inExpandoMode ? 0 : -1), light); 152 menu->AddLine(frame.RightBottom(), frame.RightTop(), dark); 153 if (inExpandoMode) { 154 frame.top += 1; 155 menu->AddLine(frame.LeftTop(), frame.RightTop() + BPoint(-1, 0), 156 light); 157 } 158 159 menu->EndLineArray(); 160 161 frame.InsetBy(1, 1); 162 menu->SetHighColor(menuColor); 163 menu->FillRect(frame); 164 if (IsSelected()) 165 menu->SetHighColor(ui_color(B_MENU_SELECTED_ITEM_TEXT_COLOR)); 166 else 167 menu->SetHighColor(ui_color(B_MENU_ITEM_TEXT_COLOR)); 168 frame.InsetBy(-1, -1); 169 if (inExpandoMode) 170 frame.top -= 1; 171 } 172 173 ASSERT(IsEnabled()); 174 if (IsSelected() && !menu->IsRedrawAfterSticky()) { 175 menu->SetHighColor(tint_color(menuColor, B_HIGHLIGHT_BACKGROUND_TINT)); 176 menu->FillRect(frame); 177 178 if (menu->IndexOf(this) > 0) { 179 menu->SetHighColor(tint_color(menuColor, B_DARKEN_4_TINT)); 180 menu->StrokeLine(frame.LeftTop(), frame.LeftBottom()); 181 } 182 183 if (IsSelected()) 184 menu->SetHighColor(ui_color(B_MENU_SELECTED_ITEM_TEXT_COLOR)); 185 else 186 menu->SetHighColor(ui_color(B_MENU_ITEM_TEXT_COLOR)); 187 } 188 189 menu->SetDrawingMode(B_OP_ALPHA); 190 191 if (fIcon != NULL) { 192 BRect dstRect(fIcon->Bounds()); 193 dstRect.OffsetTo(frame.LeftTop()); 194 dstRect.OffsetBy(rintf(((frame.Width() - dstRect.Width()) / 2) - 1.0f), 195 rintf(((frame.Height() - dstRect.Height()) / 2) - 0.0f)); 196 197 menu->DrawBitmapAsync(fIcon, dstRect); 198 } 199 } 200 201 202 status_t 203 TBarMenuTitle::Invoke(BMessage* message) 204 { 205 TBarView* barview = dynamic_cast<TBarApp*>(be_app)->BarView(); 206 if (barview) { 207 BLooper* looper = barview->Looper(); 208 if (looper->Lock()) { 209 // tell barview to add the refs to the deskbar menu 210 barview->HandleDeskbarMenu(NULL); 211 looper->Unlock(); 212 } 213 } 214 215 return BMenuItem::Invoke(message); 216 } 217