xref: /haiku/src/apps/people/AttributeTextControl.cpp (revision e711e6e42fd7ec3111ba9dc2324fa8efedd6674b)
1 /*
2  * Copyright 2005-2012, Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT license.
4  *
5  * Authors:
6  *		Robert Polic
7  *
8  * Copyright 1999, Be Incorporated.   All Rights Reserved.
9  * This file may be used under the terms of the Be Sample Code License.
10  */
11 
12 
13 #include "AttributeTextControl.h"
14 
15 #include <string.h>
16 #include <malloc.h>
17 
18 #include <Font.h>
19 #include <Catalog.h>
20 
21 
22 #undef B_TRANSLATION_CONTEXT
23 #define B_TRANSLATION_CONTEXT "People"
24 
25 
26 AttributeTextControl::AttributeTextControl(const char* label,
27 	const char* attribute)
28 	:
29 	BTextControl(NULL, "", NULL),
30 	fAttribute(attribute),
31 	fOriginalValue()
32 {
33 	if (label != NULL && label[0] != 0) {
34 		SetLabel(BString(B_TRANSLATE("%attribute_label:"))
35 			.ReplaceFirst("%attribute_label", label));
36 	}
37 	SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);
38 }
39 
40 
41 AttributeTextControl::~AttributeTextControl()
42 {
43 }
44 
45 
46 bool
47 AttributeTextControl::HasChanged()
48 {
49 	return fOriginalValue != Text();
50 }
51 
52 
53 void
54 AttributeTextControl::Revert()
55 {
56 	if (HasChanged())
57 		SetText(fOriginalValue);
58 }
59 
60 
61 void
62 AttributeTextControl::Update()
63 {
64 	fOriginalValue = Text();
65 }
66