#ifndef JEZUK_DOM_SimpleDOM_EVENT_IMPL_H #define JEZUK_DOM_SimpleDOM_EVENT_IMPL_H //////////////////////////// // C++ Event implementation //////////////////////////// #include #include #include #ifdef _WIN32 # ifndef WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN # define __UNDEF_LEAN_AND_MEAN # endif # include # ifdef __UNDEF_LEAN_AND_MEAN # undef WIN32_LEAN_AND_MEAN # undef __UNDEF_LEAN_AND_MEAN # endif #else # include #endif //#include namespace Arabica { namespace SimpleDOM { //////////////////////////////////////////////////////////////////// template class EventTargetImpl; template class EventImpl : virtual public Arabica::DOM::Events::Event_impl { public: typedef Arabica::DOM::Node_impl DOMNode_implT; typedef Arabica::DOM::Text_impl DOMText_implT; typedef Arabica::DOM::Document_impl DOMDocument_implT; typedef Arabica::DOM::NamedNodeMap_impl DOMNamedNodeMap_implT; typedef Arabica::DOM::NodeList_impl DOMNodeList_implT; typedef Arabica::DOM::Events::Event EventT; typedef Arabica::DOM::Events::EventTarget EventTargetT; typedef EventImpl EventImplT; EventImpl() : timeStamp_(0), stopped_(false), defaultsPrevented_(false), refCount_(0) { //std::cout << std::endl << "born " << this << std::endl; timeStamp_ = timeStamp(); } // EventImpl virtual ~EventImpl() { //std::cout << std::endl << "die " << this << std::endl; } virtual stringT getType() const { return type_; } virtual EventTargetT getTarget() const { return target_; } virtual EventTargetT getCurrentTarget() const { return currTarget_; } virtual typename EventT::Phase getEventPhase() const { return phase_; } virtual bool getBubbles() const { return canBubble_; } virtual bool getCancelable() const { return canCancel_; } virtual unsigned long long getTimeStamp() const { return timeStamp_; } virtual void stopPropagation() { if (canCancel_) stopped_ = true; } virtual void preventDefault() { defaultsPrevented_ = true; } virtual void initEvent(const stringT& eventTypeArg, bool canBubble, bool cancelable) { type_ = eventTypeArg; canBubble_ = canBubble; canCancel_ = cancelable; } /////////////////////////////////////////////////////// // Ref counting virtual void addRef() { ++refCount_; } // addRef virtual void releaseRef() { if(--refCount_ == 0) delete this; } // releaseRef protected: virtual unsigned long long timeStamp() { unsigned long long time = 0; #ifdef _WIN32 FILETIME tv; GetSystemTimeAsFileTime(&tv); time = (((__int64) tv.dwHighDateTime) << 32) + tv.dwLowDateTime; time /= 10000; #else struct timeval tv; gettimeofday(&tv, NULL); time += tv.tv_sec * 1000; time += tv.tv_usec / 1000; #endif return time; } stringT type_; EventTargetT target_; EventTargetT currTarget_; typename EventT::Phase phase_; unsigned long long timeStamp_; bool canBubble_; bool canCancel_; bool stopped_; bool defaultsPrevented_; unsigned long refCount_; friend class EventTargetImpl; }; // class EventImpl } // namespace SimpleDOM } // namespace Arabica #endif // JEZUK_DOM_SimpleDOM_EVENTTARGET_H // end of file