xref: /haiku/src/kits/interface/SeparatorItem.cpp (revision aff60bb217827097c13d643275fdf1f1c66e7f17)
1 //------------------------------------------------------------------------------
2 //	Copyright (c) 2001-2005 Haiku, Inc.
3 //
4 //	Permission is hereby granted, free of charge, to any person obtaining a
5 //	copy of this software and associated documentation files (the "Software"),
6 //	to deal in the Software without restriction, including without limitation
7 //	the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 //	and/or sell copies of the Software, and to permit persons to whom the
9 //	Software is furnished to do so, subject to the following conditions:
10 //
11 //	The above copyright notice and this permission notice shall be included in
12 //	all copies or substantial portions of the Software.
13 //
14 //	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 //	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 //	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 //	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 //	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 //	FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 //	DEALINGS IN THE SOFTWARE.
21 //
22 //	File Name:		SeparatorItem.cpp
23 //	Author:			Marc Flerackers (mflerackers@androme.be)
24 //					Bill Hayden (haydentech@users.sourceforge.net)
25 //					Stefano Ceccherini (burton666@libero.it)
26 //	Description:	Display separator item for BMenu class
27 //
28 //------------------------------------------------------------------------------
29 #include <MenuItem.h>
30 
31 
32 BSeparatorItem::BSeparatorItem()
33 	:	BMenuItem(NULL, NULL, 0, 0)
34 {
35 }
36 
37 
38 BSeparatorItem::BSeparatorItem(BMessage *data)
39 	:	BMenuItem(data)
40 {
41 }
42 
43 
44 BSeparatorItem::~BSeparatorItem()
45 {
46 }
47 
48 
49 status_t
50 BSeparatorItem::Archive(BMessage *data, bool deep) const
51 {
52 	return BMenuItem::Archive(data, deep);
53 }
54 
55 
56 BArchivable *
57 BSeparatorItem::Instantiate(BMessage *data)
58 {
59 	if (validate_instantiation(data, "BSeparatorItem"))
60 		return new BSeparatorItem(data);
61 	else
62 		return NULL;
63 }
64 
65 
66 void
67 BSeparatorItem::SetEnabled(bool state)
68 {
69 	// Don't do anything
70 }
71 
72 
73 void
74 BSeparatorItem::GetContentSize(float *width, float *height)
75 {
76 	if (width != NULL)
77 		*width = 2.0f;
78 	if (height != NULL)
79 		*height = 8.0f;
80 }
81 
82 
83 void
84 BSeparatorItem::Draw()
85 {
86 	BMenu *menu = Menu();
87 	if (menu == NULL)
88 		return;
89 
90 	BRect bounds = Frame();
91 	rgb_color oldColor = menu->HighColor();
92 
93 	menu_info menuInfo;
94 	get_menu_info(&menuInfo);
95 	switch (menuInfo.separator) {
96 		case 0:
97 			menu->SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR),
98 				B_DARKEN_1_TINT));
99 			menu->StrokeLine(BPoint(bounds.left + 1.0f, bounds.top + 4.0f),
100 				BPoint(bounds.right - 1.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 + 1.0f, bounds.top + 5.0f),
104 				BPoint(bounds.right - 1.0f, bounds.top + 5.0f));
105 			break;
106 
107 		case 1:
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->SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR),
113 				B_LIGHTEN_2_TINT));
114 			menu->StrokeLine(BPoint(bounds.left + 9.0f, bounds.top + 5.0f),
115 				BPoint(bounds.right - 9.0f, bounds.top + 5.0f));
116 			break;
117 
118 		case 2:
119 			menu->SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR),
120 				B_DARKEN_1_TINT));
121 			menu->StrokeLine(BPoint(bounds.left + 9.0f, bounds.top + 4.0f),
122 				BPoint(bounds.right - 9.0f, bounds.top + 4.0f));
123 			menu->StrokeLine(BPoint(bounds.left + 10.0f, bounds.top + 5.0f),
124 				BPoint(bounds.right - 10.0f, bounds.top + 5.0f));
125 			menu->SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR),
126 				B_LIGHTEN_2_TINT));
127 			menu->StrokeLine(BPoint(bounds.left + 11.0f, bounds.top + 6.0f),
128 				BPoint(bounds.right - 11.0f, bounds.top + 6.0f));
129 			break;
130 
131 		default:
132 			break;
133 	}
134 
135 	menu->SetHighColor(oldColor);
136 }
137 
138 
139 void BSeparatorItem::_ReservedSeparatorItem1() {}
140 void BSeparatorItem::_ReservedSeparatorItem2() {}
141 
142 
143 BSeparatorItem &
144 BSeparatorItem::operator=(const BSeparatorItem &)
145 {
146 	return *this;
147 }
148