From 8f9807daf332f523df013b13e1a900953c96cbda Mon Sep 17 00:00:00 2001 From: Peter Schojer Date: Tue, 16 Sep 2008 08:15:36 +0000 Subject: [PATCH] extensions to template --- WebWidgets/ExtJS/src/Utility.cpp | 3 + WebWidgets/WebWidgets_VS80.vcproj | 4 + WebWidgets/WebWidgets_VS90.vcproj | 4 + WebWidgets/include/Poco/WebWidgets/Getter.h | 144 +++++++++++ WebWidgets/include/Poco/WebWidgets/Template.h | 57 ++++- WebWidgets/src/Template.cpp | 228 +++++++++++++++++- 6 files changed, 424 insertions(+), 16 deletions(-) create mode 100644 WebWidgets/include/Poco/WebWidgets/Getter.h diff --git a/WebWidgets/ExtJS/src/Utility.cpp b/WebWidgets/ExtJS/src/Utility.cpp index 9a6ffbe07..7886e1fd3 100644 --- a/WebWidgets/ExtJS/src/Utility.cpp +++ b/WebWidgets/ExtJS/src/Utility.cpp @@ -63,6 +63,7 @@ #include "Poco/WebWidgets/ExtJS/ProgressIndicatorRenderer.h" #include "Poco/WebWidgets/ExtJS/HTMLRenderer.h" #include "Poco/WebWidgets/ExtJS/DynamicCodeLoaderRenderer.h" +#include "Poco/WebWidgets/ExtJS/TemplateRenderer.h" #include "Poco/WebWidgets/Label.h" #include "Poco/WebWidgets/Page.h" @@ -96,6 +97,7 @@ #include "Poco/WebWidgets/WebApplication.h" #include "Poco/WebWidgets/RequestHandler.h" #include "Poco/WebWidgets/ProgressIndicator.h" +#include "Poco/WebWidgets/Template.h" #include "Poco/String.h" #include "Poco/StringTokenizer.h" @@ -140,6 +142,7 @@ void Utility::initialize(LookAndFeel::Ptr ptr) ptr->registerRenderer(typeid(ProgressIndicator), new ProgressIndicatorRenderer()); ptr->registerRenderer(typeid(HTML),new HTMLRenderer()); ptr->registerRenderer(typeid(DynamicCodeLoader),new DynamicCodeLoaderRenderer()); + ptr->registerRenderer(typeid(Template),new TemplateRenderer()); } diff --git a/WebWidgets/WebWidgets_VS80.vcproj b/WebWidgets/WebWidgets_VS80.vcproj index ce367d8e9..dda099859 100644 --- a/WebWidgets/WebWidgets_VS80.vcproj +++ b/WebWidgets/WebWidgets_VS80.vcproj @@ -241,6 +241,10 @@ RelativePath=".\include\Poco\WebWidgets\Event.h" > + + diff --git a/WebWidgets/WebWidgets_VS90.vcproj b/WebWidgets/WebWidgets_VS90.vcproj index a62751f07..e385d69df 100644 --- a/WebWidgets/WebWidgets_VS90.vcproj +++ b/WebWidgets/WebWidgets_VS90.vcproj @@ -240,6 +240,10 @@ RelativePath=".\include\Poco\WebWidgets\Event.h" > + File + RelativePath=".\include\Poco\WebWidgets\Getter.h" + > + diff --git a/WebWidgets/include/Poco/WebWidgets/Getter.h b/WebWidgets/include/Poco/WebWidgets/Getter.h new file mode 100644 index 000000000..ff443e2d1 --- /dev/null +++ b/WebWidgets/include/Poco/WebWidgets/Getter.h @@ -0,0 +1,144 @@ +// +// Getter.h +// +// $Id: //poco/Main/WebWidgets/include/Poco/WebWidgets/Getter.h#2 $ +// +// Library: WebWidgets +// Package: Core +// Module: Getter +// +// Definition of the Getter class. +// +// Copyright (c) 2008, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef WebWidgets_Getter_INCLUDED +#define WebWidgets_Getter_INCLUDED + + +#include "Poco/WebWidgets/WebWidgets.h" +#include "Poco/RefCountedObject.h" +#include "Poco/AutoPtr.h" +#include "Poco/Any.h" +#include "Poco/MetaProgramming.h" + + +namespace Poco { +namespace WebWidgets { + + +class WebWidgets_API Getter: public Poco::RefCountedObject +{ +public: + typedef Poco::AutoPtr Ptr; +public: + Getter() + { + } + + virtual Poco::Any get() const = 0; +}; + + +template +class GetterImpl: public Getter +{ +public: + typedef TArg (TObj::*NotifyMethod)() const; + + GetterImpl(TObj* obj, NotifyMethod method): + _object(obj), + _method(method) + { + } + + TArg operator()() const + { + return (_object->*_method)(); + } + + Poco::Any get() const + { + return this->operator(); + } + +protected: + TObj* _object; + NotifyMethod _method; +}; + + +template +class GetterImpl2: public Getter +{ +public: + typedef TArg (TObj::*NotifyMethod)(TArgIn) const; + typedef typename TypeWrapper::TYPE TArgInValue; + + GetterImpl2(TObj* obj, NotifyMethod method, TArgIn in): + _object(obj), + _method(method), + _value(in) + { + } + + TArg operator()() const + { + return (_object->*_method)(_value); + } + + Poco::Any get() const + { + return this->operator(); + } + +protected: + TObj* _object; + NotifyMethod _method; + TArgInValue _value; +}; + +template +Getter* getter(const TObj* object, TArg (TObj::*method)(TArgIn in) const) + /// "Constructor" function for a Getter. +{ + return new GetterImpl2(object, method, in); +} + + +template +Getter* getter(const TObj* object, TArg (TObj::*method)() const) + /// "Constructor" function for a Getter. +{ + return new GetterImpl(object, method); +} + + +} } // namespace Poco::WebWidgets + + +#endif // WebWidgets_Getter_INCLUDED diff --git a/WebWidgets/include/Poco/WebWidgets/Template.h b/WebWidgets/include/Poco/WebWidgets/Template.h index 26b7935b9..508377df3 100644 --- a/WebWidgets/include/Poco/WebWidgets/Template.h +++ b/WebWidgets/include/Poco/WebWidgets/Template.h @@ -40,7 +40,8 @@ #define WebWidgets_Template_INCLUDED -#include "Poco/WebWidgets/Renderable.h" +#include "Poco/WebWidgets/View.h" +#include "Poco/WebWidgets/Getter.h" #include "Poco/FIFOEvent.h" #include "Poco/Any.h" #include @@ -53,10 +54,11 @@ namespace WebWidgets { class RenderContext; -class WebWidgets_API Template: public Renderable +class WebWidgets_API Template: public View /// A JavaScript template class: Defines a template string which contains wildcards of the form %0, %1 %2 ... /// You can bind values to the wildcards. Values must be of type: /// - string, int, double, float, char, bool, Poco::WebWidgets::Renderable, DateTime + /// properties inherited by View (like width, height) are ignored { public: typedef Poco::AutoPtr