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 17BSeparatorItem::BSeparatorItem() 18 : 19 BMenuItem("", NULL) 20{ 21 BMenuItem::SetEnabled(false); 22} 23 24 25BSeparatorItem::BSeparatorItem(BMessage* data) 26 : 27 BMenuItem(data) 28{ 29 BMenuItem::SetEnabled(false); 30} 31 32 33BSeparatorItem::~BSeparatorItem() 34{ 35} 36 37 38status_t 39BSeparatorItem::Archive(BMessage* data, bool deep) const 40{ 41 return BMenuItem::Archive(data, deep); 42} 43 44 45BArchivable* 46BSeparatorItem::Instantiate(BMessage* data) 47{ 48 if (validate_instantiation(data, "BSeparatorItem")) 49 return new BSeparatorItem(data); 50 51 return NULL; 52} 53 54 55void 56BSeparatorItem::SetEnabled(bool enable) 57{ 58 // Don't do anything - we don't want to get enabled ever 59} 60 61 62void 63BSeparatorItem::GetContentSize(float* _width, float* _height) 64{ 65 if (Menu() != NULL && Menu()->Layout() == B_ITEMS_IN_ROW) { 66 if (_width != NULL) 67 *_width = 2.0; 68 69 if (_height != NULL) 70 *_height = 2.0; 71 } else { 72 if (_width != NULL) 73 *_width = 2.0; 74 75 if (_height != NULL) { 76 BFont font(be_plain_font); 77 if (Menu() != NULL) 78 Menu()->GetFont(&font); 79 80 const float height = floorf((font.Size() * 0.8) / 2) * 2; 81 *_height = max_c(4, height); 82 } 83 } 84} 85 86 87void 88BSeparatorItem::Draw() 89{ 90 BMenu *menu = Menu(); 91 if (menu == NULL) 92 return; 93 94 BRect bounds = Frame(); 95 rgb_color oldColor = menu->HighColor(); 96 rgb_color lowColor = menu->LowColor(); 97 98 if (menu->Layout() == B_ITEMS_IN_ROW) { 99 const float startLeft = bounds.left + (floor(bounds.Width())) / 2; 100 menu->SetHighColor(tint_color(lowColor, B_DARKEN_1_TINT)); 101 menu->StrokeLine(BPoint(startLeft, bounds.top + 1.0f), 102 BPoint(startLeft, bounds.bottom - 1.0f)); 103 menu->SetHighColor(tint_color(lowColor, B_LIGHTEN_2_TINT)); 104 menu->StrokeLine(BPoint(startLeft + 1.0f, bounds.top + 1.0f), 105 BPoint(startLeft + 1.0f, bounds.bottom - 1.0f)); 106 } else { 107 const float startTop = bounds.top + (floor(bounds.Height())) / 2; 108 menu->SetHighColor(tint_color(lowColor, B_DARKEN_1_TINT)); 109 menu->StrokeLine(BPoint(bounds.left + 1.0f, startTop), 110 BPoint(bounds.right - 1.0f, startTop)); 111 menu->SetHighColor(tint_color(lowColor, B_LIGHTEN_2_TINT)); 112 menu->StrokeLine(BPoint(bounds.left + 1.0f, startTop + 1.0f), 113 BPoint(bounds.right - 1.0f, startTop + 1.0f)); 114 } 115 menu->SetHighColor(oldColor); 116} 117 118 119// #pragma mark - private 120 121 122void BSeparatorItem::_ReservedSeparatorItem1() {} 123void BSeparatorItem::_ReservedSeparatorItem2() {} 124 125 126BSeparatorItem & 127BSeparatorItem::operator=(const BSeparatorItem &) 128{ 129 return *this; 130} 131