summaryrefslogtreecommitdiff
path: root/unoxml/source/events
diff options
context:
space:
mode:
Diffstat (limited to 'unoxml/source/events')
-rw-r--r--unoxml/source/events/event.cxx61
-rw-r--r--unoxml/source/events/event.hxx67
-rw-r--r--unoxml/source/events/eventdispatcher.cxx159
-rw-r--r--unoxml/source/events/eventdispatcher.hxx50
-rw-r--r--unoxml/source/events/makefile.mk86
-rw-r--r--unoxml/source/events/mutationevent.cxx100
-rw-r--r--unoxml/source/events/mutationevent.hxx65
-rw-r--r--unoxml/source/events/testlistener.cxx175
-rw-r--r--unoxml/source/events/testlistener.hxx140
9 files changed, 903 insertions, 0 deletions
diff --git a/unoxml/source/events/event.cxx b/unoxml/source/events/event.cxx
new file mode 100644
index 000000000000..abb471916044
--- /dev/null
+++ b/unoxml/source/events/event.cxx
@@ -0,0 +1,61 @@
+#include "event.hxx"
+
+namespace DOM { namespace events
+{
+
+ CEvent::~CEvent()
+ {
+ }
+
+ EventType SAL_CALL CEvent::getType() throw (RuntimeException)
+ {
+ return m_eventType;
+ }
+
+ Reference< XEventTarget > SAL_CALL CEvent::getTarget() throw (RuntimeException)
+ {
+ return m_target;
+ }
+
+ Reference< XEventTarget > SAL_CALL CEvent::getCurrentTarget() throw (RuntimeException)
+ {
+ return m_currentTarget;
+ }
+
+ PhaseType SAL_CALL CEvent::getEventPhase() throw (RuntimeException)
+ {
+ return m_phase;
+ }
+
+ sal_Bool SAL_CALL CEvent::getBubbles() throw (RuntimeException)
+ {
+ return m_bubbles;
+ }
+
+ sal_Bool SAL_CALL CEvent::getCancelable() throw (RuntimeException)
+ {
+ return m_cancelable;
+ }
+
+ com::sun::star::util::Time SAL_CALL CEvent::getTimeStamp() throw (RuntimeException)
+ {
+ return m_time;
+ }
+
+ void SAL_CALL CEvent::stopPropagation() throw (RuntimeException)
+ {
+ }
+
+ void SAL_CALL CEvent::preventDefault() throw (RuntimeException)
+ {
+ }
+
+ void SAL_CALL CEvent::initEvent( EventType eventTypeArg, sal_Bool canBubbleArg,
+ sal_Bool cancelableArg) throw (RuntimeException)
+ {
+ m_eventType = eventTypeArg;
+ m_bubbles = canBubbleArg;
+ m_cancelable = cancelableArg;
+ }
+
+}} \ No newline at end of file
diff --git a/unoxml/source/events/event.hxx b/unoxml/source/events/event.hxx
new file mode 100644
index 000000000000..08c9ba213c1d
--- /dev/null
+++ b/unoxml/source/events/event.hxx
@@ -0,0 +1,67 @@
+#ifndef __EVENT_HXX
+#define __EVENT_HXX
+
+#include <sal/types.h>
+
+#include <cppuhelper/implbase1.hxx>
+#include <cppuhelper/implbase2.hxx>
+#include <cppuhelper/implbase3.hxx>
+#include <com/sun/star/uno/Reference.h>
+#include <com/sun/star/uno/Exception.hpp>
+#include <com/sun/star/xml/dom/events/XEventTarget.hpp>
+#include <com/sun/star/util/Time.hpp>
+
+#include "../dom/node.hxx"
+
+#include <libxml/tree.h>
+
+using namespace com::sun::star::uno;
+using namespace com::sun::star::lang;
+using namespace com::sun::star::xml::dom;
+using namespace com::sun::star::xml::dom::events;
+
+
+namespace DOM {namespace events
+{
+class CEvent : public cppu::WeakImplHelper1< XEvent >
+{
+friend class CEventDispatcher;
+friend class CNode;
+friend class CDocument;
+friend class CElement;
+friend class CText;
+friend class CCharacterData;
+friend class CAttr;
+
+
+protected:
+ EventType m_eventType;
+ Reference< XEventTarget > m_target;
+ Reference< XEventTarget > m_currentTarget;
+ //xmlNodePtr m_target;
+ //xmlNodePtr m_currentTarget;
+ PhaseType m_phase;
+ sal_Bool m_bubbles;
+ sal_Bool m_cancelable;
+ com::sun::star::util::Time m_time;
+
+public:
+
+ virtual ~CEvent();
+ virtual EventType SAL_CALL getType() throw (RuntimeException);
+ virtual Reference< XEventTarget > SAL_CALL getTarget() throw (RuntimeException);
+ virtual Reference< XEventTarget > SAL_CALL getCurrentTarget() throw (RuntimeException);
+ virtual PhaseType SAL_CALL getEventPhase() throw (RuntimeException);
+ virtual sal_Bool SAL_CALL getBubbles() throw (RuntimeException);
+ virtual sal_Bool SAL_CALL getCancelable() throw (RuntimeException);
+ virtual com::sun::star::util::Time SAL_CALL getTimeStamp() throw (RuntimeException);
+ virtual void SAL_CALL stopPropagation() throw (RuntimeException);
+ virtual void SAL_CALL preventDefault() throw (RuntimeException);
+ virtual void SAL_CALL initEvent(
+ EventType eventTypeArg,
+ sal_Bool canBubbleArg,
+ sal_Bool cancelableArg)
+ throw (RuntimeException);
+};
+}}
+#endif
diff --git a/unoxml/source/events/eventdispatcher.cxx b/unoxml/source/events/eventdispatcher.cxx
new file mode 100644
index 000000000000..26e614dadef8
--- /dev/null
+++ b/unoxml/source/events/eventdispatcher.cxx
@@ -0,0 +1,159 @@
+#include "eventdispatcher.hxx"
+#include "mutationevent.hxx"
+#include "../dom/node.hxx"
+
+namespace DOM { namespace events {
+
+ TypeListenerMap CEventDispatcher::captureListeners;
+ TypeListenerMap CEventDispatcher::targetListeners;
+
+ void CEventDispatcher::addListener(xmlNodePtr pNode, EventType aType, const Reference<XEventListener>& aListener, sal_Bool bCapture)
+ {
+ TypeListenerMap* pTMap = &targetListeners;
+ if (bCapture) pTMap = &captureListeners;
+
+ // get the multimap for the specified type
+ ListenerMap *pMap = 0;
+ TypeListenerMap::const_iterator tIter = pTMap->find(aType);
+ if (tIter == pTMap->end()) {
+ // the map has to be created
+ pMap = new ListenerMap();
+ pTMap->insert(TypeListenerMap::value_type(aType, pMap));
+ } else {
+ pMap = tIter->second;
+ }
+ if (pMap !=0)
+ pMap->insert(ListenerMap::value_type(pNode, aListener));
+ }
+
+ void CEventDispatcher::removeListener(xmlNodePtr pNode, EventType aType, const Reference<XEventListener>& aListener, sal_Bool bCapture)
+ {
+ TypeListenerMap *pTMap = &targetListeners;
+ if (bCapture) pTMap = &captureListeners;
+
+ // get the multimap for the specified type
+ TypeListenerMap::const_iterator tIter = pTMap->find(aType);
+ if (tIter != pTMap->end()) {
+ ListenerMap *pMap = tIter->second;
+ // find listeners of specied type for specified node
+ ListenerMap::iterator iter = pMap->find(pNode);
+ ListenerMap::const_iterator ibound = pMap->upper_bound(pNode);
+ while (iter != ibound)
+ {
+ // erase all references to specified listener
+ if((iter->second).is() && (iter->second) == aListener)
+ {
+ ListenerMap::iterator i2 = iter;
+ iter++;
+ pMap->erase(i2);
+ }
+ else
+ iter++;
+ }
+ }
+ }
+
+ void CEventDispatcher::callListeners(xmlNodePtr pNode, EventType aType, const Reference< XEvent >& xEvent, sal_Bool bCapture)
+ {
+ TypeListenerMap *pTMap = &targetListeners;
+ if (bCapture) pTMap = &captureListeners;
+
+ // get the multimap for the specified type
+ TypeListenerMap::const_iterator tIter = pTMap->find(aType);
+ if (tIter != pTMap->end()) {
+ ListenerMap *pMap = tIter->second;
+ ListenerMap::const_iterator iter = pMap->find(pNode);
+ if( iter == pMap->end() ) return;
+ ListenerMap::const_iterator ibound = pMap->upper_bound(pNode);
+ while (iter != ibound)
+ {
+ if((iter->second).is())
+ {
+ (iter->second)->handleEvent(xEvent);
+ }
+ iter++;
+ }
+ }
+ }
+
+ sal_Bool CEventDispatcher::dispatchEvent(xmlNodePtr aNodePtr, const Reference< XEvent >& aEvent)
+ {
+ EventType aType = aEvent->getType();
+ switch (aType)
+ {
+ case EventType_DOMSubtreeModified:
+ case EventType_DOMNodeInserted:
+ case EventType_DOMNodeRemoved:
+ case EventType_DOMNodeRemovedFromDocument:
+ case EventType_DOMNodeInsertedIntoDocument:
+ case EventType_DOMAttrModified:
+ case EventType_DOMCharacterDataModified:
+ {
+ Reference< XMutationEvent > aMEvent(aEvent, UNO_QUERY);
+ // dispatch a mutation event
+ // we need to clone the event in order to have complete control
+ // over the implementation
+ CMutationEvent* pEvent = new CMutationEvent;
+ pEvent->m_target = aEvent->getTarget();
+ pEvent->m_currentTarget = aEvent->getCurrentTarget();
+ pEvent->m_time = aEvent->getTimeStamp();
+ pEvent->initMutationEvent(
+ aType, aMEvent->getBubbles(), aMEvent->getCancelable(),
+ aMEvent->getRelatedNode(), aMEvent->getPrevValue(),
+ aMEvent->getNewValue(), aMEvent->getAttrName(),
+ aMEvent->getAttrChange());
+ Reference< XEvent > xEvent(static_cast< CEvent* >(pEvent));
+
+ // build the path from target node to the root
+ NodeVector captureVector;
+ Reference< XUnoTunnel > aTunnel(xEvent->getTarget(), UNO_QUERY_THROW);
+ xmlNodePtr cur = (xmlNodePtr)aTunnel->getSomething(Sequence< sal_Int8 >());
+ while (cur != NULL)
+ {
+ captureVector.push_back(cur);
+ cur = cur->parent;
+ }
+
+ // the caputre vector now holds the node path from target to root
+ // first we must search for capture listernes in order root to
+ // to target. after that, any target listeners have to be called
+ // then bubbeling phase listeners are called in target to root
+ // order
+ NodeVector::const_iterator inode;
+
+ // start at the root
+ inode = captureVector.end();
+ inode--;
+ if (inode != captureVector.end())
+ {
+ // capturing phase:
+ pEvent->m_phase = PhaseType_CAPTURING_PHASE;
+ while (inode != captureVector.begin())
+ {
+ //pEvent->m_currentTarget = *inode;
+ pEvent->m_currentTarget = Reference< XEventTarget >(CNode::get(*inode));
+ callListeners(*inode, aType, xEvent, sal_True);
+ inode--;
+ }
+
+ // target phase
+ pEvent->m_phase = PhaseType_AT_TARGET;
+ callListeners(*inode, aType, xEvent, sal_False);
+ // bubbeling phase
+ inode++;
+ if (aEvent->getBubbles()) {
+ pEvent->m_phase = PhaseType_BUBBLING_PHASE;
+ while (inode != captureVector.end())
+ {
+ pEvent->m_currentTarget = Reference< XEventTarget >(CNode::get(*inode));
+ callListeners(*inode, aType, xEvent, sal_False);
+ inode++;
+ }
+ }
+ }
+ }
+ break;
+ }
+ return sal_True;
+ }
+}} \ No newline at end of file
diff --git a/unoxml/source/events/eventdispatcher.hxx b/unoxml/source/events/eventdispatcher.hxx
new file mode 100644
index 000000000000..776e0d621279
--- /dev/null
+++ b/unoxml/source/events/eventdispatcher.hxx
@@ -0,0 +1,50 @@
+
+//#include <multimap>
+#include <map>
+#include <vector>
+
+#include <com/sun/star/uno/Reference.h>
+#include <com/sun/star/xml/dom/events/EventType.hpp>
+#include <com/sun/star/xml/dom/events/PhaseType.hpp>
+#include <com/sun/star/xml/dom/events/XEvent.hpp>
+#include "event.hxx"
+
+using namespace com::sun::star::uno;
+using namespace com::sun::star::xml::dom;
+using namespace com::sun::star::xml::dom::events;
+
+namespace DOM { namespace events
+{
+
+typedef std::vector< xmlNodePtr > NodeVector;
+typedef std::multimap< xmlNodePtr, Reference< XEventListener> > ListenerMap;
+typedef std::map<EventType, ListenerMap*> TypeListenerMap;
+
+class CEventDispatcher
+{
+private:
+ static TypeListenerMap captureListeners;
+ static TypeListenerMap targetListeners;
+
+public:
+ static sal_Bool dispatchEvent(xmlNodePtr aNode, const Reference< XEvent >& aEvent);
+
+ static void addListener(
+ xmlNodePtr pNode,
+ EventType aType,
+ const Reference<XEventListener>& aListener,
+ sal_Bool bCapture);
+
+ static void removeListener(
+ xmlNodePtr pNode,
+ EventType aType,
+ const Reference<XEventListener>& aListener,
+ sal_Bool bCapture);
+
+ static void callListeners(
+ xmlNodePtr pNode,
+ EventType aType,
+ const Reference< XEvent >& xEvent,
+ sal_Bool bCapture);
+};
+}} \ No newline at end of file
diff --git a/unoxml/source/events/makefile.mk b/unoxml/source/events/makefile.mk
new file mode 100644
index 000000000000..08d946cf6690
--- /dev/null
+++ b/unoxml/source/events/makefile.mk
@@ -0,0 +1,86 @@
+#*************************************************************************
+#
+# $RCSfile: makefile.mk,v $
+#
+# $Revision: 1.1 $
+#
+# last change: $Author: lo $ $Date: 2004-02-16 16:41:50 $
+#
+# The Contents of this file are made available subject to the terms of
+# either of the following licenses
+#
+# - GNU Lesser General Public License Version 2.1
+# - Sun Industry Standards Source License Version 1.1
+#
+# Sun Microsystems Inc., October, 2000
+#
+# GNU Lesser General Public License Version 2.1
+# =============================================
+# Copyright 2000 by Sun Microsystems, Inc.
+# 901 San Antonio Road, Palo Alto, CA 94303, USA
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1, as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+#
+#
+# Sun Industry Standards Source License Version 1.1
+# =================================================
+# The contents of this file are subject to the Sun Industry Standards
+# Source License Version 1.1 (the "License"); You may not use this file
+# except in compliance with the License. You may obtain a copy of the
+# License at http://www.openoffice.org/license.html.
+#
+# Software provided under this License is provided on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+# See the License for the specific provisions governing your rights and
+# obligations concerning the Software.
+#
+# The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+#
+# Copyright: 2000 by Sun Microsystems, Inc.
+#
+# All Rights Reserved.
+#
+# Contributor(s): _______________________________________
+#
+#
+#
+#*************************************************************************
+
+PRJ=../..
+
+PRJNAME=libxml2
+TARGET=eventsimpl
+ENABLE_EXCEPTIONS=TRUE
+
+# --- Settings -----------------------------------------------------
+
+.INCLUDE : settings.mk
+RSCUPDVER=$(RSCREVISION)(SV$(UPD)$(UPDMINOR))
+
+# --- Files --------------------------------------------------------
+
+SLOFILES =\
+ $(SLO)$/event.obj \
+ $(SLO)$/eventdispatcher.obj \
+ $(SLO)$/mutationevent.obj \
+ $(SLO)$/testlistener.obj
+
+# --- Targets ------------------------------------------------------
+
+.INCLUDE : target.mk
+
+
diff --git a/unoxml/source/events/mutationevent.cxx b/unoxml/source/events/mutationevent.cxx
new file mode 100644
index 000000000000..7b11a719ba01
--- /dev/null
+++ b/unoxml/source/events/mutationevent.cxx
@@ -0,0 +1,100 @@
+#include "mutationevent.hxx"
+
+namespace DOM { namespace events
+{
+ CMutationEvent::~CMutationEvent()
+ {
+ }
+
+ Reference< XNode > SAL_CALL CMutationEvent::getRelatedNode() throw (RuntimeException)
+ {
+ return m_relatedNode;
+ }
+
+ OUString SAL_CALL CMutationEvent::getPrevValue() throw (RuntimeException)
+ {
+ return m_prevValue;
+ }
+
+ OUString SAL_CALL CMutationEvent::getNewValue() throw (RuntimeException)
+ {
+ return m_newValue;
+ }
+
+ OUString SAL_CALL CMutationEvent::getAttrName() throw (RuntimeException)
+ {
+ return m_attrName;
+ }
+
+ AttrChangeType SAL_CALL CMutationEvent::getAttrChange() throw (RuntimeException)
+ {
+ return m_attrChangeType;
+ }
+
+ void SAL_CALL CMutationEvent::initMutationEvent(EventType typeArg,
+ sal_Bool canBubbleArg, sal_Bool cancelableArg,
+ const Reference< XNode >& relatedNodeArg, const OUString& prevValueArg,
+ const OUString& newValueArg, const OUString& attrNameArg,
+ AttrChangeType attrChangeArg) throw (RuntimeException)
+ {
+ initEvent(typeArg, canBubbleArg, cancelableArg);
+ m_relatedNode = relatedNodeArg;
+ m_prevValue = prevValueArg;
+ m_newValue = newValueArg;
+ m_attrName = attrNameArg;
+ m_attrChangeType = attrChangeArg;
+ }
+
+ // delegate to CEvent, since we are inheriting from CEvent and XEvent
+ EventType SAL_CALL CMutationEvent::getType() throw (RuntimeException)
+ {
+ return CEvent::getType();
+ }
+
+ Reference< XEventTarget > SAL_CALL CMutationEvent::getTarget() throw (RuntimeException)
+ {
+ return CEvent::getTarget();
+ }
+
+ Reference< XEventTarget > SAL_CALL CMutationEvent::getCurrentTarget() throw (RuntimeException)
+ {
+ return CEvent::getCurrentTarget();
+ }
+
+ PhaseType SAL_CALL CMutationEvent::getEventPhase() throw (RuntimeException)
+ {
+ return CEvent::getEventPhase();
+ }
+
+ sal_Bool SAL_CALL CMutationEvent::getBubbles() throw (RuntimeException)
+ {
+ return CEvent::getBubbles();
+ }
+
+ sal_Bool SAL_CALL CMutationEvent::getCancelable() throw (RuntimeException)
+ {
+ // mutation events cannot be canceled
+ return sal_False;
+ }
+
+ com::sun::star::util::Time SAL_CALL CMutationEvent::getTimeStamp() throw (RuntimeException)
+ {
+ return CEvent::getTimeStamp();
+ }
+
+ void SAL_CALL CMutationEvent::stopPropagation() throw (RuntimeException)
+ {
+ // do nothing, does not apply to mutation events
+ }
+ void SAL_CALL CMutationEvent::preventDefault() throw (RuntimeException)
+ {
+ // no effect
+ }
+
+ void SAL_CALL CMutationEvent::initEvent( EventType eventTypeArg, sal_Bool canBubbleArg,
+ sal_Bool cancelableArg) throw (RuntimeException)
+ {
+ // base initializer
+ CEvent::initEvent(eventTypeArg, canBubbleArg, cancelableArg);
+ }
+}} \ No newline at end of file
diff --git a/unoxml/source/events/mutationevent.hxx b/unoxml/source/events/mutationevent.hxx
new file mode 100644
index 000000000000..d5c0aa3e8a79
--- /dev/null
+++ b/unoxml/source/events/mutationevent.hxx
@@ -0,0 +1,65 @@
+#ifndef __MUTATIONEVENT_HXX
+#define __MUTATIONEVENT_HXX
+
+#include <sal/types.h>
+#include <cppuhelper/implbase1.hxx>
+#include <cppuhelper/implbase2.hxx>
+#include <cppuhelper/implbase3.hxx>
+#include <com/sun/star/uno/Reference.h>
+#include <com/sun/star/xml/dom/events/EventType.hpp>
+#include <com/sun/star/xml/dom/events/PhaseType.hpp>
+#include <com/sun/star/xml/dom/events/AttrChangeType.hpp>
+#include <com/sun/star/xml/dom/events/XEvent.hpp>
+#include <com/sun/star/xml/dom/events/XMutationEvent.hpp>
+#include "event.hxx"
+
+using namespace rtl;
+
+namespace DOM { namespace events {
+
+class CMutationEvent : public cppu::ImplInheritanceHelper1< CEvent, XMutationEvent >
+{
+ friend class CEventDispatcher;
+protected:
+ Reference< XNode > m_relatedNode;
+ OUString m_prevValue;
+ OUString m_newValue;
+ OUString m_attrName;
+ AttrChangeType m_attrChangeType;
+
+public:
+
+ virtual ~CMutationEvent();
+
+ virtual Reference< XNode > SAL_CALL getRelatedNode() throw (RuntimeException);
+ virtual OUString SAL_CALL getPrevValue() throw (RuntimeException);
+ virtual OUString SAL_CALL getNewValue() throw (RuntimeException);
+ virtual OUString SAL_CALL getAttrName() throw (RuntimeException);
+ virtual AttrChangeType SAL_CALL getAttrChange() throw (RuntimeException);
+ virtual void SAL_CALL initMutationEvent(EventType typeArg,
+ sal_Bool canBubbleArg,
+ sal_Bool cancelableArg,
+ const Reference< XNode >& relatedNodeArg,
+ const OUString& prevValueArg,
+ const OUString& newValueArg,
+ const OUString& attrNameArg,
+ AttrChangeType attrChangeArg) throw (RuntimeException);
+
+ // delegate to CEvent, since we are inheriting from CEvent and XEvent
+ virtual EventType SAL_CALL getType() throw (RuntimeException);
+ virtual Reference< XEventTarget > SAL_CALL getTarget() throw (RuntimeException);
+ virtual Reference< XEventTarget > SAL_CALL getCurrentTarget() throw (RuntimeException);
+ virtual PhaseType SAL_CALL getEventPhase() throw (RuntimeException);
+ virtual sal_Bool SAL_CALL getBubbles() throw (RuntimeException);
+ virtual sal_Bool SAL_CALL getCancelable() throw (RuntimeException);
+ virtual com::sun::star::util::Time SAL_CALL getTimeStamp() throw (RuntimeException);
+ virtual void SAL_CALL stopPropagation() throw (RuntimeException);
+ virtual void SAL_CALL preventDefault() throw (RuntimeException);
+ virtual void SAL_CALL initEvent(
+ EventType eventTypeArg,
+ sal_Bool canBubbleArg,
+ sal_Bool cancelableArg)
+ throw (RuntimeException);
+};
+}}
+#endif
diff --git a/unoxml/source/events/testlistener.cxx b/unoxml/source/events/testlistener.cxx
new file mode 100644
index 000000000000..695507ec9caa
--- /dev/null
+++ b/unoxml/source/events/testlistener.cxx
@@ -0,0 +1,175 @@
+/*************************************************************************
+ *
+ * $RCSfile: testlistener.cxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: lo $ $Date: 2004-02-16 16:41:53 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2004 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+#include <stdio.h>
+
+#include <com/sun/star/lang/IllegalArgumentException.hpp>
+
+#include "testlistener.hxx"
+
+#define U2S(s) OUStringToOString(s, RTL_TEXTENCODING_UTF8).getStr()
+
+
+namespace DOM { namespace events
+{
+
+ Reference< XInterface > CTestListener::_getInstance(const Reference< XMultiServiceFactory >& rSMgr)
+ {
+ // XXX
+ // return static_cast< XXPathAPI* >(new CTestListener());
+ return Reference< XInterface >(static_cast<XEventListener*>(new CTestListener(rSMgr)));
+ }
+
+ const char* CTestListener::aImplementationName = "com.sun.star.comp.xml.dom.events.TestListener";
+ const char* CTestListener::aSupportedServiceNames[] = {
+ "com.sun.star.comp.xml.dom.events.TestListener",
+ NULL
+ };
+
+ OUString CTestListener::_getImplementationName()
+ {
+ return OUString::createFromAscii(aImplementationName);
+ }
+ Sequence<OUString> CTestListener::_getSupportedServiceNames()
+ {
+ Sequence<OUString> aSequence;
+ for (int i=0; aSupportedServiceNames[i]!=NULL; i++) {
+ aSequence.realloc(i+1);
+ aSequence[i]=(OUString::createFromAscii(aSupportedServiceNames[i]));
+ }
+ return aSequence;
+ }
+
+ Sequence< OUString > SAL_CALL CTestListener::getSupportedServiceNames()
+ throw (RuntimeException)
+ {
+ return CTestListener::_getSupportedServiceNames();
+ }
+
+ OUString SAL_CALL CTestListener::getImplementationName()
+ throw (RuntimeException)
+ {
+ return CTestListener::_getImplementationName();
+ }
+
+ sal_Bool SAL_CALL CTestListener::supportsService(const OUString& aServiceName)
+ throw (RuntimeException)
+ {
+ Sequence< OUString > supported = CTestListener::_getSupportedServiceNames();
+ for (sal_Int32 i=0; i<supported.getLength(); i++)
+ {
+ if (supported[i] == aServiceName) return sal_True;
+ }
+ return sal_False;
+ }
+
+ // --- XInitialize
+
+ void SAL_CALL CTestListener::initialize(const Sequence< Any >& args) throw(RuntimeException)
+ {
+ if (args.getLength() < 3) throw IllegalArgumentException(
+ OUString::createFromAscii("Wrong number of arguments"), Reference< XInterface >(), 0);
+
+ Reference <XEventTarget> aTarget;
+ if(! (args[0] >>= aTarget)) throw IllegalArgumentException(
+ OUString::createFromAscii("Illegal argument 1"), Reference< XInterface >(), 1);
+
+ EventType aType = (EventType)0;
+ if (! (args[1] >>= aType)) {
+ sal_Int32 i = 0;
+ if (args[1] >>= i) aType = (EventType)i;
+ else throw IllegalArgumentException(
+ OUString::createFromAscii("Illegal argument 2"), Reference< XInterface >(), 2);
+ }
+
+ sal_Bool bCapture = sal_False;
+ if(! (args[2] >>= bCapture)) throw IllegalArgumentException(
+ OUString::createFromAscii("Illegal argument 3"), Reference< XInterface >(), 3);
+
+ if(! (args[3] >>= m_name)) m_name = OUString::createFromAscii("<unnamed listener>");
+
+ m_target = aTarget;
+ m_type = aType;
+ m_capture = bCapture;
+
+ m_target->addEventListener(m_type, Reference< XEventListener >(this), m_capture);
+
+
+ }
+
+ CTestListener::~CTestListener()
+ {
+ fprintf(stderr, "CTestListener::~CTestListener()\n");
+ if( m_target.is())
+ m_target->removeEventListener(m_type, Reference< XEventListener >(this), m_capture);
+ }
+
+ // --- XEventListener
+
+ void SAL_CALL CTestListener::handleEvent(const Reference< XEvent >& evt) throw (RuntimeException)
+ {
+ FILE* f = fopen("C:\\listener.out", "a");
+ fprintf(f, "CTestListener::handleEvent in %s\n", U2S(m_name));
+ fprintf(f, " type: %d\n\n", evt->getType());
+ fclose(f);
+
+ }
+
+}}
diff --git a/unoxml/source/events/testlistener.hxx b/unoxml/source/events/testlistener.hxx
new file mode 100644
index 000000000000..52fd8d5ed3f8
--- /dev/null
+++ b/unoxml/source/events/testlistener.hxx
@@ -0,0 +1,140 @@
+/*************************************************************************
+ *
+ * $RCSfile: testlistener.hxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: lo $ $Date: 2004-02-16 16:41:54 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2004 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+#ifndef _TESTLISTENER_HXX
+#define _TESTLISTENER_HXX
+
+#include <map>
+
+#include <sal/types.h>
+#include <cppuhelper/implbase3.hxx>
+#include <com/sun/star/uno/Reference.h>
+#include <com/sun/star/uno/Sequence.h>
+
+#include <com/sun/star/uno/XInterface.hpp>
+#include <com/sun/star/uno/Exception.hpp>
+#include <com/sun/star/xml/dom/XNode.hpp>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/lang/XInitialization.hpp>
+#include <com/sun/star/lang/XSingleServiceFactory.hpp>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/lang/XUnoTunnel.hpp>
+#include <com/sun/star/xml/dom/events/XEventTarget.hpp>
+#include <com/sun/star/xml/dom/events/XEventListener.hpp>
+#include <com/sun/star/xml/dom/events/XEvent.hpp>
+#include <com/sun/star/xml/dom/events/EventType.hpp>
+#include <com/sun/star/xml/dom/events/XMutationEvent.hpp>
+
+#include "libxml/tree.h"
+
+using namespace rtl;
+using namespace com::sun::star::uno;
+using namespace com::sun::star::lang;
+using namespace com::sun::star::xml::dom;
+using namespace com::sun::star::xml::dom::events;
+
+namespace DOM { namespace events
+{
+
+ class CTestListener
+ : public ::cppu::WeakImplHelper3< com::sun::star::xml::dom::events::XEventListener, XInitialization, XServiceInfo >
+ {
+
+ private:
+ Reference< XMultiServiceFactory > m_factory;
+ Reference <XEventTarget> m_target;
+ EventType m_type;
+ sal_Bool m_capture;
+ OUString m_name;
+
+ public:
+
+ // static helpers for service info and component management
+ static const char* aImplementationName;
+ static const char* aSupportedServiceNames[];
+ static OUString _getImplementationName();
+ static Sequence< OUString > _getSupportedServiceNames();
+ static Reference< XInterface > _getInstance(const Reference< XMultiServiceFactory >& rSMgr);
+
+ CTestListener(const Reference< XMultiServiceFactory >& rSMgr)
+ : m_factory(rSMgr){};
+
+ virtual ~CTestListener();
+
+ // XServiceInfo
+ virtual OUString SAL_CALL getImplementationName()
+ throw (RuntimeException);
+ virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName)
+ throw (RuntimeException);
+ virtual Sequence< OUString > SAL_CALL getSupportedServiceNames ()
+ throw (RuntimeException);
+
+
+ // XEventListener
+ virtual void SAL_CALL initialize(const Sequence< Any >& args) throw (RuntimeException);
+
+ virtual void SAL_CALL handleEvent(const Reference< XEvent >& evt) throw (RuntimeException);
+
+
+ };
+}}
+
+#endif