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
BSeparatorItem()17 BSeparatorItem::BSeparatorItem()
18 :
19 BMenuItem("", NULL)
20 {
21 BMenuItem::SetEnabled(false);
22 }
23
24
BSeparatorItem(BMessage * data)25 BSeparatorItem::BSeparatorItem(BMessage* data)
26 :
27 BMenuItem(data)
28 {
29 BMenuItem::SetEnabled(false);
30 }
31
32
~BSeparatorItem()33 BSeparatorItem::~BSeparatorItem()
34 {
35 }
36
37
38 status_t
Archive(BMessage * data,bool deep) const39 BSeparatorItem::Archive(BMessage* data, bool deep) const
40 {
41 return BMenuItem::Archive(data, deep);
42 }
43
44
45 BArchivable*
Instantiate(BMessage * data)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
SetEnabled(bool enable)56 BSeparatorItem::SetEnabled(bool enable)
57 {
58 // Don't do anything - we don't want to get enabled ever
59 }
60
61
62 void
GetContentSize(float * _width,float * _height)63 BSeparatorItem::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
87 void
Draw()88 BSeparatorItem::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
_ReservedSeparatorItem1()122 void BSeparatorItem::_ReservedSeparatorItem1() {}
_ReservedSeparatorItem2()123 void BSeparatorItem::_ReservedSeparatorItem2() {}
124
125
126 BSeparatorItem &
operator =(const BSeparatorItem &)127 BSeparatorItem::operator=(const BSeparatorItem &)
128 {
129 return *this;
130 }
131