diff options
author | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
commit | 38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch) | |
tree | adca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/newview/llnamelistctrl.cpp | |
parent | README.txt (diff) | |
download | meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2 meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz |
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/newview/llnamelistctrl.cpp')
-rw-r--r-- | linden/indra/newview/llnamelistctrl.cpp | 428 |
1 files changed, 428 insertions, 0 deletions
diff --git a/linden/indra/newview/llnamelistctrl.cpp b/linden/indra/newview/llnamelistctrl.cpp new file mode 100644 index 0000000..f02e86b --- /dev/null +++ b/linden/indra/newview/llnamelistctrl.cpp | |||
@@ -0,0 +1,428 @@ | |||
1 | /** | ||
2 | * @file llnamelistctrl.cpp | ||
3 | * @brief A list of names, automatically refreshed from name cache. | ||
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 <boost/tokenizer.hpp> | ||
31 | |||
32 | #include "llnamelistctrl.h" | ||
33 | |||
34 | #include "llcachename.h" | ||
35 | #include "llagent.h" | ||
36 | #include "llinventory.h" | ||
37 | |||
38 | // statics | ||
39 | std::set<LLNameListCtrl*> LLNameListCtrl::sInstances; | ||
40 | |||
41 | LLNameListCtrl::LLNameListCtrl(const LLString& name, | ||
42 | const LLRect& rect, | ||
43 | LLUICtrlCallback cb, | ||
44 | void* userdata, | ||
45 | BOOL allow_multiple_selection, | ||
46 | BOOL draw_border, | ||
47 | S32 name_column_index, | ||
48 | const LLString& tooltip) | ||
49 | : LLScrollListCtrl(name, rect, cb, userdata, allow_multiple_selection, | ||
50 | draw_border), | ||
51 | mNameColumnIndex(name_column_index), | ||
52 | mAllowCallingCardDrop(FALSE) | ||
53 | { | ||
54 | setToolTip(tooltip); | ||
55 | LLNameListCtrl::sInstances.insert(this); | ||
56 | } | ||
57 | |||
58 | |||
59 | // virtual | ||
60 | LLNameListCtrl::~LLNameListCtrl() | ||
61 | { | ||
62 | LLNameListCtrl::sInstances.erase(this); | ||
63 | } | ||
64 | |||
65 | |||
66 | // public | ||
67 | BOOL LLNameListCtrl::addNameItem(const LLUUID& agent_id, EAddPosition pos, | ||
68 | BOOL enabled, LLString& suffix) | ||
69 | { | ||
70 | //llinfos << "LLNameListCtrl::addNameItem " << agent_id << llendl; | ||
71 | |||
72 | char first[DB_FIRST_NAME_BUF_SIZE]; | ||
73 | char last[DB_LAST_NAME_BUF_SIZE]; | ||
74 | |||
75 | BOOL result = gCacheName->getName(agent_id, first, last); | ||
76 | |||
77 | LLString fullname; | ||
78 | fullname.assign(first); | ||
79 | fullname.append(1, ' '); | ||
80 | fullname.append(last); | ||
81 | fullname.append(suffix); | ||
82 | |||
83 | addStringUUIDItem(fullname, agent_id, pos, enabled); | ||
84 | |||
85 | return result; | ||
86 | } | ||
87 | |||
88 | // virtual, public | ||
89 | BOOL LLNameListCtrl::handleDragAndDrop( | ||
90 | S32 x, S32 y, MASK mask, | ||
91 | BOOL drop, | ||
92 | EDragAndDropType cargo_type, void *cargo_data, | ||
93 | EAcceptance *accept, | ||
94 | LLString& tooltip_msg) | ||
95 | { | ||
96 | if (!mAllowCallingCardDrop) | ||
97 | { | ||
98 | return FALSE; | ||
99 | } | ||
100 | |||
101 | BOOL handled = FALSE; | ||
102 | |||
103 | if (cargo_type == DAD_CALLINGCARD) | ||
104 | { | ||
105 | if (drop) | ||
106 | { | ||
107 | LLInventoryItem* item = (LLInventoryItem *)cargo_data; | ||
108 | addNameItem(item->getCreatorUUID()); | ||
109 | } | ||
110 | |||
111 | *accept = ACCEPT_YES_MULTI; | ||
112 | } | ||
113 | else | ||
114 | { | ||
115 | *accept = ACCEPT_NO; | ||
116 | if (tooltip_msg.empty()) | ||
117 | { | ||
118 | if (!getToolTip().empty()) | ||
119 | { | ||
120 | tooltip_msg = getToolTip(); | ||
121 | } | ||
122 | else | ||
123 | { | ||
124 | // backwards compatable English tooltip (should be overridden in xml) | ||
125 | tooltip_msg.assign("Drag a calling card here\nto add a resident."); | ||
126 | } | ||
127 | } | ||
128 | } | ||
129 | |||
130 | handled = TRUE; | ||
131 | lldebugst(LLERR_USER_INPUT) << "dragAndDrop handled by LLNameListCtrl " << getName() << llendl; | ||
132 | |||
133 | return handled; | ||
134 | } | ||
135 | |||
136 | // public | ||
137 | void LLNameListCtrl::addGroupNameItem(const LLUUID& group_id, EAddPosition pos, | ||
138 | BOOL enabled) | ||
139 | { | ||
140 | //llinfos << "LLNameListCtrl::addGroupNameItem " << group_id << llendl; | ||
141 | char group_name[DB_GROUP_NAME_BUF_SIZE]; | ||
142 | gCacheName->getGroupName(group_id, group_name); | ||
143 | addStringUUIDItem(group_name, group_id, pos, enabled); | ||
144 | } | ||
145 | |||
146 | // public | ||
147 | void LLNameListCtrl::addGroupNameItem(LLScrollListItem* item, EAddPosition pos) | ||
148 | |||
149 | { | ||
150 | //llinfos << "LLNameListCtrl::addGroupNameItem " << item->getUUID() << llendl; | ||
151 | |||
152 | char group_name[DB_GROUP_NAME_BUF_SIZE]; | ||
153 | gCacheName->getGroupName(item->getUUID(), group_name); | ||
154 | |||
155 | LLScrollListCell* cell = (LLScrollListCell*)item->getColumn(mNameColumnIndex); | ||
156 | ((LLScrollListText*)cell)->setText( group_name ); | ||
157 | |||
158 | addItem(item, pos); | ||
159 | } | ||
160 | |||
161 | BOOL LLNameListCtrl::addNameItem(LLScrollListItem* item, EAddPosition pos) | ||
162 | { | ||
163 | //llinfos << "LLNameListCtrl::addNameItem " << item->getUUID() << llendl; | ||
164 | |||
165 | char first[DB_FIRST_NAME_BUF_SIZE]; | ||
166 | char last[DB_LAST_NAME_BUF_SIZE]; | ||
167 | |||
168 | BOOL result = gCacheName->getName(item->getUUID(), first, last); | ||
169 | |||
170 | LLString fullname; | ||
171 | fullname.assign(first); | ||
172 | fullname.append(1, ' '); | ||
173 | fullname.append(last); | ||
174 | |||
175 | LLScrollListCell* cell = (LLScrollListCell*)item->getColumn(mNameColumnIndex); | ||
176 | ((LLScrollListText*)cell)->setText( fullname ); | ||
177 | |||
178 | addItem(item, pos); | ||
179 | |||
180 | return result; | ||
181 | } | ||
182 | |||
183 | LLScrollListItem* LLNameListCtrl::addElement(const LLSD& value, EAddPosition pos, void* userdata) | ||
184 | { | ||
185 | LLScrollListItem* item = LLScrollListCtrl::addElement(value, pos, userdata); | ||
186 | |||
187 | char first[DB_FIRST_NAME_BUF_SIZE]; | ||
188 | char last[DB_LAST_NAME_BUF_SIZE]; | ||
189 | |||
190 | gCacheName->getName(item->getUUID(), first, last); | ||
191 | |||
192 | LLString fullname; | ||
193 | fullname.assign(first); | ||
194 | fullname.append(1, ' '); | ||
195 | fullname.append(last); | ||
196 | |||
197 | LLScrollListCell* cell = (LLScrollListCell*)item->getColumn(mNameColumnIndex); | ||
198 | ((LLScrollListText*)cell)->setText( fullname ); | ||
199 | |||
200 | return item; | ||
201 | } | ||
202 | |||
203 | // public | ||
204 | void LLNameListCtrl::removeNameItem(const LLUUID& agent_id) | ||
205 | { | ||
206 | BOOL item_exists = selectByID( agent_id ); | ||
207 | if(item_exists) | ||
208 | { | ||
209 | S32 index = getItemIndex(getFirstSelected()); | ||
210 | if(index >= 0) | ||
211 | { | ||
212 | deleteSingleItem(index); | ||
213 | } | ||
214 | } | ||
215 | } | ||
216 | |||
217 | // public | ||
218 | void LLNameListCtrl::refresh(const LLUUID& id, const char* first, | ||
219 | const char* last, | ||
220 | BOOL is_group) | ||
221 | { | ||
222 | //llinfos << "LLNameListCtrl::refresh " << id << " '" << first << " " | ||
223 | // << last << "'" << llendl; | ||
224 | |||
225 | LLString fullname; | ||
226 | fullname.assign(first); | ||
227 | if (last[0] && !is_group) | ||
228 | { | ||
229 | fullname.append(1, ' '); | ||
230 | fullname.append(last); | ||
231 | } | ||
232 | |||
233 | // TODO: scan items for that ID, fix if necessary | ||
234 | item_list::iterator iter; | ||
235 | for (iter = mItemList.begin(); iter != mItemList.end(); iter++) | ||
236 | { | ||
237 | LLScrollListItem* item = *iter; | ||
238 | if (item->getUUID() == id) | ||
239 | { | ||
240 | LLScrollListCell* cell = (LLScrollListCell*)item->getColumn(0); | ||
241 | cell = (LLScrollListCell*)item->getColumn(mNameColumnIndex); | ||
242 | |||
243 | ((LLScrollListText*)cell)->setText( fullname ); | ||
244 | } | ||
245 | } | ||
246 | } | ||
247 | |||
248 | |||
249 | // static | ||
250 | void LLNameListCtrl::refreshAll(const LLUUID& id, const char* first, | ||
251 | const char* last, | ||
252 | BOOL is_group) | ||
253 | { | ||
254 | std::set<LLNameListCtrl*>::iterator it; | ||
255 | for (it = LLNameListCtrl::sInstances.begin(); | ||
256 | it != LLNameListCtrl::sInstances.end(); | ||
257 | ++it) | ||
258 | { | ||
259 | LLNameListCtrl* ctrl = *it; | ||
260 | ctrl->refresh(id, first, last, is_group); | ||
261 | } | ||
262 | } | ||
263 | |||
264 | // virtual | ||
265 | LLXMLNodePtr LLNameListCtrl::getXML(bool save_children) const | ||
266 | { | ||
267 | LLXMLNodePtr node = LLScrollListCtrl::getXML(); | ||
268 | |||
269 | node->createChild("allow_calling_card_drop", TRUE)->setBoolValue(mAllowCallingCardDrop); | ||
270 | |||
271 | if (mNameColumnIndex != 0) | ||
272 | { | ||
273 | node->createChild("name_column_index", TRUE)->setIntValue(mNameColumnIndex); | ||
274 | } | ||
275 | |||
276 | // Don't save contents, probably filled by code | ||
277 | |||
278 | return node; | ||
279 | } | ||
280 | |||
281 | LLView* LLNameListCtrl::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory) | ||
282 | { | ||
283 | LLString name("name_list"); | ||
284 | node->getAttributeString("name", name); | ||
285 | |||
286 | LLRect rect; | ||
287 | createRect(node, rect, parent, LLRect()); | ||
288 | |||
289 | BOOL multi_select = FALSE; | ||
290 | node->getAttributeBOOL("multi_select", multi_select); | ||
291 | |||
292 | BOOL draw_border = TRUE; | ||
293 | node->getAttributeBOOL("draw_border", draw_border); | ||
294 | |||
295 | BOOL draw_heading = FALSE; | ||
296 | node->getAttributeBOOL("draw_heading", draw_heading); | ||
297 | |||
298 | BOOL collapse_empty_columns = FALSE; | ||
299 | node->getAttributeBOOL("collapse_empty_columns", collapse_empty_columns); | ||
300 | |||
301 | S32 name_column_index = 0; | ||
302 | node->getAttributeS32("name_column_index", name_column_index); | ||
303 | |||
304 | LLUICtrlCallback callback = NULL; | ||
305 | |||
306 | LLNameListCtrl* name_list = new LLNameListCtrl(name, | ||
307 | rect, | ||
308 | callback, | ||
309 | NULL, | ||
310 | multi_select, | ||
311 | draw_border, | ||
312 | name_column_index); | ||
313 | |||
314 | name_list->setDisplayHeading(draw_heading); | ||
315 | if (node->hasAttribute("heading_height")) | ||
316 | { | ||
317 | S32 heading_height; | ||
318 | node->getAttributeS32("heading_height", heading_height); | ||
319 | name_list->setHeadingHeight(heading_height); | ||
320 | } | ||
321 | if (node->hasAttribute("heading_font")) | ||
322 | { | ||
323 | LLString heading_font(""); | ||
324 | node->getAttributeString("heading_font", heading_font); | ||
325 | LLFontGL* gl_font = LLFontGL::fontFromName(heading_font.c_str()); | ||
326 | name_list->setHeadingFont(gl_font); | ||
327 | } | ||
328 | name_list->setCollapseEmptyColumns(collapse_empty_columns); | ||
329 | |||
330 | BOOL allow_calling_card_drop = FALSE; | ||
331 | if (node->getAttributeBOOL("allow_calling_card_drop", allow_calling_card_drop)) | ||
332 | { | ||
333 | name_list->setAllowCallingCardDrop(allow_calling_card_drop); | ||
334 | } | ||
335 | |||
336 | name_list->setScrollListParameters(node); | ||
337 | |||
338 | name_list->initFromXML(node, parent); | ||
339 | |||
340 | LLSD columns; | ||
341 | S32 index = 0; | ||
342 | LLXMLNodePtr child; | ||
343 | for (child = node->getFirstChild(); child.notNull(); child = child->getNextSibling()) | ||
344 | { | ||
345 | if (child->hasName("column")) | ||
346 | { | ||
347 | LLString labelname(""); | ||
348 | child->getAttributeString("label", labelname); | ||
349 | |||
350 | LLString columnname(labelname); | ||
351 | child->getAttributeString("name", columnname); | ||
352 | |||
353 | if (child->hasAttribute("relwidth")) | ||
354 | { | ||
355 | F32 columnrelwidth = 0.f; | ||
356 | child->getAttributeF32("relwidth", columnrelwidth); | ||
357 | columns[index]["relwidth"] = columnrelwidth; | ||
358 | } | ||
359 | else | ||
360 | { | ||
361 | S32 columnwidth = -1; | ||
362 | child->getAttributeS32("width", columnwidth); | ||
363 | columns[index]["width"] = columnwidth; | ||
364 | } | ||
365 | |||
366 | columns[index]["name"] = columnname; | ||
367 | columns[index]["label"] = labelname; | ||
368 | index++; | ||
369 | } | ||
370 | } | ||
371 | name_list->setColumnHeadings(columns); | ||
372 | |||
373 | for (child = node->getFirstChild(); child.notNull(); child = child->getNextSibling()) | ||
374 | { | ||
375 | if (child->hasName("row")) | ||
376 | { | ||
377 | LLUUID id; | ||
378 | child->getAttributeUUID("id", id); | ||
379 | |||
380 | LLSD row; | ||
381 | |||
382 | row["id"] = id; | ||
383 | |||
384 | S32 column_idx = 0; | ||
385 | LLXMLNodePtr row_child; | ||
386 | for (row_child = node->getFirstChild(); row_child.notNull(); row_child = row_child->getNextSibling()) | ||
387 | { | ||
388 | if (row_child->hasName("column")) | ||
389 | { | ||
390 | LLString value = row_child->getTextContents(); | ||
391 | |||
392 | LLString columnname(""); | ||
393 | row_child->getAttributeString("name", columnname); | ||
394 | |||
395 | LLString font(""); | ||
396 | row_child->getAttributeString("font", font); | ||
397 | |||
398 | LLString font_style(""); | ||
399 | row_child->getAttributeString("font-style", font_style); | ||
400 | |||
401 | row["columns"][column_idx]["column"] = columnname; | ||
402 | row["columns"][column_idx]["value"] = value; | ||
403 | row["columns"][column_idx]["font"] = font; | ||
404 | row["columns"][column_idx]["font-style"] = font_style; | ||
405 | column_idx++; | ||
406 | } | ||
407 | } | ||
408 | name_list->addElement(row); | ||
409 | } | ||
410 | } | ||
411 | |||
412 | LLString contents = node->getTextContents(); | ||
413 | |||
414 | typedef boost::tokenizer<boost::char_separator<char> > tokenizer; | ||
415 | boost::char_separator<char> sep("\t\n"); | ||
416 | tokenizer tokens(contents, sep); | ||
417 | tokenizer::iterator token_iter = tokens.begin(); | ||
418 | |||
419 | while(token_iter != tokens.end()) | ||
420 | { | ||
421 | const char* line = token_iter->c_str(); | ||
422 | name_list->addSimpleItem(line); | ||
423 | ++token_iter; | ||
424 | } | ||
425 | |||
426 | return name_list; | ||
427 | } | ||
428 | |||