xref: /haiku/src/apps/icon-o-matic/generic/property/view/specific_properties/StringValueView.cpp (revision ed24eb5ff12640d052171c6a7feba37fab8a75d1)
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
17 StringValueView::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
32 StringValueView::~StringValueView()
33 {
34 }
35 
36 // TextView
37 InputTextView*
38 StringValueView::TextView() const
39 {
40 	return fTextView;
41 }
42 
43 // ValueChanged
44 void
45 StringValueView::ValueChanged()
46 {
47 	if (fProperty) {
48 		fProperty->SetValue(fTextView->Value());
49 		fTextView->SetValue(fProperty->Value());
50 		TextInputValueView::ValueChanged();
51 	}
52 }
53 
54 // AdoptProperty
55 bool
56 StringValueView::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
70 Property*
71 StringValueView::GetProperty() const
72 {
73 	return fProperty;
74 }
75