arabica/include/DOM/Events/EventTarget.hpp

117 lines
3.8 KiB
C++
Raw Normal View History

2002-06-21 13:16:28 +02:00
#ifndef JEZUK_EVENTS_EVENTTARGET_H
#define JEZUK_EVENTS_EVENTTARGET_H
////////////////////////////
// C++ DOM definition
//
// $Id$
////////////////////////////
2012-12-30 01:10:31 +01:00
#include <DOM/Proxy.hpp>
#include <Arabica/StringAdaptor.hpp>
2002-06-21 13:16:28 +02:00
2007-09-05 13:47:13 +02:00
namespace Arabica
{
2002-06-21 13:16:28 +02:00
namespace DOM
{
namespace Events
{
2012-12-30 01:10:31 +01:00
template<class stringT, class string_adaptorT> class Event;
template<class stringT, class string_adaptorT> class EventListener;
template<class stringT, class string_adaptorT> class EventTarget_impl;
2002-06-21 13:16:28 +02:00
2012-12-30 01:10:31 +01:00
template<class stringT, class string_adaptorT = Arabica::default_string_adaptor<stringT> >
class EventTarget : protected Arabica::DOM::Proxy<EventTarget_impl<stringT, string_adaptorT> >
2002-06-21 13:16:28 +02:00
{
public:
2012-12-30 01:10:31 +01:00
typedef EventTarget_impl<stringT, string_adaptorT> EventTarget_implT;
typedef Event<stringT, string_adaptorT> EventT;
typedef EventListener<stringT, string_adaptorT> EventListenerT;
typedef DOM::Proxy<EventTarget_implT> 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<stringT, string_adaptorT>& rhs) : proxy_t(dynamic_cast<EventTarget_implT*>(rhs.underlying_impl()))
2002-06-21 13:16:28 +02:00
{
2012-12-30 01:10:31 +01:00
if(dynamic_cast<EventTarget_implT*>(rhs.underlying_impl()) == 0)
2002-06-21 13:16:28 +02:00
throw DOM::DOMException(DOM::DOMException::NOT_SUPPORTED_ERR);
}
2002-06-21 13:16:28 +02:00
virtual ~EventTarget() { }
2012-12-30 01:10:31 +01:00
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); }
2002-06-21 13:16:28 +02:00
EventTarget& operator=(const EventTarget& rhs)
{
2012-12-30 01:10:31 +01:00
proxy_t::operator=(rhs);
2002-06-21 13:16:28 +02:00
return *this;
} // operator=
#if 0
DOM::Node<stringT> asNode() {
return DOM::Node<stringT>(dynamic_cast<Node_impl<stringT, string_adaptorT>*>(proxy_t::operator*()));
}
#endif
2002-06-21 13:16:28 +02:00
///////////////////////////////////////////////////////////////
// EventTarget methods
void addEventListener(const stringT type,
2012-12-30 01:10:31 +01:00
EventListenerT& listener,
2002-06-21 13:16:28 +02:00
bool useCapture)
{
2012-12-30 01:10:31 +01:00
Impl()->addEventListener(type, listener, useCapture);
2002-06-21 13:16:28 +02:00
} // addEventListener
void removeEventListener(const stringT type,
2012-12-30 01:10:31 +01:00
EventListenerT& listener,
2002-06-21 13:16:28 +02:00
bool useCapture)
{
Impl()->removeEventListener(type, listener, useCapture);
} // removeEventListener
2012-12-30 01:10:31 +01:00
bool dispatchEvent(EventT& event)
2002-06-21 13:16:28 +02:00
{
2012-12-30 01:10:31 +01:00
return Impl()->dispatchEvent(event);
2002-06-21 13:16:28 +02:00
} // dispatchEvent
2012-12-30 01:10:31 +01:00
// private:
EventTarget_implT* Impl() const { return dynamic_cast<EventTarget_implT*>(proxy_t::operator*()); }
2002-06-21 13:16:28 +02:00
}; // class EventTarget
//////////////////////////////////////////////////////////////////////
// Event_impl
2012-12-30 01:10:31 +01:00
template<class stringT, class string_adaptorT>
class EventTarget_impl
2002-06-21 13:16:28 +02:00
{
2012-12-30 01:10:31 +01:00
public:
typedef Event<stringT, string_adaptorT> EventT;
typedef EventListener<stringT, string_adaptorT> EventListenerT;
///////////////////////////////////////////////////////
// Ref counting
virtual void addRef() = 0;
virtual void releaseRef() = 0;
2002-06-21 13:16:28 +02:00
///////////////////////////////////////////////////////////////
// EventTarget methods
virtual void addEventListener(const stringT type,
2012-12-30 01:10:31 +01:00
EventListenerT& listener,
2002-06-21 13:16:28 +02:00
bool useCapture) = 0;
virtual void removeEventListener(const stringT type,
2012-12-30 01:10:31 +01:00
EventListenerT& listener,
2002-06-21 13:16:28 +02:00
bool useCapture) = 0;
2012-12-30 01:10:31 +01:00
virtual bool dispatchEvent(EventT& event) = 0;
2002-06-21 13:16:28 +02:00
}; // class EventTarget_impl
} // namespace Events
} // namespace DOM
2007-09-05 13:47:13 +02:00
} // namespace Arabica
2002-06-21 13:16:28 +02:00
2007-09-05 00:55:47 +02:00
#endif