PageRenderTime 16ms CodeModel.GetById 2ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 1ms

/indra/newview/llnamelistctrl.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 147 lines | 86 code | 24 blank | 37 comment | 0 complexity | 073cd386aed3a8f19fb0fffdfa5be699 MD5 | raw file
  1/**
  2 * @file llnamelistctrl.h
  3 * @brief A list of names, automatically refreshing from the name cache.
  4 *
  5 * $LicenseInfo:firstyear=2003&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 *
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 *
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 *
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 *
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#ifndef LL_LLNAMELISTCTRL_H
 28#define LL_LLNAMELISTCTRL_H
 29
 30#include <set>
 31
 32#include "llscrolllistctrl.h"
 33
 34class LLAvatarName;
 35
 36class LLNameListCtrl
 37:	public LLScrollListCtrl, public LLInstanceTracker<LLNameListCtrl>
 38{
 39public:
 40	typedef enum e_name_type
 41	{
 42		INDIVIDUAL,
 43		GROUP,
 44		SPECIAL
 45	} ENameType;
 46
 47	// provide names for enums
 48	struct NameTypeNames : public LLInitParam::TypeValuesHelper<LLNameListCtrl::ENameType, NameTypeNames>
 49	{
 50		static void declareValues();
 51	};
 52
 53	struct NameItem : public LLInitParam::Block<NameItem, LLScrollListItem::Params>
 54	{
 55		Optional<std::string>				name;
 56		Optional<ENameType, NameTypeNames>	target;
 57
 58		NameItem()
 59		:	name("name"),
 60			target("target", INDIVIDUAL)
 61		{}
 62	};
 63
 64	struct NameColumn : public LLInitParam::ChoiceBlock<NameColumn>
 65	{
 66		Alternative<S32>				column_index;
 67		Alternative<std::string>		column_name;
 68		NameColumn()
 69		:	column_name("name_column"),
 70			column_index("name_column_index", 0)
 71		{}
 72	};
 73
 74	struct Params : public LLInitParam::Block<Params, LLScrollListCtrl::Params>
 75	{
 76		Optional<NameColumn>	name_column;
 77		Optional<bool>	allow_calling_card_drop;
 78		Optional<bool>			short_names;
 79		Params();
 80	};
 81
 82protected:
 83	LLNameListCtrl(const Params&);
 84	friend class LLUICtrlFactory;
 85public:
 86	// Add a user to the list by name.  It will be added, the name
 87	// requested from the cache, and updated as necessary.
 88	void addNameItem(const LLUUID& agent_id, EAddPosition pos = ADD_BOTTOM,
 89					 BOOL enabled = TRUE, const std::string& suffix = LLStringUtil::null);
 90	void addNameItem(NameItem& item, EAddPosition pos = ADD_BOTTOM);
 91
 92	/*virtual*/ LLScrollListItem* addElement(const LLSD& element, EAddPosition pos = ADD_BOTTOM, void* userdata = NULL);
 93	LLScrollListItem* addNameItemRow(const NameItem& value, EAddPosition pos = ADD_BOTTOM, const std::string& suffix = LLStringUtil::null);
 94
 95	// Add a user to the list by name.  It will be added, the name
 96	// requested from the cache, and updated as necessary.
 97	void addGroupNameItem(const LLUUID& group_id, EAddPosition pos = ADD_BOTTOM,
 98						  BOOL enabled = TRUE);
 99	void addGroupNameItem(NameItem& item, EAddPosition pos = ADD_BOTTOM);
100
101
102	void removeNameItem(const LLUUID& agent_id);
103
104	// LLView interface
105	/*virtual*/ BOOL	handleDragAndDrop(S32 x, S32 y, MASK mask,
106									  BOOL drop, EDragAndDropType cargo_type, void *cargo_data,
107									  EAcceptance *accept,
108									  std::string& tooltip_msg);
109	/*virtual*/ BOOL handleToolTip(S32 x, S32 y, MASK mask);
110
111	void setAllowCallingCardDrop(BOOL b) { mAllowCallingCardDrop = b; }
112
113	/*virtual*/ void updateColumns();
114
115	/*virtual*/ void	mouseOverHighlightNthItem( S32 index );
116private:
117	void showInspector(const LLUUID& avatar_id, bool is_group);
118	void onAvatarNameCache(const LLUUID& agent_id, const LLAvatarName& av_name);
119
120private:
121	S32    			mNameColumnIndex;
122	std::string		mNameColumn;
123	BOOL			mAllowCallingCardDrop;
124	bool			mShortNames;  // display name only, no SLID
125};
126
127/**
128 * LLNameListCtrl item
129 *
130 * We don't use LLScrollListItem to be able to override getUUID(), which is needed
131 * because the name list item value is not simply an UUID but a map (uuid, is_group).
132 */
133class LLNameListItem : public LLScrollListItem
134{
135public:
136	LLUUID	getUUID() const		{ return getValue()["uuid"].asUUID(); }
137
138protected:
139	friend class LLNameListCtrl;
140
141	LLNameListItem( const LLScrollListItem::Params& p )
142	:	LLScrollListItem(p)
143	{
144	}
145};
146
147#endif