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 static LLRegisterWidget<LLNameEditor> r("name_editor");
00046
00047
00048 std::set<LLNameEditor*> LLNameEditor::sInstances;
00049
00050 LLNameEditor::LLNameEditor(const std::string& name, const LLRect& rect,
00051 const LLUUID& name_id,
00052 BOOL is_group,
00053 const LLFontGL* glfont,
00054 S32 max_text_length,
00055 void (*commit_callback)(LLUICtrl* caller, void* user_data),
00056 void (*keystroke_callback)(LLLineEditor* caller, void* user_data),
00057 void (*focus_lost_callback)(LLFocusableElement* caller, void* user_data),
00058 void* userdata,
00059 LLLinePrevalidateFunc prevalidate_func)
00060 : LLLineEditor(name, rect,
00061 "(retrieving)",
00062 glfont,
00063 max_text_length,
00064 commit_callback,
00065 keystroke_callback,
00066 focus_lost_callback,
00067 userdata,
00068 prevalidate_func),
00069 mNameID(name_id)
00070 {
00071 LLNameEditor::sInstances.insert(this);
00072 if(!name_id.isNull())
00073 {
00074 setNameID(name_id, is_group);
00075 }
00076 }
00077
00078
00079 LLNameEditor::~LLNameEditor()
00080 {
00081 LLNameEditor::sInstances.erase(this);
00082 }
00083
00084 void LLNameEditor::setNameID(const LLUUID& name_id, BOOL is_group)
00085 {
00086 mNameID = name_id;
00087
00088 std::string name;
00089
00090 if (!is_group)
00091 {
00092 gCacheName->getFullName(name_id, name);
00093 }
00094 else
00095 {
00096 gCacheName->getGroupName(name_id, name);
00097 }
00098
00099 setText(name);
00100 }
00101
00102 void LLNameEditor::refresh(const LLUUID& id, const char* firstname,
00103 const char* lastname, BOOL is_group)
00104 {
00105 if (id == mNameID)
00106 {
00107 LLString name;
00108
00109 name.assign(firstname);
00110 if (!is_group)
00111 {
00112 name.append(1, ' ');
00113 name.append(lastname);
00114 }
00115
00116 setText(name);
00117 }
00118 }
00119
00120 void LLNameEditor::refreshAll(const LLUUID& id, const char* firstname,
00121 const char* lastname, BOOL is_group)
00122 {
00123 std::set<LLNameEditor*>::iterator it;
00124 for (it = LLNameEditor::sInstances.begin();
00125 it != LLNameEditor::sInstances.end();
00126 ++it)
00127 {
00128 LLNameEditor* box = *it;
00129 box->refresh(id, firstname, lastname, is_group);
00130 }
00131 }
00132
00133 void LLNameEditor::setValue( const LLSD& value )
00134 {
00135 setNameID(value.asUUID(), FALSE);
00136 }
00137
00138 LLSD LLNameEditor::getValue() const
00139 {
00140 return LLSD(mNameID);
00141 }
00142
00143 LLView* LLNameEditor::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory)
00144 {
00145 LLString name("name_editor");
00146 node->getAttributeString("name", name);
00147
00148 LLRect rect;
00149 createRect(node, rect, parent, LLRect());
00150
00151 S32 max_text_length = 128;
00152 node->getAttributeS32("max_length", max_text_length);
00153
00154 LLFontGL* font = LLView::selectFont(node);
00155
00156 LLUICtrlCallback commit_callback = NULL;
00157
00158 LLNameEditor* line_editor = new LLNameEditor(name,
00159 rect,
00160 LLUUID::null, FALSE,
00161 font,
00162 max_text_length,
00163 commit_callback);
00164
00165 LLString label;
00166 if(node->getAttributeString("label", label))
00167 {
00168 line_editor->setLabel(label);
00169 }
00170 line_editor->setColorParameters(node);
00171 line_editor->initFromXML(node, parent);
00172
00173 return line_editor;
00174 }