summaryrefslogtreecommitdiff
path: root/indra/newview/llnamelistctrl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/llnamelistctrl.cpp')
-rw-r--r--indra/newview/llnamelistctrl.cpp328
1 files changed, 79 insertions, 249 deletions
diff --git a/indra/newview/llnamelistctrl.cpp b/indra/newview/llnamelistctrl.cpp
index baf06567c1..722113928b 100644
--- a/indra/newview/llnamelistctrl.cpp
+++ b/indra/newview/llnamelistctrl.cpp
@@ -39,51 +39,46 @@
#include "llcachename.h"
#include "llagent.h"
#include "llinventory.h"
+#include "llscrolllistitem.h"
+#include "llscrolllistcell.h"
+#include "llscrolllistcolumn.h"
+#include "llsdparam.h"
-static LLRegisterWidget<LLNameListCtrl> r("name_list");
-
-// statics
-std::set<LLNameListCtrl*> LLNameListCtrl::sInstances;
-
-LLNameListCtrl::LLNameListCtrl(const std::string& name,
- const LLRect& rect,
- LLUICtrlCallback cb,
- void* userdata,
- BOOL allow_multiple_selection,
- BOOL draw_border,
- S32 name_column_index,
- const std::string& tooltip)
-: LLScrollListCtrl(name, rect, cb, userdata, allow_multiple_selection,
- draw_border),
- mNameColumnIndex(name_column_index),
- mAllowCallingCardDrop(FALSE)
+static LLDefaultWidgetRegistry::Register<LLNameListCtrl> r("name_list");
+
+void LLNameListCtrl::NameTypeNames::declareValues()
{
- setToolTip(tooltip);
- LLNameListCtrl::sInstances.insert(this);
+ declare("INDIVIDUAL", LLNameListCtrl::INDIVIDUAL);
+ declare("GROUP", LLNameListCtrl::GROUP);
+ declare("SPECIAL", LLNameListCtrl::SPECIAL);
}
-
-// virtual
-LLNameListCtrl::~LLNameListCtrl()
+LLNameListCtrl::Params::Params()
+: name_column(""),
+ allow_calling_card_drop("allow_calling_card_drop", false)
{
- LLNameListCtrl::sInstances.erase(this);
+ name = "name_list";
}
+LLNameListCtrl::LLNameListCtrl(const LLNameListCtrl::Params& p)
+: LLScrollListCtrl(p),
+ mAllowCallingCardDrop(p.allow_calling_card_drop),
+ mNameColumn(p.name_column.column_name),
+ mNameColumnIndex(p.name_column.column_index)
+{}
// public
-BOOL LLNameListCtrl::addNameItem(const LLUUID& agent_id, EAddPosition pos,
+void LLNameListCtrl::addNameItem(const LLUUID& agent_id, EAddPosition pos,
BOOL enabled, std::string& suffix)
{
//llinfos << "LLNameListCtrl::addNameItem " << agent_id << llendl;
std::string fullname;
- BOOL result = gCacheName->getFullName(agent_id, fullname);
+ gCacheName->getFullName(agent_id, fullname);
fullname.append(suffix);
addStringUUIDItem(fullname, agent_id, pos, enabled);
-
- return result;
}
// virtual, public
@@ -138,75 +133,70 @@ BOOL LLNameListCtrl::handleDragAndDrop(
void LLNameListCtrl::addGroupNameItem(const LLUUID& group_id, EAddPosition pos,
BOOL enabled)
{
- //llinfos << "LLNameListCtrl::addGroupNameItem " << group_id << llendl;
- std::string group_name;
- gCacheName->getGroupName(group_id, group_name);
- addStringUUIDItem(group_name, group_id, pos, enabled);
+ NameItem item;
+ item.value = group_id;
+ item.enabled = enabled;
+ item.target = GROUP;
+
+ addRow(item, pos);
}
// public
-void LLNameListCtrl::addGroupNameItem(LLScrollListItem* item, EAddPosition pos)
-
+void LLNameListCtrl::addGroupNameItem(LLNameListCtrl::NameItem& item, EAddPosition pos)
{
- //llinfos << "LLNameListCtrl::addGroupNameItem " << item->getUUID() << llendl;
-
- std::string group_name;
- gCacheName->getGroupName(item->getUUID(), group_name);
-
- LLScrollListCell* cell = (LLScrollListCell*)item->getColumn(mNameColumnIndex);
- ((LLScrollListText*)cell)->setText( std::string(group_name) );
-
- addItem(item, pos);
+ item.target = GROUP;
+ addRow(item, pos);
}
-BOOL LLNameListCtrl::addNameItem(LLScrollListItem* item, EAddPosition pos)
+void LLNameListCtrl::addNameItem(LLNameListCtrl::NameItem& item, EAddPosition pos)
{
- //llinfos << "LLNameListCtrl::addNameItem " << item->getUUID() << llendl;
-
- std::string fullname;
- BOOL result = gCacheName->getFullName(item->getUUID(), fullname);
-
- LLScrollListCell* cell = (LLScrollListCell*)item->getColumn(mNameColumnIndex);
- ((LLScrollListText*)cell)->setText( fullname );
-
- addItem(item, pos);
-
- // this column is resizable
- LLScrollListColumn* columnp = getColumn(mNameColumnIndex);
- if (columnp && columnp->mHeader)
- {
- columnp->mHeader->setHasResizableElement(TRUE);
- }
+ item.target = INDIVIDUAL;
+ addRow(item, pos);
+}
- return result;
+LLScrollListItem* LLNameListCtrl::addElement(const LLSD& element, EAddPosition pos, void* userdata)
+{
+ LLNameListCtrl::NameItem item_params;
+ LLParamSDParser::instance().readSD(element, item_params);
+ item_params.userdata = userdata;
+ return addRow(item_params, pos);
}
-LLScrollListItem* LLNameListCtrl::addElement(const LLSD& value, EAddPosition pos, void* userdata)
+
+LLScrollListItem* LLNameListCtrl::addRow(const LLNameListCtrl::NameItem& name_item, EAddPosition pos)
{
- LLScrollListItem* item = LLScrollListCtrl::addElement(value, pos, userdata);
+ LLScrollListItem* item = LLScrollListCtrl::addRow(name_item, pos);
+ if (!item) return NULL;
// use supplied name by default
- std::string fullname = value["name"].asString();
- if (value["target"].asString() == "GROUP")
+ std::string fullname = name_item.display_name;
+ switch(name_item.target)
{
- gCacheName->getGroupName(item->getUUID(), fullname);
+ case GROUP:
+ gCacheName->getGroupName(name_item.value().asUUID(), fullname);
// fullname will be "nobody" if group not found
- }
- else if (value["target"].asString() == "SPECIAL")
- {
+ break;
+ case SPECIAL:
// just use supplied name
- }
- else // normal resident
- {
- std::string name;
- if (gCacheName->getFullName(item->getUUID(), name))
+ break;
+ case INDIVIDUAL:
{
- fullname = name;
+ std::string name;
+ if (gCacheName->getFullName(name_item.value().asUUID(), name))
+ {
+ fullname = name;
+ }
+ break;
}
+ default:
+ break;
}
- LLScrollListCell* cell = (LLScrollListCell*)item->getColumn(mNameColumnIndex);
- ((LLScrollListText*)cell)->setText( fullname );
+ LLScrollListCell* cell = item->getColumn(mNameColumnIndex);
+ if (cell)
+ {
+ cell->setValue(fullname);
+ }
dirtyColumns();
@@ -259,9 +249,11 @@ void LLNameListCtrl::refresh(const LLUUID& id, const std::string& first,
if (item->getUUID() == id)
{
LLScrollListCell* cell = (LLScrollListCell*)item->getColumn(0);
- cell = (LLScrollListCell*)item->getColumn(mNameColumnIndex);
-
- ((LLScrollListText*)cell)->setText( fullname );
+ cell = item->getColumn(mNameColumnIndex);
+ if (cell)
+ {
+ cell->setValue(fullname);
+ }
}
}
@@ -273,186 +265,24 @@ void LLNameListCtrl::refresh(const LLUUID& id, const std::string& first,
void LLNameListCtrl::refreshAll(const LLUUID& id, const std::string& first,
const std::string& last, BOOL is_group)
{
- std::set<LLNameListCtrl*>::iterator it;
- for (it = LLNameListCtrl::sInstances.begin();
- it != LLNameListCtrl::sInstances.end();
- ++it)
+ LLInstanceTracker<LLNameListCtrl>::instance_iter it;
+ for (it = beginInstances(); it != endInstances(); ++it)
{
LLNameListCtrl* ctrl = *it;
ctrl->refresh(id, first, last, is_group);
}
}
-// virtual
-LLXMLNodePtr LLNameListCtrl::getXML(bool save_children) const
+void LLNameListCtrl::updateColumns()
{
- LLXMLNodePtr node = LLScrollListCtrl::getXML();
-
- node->createChild("allow_calling_card_drop", TRUE)->setBoolValue(mAllowCallingCardDrop);
-
- if (mNameColumnIndex != 0)
- {
- node->createChild("name_column_index", TRUE)->setIntValue(mNameColumnIndex);
- }
-
- // Don't save contents, probably filled by code
-
- return node;
-}
-
-LLView* LLNameListCtrl::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory)
-{
- std::string name("name_list");
- node->getAttributeString("name", name);
-
- LLRect rect;
- createRect(node, rect, parent, LLRect());
-
- BOOL multi_select = FALSE;
- node->getAttributeBOOL("multi_select", multi_select);
-
- BOOL draw_border = TRUE;
- node->getAttributeBOOL("draw_border", draw_border);
-
- BOOL draw_heading = FALSE;
- node->getAttributeBOOL("draw_heading", draw_heading);
-
- S32 name_column_index = 0;
- node->getAttributeS32("name_column_index", name_column_index);
+ LLScrollListCtrl::updateColumns();
- LLUICtrlCallback callback = NULL;
-
- LLNameListCtrl* name_list = new LLNameListCtrl(name,
- rect,
- callback,
- NULL,
- multi_select,
- draw_border,
- name_column_index);
-
- name_list->setDisplayHeading(draw_heading);
- if (node->hasAttribute("heading_height"))
- {
- S32 heading_height;
- node->getAttributeS32("heading_height", heading_height);
- name_list->setHeadingHeight(heading_height);
- }
-
- BOOL allow_calling_card_drop = FALSE;
- if (node->getAttributeBOOL("allow_calling_card_drop", allow_calling_card_drop))
- {
- name_list->setAllowCallingCardDrop(allow_calling_card_drop);
- }
-
- name_list->setScrollListParameters(node);
-
- name_list->initFromXML(node, parent);
-
- LLSD columns;
- S32 index = 0;
- //S32 total_static = 0;
- LLXMLNodePtr child;
- for (child = node->getFirstChild(); child.notNull(); child = child->getNextSibling())
- {
- if (child->hasName("column"))
- {
- std::string labelname("");
- child->getAttributeString("label", labelname);
-
- std::string columnname(labelname);
- child->getAttributeString("name", columnname);
-
- BOOL columndynamicwidth = FALSE;
- child->getAttributeBOOL("dynamicwidth", columndynamicwidth);
-
- std::string sortname(columnname);
- child->getAttributeString("sort", sortname);
-
- S32 columnwidth = -1;
- if (child->hasAttribute("relwidth"))
- {
- F32 columnrelwidth = 0.f;
- child->getAttributeF32("relwidth", columnrelwidth);
- columns[index]["relwidth"] = columnrelwidth;
- }
- else
- {
- child->getAttributeS32("width", columnwidth);
- columns[index]["width"] = columnwidth;
- }
-
- LLFontGL::HAlign h_align = LLFontGL::LEFT;
- h_align = LLView::selectFontHAlign(child);
-
- //if(!columndynamicwidth) total_static += llmax(0, columnwidth);
-
- columns[index]["name"] = columnname;
- columns[index]["label"] = labelname;
- columns[index]["halign"] = (S32)h_align;
- columns[index]["dynamicwidth"] = columndynamicwidth;
- columns[index]["sort"] = sortname;
-
- index++;
- }
- }
- name_list->setColumnHeadings(columns);
-
-
- for (child = node->getFirstChild(); child.notNull(); child = child->getNextSibling())
+ if (!mNameColumn.empty())
{
- if (child->hasName("row"))
+ LLScrollListColumn* name_column = getColumn(mNameColumn);
+ if (name_column)
{
- LLUUID id;
- child->getAttributeUUID("id", id);
-
- LLSD row;
-
- row["id"] = id;
-
- S32 column_idx = 0;
- LLXMLNodePtr row_child;
- for (row_child = node->getFirstChild(); row_child.notNull(); row_child = row_child->getNextSibling())
- {
- if (row_child->hasName("column"))
- {
- std::string value = row_child->getTextContents();
-
- std::string columnname("");
- row_child->getAttributeString("name", columnname);
-
- std::string font("");
- row_child->getAttributeString("font", font);
-
- std::string font_style("");
- row_child->getAttributeString("font-style", font_style);
-
- row["columns"][column_idx]["column"] = columnname;
- row["columns"][column_idx]["value"] = value;
- row["columns"][column_idx]["font"] = font;
- row["columns"][column_idx]["font-style"] = font_style;
- column_idx++;
- }
- }
- name_list->addElement(row);
+ mNameColumnIndex = name_column->mIndex;
}
}
-
- std::string contents = node->getTextContents();
-
- typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
- boost::char_separator<char> sep("\t\n");
- tokenizer tokens(contents, sep);
- tokenizer::iterator token_iter = tokens.begin();
-
- while(token_iter != tokens.end())
- {
- const std::string& line = *token_iter;
- name_list->addCommentText(line);
- ++token_iter;
- }
-
- return name_list;
}
-
-
-