PageRenderTime 55ms CodeModel.GetById 45ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llui/llfloaterreg.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 153 lines | 78 code | 26 blank | 49 comment | 0 complexity | d50d6daa7bbd67d1bd4ee8fcc83ca8f9 MD5 | raw file
  1/** 
  2 * @file llfloaterreg.h
  3 * @brief LLFloaterReg Floater Registration Class
  4 *
  5 * $LicenseInfo:firstyear=2002&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#ifndef LLFLOATERREG_H
 27#define LLFLOATERREG_H
 28
 29/// llcommon
 30#include "llrect.h"
 31#include "llsd.h"
 32
 33#include <boost/function.hpp>
 34
 35//*******************************************************
 36//
 37// Floater Class Registry
 38//
 39
 40class LLFloater;
 41class LLUICtrl;
 42
 43typedef boost::function<LLFloater* (const LLSD& key)> LLFloaterBuildFunc;
 44
 45class LLFloaterReg
 46{
 47public:
 48	// We use a list of LLFloater's instead of a set for two reasons:
 49	// 1) With a list we have a predictable ordering, useful for finding the last opened floater of a given type.
 50	// 2) We can change the key of a floater without altering the list.
 51	typedef std::list<LLFloater*> instance_list_t;
 52	typedef const instance_list_t const_instance_list_t;
 53	typedef std::map<std::string, instance_list_t> instance_map_t;
 54
 55	struct BuildData
 56	{
 57		LLFloaterBuildFunc mFunc;
 58		std::string mFile;
 59	};
 60	typedef std::map<std::string, BuildData> build_map_t;
 61	
 62private:
 63	friend class LLFloaterRegListener;
 64	static instance_list_t sNullInstanceList;
 65	static instance_map_t sInstanceMap;
 66	static build_map_t sBuildMap;
 67	static std::map<std::string,std::string> sGroupMap;
 68	static bool sBlockShowFloaters;
 69	/**
 70	 * Defines list of floater names that can be shown despite state of sBlockShowFloaters.
 71	 */
 72	static std::set<std::string> sAlwaysShowableList;
 73	
 74public:
 75	// Registration
 76	
 77	// usage: LLFloaterClassRegistry::add("foo", (LLFloaterBuildFunc)&LLFloaterClassRegistry::build<LLFloaterFoo>);
 78	template <class T>
 79	static LLFloater* build(const LLSD& key)
 80	{
 81		T* floater = new T(key);
 82		return floater;
 83	}
 84	
 85	static void add(const std::string& name, const std::string& file, const LLFloaterBuildFunc& func,
 86					const std::string& groupname = LLStringUtil::null);
 87
 88	// Helpers
 89	static LLFloater* getLastFloaterInGroup(const std::string& name);
 90	static LLFloater* getLastFloaterCascading();
 91	
 92	// Find / get (create) / remove / destroy
 93	static LLFloater* findInstance(const std::string& name, const LLSD& key = LLSD());
 94	static LLFloater* getInstance(const std::string& name, const LLSD& key = LLSD());
 95	static LLFloater* removeInstance(const std::string& name, const LLSD& key = LLSD());
 96	static bool destroyInstance(const std::string& name, const LLSD& key = LLSD());
 97	
 98	// Iterators
 99	static const_instance_list_t& getFloaterList(const std::string& name);
100
101	// Visibility Management
102	// return NULL if instance not found or can't create instance (no builder)
103	static LLFloater* showInstance(const std::string& name, const LLSD& key = LLSD(), BOOL focus = FALSE);
104	// Close a floater (may destroy or set invisible)
105	// return false if can't find instance
106	static bool hideInstance(const std::string& name, const LLSD& key = LLSD());
107	// return true if instance is visible:
108	static bool toggleInstance(const std::string& name, const LLSD& key = LLSD());
109	static bool instanceVisible(const std::string& name, const LLSD& key = LLSD());
110
111	static void showInitialVisibleInstances();
112	static void hideVisibleInstances(const std::set<std::string>& exceptions = std::set<std::string>());
113	static void restoreVisibleInstances();
114
115	// Control Variables
116	static std::string getRectControlName(const std::string& name);
117	static std::string declareRectControl(const std::string& name);
118	static std::string getVisibilityControlName(const std::string& name);
119	static std::string declareVisibilityControl(const std::string& name);
120
121	static std::string declareDockStateControl(const std::string& name);
122	static std::string getDockStateControlName(const std::string& name);
123
124	static void registerControlVariables();
125
126	// Callback wrappers
127	static void toggleInstanceOrBringToFront(const LLSD& sdname, const LLSD& key = LLSD());
128	
129	// Typed find / get / show
130	template <class T>
131	static T* findTypedInstance(const std::string& name, const LLSD& key = LLSD())
132	{
133		return dynamic_cast<T*>(findInstance(name, key));
134	}
135
136	template <class T>
137	static T* getTypedInstance(const std::string& name, const LLSD& key = LLSD())
138	{
139		return dynamic_cast<T*>(getInstance(name, key));
140	}
141
142	template <class T>
143	static T* showTypedInstance(const std::string& name, const LLSD& key = LLSD(), BOOL focus = FALSE)
144	{
145		return dynamic_cast<T*>(showInstance(name, key, focus));
146	}
147
148	static void blockShowFloaters(bool value) { sBlockShowFloaters = value;}
149	
150	static U32 getVisibleFloaterInstanceCount();
151};
152
153#endif