xref: /haiku/src/kits/interface/SeparatorItem.cpp (revision 1b8f7f13a3dc70e0e903cb94248220b40b732204)
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 #include <Font.h>
16 
17 
18 BSeparatorItem::BSeparatorItem()
19 	: BMenuItem("", NULL)
20 {
21 	BMenuItem::SetEnabled(false);
22 }
23 
24 
25 BSeparatorItem::BSeparatorItem(BMessage* archive)
26 	: BMenuItem(archive)
27 {
28 	BMenuItem::SetEnabled(false);
29 }
30 
31 
32 BSeparatorItem::~BSeparatorItem()
33 {
34 }
35 
36 
37 status_t
38 BSeparatorItem::Archive(BMessage* archive, bool deep) const
39 {
40 	return BMenuItem::Archive(archive, deep);
41 }
42 
43 
44 BArchivable *
45 BSeparatorItem::Instantiate(BMessage* archive)
46 {
47 	if (validate_instantiation(archive, "BSeparatorItem"))
48 		return new BSeparatorItem(archive);
49 
50 	return NULL;
51 }
52 
53 
54 void
55 BSeparatorItem::SetEnabled(bool state)
56 {
57 	// Don't do anything - we don't want to get enabled ever
58 }
59 
60 
61 void
62 BSeparatorItem::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 		*_height = floorf(font.Size() * 0.8);
72 	}
73 }
74 
75 
76 void
77 BSeparatorItem::Draw()
78 {
79 	BMenu *menu = Menu();
80 	if (menu == NULL)
81 		return;
82 
83 	BRect bounds = Frame();
84 	rgb_color oldColor = menu->HighColor();
85 	rgb_color lowColor = menu->LowColor();
86 
87 	menu->SetHighColor(tint_color(lowColor, 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(lowColor, B_LIGHTEN_2_TINT));
91 	menu->StrokeLine(BPoint(bounds.left + 1.0f, bounds.top + 5.0f),
92 		BPoint(bounds.right - 1.0f, bounds.top + 5.0f));
93 
94 	menu->SetHighColor(oldColor);
95 }
96 
97 
98 //	#pragma mark - private
99 
100 
101 void BSeparatorItem::_ReservedSeparatorItem1() {}
102 void BSeparatorItem::_ReservedSeparatorItem2() {}
103 
104 
105 BSeparatorItem &
106 BSeparatorItem::operator=(const BSeparatorItem &)
107 {
108 	return *this;
109 }
110