175936a02SAxel Dörfler/*
2c67dde0fSKacper Kasper * Copyright 2001-2019 Haiku, Inc. All rights reserved.
375936a02SAxel Dörfler * Distributed under the terms of the MIT License.
475936a02SAxel Dörfler *
575936a02SAxel Dörfler * Authors:
61e6e124cSJohn Scipione *		Stephan A��mus, superstippi@gmx.de
775936a02SAxel Dörfler *		Axel D��rfler, axeld@pinc-software.de
81e6e124cSJohn Scipione *		Adrian Oanca, adioanca@cotty.iren.ro
91e6e124cSJohn Scipione *		Ingo Weinhold. ingo_weinhold@gmx.de
10551438b9SJulian Harnath *		Julian Harnath, julian.harnath@rwth-aachen.de
117f9368caSlooncraz *		Joseph Groover, looncraz@looncraz.net
1275936a02SAxel Dörfler */
13b56bbfdfSAdi Oanca
1468504ee9SAxel Dörfler
15834a9474SAxel Dörfler#include <View.h>
16b56bbfdfSAdi Oanca
17a6213356SJohn Scipione#include <algorithm>
1839fbf550SOliver Tappe#include <new>
19621a8324SAxel Dörfler
20834a9474SAxel Dörfler#include <math.h>
21834a9474SAxel Dörfler#include <stdio.h>
22834a9474SAxel Dörfler
23621a8324SAxel Dörfler#include <Application.h>
24621a8324SAxel Dörfler#include <Bitmap.h>
25621a8324SAxel Dörfler#include <Button.h>
26621a8324SAxel Dörfler#include <Cursor.h>
2707cc0513SStefano Ceccherini#include <File.h>
28834a9474SAxel Dörfler#include <GradientLinear.h>
29834a9474SAxel Dörfler#include <GradientRadial.h>
30834a9474SAxel Dörfler#include <GradientRadialFocus.h>
31834a9474SAxel Dörfler#include <GradientDiamond.h>
32834a9474SAxel Dörfler#include <GradientConic.h>
33b56bbfdfSAdi Oanca#include <InterfaceDefs.h>
349ecf9d1cSIngo Weinhold#include <Layout.h>
359ecf9d1cSIngo Weinhold#include <LayoutContext.h>
369ecf9d1cSIngo Weinhold#include <LayoutUtils.h>
3707cc0513SStefano Ceccherini#include <MenuBar.h>
38a159d2c7SDarkWyrm#include <Message.h>
39b56bbfdfSAdi Oanca#include <MessageQueue.h>
40bd97b9adSAlex Wilson#include <ObjectList.h>
41621a8324SAxel Dörfler#include <Picture.h>
42b56bbfdfSAdi Oanca#include <Point.h>
43621a8324SAxel Dörfler#include <Polygon.h>
44621a8324SAxel Dörfler#include <PropertyInfo.h>
45b56bbfdfSAdi Oanca#include <Region.h>
46b56bbfdfSAdi Oanca#include <ScrollBar.h>
47a159d2c7SDarkWyrm#include <Shape.h>
48a159d2c7SDarkWyrm#include <Shelf.h>
493ceb31b9SDarkWyrm#include <String.h>
50621a8324SAxel Dörfler#include <Window.h>
51cf10934eSMichael Lotz
5239fbf550SOliver Tappe#include <AppMisc.h>
5339fbf550SOliver Tappe#include <AppServerLink.h>
5439fbf550SOliver Tappe#include <binary_compatibility/Interface.h>
55cbac1a23SIngo Weinhold#include <binary_compatibility/Support.h>
5639fbf550SOliver Tappe#include <MessagePrivate.h>
5739fbf550SOliver Tappe#include <MessageUtils.h>
5839fbf550SOliver Tappe#include <PortLink.h>
5939fbf550SOliver Tappe#include <ServerProtocol.h>
6012349c7dSStephan Aßmus#include <ServerProtocolStructs.h>
6139fbf550SOliver Tappe#include <ShapePrivate.h>
628318af01SAxel Dörfler#include <ToolTip.h>
638318af01SAxel Dörfler#include <ToolTipManager.h>
6439fbf550SOliver Tappe#include <TokenSpace.h>
6539fbf550SOliver Tappe#include <ViewPrivate.h>
66b56bbfdfSAdi Oanca
67af43bb3cSStephan Aßmususing std::nothrow;
68af43bb3cSStephan Aßmus
696e627905SAdi Oanca//#define DEBUG_BVIEW
702f8db4e4SAdi Oanca#ifdef DEBUG_BVIEW
712f8db4e4SAdi Oanca#	include <stdio.h>
722f8db4e4SAdi Oanca#	define STRACE(x) printf x
73099fb2d3SStephan Aßmus#	define BVTRACE _PrintToStream()
742f8db4e4SAdi Oanca#else
758bd2c11fSAxel Dörfler#	define STRACE(x) ;
762f8db4e4SAdi Oanca#	define BVTRACE ;
772f8db4e4SAdi Oanca#endif
782f8db4e4SAdi Oanca
79b56bbfdfSAdi Oanca
8075936a02SAxel Dörflerstatic property_info sViewPropInfo[] = {
81a47e7e30SJérôme Duval	{ "Frame", { B_GET_PROPERTY, B_SET_PROPERTY },
82a47e7e30SJérôme Duval		{ B_DIRECT_SPECIFIER, 0 }, "The view's frame rectangle.", 0,
8328d5567eSAxel Dörfler		{ B_RECT_TYPE }
84a03ac895SJérôme Duval	},
85a47e7e30SJérôme Duval	{ "Hidden", { B_GET_PROPERTY, B_SET_PROPERTY },
86a47e7e30SJérôme Duval		{ B_DIRECT_SPECIFIER, 0 }, "Whether or not the view is hidden.",
8728d5567eSAxel Dörfler		0, { B_BOOL_TYPE }
88a03ac895SJérôme Duval	},
89b56bbfdfSAdi Oanca	{ "Shelf", { 0 },
9028d5567eSAxel Dörfler		{ B_DIRECT_SPECIFIER, 0 }, "Directs the scripting message to the "
9128d5567eSAxel Dörfler			"shelf.", 0
92a03ac895SJérôme Duval	},
93b56bbfdfSAdi Oanca	{ "View", { B_COUNT_PROPERTIES, 0 },
947b40eb42SPhilippe Houdoin		{ B_DIRECT_SPECIFIER, 0 }, "Returns the number of child views.", 0,
9528d5567eSAxel Dörfler		{ B_INT32_TYPE }
96a03ac895SJérôme Duval	},
97b56bbfdfSAdi Oanca	{ "View", { 0 },
9828d5567eSAxel Dörfler		{ B_INDEX_SPECIFIER, B_REVERSE_INDEX_SPECIFIER, B_NAME_SPECIFIER, 0 },
9928d5567eSAxel Dörfler		"Directs the scripting message to the specified view.", 0
100a03ac895SJérôme Duval	},
101b56bbfdfSAdi Oanca
102346d1496SHumdinger	{ 0 }
10328d5567eSAxel Dörfler};
104b56bbfdfSAdi Oanca
105b56bbfdfSAdi Oanca
106e9e39349SAxel Dörfler//	#pragma mark -
107b56bbfdfSAdi Oanca
108b56bbfdfSAdi Oanca
10978aa8eeaSAxel Dörflerstatic inline uint32
11078aa8eeaSAxel Dörflerget_uint32_color(rgb_color color)
11178aa8eeaSAxel Dörfler{
11268504ee9SAxel Dörfler	return B_BENDIAN_TO_HOST_INT32(*(uint32*)&color);
1135464b10fSAxel Dörfler		// rgb_color is always in rgba format, no matter what endian;
1145464b10fSAxel Dörfler		// we always return the int32 value in host endian.
1155464b10fSAxel Dörfler}
1165464b10fSAxel Dörfler
1175464b10fSAxel Dörfler
1185464b10fSAxel Dörflerstatic inline rgb_color
1195464b10fSAxel Dörflerget_rgb_color(uint32 value)
1205464b10fSAxel Dörfler{
1215464b10fSAxel Dörfler	value = B_HOST_TO_BENDIAN_INT32(value);
12268504ee9SAxel Dörfler	return *(rgb_color*)&value;
12378aa8eeaSAxel Dörfler}
12478aa8eeaSAxel Dörfler
12578aa8eeaSAxel Dörfler
12678aa8eeaSAxel Dörfler//	#pragma mark -
12778aa8eeaSAxel Dörfler
12878aa8eeaSAxel Dörfler
12980a230b1SAxel Dörflernamespace BPrivate {
13080a230b1SAxel Dörfler
13180a230b1SAxel DörflerViewState::ViewState()
13280a230b1SAxel Dörfler{
13380a230b1SAxel Dörfler	pen_location.Set(0, 0);
13480a230b1SAxel Dörfler	pen_size = 1.0;
13580a230b1SAxel Dörfler
1368e89843eSStephan Aßmus	// NOTE: the clipping_region is empty
1378e89843eSStephan Aßmus	// on construction but it is not used yet,
1388e89843eSStephan Aßmus	// we avoid having to keep track of it via
1398e89843eSStephan Aßmus	// this flag
1408e89843eSStephan Aßmus	clipping_region_used = false;
14180a230b1SAxel Dörfler
142bc685a64SStephan Aßmus	high_color = (rgb_color){ 0, 0, 0, 255 };
1434cf88b82SMarcus Overhagen	low_color = (rgb_color){ 255, 255, 255, 255 };
14480a230b1SAxel Dörfler	view_color = low_color;
1457f9368caSlooncraz	which_view_color = B_NO_COLOR;
1467f9368caSlooncraz	which_view_color_tint = B_NO_TINT;
1477f9368caSlooncraz
1487f9368caSlooncraz	which_high_color = B_NO_COLOR;
1497f9368caSlooncraz	which_high_color_tint = B_NO_TINT;
1507f9368caSlooncraz
1517f9368caSlooncraz	which_low_color = B_NO_COLOR;
1527f9368caSlooncraz	which_low_color_tint = B_NO_TINT;
15380a230b1SAxel Dörfler
15480a230b1SAxel Dörfler	pattern = B_SOLID_HIGH;
15580a230b1SAxel Dörfler	drawing_mode = B_OP_COPY;
15680a230b1SAxel Dörfler
15780a230b1SAxel Dörfler	origin.Set(0, 0);
15880a230b1SAxel Dörfler
15972b26b59SStephan Aßmus	line_join = B_MITER_JOIN;
16080a230b1SAxel Dörfler	line_cap = B_BUTT_CAP;
16180a230b1SAxel Dörfler	miter_limit = B_DEFAULT_MITER_LIMIT;
162eb431663SAdrien Destugues	fill_rule = B_NONZERO;
16380a230b1SAxel Dörfler
16480a230b1SAxel Dörfler	alpha_source_mode = B_PIXEL_ALPHA;
16580a230b1SAxel Dörfler	alpha_function_mode = B_ALPHA_OVERLAY;
16680a230b1SAxel Dörfler
16780a230b1SAxel Dörfler	scale = 1.0;
16880a230b1SAxel Dörfler
16980a230b1SAxel Dörfler	font = *be_plain_font;
17080a230b1SAxel Dörfler	font_flags = font.Flags();
17180a230b1SAxel Dörfler	font_aliasing = false;
17280a230b1SAxel Dörfler
173834a9474SAxel Dörfler	// We only keep the B_VIEW_CLIP_REGION_BIT flag invalidated,
174834a9474SAxel Dörfler	// because we should get the clipping region from app_server.
175834a9474SAxel Dörfler	// The other flags do not need to be included because the data they
176834a9474SAxel Dörfler	// represent is already in sync with app_server - app_server uses the
177834a9474SAxel Dörfler	// same init (default) values.
17880a230b1SAxel Dörfler	valid_flags = ~B_VIEW_CLIP_REGION_BIT;
17980a230b1SAxel Dörfler
180e229fcb2SStephan Aßmus	archiving_flags = B_VIEW_FRAME_BIT | B_VIEW_RESIZE_BIT;
18180a230b1SAxel Dörfler}
18280a230b1SAxel Dörfler
18380a230b1SAxel Dörfler
18480a230b1SAxel Dörflervoid
18580a230b1SAxel DörflerViewState::UpdateServerFontState(BPrivate::PortLink &link)
18680a230b1SAxel Dörfler{
187c7a77521SAxel Dörfler	link.StartMessage(AS_VIEW_SET_FONT_STATE);
18880a230b1SAxel Dörfler	link.Attach<uint16>(font_flags);
18910f6ed94SStephan Aßmus		// always present
19080a230b1SAxel Dörfler
19110f6ed94SStephan Aßmus	if (font_flags & B_FONT_FAMILY_AND_STYLE)
19210f6ed94SStephan Aßmus		link.Attach<uint32>(font.FamilyAndStyle());
19380a230b1SAxel Dörfler
19480a230b1SAxel Dörfler	if (font_flags & B_FONT_SIZE)
19580a230b1SAxel Dörfler		link.Attach<float>(font.Size());
19680a230b1SAxel Dörfler
19780a230b1SAxel Dörfler	if (font_flags & B_FONT_SHEAR)
19880a230b1SAxel Dörfler		link.Attach<float>(font.Shear());
19980a230b1SAxel Dörfler
20080a230b1SAxel Dörfler	if (font_flags & B_FONT_ROTATION)
20180a230b1SAxel Dörfler		link.Attach<float>(font.Rotation());
20280a230b1SAxel Dörfler
20310f6ed94SStephan Aßmus	if (font_flags & B_FONT_FALSE_BOLD_WIDTH)
20410f6ed94SStephan Aßmus		link.Attach<float>(font.FalseBoldWidth());
20510f6ed94SStephan Aßmus
20680a230b1SAxel Dörfler	if (font_flags & B_FONT_SPACING)
20780a230b1SAxel Dörfler		link.Attach<uint8>(font.Spacing());
20880a230b1SAxel Dörfler
20980a230b1SAxel Dörfler	if (font_flags & B_FONT_ENCODING)
21080a230b1SAxel Dörfler		link.Attach<uint8>(font.Encoding());
21180a230b1SAxel Dörfler
21280a230b1SAxel Dörfler	if (font_flags & B_FONT_FACE)
21380a230b1SAxel Dörfler		link.Attach<uint16>(font.Face());
21480a230b1SAxel Dörfler
21580a230b1SAxel Dörfler	if (font_flags & B_FONT_FLAGS)
21680a230b1SAxel Dörfler		link.Attach<uint32>(font.Flags());
21780a230b1SAxel Dörfler}
21880a230b1SAxel Dörfler
21980a230b1SAxel Dörfler
22080a230b1SAxel Dörflervoid
22180a230b1SAxel DörflerViewState::UpdateServerState(BPrivate::PortLink &link)
22280a230b1SAxel Dörfler{
22380a230b1SAxel Dörfler	UpdateServerFontState(link);
22480a230b1SAxel Dörfler
225c7a77521SAxel Dörfler	link.StartMessage(AS_VIEW_SET_STATE);
22612349c7dSStephan Aßmus
22712349c7dSStephan Aßmus	ViewSetStateInfo info;
22812349c7dSStephan Aßmus	info.penLocation = pen_location;
22912349c7dSStephan Aßmus	info.penSize = pen_size;
23012349c7dSStephan Aßmus	info.highColor = high_color;
23112349c7dSStephan Aßmus	info.lowColor = low_color;
2327f9368caSlooncraz	info.whichHighColor = which_high_color;
2337f9368caSlooncraz	info.whichLowColor = which_low_color;
2347f9368caSlooncraz	info.whichHighColorTint = which_high_color_tint;
2357f9368caSlooncraz	info.whichLowColorTint = which_low_color_tint;
23612349c7dSStephan Aßmus	info.pattern = pattern;
23712349c7dSStephan Aßmus	info.drawingMode = drawing_mode;
23812349c7dSStephan Aßmus	info.origin = origin;
23912349c7dSStephan Aßmus	info.scale = scale;
24012349c7dSStephan Aßmus	info.lineJoin = line_join;
24112349c7dSStephan Aßmus	info.lineCap = line_cap;
24212349c7dSStephan Aßmus	info.miterLimit = miter_limit;
24324479670SStephan Aßmus	info.fillRule = fill_rule;
24412349c7dSStephan Aßmus	info.alphaSourceMode = alpha_source_mode;
24512349c7dSStephan Aßmus	info.alphaFunctionMode = alpha_function_mode;
24612349c7dSStephan Aßmus	info.fontAntialiasing = font_aliasing;
24712349c7dSStephan Aßmus	link.Attach<ViewSetStateInfo>(info);
24880a230b1SAxel Dörfler
249630e3f14SJérôme Duval	// BAffineTransform is transmitted as a double array
250630e3f14SJérôme Duval	double _transform[6];
251630e3f14SJérôme Duval	if (transform.Flatten(_transform, sizeof(_transform)) != B_OK)
252630e3f14SJérôme Duval		return;
253630e3f14SJérôme Duval	link.Attach<double[6]>(_transform);
254630e3f14SJérôme Duval
25580a230b1SAxel Dörfler	// we send the 'local' clipping region... if we have one...
25612349c7dSStephan Aßmus	// TODO: Could be optimized, but is low prio, since most views won't
25712349c7dSStephan Aßmus	// have a custom clipping region.
2588e89843eSStephan Aßmus	if (clipping_region_used) {
2598e89843eSStephan Aßmus		int32 count = clipping_region.CountRects();
2608e89843eSStephan Aßmus		link.Attach<int32>(count);
2618e89843eSStephan Aßmus		for (int32 i = 0; i < count; i++)
2628e89843eSStephan Aßmus			link.Attach<BRect>(clipping_region.RectAt(i));
2638e89843eSStephan Aßmus	} else {
2648e89843eSStephan Aßmus		// no clipping region
2658e89843eSStephan Aßmus		link.Attach<int32>(-1);
2668e89843eSStephan Aßmus	}
26780a230b1SAxel Dörfler
268834a9474SAxel Dörfler	// Although we might have a 'local' clipping region, when we call
269834a9474SAxel Dörfler	// BView::GetClippingRegion() we ask for the 'global' one and it
270834a9474SAxel Dörfler	// is kept on server, so we must invalidate B_VIEW_CLIP_REGION_BIT flag
27180a230b1SAxel Dörfler
27280a230b1SAxel Dörfler	valid_flags = ~B_VIEW_CLIP_REGION_BIT;
27380a230b1SAxel Dörfler}
27480a230b1SAxel Dörfler
275bb1336b4SAxel Dörfler
276bb1336b4SAxel Dörflervoid
277bb1336b4SAxel DörflerViewState::UpdateFrom(BPrivate::PortLink &link)
278bb1336b4SAxel Dörfler{
279c7a77521SAxel Dörfler	link.StartMessage(AS_VIEW_GET_STATE);
280bb1336b4SAxel Dörfler
281bb1336b4SAxel Dörfler	int32 code;
282bb1336b4SAxel Dörfler	if (link.FlushWithReply(code) != B_OK
2837cc0dec4SAxel Dörfler		|| code != B_OK)
284bb1336b4SAxel Dörfler		return;
285bb1336b4SAxel Dörfler
28612349c7dSStephan Aßmus	ViewGetStateInfo info;
28712349c7dSStephan Aßmus	link.Read<ViewGetStateInfo>(&info);
288bb1336b4SAxel Dörfler
28912349c7dSStephan Aßmus	// set view's font state
290bb1336b4SAxel Dörfler	font_flags = B_FONT_ALL;
29112349c7dSStephan Aßmus	font.SetFamilyAndStyle(info.fontID);
29212349c7dSStephan Aßmus	font.SetSize(info.fontSize);
29312349c7dSStephan Aßmus	font.SetShear(info.fontShear);
29412349c7dSStephan Aßmus	font.SetRotation(info.fontRotation);
29512349c7dSStephan Aßmus	font.SetFalseBoldWidth(info.fontFalseBoldWidth);
29612349c7dSStephan Aßmus	font.SetSpacing(info.fontSpacing);
29712349c7dSStephan Aßmus	font.SetEncoding(info.fontEncoding);
29812349c7dSStephan Aßmus	font.SetFace(info.fontFace);
29912349c7dSStephan Aßmus	font.SetFlags(info.fontFlags);
30012349c7dSStephan Aßmus
30112349c7dSStephan Aßmus	// set view's state
30212349c7dSStephan Aßmus	pen_location = info.viewStateInfo.penLocation;
30312349c7dSStephan Aßmus	pen_size = info.viewStateInfo.penSize;
30412349c7dSStephan Aßmus	high_color = info.viewStateInfo.highColor;
30512349c7dSStephan Aßmus	low_color = info.viewStateInfo.lowColor;
30612349c7dSStephan Aßmus	pattern = info.viewStateInfo.pattern;
30712349c7dSStephan Aßmus	drawing_mode = info.viewStateInfo.drawingMode;
30812349c7dSStephan Aßmus	origin = info.viewStateInfo.origin;
30912349c7dSStephan Aßmus	scale = info.viewStateInfo.scale;
31012349c7dSStephan Aßmus	line_join = info.viewStateInfo.lineJoin;
31112349c7dSStephan Aßmus	line_cap = info.viewStateInfo.lineCap;
31212349c7dSStephan Aßmus	miter_limit = info.viewStateInfo.miterLimit;
31324479670SStephan Aßmus	fill_rule = info.viewStateInfo.fillRule;
31412349c7dSStephan Aßmus	alpha_source_mode = info.viewStateInfo.alphaSourceMode;
31512349c7dSStephan Aßmus	alpha_function_mode = info.viewStateInfo.alphaFunctionMode;
31612349c7dSStephan Aßmus	font_aliasing = info.viewStateInfo.fontAntialiasing;
317bb1336b4SAxel Dörfler
318630e3f14SJérôme Duval	// BAffineTransform is transmitted as a double array
319630e3f14SJérôme Duval	double _transform[6];
320630e3f14SJérôme Duval	link.Read<double[6]>(&_transform);
321630e3f14SJérôme Duval	if (transform.Unflatten(B_AFFINE_TRANSFORM_TYPE, _transform,
322630e3f14SJérôme Duval		sizeof(_transform)) != B_OK) {
323630e3f14SJérôme Duval		return;
324630e3f14SJérôme Duval	}
325630e3f14SJérôme Duval
3268e89843eSStephan Aßmus	// read the user clipping
3278e89843eSStephan Aßmus	// (that's NOT the current View visible clipping but the additional
3288e89843eSStephan Aßmus	// user specified clipping!)
3298e89843eSStephan Aßmus	int32 clippingRectCount;
3308e89843eSStephan Aßmus	link.Read<int32>(&clippingRectCount);
3318e89843eSStephan Aßmus	if (clippingRectCount >= 0) {
3328e89843eSStephan Aßmus		clipping_region.MakeEmpty();
3338e89843eSStephan Aßmus		for (int32 i = 0; i < clippingRectCount; i++) {
3348e89843eSStephan Aßmus			BRect rect;
3358e89843eSStephan Aßmus			link.Read<BRect>(&rect);
3368e89843eSStephan Aßmus			clipping_region.Include(rect);
3378e89843eSStephan Aßmus		}
3388e89843eSStephan Aßmus	} else {
3398e89843eSStephan Aßmus		// no user clipping used
3408e89843eSStephan Aßmus		clipping_region_used = false;
3418e89843eSStephan Aßmus	}
342bb1336b4SAxel Dörfler
343bb1336b4SAxel Dörfler	valid_flags = ~B_VIEW_CLIP_REGION_BIT;
344bb1336b4SAxel Dörfler}
345bb1336b4SAxel Dörfler
34680a230b1SAxel Dörfler}	// namespace BPrivate
34780a230b1SAxel Dörfler
34880a230b1SAxel Dörfler
34980a230b1SAxel Dörfler//	#pragma mark -
35080a230b1SAxel Dörfler
35180a230b1SAxel Dörfler
352cbac1a23SIngo Weinhold// archiving constants
353cbac1a23SIngo Weinholdnamespace {
3544a254e4dSAlex Wilson	const char* const kSizesField = "BView:sizes";
3554a254e4dSAlex Wilson		// kSizesField = {min, max, pref}
3564a254e4dSAlex Wilson	const char* const kAlignmentField = "BView:alignment";
3574a254e4dSAlex Wilson	const char* const kLayoutField = "BView:layout";
358cbac1a23SIngo Weinhold}
359cbac1a23SIngo Weinhold
360cbac1a23SIngo Weinhold
3619ecf9d1cSIngo Weinholdstruct BView::LayoutData {
3629ecf9d1cSIngo Weinhold	LayoutData()
363834a9474SAxel Dörfler		:
364834a9474SAxel Dörfler		fMinSize(),
365834a9474SAxel Dörfler		fMaxSize(),
366834a9474SAxel Dörfler		fPreferredSize(),
367834a9474SAxel Dörfler		fAlignment(),
368834a9474SAxel Dörfler		fLayoutInvalidationDisabled(0),
369834a9474SAxel Dörfler		fLayout(NULL),
370834a9474SAxel Dörfler		fLayoutContext(NULL),
371bd97b9adSAlex Wilson		fLayoutItems(5, false),
372a0747aadSIngo Weinhold		fLayoutValid(true),		// TODO: Rethink these initial values!
373a0747aadSIngo Weinhold		fMinMaxValid(true),		//
374834a9474SAxel Dörfler		fLayoutInProgress(false),
375834a9474SAxel Dörfler		fNeedsRelayout(true)
3769ecf9d1cSIngo Weinhold	{
3779ecf9d1cSIngo Weinhold	}
3789ecf9d1cSIngo Weinhold
379cbac1a23SIngo Weinhold	status_t
380cbac1a23SIngo Weinhold	AddDataToArchive(BMessage* archive)
381cbac1a23SIngo Weinhold	{
3824a254e4dSAlex Wilson		status_t err = archive->AddSize(kSizesField, fMinSize);
383cbac1a23SIngo Weinhold
384cbac1a23SIngo Weinhold		if (err == B_OK)
3854a254e4dSAlex Wilson			err = archive->AddSize(kSizesField, fMaxSize);
3864a254e4dSAlex Wilson
3874a254e4dSAlex Wilson		if (err == B_OK)
3884a254e4dSAlex Wilson			err = archive->AddSize(kSizesField, fPreferredSize);
389cbac1a23SIngo Weinhold
390cbac1a23SIngo Weinhold		if (err == B_OK)
391cbac1a23SIngo Weinhold			err = archive->AddAlignment(kAlignmentField, fAlignment);
392cbac1a23SIngo Weinhold
393cbac1a23SIngo Weinhold		return err;
394cbac1a23SIngo Weinhold	}
395cbac1a23SIngo Weinhold
396cbac1a23SIngo Weinhold	void
397cbac1a23SIngo Weinhold	PopulateFromArchive(BMessage* archive)
398cbac1a23SIngo Weinhold	{
3994a254e4dSAlex Wilson		archive->FindSize(kSizesField, 0, &fMinSize);
4004a254e4dSAlex Wilson		archive->FindSize(kSizesField, 1, &fMaxSize);
4014a254e4dSAlex Wilson		archive->FindSize(kSizesField, 2, &fPreferredSize);
402cbac1a23SIngo Weinhold		archive->FindAlignment(kAlignmentField, &fAlignment);
403cbac1a23SIngo Weinhold	}
404cbac1a23SIngo Weinhold
4059ecf9d1cSIngo Weinhold	BSize			fMinSize;
4069ecf9d1cSIngo Weinhold	BSize			fMaxSize;
4079ecf9d1cSIngo Weinhold	BSize			fPreferredSize;
4089ecf9d1cSIngo Weinhold	BAlignment		fAlignment;
4099ecf9d1cSIngo Weinhold	int				fLayoutInvalidationDisabled;
4109ecf9d1cSIngo Weinhold	BLayout*		fLayout;
4119ecf9d1cSIngo Weinhold	BLayoutContext*	fLayoutContext;
412bd97b9adSAlex Wilson	BObjectList<BLayoutItem> fLayoutItems;
4139ecf9d1cSIngo Weinhold	bool			fLayoutValid;
414a0747aadSIngo Weinhold	bool			fMinMaxValid;
4159ecf9d1cSIngo Weinhold	bool			fLayoutInProgress;
4169ecf9d1cSIngo Weinhold	bool			fNeedsRelayout;
4179ecf9d1cSIngo Weinhold};
4189ecf9d1cSIngo Weinhold
4199ecf9d1cSIngo Weinhold
4209ecf9d1cSIngo WeinholdBView::BView(const char* name, uint32 flags, BLayout* layout)
42168504ee9SAxel Dörfler	:
42268504ee9SAxel Dörfler	BHandler(name)
4239ecf9d1cSIngo Weinhold{
4242a493ea0SJulian Harnath	_InitData(BRect(0, 0, -1, -1), name, B_FOLLOW_NONE,
4259ecf9d1cSIngo Weinhold		flags | B_SUPPORTS_LAYOUT);
4269ecf9d1cSIngo Weinhold	SetLayout(layout);
4279ecf9d1cSIngo Weinhold}
4289ecf9d1cSIngo Weinhold
4299ecf9d1cSIngo Weinhold
43068504ee9SAxel DörflerBView::BView(BRect frame, const char* name, uint32 resizingMode, uint32 flags)
43168504ee9SAxel Dörfler	:
43268504ee9SAxel Dörfler	BHandler(name)
433e9e39349SAxel Dörfler{
43414d02d22SAxel Dörfler	_InitData(frame, name, resizingMode, flags);
435e9e39349SAxel Dörfler}
436b56bbfdfSAdi Oanca
437b56bbfdfSAdi Oanca
43868504ee9SAxel DörflerBView::BView(BMessage* archive)
43968504ee9SAxel Dörfler	:
440cbac1a23SIngo Weinhold	BHandler(BUnarchiver::PrepareArchive(archive))
441e9e39349SAxel Dörfler{
442cbac1a23SIngo Weinhold	BUnarchiver unarchiver(archive);
443aa818be6SAlex Wilson	if (!archive)
444aa818be6SAlex Wilson		debugger("BView cannot be constructed from a NULL archive.");
445cbac1a23SIngo Weinhold
446e9e39349SAxel Dörfler	BRect frame;
447e9e39349SAxel Dörfler	archive->FindRect("_frame", &frame);
448e229fcb2SStephan Aßmus
449e229fcb2SStephan Aßmus	uint32 resizingMode;
450e229fcb2SStephan Aßmus	if (archive->FindInt32("_resize_mode", (int32*)&resizingMode) != B_OK)
451e9e39349SAxel Dörfler		resizingMode = 0;
452b56bbfdfSAdi Oanca
453e229fcb2SStephan Aßmus	uint32 flags;
454e229fcb2SStephan Aßmus	if (archive->FindInt32("_flags", (int32*)&flags) != B_OK)
455e9e39349SAxel Dörfler		flags = 0;
45684e57fc9Shaydentech
45714d02d22SAxel Dörfler	_InitData(frame, Name(), resizingMode, flags);
458b56bbfdfSAdi Oanca
459e9e39349SAxel Dörfler	font_family family;
460e9e39349SAxel Dörfler	font_style style;
46168504ee9SAxel Dörfler	if (archive->FindString("_fname", 0, (const char**)&family) == B_OK
46268504ee9SAxel Dörfler		&& archive->FindString("_fname", 1, (const char**)&style) == B_OK) {
463e9e39349SAxel Dörfler		BFont font;
464e9e39349SAxel Dörfler		font.SetFamilyAndStyle(family, style);
465b56bbfdfSAdi Oanca
466e9e39349SAxel Dörfler		float size;
467e9e39349SAxel Dörfler		if (archive->FindFloat("_fflt", 0, &size) == B_OK)
468e9e39349SAxel Dörfler			font.SetSize(size);
469b56bbfdfSAdi Oanca
470e9e39349SAxel Dörfler		float shear;
471a1a5f124SJérôme Duval		if (archive->FindFloat("_fflt", 1, &shear) == B_OK
472a1a5f124SJérôme Duval			&& shear >= 45.0 && shear <= 135.0)
473e9e39349SAxel Dörfler			font.SetShear(shear);
474b56bbfdfSAdi Oanca
475e9e39349SAxel Dörfler		float rotation;
476a1a5f124SJérôme Duval		if (archive->FindFloat("_fflt", 2, &rotation) == B_OK
477a1a5f124SJérôme Duval			&& rotation >=0 && rotation <= 360)
478e229fcb2SStephan Aßmus			font.SetRotation(rotation);
479b56bbfdfSAdi Oanca
480e9e39349SAxel Dörfler		SetFont(&font, B_FONT_FAMILY_AND_STYLE | B_FONT_SIZE
481e9e39349SAxel Dörfler			| B_FONT_SHEAR | B_FONT_ROTATION);
482b56bbfdfSAdi Oanca	}
483b56bbfdfSAdi Oanca
4847f9368caSlooncraz	int32 color = 0;
4855464b10fSAxel Dörfler	if (archive->FindInt32("_color", 0, &color) == B_OK)
4865464b10fSAxel Dörfler		SetHighColor(get_rgb_color(color));
4875464b10fSAxel Dörfler	if (archive->FindInt32("_color", 1, &color) == B_OK)
4885464b10fSAxel Dörfler		SetLowColor(get_rgb_color(color));
4895464b10fSAxel Dörfler	if (archive->FindInt32("_color", 2, &color) == B_OK)
4905464b10fSAxel Dörfler		SetViewColor(get_rgb_color(color));
491b56bbfdfSAdi Oanca
4927f9368caSlooncraz	float tint = B_NO_TINT;
4937f9368caSlooncraz	if (archive->FindInt32("_uicolor", 0, &color) == B_OK
4947f9368caSlooncraz		&& color != B_NO_COLOR) {
4957f9368caSlooncraz		if (archive->FindFloat("_uitint", 0, &tint) != B_OK)
4967f9368caSlooncraz			tint = B_NO_TINT;
497