summaryrefslogtreecommitdiff
path: root/indra/llui/lluictrlfactory.h
diff options
context:
space:
mode:
authorJames Cook <james@lindenlab.com>2009-07-07 00:53:05 +0000
committerJames Cook <james@lindenlab.com>2009-07-07 00:53:05 +0000
commit52aeaa32841e7d0b37abab0a2a2540c2be2f16b7 (patch)
treed8f5c98644029dd289a97aa0d8b55c5a6200c214 /indra/llui/lluictrlfactory.h
parent2c722655bd6701a3dc8518c6518c51f538765dcd (diff)
Merge skinning-14 to viewer-2, including refactoring many floaters to register them with LLFloaterReg, support for introspection of ParamBlock based UI widgets to dump XML schema, splitting llfolderview.cpp into three separate files to unravel dependencies and skeleton for for LLListView widget. Resolved conflicts in these files:
lldraghandle.h, lluictrl.h, llchiclet.cpp, llfolderview.h/cpp, lliinventorybridge.cpp, llpanelpicks.cpp, llviewermenu.cpp, floater_mute.xml, floater_preferences.xml, notifications.xml, panel_preferences_audio.xml, panel_preferences_graphics1.xml, panel_region_general.xml svn merge -r124961:126284 svn+ssh://svn.lindenlab.com/svn/linden/branches/skinning/skinning-14
Diffstat (limited to 'indra/llui/lluictrlfactory.h')
-rw-r--r--indra/llui/lluictrlfactory.h171
1 files changed, 126 insertions, 45 deletions
diff --git a/indra/llui/lluictrlfactory.h b/indra/llui/lluictrlfactory.h
index f8d584bc75..894c77888c 100644
--- a/indra/llui/lluictrlfactory.h
+++ b/indra/llui/lluictrlfactory.h
@@ -41,11 +41,64 @@
#include <boost/function.hpp>
#include <iosfwd>
#include <stack>
+#include <set>
class LLPanel;
class LLFloater;
class LLView;
+class LLRNGWriter : public LLInitParam::Parser
+{
+ LOG_CLASS(LLRNGWriter);
+public:
+ void writeRNG(const std::string& name, LLXMLNodePtr node, const LLInitParam::BaseBlock& block, const std::string& xml_namespace);
+
+ /*virtual*/ std::string getCurrentElementName() { return LLStringUtil::null; }
+
+ LLRNGWriter();
+
+private:
+ LLXMLNodePtr getCardinalityNode(LLXMLNodePtr parent_node, S32 min_count, S32 max_count);
+
+ void writeAttribute(const std::string& type, const Parser::name_stack_t&, S32 min_count, S32 max_count, const std::vector<std::string>* possible_values);
+ LLXMLNodePtr mElementNode;
+ LLXMLNodePtr mGrammarNode;
+
+ typedef std::map<std::string, LLXMLNodePtr> elements_map_t;
+ elements_map_t mElementsWritten;
+};
+
+
+class LLXSDWriter : public LLInitParam::Parser
+{
+ LOG_CLASS(LLXSDWriter);
+public:
+ void writeXSD(const std::string& name, LLXMLNodePtr node, const LLInitParam::BaseBlock& block, const std::string& xml_namespace);
+
+ /*virtual*/ std::string getCurrentElementName() { return LLStringUtil::null; }
+
+ LLXSDWriter();
+
+protected:
+ void writeAttribute(const std::string& type, const Parser::name_stack_t&, S32 min_count, S32 max_count, const std::vector<std::string>* possible_values);
+ void addAttributeToSchema(LLXMLNodePtr nodep, const std::string& attribute_name, const std::string& type, bool mandatory, const std::vector<std::string>* possible_values);
+ LLXMLNodePtr mAttributeNode;
+ LLXMLNodePtr mElementNode;
+ LLXMLNodePtr mSchemaNode;
+
+ typedef std::set<std::string> string_set_t;
+ typedef std::map<LLXMLNodePtr, string_set_t> attributes_map_t;
+ attributes_map_t mAttributesWritten;
+};
+
+// NOTE: DOES NOT WORK YET
+// should support child widgets for XUI
+class LLXUIXSDWriter : public LLXSDWriter
+{
+public:
+ void writeXSD(const std::string& name, const std::string& path, const LLInitParam::BaseBlock& block);
+};
+
class LLXUIParser : public LLInitParam::Parser, public LLSingleton<LLXUIParser>
{
LOG_CLASS(LLXUIParser);
@@ -118,13 +171,23 @@ typedef boost::function<LLView* (LLXMLNodePtr node, LLView *parent, LLXMLNodePtr
typedef LLRegistry<std::string, LLWidgetCreatorFunc> widget_registry_t;
+// sort functor for typeid maps
+struct LLCompareTypeID
+{
+ bool operator()(const std::type_info* lhs, const std::type_info* rhs) const
+ {
+ return lhs->before(*rhs);
+ }
+};
+
+// lookup widget constructor funcs by widget name
template <typename DERIVED_TYPE>
-class LLWidgetRegistry : public LLRegistrySingleton<std::string, LLWidgetCreatorFunc, DERIVED_TYPE>
+class LLChildRegistry : public LLRegistrySingleton<std::string, LLWidgetCreatorFunc, DERIVED_TYPE>
{
public:
typedef LLRegistrySingleton<std::string, LLWidgetCreatorFunc, DERIVED_TYPE> super_t;
// local static instance for registering a particular widget
- template<typename T, typename PARAM_BLOCK = typename T::Params>
+ template<typename T>
class Register : public super_t::StaticRegistrar
{
public:
@@ -133,35 +196,40 @@ public:
};
protected:
- LLWidgetRegistry() {}
+ LLChildRegistry() {}
};
-class LLDefaultWidgetRegistry : public LLWidgetRegistry<LLDefaultWidgetRegistry>
+class LLDefaultChildRegistry : public LLChildRegistry<LLDefaultChildRegistry>
{
protected:
- LLDefaultWidgetRegistry() {}
- friend class LLSingleton<LLDefaultWidgetRegistry>;
-};
-
-struct LLCompareTypeID
-{
- bool operator()(const std::type_info* lhs, const std::type_info* rhs) const
- {
- return lhs->before(*rhs);
- }
+ LLDefaultChildRegistry(){}
+ friend class LLSingleton<LLDefaultChildRegistry>;
};
+// lookup widget name by type
+class LLWidgetNameRegistry
+: public LLRegistrySingleton<const std::type_info*, std::string, LLWidgetNameRegistry , LLCompareTypeID>
+{};
-class LLWidgetTemplateRegistry
-: public LLRegistrySingleton<const std::type_info*, std::string, LLWidgetTemplateRegistry, LLCompareTypeID>
+// lookup widget type by name
+class LLWidgetTypeRegistry
+: public LLRegistrySingleton<std::string, const std::type_info*, LLWidgetTypeRegistry>
{};
-// function used to create new default widgets via LLView::getChild<T>
+// 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>
+{};
-// used to register factory functions for default widget instances
-class LLDummyWidgetRegistry
-: public LLRegistrySingleton<const std::type_info*, dummy_widget_creator_func_t, LLDummyWidgetRegistry, LLCompareTypeID>
+// lookup function for generating empty param block by widget type
+typedef const LLInitParam::BaseBlock& (*empty_param_block_func_t)();
+class LLDefaultParamBlockRegistry
+: public LLRegistrySingleton<const std::type_info*, empty_param_block_func_t, LLDefaultParamBlockRegistry, LLCompareTypeID>
+{};
+
+class LLChildRegistryRegistry
+: public LLRegistrySingleton<const std::type_info*, widget_registry_t, LLChildRegistryRegistry>
{};
extern LLFastTimer::DeclareTimer FTM_WIDGET_SETUP;
@@ -176,26 +244,26 @@ private:
~LLUICtrlFactory();
// only partial specialization allowed in inner classes, so use extra dummy parameter
- template <typename T, int DUMMY>
- class ParamDefaults : public LLSingleton<ParamDefaults<T, DUMMY> >
+ template <typename PARAM_BLOCK, int DUMMY>
+ class ParamDefaults : public LLSingleton<ParamDefaults<PARAM_BLOCK, DUMMY> >
{
public:
ParamDefaults()
{
// recursively initialize from base class param block
- ((typename T::base_block_t&)mPrototype).fillFrom(ParamDefaults<typename T::base_block_t, DUMMY>::instance().get());
+ ((typename PARAM_BLOCK::base_block_t&)mPrototype).fillFrom(ParamDefaults<typename PARAM_BLOCK::base_block_t, DUMMY>::instance().get());
// after initializing base classes, look up template file for this param block
- std::string* param_block_tag = LLWidgetTemplateRegistry::instance().getValue(&typeid(T));
+ std::string* param_block_tag = LLWidgetNameRegistry::instance().getValue(&typeid(PARAM_BLOCK));
if (param_block_tag)
{
LLUICtrlFactory::loadWidgetTemplate(*param_block_tag, mPrototype);
}
}
- const T& get() { return mPrototype; }
+ const PARAM_BLOCK& get() { return mPrototype; }
private:
- T mPrototype;
+ PARAM_BLOCK mPrototype;
};
// base case for recursion, there are NO base classes of LLInitParam::BaseBlock
@@ -210,11 +278,12 @@ private:
public:
+ // get default parameter block for widget of a specific type
template<typename T>
- static const T& getDefaultParams()
+ static const typename T::Params& getDefaultParams()
{
//#pragma message("Generating ParamDefaults")
- return ParamDefaults<T, 0>::instance().get();
+ return ParamDefaults<typename T::Params, 0>::instance().get();
}
void buildFloater(LLFloater* floaterp, const std::string &filename, BOOL open_floater = TRUE, LLXMLNodePtr output_node = NULL);
@@ -252,12 +321,10 @@ public:
return widget;
}
- LLView* createFromXML(LLXMLNodePtr node, LLView* parent, const std::string& filename, LLXMLNodePtr output_node, const widget_registry_t& );
+ LLView* createFromXML(LLXMLNodePtr node, LLView* parent, const std::string& filename, const widget_registry_t&, LLXMLNodePtr output_node );
- static const widget_registry_t& getWidgetRegistry(LLView*);
-
template<typename T>
- static T* createFromFile(const std::string &filename, LLView *parent, LLXMLNodePtr output_node = NULL)
+ 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;
@@ -283,7 +350,7 @@ public:
goto fail;
}
- LLView* view = getInstance()->createFromXML(root_node, parent, filename, output_node, getWidgetRegistry(parent));
+ LLView* view = getInstance()->createFromXML(root_node, parent, filename, registry, output_node);
if (view)
{
widget = dynamic_cast<T*>(view);
@@ -304,7 +371,7 @@ fail:
template<class T>
static T* getDefaultWidget(const std::string& name)
{
- dummy_widget_creator_func_t* dummy_func = LLDummyWidgetRegistry::instance().getValue(&typeid(T));
+ dummy_widget_creator_func_t* dummy_func = LLDefaultWidgetRegistry::instance().getValue(&typeid(T));
return dummy_func ? dynamic_cast<T*>((*dummy_func)(name)) : NULL;
}
@@ -317,23 +384,23 @@ fail:
return create<T>(params);
}
- template<typename T, typename PARAM_BLOCK>
+ template<typename T>
static T* defaultBuilder(LLXMLNodePtr node, LLView *parent, LLXMLNodePtr output_node)
{
LLFastTimer timer(FTM_WIDGET_SETUP);
//#pragma message("Generating LLUICtrlFactory::defaultBuilder")
- PARAM_BLOCK params(getDefaultParams<PARAM_BLOCK>());
+ typename T::Params params(getDefaultParams<T>());
LLXUIParser::instance().readXUI(node, params);
if (output_node)
{
// We always want to output top-left coordinates
- PARAM_BLOCK output_params(params);
+ typename T::Params output_params(params);
T::setupParamsForExport(output_params, parent);
// Export only the differences between this any default params
- PARAM_BLOCK default_params(getDefaultParams<PARAM_BLOCK>());
+ typename T::Params default_params(getDefaultParams<T>());
output_node->setName(node->getName()->mString);
LLXUIParser::instance().writeXUI(
output_node, output_params, &default_params);
@@ -361,8 +428,10 @@ fail:
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, output_node);
+ createChildren(widget, node, registry_t::instance(), output_node);
if (!widget->postBuild())
{
@@ -373,7 +442,7 @@ fail:
return widget;
}
- static void createChildren(LLView* viewp, LLXMLNodePtr node, LLXMLNodePtr output_node = NULL);
+ static void createChildren(LLView* viewp, LLXMLNodePtr node, const widget_registry_t&, LLXMLNodePtr output_node = NULL);
static bool getLayeredXMLNode(const std::string &filename, LLXMLNodePtr& root);
@@ -395,16 +464,28 @@ private:
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, typename PARAM_BLOCK>
-LLWidgetRegistry<DERIVED>::Register<T, PARAM_BLOCK>::Register(const char* tag, LLWidgetCreatorFunc func)
-: LLWidgetRegistry<DERIVED>::StaticRegistrar(tag, func.empty() ? (LLWidgetCreatorFunc)&LLUICtrlFactory::defaultBuilder<T, PARAM_BLOCK> : func)
+template<typename T>
+LLChildRegistry<DERIVED>::Register<T>::Register(const char* tag, LLWidgetCreatorFunc func)
+: LLChildRegistry<DERIVED>::StaticRegistrar(tag, func.empty() ? (LLWidgetCreatorFunc)&LLUICtrlFactory::defaultBuilder<T> : func)
{
+ const std::type_info* widget_type_infop = &typeid(T);
// associate parameter block type with template .xml file
- LLWidgetTemplateRegistry::instance().defaultRegistrar().add(&typeid(PARAM_BLOCK), tag);
+ LLWidgetNameRegistry ::instance().defaultRegistrar().add(&typeid(typename T::Params), tag);
// associate widget type with factory function
- LLDummyWidgetRegistry::instance().defaultRegistrar().add(&typeid(T), &LLUICtrlFactory::createDefaultWidget<T>);
+ LLDefaultWidgetRegistry::instance().defaultRegistrar().add(widget_type_infop, &LLUICtrlFactory::createDefaultWidget<T>);
+ LLWidgetTypeRegistry::instance().defaultRegistrar().add(tag, widget_type_infop);
+ LLDefaultParamBlockRegistry::instance().defaultRegistrar().add(widget_type_infop, &getEmptyParamBlock<T>);
+ typedef typename T::child_registry_t registry_t;
+ LLChildRegistryRegistry::instance().defaultRegistrar().add(widget_type_infop, registry_t::instance());
}