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 "StringTextView.h" 10 11#include <stdio.h> 12#include <stdlib.h> 13 14// constructor 15StringTextView::StringTextView(BRect frame, const char* name, 16 BRect textRect, 17 uint32 resizingMode, 18 uint32 flags) 19 : InputTextView(frame, name, textRect, resizingMode, flags), 20 fStringCache("") 21{ 22} 23 24// destructor 25StringTextView::~StringTextView() 26{ 27} 28 29// Invoke 30status_t 31StringTextView::Invoke(BMessage* message) 32{ 33 if (!message) 34 message = Message(); 35 36 if (message) { 37 BMessage copy(*message); 38 copy.AddString("value", Value()); 39 return InputTextView::Invoke(©); 40 } 41 return B_BAD_VALUE; 42} 43 44// RevertChanges 45void 46StringTextView::RevertChanges() 47{ 48 SetValue(fStringCache.String()); 49} 50 51// ApplyChanges 52void 53StringTextView::ApplyChanges() 54{ 55 if (fStringCache != Text()) { 56 Invoke(); 57 } 58} 59 60// SetValue 61void 62StringTextView::SetValue(const char* string) 63{ 64 SetText(string); 65 66 // update cache 67 Value(); 68 69 if (IsFocus()) 70 SelectAll(); 71} 72 73// Value 74const char* 75StringTextView::Value() const 76{ 77 fStringCache = Text(); 78 return fStringCache.String(); 79} 80 81