1/*
2 * Copyright 2006, Haiku.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 *		Stephan A��mus <superstippi@gmx.de>
7 */
8
9#include "StringValueView.h"
10
11#include <stdio.h>
12#include <string.h>
13
14#include "StringTextView.h"
15
16// constructor
17StringValueView::StringValueView(StringProperty* property)
18	: TextInputValueView(),
19	  fProperty(property)
20{
21	BRect b = Bounds();
22	fTextView = new StringTextView(b, "string input", b,
23								   B_FOLLOW_LEFT | B_FOLLOW_TOP,
24								   B_WILL_DRAW);
25	AddChild(fTextView);
26
27	if (fProperty)
28		fTextView->SetValue(fProperty->Value());
29}
30
31// destructor
32StringValueView::~StringValueView()
33{
34}
35
36// TextView
37InputTextView*
38StringValueView::TextView() const
39{
40	return fTextView;
41}
42
43// ValueChanged
44void
45StringValueView::ValueChanged()
46{
47	if (fProperty) {
48		fProperty->SetValue(fTextView->Value());
49		fTextView->SetValue(fProperty->Value());
50		TextInputValueView::ValueChanged();
51	}
52}
53
54// AdoptProperty
55bool
56StringValueView::AdoptProperty(Property* property)
57{
58	StringProperty* p = dynamic_cast<StringProperty*>(property);
59	if (p) {
60		if (!fProperty || strcmp(p->Value(), fTextView->Text()) != 0) {
61			fTextView->SetValue(p->Value());
62		}
63		fProperty = p;
64		return true;
65	}
66	return false;
67}
68
69// GetProperty
70Property*
71StringValueView::GetProperty() const
72{
73	return fProperty;
74}
75