xref: /haiku/headers/os/interface/ControlLook.h (revision 68ea01249e1e2088933cb12f9c28d4e5c5d1c9ef)
1 /*
2  * Copyright 2009-2020 Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _CONTROL_LOOK_H
6 #define _CONTROL_LOOK_H
7 
8 
9 #include <Alignment.h>
10 #include <Font.h>
11 #include <Rect.h>
12 #include <Slider.h>
13 
14 
15 class BBitmap;
16 class BControl;
17 class BGradientLinear;
18 class BView;
19 
20 
21 // WARNING! This is experimental API and may change! Be prepared to
22 // recompile your software in a next version of haiku.
23 
24 
25 namespace BPrivate {
26 
27 
28 class BControlLook {
29 public:
30 								BControlLook();
31 	virtual						~BControlLook();
32 
33 	// TODO: Probably more convenient to pull these enums into global
34 	// namespace and rename them to e.g. "B_CONTROL_LOOK_FOCUSED" instead of
35 	// "BControlLook::B_FOCUSED".
36 
37 	enum frame_type {
38 		B_BUTTON_FRAME,
39 		B_GROUP_FRAME,
40 		B_MENU_FIELD_FRAME,
41 		B_SCROLL_VIEW_FRAME,
42 		B_TEXT_CONTROL_FRAME,
43 	};
44 
45 	enum background_type {
46 		B_BUTTON_BACKGROUND,
47 		B_BUTTON_WITH_POP_UP_BACKGROUND,
48 		B_MENU_BACKGROUND,
49 		B_MENU_BAR_BACKGROUND,
50 		B_MENU_FIELD_BACKGROUND,
51 		B_MENU_ITEM_BACKGROUND,
52 		B_HORIZONTAL_SCROLL_BAR_BACKGROUND,
53 		B_VERTICAL_SCROLL_BAR_BACKGROUND,
54 	};
55 
56 	enum {
57 		B_LEFT_BORDER		= 1 << 0,
58 		B_RIGHT_BORDER		= 1 << 1,
59 		B_TOP_BORDER		= 1 << 2,
60 		B_BOTTOM_BORDER		= 1 << 3,
61 
62 		B_ALL_BORDERS		= B_LEFT_BORDER | B_RIGHT_BORDER
63 								| B_TOP_BORDER | B_BOTTOM_BORDER
64 	};
65 
66 	enum {
67 		B_LEFT_ARROW		= 0,
68 		B_RIGHT_ARROW		= 1,
69 		B_UP_ARROW			= 2,
70 		B_DOWN_ARROW		= 3,
71 		B_LEFT_UP_ARROW		= 4,
72 		B_RIGHT_UP_ARROW	= 5,
73 		B_RIGHT_DOWN_ARROW	= 6,
74 		B_LEFT_DOWN_ARROW	= 7
75 	};
76 
77 	enum {
78 		B_FOCUSED				= 1 << 0,
79 		B_CLICKED				= 1 << 1, // some controls activate on mouse up
80 		B_ACTIVATED				= 1 << 2,
81 		B_HOVER					= 1 << 3,
82 		B_DISABLED				= 1 << 4,
83 		B_DEFAULT_BUTTON		= 1 << 5,
84 		B_IGNORE_OUTLINE		= 1 << 6,
85 		B_PARTIALLY_ACTIVATED	= 1 << 7, // like B_ACTIVATED, but for tri-state
86 		B_FLAT					= 1 << 8, // flat look (e.g. button background)
87 		B_INVALID				= 1 << 9, // invalid value, use B_FAILURE_COLOR
88 		B_IS_CONTROL			= 1 << 10, // use control colors
89 
90 		B_BLEND_FRAME			= 1 << 16,
91 	};
92 
93 	enum {
94 		B_KNOB_NONE = 0,
95 		B_KNOB_DOTS,
96 		B_KNOB_LINES
97 	};
98 
99 	virtual BAlignment			DefaultLabelAlignment() const = 0;
100 	virtual float				DefaultLabelSpacing() const = 0;
101 
102 	virtual	float				DefaultItemSpacing() const = 0;
103 
104 	static	float				ComposeSpacing(float spacing);
105 
106 	virtual uint32				Flags(BControl* control) const = 0;
107 
108 	virtual	void				DrawButtonFrame(BView* view, BRect& rect,
109 									const BRect& updateRect,
110 									const rgb_color& base,
111 									const rgb_color& background,
112 									uint32 flags = 0,
113 									uint32 borders = B_ALL_BORDERS) = 0;
114 	virtual	void				DrawButtonFrame(BView* view, BRect& rect,
115 									const BRect& updateRect,
116 									float radius,
117 									const rgb_color& base,
118 									const rgb_color& background,
119 									uint32 flags = 0,
120 									uint32 borders = B_ALL_BORDERS) = 0;
121 	virtual	void				DrawButtonFrame(BView* view, BRect& rect,
122 									const BRect& updateRect,
123 									float leftTopRadius,
124 									float rightTopRadius,
125 									float leftBottomRadius,
126 									float rightBottomRadius,
127 									const rgb_color& base,
128 									const rgb_color& background,
129 									uint32 flags = 0,
130 									uint32 borders = B_ALL_BORDERS) = 0;
131 
132 	virtual	void				DrawButtonBackground(BView* view, BRect& rect,
133 									const BRect& updateRect,
134 									const rgb_color& base,
135 									uint32 flags = 0,
136 									uint32 borders = B_ALL_BORDERS,
137 									orientation orientation = B_HORIZONTAL) = 0;
138 	virtual	void				DrawButtonBackground(BView* view, BRect& rect,
139 									const BRect& updateRect,
140 									float radius,
141 									const rgb_color& base,
142 									uint32 flags = 0,
143 									uint32 borders = B_ALL_BORDERS,
144 									orientation orientation = B_HORIZONTAL) = 0;
145 	virtual	void				DrawButtonBackground(BView* view, BRect& rect,
146 									const BRect& updateRect,
147 									float leftTopRadius,
148 									float rightTopRadius,
149 									float leftBottomRadius,
150 									float rightBottomRadius,
151 									const rgb_color& base,
152 									uint32 flags = 0,
153 									uint32 borders = B_ALL_BORDERS,
154 									orientation orientation = B_HORIZONTAL) = 0;
155 
156 	virtual	void				DrawMenuBarBackground(BView* view, BRect& rect,
157 									const BRect& updateRect,
158 									const rgb_color& base,
159 									uint32 flags = 0,
160 									uint32 borders = B_ALL_BORDERS) = 0;
161 
162 	virtual	void				DrawMenuFieldFrame(BView* view, BRect& rect,
163 									const BRect& updateRect,
164 									const rgb_color& base,
165 									const rgb_color& background,
166 									uint32 flags = 0,
167 									uint32 borders = B_ALL_BORDERS) = 0;
168 	virtual	void				DrawMenuFieldFrame(BView* view, BRect& rect,
169 									const BRect& updateRect,
170 									float radius,
171 									const rgb_color& base,
172 									const rgb_color& background,
173 									uint32 flags = 0,
174 									uint32 borders = B_ALL_BORDERS) = 0;
175 	virtual	void				DrawMenuFieldFrame(BView* view, BRect& rect,
176 									const BRect& updateRect,
177 									float leftTopRadius,
178 									float rightTopRadius,
179 									float leftBottomRadius,
180 									float rightBottomRadius,
181 									const rgb_color& base,
182 									const rgb_color& background,
183 									uint32 flags = 0,
184 									uint32 borders = B_ALL_BORDERS) = 0;
185 
186 	virtual	void				DrawMenuFieldBackground(BView* view,
187 									BRect& rect, const BRect& updateRect,
188 									const rgb_color& base, bool popupIndicator,
189 									uint32 flags = 0) = 0;
190 	virtual	void				DrawMenuFieldBackground(BView* view,
191 									BRect& rect, const BRect& updateRect,
192 									float radius, const rgb_color& base,
193 									bool popupIndicator, uint32 flags = 0) = 0;
194 	virtual	void				DrawMenuFieldBackground(BView* view,
195 									BRect& rect, const BRect& updateRect,
196 									float leftTopRadius,
197 									float rightTopRadius,
198 									float leftBottomRadius,
199 									float rightBottomRadius,
200 									const rgb_color& base,
201 									bool popupIndicator, uint32 flags = 0) = 0;
202 	virtual	void				DrawMenuFieldBackground(BView* view,
203 									BRect& rect, const BRect& updateRect,
204 									const rgb_color& base, uint32 flags = 0,
205 									uint32 borders = B_ALL_BORDERS) = 0;
206 
207 	virtual	void				DrawMenuBackground(BView* view,
208 									BRect& rect, const BRect& updateRect,
209 									const rgb_color& base, uint32 flags = 0,
210 									uint32 borders = B_ALL_BORDERS) = 0;
211 
212 	virtual	void				DrawMenuItemBackground(BView* view,
213 									BRect& rect, const BRect& updateRect,
214 									const rgb_color& base, uint32 flags = 0,
215 									uint32 borders = B_ALL_BORDERS) = 0;
216 
217 	virtual	void				DrawStatusBar(BView* view, BRect& rect,
218 									const BRect& updateRect,
219 									const rgb_color& base,
220 									const rgb_color& barColor,
221 									float progressPosition) = 0;
222 
223 	virtual	void				DrawCheckBox(BView* view, BRect& rect,
224 									const BRect& updateRect,
225 									const rgb_color& base,
226 									uint32 flags = 0) = 0;
227 
228 	virtual	void				DrawRadioButton(BView* view, BRect& rect,
229 									const BRect& updateRect,
230 									const rgb_color& base,
231 									uint32 flags = 0) = 0;
232 
233 	virtual	void				DrawScrollBarBackground(BView* view,
234 									BRect& rect1, BRect& rect2,
235 									const BRect& updateRect,
236 									const rgb_color& base, uint32 flags,
237 									orientation orientation) = 0;
238 	virtual	void				DrawScrollBarBackground(BView* view,
239 									BRect& rect, const BRect& updateRect,
240 									const rgb_color& base, uint32 flags,
241 									orientation orientation) = 0;
242 
243 	virtual	void				DrawScrollViewFrame(BView* view,
244 									BRect& rect, const BRect& updateRect,
245 									BRect verticalScrollBarFrame,
246 									BRect horizontalScrollBarFrame,
247 									const rgb_color& base,
248 									border_style borderStyle,
249 									uint32 flags = 0,
250 									uint32 borders = B_ALL_BORDERS) = 0;
251 
252 	virtual	void				DrawArrowShape(BView* view,
253 									BRect& rect, const BRect& updateRect,
254 									const rgb_color& base, uint32 direction,
255 									uint32 flags = 0,
256 									float tint = B_DARKEN_MAX_TINT) = 0;
257 
258 	virtual	rgb_color			SliderBarColor(const rgb_color& base) = 0;
259 
260 	virtual	void				DrawSliderBar(BView* view, BRect rect,
261 									const BRect& updateRect,
262 									const rgb_color& base,
263 									rgb_color leftFillColor,
264 									rgb_color rightFillColor,
265 									float sliderScale, uint32 flags,
266 									orientation orientation) = 0;
267 	virtual	void				DrawSliderBar(BView* view, BRect rect,
268 									const BRect& updateRect,
269 									const rgb_color& base, rgb_color fillColor,
270 									uint32 flags, orientation orientation) = 0;
271 
272 	virtual	void				DrawSliderThumb(BView* view, BRect& rect,
273 									const BRect& updateRect,
274 									const rgb_color& base, uint32 flags,
275 									orientation orientation) = 0;
276 
277 	virtual	void				DrawSliderTriangle(BView* view, BRect& rect,
278 									const BRect& updateRect,
279 									const rgb_color& base, uint32 flags,
280 									orientation orientation) = 0;
281 	virtual	void				DrawSliderTriangle(BView* view, BRect& rect,
282 									const BRect& updateRect,
283 									const rgb_color& base,
284 									const rgb_color& fill, uint32 flags,
285 									orientation orientation) = 0;
286 
287 	virtual	void				DrawSliderHashMarks(BView* view, BRect& rect,
288 									const BRect& updateRect,
289 									const rgb_color& base, int32 count,
290 									hash_mark_location location,
291 									uint32 flags, orientation orientation) = 0;
292 
293 	virtual	void				DrawActiveTab(BView* view, BRect& rect,
294 									const BRect& updateRect,
295 									const rgb_color& base, uint32 flags = 0,
296 									uint32 borders = B_ALL_BORDERS,
297 									uint32 side = B_TOP_BORDER) = 0;
298 	virtual	void				DrawInactiveTab(BView* view, BRect& rect,
299 									const BRect& updateRect,
300 									const rgb_color& base, uint32 flags = 0,
301 									uint32 borders = B_ALL_BORDERS,
302 									uint32 side = B_TOP_BORDER) = 0;
303 
304 	virtual	void				DrawSplitter(BView* view, BRect& rect,
305 									const BRect& updateRect,
306 									const rgb_color& base,
307 									orientation orientation,
308 									uint32 flags = 0,
309 									uint32 borders = B_ALL_BORDERS) = 0;
310 
311 	// various borders
312 
313 	virtual	void				DrawBorder(BView* view, BRect& rect,
314 									const BRect& updateRect,
315 									const rgb_color& base,
316 									border_style borderStyle, uint32 flags = 0,
317 									uint32 borders = B_ALL_BORDERS) = 0;
318 
319 	virtual	void				DrawRaisedBorder(BView* view, BRect& rect,
320 									const BRect& updateRect,
321 									const rgb_color& base, uint32 flags = 0,
322 									uint32 borders = B_ALL_BORDERS) = 0;
323 
324 	virtual	void				DrawGroupFrame(BView* view, BRect& rect,
325 									const BRect& updateRect,
326 									const rgb_color& base,
327 									uint32 borders = B_ALL_BORDERS) = 0;
328 
329 	virtual	void				DrawTextControlBorder(BView* view, BRect& rect,
330 									const BRect& updateRect,
331 									const rgb_color& base, uint32 flags = 0,
332 									uint32 borders = B_ALL_BORDERS) = 0;
333 
334 	// aligned labels
335 
336 	virtual	void				DrawLabel(BView* view, const char* label,
337 									BRect rect, const BRect& updateRect,
338 									const rgb_color& base, uint32 flags,
339 									const rgb_color* textColor = NULL) = 0;
340 	virtual	void				DrawLabel(BView* view, const char* label,
341 									BRect rect, const BRect& updateRect,
342 									const rgb_color& base, uint32 flags,
343 									const BAlignment& alignment,
344 									const rgb_color* textColor = NULL) = 0;
345 	// TODO: Would be nice to have a (non-virtual) version of this method
346 	// which takes an array of labels and locations. That would save some
347 	// setup with the view graphics state.
348 	virtual	void				DrawLabel(BView* view, const char* label,
349 									const rgb_color& base, uint32 flags,
350 									const BPoint& where,
351 									const rgb_color* textColor = NULL) = 0;
352 
353 			void				DrawLabel(BView* view, const char* label,
354 									const BBitmap* icon, BRect rect,
355 									const BRect& updateRect,
356 									const rgb_color& base, uint32 flags,
357 									const rgb_color* textColor = NULL);
358 	virtual	void				DrawLabel(BView* view, const char* label,
359 									const BBitmap* icon, BRect rect,
360 									const BRect& updateRect,
361 									const rgb_color& base, uint32 flags,
362 									const BAlignment& alignment,
363 									const rgb_color* textColor = NULL) = 0;
364 
365 	virtual	void				GetFrameInsets(frame_type frameType,
366 									uint32 flags, float& _left, float& _top,
367 									float& _right, float& _bottom) = 0;
368 	virtual	void				GetBackgroundInsets(
369 									background_type backgroundType,
370 									uint32 flags, float& _left, float& _top,
371 									float& _right, float& _bottom) = 0;
372 			void				GetInsets(frame_type frameType,
373 									background_type backgroundType,
374 									uint32 flags, float& _left, float& _top,
375 									float& _right, float& _bottom);
376 
377 	virtual	void				DrawButtonWithPopUpBackground(BView* view,
378 									BRect& rect, const BRect& updateRect,
379 									const rgb_color& base,
380 									uint32 flags = 0,
381 									uint32 borders = B_ALL_BORDERS,
382 									orientation orientation = B_HORIZONTAL) = 0;
383 	virtual	void				DrawButtonWithPopUpBackground(BView* view,
384 									BRect& rect, const BRect& updateRect,
385 									float radius,
386 									const rgb_color& base,
387 									uint32 flags = 0,
388 									uint32 borders = B_ALL_BORDERS,
389 									orientation orientation = B_HORIZONTAL) = 0;
390 	virtual	void				DrawButtonWithPopUpBackground(BView* view,
391 									BRect& rect, const BRect& updateRect,
392 									float leftTopRadius,
393 									float rightTopRadius,
394 									float leftBottomRadius,
395 									float rightBottomRadius,
396 									const rgb_color& base,
397 									uint32 flags = 0,
398 									uint32 borders = B_ALL_BORDERS,
399 									orientation orientation = B_HORIZONTAL) = 0;
400 
401 			void				SetBackgroundInfo(
402 									const BMessage& backgroundInfo);
403 
404 	virtual	void				DrawTabFrame(BView* view, BRect& rect,
405 									const BRect& updateRect,
406 									const rgb_color& base, uint32 flags = 0,
407 									uint32 borders = B_ALL_BORDERS,
408 									border_style borderStyle = B_FANCY_BORDER,
409 									uint32 side = B_TOP_BORDER) = 0;
410 
411 	virtual	void				DrawScrollBarButton(BView* view,
412 									BRect rect, const BRect& updateRect,
413 									const rgb_color& base, uint32 flags,
414 									int32 direction, orientation orientation,
415 									bool down = false) = 0;
416 	virtual	void				DrawScrollBarThumb(BView* view,
417 									BRect& rect, const BRect& updateRect,
418 									const rgb_color& base, uint32 flags,
419 									orientation orientation,
420 									uint32 knobStyle = B_KNOB_NONE) = 0;
421 	virtual	void				DrawScrollBarBorder(BView* view,
422 									BRect rect, const BRect& updateRect,
423 									const rgb_color& base, uint32 flags,
424 									orientation orientation) = 0;
425 
426 private:
427 	// FBC padding
428 	virtual	void				_ReservedControlLook5();
429 	virtual	void				_ReservedControlLook6();
430 	virtual	void				_ReservedControlLook7();
431 	virtual	void				_ReservedControlLook8();
432 	virtual	void				_ReservedControlLook9();
433 	virtual	void				_ReservedControlLook10();
434 
435 protected:
436 			int32				fCachedWorkspace;
437 			BMessage			fBackgroundInfo;
438 
439 			uint32				_reserved[20];
440 };
441 
442 extern BControlLook* be_control_look;
443 
444 extern "C" _EXPORT BControlLook *instantiate_control_look(image_id id);
445 
446 
447 } // namespace BPrivate
448 
449 using BPrivate::BControlLook;
450 using BPrivate::be_control_look;
451 
452 
453 #endif // _CONTROL_LOOK_H
454