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
StringTextView(BRect frame,const char * name,BRect textRect,uint32 resizingMode,uint32 flags)15 StringTextView::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
~StringTextView()25 StringTextView::~StringTextView()
26 {
27 }
28
29 // Invoke
30 status_t
Invoke(BMessage * message)31 StringTextView::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
45 void
RevertChanges()46 StringTextView::RevertChanges()
47 {
48 SetValue(fStringCache.String());
49 }
50
51 // ApplyChanges
52 void
ApplyChanges()53 StringTextView::ApplyChanges()
54 {
55 if (fStringCache != Text()) {
56 Invoke();
57 }
58 }
59
60 // SetValue
61 void
SetValue(const char * string)62 StringTextView::SetValue(const char* string)
63 {
64 SetText(string);
65
66 // update cache
67 Value();
68
69 if (IsFocus())
70 SelectAll();
71 }
72
73 // Value
74 const char*
Value() const75 StringTextView::Value() const
76 {
77 fStringCache = Text();
78 return fStringCache.String();
79 }
80
81