#ifndef JEZUK_EVENTS_EVENTTARGET_H #define JEZUK_EVENTS_EVENTTARGET_H //////////////////////////// // C++ DOM definition // // $Id$ //////////////////////////// #include #include namespace Arabica { namespace DOM { namespace Events { template class Event; template class EventListener; template class EventTarget_impl; template > class EventTarget : protected Arabica::DOM::Proxy > { public: typedef EventTarget_impl EventTarget_implT; typedef Event EventT; typedef EventListener EventListenerT; typedef DOM::Proxy proxy_t; EventTarget() : proxy_t(0) { } EventTarget(EventTarget_implT* const impl) : proxy_t(impl) { } EventTarget(const EventTarget& rhs) : proxy_t(rhs) { } explicit EventTarget(const DOM::Node& rhs) : proxy_t(dynamic_cast(rhs.underlying_impl())) { if(dynamic_cast(rhs.underlying_impl()) == 0) throw DOM::DOMException(DOM::DOMException::NOT_SUPPORTED_ERR); } virtual ~EventTarget() { } bool operator==(const EventTarget& rhs) const { return proxy_t::operator==(rhs); } bool operator!=(const EventTarget& rhs) const { return proxy_t::operator!=(rhs); } bool operator==(int dummy) const { return proxy_t::operator==(dummy); } bool operator!=(int dummy) const { return proxy_t::operator!=(dummy); } EventTarget& operator=(const EventTarget& rhs) { proxy_t::operator=(rhs); return *this; } // operator= #if 0 DOM::Node asNode() { return DOM::Node(dynamic_cast*>(proxy_t::operator*())); } #endif /////////////////////////////////////////////////////////////// // EventTarget methods void addEventListener(const stringT type, EventListenerT& listener, bool useCapture) { Impl()->addEventListener(type, listener, useCapture); } // addEventListener void removeEventListener(const stringT type, EventListenerT& listener, bool useCapture) { Impl()->removeEventListener(type, listener, useCapture); } // removeEventListener bool dispatchEvent(EventT& event) { return Impl()->dispatchEvent(event); } // dispatchEvent // private: EventTarget_implT* Impl() const { return dynamic_cast(proxy_t::operator*()); } }; // class EventTarget ////////////////////////////////////////////////////////////////////// // Event_impl template class EventTarget_impl { public: typedef Event EventT; typedef EventListener EventListenerT; /////////////////////////////////////////////////////// // Ref counting virtual void addRef() = 0; virtual void releaseRef() = 0; /////////////////////////////////////////////////////////////// // EventTarget methods virtual void addEventListener(const stringT type, EventListenerT& listener, bool useCapture) = 0; virtual void removeEventListener(const stringT type, EventListenerT& listener, bool useCapture) = 0; virtual bool dispatchEvent(EventT& event) = 0; }; // class EventTarget_impl } // namespace Events } // namespace DOM } // namespace Arabica #endif