1 /* 2 * Copyright (c) 2001-2006, 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 16 17 BSeparatorItem::BSeparatorItem() 18 : BMenuItem("", NULL) 19 { 20 BMenuItem::SetEnabled(false); 21 } 22 23 24 BSeparatorItem::BSeparatorItem(BMessage* archive) 25 : BMenuItem(archive) 26 { 27 BMenuItem::SetEnabled(false); 28 } 29 30 31 BSeparatorItem::~BSeparatorItem() 32 { 33 } 34 35 36 status_t 37 BSeparatorItem::Archive(BMessage* archive, bool deep) const 38 { 39 return BMenuItem::Archive(archive, deep); 40 } 41 42 43 BArchivable * 44 BSeparatorItem::Instantiate(BMessage* archive) 45 { 46 if (validate_instantiation(archive, "BSeparatorItem")) 47 return new BSeparatorItem(archive); 48 49 return NULL; 50 } 51 52 53 void 54 BSeparatorItem::SetEnabled(bool state) 55 { 56 // Don't do anything - we don't want to get enabled ever 57 } 58 59 60 void 61 BSeparatorItem::GetContentSize(float* _width, float* _height) 62 { 63 if (_width != NULL) 64 *_width = 2.0f; 65 66 if (_height != NULL) 67 *_height = 8.0f; 68 } 69 70 71 void 72 BSeparatorItem::Draw() 73 { 74 BMenu *menu = Menu(); 75 if (menu == NULL) 76 return; 77 78 BRect bounds = Frame(); 79 rgb_color oldColor = menu->HighColor(); 80 81 // TODO: remove superfluous separators 82 menu_info menuInfo; 83 get_menu_info(&menuInfo); 84 switch (menuInfo.separator) { 85 case 0: 86 menu->SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), 87 B_DARKEN_1_TINT)); 88 menu->StrokeLine(BPoint(bounds.left + 1.0f, bounds.top + 4.0f), 89 BPoint(bounds.right - 1.0f, bounds.top + 4.0f)); 90 menu->SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), 91 B_LIGHTEN_2_TINT)); 92 menu->StrokeLine(BPoint(bounds.left + 1.0f, bounds.top + 5.0f), 93 BPoint(bounds.right - 1.0f, bounds.top + 5.0f)); 94 break; 95 96 case 1: 97 menu->SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), 98 B_DARKEN_1_TINT)); 99 menu->StrokeLine(BPoint(bounds.left + 9.0f, bounds.top + 4.0f), 100 BPoint(bounds.right - 9.0f, bounds.top + 4.0f)); 101 menu->SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), 102 B_LIGHTEN_2_TINT)); 103 menu->StrokeLine(BPoint(bounds.left + 9.0f, bounds.top + 5.0f), 104 BPoint(bounds.right - 9.0f, bounds.top + 5.0f)); 105 break; 106 107 case 2: 108 menu->SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), 109 B_DARKEN_1_TINT)); 110 menu->StrokeLine(BPoint(bounds.left + 9.0f, bounds.top + 4.0f), 111 BPoint(bounds.right - 9.0f, bounds.top + 4.0f)); 112 menu->StrokeLine(BPoint(bounds.left + 10.0f, bounds.top + 5.0f), 113 BPoint(bounds.right - 10.0f, bounds.top + 5.0f)); 114 menu->SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), 115 B_LIGHTEN_2_TINT)); 116 menu->StrokeLine(BPoint(bounds.left + 11.0f, bounds.top + 6.0f), 117 BPoint(bounds.right - 11.0f, bounds.top + 6.0f)); 118 break; 119 120 default: 121 break; 122 } 123 124 menu->SetHighColor(oldColor); 125 } 126 127 128 // #pragma mark - private 129 130 131 void BSeparatorItem::_ReservedSeparatorItem1() {} 132 void BSeparatorItem::_ReservedSeparatorItem2() {} 133 134 135 BSeparatorItem & 136 BSeparatorItem::operator=(const BSeparatorItem &) 137 { 138 return *this; 139 } 140