1/* 2 * Copyright (c) 2001-2010, Haiku, Inc. 3 * Distributed under the terms of the MIT license. 4 * 5 * Authors: 6 * Marc Flerackers (mflerackers@androme.be) 7 * Bill Hayden (haydentech@users.sourceforge.net) 8 * Stefano Ceccherini (burton666@libero.it) 9 */ 10 11/*! Display separator item for BMenu class */ 12 13 14#include <SeparatorItem.h> 15#include <Font.h> 16 17 18BSeparatorItem::BSeparatorItem() 19 : BMenuItem("", NULL) 20{ 21 BMenuItem::SetEnabled(false); 22} 23 24 25BSeparatorItem::BSeparatorItem(BMessage* archive) 26 : BMenuItem(archive) 27{ 28 BMenuItem::SetEnabled(false); 29} 30 31 32BSeparatorItem::~BSeparatorItem() 33{ 34} 35 36 37status_t 38BSeparatorItem::Archive(BMessage* archive, bool deep) const 39{ 40 return BMenuItem::Archive(archive, deep); 41} 42 43 44BArchivable * 45BSeparatorItem::Instantiate(BMessage* archive) 46{ 47 if (validate_instantiation(archive, "BSeparatorItem")) 48 return new BSeparatorItem(archive); 49 50 return NULL; 51} 52 53 54void 55BSeparatorItem::SetEnabled(bool state) 56{ 57 // Don't do anything - we don't want to get enabled ever 58} 59 60 61void 62BSeparatorItem::GetContentSize(float* _width, float* _height) 63{ 64 if (_width != NULL) 65 *_width = 2.0; 66 67 if (_height != NULL) { 68 BFont font(be_plain_font); 69 if (Menu()) 70 Menu()->GetFont(&font); 71 const float height = floorf((font.Size() * 0.8) / 2) * 2; 72 *_height = max_c(4, height); 73 } 74} 75 76 77void 78BSeparatorItem::Draw() 79{ 80 BMenu *menu = Menu(); 81 if (menu == NULL) 82 return; 83 84 BRect bounds = Frame(); 85 rgb_color oldColor = menu->HighColor(); 86 rgb_color lowColor = menu->LowColor(); 87 88 const float startTop = bounds.top + (floor(bounds.Height())) / 2; 89 menu->SetHighColor(tint_color(lowColor, B_DARKEN_1_TINT)); 90 menu->StrokeLine(BPoint(bounds.left + 1.0f, startTop), 91 BPoint(bounds.right - 1.0f, startTop)); 92 menu->SetHighColor(tint_color(lowColor, B_LIGHTEN_2_TINT)); 93 menu->StrokeLine(BPoint(bounds.left + 1.0f, startTop + 1.0f), 94 BPoint(bounds.right - 1.0f, startTop + 1.0f)); 95 96 menu->SetHighColor(oldColor); 97} 98 99 100// #pragma mark - private 101 102 103void BSeparatorItem::_ReservedSeparatorItem1() {} 104void BSeparatorItem::_ReservedSeparatorItem2() {} 105 106 107BSeparatorItem & 108BSeparatorItem::operator=(const BSeparatorItem &) 109{ 110 return *this; 111} 112