diff options
Diffstat (limited to 'indra/llui/lluictrlfactory.h')
-rw-r--r-- | indra/llui/lluictrlfactory.h | 73 |
1 files changed, 41 insertions, 32 deletions
diff --git a/indra/llui/lluictrlfactory.h b/indra/llui/lluictrlfactory.h index 17e32dc7a9..b1fa6add67 100644 --- a/indra/llui/lluictrlfactory.h +++ b/indra/llui/lluictrlfactory.h @@ -108,6 +108,11 @@ extern LLFastTimer::DeclareTimer FTM_WIDGET_SETUP; extern LLFastTimer::DeclareTimer FTM_WIDGET_CONSTRUCTION; extern LLFastTimer::DeclareTimer FTM_INIT_FROM_PARAMS; +// Build time optimization, generate this once in .cpp file +#ifndef LLUICTRLFACTORY_CPP +extern template class LLUICtrlFactory* LLSingleton<class LLUICtrlFactory>::getInstance(); +#endif + class LLUICtrlFactory : public LLSingleton<LLUICtrlFactory> { private: @@ -175,20 +180,44 @@ public: void popFactoryFunctions(); template<typename T> - static T* create(typename T::Params& params, LLView* parent = NULL) + static T* createWidget(typename T::Params& params, LLView* parent = NULL) { - //#pragma message("Generating LLUICtrlFactory::create") - params.fillFrom(ParamDefaults<typename T::Params, 0>::instance().get()); - //S32 foo = "test"; + 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); } - T* widget = new T(params); - widget->initFromParams(params); + { + LLFastTimer timer(FTM_INIT_FROM_PARAMS); + widget->initFromParams(params); + } + if (parent) - widget->setParent(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); + if (widget) + { + widget->postBuild(); + } + return widget; } @@ -197,7 +226,6 @@ public: template<typename T> static T* createFromFile(const std::string &filename, LLView *parent, const widget_registry_t& registry, LLXMLNodePtr output_node = NULL) { - //#pragma message("Generating LLUICtrlFactory::createFromFile") T* widget = NULL; std::string skinned_filename = findSkinnedFilename(filename); @@ -262,7 +290,6 @@ fail: { LLFastTimer timer(FTM_WIDGET_SETUP); - //#pragma message("Generating LLUICtrlFactory::defaultBuilder") typename T::Params params(getDefaultParams<T>()); LLXUIParser::instance().readXUI(node, params, LLUICtrlFactory::getInstance()->getCurFileName()); @@ -280,36 +307,18 @@ fail: } // Apply layout transformations, usually munging rect - T::setupParams(params, parent); + params.from_xui = true; + T::applyXUILayout(params, parent); + T* widget = createWidget<T>(params, parent); - if (!params.validateBlock()) - { - llwarns << getInstance()->getCurFileName() << ": Invalid parameter block for " << typeid(T).name() << llendl; - } - T* widget; - { - 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() : -1; - setCtrlParent(widget, parent, tab_group); - } - typedef typename T::child_registry_t registry_t; createChildren(widget, node, registry_t::instance(), output_node); - if (!widget->postBuild()) + if (widget && !widget->postBuild()) { delete widget; - return NULL; + widget = NULL; } return widget; |