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 "FloatValueView.h" 10 11 #include <stdio.h> 12 13 #include "NummericalTextView.h" 14 15 // constructor 16 FloatValueView::FloatValueView(FloatProperty* 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(true); 27 28 if (fProperty) 29 fTextView->SetValue(fProperty->Value()); 30 } 31 32 // destructor 33 FloatValueView::~FloatValueView() 34 { 35 } 36 37 // TextView 38 InputTextView* 39 FloatValueView::TextView() const 40 { 41 return fTextView; 42 } 43 44 // ValueChanged 45 void 46 FloatValueView::ValueChanged() 47 { 48 if (fProperty) { 49 fProperty->SetValue(fTextView->FloatValue()); 50 fTextView->SetValue(fProperty->Value()); 51 TextInputValueView::ValueChanged(); 52 } 53 } 54 55 // AdoptProperty 56 bool 57 FloatValueView::AdoptProperty(Property* property) 58 { 59 FloatProperty* p = dynamic_cast<FloatProperty*>(property); 60 if (p) { 61 if (fTextView->FloatValue() != p->Value()) 62 fTextView->SetValue(p->Value()); 63 fProperty = p; 64 return true; 65 } 66 return false; 67 } 68 69 // GetProperty 70 Property* 71 FloatValueView::GetProperty() const 72 { 73 return fProperty; 74 } 75 76 77 78