summaryrefslogtreecommitdiff
path: root/indra/llui/lluictrlfactory.h
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llui/lluictrlfactory.h')
-rw-r--r--indra/llui/lluictrlfactory.h203
1 files changed, 52 insertions, 151 deletions
diff --git a/indra/llui/lluictrlfactory.h b/indra/llui/lluictrlfactory.h
index dc43b311a7..6b5d055b78 100644
--- a/indra/llui/lluictrlfactory.h
+++ b/indra/llui/lluictrlfactory.h
@@ -33,24 +33,13 @@
#ifndef LLUICTRLFACTORY_H
#define LLUICTRLFACTORY_H
-#include "llcallbackmap.h"
+#include "llfasttimer.h"
#include "llinitparam.h"
#include "llregistry.h"
-#include "v4color.h"
-#include "llfasttimer.h"
-
#include "llxuiparser.h"
-#include <boost/function.hpp>
-#include <iosfwd>
-#include <stack>
-#include <set>
-
-class LLPanel;
-class LLFloater;
class LLView;
-
// sort functor for typeid maps
struct LLCompareTypeID
{
@@ -91,12 +80,6 @@ class LLWidgetNameRegistry
: public LLRegistrySingleton<const std::type_info*, std::string, LLWidgetNameRegistry , LLCompareTypeID>
{};
-// lookup factory functions for default widget instances by widget type
-typedef LLView* (*dummy_widget_creator_func_t)(const std::string&);
-class LLDefaultWidgetRegistry
-: public LLRegistrySingleton<const std::type_info*, dummy_widget_creator_func_t, LLDefaultWidgetRegistry, LLCompareTypeID>
-{};
-
// lookup function for generating empty param block by widget type
// this is used for schema generation
//typedef const LLInitParam::BaseBlock& (*empty_param_block_func_t)();
@@ -163,58 +146,21 @@ public:
return ParamDefaults<typename T::Params, 0>::instance().get();
}
- bool buildFloater(LLFloater* floaterp, const std::string &filename, LLXMLNodePtr output_node);
- BOOL buildPanel(LLPanel* panelp, const std::string &filename, LLXMLNodePtr output_node = NULL);
-
// Does what you want for LLFloaters and LLPanels
// Returns 0 on success
S32 saveToXML(LLView* viewp, const std::string& filename);
+ // filename tracking for debugging info
std::string getCurFileName();
void pushFileName(const std::string& name);
void popFileName();
- static BOOL getAttributeColor(LLXMLNodePtr node, const std::string& name, LLColor4& color);
-
- LLPanel* createFactoryPanel(const std::string& name);
-
- void pushFactoryFunctions(const LLCallbackMap::map_t* map);
- void popFactoryFunctions();
-
- template<typename T>
- static T* createWidget(const typename T::Params& params, LLView* parent = NULL)
- {
- T* widget = NULL;
-
- if (!params.validateBlock())
- {
- llwarns << getInstance()->getCurFileName() << ": Invalid parameter block for " << typeid(T).name() << llendl;
- //return NULL;
- }
-
- {
- LLFastTimer timer(FTM_WIDGET_CONSTRUCTION);
- widget = new T(params);
- }
- {
- LLFastTimer timer(FTM_INIT_FROM_PARAMS);
- widget->initFromParams(params);
- }
-
- if (parent)
- {
- S32 tab_group = params.tab_group.isProvided() ? params.tab_group() : S32_MAX;
- setCtrlParent(widget, parent, tab_group);
- }
- return widget;
- }
-
template<typename T>
static T* create(typename T::Params& params, LLView* parent = NULL)
{
params.fillFrom(ParamDefaults<typename T::Params, 0>::instance().get());
- T* widget = createWidget<T>(params, parent);
+ T* widget = createWidgetImpl<T>(params, parent);
if (widget)
{
widget->postBuild();
@@ -272,21 +218,54 @@ fail:
template<class T>
static T* getDefaultWidget(const std::string& name)
{
- dummy_widget_creator_func_t* dummy_func = getDefaultWidgetFunc(&typeid(T));
- return dummy_func ? dynamic_cast<T*>((*dummy_func)(name)) : NULL;
+ typename T::Params widget_params;
+ widget_params.name = name;
+ return create<T>(widget_params);
}
- template <class T>
- static LLView* createDefaultWidget(const std::string& name)
- {
- typename T::Params params;
- params.name(name);
-
- return create<T>(params);
- }
+ static void createChildren(LLView* viewp, LLXMLNodePtr node, const widget_registry_t&, LLXMLNodePtr output_node = NULL);
+
+ static bool getLayeredXMLNode(const std::string &filename, LLXMLNodePtr& root);
+ static bool getLocalizedXMLNode(const std::string &xui_filename, LLXMLNodePtr& root);
+
+private:
+ //NOTE: both friend declarations are necessary to keep both gcc and msvc happy
+ template <typename T> friend class LLChildRegistry;
+ template <typename T> template <typename U> friend class LLChildRegistry<T>::Register;
static void copyName(LLXMLNodePtr src, LLXMLNodePtr dest);
+ // helper function for adding widget type info to various registries
+ static void registerWidget(const std::type_info* widget_type, const std::type_info* param_block_type, const std::string& tag);
+
+ static void loadWidgetTemplate(const std::string& widget_tag, LLInitParam::BaseBlock& block);
+
+ template<typename T>
+ static T* createWidgetImpl(const typename T::Params& params, LLView* parent = NULL)
+ {
+ T* widget = NULL;
+
+ if (!params.validateBlock())
+ {
+ llwarns << getInstance()->getCurFileName() << ": Invalid parameter block for " << typeid(T).name() << llendl;
+ //return NULL;
+ }
+
+ { LLFastTimer _(FTM_WIDGET_CONSTRUCTION);
+ widget = new T(params);
+ }
+ { LLFastTimer _(FTM_INIT_FROM_PARAMS);
+ widget->initFromParams(params);
+ }
+
+ if (parent)
+ {
+ S32 tab_group = params.tab_group.isProvided() ? params.tab_group() : S32_MAX;
+ setCtrlParent(widget, parent, tab_group);
+ }
+ return widget;
+ }
+
template<typename T>
static T* defaultBuilder(LLXMLNodePtr node, LLView *parent, LLXMLNodePtr output_node)
{
@@ -294,7 +273,8 @@ fail:
typename T::Params params(getDefaultParams<T>());
- LLXUIParser::instance().readXUI(node, params, LLUICtrlFactory::getInstance()->getCurFileName());
+ LLXUIParser parser;
+ parser.readXUI(node, params, LLUICtrlFactory::getInstance()->getCurFileName());
if (output_node)
{
@@ -304,14 +284,13 @@ fail:
// Export only the differences between this any default params
typename T::Params default_params(getDefaultParams<T>());
copyName(node, output_node);
- LLXUIParser::instance().writeXUI(
- output_node, output_params, &default_params);
+ parser.writeXUI(output_node, output_params, &default_params);
}
// Apply layout transformations, usually munging rect
params.from_xui = true;
T::applyXUILayout(params, parent);
- T* widget = createWidget<T>(params, parent);
+ T* widget = createWidgetImpl<T>(params, parent);
typedef typename T::child_registry_t registry_t;
@@ -326,20 +305,6 @@ fail:
return widget;
}
- static void createChildren(LLView* viewp, LLXMLNodePtr node, const widget_registry_t&, LLXMLNodePtr output_node = NULL);
-
- static bool getLayeredXMLNode(const std::string &filename, LLXMLNodePtr& root);
-
- static bool getLocalizedXMLNode(const std::string &xui_filename, LLXMLNodePtr& root);
-
- static void loadWidgetTemplate(const std::string& widget_tag, LLInitParam::BaseBlock& block);
-
- // helper function for adding widget type info to various registries
- static void registerWidget(const std::type_info* widget_type, const std::type_info* param_block_type, dummy_widget_creator_func_t creator_func, const std::string& tag);
-
-private:
- // return default widget instance factory func for a given type
- static dummy_widget_creator_func_t* getDefaultWidgetFunc(const std::type_info* widget_type);
static const std::string* getWidgetTag(const std::type_info* widget_type);
@@ -349,20 +314,10 @@ private:
// Avoid directly using LLUI and LLDir in the template code
static std::string findSkinnedFilename(const std::string& filename);
- typedef std::deque<const LLCallbackMap::map_t*> factory_stack_t;
- factory_stack_t mFactoryStack;
-
- LLPanel* mDummyPanel;
+ class LLPanel* mDummyPanel;
std::vector<std::string> mFileNames;
};
-template<typename T>
-const LLInitParam::BaseBlock& getEmptyParamBlock()
-{
- static typename T::Params params;
- return params;
-}
-
// this is here to make gcc happy with reference to LLUICtrlFactory
template<typename DERIVED>
template<typename T>
@@ -370,7 +325,7 @@ LLChildRegistry<DERIVED>::Register<T>::Register(const char* tag, LLWidgetCreator
: LLChildRegistry<DERIVED>::StaticRegistrar(tag, func.empty() ? (LLWidgetCreatorFunc)&LLUICtrlFactory::defaultBuilder<T> : func)
{
// add this widget to various registries
- LLUICtrlFactory::instance().registerWidget(&typeid(T), &typeid(typename T::Params), &LLUICtrlFactory::createDefaultWidget<T>, tag);
+ LLUICtrlFactory::instance().registerWidget(&typeid(T), &typeid(typename T::Params), tag);
// since registry_t depends on T, do this in line here
// TODO: uncomment this for schema generation
@@ -378,58 +333,4 @@ LLChildRegistry<DERIVED>::Register<T>::Register(const char* tag, LLWidgetCreator
//LLChildRegistryRegistry::instance().defaultRegistrar().add(&typeid(T), registry_t::instance());
}
-
-typedef boost::function<LLPanel* (void)> LLPanelClassCreatorFunc;
-
-// local static instance for registering a particular panel class
-
-class LLRegisterPanelClass
-: public LLSingleton< LLRegisterPanelClass >
-{
-public:
- // reigister with either the provided builder, or the generic templated builder
- void addPanelClass(const std::string& tag,LLPanelClassCreatorFunc func)
- {
- mPanelClassesNames[tag] = func;
- }
-
- LLPanel* createPanelClass(const std::string& tag)
- {
- param_name_map_t::iterator iT = mPanelClassesNames.find(tag);
- if(iT == mPanelClassesNames.end())
- return 0;
- return iT->second();
- }
- template<typename T>
- static T* defaultPanelClassBuilder()
- {
- T* pT = new T();
- return pT;
- }
-
-private:
- typedef std::map< std::string, LLPanelClassCreatorFunc> param_name_map_t;
-
- param_name_map_t mPanelClassesNames;
-};
-
-
-// local static instance for registering a particular panel class
-template<typename T>
-class LLRegisterPanelClassWrapper
-: public LLRegisterPanelClass
-{
-public:
- // reigister with either the provided builder, or the generic templated builder
- LLRegisterPanelClassWrapper(const std::string& tag);
-};
-
-
-template<typename T>
-LLRegisterPanelClassWrapper<T>::LLRegisterPanelClassWrapper(const std::string& tag)
-{
- LLRegisterPanelClass::instance().addPanelClass(tag,&LLRegisterPanelClass::defaultPanelClassBuilder<T>);
-}
-
-
#endif //LLUICTRLFACTORY_H