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