xref: /haiku/src/apps/people/AttributeTextControl.cpp (revision 1c09002cbee8e797a0f8bbfc5678dfadd39ee1a7)
1 /*
2  * Copyright 2005-2011, 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_TRANSLATE_CONTEXT
23 #define B_TRANSLATE_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 	SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);
37 }
38 
39 
40 AttributeTextControl::~AttributeTextControl()
41 {
42 }
43 
44 
45 bool
46 AttributeTextControl::HasChanged()
47 {
48 	return fOriginalValue != Text();
49 }
50 
51 
52 void
53 AttributeTextControl::Revert()
54 {
55 	if (HasChanged())
56 		SetText(fOriginalValue);
57 }
58 
59 
60 void
61 AttributeTextControl::Update()
62 {
63 	fOriginalValue = Text();
64 }
65