PageRenderTime 26ms CodeModel.GetById 10ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llui/llcombobox.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 265 lines | 166 code | 51 blank | 48 comment | 0 complexity | 4e48e703e4789abfea31b535c01cda26 MD5 | raw file
  1/** 
  2 * @file llcombobox.h
  3 * @brief LLComboBox base class
  4 *
  5 * $LicenseInfo:firstyear=2001&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// A control that displays the name of the chosen item, which when clicked
 28// shows a scrolling box of choices.
 29
 30#ifndef LL_LLCOMBOBOX_H
 31#define LL_LLCOMBOBOX_H
 32
 33#include "llbutton.h"
 34#include "lluictrl.h"
 35#include "llctrlselectioninterface.h"
 36#include "llrect.h"
 37#include "llscrolllistctrl.h"
 38#include "lllineeditor.h"
 39#include <boost/function.hpp>
 40
 41// Classes
 42
 43class LLFontGL;
 44class LLViewBorder;
 45
 46class LLComboBox
 47:	public LLUICtrl, public LLCtrlListInterface
 48{
 49public:	
 50	typedef enum e_preferred_position
 51	{
 52		ABOVE,
 53		BELOW
 54	} EPreferredPosition;
 55
 56	struct PreferredPositionValues : public LLInitParam::TypeValuesHelper<EPreferredPosition, PreferredPositionValues>
 57	{
 58		static void declareValues();
 59	};
 60
 61
 62	struct ItemParams : public LLInitParam::Block<ItemParams, LLScrollListItem::Params>
 63	{
 64		Optional<std::string>	label;
 65		ItemParams();
 66	};
 67
 68	struct Params 
 69	:	public LLInitParam::Block<Params, LLUICtrl::Params>
 70	{
 71		Optional<bool>						allow_text_entry,
 72											show_text_as_tentative,
 73											allow_new_values;
 74		Optional<S32>						max_chars;
 75		Optional<commit_callback_t> 		prearrange_callback,
 76											text_entry_callback,
 77											text_changed_callback;
 78
 79		Optional<EPreferredPosition, PreferredPositionValues>	list_position;
 80		
 81		// components
 82		Optional<LLButton::Params>			combo_button;
 83		Optional<LLScrollListCtrl::Params>	combo_list;
 84		Optional<LLLineEditor::Params>		combo_editor;
 85
 86		Optional<LLButton::Params>          drop_down_button;
 87
 88		Multiple<ItemParams>				items;
 89		
 90		Params();
 91	};
 92
 93
 94	virtual ~LLComboBox(); 
 95	/*virtual*/ BOOL postBuild();
 96	
 97protected:
 98	friend class LLUICtrlFactory;
 99	LLComboBox(const Params&);
100	void	initFromParams(const Params&);
101	void	prearrangeList(std::string filter = "");
102
103public:
104	// LLView interface
105	virtual void	onFocusLost();
106
107	virtual BOOL	handleToolTip(S32 x, S32 y, MASK mask);
108	virtual BOOL	handleKeyHere(KEY key, MASK mask);
109	virtual BOOL	handleUnicodeCharHere(llwchar uni_char);
110
111	// LLUICtrl interface
112	virtual void	clear();					// select nothing
113	virtual void	onCommit();
114	virtual BOOL	acceptsTextInput() const		{ return mAllowTextEntry; }
115	virtual BOOL	isDirty() const;			// Returns TRUE if the user has modified this control.
116	virtual void	resetDirty();				// Clear dirty state
117
118	virtual void	setFocus(BOOL b);
119
120	// Selects item by underlying LLSD value, using LLSD::asString() matching.  
121	// For simple items, this is just the name of the label.
122	virtual void	setValue(const LLSD& value );
123
124	// Gets underlying LLSD value for currently selected items.  For simple
125	// items, this is just the label.
126	virtual LLSD	getValue() const;
127
128	void			setTextEntry(const LLStringExplicit& text);
129
130	LLScrollListItem*	add(const std::string& name, EAddPosition pos = ADD_BOTTOM, BOOL enabled = TRUE);	// add item "name" to menu
131	LLScrollListItem*	add(const std::string& name, const LLUUID& id, EAddPosition pos = ADD_BOTTOM, BOOL enabled = TRUE);
132	LLScrollListItem*	add(const std::string& name, void* userdata, EAddPosition pos = ADD_BOTTOM, BOOL enabled = TRUE);
133	LLScrollListItem*	add(const std::string& name, LLSD value, EAddPosition pos = ADD_BOTTOM, BOOL enabled = TRUE);
134	LLScrollListItem*	addSeparator(EAddPosition pos = ADD_BOTTOM);
135	BOOL			remove( S32 index );	// remove item by index, return TRUE if found and removed
136	void			removeall() { clearRows(); }
137	bool			itemExists(const std::string& name);
138
139	void			sortByName(BOOL ascending = TRUE); // Sort the entries in the combobox by name
140
141	// Select current item by name using selectItemByLabel.  Returns FALSE if not found.
142	BOOL			setSimple(const LLStringExplicit& name);
143	// Get name of current item. Returns an empty string if not found.
144	const std::string	getSimple() const;
145	// Get contents of column x of selected row
146	virtual const std::string getSelectedItemLabel(S32 column = 0) const;
147
148	// Sets the label, which doesn't have to exist in the label.
149	// This is probably a UI abuse.
150	void			setLabel(const LLStringExplicit& name);
151
152	// Updates the combobox label to match the selected list item.
153	void			updateLabel();
154
155	BOOL			remove(const std::string& name);	// remove item "name", return TRUE if found and removed
156	
157	BOOL			setCurrentByIndex( S32 index );
158	S32				getCurrentIndex() const;
159
160	void			createLineEditor(const Params&);
161
162	//========================================================================
163	LLCtrlSelectionInterface* getSelectionInterface()	{ return (LLCtrlSelectionInterface*)this; };
164	LLCtrlListInterface* getListInterface()				{ return (LLCtrlListInterface*)this; };
165
166	// LLCtrlListInterface functions
167	// See llscrolllistctrl.h
168	virtual S32		getItemCount() const;
169	// Overwrites the default column (See LLScrollListCtrl for format)
170	virtual void 	addColumn(const LLSD& column, EAddPosition pos = ADD_BOTTOM);
171	virtual void 	clearColumns();
172	virtual void	setColumnLabel(const std::string& column, const std::string& label);
173	virtual LLScrollListItem* addElement(const LLSD& value, EAddPosition pos = ADD_BOTTOM, void* userdata = NULL);
174	virtual LLScrollListItem* addSimpleElement(const std::string& value, EAddPosition pos = ADD_BOTTOM, const LLSD& id = LLSD());
175	virtual void 	clearRows();
176	virtual void 	sortByColumn(const std::string& name, BOOL ascending);
177
178	// LLCtrlSelectionInterface functions
179	virtual BOOL	getCanSelect() const				{ return TRUE; }
180	virtual BOOL	selectFirstItem()					{ return setCurrentByIndex(0); }
181	virtual BOOL	selectNthItem( S32 index )			{ return setCurrentByIndex(index); }
182	virtual BOOL	selectItemRange( S32 first, S32 last );
183	virtual S32		getFirstSelectedIndex() const		{ return getCurrentIndex(); }
184	virtual BOOL	setCurrentByID( const LLUUID& id );
185	virtual LLUUID	getCurrentID() const;				// LLUUID::null if no items in menu
186	virtual BOOL	setSelectedByValue(const LLSD& value, BOOL selected);
187	virtual LLSD	getSelectedValue();
188	virtual BOOL	isSelected(const LLSD& value) const;
189	virtual BOOL	operateOnSelection(EOperation op);
190	virtual BOOL	operateOnAll(EOperation op);
191
192	//========================================================================
193	
194	void*			getCurrentUserdata();
195
196	void			setPrearrangeCallback( commit_callback_t cb ) { mPrearrangeCallback = cb; }
197	void			setTextEntryCallback( commit_callback_t cb ) { mTextEntryCallback = cb; }
198	void			setTextChangedCallback( commit_callback_t cb ) { mTextChangedCallback = cb; }
199
200	void			setButtonVisible(BOOL visible);
201
202	void			onButtonMouseDown();
203	void			onListMouseUp();
204	void			onItemSelected(const LLSD& data);
205	void			onTextCommit(const LLSD& data);
206
207	void			updateSelection();
208	virtual void	showList();
209	virtual void	hideList();
210	
211	virtual void	onTextEntry(LLLineEditor* line_editor);
212	
213protected:
214	LLButton*			mButton;
215	LLLineEditor*		mTextEntry;
216	LLScrollListCtrl*	mList;
217	EPreferredPosition	mListPosition;
218	LLPointer<LLUIImage>	mArrowImage;
219	LLUIString			mLabel;
220	BOOL				mHasAutocompletedText;
221
222private:
223	BOOL				mAllowTextEntry;
224	BOOL				mAllowNewValues;
225	S32					mMaxChars;
226	BOOL				mTextEntryTentative;
227	commit_callback_t	mPrearrangeCallback;
228	commit_callback_t	mTextEntryCallback;
229	commit_callback_t	mTextChangedCallback;
230	commit_callback_t	mSelectionCallback;
231	boost::signals2::connection mTopLostSignalConnection;
232	S32                 mLastSelectedIndex;
233};
234
235// A combo box with icons for the list of items.
236class LLIconsComboBox
237:	public LLComboBox
238{
239public:
240	struct Params
241	:	public LLInitParam::Block<Params, LLComboBox::Params>
242	{
243		Optional<S32>		icon_column,
244							label_column;
245		Params();
246	};
247
248	/*virtual*/ const std::string getSelectedItemLabel(S32 column = 0) const;
249
250private:
251	enum EColumnIndex
252	{
253		ICON_COLUMN = 0,
254		LABEL_COLUMN
255	};
256
257	friend class LLUICtrlFactory;
258	LLIconsComboBox(const Params&);
259	virtual ~LLIconsComboBox() {};
260
261	S32			mIconColumnIndex;
262	S32			mLabelColumnIndex;
263};
264
265#endif