xref: /haiku/headers/os/interface/ControlLook.h (revision 445d4fd926c569e7b9ae28017da86280aaecbae2)
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 	static	BSize				ComposeIconSize(int32 size);
106 
107 	virtual uint32				Flags(BControl* control) const = 0;
108 
109 	virtual	void				DrawButtonFrame(BView* view, BRect& rect,
110 									const BRect& updateRect,
111 									const rgb_color& base,
112 									const rgb_color& background,
113 									uint32 flags = 0,
114 									uint32 borders = B_ALL_BORDERS) = 0;
115 	virtual	void				DrawButtonFrame(BView* view, BRect& rect,
116 									const BRect& updateRect,
117 									float radius,
118 									const rgb_color& base,
119 									const rgb_color& background,
120 									uint32 flags = 0,
121 									uint32 borders = B_ALL_BORDERS) = 0;
122 	virtual	void				DrawButtonFrame(BView* view, BRect& rect,
123 									const BRect& updateRect,
124 									float leftTopRadius,
125 									float rightTopRadius,
126 									float leftBottomRadius,
127 									float rightBottomRadius,
128 									const rgb_color& base,
129 									const rgb_color& background,
130 									uint32 flags = 0,
131 									uint32 borders = B_ALL_BORDERS) = 0;
132 
133 	virtual	void				DrawButtonBackground(BView* view, BRect& rect,
134 									const BRect& updateRect,
135 									const rgb_color& base,
136 									uint32 flags = 0,
137 									uint32 borders = B_ALL_BORDERS,
138 									orientation orientation = B_HORIZONTAL) = 0;
139 	virtual	void				DrawButtonBackground(BView* view, BRect& rect,
140 									const BRect& updateRect,
141 									float radius,
142 									const rgb_color& base,
143 									uint32 flags = 0,
144 									uint32 borders = B_ALL_BORDERS,
145 									orientation orientation = B_HORIZONTAL) = 0;
146 	virtual	void				DrawButtonBackground(BView* view, BRect& rect,
147 									const BRect& updateRect,
148 									float leftTopRadius,
149 									float rightTopRadius,
150 									float leftBottomRadius,
151 									float rightBottomRadius,
152 									const rgb_color& base,
153 									uint32 flags = 0,
154 									uint32 borders = B_ALL_BORDERS,
155 									orientation orientation = B_HORIZONTAL) = 0;
156 
157 	virtual	void				DrawMenuBarBackground(BView* view, BRect& rect,
158 									const BRect& updateRect,
159 									const rgb_color& base,
160 									uint32 flags = 0,
161 									uint32 borders = B_ALL_BORDERS) = 0;
162 
163 	virtual	void				DrawMenuFieldFrame(BView* view, BRect& rect,
164 									const BRect& updateRect,
165 									const rgb_color& base,
166 									const rgb_color& background,
167 									uint32 flags = 0,
168 									uint32 borders = B_ALL_BORDERS) = 0;
169 	virtual	void				DrawMenuFieldFrame(BView* view, BRect& rect,
170 									const BRect& updateRect,
171 									float radius,
172 									const rgb_color& base,
173 									const rgb_color& background,
174 									uint32 flags = 0,
175 									uint32 borders = B_ALL_BORDERS) = 0;
176 	virtual	void				DrawMenuFieldFrame(BView* view, BRect& rect,
177 									const BRect& updateRect,
178 									float leftTopRadius,
179 									float rightTopRadius,
180 									float leftBottomRadius,
181 									float rightBottomRadius,
182 									const rgb_color& base,
183 									const rgb_color& background,
184 									uint32 flags = 0,
185 									uint32 borders = B_ALL_BORDERS) = 0;
186 
187 	virtual	void				DrawMenuFieldBackground(BView* view,
188 									BRect& rect, const BRect& updateRect,
189 									const rgb_color& base, bool popupIndicator,
190 									uint32 flags = 0) = 0;
191 	virtual	void				DrawMenuFieldBackground(BView* view,
192 									BRect& rect, const BRect& updateRect,
193 									float radius, const rgb_color& base,
194 									bool popupIndicator, uint32 flags = 0) = 0;
195 	virtual	void				DrawMenuFieldBackground(BView* view,
196 									BRect& rect, const BRect& updateRect,
197 									float leftTopRadius,
198 									float rightTopRadius,
199 									float leftBottomRadius,
200 									float rightBottomRadius,
201 									const rgb_color& base,
202 									bool popupIndicator, uint32 flags = 0) = 0;
203 	virtual	void				DrawMenuFieldBackground(BView* view,
204 									BRect& rect, const BRect& updateRect,
205 									const rgb_color& base, uint32 flags = 0,
206 									uint32 borders = B_ALL_BORDERS) = 0;
207 
208 	virtual	void				DrawMenuBackground(BView* view,
209 									BRect& rect, const BRect& updateRect,
210 									const rgb_color& base, uint32 flags = 0,
211 									uint32 borders = B_ALL_BORDERS) = 0;
212 
213 	virtual	void				DrawMenuItemBackground(BView* view,
214 									BRect& rect, const BRect& updateRect,
215 									const rgb_color& base, uint32 flags = 0,
216 									uint32 borders = B_ALL_BORDERS) = 0;
217 
218 	virtual	void				DrawStatusBar(BView* view, BRect& rect,
219 									const BRect& updateRect,
220 									const rgb_color& base,
221 									const rgb_color& barColor,
222 									float progressPosition) = 0;
223 
224 	virtual	void				DrawCheckBox(BView* view, BRect& rect,
225 									const BRect& updateRect,
226 									const rgb_color& base,
227 									uint32 flags = 0) = 0;
228 
229 	virtual	void				DrawRadioButton(BView* view, BRect& rect,
230 									const BRect& updateRect,
231 									const rgb_color& base,
232 									uint32 flags = 0) = 0;
233 
234 	virtual	void				DrawScrollBarBackground(BView* view,
235 									BRect& rect1, BRect& rect2,
236 									const BRect& updateRect,
237 									const rgb_color& base, uint32 flags,
238 									orientation orientation) = 0;
239 	virtual	void				DrawScrollBarBackground(BView* view,
240 									BRect& rect, const BRect& updateRect,
241 									const rgb_color& base, uint32 flags,
242 									orientation orientation) = 0;
243 
244 	virtual	void				DrawScrollViewFrame(BView* view,
245 									BRect& rect, const BRect& updateRect,
246 									BRect verticalScrollBarFrame,
247 									BRect horizontalScrollBarFrame,
248 									const rgb_color& base,
249 									border_style borderStyle,
250 									uint32 flags = 0,
251 									uint32 borders = B_ALL_BORDERS) = 0;
252 
253 	virtual	void				DrawArrowShape(BView* view,
254 									BRect& rect, const BRect& updateRect,
255 									const rgb_color& base, uint32 direction,
256 									uint32 flags = 0,
257 									float tint = B_DARKEN_MAX_TINT) = 0;
258 
259 	virtual	rgb_color			SliderBarColor(const rgb_color& base) = 0;
260 
261 	virtual	void				DrawSliderBar(BView* view, BRect rect,
262 									const BRect& updateRect,
263 									const rgb_color& base,
264 									rgb_color leftFillColor,
265 									rgb_color rightFillColor,
266 									float sliderScale, uint32 flags,
267 									orientation orientation) = 0;
268 	virtual	void				DrawSliderBar(BView* view, BRect rect,
269 									const BRect& updateRect,
270 									const rgb_color& base, rgb_color fillColor,
271 									uint32 flags, orientation orientation) = 0;
272 
273 	virtual	void				DrawSliderThumb(BView* view, BRect& rect,
274 									const BRect& updateRect,
275 									const rgb_color& base, uint32 flags,
276 									orientation orientation) = 0;
277 
278 	virtual	void				DrawSliderTriangle(BView* view, BRect& rect,
279 									const BRect& updateRect,
280 									const rgb_color& base, uint32 flags,
281 									orientation orientation) = 0;
282 	virtual	void				DrawSliderTriangle(BView* view, BRect& rect,
283 									const BRect& updateRect,
284 									const rgb_color& base,
285 									const rgb_color& fill, uint32 flags,
286 									orientation orientation) = 0;
287 
288 	virtual	void				DrawSliderHashMarks(BView* view, BRect& rect,
289 									const BRect& updateRect,
290 									const rgb_color& base, int32 count,
291 									hash_mark_location location,
292 									uint32 flags, orientation orientation) = 0;
293 
294 	virtual	void				DrawActiveTab(BView* view, BRect& rect,
295 									const BRect& updateRect,
296 									const rgb_color& base, uint32 flags = 0,
297 									uint32 borders = B_ALL_BORDERS,
298 									uint32 side = B_TOP_BORDER,
299 									int32 index = 0, int32 selected = -1,
300 									int32 first = 0, int32 last = 0) = 0;
301 	virtual	void				DrawInactiveTab(BView* view, BRect& rect,
302 									const BRect& updateRect,
303 									const rgb_color& base, uint32 flags = 0,
304 									uint32 borders = B_ALL_BORDERS,
305 									uint32 side = B_TOP_BORDER,
306 									int32 index = 0, int32 selected = -1,
307 									int32 first = 0, int32 last = 0) = 0;
308 
309 	virtual	void				DrawSplitter(BView* view, BRect& rect,
310 									const BRect& updateRect,
311 									const rgb_color& base,
312 									orientation orientation,
313 									uint32 flags = 0,
314 									uint32 borders = B_ALL_BORDERS) = 0;
315 
316 	// various borders
317 
318 	virtual	void				DrawBorder(BView* view, BRect& rect,
319 									const BRect& updateRect,
320 									const rgb_color& base,
321 									border_style borderStyle, uint32 flags = 0,
322 									uint32 borders = B_ALL_BORDERS) = 0;
323 
324 	virtual	void				DrawRaisedBorder(BView* view, BRect& rect,
325 									const BRect& updateRect,
326 									const rgb_color& base, uint32 flags = 0,
327 									uint32 borders = B_ALL_BORDERS) = 0;
328 
329 	virtual	void				DrawGroupFrame(BView* view, BRect& rect,
330 									const BRect& updateRect,
331 									const rgb_color& base,
332 									uint32 borders = B_ALL_BORDERS) = 0;
333 
334 	virtual	void				DrawTextControlBorder(BView* view, BRect& rect,
335 									const BRect& updateRect,
336 									const rgb_color& base, uint32 flags = 0,
337 									uint32 borders = B_ALL_BORDERS) = 0;
338 
339 	// aligned labels
340 
341 	virtual	void				DrawLabel(BView* view, const char* label,
342 									BRect rect, const BRect& updateRect,
343 									const rgb_color& base, uint32 flags,
344 									const rgb_color* textColor = NULL) = 0;
345 	virtual	void				DrawLabel(BView* view, const char* label,
346 									BRect rect, const BRect& updateRect,
347 									const rgb_color& base, uint32 flags,
348 									const BAlignment& alignment,
349 									const rgb_color* textColor = NULL) = 0;
350 	// TODO: Would be nice to have a (non-virtual) version of this method
351 	// which takes an array of labels and locations. That would save some
352 	// setup with the view graphics state.
353 	virtual	void				DrawLabel(BView* view, const char* label,
354 									const rgb_color& base, uint32 flags,
355 									const BPoint& where,
356 									const rgb_color* textColor = NULL) = 0;
357 
358 			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 rgb_color* textColor = NULL);
363 	virtual	void				DrawLabel(BView* view, const char* label,
364 									const BBitmap* icon, BRect rect,
365 									const BRect& updateRect,
366 									const rgb_color& base, uint32 flags,
367 									const BAlignment& alignment,
368 									const rgb_color* textColor = NULL) = 0;
369 
370 	virtual	void				GetFrameInsets(frame_type frameType,
371 									uint32 flags, float& _left, float& _top,
372 									float& _right, float& _bottom) = 0;
373 	virtual	void				GetBackgroundInsets(
374 									background_type backgroundType,
375 									uint32 flags, float& _left, float& _top,
376 									float& _right, float& _bottom) = 0;
377 			void				GetInsets(frame_type frameType,
378 									background_type backgroundType,
379 									uint32 flags, float& _left, float& _top,
380 									float& _right, float& _bottom);
381 
382 	virtual	void				DrawButtonWithPopUpBackground(BView* view,
383 									BRect& rect, const BRect& updateRect,
384 									const rgb_color& base,
385 									uint32 flags = 0,
386 									uint32 borders = B_ALL_BORDERS,
387 									orientation orientation = B_HORIZONTAL) = 0;
388 	virtual	void				DrawButtonWithPopUpBackground(BView* view,
389 									BRect& rect, const BRect& updateRect,
390 									float radius,
391 									const rgb_color& base,
392 									uint32 flags = 0,
393 									uint32 borders = B_ALL_BORDERS,
394 									orientation orientation = B_HORIZONTAL) = 0;
395 	virtual	void				DrawButtonWithPopUpBackground(BView* view,
396 									BRect& rect, const BRect& updateRect,
397 									float leftTopRadius,
398 									float rightTopRadius,
399 									float leftBottomRadius,
400 									float rightBottomRadius,
401 									const rgb_color& base,
402 									uint32 flags = 0,
403 									uint32 borders = B_ALL_BORDERS,
404 									orientation orientation = B_HORIZONTAL) = 0;
405 
406 			void				SetBackgroundInfo(
407 									const BMessage& backgroundInfo);
408 
409 	virtual	void				DrawTabFrame(BView* view, BRect& rect,
410 									const BRect& updateRect,
411 									const rgb_color& base, uint32 flags = 0,
412 									uint32 borders = B_ALL_BORDERS,
413 									border_style borderStyle = B_FANCY_BORDER,
414 									uint32 side = B_TOP_BORDER) = 0;
415 
416 	virtual	void				DrawScrollBarButton(BView* view,
417 									BRect rect, const BRect& updateRect,
418 									const rgb_color& base, uint32 flags,
419 									int32 direction, orientation orientation,
420 									bool down = false) = 0;
421 	virtual	void				DrawScrollBarThumb(BView* view,
422 									BRect& rect, const BRect& updateRect,
423 									const rgb_color& base, uint32 flags,
424 									orientation orientation,
425 									uint32 knobStyle = B_KNOB_NONE) = 0;
426 	virtual	void				DrawScrollBarBorder(BView* view,
427 									BRect rect, const BRect& updateRect,
428 									const rgb_color& base, uint32 flags,
429 									orientation orientation) = 0;
430 	virtual float				GetScrollBarWidth(
431 									orientation orientation = B_VERTICAL);
432 
433 	static	bool				ShouldDraw(BView* view, const BRect& rect,
434 									const BRect& updateRect);
435 
436 private:
437 	// FBC padding
438 	virtual	void				_ReservedControlLook6();
439 	virtual	void				_ReservedControlLook7();
440 	virtual	void				_ReservedControlLook8();
441 	virtual	void				_ReservedControlLook9();
442 	virtual	void				_ReservedControlLook10();
443 
444 protected:
445 			int32				fCachedWorkspace;
446 			BMessage			fBackgroundInfo;
447 
448 			uint32				_reserved[20];
449 };
450 
451 extern BControlLook* be_control_look;
452 
453 extern "C" _EXPORT BControlLook *instantiate_control_look(image_id id);
454 
455 
456 } // namespace BPrivate
457 
458 using BPrivate::BControlLook;
459 using BPrivate::be_control_look;
460 
461 
462 #endif // _CONTROL_LOOK_H
463