1a71c9607SAxel Dörfler/*
27a96554cSlooncraz * Copyright 2001-2015, Haiku, Inc.
3a71c9607SAxel Dörfler * Distributed under the terms of the MIT License.
4a71c9607SAxel Dörfler *
5a71c9607SAxel Dörfler * Authors:
6be260374SIngo Weinhold *		Marc Flerackers, mflerackers@androme.be
7be260374SIngo Weinhold *		Ingo Weinhold, ingo_weinhold@gmx.de
8a71c9607SAxel Dörfler */
9a71c9607SAxel Dörfler
10092e3093SJohn Scipione
11092e3093SJohn Scipione// BControl is the base class for user-event handling objects.
12a71c9607SAxel Dörfler
13ac6f7aa8SMarc Flerackers
1439fbf550SOliver Tappe#include <stdlib.h>
1539fbf550SOliver Tappe#include <string.h>
1639fbf550SOliver Tappe
17ac6f7aa8SMarc Flerackers#include <Control.h>
18ac6f7aa8SMarc Flerackers#include <PropertyInfo.h>
19ac6f7aa8SMarc Flerackers#include <Window.h>
20ac6f7aa8SMarc Flerackers
2139fbf550SOliver Tappe#include <binary_compatibility/Interface.h>
2297bf0ce3SIngo Weinhold#include <Icon.h>
23ac6f7aa8SMarc Flerackers
24ac6f7aa8SMarc Flerackers
2555932743SAxel Dörflerstatic property_info sPropertyList[] = {
26ac6f7aa8SMarc Flerackers	{
27ac6f7aa8SMarc Flerackers		"Enabled",
2855932743SAxel Dörfler		{ B_GET_PROPERTY, B_SET_PROPERTY },
2955932743SAxel Dörfler		{ B_DIRECT_SPECIFIER },
3055932743SAxel Dörfler		NULL, 0,
3155932743SAxel Dörfler		{ B_BOOL_TYPE }
32ac6f7aa8SMarc Flerackers	},
33ac6f7aa8SMarc Flerackers	{
34ac6f7aa8SMarc Flerackers		"Label",
3555932743SAxel Dörfler		{ B_GET_PROPERTY, B_SET_PROPERTY },
3655932743SAxel Dörfler		{ B_DIRECT_SPECIFIER },
3755932743SAxel Dörfler		NULL, 0,
3855932743SAxel Dörfler		{ B_STRING_TYPE }
39ac6f7aa8SMarc Flerackers	},
40ac6f7aa8SMarc Flerackers	{
41ac6f7aa8SMarc Flerackers		"Value",
4255932743SAxel Dörfler		{ B_GET_PROPERTY, B_SET_PROPERTY },
4355932743SAxel Dörfler		{ B_DIRECT_SPECIFIER },
4455932743SAxel Dörfler		NULL, 0,
4555932743SAxel Dörfler		{ B_INT32_TYPE }
46ac6f7aa8SMarc Flerackers	},
47346d1496SHumdinger
4816af9b4cSHumdinger	{ 0 }
49ac6f7aa8SMarc Flerackers};
50ac6f7aa8SMarc Flerackers
5155932743SAxel Dörfler
52092e3093SJohn ScipioneBControl::BControl(BRect frame, const char* name, const char* label,
53092e3093SJohn Scipione	BMessage* message, uint32 resizingMode, uint32 flags)
54092e3093SJohn Scipione	:
55092e3093SJohn Scipione	BView(frame, name, resizingMode, flags)
56ac6f7aa8SMarc Flerackers{
5747bc8348SMarc Flerackers	InitData(NULL);
5847bc8348SMarc Flerackers
5947bc8348SMarc Flerackers	SetLabel(label);
6047bc8348SMarc Flerackers	SetMessage(message);
61ac6f7aa8SMarc Flerackers}
6255932743SAxel Dörfler
6355932743SAxel Dörfler
64092e3093SJohn ScipioneBControl::BControl(const char* name, const char* label, BMessage* message,
65a2c9eeeeSIngo Weinhold	uint32 flags)
66092e3093SJohn Scipione	:
67092e3093SJohn Scipione	BView(name, flags)
68a2c9eeeeSIngo Weinhold{
69a2c9eeeeSIngo Weinhold	InitData(NULL);
70a2c9eeeeSIngo Weinhold
71a2c9eeeeSIngo Weinhold	SetLabel(label);
72a2c9eeeeSIngo Weinhold	SetMessage(message);
73a2c9eeeeSIngo Weinhold}
74a2c9eeeeSIngo Weinhold
75a2c9eeeeSIngo Weinhold
76ac6f7aa8SMarc FlerackersBControl::~BControl()
77ac6f7aa8SMarc Flerackers{
7855932743SAxel Dörfler	free(fLabel);
7997bf0ce3SIngo Weinhold	delete fIcon;
8047bc8348SMarc Flerackers	SetMessage(NULL);
81ac6f7aa8SMarc Flerackers}
8255932743SAxel Dörfler
8355932743SAxel Dörfler
84092e3093SJohn ScipioneBControl::BControl(BMessage* data)
85092e3093SJohn Scipione	:
86092e3093SJohn Scipione	BView(data)
87ac6f7aa8SMarc Flerackers{
88092e3093SJohn Scipione	InitData(data);
8947bc8348SMarc Flerackers
9047bc8348SMarc Flerackers	BMessage message;
91092e3093SJohn Scipione	if (data->FindMessage("_msg", &message) == B_OK)
9247bc8348SMarc Flerackers		SetMessage(new BMessage(message));
93ac6f7aa8SMarc Flerackers
94092e3093SJohn Scipione	const char* label;
95092e3093SJohn Scipione	if (data->FindString("_label", &label) == B_OK)
96ac6f7aa8SMarc Flerackers		SetLabel(label);
97ac6f7aa8SMarc Flerackers
9847bc8348SMarc Flerackers	int32 value;
99092e3093SJohn Scipione	if (data->FindInt32("_val", &value) == B_OK)
10047bc8348SMarc Flerackers		SetValue(value);
101ac6f7aa8SMarc Flerackers
10247bc8348SMarc Flerackers	bool toggle;
103092e3093SJohn Scipione	if (data->FindBool("_disable", &toggle) == B_OK)
10447bc8348SMarc Flerackers		SetEnabled(!toggle);
10547bc8348SMarc Flerackers
106092e3093SJohn Scipione	if (data->FindBool("be:wants_nav", &toggle) == B_OK)
10747bc8348SMarc Flerackers		fWantsNav = toggle;
108ac6f7aa8SMarc Flerackers}
10955932743SAxel Dörfler
11055932743SAxel Dörfler
111092e3093SJohn ScipioneBArchivable*
112092e3093SJohn ScipioneBControl::Instantiate(BMessage* data)
113ac6f7aa8SMarc Flerackers{
114092e3093SJohn Scipione	if (validate_instantiation(data, "BControl"))
115092e3093SJohn Scipione		return new BControl(data);
116ac6f7aa8SMarc Flerackers
11755932743SAxel Dörfler	return NULL;
11855932743SAxel Dörfler}
119ac6f7aa8SMarc Flerackers
120ac6f7aa8SMarc Flerackers
12155932743SAxel Dörflerstatus_t
122092e3093SJohn ScipioneBControl::Archive(BMessage* data, bool deep) const
12355932743SAxel Dörfler{
124092e3093SJohn Scipione	status_t status = BView::Archive(data, deep);
125ac6f7aa8SMarc Flerackers
12655932743SAxel Dörfler	if (status == B_OK && Message())
127092e3093SJohn Scipione		status = data->AddMessage("_msg", Message());
128ac6f7aa8SMarc Flerackers
12955932743SAxel Dörfler	if (status == B_OK && fLabel)
130092e3093SJohn Scipione		status = data->AddString("_label", fLabel);
131ac6f7aa8SMarc Flerackers
13255932743SAxel Dörfler	if (status == B_OK && fValue != B_CONTROL_OFF)
133092e3093SJohn Scipione		status = data->AddInt32("_val", fValue);
134ac6f7aa8SMarc Flerackers
13555932743SAxel Dörfler	if (status == B_OK && !fEnabled)
136092e3093SJohn Scipione		status = data->AddBool("_disable", true);
137ac6f7aa8SMarc Flerackers
13855932743SAxel Dörfler	return status;
139ac6f7aa8SMarc Flerackers}
14055932743SAxel Dörfler
14155932743SAxel Dörfler
14255932743SAxel Dörflervoid
14355932743SAxel DörflerBControl::WindowActivated(bool active)
144ac6f7aa8SMarc Flerackers{
14547bc8348SMarc Flerackers	BView::WindowActivated(active);
14647bc8348SMarc Flerackers
147ac6f7aa8SMarc Flerackers	if (IsFocus())
1483c2fddeeSStephan Aßmus		Invalidate();
149ac6f7aa8SMarc Flerackers}
15055932743SAxel Dörfler
15155932743SAxel Dörfler
15255932743SAxel Dörflervoid
15355932743SAxel DörflerBControl::AttachedToWindow()
154ac6f7aa8SMarc Flerackers{
1557a96554cSlooncraz	AdoptParentColors();
1563a816565SAxel Dörfler
157c9bd4d84Slooncraz	if (ViewColor() == B_TRANSPARENT_COLOR
158c9bd4d84Slooncraz		|| Parent() == NULL) {
159c9bd4d84Slooncraz		AdoptSystemColors();
160c9bd4d84Slooncraz	}
161ac6f7aa8SMarc Flerackers
1627a96554cSlooncraz	// Force view color as low color
1637a96554cSlooncraz	if (Parent() != NULL) {
1647a96554cSlooncraz		float tint = B_NO_TINT;
1657a96554cSlooncraz		color_which which = ViewUIColor(&tint);
1667a96554cSlooncraz		if (which != B_NO_COLOR)
1677a96554cSlooncraz			SetLowUIColor(which, tint);
1687a96554cSlooncraz		else
1697a96554cSlooncraz			SetLowColor(ViewColor());
1707a96554cSlooncraz	}
17147bc8348SMarc Flerackers
17247bc8348SMarc Flerackers	if (!Messenger().IsValid())
17355932743SAxel Dörfler		SetTarget(Window());
174ac6f7aa8SMarc Flerackers
175ac6f7aa8SMarc Flerackers	BView::AttachedToWindow();
176ac6f7aa8SMarc Flerackers}
17755932743SAxel Dörfler
17855932743SAxel Dörfler
179041b97a8SStephan Aßmusvoid
180041b97a8SStephan AßmusBControl::DetachedFromWindow()
181041b97a8SStephan Aßmus{
182041b97a8SStephan Aßmus	BView::DetachedFromWindow();
183041b97a8SStephan Aßmus}
184041b97a8SStephan Aßmus
185041b97a8SStephan Aßmus
186041b97a8SStephan Aßmusvoid
187041b97a8SStephan AßmusBControl::AllAttached()
188041b97a8SStephan Aßmus{
189041b97a8SStephan Aßmus	BView::AllAttached();
190041b97a8SStephan Aßmus}
191041b97a8SStephan Aßmus
192041b97a8SStephan Aßmus
193041b97a8SStephan Aßmusvoid
194041b97a8SStephan AßmusBControl::AllDetached()
195041b97a8SStephan Aßmus{
196041b97a8SStephan Aßmus	BView::AllDetached();
197041b97a8SStephan Aßmus}
198041b97a8SStephan Aßmus
199041b97a8SStephan Aßmus
20055932743SAxel Dörflervoid
201092e3093SJohn ScipioneBControl::MessageReceived(BMessage* message)
202ac6f7aa8SMarc Flerackers{
20355932743SAxel Dörfler	if (message->what == B_GET_PROPERTY || message->what == B_SET_PROPERTY) {
20455932743SAxel Dörfler		BMessage reply(B_REPLY);
20555932743SAxel Dörfler		bool handled = false;
20647bc8348SMarc Flerackers
20747bc8348SMarc Flerackers		BMessage specifier;
20847bc8348SMarc Flerackers		int32 index;
20947bc8348SMarc Flerackers		int32 form;
210092e3093SJohn Scipione		const char* property;
21155932743SAxel Dörfler		if (message->GetCurrentSpecifier(&index, &specifier, &form, &property) == B_OK) {
21255932743SAxel Dörfler			if (strcmp(property, "Label") == 0) {
21355932743SAxel Dörfler				if (message->what == B_GET_PROPERTY) {
214ac6f7aa8SMarc Flerackers					reply.AddString("result", fLabel);
21547bc8348SMarc Flerackers					handled = true;
21655932743SAxel Dörfler				} else {
2172a30a9e9SRene Gollent					// B_SET_PROPERTY
218092e3093SJohn Scipione					const char* label;
21955932743SAxel Dörfler					if (message->FindString("data", &label) == B_OK) {
22047bc8348SMarc Flerackers						SetLabel(label);
22147bc8348SMarc Flerackers						reply.AddInt32("error", B_OK);
22247bc8348SMarc Flerackers						handled = true;
22347bc8348SMarc Flerackers					}
224ac6f7aa8SMarc Flerackers				}
22555932743SAxel Dörfler			} else if (strcmp(property, "Value") == 0) {
22655932743SAxel Dörfler				if (message->what == B_GET_PROPERTY) {
227ac6f7aa8SMarc Flerackers					reply.AddInt32("result", fValue);
22847bc8348SMarc Flerackers					handled = true;
22955932743SAxel Dörfler				} else {
2302a30a9e9SRene Gollent					// B_SET_PROPERTY
231ac6f7aa8SMarc Flerackers					int32 value;
23255932743SAxel Dörfler					if (message->FindInt32("data", &value) == B_OK) {
23347bc8348SMarc Flerackers						SetValue(value);
23447bc8348SMarc Flerackers						reply.AddInt32("error", B_OK);
23547bc8348SMarc Flerackers						handled = true;
23647bc8348SMarc Flerackers					}
23747bc8348SMarc Flerackers				}
23855932743SAxel Dörfler			} else if (strcmp(property, "Enabled") == 0) {
23955932743SAxel Dörfler				if (message->what == B_GET_PROPERTY) {
24047bc8348SMarc Flerackers					reply.AddBool("result", fEnabled);
24147bc8348SMarc Flerackers					handled = true;
24255932743SAxel Dörfler				} else {
2432a30a9e9SRene Gollent					// B_SET_PROPERTY
24447bc8348SMarc Flerackers					bool enabled;
24555932743SAxel Dörfler					if (message->FindBool("data", &enabled) == B_OK) {
24647bc8348SMarc Flerackers						SetEnabled(enabled);
24747bc8348SMarc Flerackers						reply.AddInt32("error", B_OK);
24847bc8348SMarc Flerackers						handled = true;
24947bc8348SMarc Flerackers					}
250ac6f7aa8SMarc Flerackers				}
251ac6f7aa8SMarc Flerackers			}
252ac6f7aa8SMarc Flerackers		}
253041b97a8SStephan Aßmus
25455932743SAxel Dörfler		if (handled) {
25555932743SAxel Dörfler			message->SendReply(&reply);
25655932743SAxel Dörfler			return;
25755932743SAxel Dörfler		}
258ac6f7aa8SMarc Flerackers	}
25947bc8348SMarc Flerackers
26055932743SAxel Dörfler	BView::MessageReceived(message);
261ac6f7aa8SMarc Flerackers}
26255932743SAxel Dörfler
26355932743SAxel Dörfler
26455932743SAxel Dörflervoid
2651f424632SJohn ScipioneBControl::MakeFocus(bool focus)
266ac6f7aa8SMarc Flerackers{
2671f424632SJohn Scipione	if (focus == IsFocus())
26847bc8348SMarc Flerackers		return;
26947bc8348SMarc Flerackers
2701f424632SJohn Scipione	BView::MakeFocus(focus);
271ac6f7aa8SMarc Flerackers
2721f424632SJohn Scipione	if (Window() != NULL) {
273ac6f7aa8SMarc Flerackers		fFocusChanging = true;
2743ceb31b9SDarkWyrm		Invalidate(Bounds());
275ac6f7aa8SMarc Flerackers		Flush();
276ac6f7aa8SMarc Flerackers		fFocusChanging = false;
277ac6f7aa8SMarc Flerackers	}
278ac6f7aa8SMarc Flerackers}
27955932743SAxel Dörfler
28055932743SAxel Dörfler
28155932743SAxel Dörflervoid
282092e3093SJohn ScipioneBControl::KeyDown(const char* bytes, int32 numBytes)
283ac6f7aa8SMarc Flerackers{
28455932743SAxel Dörfler	if (*bytes == B_ENTER || *bytes == B_SPACE) {
28547bc8348SMarc Flerackers		if (!fEnabled)
28647bc8348SMarc Flerackers			return;
28747bc8348SMarc Flerackers
28855932743SAxel Dörfler		SetValue(Value() ? B_CONTROL_OFF : B_CONTROL_ON);
28947bc8348SMarc Flerackers		Invoke();
29055932743SAxel Dörfler	} else
291ac6f7aa8SMarc Flerackers		BView::KeyDown(bytes, numBytes);
292ac6f7aa8SMarc Flerackers}
29355932743SAxel Dörfler
29455932743SAxel Dörfler
29555932743SAxel Dörflervoid
296092e3093SJohn ScipioneBControl::MouseDown(BPoint where)
297ac6f7aa8SMarc Flerackers{
298092e3093SJohn Scipione	BView::MouseDown(where);
299ac6f7aa8SMarc Flerackers}
30055932743SAxel Dörfler
30155932743SAxel Dörfler
30255932743SAxel Dörflervoid
303092e3093SJohn ScipioneBControl::MouseUp(BPoint where)
304ac6f7aa8SMarc Flerackers{
305092e3093SJohn Scipione	BView::MouseUp(where);
306ac6f7aa8SMarc Flerackers}
30755932743SAxel Dörfler
30855932743SAxel Dörfler
30955932743SAxel Dörflervoid
310092e3093SJohn ScipioneBControl::MouseMoved(BPoint where, uint32 code, const BMessage* dragMessage)
311ac6f7aa8SMarc Flerackers{
312092e3093SJohn Scipione	BView::MouseMoved(where, code, dragMessage);
313ac6f7aa8SMarc Flerackers}
31455932743SAxel Dörfler
31555932743SAxel Dörfler
31655932743SAxel Dörflervoid
317092e3093SJohn ScipioneBControl::SetLabel(const char* label)
318ac6f7aa8SMarc Flerackers{
3197d34abc3SAxel Dörfler	if (label != NULL && !label[0])
3207d34abc3SAxel Dörfler		label = NULL;
3217d34abc3SAxel Dörfler
3227d34abc3SAxel Dörfler	// Has the label been changed?
3237d34abc3SAxel Dörfler	if ((fLabel && label && !strcmp(fLabel, label))
3247d34abc3SAxel Dörfler		|| ((fLabel == NULL || !fLabel[0]) && label == NULL))
325ac6f7aa8SMarc Flerackers		return;
326ac6f7aa8SMarc Flerackers
32755932743SAxel Dörfler	free(fLabel);
3287d34abc3SAxel Dörfler	fLabel = label ? strdup(label) : NULL;
329ac6f7aa8SMarc Flerackers
3309ecf9d1cSIngo Weinhold	InvalidateLayout();
331ac6f7aa8SMarc Flerackers	Invalidate();
332ac6f7aa8SMarc Flerackers}
33355932743SAxel Dörfler
33455932743SAxel Dörfler
335092e3093SJohn Scipioneconst char*
33655932743SAxel DörflerBControl::Label() const
337ac6f7aa8SMarc Flerackers{
338ac6f7aa8SMarc Flerackers	return fLabel;
339ac6f7aa8SMarc Flerackers}
34055932743SAxel Dörfler
34155932743SAxel Dörfler
34255932743SAxel Dörflervoid
34355932743SAxel DörflerBControl::SetValue(int32 value)
344a71c9607SAxel Dörfler{
3452313ae79SMarcus Overhagen	if (value == fValue)
3462313ae79SMarcus Overhagen		return;
3472313ae79SMarcus Overhagen
348a71c9607SAxel Dörfler	fValue = value;
349a71c9607SAxel Dörfler	Invalidate();
350a71c9607SAxel Dörfler}
351a71c9607SAxel Dörfler
352a71c9607SAxel Dörfler
353a71c9607SAxel Dörflervoid
354a71c9607SAxel DörflerBControl::SetValueNoUpdate(int32 value)
355ac6f7aa8SMarc Flerackers{
356ac6f7aa8SMarc Flerackers	fValue = value;
357ac6f7aa8SMarc Flerackers}
35855932743SAxel Dörfler
35955932743SAxel Dörfler
36055932743SAxel Dörflerint32
36155932743SAxel DörflerBControl::Value() const
362ac6f7aa8SMarc Flerackers{
363ac6f7aa8SMarc Flerackers	return fValue;
364ac6f7aa8SMarc Flerackers}
36555932743SAxel Dörfler
36655932743SAxel Dörfler
36755932743SAxel Dörflervoid
36855932743SAxel DörflerBControl::SetEnabled(bool enabled)
369ac6f7aa8SMarc Flerackers{
370ac6f7aa8SMarc Flerackers	if (fEnabled == enabled)
371ac6f7aa8SMarc Flerackers		return;
372ac6f7aa8SMarc Flerackers
373ac6f7aa8SMarc Flerackers	fEnabled = enabled;
374ac6f7aa8SMarc Flerackers
37573161598SJérôme Duval	if (fEnabled && fWantsNav)
37673161598SJérôme Duval		SetFlags(Flags() | B_NAVIGABLE);
37773161598SJérôme Duval	else if (!fEnabled && (Flags() & B_NAVIGABLE)) {
37873161598SJérôme Duval		fWantsNav = true;
37973161598SJérôme Duval		SetFlags(Flags() & ~B_NAVIGABLE);
38073161598SJérôme Duval	} else
38173161598SJérôme Duval		fWantsNav = false;
382ac6f7aa8SMarc Flerackers
38355932743SAxel Dörfler	if (Window()) {
3843ceb31b9SDarkWyrm		Invalidate(Bounds());
385ac6f7aa8SMarc Flerackers		Flush();
386ac6f7aa8SMarc Flerackers	}
387ac6f7aa8SMarc Flerackers}
38855932743SAxel Dörfler
38955932743SAxel Dörfler
39055932743SAxel Dörflerbool
39155932743SAxel DörflerBControl::IsEnabled() const
392ac6f7aa8SMarc Flerackers{
393ac6f7aa8SMarc Flerackers	return fEnabled;
394ac6f7aa8SMarc Flerackers}
39555932743SAxel Dörfler
39655932743SAxel Dörfler
39755932743SAxel Dörflervoid
398092e3093SJohn ScipioneBControl::GetPreferredSize(float* _width, float* _height)
399ac6f7aa8SMarc Flerackers{
40055932743SAxel Dörfler	BView::GetPreferredSize(_width, _height);
401ac6f7aa8SMarc Flerackers}
40255932743SAxel Dörfler
40355932743SAxel Dörfler
40455932743SAxel Dörflervoid
40555932743SAxel DörflerBControl::ResizeToPreferred()
406ac6f7aa8SMarc Flerackers{
407ac6f7aa8SMarc Flerackers	BView::ResizeToPreferred();
408ac6f7aa8SMarc Flerackers}
40955932743SAxel Dörfler
41055932743SAxel Dörfler
41155932743SAxel Dörflerstatus_t
412092e3093SJohn ScipioneBControl::Invoke(BMessage* message)
413ac6f7aa8SMarc Flerackers{
41447bc8348SMarc Flerackers	bool notify = false;
41547bc8348SMarc Flerackers	uint32 kind = InvokeKind(&notify);
41647bc8348SMarc Flerackers
41747bc8348SMarc Flerackers	if (!message && !notify)
41847bc8348SMarc Flerackers		message = Message();
41955932743SAxel Dörfler
42055932743SAxel Dörfler	BMessage clone(kind);
42155932743SAxel Dörfler
42255932743SAxel Dörfler	if (!message) {
42347bc8348SMarc Flerackers		if (!IsWatched())
42455932743SAxel Dörfler			return B_BAD_VALUE;
42555932743SAxel Dörfler	} else
42647bc8348SMarc Flerackers		clone = *message;
42747bc8348SMarc Flerackers
42847bc8348SMarc Flerackers	clone.AddInt64("when", (int64)system_time());
42947bc8348SMarc Flerackers	clone.AddPointer("source", this);
43047bc8348SMarc Flerackers	clone.AddInt32("be:value", fValue);
43147bc8348SMarc Flerackers	clone.AddMessenger("be:sender", BMessenger(this));
43247bc8348SMarc Flerackers
43355932743SAxel Dörfler	// ToDo: is this correct? If message == NULL (even if IsWatched()), we always return B_BAD_VALUE
43455932743SAxel Dörfler	status_t err;
43547bc8348SMarc Flerackers	if (message)
43647bc8348SMarc Flerackers		err = BInvoker::Invoke(&clone);
43755932743SAxel Dörfler	else
43855932743SAxel Dörfler		err = B_BAD_VALUE;
43947bc8348SMarc Flerackers
4403ceb31b9SDarkWyrm	// TODO: asynchronous messaging
4413ceb31b9SDarkWyrm	SendNotices(kind, &clone);
442ac6f7aa8SMarc Flerackers
44347bc8348SMarc Flerackers	return err;
444ac6f7aa8SMarc Flerackers}
44555932743SAxel Dörfler
44655932743SAxel Dörfler
447092e3093SJohn ScipioneBHandler*
448092e3093SJohn ScipioneBControl::ResolveSpecifier(BMessage* message, int32 index,
449092e3093SJohn Scipione	BMessage* specifier, int32 what, const char* property)
450ac6f7aa8SMarc Flerackers{
45155932743SAxel Dörfler	BPropertyInfo propInfo(sPropertyList);
452ac6f7aa8SMarc Flerackers
45355932743SAxel Dörfler	if (propInfo.FindMatch(message, 0, specifier, what, property) >= B_OK)
45447bc8348SMarc Flerackers		return this;
45555932743SAxel Dörfler
45655932743SAxel Dörfler	return BView::ResolveSpecifier(message, index, specifier, what,
45755932743SAxel Dörfler		property);
458ac6f7aa8SMarc Flerackers}
45955932743SAxel Dörfler
46055932743SAxel Dörfler
46155932743SAxel Dörflerstatus_t
462092e3093SJohn ScipioneBControl::GetSupportedSuites(BMessage* message)
463ac6f7aa8SMarc Flerackers{
46447bc8348SMarc Flerackers	message->AddString("suites", "suite/vnd.Be-control");
46555932743SAxel Dörfler
46655932743SAxel Dörfler	BPropertyInfo propInfo(sPropertyList);
46755932743SAxel Dörfler	message->AddFlat("messages", &propInfo);
46855932743SAxel Dörfler
469ac6f7aa8SMarc Flerackers	return BView::GetSupportedSuites(message);
470ac6f7aa8SMarc Flerackers}
47155932743SAxel Dörfler
47255932743SAxel Dörfler
47355932743SAxel Dörflerstatus_t
47439fbf550SOliver TappeBControl::Perform(perform_code code, void* _data)
47539fbf550SOliver Tappe{
47639fbf550SOliver Tappe	switch (code) {
47739fbf550SOliver Tappe		case PERFORM_CODE_MIN_SIZE:
47839fbf550SOliver Tappe			((perform_data_min_size*)_data)->return_value
47939fbf550SOliver Tappe				= BControl::MinSize();
48039fbf550SOliver Tappe			return B_OK;
48139fbf550SOliver Tappe		case PERFORM_CODE_MAX_SIZE:
48239fbf550SOliver Tappe			((perform_data_max_size*)_data)->return_value
48339fbf550SOliver Tappe				= BControl::MaxSize();
48439fbf550SOliver Tappe			return B_OK;
48539fbf550SOliver Tappe		case PERFORM_CODE_PREFERRED_SIZE:
48639fbf550SOliver Tappe			((perform_data_preferred_size*)_data)->return_value
48739fbf550SOliver Tappe				= BControl::PreferredSize();
48839fbf550SOliver Tappe			return B_OK;
48939fbf550SOliver Tappe		case PERFORM_CODE_LAYOUT_ALIGNMENT:
49039fbf550SOliver Tappe			((perform_data_layout_alignment*)_data)->return_value
49139fbf550SOliver Tappe				= BControl::LayoutAlignment();
49239fbf550SOliver Tappe			return B_OK;
49339fbf550SOliver Tappe		case PERFORM_CODE_HAS_HEIGHT_FOR_WIDTH:
49439fbf550SOliver Tappe			((perform_data_has_height_for_width*)_data)->return_value
49539fbf550SOliver Tappe				= BControl::HasHeightForWidth();
49639fbf550SOliver Tappe			return B_OK;
49739fbf550SOliver Tappe		case PERFORM_CODE_GET_HEIGHT_FOR_WIDTH:
49839fbf550SOliver Tappe		{
49939fbf550SOliver Tappe			perform_data_get_height_for_width* data
50039fbf550SOliver Tappe				= (perform_data_get_height_for_width*)_data;
50139fbf550SOliver Tappe			BControl::GetHeightForWidth(data->width, &data->min, &data->max,
50239fbf550SOliver Tappe				&data->preferred);
50339fbf550SOliver Tappe			return B_OK;
50439fbf550SOliver Tappe}
50539fbf550SOliver Tappe		case PERFORM_CODE_SET_LAYOUT:
50639fbf550SOliver Tappe		{
50739fbf550SOliver Tappe			perform_data_set_layout* data = (perform_data_set_layout*)_data;
50839fbf550SOliver Tappe			BControl::SetLayout(data->layout);
50939fbf550SOliver Tappe			return B_OK;
51039fbf550SOliver Tappe		}
511eee4243dSAlex Wilson		case PERFORM_CODE_LAYOUT_INVALIDATED:
51239fbf550SOliver Tappe		{
513eee4243dSAlex Wilson			perform_data_layout_invalidated* data
514eee4243dSAlex Wilson				= (perform_data_layout_invalidated*)_data;
515eee4243dSAlex Wilson			BControl::LayoutInvalidated(data->descendants);
51639fbf550SOliver Tappe			return B_OK;
51739fbf550SOliver Tappe		}
51839fbf550SOliver Tappe		case PERFORM_CODE_DO_LAYOUT:
51939fbf550SOliver Tappe		{
52039fbf550SOliver Tappe			BControl::DoLayout();
52139fbf550SOliver Tappe			return B_OK;
52239fbf550SOliver Tappe		}
523be260374SIngo Weinhold		case PERFORM_CODE_SET_ICON:
524be260374SIngo Weinhold		{
525be260374SIngo Weinhold			perform_data_set_icon* data = (perform_data_set_icon*)_data;
526be260374SIngo Weinhold			return BControl::SetIcon(data->icon, data->flags);
527be260374SIngo Weinhold		}
52839fbf550SOliver Tappe	}
52939fbf550SOliver Tappe
53039fbf550SOliver Tappe	return BView::Perform(code, _data);
531ac6f7aa8SMarc Flerackers}
53255932743SAxel Dörfler
53355932743SAxel Dörfler
534be260374SIngo Weinholdstatus_t
535be260374SIngo WeinholdBControl::SetIcon(const BBitmap* bitmap, uint32 flags)
536be260374SIngo Weinhold{
53797bf0ce3SIngo Weinhold	status_t error = BIcon::UpdateIcon(bitmap, flags, fIcon);
538be260374SIngo Weinhold
53997bf0ce3SIngo Weinhold	if (error == B_OK) {
54097bf0ce3SIngo Weinhold		InvalidateLayout();
54197bf0ce3SIngo Weinhold		Invalidate();
542be260374SIngo Weinhold	}
543be260374SIngo Weinhold
544be260374SIngo Weinhold	return error;
545be260374SIngo Weinhold}
546be260374SIngo Weinhold
547be260374SIngo Weinhold
548be260374SIngo Weinholdstatus_t
549be260374SIngo WeinholdBControl::SetIconBitmap(const BBitmap* bitmap, uint32 which, uint32 flags)
550be260374SIngo Weinhold{
55197bf0ce3SIngo Weinhold	status_t error = BIcon::SetIconBitmap(bitmap, which, flags, fIcon);
552be260374SIngo Weinhold
55397bf0ce3SIngo Weinhold	if (error != B_OK) {
55497bf0ce3SIngo Weinhold		InvalidateLayout();
55597bf0ce3SIngo Weinhold		Invalidate();
556be260374SIngo Weinhold	}
557be260374SIngo Weinhold
55897bf0ce3SIngo Weinhold	return error;
559be260374SIngo Weinhold}
560be260374SIngo Weinhold
561be260374SIngo Weinhold
562be260374SIngo Weinholdconst BBitmap*
563be260374SIngo WeinholdBControl::IconBitmap(uint32 which) const
564be260374SIngo Weinhold{
56597bf0ce3SIngo Weinhold	return fIcon != NULL ? fIcon->Bitmap(which) : NULL;
566be260374SIngo Weinhold}
567be260374SIngo Weinhold
568be260374SIngo Weinhold
56955932743SAxel Dörflerbool
57055932743SAxel DörflerBControl::IsFocusChanging() const
571ac6f7aa8SMarc Flerackers{
572ac6f7aa8SMarc Flerackers	return fFocusChanging;
573ac6f7aa8SMarc Flerackers}
57455932743SAxel Dörfler
57555932743SAxel Dörfler
57655932743SAxel Dörflerbool
57755932743SAxel DörflerBControl::IsTracking() const
578ac6f7aa8SMarc Flerackers{
579ac6f7aa8SMarc Flerackers	return fTracking;
580ac6f7aa8SMarc Flerackers}
58155932743SAxel Dörfler
58255932743SAxel Dörfler
58355932743SAxel Dörflervoid
58455932743SAxel DörflerBControl::SetTracking(bool state)
585ac6f7aa8SMarc Flerackers{
586ac6f7aa8SMarc Flerackers	fTracking = state;
587ac6f7aa8SMarc Flerackers}
58855932743SAxel Dörfler
58955932743SAxel Dörfler
590be260374SIngo Weinholdextern "C" status_t
591be260374SIngo WeinholdB_IF_GCC_2(_ReservedControl1__8BControl, _ZN8BControl17_ReservedControl1Ev)(
592be260374SIngo Weinhold	BControl* control, const BBitmap* icon, uint32 flags)
593be260374SIngo Weinhold{
594be260374SIngo Weinhold	// SetIcon()
595be260374SIngo Weinhold	perform_data_set_icon data;
596be260374SIngo Weinhold	data.icon = icon;
597be260374SIngo Weinhold	data.flags = flags;
598be260374SIngo Weinhold	return control->Perform(PERFORM_CODE_SET_ICON, &data);
599be260374SIngo Weinhold}
600be260374SIngo Weinhold
601be260374SIngo Weinhold
602ac6f7aa8SMarc Flerackersvoid BControl::_ReservedControl2() {}
603ac6f7aa8SMarc Flerackersvoid BControl::_ReservedControl3() {}
604ac6f7aa8SMarc Flerackersvoid BControl::_ReservedControl4() {}
60555932743SAxel Dörfler
60655932743SAxel Dörfler
60755932743SAxel DörflerBControl &
60855932743SAxel DörflerBControl::operator=(const BControl &)
609ac6f7aa8SMarc Flerackers{
610ac6f7aa8SMarc Flerackers	return *this;
611ac6f7aa8SMarc Flerackers}
61255932743SAxel Dörfler
61355932743SAxel Dörfler
61455932743SAxel Dörflervoid
615092e3093SJohn ScipioneBControl::InitData(BMessage* data)
616ac6f7aa8SMarc Flerackers{
6177a96554cSlooncraz	SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
6187a96554cSlooncraz	SetLowUIColor(ViewUIColor());
6197a96554cSlooncraz
62047bc8348SMarc Flerackers	fLabel = NULL;
6213ceb31b9SDarkWyrm	SetLabel(B_EMPTY_STRING);
62247bc8348SMarc Flerackers	fValue = B_CONTROL_OFF;
62347bc8348SMarc Flerackers	fEnabled = true;
62447bc8348SMarc Flerackers	fFocusChanging = false;
62547bc8348SMarc Flerackers	fTracking = false;
62673161598SJérôme Duval	fWantsNav = Flags() & B_NAVIGABLE;
62797bf0ce3SIngo Weinhold	fIcon = NULL;
628ac6f7aa8SMarc Flerackers
62947bc8348SMarc Flerackers	if (data && data->HasString("_fname"))
63047bc8348SMarc Flerackers		SetFont(be_plain_font, B_FONT_FAMILY_AND_STYLE);
631ac6f7aa8SMarc Flerackers}
63255932743SAxel Dörfler
633