xref: /haiku/src/apps/icon-o-matic/generic/property/view/specific_properties/IntValueView.cpp (revision 1e36cfc2721ef13a187c6f7354dc9cbc485e89d3)
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 "IntValueView.h"
10 
11 #include <stdio.h>
12 
13 #include "NummericalTextView.h"
14 
15 // constructor
16 IntValueView::IntValueView(IntProperty* property)
17 	: TextInputValueView(),
18 	  fProperty(property)
19 {
20 	BRect b = Bounds();
21 	fTextView = new NummericalTextView(b, "nummerical input", b,
22 									   B_FOLLOW_LEFT | B_FOLLOW_TOP,
23 									   B_WILL_DRAW);
24 
25 	AddChild(fTextView);
26 	fTextView->SetFloatMode(false);
27 
28 	if (fProperty)
29 		fTextView->SetValue(fProperty->Value());
30 }
31 
32 // destructor
33 IntValueView::~IntValueView()
34 {
35 }
36 
37 // TextView
38 InputTextView*
39 IntValueView::TextView() const
40 {
41 	return fTextView;
42 }
43 
44 // ValueChanged
45 void
46 IntValueView::ValueChanged()
47 {
48 	if (fProperty) {
49 		fProperty->SetValue(fTextView->IntValue());
50 		fTextView->SetValue(fProperty->Value());
51 		TextInputValueView::ValueChanged();
52 	}
53 }
54 
55 // AdoptProperty
56 bool
57 IntValueView::AdoptProperty(Property* property)
58 {
59 	IntProperty* p = dynamic_cast<IntProperty*>(property);
60 	if (p) {
61 		if (fTextView->IntValue() != p->Value())
62 			fTextView->SetValue(p->Value());
63 		fProperty = p;
64 		return true;
65 	}
66 	return false;
67 }
68 
69 // GetProperty
70 Property*
71 IntValueView::GetProperty() const
72 {
73 	return fProperty;
74 }
75 
76