xref: /haiku/src/kits/interface/Box.cpp (revision aa3083e086e5a929c061c72983e09d916c548a38)
1 /*
2  * Copyright 2001-2015 Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT license.
4  *
5  * Authors:
6  *		Stephan Aßmus, superstippi@gmx.de
7  *		DarkWyrm, bpmagic@columbus.rr.com
8  *		Axel Dörfler, axeld@pinc-software.de
9  *		Marc Flerackers, mflerackers@androme.be
10  *		John Scipione, jscipione@gmail.com
11  */
12 
13 
14 #include <Box.h>
15 
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
19 
20 #include <ControlLook.h>
21 #include <Layout.h>
22 #include <LayoutUtils.h>
23 #include <Message.h>
24 #include <Region.h>
25 
26 #include <binary_compatibility/Interface.h>
27 
28 
29 struct BBox::LayoutData {
30 	LayoutData()
31 		: valid(false)
32 	{
33 	}
34 
35 	BRect	label_box;		// label box (label string or label view); in case
36 							// of a label string not including descent
37 	BRect	insets;			// insets induced by border and label
38 	BSize	min;
39 	BSize	max;
40 	BSize	preferred;
41 	BAlignment alignment;
42 	bool	valid;			// validity the other fields
43 };
44 
45 
46 BBox::BBox(BRect frame, const char* name, uint32 resizingMode, uint32 flags,
47 		border_style border)
48 	:
49 	BView(frame, name, resizingMode, flags  | B_WILL_DRAW | B_FRAME_EVENTS),
50 	  fStyle(border)
51 {
52 	_InitObject();
53 }
54 
55 
56 BBox::BBox(const char* name, uint32 flags, border_style border, BView* child)
57 	:
58 	BView(name, flags | B_WILL_DRAW | B_FRAME_EVENTS),
59 	fStyle(border)
60 {
61 	_InitObject();
62 
63 	if (child)
64 		AddChild(child);
65 }
66 
67 
68 BBox::BBox(border_style border, BView* child)
69 	:
70 	BView(NULL, B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP),
71 	fStyle(border)
72 {
73 	_InitObject();
74 
75 	if (child)
76 		AddChild(child);
77 }
78 
79 
80 BBox::BBox(BMessage* archive)
81 	:
82 	BView(archive),
83 	fStyle(B_FANCY_BORDER)
84 {
85 	_InitObject(archive);
86 }
87 
88 
89 BBox::~BBox()
90 {
91 	_ClearLabel();
92 
93 	delete fLayoutData;
94 }
95 
96 
97 BArchivable*
98 BBox::Instantiate(BMessage* archive)
99 {
100 	if (validate_instantiation(archive, "BBox"))
101 		return new BBox(archive);
102 
103 	return NULL;
104 }
105 
106 
107 status_t
108 BBox::Archive(BMessage* archive, bool deep) const
109 {
110 	status_t ret = BView::Archive(archive, deep);
111 
112 	if (fLabel && ret == B_OK)
113 		ret = archive->AddString("_label", fLabel);
114 
115 	if (fLabelView && ret == B_OK)
116 		ret = archive->AddBool("_lblview", true);
117 
118 	if (fStyle != B_FANCY_BORDER && ret == B_OK)
119 		ret = archive->AddInt32("_style", fStyle);
120 
121 	return ret;
122 }
123 
124 
125 void
126 BBox::SetBorder(border_style border)
127 {
128 	if (border == fStyle)
129 		return;
130 
131 	fStyle = border;
132 
133 	InvalidateLayout();
134 
135 	if (Window() != NULL && LockLooper()) {
136 		Invalidate();
137 		UnlockLooper();
138 	}
139 }
140 
141 
142 border_style
143 BBox::Border() const
144 {
145 	return fStyle;
146 }
147 
148 
149 //! This function is not part of the R5 API and is not yet finalized yet
150 float
151 BBox::TopBorderOffset()
152 {
153 	_ValidateLayoutData();
154 
155 	if (fLabel != NULL || fLabelView != NULL)
156 		return fLayoutData->label_box.Height() / 2;
157 
158 	return 0;
159 }
160 
161 
162 //! This function is not part of the R5 API and is not yet finalized yet
163 BRect
164 BBox::InnerFrame()
165 {
166 	_ValidateLayoutData();
167 
168 	BRect frame(Bounds());
169 	frame.left += fLayoutData->insets.left;
170 	frame.top += fLayoutData->insets.top;
171 	frame.right -= fLayoutData->insets.right;
172 	frame.bottom -= fLayoutData->insets.bottom;
173 
174 	return frame;
175 }
176 
177 
178 void
179 BBox::SetLabel(const char* string)
180 {
181 	_ClearLabel();
182 
183 	if (string)
184 		fLabel = strdup(string);
185 
186 	InvalidateLayout();
187 
188 	if (Window())
189 		Invalidate();
190 }
191 
192 
193 status_t
194 BBox::SetLabel(BView* viewLabel)
195 {
196 	_ClearLabel();
197 
198 	if (viewLabel) {
199 		fLabelView = viewLabel;
200 		fLabelView->MoveTo(10.0f, 0.0f);
201 		AddChild(fLabelView, ChildAt(0));
202 	}
203 
204 	InvalidateLayout();
205 
206 	if (Window())
207 		Invalidate();
208 
209 	return B_OK;
210 }
211 
212 
213 const char*
214 BBox::Label() const
215 {
216 	return fLabel;
217 }
218 
219 
220 BView*
221 BBox::LabelView() const
222 {
223 	return fLabelView;
224 }
225 
226 
227 void
228 BBox::Draw(BRect updateRect)
229 {
230 	_ValidateLayoutData();
231 
232 	PushState();
233 
234 	BRect labelBox = BRect(0, 0, 0, 0);
235 	if (fLabel != NULL) {
236 		labelBox = fLayoutData->label_box;
237 		BRegion update(updateRect);
238 		update.Exclude(labelBox);
239 
240 		ConstrainClippingRegion(&update);
241 	} else if (fLabelView != NULL)
242 		labelBox = fLabelView->Bounds();
243 
244 	switch (fStyle) {
245 		case B_FANCY_BORDER:
246 			_DrawFancy(labelBox);
247 			break;
248 
249 		case B_PLAIN_BORDER:
250 			_DrawPlain(labelBox);
251 			break;
252 
253 		default:
254 			break;
255 	}
256 
257 	if (fLabel) {
258 		ConstrainClippingRegion(NULL);
259 
260 		font_height fontHeight;
261 		GetFontHeight(&fontHeight);
262 
263 		SetHighColor(ui_color(B_PANEL_TEXT_COLOR));
264 		DrawString(fLabel, BPoint(10.0f, ceilf(fontHeight.ascent)));
265 	}
266 
267 	PopState();
268 }
269 
270 
271 void
272 BBox::AttachedToWindow()
273 {
274 	AdoptParentColors();
275 
276 	// Force low color to match view color for proper label drawing.
277 	float viewTint = B_NO_TINT;
278 	float lowTint = B_NO_TINT;
279 
280 	if (LowUIColor(&lowTint) != ViewUIColor(&viewTint) || viewTint != lowTint)
281 		SetLowUIColor(ViewUIColor(), viewTint);
282 	else if (LowColor() != ViewColor())
283 		SetLowColor(ViewColor());
284 
285 	if (ViewColor() == B_TRANSPARENT_COLOR)
286 		AdoptSystemColors();
287 
288 	// The box could have been resized in the mean time
289 	fBounds = Bounds();
290 }
291 
292 
293 void
294 BBox::DetachedFromWindow()
295 {
296 	BView::DetachedFromWindow();
297 }
298 
299 
300 void
301 BBox::AllAttached()
302 {
303 	BView::AllAttached();
304 }
305 
306 
307 void
308 BBox::AllDetached()
309 {
310 	BView::AllDetached();
311 }
312 
313 
314 void
315 BBox::FrameResized(float width, float height)
316 {
317 	BRect bounds(Bounds());
318 
319 	// invalidate the regions that the app_server did not
320 	// (for removing the previous or drawing the new border)
321 	if (fStyle != B_NO_BORDER) {
322 		// TODO: this must be made part of the be_control_look stuff!
323 		int32 borderSize = fStyle == B_PLAIN_BORDER ? 0 : 2;
324 
325 		BRect invalid(bounds);
326 		if (fBounds.right < bounds.right) {
327 			// enlarging
328 			invalid.left = fBounds.right - borderSize;
329 			invalid.right = fBounds.right;
330 
331 			Invalidate(invalid);
332 		} else if (fBounds.right > bounds.right) {
333 			// shrinking
334 			invalid.left = bounds.right - borderSize;
335 
336 			Invalidate(invalid);
337 		}
338 
339 		invalid = bounds;
340 		if (fBounds.bottom < bounds.bottom) {
341 			// enlarging
342 			invalid.top = fBounds.bottom - borderSize;
343 			invalid.bottom = fBounds.bottom;
344 
345 			Invalidate(invalid);
346 		} else if (fBounds.bottom > bounds.bottom) {
347 			// shrinking
348 			invalid.top = bounds.bottom - borderSize;
349 
350 			Invalidate(invalid);
351 		}
352 	}
353 
354 	fBounds.right = bounds.right;
355 	fBounds.bottom = bounds.bottom;
356 }
357 
358 
359 void
360 BBox::MessageReceived(BMessage* message)
361 {
362 	BView::MessageReceived(message);
363 }
364 
365 
366 void
367 BBox::MouseDown(BPoint point)
368 {
369 	BView::MouseDown(point);
370 }
371 
372 
373 void
374 BBox::MouseUp(BPoint point)
375 {
376 	BView::MouseUp(point);
377 }
378 
379 
380 void
381 BBox::WindowActivated(bool active)
382 {
383 	BView::WindowActivated(active);
384 }
385 
386 
387 void
388 BBox::MouseMoved(BPoint point, uint32 transit, const BMessage* message)
389 {
390 	BView::MouseMoved(point, transit, message);
391 }
392 
393 
394 void
395 BBox::FrameMoved(BPoint newLocation)
396 {
397 	BView::FrameMoved(newLocation);
398 }
399 
400 
401 BHandler*
402 BBox::ResolveSpecifier(BMessage* message, int32 index, BMessage* specifier,
403 	int32 what, const char* property)
404 {
405 	return BView::ResolveSpecifier(message, index, specifier, what, property);
406 }
407 
408 
409 void
410 BBox::ResizeToPreferred()
411 {
412 	float width, height;
413 	GetPreferredSize(&width, &height);
414 
415 	// make sure the box don't get smaller than it already is
416 	if (width < Bounds().Width())
417 		width = Bounds().Width();
418 	if (height < Bounds().Height())
419 		height = Bounds().Height();
420 
421 	BView::ResizeTo(width, height);
422 }
423 
424 
425 void
426 BBox::GetPreferredSize(float* _width, float* _height)
427 {
428 	_ValidateLayoutData();
429 
430 	if (_width)
431 		*_width = fLayoutData->preferred.width;
432 	if (_height)
433 		*_height = fLayoutData->preferred.height;
434 }
435 
436 
437 void
438 BBox::MakeFocus(bool focused)
439 {
440 	BView::MakeFocus(focused);
441 }
442 
443 
444 status_t
445 BBox::GetSupportedSuites(BMessage* message)
446 {
447 	return BView::GetSupportedSuites(message);
448 }
449 
450 
451 status_t
452 BBox::Perform(perform_code code, void* _data)
453 {
454 	switch (code) {
455 		case PERFORM_CODE_MIN_SIZE:
456 			((perform_data_min_size*)_data)->return_value
457 				= BBox::MinSize();
458 			return B_OK;
459 		case PERFORM_CODE_MAX_SIZE:
460 			((perform_data_max_size*)_data)->return_value
461 				= BBox::MaxSize();
462 			return B_OK;
463 		case PERFORM_CODE_PREFERRED_SIZE:
464 			((perform_data_preferred_size*)_data)->return_value
465 				= BBox::PreferredSize();
466 			return B_OK;
467 		case PERFORM_CODE_LAYOUT_ALIGNMENT:
468 			((perform_data_layout_alignment*)_data)->return_value
469 				= BBox::LayoutAlignment();
470 			return B_OK;
471 		case PERFORM_CODE_HAS_HEIGHT_FOR_WIDTH:
472 			((perform_data_has_height_for_width*)_data)->return_value
473 				= BBox::HasHeightForWidth();
474 			return B_OK;
475 		case PERFORM_CODE_GET_HEIGHT_FOR_WIDTH:
476 		{
477 			perform_data_get_height_for_width* data
478 				= (perform_data_get_height_for_width*)_data;
479 			BBox::GetHeightForWidth(data->width, &data->min, &data->max,
480 				&data->preferred);
481 			return B_OK;
482 		}
483 		case PERFORM_CODE_SET_LAYOUT:
484 		{
485 			perform_data_set_layout* data = (perform_data_set_layout*)_data;
486 			BBox::SetLayout(data->layout);
487 			return B_OK;
488 		}
489 		case PERFORM_CODE_LAYOUT_INVALIDATED:
490 		{
491 			perform_data_layout_invalidated* data
492 				= (perform_data_layout_invalidated*)_data;
493 			BBox::LayoutInvalidated(data->descendants);
494 			return B_OK;
495 		}
496 		case PERFORM_CODE_DO_LAYOUT:
497 		{
498 			BBox::DoLayout();
499 			return B_OK;
500 		}
501 	}
502 
503 	return BView::Perform(code, _data);
504 }
505 
506 
507 BSize
508 BBox::MinSize()
509 {
510 	_ValidateLayoutData();
511 
512 	BSize size = (GetLayout() ? GetLayout()->MinSize() : fLayoutData->min);
513 	if (size.width < fLayoutData->min.width)
514 		size.width = fLayoutData->min.width;
515 	return BLayoutUtils::ComposeSize(ExplicitMinSize(), size);
516 }
517 
518 
519 BSize
520 BBox::MaxSize()
521 {
522 	_ValidateLayoutData();
523 
524 	BSize size = (GetLayout() ? GetLayout()->MaxSize() : fLayoutData->max);
525 	return BLayoutUtils::ComposeSize(ExplicitMaxSize(), size);
526 }
527 
528 
529 BSize
530 BBox::PreferredSize()
531 {
532 	_ValidateLayoutData();
533 
534 	BSize size = (GetLayout() ? GetLayout()->PreferredSize()
535 		: fLayoutData->preferred);
536 	return BLayoutUtils::ComposeSize(ExplicitPreferredSize(), size);
537 }
538 
539 
540 BAlignment
541 BBox::LayoutAlignment()
542 {
543 	_ValidateLayoutData();
544 
545 	BAlignment alignment = (GetLayout() ? GetLayout()->Alignment()
546 			: fLayoutData->alignment);
547 	return BLayoutUtils::ComposeAlignment(ExplicitAlignment(), alignment);
548 }
549 
550 
551 void
552 BBox::LayoutInvalidated(bool descendants)
553 {
554 	fLayoutData->valid = false;
555 }
556 
557 
558 void
559 BBox::DoLayout()
560 {
561 	// Bail out, if we shan't do layout.
562 	if (!(Flags() & B_SUPPORTS_LAYOUT))
563 		return;
564 
565 	BLayout* layout = GetLayout();
566 
567 	// If the user set a layout, let the base class version call its
568 	// hook. In case when we have BView as a label, remove it from child list
569 	// so it won't be layouted with the rest of views and add it again
570 	// after that.
571 	if (layout != NULL) {
572 		if (fLabelView)
573 			RemoveChild(fLabelView);
574 
575 		BView::DoLayout();
576 
577 		if (fLabelView != NULL) {
578 			DisableLayoutInvalidation();
579 				// don't trigger a relayout
580 			AddChild(fLabelView, ChildAt(0));
581 			EnableLayoutInvalidation();
582 		}
583 	}
584 
585 	_ValidateLayoutData();
586 
587 	// Even if the user set a layout, restore label view to it's
588 	// desired position.
589 
590 	// layout the label view
591 	if (fLabelView != NULL) {
592 		fLabelView->MoveTo(fLayoutData->label_box.LeftTop());
593 		fLabelView->ResizeTo(fLayoutData->label_box.Size());
594 	}
595 
596 	// If we have layout return here and do not layout the child
597 	if (layout != NULL)
598 		return;
599 
600 	// layout the child
601 	BView* child = _Child();
602 	if (child != NULL) {
603 		BRect frame(Bounds());
604 		frame.left += fLayoutData->insets.left;
605 		frame.top += fLayoutData->insets.top;
606 		frame.right -= fLayoutData->insets.right;
607 		frame.bottom -= fLayoutData->insets.bottom;
608 
609 		if ((child->Flags() & B_SUPPORTS_LAYOUT) != 0)
610 			BLayoutUtils::AlignInFrame(child, frame);
611 		else
612 			child->MoveTo(frame.LeftTop());
613 	}
614 }
615 
616 
617 void BBox::_ReservedBox1() {}
618 void BBox::_ReservedBox2() {}
619 
620 
621 BBox &
622 BBox::operator=(const BBox &)
623 {
624 	return *this;
625 }
626 
627 
628 void
629 BBox::_InitObject(BMessage* archive)
630 {
631 	fBounds = Bounds();
632 
633 	fLabel = NULL;
634 	fLabelView = NULL;
635 	fLayoutData = new LayoutData;
636 
637 	int32 flags = 0;
638 
639 	BFont font(be_bold_font);
640 
641 	if (!archive || !archive->HasString("_fname"))
642 		flags = B_FONT_FAMILY_AND_STYLE;
643 
644 	if (!archive || !archive->HasFloat("_fflt"))
645 		flags |= B_FONT_SIZE;
646 
647 	if (flags != 0)
648 		SetFont(&font, flags);
649 
650 	if (archive != NULL) {
651 		const char* string;
652 		if (archive->FindString("_label", &string) == B_OK)
653 			SetLabel(string);
654 
655 		bool fancy;
656 		int32 style;
657 
658 		if (archive->FindBool("_style", &fancy) == B_OK)
659 			fStyle = fancy ? B_FANCY_BORDER : B_PLAIN_BORDER;
660 		else if (archive->FindInt32("_style", &style) == B_OK)
661 			fStyle = (border_style)style;
662 
663 		bool hasLabelView;
664 		if (archive->FindBool("_lblview", &hasLabelView) == B_OK)
665 			fLabelView = ChildAt(0);
666 	}
667 
668 	AdoptSystemColors();
669 }
670 
671 
672 void
673 BBox::_DrawPlain(BRect labelBox)
674 {
675 	BRect rect = Bounds();
676 	rect.top += TopBorderOffset();
677 
678 	float lightTint;
679 	float shadowTint;
680 	if (be_control_look != NULL) {
681 		lightTint = B_LIGHTEN_1_TINT;
682 		shadowTint = B_DARKEN_1_TINT;
683 	} else {
684 		lightTint = B_LIGHTEN_MAX_TINT;
685 		shadowTint = B_DARKEN_3_TINT;
686 	}
687 
688 	if (rect.Height() == 0.0 || rect.Width() == 0.0) {
689 		// used as separator
690 		rgb_color shadow = tint_color(ViewColor(), B_DARKEN_2_TINT);
691 
692 		SetHighColor(shadow);
693 		StrokeLine(rect.LeftTop(),rect.RightBottom());
694 	} else {
695 		// used as box
696 		rgb_color light = tint_color(ViewColor(), lightTint);
697 		rgb_color shadow = tint_color(ViewColor(), shadowTint);
698 
699 		BeginLineArray(4);
700 			AddLine(BPoint(rect.left, rect.bottom),
701 					BPoint(rect.left, rect.top), light);
702 			AddLine(BPoint(rect.left + 1.0f, rect.top),
703 					BPoint(rect.right, rect.top), light);
704 			AddLine(BPoint(rect.left + 1.0f, rect.bottom),
705 					BPoint(rect.right, rect.bottom), shadow);
706 			AddLine(BPoint(rect.right, rect.bottom - 1.0f),
707 					BPoint(rect.right, rect.top + 1.0f), shadow);
708 		EndLineArray();
709 	}
710 }
711 
712 
713 void
714 BBox::_DrawFancy(BRect labelBox)
715 {
716 	BRect rect = Bounds();
717 	rect.top += TopBorderOffset();
718 
719 	if (be_control_look != NULL) {
720 		rgb_color base = ViewColor();
721 		if (rect.Height() == 1.0) {
722 			// used as horizontal separator
723 			be_control_look->DrawGroupFrame(this, rect, rect, base,
724 				BControlLook::B_TOP_BORDER);
725 		} else if (rect.Width() == 1.0) {
726 			// used as vertical separator
727 			be_control_look->DrawGroupFrame(this, rect, rect, base,
728 				BControlLook::B_LEFT_BORDER);
729 		} else {
730 			// used as box
731 			be_control_look->DrawGroupFrame(this, rect, rect, base);
732 		}
733 		return;
734 	}
735 
736 	rgb_color light = tint_color(ViewColor(), B_LIGHTEN_MAX_TINT);
737 	rgb_color shadow = tint_color(ViewColor(), B_DARKEN_3_TINT);
738 
739 	if (rect.Height() == 1.0) {
740 		// used as horizontal separator
741 		BeginLineArray(2);
742 			AddLine(BPoint(rect.left, rect.top),
743 					BPoint(rect.right, rect.top), shadow);
744 			AddLine(BPoint(rect.left, rect.bottom),
745 					BPoint(rect.right, rect.bottom), light);
746 		EndLineArray();
747 	} else if (rect.Width() == 1.0) {
748 		// used as vertical separator
749 		BeginLineArray(2);
750 			AddLine(BPoint(rect.left, rect.top),
751 					BPoint(rect.left, rect.bottom), shadow);
752 			AddLine(BPoint(rect.right, rect.top),
753 					BPoint(rect.right, rect.bottom), light);
754 		EndLineArray();
755 	} else {
756 		// used as box
757 		BeginLineArray(8);
758 			AddLine(BPoint(rect.left, rect.bottom - 1.0),
759 					BPoint(rect.left, rect.top), shadow);
760 			AddLine(BPoint(rect.left + 1.0, rect.top),
761 					BPoint(rect.right - 1.0, rect.top), shadow);
762 			AddLine(BPoint(rect.left, rect.bottom),
763 					BPoint(rect.right, rect.bottom), light);
764 			AddLine(BPoint(rect.right, rect.bottom - 1.0),
765 					BPoint(rect.right, rect.top), light);
766 
767 			rect.InsetBy(1.0, 1.0);
768 
769 			AddLine(BPoint(rect.left, rect.bottom - 1.0),
770 					BPoint(rect.left, rect.top), light);
771 			AddLine(BPoint(rect.left + 1.0, rect.top),
772 					BPoint(rect.right - 1.0, rect.top), light);
773 			AddLine(BPoint(rect.left, rect.bottom),
774 					BPoint(rect.right, rect.bottom), shadow);
775 			AddLine(BPoint(rect.right, rect.bottom - 1.0),
776 					BPoint(rect.right, rect.top), shadow);
777 		EndLineArray();
778 	}
779 }
780 
781 
782 void
783 BBox::_ClearLabel()
784 {
785 	fBounds.top = 0;
786 
787 	if (fLabel) {
788 		free(fLabel);
789 		fLabel = NULL;
790 	} else if (fLabelView) {
791 		fLabelView->RemoveSelf();
792 		delete fLabelView;
793 		fLabelView = NULL;
794 	}
795 }
796 
797 
798 BView*
799 BBox::_Child() const
800 {
801 	for (int32 i = 0; BView* view = ChildAt(i); i++) {
802 		if (view != fLabelView)
803 			return view;
804 	}
805 
806 	return NULL;
807 }
808 
809 
810 void
811 BBox::_ValidateLayoutData()
812 {
813 	if (fLayoutData->valid)
814 		return;
815 
816 	// compute the label box, width and height
817 	bool label = true;
818 	float labelHeight = 0;	// height of the label (pixel count)
819 	if (fLabel) {
820 		// leave 6 pixels of the frame, and have a gap of 4 pixels between
821 		// the frame and the text on either side
822 		font_height fontHeight;
823 		GetFontHeight(&fontHeight);
824 		fLayoutData->label_box.Set(6.0f, 0, 14.0f + StringWidth(fLabel),
825 			ceilf(fontHeight.ascent));
826 		labelHeight = ceilf(fontHeight.ascent + fontHeight.descent) + 1;
827 	} else if (fLabelView) {
828 		// the label view is placed at (0, 10) at its preferred size
829 		BSize size = fLabelView->PreferredSize();
830 		fLayoutData->label_box.Set(10, 0, 10 + size.width, size.height);
831 		labelHeight = size.height + 1;
832 	} else
833 		label = false;
834 
835 	// border
836 	switch (fStyle) {
837 		case B_PLAIN_BORDER:
838 			fLayoutData->insets.Set(1, 1, 1, 1);
839 			break;
840 		case B_FANCY_BORDER:
841 			fLayoutData->insets.Set(3, 3, 3, 3);
842 			break;
843 		case B_NO_BORDER:
844 		default:
845 			fLayoutData->insets.Set(0, 0, 0, 0);
846 			break;
847 	}
848 
849 	// if there's a label, the top inset will be dictated by the label
850 	if (label && labelHeight > fLayoutData->insets.top)
851 		fLayoutData->insets.top = labelHeight;
852 
853 	// total number of pixel the border adds
854 	float addWidth = fLayoutData->insets.left + fLayoutData->insets.right;
855 	float addHeight = fLayoutData->insets.top + fLayoutData->insets.bottom;
856 
857 	// compute the minimal width induced by the label
858 	float minWidth;
859 	if (label)
860 		minWidth = fLayoutData->label_box.right + fLayoutData->insets.right;
861 	else
862 		minWidth = addWidth - 1;
863 
864 	BAlignment alignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER);
865 
866 	// finally consider the child constraints, if we shall support layout
867 	BView* child = _Child();
868 	if (child && (child->Flags() & B_SUPPORTS_LAYOUT)) {
869 		BSize min = child->MinSize();
870 		BSize max = child->MaxSize();
871 		BSize preferred = child->PreferredSize();
872 
873 		min.width += addWidth;
874 		min.height += addHeight;
875 		preferred.width += addWidth;
876 		preferred.height += addHeight;
877 		max.width = BLayoutUtils::AddDistances(max.width, addWidth - 1);
878 		max.height = BLayoutUtils::AddDistances(max.height, addHeight - 1);
879 
880 		if (min.width < minWidth)
881 			min.width = minWidth;
882 		BLayoutUtils::FixSizeConstraints(min, max, preferred);
883 
884 		fLayoutData->min = min;
885 		fLayoutData->max = max;
886 		fLayoutData->preferred = preferred;
887 
888 		BAlignment childAlignment = child->LayoutAlignment();
889 		if (childAlignment.horizontal == B_ALIGN_USE_FULL_WIDTH)
890 			alignment.horizontal = B_ALIGN_USE_FULL_WIDTH;
891 		if (childAlignment.vertical == B_ALIGN_USE_FULL_HEIGHT)
892 			alignment.vertical = B_ALIGN_USE_FULL_HEIGHT;
893 
894 		fLayoutData->alignment = alignment;
895 	} else {
896 		fLayoutData->min.Set(minWidth, addHeight - 1);
897 		fLayoutData->max.Set(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED);
898 		fLayoutData->preferred = fLayoutData->min;
899 		fLayoutData->alignment = alignment;
900 	}
901 
902 	fLayoutData->valid = true;
903 	ResetLayoutInvalidation();
904 }
905 
906 
907 extern "C" void
908 B_IF_GCC_2(InvalidateLayout__4BBoxb, _ZN4BBox16InvalidateLayoutEb)(
909 	BBox* box, bool descendants)
910 {
911 	perform_data_layout_invalidated data;
912 	data.descendants = descendants;
913 
914 	box->Perform(PERFORM_CODE_LAYOUT_INVALIDATED, &data);
915 }
916 
917