From 02d8197019dcecec7aee80a104c4644ddb4807ca Mon Sep 17 00:00:00 2001
From: Richard Nelson <none@none>
Date: Fri, 20 Aug 2010 10:14:28 -0700
Subject: changed buildPanel/buildFloater to member functions buildFromFile
 streamlined LLUICtrlFactory's interface

---
 indra/llui/llaccordionctrl.cpp |  2 +-
 indra/llui/llfloater.cpp       | 21 ++++++-----
 indra/llui/llfloater.h         |  2 +-
 indra/llui/llfloaterreg.cpp    |  2 +-
 indra/llui/llpanel.cpp         | 20 +++++------
 indra/llui/llpanel.h           |  2 +-
 indra/llui/lluictrlfactory.h   | 80 ++++++++++++++++++++++--------------------
 7 files changed, 65 insertions(+), 64 deletions(-)

(limited to 'indra/llui')

diff --git a/indra/llui/llaccordionctrl.cpp b/indra/llui/llaccordionctrl.cpp
index 9337626c8e..5ce52185e3 100644
--- a/indra/llui/llaccordionctrl.cpp
+++ b/indra/llui/llaccordionctrl.cpp
@@ -89,7 +89,7 @@ LLAccordionCtrl::LLAccordionCtrl() : LLPanel()
 
 	mSingleExpansion = false;
 	mFitParent = false;
-	buildPanel(this, "accordion_parent.xml");	
+	buildFromFile( "accordion_parent.xml");	
 }
 
 //---------------------------------------------------------------------------------
diff --git a/indra/llui/llfloater.cpp b/indra/llui/llfloater.cpp
index d66b3c1707..0cd692b4a4 100644
--- a/indra/llui/llfloater.cpp
+++ b/indra/llui/llfloater.cpp
@@ -2887,8 +2887,7 @@ bool LLFloater::isVisible(const LLFloater* floater)
 
 static LLFastTimer::DeclareTimer FTM_BUILD_FLOATERS("Build Floaters");
 
-/* static */
-bool LLFloater::buildFloater(LLFloater* floaterp, const std::string& filename, LLXMLNodePtr output_node)
+bool LLFloater::buildFromFile(const std::string& filename, LLXMLNodePtr output_node)
 {
 	LLFastTimer timer(FTM_BUILD_FLOATERS);
 	LLXMLNodePtr root;
@@ -2921,23 +2920,23 @@ bool LLFloater::buildFloater(LLFloater* floaterp, const std::string& filename, L
 	lldebugs << "Building floater " << filename << llendl;
 	LLUICtrlFactory::instance().pushFileName(filename);
 	{
-		if (!floaterp->getFactoryMap().empty())
+		if (!getFactoryMap().empty())
 		{
-			LLPanel::sFactoryStack.push_front(&floaterp->getFactoryMap());
+			LLPanel::sFactoryStack.push_front(&getFactoryMap());
 		}
 
 		 // for local registry callbacks; define in constructor, referenced in XUI or postBuild
-		floaterp->getCommitCallbackRegistrar().pushScope();
-		floaterp->getEnableCallbackRegistrar().pushScope();
+		getCommitCallbackRegistrar().pushScope();
+		getEnableCallbackRegistrar().pushScope();
 		
-		res = floaterp->initFloaterXML(root, floaterp->getParent(), filename, output_node);
+		res = initFloaterXML(root, getParent(), filename, output_node);
 
-		floaterp->setXMLFilename(filename);
+		setXMLFilename(filename);
 		
-		floaterp->getCommitCallbackRegistrar().popScope();
-		floaterp->getEnableCallbackRegistrar().popScope();
+		getCommitCallbackRegistrar().popScope();
+		getEnableCallbackRegistrar().popScope();
 		
-		if (!floaterp->getFactoryMap().empty())
+		if (!getFactoryMap().empty())
 		{
 			LLPanel::sFactoryStack.pop_front();
 		}
diff --git a/indra/llui/llfloater.h b/indra/llui/llfloater.h
index 69762c7723..750cf23c7d 100644
--- a/indra/llui/llfloater.h
+++ b/indra/llui/llfloater.h
@@ -147,7 +147,7 @@ public:
 
 	// Don't export top/left for rect, only height/width
 	static void setupParamsForExport(Params& p, LLView* parent);
-	static bool buildFloater(LLFloater* floaterp, const std::string &filename, LLXMLNodePtr output_node);
+	bool buildFromFile(const std::string &filename, LLXMLNodePtr output_node = NULL);
 
 	void initFromParams(const LLFloater::Params& p);
 	bool initFloaterXML(LLXMLNodePtr node, LLView *parent, const std::string& filename, LLXMLNodePtr output_node = NULL);
diff --git a/indra/llui/llfloaterreg.cpp b/indra/llui/llfloaterreg.cpp
index 2c31854011..39a67ee57b 100644
--- a/indra/llui/llfloaterreg.cpp
+++ b/indra/llui/llfloaterreg.cpp
@@ -127,7 +127,7 @@ LLFloater* LLFloaterReg::getInstance(const std::string& name, const LLSD& key)
 
 				res = build_func(key);
 				
-				bool success = LLFloater::buildFloater(res, xui_file, NULL);
+				bool success = res->buildFromFile(xui_file, NULL);
 				if (!success)
 				{
 					llwarns << "Failed to build floater type: '" << name << "'." << llendl;
diff --git a/indra/llui/llpanel.cpp b/indra/llui/llpanel.cpp
index f79429e0f6..51c8f6c743 100644
--- a/indra/llui/llpanel.cpp
+++ b/indra/llui/llpanel.cpp
@@ -972,7 +972,7 @@ static LLFastTimer::DeclareTimer FTM_BUILD_PANELS("Build Panels");
 //-----------------------------------------------------------------------------
 // buildPanel()
 //-----------------------------------------------------------------------------
-BOOL LLPanel::buildPanel(LLPanel* panelp, const std::string& filename, LLXMLNodePtr output_node, const LLPanel::Params& default_params)
+BOOL LLPanel::buildFromFile(const std::string& filename, LLXMLNodePtr output_node, const LLPanel::Params& default_params)
 {
 	LLFastTimer timer(FTM_BUILD_PANELS);
 	BOOL didPost = FALSE;
@@ -1005,23 +1005,23 @@ BOOL LLPanel::buildPanel(LLPanel* panelp, const std::string& filename, LLXMLNode
 
 	LLUICtrlFactory::instance().pushFileName(filename);
 	{
-		if (!panelp->getFactoryMap().empty())
+		if (!getFactoryMap().empty())
 		{
-			sFactoryStack.push_back(&panelp->getFactoryMap());
+			sFactoryStack.push_back(&getFactoryMap());
 		}
 		
 		 // for local registry callbacks; define in constructor, referenced in XUI or postBuild
-		panelp->getCommitCallbackRegistrar().pushScope();
-		panelp->getEnableCallbackRegistrar().pushScope();
+		getCommitCallbackRegistrar().pushScope();
+		getEnableCallbackRegistrar().pushScope();
 		
-		didPost = panelp->initPanelXML(root, NULL, output_node, default_params);
+		didPost = initPanelXML(root, NULL, output_node, default_params);
 
-		panelp->getCommitCallbackRegistrar().popScope();
-		panelp->getEnableCallbackRegistrar().popScope();
+		getCommitCallbackRegistrar().popScope();
+		getEnableCallbackRegistrar().popScope();
 		
-		panelp->setXMLFilename(filename);
+		setXMLFilename(filename);
 
-		if (!panelp->getFactoryMap().empty())
+		if (!getFactoryMap().empty())
 		{
 			sFactoryStack.pop_back();
 		}
diff --git a/indra/llui/llpanel.h b/indra/llui/llpanel.h
index de16d28e27..cacd1fdcf0 100644
--- a/indra/llui/llpanel.h
+++ b/indra/llui/llpanel.h
@@ -110,7 +110,7 @@ protected:
 	LLPanel(const LLPanel::Params& params = getDefaultParams());
 	
 public:
-	static 	BOOL buildPanel(LLPanel* panelp, const std::string &filename, LLXMLNodePtr output_node = NULL, const LLPanel::Params&default_params = getDefaultParams());
+	BOOL buildFromFile(const std::string &filename, LLXMLNodePtr output_node = NULL, const LLPanel::Params&default_params = getDefaultParams());
 
 	static LLPanel* createFactoryPanel(const std::string& name);
 
diff --git a/indra/llui/lluictrlfactory.h b/indra/llui/lluictrlfactory.h
index 16fb618c88..82076335d7 100644
--- a/indra/llui/lluictrlfactory.h
+++ b/indra/llui/lluictrlfactory.h
@@ -155,38 +155,12 @@ public:
 	void pushFileName(const std::string& name);
 	void popFileName();
 
-	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 _(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* 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();
@@ -249,8 +223,47 @@ fail:
 		return create<T>(widget_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:
+	template <typename T> friend class LLChildRegistry;
+
 	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)
 	{
@@ -275,7 +288,7 @@ fail:
 		// 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;
 
@@ -290,18 +303,7 @@ 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, const std::string& tag);
-
-private:
 	static const std::string* getWidgetTag(const std::type_info* widget_type);
 
 	// this exists to get around dependency on llview
-- 
cgit v1.2.3