Update LLNameListCtrl, mostly to use Params for its elements

This commit is contained in:
Lirusaito
2013-07-17 02:07:17 -04:00
parent c35a1c36e9
commit 76f0f42f20
7 changed files with 205 additions and 182 deletions

View File

@@ -2,31 +2,25 @@
* @file llnamelistctrl.cpp
* @brief A list of names, automatically refreshed from name cache.
*
* $LicenseInfo:firstyear=2003&license=viewergpl$
*
* Copyright (c) 2003-2009, Linden Research, Inc.
*
* $LicenseInfo:firstyear=2003&license=viewerlgpl$
* Second Life Viewer Source Code
* The source code in this file ("Source Code") is provided by Linden Lab
* to you under the terms of the GNU General Public License, version 2.0
* ("GPL"), unless you have obtained a separate licensing agreement
* ("Other License"), formally executed by you and Linden Lab. Terms of
* the GPL can be found in doc/GPL-license.txt in this distribution, or
* online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* There are special exceptions to the terms and conditions of the GPL as
* it is applied to this Source Code. View the full text of the exception
* in the file doc/FLOSS-exception.txt in this software distribution, or
* online at
* http://secondlifegrid.net/programs/open_source/licensing/flossexception
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* By copying, modifying or distributing this software, you acknowledge
* that you have read and understood your obligations described above,
* and agree to abide by those obligations.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
@@ -42,55 +36,41 @@
#include "llinventory.h"
#include "llscrolllistitem.h"
#include "llscrolllistcolumn.h"
#include "llsdparam.h"
#include "lltrans.h"
static LLRegisterWidget<LLNameListCtrl> r("name_list");
// statics
std::set<LLNameListCtrl*> LLNameListCtrl::sInstances;
LLNameListCtrl::LLNameListCtrl(const std::string& name,
const LLRect& rect,
BOOL allow_multiple_selection,
BOOL draw_border,
bool draw_heading,
S32 name_column_index,
const std::string& tooltip)
: LLScrollListCtrl(name, rect, NULL, allow_multiple_selection,
draw_border,draw_heading),
void LLNameListCtrl::NameTypeNames::declareValues()
{
declare("INDIVIDUAL", LLNameListCtrl::INDIVIDUAL);
declare("GROUP", LLNameListCtrl::GROUP);
declare("SPECIAL", LLNameListCtrl::SPECIAL);
}
LLNameListCtrl::LLNameListCtrl(const std::string& name, const LLRect& rect, BOOL allow_multiple_selection, BOOL draw_border, bool draw_heading, S32 name_column_index, const std::string& tooltip)
: LLScrollListCtrl(name, rect, NULL, allow_multiple_selection, draw_border,draw_heading),
mNameColumnIndex(name_column_index),
mAllowCallingCardDrop(FALSE),
mShortNames(FALSE)
mAllowCallingCardDrop(false),
mShortNames(false),
mAvatarNameCacheConnection()
{
setToolTip(tooltip);
LLNameListCtrl::sInstances.insert(this);
}
// virtual
LLNameListCtrl::~LLNameListCtrl()
{
LLNameListCtrl::sInstances.erase(this);
}
// public
LLScrollListItem* LLNameListCtrl::addNameItem(const LLUUID& agent_id, EAddPosition pos,
BOOL enabled, const std::string& suffix)
{
//llinfos << "LLNameListCtrl::addNameItem " << agent_id << llendl;
LLSD item;
item["id"] = agent_id;
item["enabled"] = enabled;
item["target"] = INDIVIDUAL;
item["suffix"] = suffix;
LLSD& column = item["columns"][0];
column["value"] = "";
column["font"] = "SANSSERIF";
column["column"] = "name";
NameItem item;
item.value = agent_id;
item.enabled = enabled;
item.target = INDIVIDUAL;
return addNameItemRow(item, pos);
return addNameItemRow(item, pos, suffix);
}
// virtual, public
@@ -146,50 +126,52 @@ BOOL LLNameListCtrl::handleDragAndDrop(
void LLNameListCtrl::addGroupNameItem(const LLUUID& group_id, EAddPosition pos,
BOOL enabled)
{
LLSD item;
item["id"] = group_id;
item["enabled"] = enabled;
item["target"] = GROUP;
LLSD& column = item["columns"][0];
column["value"] = "";
column["font"] = "SANSSERIF";
column["column"] = "name";
NameItem item;
item.value = group_id;
item.enabled = enabled;
item.target = GROUP;
addNameItemRow(item, pos);
}
// public
void LLNameListCtrl::addGroupNameItem(LLSD& item, EAddPosition pos)
void LLNameListCtrl::addGroupNameItem(LLNameListCtrl::NameItem& item, EAddPosition pos)
{
item["target"] = GROUP;
item.target = GROUP;
addNameItemRow(item, pos);
}
LLScrollListItem* LLNameListCtrl::addNameItem(LLSD& item, EAddPosition pos)
LLScrollListItem* LLNameListCtrl::addNameItem(LLNameListCtrl::NameItem& item, EAddPosition pos)
{
item["target"] = INDIVIDUAL;
item.target = INDIVIDUAL;
return addNameItemRow(item, pos);
}
LLScrollListItem* LLNameListCtrl::addElement(const LLSD& value, EAddPosition pos, void* userdata)
LLScrollListItem* LLNameListCtrl::addElement(const LLSD& element, EAddPosition pos, void* userdata)
{
return addNameItemRow(value, pos, userdata);
LLNameListCtrl::NameItem item_params;
LLParamSDParser parser;
parser.readSD(element, item_params);
item_params.userdata = userdata;
return addNameItemRow(item_params, pos);
}
LLScrollListItem* LLNameListCtrl::addNameItemRow(const LLSD& value, EAddPosition pos, void* userdata)
{
// Singu Note: ScrollLists don't use "target" or "suffix", for now, just remove them
LLSD scroll_value = value;
scroll_value.erase("target");
scroll_value.erase("suffix");
LLScrollListItem* item = LLScrollListCtrl::addElement(scroll_value, pos, userdata);
LLScrollListItem* LLNameListCtrl::addNameItemRow(
const LLNameListCtrl::NameItem& name_item,
EAddPosition pos,
const std::string& suffix)
{
LLUUID id = name_item.value().asUUID();
LLNameListItem* item = new LLNameListItem(name_item,name_item.target() == GROUP);
if (!item) return NULL;
LLUUID id = item->getUUID();
LLScrollListCtrl::addRow(item, name_item, pos);
// use supplied name by default
std::string fullname = value["name"].asString();
switch(value["target"].asInteger())
std::string fullname = name_item.name;
switch(name_item.target)
{
case GROUP:
gCacheName->getGroupName(id, fullname);
@@ -214,11 +196,14 @@ LLScrollListItem* LLNameListCtrl::addNameItemRow(const LLSD& value, EAddPosition
}
else
{
fullname = " ( " + LLTrans::getString("LoadingData") + " ) ";
// ...schedule a callback
LLAvatarNameCache::get(id,
boost::bind(&LLNameListCtrl::onAvatarNameCache,
this, _1, _2, item->getHandle()));
// This is not correct and will likely lead to partially populated lists in cases where avatar names are not cached.
// *TODO : Change this to have 2 callbacks : one callback per list item and one for the whole list.
if (mAvatarNameCacheConnection.connected())
{
mAvatarNameCacheConnection.disconnect();
}
mAvatarNameCacheConnection = LLAvatarNameCache::get(id,boost::bind(&LLNameListCtrl::onAvatarNameCache,this, _1, _2, item->getHandle()));
}
break;
}
@@ -227,14 +212,13 @@ LLScrollListItem* LLNameListCtrl::addNameItemRow(const LLSD& value, EAddPosition
}
// Append optional suffix.
std::string suffix = value["suffix"];
if(!suffix.empty())
{
fullname.append(suffix);
}
LLScrollListCell* cell = item->getColumn(mNameColumnIndex);
if (cell && !fullname.empty() && cell->getValue().asString().empty())
if (cell)
{
cell->setValue(fullname);
}
@@ -276,15 +260,17 @@ void LLNameListCtrl::removeNameItem(const LLUUID& agent_id)
void LLNameListCtrl::onAvatarNameCache(const LLUUID& agent_id,
const LLAvatarName& av_name,
LLHandle<LLScrollListItem> item)
LLHandle<LLNameListItem> item)
{
mAvatarNameCacheConnection.disconnect();
std::string name;
if (mShortNames)
name = av_name.mDisplayName;
else
name = av_name.getCompleteName();
LLScrollListItem* list_item = item.get();
LLNameListItem* list_item = item.get();
if (list_item && list_item->getUUID() == agent_id)
{
LLScrollListCell* cell = list_item->getColumn(mNameColumnIndex);
@@ -339,13 +325,7 @@ LLView* LLNameListCtrl::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFacto
S32 name_column_index = 0;
node->getAttributeS32("name_column_index", name_column_index);
LLNameListCtrl* name_list = new LLNameListCtrl("name_list",
rect,
multi_select,
draw_border,
draw_heading,
name_column_index
);
LLNameListCtrl* name_list = new LLNameListCtrl("name_list", rect, multi_select, draw_border, draw_heading, name_column_index);
if (node->hasAttribute("heading_height"))
{
S32 heading_height;
@@ -376,7 +356,6 @@ LLView* LLNameListCtrl::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFacto
std::string columnname(labelname);
child->getAttributeString("name", columnname);
std::string sortname(columnname);
child->getAttributeString("sort", sortname);
@@ -457,6 +436,3 @@ LLView* LLNameListCtrl::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFacto
return name_list;
}