aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llnameeditor.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--linden/indra/newview/llnameeditor.cpp203
1 files changed, 203 insertions, 0 deletions
diff --git a/linden/indra/newview/llnameeditor.cpp b/linden/indra/newview/llnameeditor.cpp
new file mode 100644
index 0000000..fb238e9
--- /dev/null
+++ b/linden/indra/newview/llnameeditor.cpp
@@ -0,0 +1,203 @@
1/**
2 * @file llnameeditor.cpp
3 * @brief Name Editor to refresh a name.
4 *
5 * Copyright (c) 2003-2007, Linden Research, Inc.
6 *
7 * The source code in this file ("Source Code") is provided by Linden Lab
8 * to you under the terms of the GNU General Public License, version 2.0
9 * ("GPL"), unless you have obtained a separate licensing agreement
10 * ("Other License"), formally executed by you and Linden Lab. Terms of
11 * the GPL can be found in doc/GPL-license.txt in this distribution, or
12 * online at http://secondlife.com/developers/opensource/gplv2
13 *
14 * There are special exceptions to the terms and conditions of the GPL as
15 * it is applied to this Source Code. View the full text of the exception
16 * in the file doc/FLOSS-exception.txt in this software distribution, or
17 * online at http://secondlife.com/developers/opensource/flossexception
18 *
19 * By copying, modifying or distributing this software, you acknowledge
20 * that you have read and understood your obligations described above,
21 * and agree to abide by those obligations.
22 *
23 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
24 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
25 * COMPLETENESS OR PERFORMANCE.
26 */
27
28#include "llviewerprecompiledheaders.h"
29
30#include "llnameeditor.h"
31#include "llcachename.h"
32#include "llagent.h"
33
34#include "llfontgl.h"
35
36#include "lluuid.h"
37#include "llrect.h"
38#include "llstring.h"
39#include "llui.h"
40
41
42// statics
43std::set<LLNameEditor*> LLNameEditor::sInstances;
44
45LLNameEditor::LLNameEditor(const std::string& name, const LLRect& rect,
46 const LLUUID& name_id,
47 BOOL is_group,
48 const LLFontGL* glfont,
49 S32 max_text_length,
50 void (*commit_callback)(LLUICtrl* caller, void* user_data),
51 void (*keystroke_callback)(LLLineEditor* caller, void* user_data),
52 void (*focus_lost_callback)(LLLineEditor* caller, void* user_data),
53 void* userdata,
54 LLLinePrevalidateFunc prevalidate_func,
55 LLViewBorder::EBevel border_bevel,
56 LLViewBorder::EStyle border_style,
57 S32 border_thickness)
58: LLLineEditor(name, rect,
59 "(retrieving)",
60 glfont,
61 max_text_length,
62 commit_callback,
63 keystroke_callback,
64 focus_lost_callback,
65 userdata,
66 prevalidate_func,
67 border_bevel,
68 border_style,
69 border_thickness),
70 mNameID(name_id)
71{
72 LLNameEditor::sInstances.insert(this);
73 if(!name_id.isNull())
74 {
75 setNameID(name_id, is_group);
76 }
77}
78
79
80LLNameEditor::~LLNameEditor()
81{
82 LLNameEditor::sInstances.erase(this);
83}
84
85void LLNameEditor::setNameID(const LLUUID& name_id, BOOL is_group)
86{
87 mNameID = name_id;
88
89 char first[DB_FIRST_NAME_BUF_SIZE];
90 char last[DB_LAST_NAME_BUF_SIZE];
91 char group_name[DB_GROUP_NAME_BUF_SIZE];
92 LLString name;
93
94 if (!is_group)
95 {
96 gCacheName->getName(name_id, first, last);
97
98 name.assign(first);
99 name.append(1, ' ');
100 name.append(last);
101 }
102 else
103 {
104 gCacheName->getGroupName(name_id, group_name);
105 name.assign(group_name);
106 }
107
108 setText(name);
109}
110
111void LLNameEditor::refresh(const LLUUID& id, const char* firstname,
112 const char* lastname, BOOL is_group)
113{
114 if (id == mNameID)
115 {
116 LLString name;
117
118 name.assign(firstname);
119 if (!is_group)
120 {
121 name.append(1, ' ');
122 name.append(lastname);
123 }
124
125 setText(name);
126 }
127}
128
129void LLNameEditor::refreshAll(const LLUUID& id, const char* firstname,
130 const char* lastname, BOOL is_group)
131{
132 std::set<LLNameEditor*>::iterator it;
133 for (it = LLNameEditor::sInstances.begin();
134 it != LLNameEditor::sInstances.end();
135 ++it)
136 {
137 LLNameEditor* box = *it;
138 box->refresh(id, firstname, lastname, is_group);
139 }
140}
141
142void LLNameEditor::setValue( LLSD value )
143{
144 setNameID(value.asUUID(), FALSE);
145}
146
147LLSD LLNameEditor::getValue() const
148{
149 return LLSD(mNameID);
150}
151
152LLView* LLNameEditor::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory)
153{
154 LLString name("name_editor");
155 node->getAttributeString("name", name);
156
157 LLRect rect;
158 createRect(node, rect, parent, LLRect());
159
160 S32 max_text_length = 128;
161 node->getAttributeS32("max_length", max_text_length);
162
163 LLFontGL* font = LLView::selectFont(node);
164
165 LLViewBorder::EStyle border_style = LLViewBorder::STYLE_LINE;
166 LLString border_string;
167 node->getAttributeString("border_style", border_string);
168 LLString::toLower(border_string);
169
170 if (border_string == "texture")
171 {
172 border_style = LLViewBorder::STYLE_TEXTURE;
173 }
174
175 S32 border_thickness = 1;
176 node->getAttributeS32("border_thickness", border_thickness);
177
178 LLUICtrlCallback commit_callback = NULL;
179
180 LLNameEditor* line_editor = new LLNameEditor(name,
181 rect,
182 LLUUID::null, FALSE,
183 font,
184 max_text_length,
185 commit_callback,
186 NULL,
187 NULL,
188 NULL,
189 NULL,
190 LLViewBorder::BEVEL_IN,
191 border_style,
192 border_thickness);
193
194 LLString label;
195 if(node->getAttributeString("label", label))
196 {
197 line_editor->setLabel(label);
198 }
199 line_editor->setColorParameters(node);
200 line_editor->initFromXML(node, parent);
201
202 return line_editor;
203}