Rapicorn - Experimental UI Toolkit - Source Code  13.07.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
factory.hh
Go to the documentation of this file.
00001  // Licensed GNU LGPL v3 or later: http://www.gnu.org/licenses/lgpl.html
00002 #ifndef __RAPICORN_FACTORY_HH__
00003 #define __RAPICORN_FACTORY_HH__
00004 
00005 #include <ui/widget.hh>
00006 #include <list>
00007 
00008 namespace Rapicorn {
00009 
00010 namespace Factory {
00011 
00012 typedef std::vector<String>      ArgumentList;  /* elements: key=utf8string */
00013 
00014 // == UI Factory ==
00015 String      parse_ui_file       (const String           &uinamespace,
00016                                  const String           &file_name,
00017                                  const String           &i18n_domain = "",
00018                                  vector<String>         *definitions = NULL);
00019 String      parse_ui_data       (const String           &uinamespace,
00020                                  const String           &data_name,
00021                                  size_t                  data_length,
00022                                  const char             *data,
00023                                  const String           &i18n_domain = "",
00024                                  vector<String>         *definitions = NULL);
00025 WidgetImpl& create_ui_widget    (const String           &widget_identifier,
00026                                  const ArgumentList     &arguments = ArgumentList());
00027 WidgetImpl& create_ui_child     (ContainerImpl &container, const String &widget_identifier,
00028                                  const ArgumentList &arguments, bool autoadd = true);
00029 
00030 void        create_ui_children  (ContainerImpl          &container,
00031                                  vector<WidgetImpl*>      *children,
00032                                  const String           &presuppose,
00033                                  int64                   max_children = -1);
00034 bool        check_ui_window     (const String           &widget_identifier);
00035 void        use_ui_namespace    (const String           &uinamespace);
00036 
00037 // == Factory Contexts ==
00038 
00039 typedef map<String,String>       VariableMap;
00040 
00041 String           factory_context_name      (FactoryContext *fc);
00042 String           factory_context_type      (FactoryContext *fc);
00043 const StringSeq& factory_context_tags      (FactoryContext *fc);
00044 UserSource       factory_context_source    (FactoryContext *fc);
00045 String           factory_context_impl_type (FactoryContext *fc);
00046 
00047 /* --- widget type registration --- */
00048 struct WidgetTypeFactory : protected Deletable {
00049   const String  qualified_type;
00050   RAPICORN_CLASS_NON_COPYABLE (WidgetTypeFactory);
00051 protected:
00052   static void   register_widget_factory   (const WidgetTypeFactory  &itfactory);
00053   static void   sanity_check_identifier (const char             *namespaced_ident);
00054 public:
00055   explicit      WidgetTypeFactory         (const char             *namespaced_ident,
00056                                          bool _isevh, bool _iscontainer, bool);
00057   virtual WidgetImpl* create_widget         (FactoryContext         *fc) const = 0;
00058   inline String type_name               () const { return qualified_type; }
00059   const bool iseventhandler, iscontainer;
00060 };
00061 
00062 } // Factory
00063 
00064 // namespace Rapicorn
00065 
00066 /* --- widget factory template --- */
00067 template<class Type>
00068 class WidgetFactory : Factory::WidgetTypeFactory {
00069   virtual WidgetImpl*
00070   create_widget (FactoryContext *fc) const
00071   {
00072     WidgetImpl *widget = new Type();
00073     widget->factory_context (fc);
00074     return widget;
00075   }
00076 public:
00077   explicit WidgetFactory (const char *namespaced_ident) :
00078     WidgetTypeFactory (namespaced_ident,
00079                      TraitConvertible<EventHandler,Type>::TRUTH,
00080                      TraitConvertible<ContainerImpl,Type>::TRUTH,
00081                      TraitConvertible<int,Type>::TRUTH)
00082   {
00083     sanity_check_identifier (namespaced_ident);
00084     register_widget_factory (*this);
00085   }
00086 };
00087 
00088 } // Rapicorn
00089 
00090 #endif /* __RAPICORN_FACTORY_HH__ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines