PageRenderTime 76ms CodeModel.GetById 19ms app.highlight 51ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llui/llpanel.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 349 lines | 208 code | 76 blank | 65 comment | 3 complexity | 2618ae9c4b4cdda85bff3a48b9db40b1 MD5 | raw file
  1/** 
  2 * @file llpanel.h
  3 * @author James Cook, Tom Yedwab
  4 * @brief LLPanel base class
  5 *
  6 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  7 * Second Life Viewer Source Code
  8 * Copyright (C) 2010, Linden Research, Inc.
  9 * 
 10 * This library is free software; you can redistribute it and/or
 11 * modify it under the terms of the GNU Lesser General Public
 12 * License as published by the Free Software Foundation;
 13 * version 2.1 of the License only.
 14 * 
 15 * This library is distributed in the hope that it will be useful,
 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 18 * Lesser General Public License for more details.
 19 * 
 20 * You should have received a copy of the GNU Lesser General Public
 21 * License along with this library; if not, write to the Free Software
 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 23 * 
 24 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 25 * $/LicenseInfo$
 26 */
 27
 28#ifndef LL_LLPANEL_H
 29#define LL_LLPANEL_H
 30
 31
 32#include "llcallbackmap.h"
 33#include "lluictrl.h"
 34#include "llviewborder.h"
 35#include "lluiimage.h"
 36#include "lluistring.h"
 37#include "v4color.h"
 38#include "llbadgeholder.h"
 39#include <list>
 40#include <queue>
 41
 42const S32 LLPANEL_BORDER_WIDTH = 1;
 43const BOOL BORDER_YES = TRUE;
 44const BOOL BORDER_NO = FALSE;
 45
 46class LLButton;
 47class LLUIImage;
 48
 49/*
 50 * General purpose concrete view base class.
 51 * Transparent or opaque,
 52 * With or without border,
 53 * Can contain LLUICtrls.
 54 */
 55class LLPanel : public LLUICtrl, public LLBadgeHolder
 56{
 57public:
 58	struct LocalizedString : public LLInitParam::Block<LocalizedString>
 59	{
 60		Mandatory<std::string>	name;
 61		Mandatory<std::string>	value;
 62		
 63		LocalizedString();
 64	};
 65
 66	struct Params 
 67	:	public LLInitParam::Block<Params, LLUICtrl::Params>
 68	{
 69		Optional<bool>			has_border;
 70		Optional<LLViewBorder::Params>	border;
 71
 72		Optional<bool>			background_visible,
 73								background_opaque;
 74
 75		Optional<LLUIColor>		bg_opaque_color,
 76								bg_alpha_color,
 77								bg_opaque_image_overlay,
 78								bg_alpha_image_overlay;
 79		// opaque image is for "panel in foreground" look
 80		Optional<LLUIImage*>	bg_opaque_image,
 81								bg_alpha_image;
 82
 83		Optional<S32>			min_width,
 84								min_height;
 85
 86		Optional<std::string>	filename;
 87		Optional<std::string>	class_name;
 88		Optional<std::string>   help_topic;
 89
 90		Multiple<LocalizedString>	strings;
 91		
 92		Optional<CommitCallbackParam> visible_callback;
 93
 94		Optional<bool>			accepts_badge;
 95		
 96		Params();
 97	};
 98
 99protected:
100	friend class LLUICtrlFactory;
101	// RN: for some reason you can't just use LLUICtrlFactory::getDefaultParams as a default argument in VC8
102	static const LLPanel::Params& getDefaultParams();
103
104	// Panels can get constructed directly
105	LLPanel(const LLPanel::Params& params = getDefaultParams());
106	
107public:
108	BOOL buildFromFile(const std::string &filename, LLXMLNodePtr output_node = NULL, const LLPanel::Params&default_params = getDefaultParams());
109
110	static LLPanel* createFactoryPanel(const std::string& name);
111
112	/*virtual*/ ~LLPanel();
113
114	// LLView interface
115	/*virtual*/ BOOL 	isPanel() const;
116	/*virtual*/ void	draw();	
117	/*virtual*/ BOOL	handleKeyHere( KEY key, MASK mask );
118	/*virtual*/ void 	handleVisibilityChange ( BOOL new_visibility );
119
120	// From LLFocusableElement
121	/*virtual*/ void	setFocus( BOOL b );
122	
123	// New virtuals
124	virtual 	void	refresh();	// called in setFocus()
125	virtual 	void	clearCtrls(); // overridden in LLPanelObject and LLPanelVolume
126
127	// Border controls
128	void addBorder( LLViewBorder::Params p);
129	void addBorder();
130	void			removeBorder();
131	BOOL			hasBorder() const { return mBorder != NULL; }
132	void			setBorderVisible( BOOL b );
133
134	void			setBackgroundColor( const LLColor4& color ) { mBgOpaqueColor = color; }
135	const LLColor4&	getBackgroundColor() const { return mBgOpaqueColor; }
136	void			setTransparentColor(const LLColor4& color) { mBgAlphaColor = color; }
137	const LLColor4& getTransparentColor() const { return mBgAlphaColor; }
138	void			setBackgroundImage(LLUIImage* image) { mBgOpaqueImage = image; }
139	void			setTransparentImage(LLUIImage* image) { mBgAlphaImage = image; }
140	LLPointer<LLUIImage> getBackgroundImage() const { return mBgOpaqueImage; }
141	LLPointer<LLUIImage> getTransparentImage() const { return mBgAlphaImage; }
142	LLColor4		getBackgroundImageOverlay() { return mBgOpaqueImageOverlay; }
143	LLColor4		getTransparentImageOverlay() { return mBgAlphaImageOverlay; }
144	void			setBackgroundVisible( BOOL b )	{ mBgVisible = b; }
145	BOOL			isBackgroundVisible() const { return mBgVisible; }
146	void			setBackgroundOpaque(BOOL b)		{ mBgOpaque = b; }
147	BOOL			isBackgroundOpaque() const { return mBgOpaque; }
148	void			setDefaultBtn(LLButton* btn = NULL);
149	void			setDefaultBtn(const std::string& id);
150	void			updateDefaultBtn();
151	void			setLabel(const LLStringExplicit& label) { mLabel = label; }
152	std::string		getLabel() const { return mLabel; }
153	void			setHelpTopic(const std::string& help_topic) { mHelpTopic = help_topic; }
154	std::string		getHelpTopic() const { return mHelpTopic; }
155	
156	void			setCtrlsEnabled(BOOL b);
157
158	LLHandle<LLPanel>	getHandle() const { return getDerivedHandle<LLPanel>(); }
159
160	const LLCallbackMap::map_t& getFactoryMap() const { return mFactoryMap; }
161	
162	CommitCallbackRegistry::ScopedRegistrar& getCommitCallbackRegistrar() { return mCommitCallbackRegistrar; }
163	EnableCallbackRegistry::ScopedRegistrar& getEnableCallbackRegistrar() { return mEnableCallbackRegistrar; }
164	
165	void initFromParams(const Params& p);
166	BOOL initPanelXML(	LLXMLNodePtr node, LLView *parent, LLXMLNodePtr output_node, const LLPanel::Params& default_params);
167	
168	bool hasString(const std::string& name);
169	std::string getString(const std::string& name, const LLStringUtil::format_map_t& args) const;
170	std::string getString(const std::string& name) const;
171
172	// ** Wrappers for setting child properties by name ** -TomY
173	// WARNING: These are deprecated, please use getChild<T>("name")->doStuff() idiom instead
174
175	// LLView
176	void childSetVisible(const std::string& name, bool visible);
177	void childShow(const std::string& name) { childSetVisible(name, true); }
178	void childHide(const std::string& name) { childSetVisible(name, false); }
179	bool childIsVisible(const std::string& id) const;
180	void childSetTentative(const std::string& name, bool tentative);
181
182	void childSetEnabled(const std::string& name, bool enabled);
183	void childEnable(const std::string& name)	{ childSetEnabled(name, true); }
184	void childDisable(const std::string& name) { childSetEnabled(name, false); };
185	bool childIsEnabled(const std::string& id) const;
186
187	void childSetToolTip(const std::string& id, const std::string& msg);
188	void childSetRect(const std::string& id, const LLRect &rect);
189	bool childGetRect(const std::string& id, LLRect& rect) const;
190
191	// LLUICtrl
192	void childSetFocus(const std::string& id, BOOL focus = TRUE);
193	BOOL childHasFocus(const std::string& id);
194	
195	// *TODO: Deprecate; for backwards compatability only:
196	// Prefer getChild<LLUICtrl>("foo")->setCommitCallback(boost:bind(...)),
197	// which takes a generic slot.  Or use mCommitCallbackRegistrar.add() with
198	// a named callback and reference it in XML.
199	void childSetCommitCallback(const std::string& id, boost::function<void (LLUICtrl*,void*)> cb, void* data);	
200	
201	void childSetValidate(const std::string& id, boost::function<bool (const LLSD& data)> cb );
202
203	void childSetColor(const std::string& id, const LLColor4& color);
204
205	LLCtrlSelectionInterface* childGetSelectionInterface(const std::string& id) const;
206	LLCtrlListInterface* childGetListInterface(const std::string& id) const;
207	LLCtrlScrollInterface* childGetScrollInterface(const std::string& id) const;
208
209	// This is the magic bullet for data-driven UI
210	void childSetValue(const std::string& id, LLSD value);
211	LLSD childGetValue(const std::string& id) const;
212
213	// For setting text / label replacement params, e.g. "Hello [NAME]"
214	// Not implemented for all types, defaults to noop, returns FALSE if not applicaple
215	BOOL childSetTextArg(const std::string& id, const std::string& key, const LLStringExplicit& text);
216	BOOL childSetLabelArg(const std::string& id, const std::string& key, const LLStringExplicit& text);
217	BOOL childSetToolTipArg(const std::string& id, const std::string& key, const LLStringExplicit& text);
218	
219	// LLTabContainer
220	void childShowTab(const std::string& id, const std::string& tabname, bool visible = true);
221	LLPanel *childGetVisibleTab(const std::string& id) const;
222
223	// Find a child with a nonempty Help topic 
224	LLPanel *childGetVisibleTabWithHelp();
225	LLPanel *childGetVisiblePanelWithHelp();
226
227	// LLTextBox/LLTextEditor/LLLineEditor
228	void childSetText(const std::string& id, const LLStringExplicit& text) { childSetValue(id, LLSD(text)); }
229
230	// *NOTE: Does not return text from <string> tags, use getString()
231	std::string childGetText(const std::string& id) const { return childGetValue(id).asString(); }
232
233	// LLLineEditor
234	void childSetPrevalidate(const std::string& id, bool (*func)(const LLWString &) );
235
236	// LLButton
237	void childSetAction(const std::string& id, boost::function<void(void*)> function, void* value);
238	void childSetAction(const std::string& id, const commit_signal_t::slot_type& function);
239
240	// LLTextBox
241	void childSetActionTextbox(const std::string& id, boost::function<void(void*)> function, void* value = NULL);
242
243	void childSetControlName(const std::string& id, const std::string& control_name);
244
245	static LLView*	fromXML(LLXMLNodePtr node, LLView *parent, LLXMLNodePtr output_node = NULL);
246
247	//call onOpen to let panel know when it's about to be shown or activated
248	virtual void	onOpen(const LLSD& key) {}
249
250	void setXMLFilename(std::string filename) { mXMLFilename = filename; };
251	std::string getXMLFilename() { return mXMLFilename; };
252	
253	boost::signals2::connection setVisibleCallback( const commit_signal_t::slot_type& cb );
254
255protected:
256	// Override to set not found list
257	LLButton*		getDefaultButton() { return mDefaultBtn; }
258	LLCallbackMap::map_t mFactoryMap;
259	CommitCallbackRegistry::ScopedRegistrar mCommitCallbackRegistrar;
260	EnableCallbackRegistry::ScopedRegistrar mEnableCallbackRegistrar;
261
262	commit_signal_t* mVisibleSignal;		// Called when visibility changes, passes new visibility as LLSD()
263
264	std::string		mHelpTopic;         // the name of this panel's help topic to display in the Help Viewer
265	typedef std::deque<const LLCallbackMap::map_t*> factory_stack_t;
266	static factory_stack_t	sFactoryStack;
267
268	// for setting the xml filename when building panel in context dependent cases
269	std::string		mXMLFilename;
270	
271private:
272	BOOL			mBgVisible;				// any background at all?
273	BOOL			mBgOpaque;				// use opaque color or image
274	LLUIColor		mBgOpaqueColor;
275	LLUIColor		mBgAlphaColor;
276	LLUIColor		mBgOpaqueImageOverlay;
277	LLUIColor		mBgAlphaImageOverlay;
278	LLPointer<LLUIImage> mBgOpaqueImage;	// "panel in front" look
279	LLPointer<LLUIImage> mBgAlphaImage;		// "panel in back" look
280	LLViewBorder*	mBorder;
281	LLButton*		mDefaultBtn;
282	LLUIString		mLabel;
283
284	typedef std::map<std::string, std::string> ui_string_map_t;
285	ui_string_map_t	mUIStrings;
286
287
288}; // end class LLPanel
289
290// Build time optimization, generate once in .cpp file
291#ifndef LLPANEL_CPP
292extern template class LLPanel* LLView::getChild<class LLPanel>(
293	const std::string& name, BOOL recurse) const;
294#endif
295
296typedef boost::function<LLPanel* (void)> LLPanelClassCreatorFunc;
297
298// local static instance for registering a particular panel class
299
300class LLRegisterPanelClass
301:	public LLSingleton< LLRegisterPanelClass >
302{
303public:
304	// reigister with either the provided builder, or the generic templated builder
305	void addPanelClass(const std::string& tag,LLPanelClassCreatorFunc func)
306	{
307		mPanelClassesNames[tag] = func;
308	}
309
310	LLPanel* createPanelClass(const std::string& tag)
311	{
312		param_name_map_t::iterator iT =  mPanelClassesNames.find(tag);
313		if(iT == mPanelClassesNames.end())
314			return 0;
315		return iT->second();
316	}
317	template<typename T>
318	static T* defaultPanelClassBuilder()
319	{
320		T* pT = new T();
321		return pT;
322	}
323
324private:
325	typedef std::map< std::string, LLPanelClassCreatorFunc> param_name_map_t;
326	
327	param_name_map_t mPanelClassesNames;
328};
329
330
331// local static instance for registering a particular panel class
332template<typename T>
333class LLRegisterPanelClassWrapper
334:	public LLRegisterPanelClass
335{
336public:
337	// reigister with either the provided builder, or the generic templated builder
338	LLRegisterPanelClassWrapper(const std::string& tag);
339};
340
341
342template<typename T>
343LLRegisterPanelClassWrapper<T>::LLRegisterPanelClassWrapper(const std::string& tag) 
344{
345	LLRegisterPanelClass::instance().addPanelClass(tag,&LLRegisterPanelClass::defaultPanelClassBuilder<T>);
346}
347
348
349#endif