xref: /haiku/src/kits/interface/ControlLook.cpp (revision cbe0a0c436162d78cc3f92a305b64918c839d079)
1 /*
2  * Copyright 2012-2020 Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include <ControlLook.h>
8 
9 #include <binary_compatibility/Interface.h>
10 
11 
12 namespace BPrivate {
13 
14 
15 BControlLook::BControlLook()
16 	:
17 	fCachedWorkspace(-1)
18 {
19 }
20 
21 
22 BControlLook::~BControlLook()
23 {
24 }
25 
26 
27 float
28 BControlLook::ComposeSpacing(float spacing)
29 {
30 	switch ((int)spacing) {
31 		case B_USE_DEFAULT_SPACING:
32 		case B_USE_ITEM_SPACING:
33 			return be_control_look->DefaultItemSpacing();
34 		case B_USE_HALF_ITEM_SPACING:
35 			return ceilf(be_control_look->DefaultItemSpacing() * 0.5f);
36 		case B_USE_WINDOW_SPACING:
37 			return be_control_look->DefaultItemSpacing();
38 		case B_USE_SMALL_SPACING:
39 			return ceilf(be_control_look->DefaultItemSpacing() * 0.7f);
40 		case B_USE_BIG_SPACING:
41 			return ceilf(be_control_look->DefaultItemSpacing() * 1.3f);
42 	}
43 
44 	return spacing;
45 }
46 
47 
48 void
49 BControlLook::DrawLabel(BView* view, const char* label, const BBitmap* icon,
50 	BRect rect, const BRect& updateRect, const rgb_color& base, uint32 flags,
51 	const rgb_color* textColor)
52 {
53 	DrawLabel(view, label, icon, rect, updateRect, base, flags,
54 		DefaultLabelAlignment(), textColor);
55 }
56 
57 
58 void
59 BControlLook::GetInsets(frame_type frameType, background_type backgroundType,
60 	uint32 flags, float& _left, float& _top, float& _right, float& _bottom)
61 {
62 	GetFrameInsets(frameType, flags, _left, _top, _right, _bottom);
63 
64 	float left, top, right, bottom;
65 	GetBackgroundInsets(backgroundType, flags, left, top, right, bottom);
66 
67 	_left += left;
68 	_top += top;
69 	_right += right;
70 	_bottom += bottom;
71 }
72 
73 
74 float
75 BControlLook::GetScrollBarWidth(orientation orientation)
76 {
77 	// this matches HaikuControlLook.cpp currently
78 	if (be_plain_font->Size() <= 12.0f)
79 		return 14.0f;
80 	return be_plain_font->Size() / 12.0f * 14.0f;
81 }
82 
83 
84 void
85 BControlLook::SetBackgroundInfo(const BMessage& backgroundInfo)
86 {
87 	fBackgroundInfo = backgroundInfo;
88 	fCachedWorkspace = -1;
89 }
90 
91 
92 extern "C" void
93 B_IF_GCC_2(_ReservedControlLook1__Q28BPrivate12BControlLook,
94 		_ZN8BPrivate12BControlLook21_ReservedControlLook1Ev)(
95 	BControlLook* controlLook, BView* view, BRect& rect,
96 	const BRect& updateRect, const rgb_color& base, uint32 flags,
97 	uint32 borders, border_style borderStyle, uint32 side)
98 {
99 	controlLook->DrawTabFrame(view, rect, updateRect, base, flags, borders,
100 		borderStyle, side);
101 }
102 
103 
104 extern "C" void
105 B_IF_GCC_2(_ReservedControlLook2__Q28BPrivate12BControlLook,
106 		_ZN8BPrivate12BControlLook21_ReservedControlLook2Ev)(
107 	BControlLook* controlLook, BView* view, BRect rect,
108 		const BRect& updateRect, const rgb_color& base, uint32 flags,
109 		int32 direction, orientation orientation, bool down)
110 {
111 	controlLook->DrawScrollBarButton(view, rect, updateRect, base, flags,
112 		direction, orientation, down);
113 }
114 
115 
116 extern "C" void
117 B_IF_GCC_2(_ReservedControlLook3__Q28BPrivate12BControlLook,
118 		_ZN8BPrivate12BControlLook21_ReservedControlLook3Ev)(
119 	BControlLook* controlLook, BView* view, BRect rect,
120 		const BRect& updateRect, const rgb_color& base, uint32 flags,
121 		int32 direction, orientation orientation, uint32 knobStyle)
122 {
123 	controlLook->DrawScrollBarThumb(view, rect, updateRect, base, flags,
124 		orientation, knobStyle);
125 }
126 
127 
128 extern "C" void
129 B_IF_GCC_2(_ReservedControlLook4__Q28BPrivate12BControlLook,
130 		_ZN8BPrivate12BControlLook21_ReservedControlLook4Ev)(
131 	BControlLook* controlLook, BView* view, BRect rect,
132 		const BRect& updateRect, const rgb_color& base, uint32 flags,
133 		orientation orientation)
134 {
135 	controlLook->DrawScrollBarBorder(view, rect, updateRect, base, flags,
136 		orientation);
137 }
138 
139 
140 extern "C" float
141 B_IF_GCC_2(_ReservedControlLook5__Q28BPrivate12BControlLook,
142 		_ZN8BPrivate12BControlLook21_ReservedControlLook5Ev)(
143 	BControlLook* controlLook, orientation orientation)
144 {
145 	return controlLook->GetScrollBarWidth(orientation);
146 }
147 
148 
149 void BControlLook::_ReservedControlLook6() {}
150 void BControlLook::_ReservedControlLook7() {}
151 void BControlLook::_ReservedControlLook8() {}
152 void BControlLook::_ReservedControlLook9() {}
153 void BControlLook::_ReservedControlLook10() {}
154 
155 
156 // Initialized in InterfaceDefs.cpp
157 BControlLook* be_control_look = NULL;
158 
159 } // namespace BPrivate
160