00001
00032 #include "llviewerprecompiledheaders.h"
00033
00034 #include "llnameeditor.h"
00035 #include "llcachename.h"
00036 #include "llagent.h"
00037
00038 #include "llfontgl.h"
00039
00040 #include "lluuid.h"
00041 #include "llrect.h"
00042 #include "llstring.h"
00043 #include "llui.h"
00044
00045
00046
00047 std::set<LLNameEditor*> LLNameEditor::sInstances;
00048
00049 LLNameEditor::LLNameEditor(const std::string& name, const LLRect& rect,
00050 const LLUUID& name_id,
00051 BOOL is_group,
00052 const LLFontGL* glfont,
00053 S32 max_text_length,
00054 void (*commit_callback)(LLUICtrl* caller, void* user_data),
00055 void (*keystroke_callback)(LLLineEditor* caller, void* user_data),
00056 void (*focus_lost_callback)(LLUICtrl* caller, void* user_data),
00057 void* userdata,
00058 LLLinePrevalidateFunc prevalidate_func,
00059 LLViewBorder::EBevel border_bevel,
00060 LLViewBorder::EStyle border_style,
00061 S32 border_thickness)
00062 : LLLineEditor(name, rect,
00063 "(retrieving)",
00064 glfont,
00065 max_text_length,
00066 commit_callback,
00067 keystroke_callback,
00068 focus_lost_callback,
00069 userdata,
00070 prevalidate_func,
00071 border_bevel,
00072 border_style,
00073 border_thickness),
00074 mNameID(name_id)
00075 {
00076 LLNameEditor::sInstances.insert(this);
00077 if(!name_id.isNull())
00078 {
00079 setNameID(name_id, is_group);
00080 }
00081 }
00082
00083
00084 LLNameEditor::~LLNameEditor()
00085 {
00086 LLNameEditor::sInstances.erase(this);
00087 }
00088
00089 void LLNameEditor::setNameID(const LLUUID& name_id, BOOL is_group)
00090 {
00091 mNameID = name_id;
00092
00093 char first[DB_FIRST_NAME_BUF_SIZE];
00094 char last[DB_LAST_NAME_BUF_SIZE];
00095 char group_name[DB_GROUP_NAME_BUF_SIZE];
00096 LLString name;
00097
00098 if (!is_group)
00099 {
00100 gCacheName->getName(name_id, first, last);
00101
00102 name.assign(first);
00103 name.append(1, ' ');
00104 name.append(last);
00105 }
00106 else
00107 {
00108 gCacheName->getGroupName(name_id, group_name);
00109 name.assign(group_name);
00110 }
00111
00112 setText(name);
00113 }
00114
00115 void LLNameEditor::refresh(const LLUUID& id, const char* firstname,
00116 const char* lastname, BOOL is_group)
00117 {
00118 if (id == mNameID)
00119 {
00120 LLString name;
00121
00122 name.assign(firstname);
00123 if (!is_group)
00124 {
00125 name.append(1, ' ');
00126 name.append(lastname);
00127 }
00128
00129 setText(name);
00130 }
00131 }
00132
00133 void LLNameEditor::refreshAll(const LLUUID& id, const char* firstname,
00134 const char* lastname, BOOL is_group)
00135 {
00136 std::set<LLNameEditor*>::iterator it;
00137 for (it = LLNameEditor::sInstances.begin();
00138 it != LLNameEditor::sInstances.end();
00139 ++it)
00140 {
00141 LLNameEditor* box = *it;
00142 box->refresh(id, firstname, lastname, is_group);
00143 }
00144 }
00145
00146 void LLNameEditor::setValue( LLSD value )
00147 {
00148 setNameID(value.asUUID(), FALSE);
00149 }
00150
00151 LLSD LLNameEditor::getValue() const
00152 {
00153 return LLSD(mNameID);
00154 }
00155
00156 LLView* LLNameEditor::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory)
00157 {
00158 LLString name("name_editor");
00159 node->getAttributeString("name", name);
00160
00161 LLRect rect;
00162 createRect(node, rect, parent, LLRect());
00163
00164 S32 max_text_length = 128;
00165 node->getAttributeS32("max_length", max_text_length);
00166
00167 LLFontGL* font = LLView::selectFont(node);
00168
00169 LLViewBorder::EStyle border_style = LLViewBorder::STYLE_LINE;
00170 LLString border_string;
00171 node->getAttributeString("border_style", border_string);
00172 LLString::toLower(border_string);
00173
00174 if (border_string == "texture")
00175 {
00176 border_style = LLViewBorder::STYLE_TEXTURE;
00177 }
00178
00179 S32 border_thickness = 1;
00180 node->getAttributeS32("border_thickness", border_thickness);
00181
00182 LLUICtrlCallback commit_callback = NULL;
00183
00184 LLNameEditor* line_editor = new LLNameEditor(name,
00185 rect,
00186 LLUUID::null, FALSE,
00187 font,
00188 max_text_length,
00189 commit_callback,
00190 NULL,
00191 NULL,
00192 NULL,
00193 NULL,
00194 LLViewBorder::BEVEL_IN,
00195 border_style,
00196 border_thickness);
00197
00198 LLString label;
00199 if(node->getAttributeString("label", label))
00200 {
00201 line_editor->setLabel(label);
00202 }
00203 line_editor->setColorParameters(node);
00204 line_editor->initFromXML(node, parent);
00205
00206 return line_editor;
00207 }