diff options
author | Lars Oppermann <lo@openoffice.org> | 2004-02-16 15:41:55 +0000 |
---|---|---|
committer | Lars Oppermann <lo@openoffice.org> | 2004-02-16 15:41:55 +0000 |
commit | efed7968470109147a4653d6f6bf60e422a8d896 (patch) | |
tree | 7086a30f3cf5b048788db5d821d34e9ea1ede408 /unoxml | |
parent | d24656331f4342648639ecf77542f7ca24c8d854 (diff) |
event handling
Diffstat (limited to 'unoxml')
-rw-r--r-- | unoxml/prj/build.lst | 1 | ||||
-rw-r--r-- | unoxml/source/dom/attr.hxx | 6 | ||||
-rw-r--r-- | unoxml/source/dom/characterdata.cxx | 34 | ||||
-rw-r--r-- | unoxml/source/dom/characterdata.hxx | 7 | ||||
-rw-r--r-- | unoxml/source/dom/document.cxx | 28 | ||||
-rw-r--r-- | unoxml/source/dom/element.cxx | 67 | ||||
-rw-r--r-- | unoxml/source/dom/node.cxx | 93 | ||||
-rw-r--r-- | unoxml/source/dom/node.hxx | 25 | ||||
-rw-r--r-- | unoxml/source/events/event.cxx | 61 | ||||
-rw-r--r-- | unoxml/source/events/event.hxx | 67 | ||||
-rw-r--r-- | unoxml/source/events/eventdispatcher.cxx | 159 | ||||
-rw-r--r-- | unoxml/source/events/eventdispatcher.hxx | 50 | ||||
-rw-r--r-- | unoxml/source/events/makefile.mk | 86 | ||||
-rw-r--r-- | unoxml/source/events/mutationevent.cxx | 100 | ||||
-rw-r--r-- | unoxml/source/events/mutationevent.hxx | 65 | ||||
-rw-r--r-- | unoxml/source/events/testlistener.cxx | 175 | ||||
-rw-r--r-- | unoxml/source/events/testlistener.hxx | 140 | ||||
-rw-r--r-- | unoxml/source/service/makefile.mk | 7 | ||||
-rw-r--r-- | unoxml/source/service/services.cxx | 21 |
19 files changed, 1166 insertions, 26 deletions
diff --git a/unoxml/prj/build.lst b/unoxml/prj/build.lst index 0f42c48d052c..35b52b6a658e 100644 --- a/unoxml/prj/build.lst +++ b/unoxml/prj/build.lst @@ -1,4 +1,5 @@ ux unoxml : libxml2 NULL
ux unoxml\source\dom nmake - all ux_dom NULL
ux unoxml\source\xpath nmake - all ux_xpath ux_dom NULL
+ux unoxml\source\events nmake - all ux_events ux_dom NULL
ux unoxml\source\service nmake - all ux_service ux_dom ux_xpath NULL
diff --git a/unoxml/source/dom/attr.hxx b/unoxml/source/dom/attr.hxx index 04c4a6ee901f..f53aeb259f15 100644 --- a/unoxml/source/dom/attr.hxx +++ b/unoxml/source/dom/attr.hxx @@ -2,9 +2,9 @@ *
* $RCSfile: attr.hxx,v $
*
- * $Revision: 1.1 $
+ * $Revision: 1.2 $
*
- * last change: $Author: lo $ $Date: 2004-01-28 16:30:51 $
+ * last change: $Author: lo $ $Date: 2004-02-16 16:41:46 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -234,7 +234,7 @@ namespace DOM virtual void SAL_CALL setNodeValue(const OUString& nodeValue)
throw (RuntimeException)
{
- return CNode::setNodeValue(nodeValue);
+ return setValue(nodeValue);
}
virtual void SAL_CALL setPrefix(const OUString& prefix)
throw (RuntimeException)
diff --git a/unoxml/source/dom/characterdata.cxx b/unoxml/source/dom/characterdata.cxx index d3e4fe05d427..9c17464f4c1d 100644 --- a/unoxml/source/dom/characterdata.cxx +++ b/unoxml/source/dom/characterdata.cxx @@ -2,9 +2,9 @@ *
* $RCSfile: characterdata.cxx,v $
*
- * $Revision: 1.1 $
+ * $Revision: 1.2 $
*
- * last change: $Author: lo $ $Date: 2004-01-28 16:31:01 $
+ * last change: $Author: lo $ $Date: 2004-02-16 16:41:46 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -61,12 +61,24 @@ #include "characterdata.hxx"
+#include "../events/mutationevent.hxx"
+
namespace DOM
{
CCharacterData::CCharacterData()
{}
+ void CCharacterData::_dispatchEvent(const OUString& prevValue, const OUString& newValue)
+ {
+ events::CMutationEvent *pEvent = new events::CMutationEvent;
+ pEvent->initMutationEvent(EventType_DOMCharacterDataModified, sal_True,
+ sal_False, Reference< XNode >(),
+ prevValue, newValue, OUString(), (AttrChangeType)0 );
+ pEvent->m_target = Reference< XEventTarget >(this);
+ dispatchEvent(Reference< XEvent >(static_cast< events::CEvent* >(pEvent)));
+ }
+
void CCharacterData::init_characterdata(const xmlNodePtr aNodePtr)
{
init_node(aNodePtr);
@@ -80,7 +92,10 @@ namespace DOM {
if (m_aNodePtr != NULL)
{
+ OUString oldValue((char*)m_aNodePtr->content, strlen((char*)m_aNodePtr->content), RTL_TEXTENCODING_UTF8);
xmlNodeAddContent(m_aNodePtr, (const xmlChar*)(OUStringToOString(arg, RTL_TEXTENCODING_UTF8).getStr()));
+ OUString newValue((char*)m_aNodePtr->content, strlen((char*)m_aNodePtr->content), RTL_TEXTENCODING_UTF8);
+ _dispatchEvent(oldValue, newValue);
}
}
@@ -102,7 +117,11 @@ namespace DOM OUString tmp2 = tmp.copy(0, offset);
tmp2 += tmp.copy(offset+count, tmp.getLength() - (offset+count));
+ OUString oldValue((char*)m_aNodePtr->content, strlen((char*)m_aNodePtr->content), RTL_TEXTENCODING_UTF8);
xmlNodeSetContent(m_aNodePtr, (const xmlChar*)(OUStringToOString(tmp2, RTL_TEXTENCODING_UTF8).getStr()));
+ OUString newValue((char*)m_aNodePtr->content, strlen((char*)m_aNodePtr->content), RTL_TEXTENCODING_UTF8);
+ _dispatchEvent(oldValue, newValue);
+
}
}
@@ -152,7 +171,11 @@ namespace DOM OUString tmp2 = tmp.copy(0, offset);
tmp2 += arg;
tmp2 += tmp.copy(offset, tmp.getLength() - offset);
+ OUString oldValue((char*)m_aNodePtr->content, strlen((char*)m_aNodePtr->content), RTL_TEXTENCODING_UTF8);
xmlNodeSetContent(m_aNodePtr, (const xmlChar*)(OUStringToOString(tmp2, RTL_TEXTENCODING_UTF8).getStr()));
+ OUString newValue((char*)m_aNodePtr->content, strlen((char*)m_aNodePtr->content), RTL_TEXTENCODING_UTF8);
+ _dispatchEvent(oldValue, newValue);
+
}
}
@@ -177,7 +200,10 @@ namespace DOM OUString tmp2 = tmp.copy(0, offset);
tmp2 += arg;
tmp2 += tmp.copy(offset+count, tmp.getLength() - (offset+count));
+ OUString oldValue((char*)m_aNodePtr->content, strlen((char*)m_aNodePtr->content), RTL_TEXTENCODING_UTF8);
xmlNodeSetContent(m_aNodePtr, (const xmlChar*)(OUStringToOString(tmp2, RTL_TEXTENCODING_UTF8).getStr()));
+ OUString newValue((char*)m_aNodePtr->content, strlen((char*)m_aNodePtr->content), RTL_TEXTENCODING_UTF8);
+ _dispatchEvent(oldValue, newValue);
}
}
@@ -189,7 +215,11 @@ namespace DOM {
if (m_aNodePtr != NULL)
{
+ OUString oldValue((char*)m_aNodePtr->content, strlen((char*)m_aNodePtr->content), RTL_TEXTENCODING_UTF8);
xmlNodeSetContent(m_aNodePtr, (const xmlChar*)(OUStringToOString(data, RTL_TEXTENCODING_UTF8).getStr()));
+ OUString newValue((char*)m_aNodePtr->content, strlen((char*)m_aNodePtr->content), RTL_TEXTENCODING_UTF8);
+ _dispatchEvent(oldValue, newValue);
+
}
}
diff --git a/unoxml/source/dom/characterdata.hxx b/unoxml/source/dom/characterdata.hxx index d2727d72a1af..4590342d6f42 100644 --- a/unoxml/source/dom/characterdata.hxx +++ b/unoxml/source/dom/characterdata.hxx @@ -2,9 +2,9 @@ *
* $RCSfile: characterdata.hxx,v $
*
- * $Revision: 1.1 $
+ * $Revision: 1.2 $
*
- * last change: $Author: lo $ $Date: 2004-01-28 16:31:02 $
+ * last change: $Author: lo $ $Date: 2004-02-16 16:41:46 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -82,9 +82,12 @@ namespace DOM {
class CCharacterData : public cppu::ImplInheritanceHelper1< CNode, XCharacterData >
{
+
+
protected:
CCharacterData();
void init_characterdata(const xmlNodePtr aNodePtr);
+ void _dispatchEvent(const OUString& prevValue, const OUString& newValue);
public:
/**
diff --git a/unoxml/source/dom/document.cxx b/unoxml/source/dom/document.cxx index e04a9efe6220..5b32b54f75f5 100644 --- a/unoxml/source/dom/document.cxx +++ b/unoxml/source/dom/document.cxx @@ -2,9 +2,9 @@ *
* $RCSfile: document.cxx,v $
*
- * $Revision: 1.1 $
+ * $Revision: 1.2 $
*
- * last change: $Author: lo $ $Date: 2004-01-28 16:31:09 $
+ * last change: $Author: lo $ $Date: 2004-02-16 16:41:47 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -73,6 +73,8 @@ #include "elementlist.hxx"
#include "domimplementation.hxx"
+#include "../events/mutationevent.hxx"
+
namespace DOM
{
@@ -496,6 +498,28 @@ namespace DOM aNode->appendChild(ic);
}
}
+
+ /* DOMNodeInsertedIntoDocument
+ * Fired when a node is being inserted into a document,
+ * either through direct insertion of the Node or insertion of a
+ * subtree in which it is contained. This event is dispatched after
+ * the insertion has taken place. The target of this event is the node
+ * being inserted. If the Node is being directly inserted the DOMNodeInserted
+ * event will fire before the DOMNodeInsertedIntoDocument event.
+ * Bubbles: No
+ * Cancelable: No
+ * Context Info: None
+ */
+ if (aNode.is())
+ {
+ events::CMutationEvent *pEvent = new events::CMutationEvent;
+ pEvent->initMutationEvent(EventType_DOMNodeInsertedIntoDocument, sal_True,
+ sal_False, Reference< XNode >(),
+ OUString(), OUString(), OUString(), (AttrChangeType)0 );
+ pEvent->m_target = Reference< XEventTarget >(aNode, UNO_QUERY);
+ dispatchEvent(Reference< XEvent >(static_cast< events::CEvent* >(pEvent)));
+ }
+
return aNode;
}
OUString SAL_CALL CDocument::getNodeName()throw (RuntimeException)
diff --git a/unoxml/source/dom/element.cxx b/unoxml/source/dom/element.cxx index 393ce2f54b36..04163df76d45 100644 --- a/unoxml/source/dom/element.cxx +++ b/unoxml/source/dom/element.cxx @@ -2,9 +2,9 @@ *
* $RCSfile: element.cxx,v $
*
- * $Revision: 1.1 $
+ * $Revision: 1.2 $
*
- * last change: $Author: lo $ $Date: 2004-01-28 16:31:23 $
+ * last change: $Author: lo $ $Date: 2004-02-16 16:41:47 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -63,6 +63,7 @@ #include "attr.hxx"
#include "elementlist.hxx"
#include "attributesmap.hxx"
+#include "../events/mutationevent.hxx"
namespace DOM
{
@@ -308,6 +309,18 @@ namespace DOM // get the new attr node
aAttr = Reference< XAttr >(static_cast< CAttr* >(CNode::get((xmlNodePtr)res)));
}
+
+ if (aAttr.is())
+ {
+ // attribute adition event
+ // dispatch DOMAttrModified event
+ events::CMutationEvent *pEvent = new events::CMutationEvent;
+ pEvent->initMutationEvent(EventType_DOMAttrModified, sal_True,
+ sal_False, Reference< XNode >(aAttr, UNO_QUERY),
+ OUString(), aAttr->getValue(), aAttr->getName(), AttrChangeType_ADDITION);
+ pEvent->m_target = Reference< XEventTarget >(this);
+ dispatchEvent(Reference< XEvent >(static_cast< events::CEvent* >(pEvent)));
+ }
return aAttr;
}
@@ -338,8 +351,30 @@ namespace DOM xmlChar *xValue = (xmlChar*)o2.getStr();
if (m_aNodePtr != NULL)
{
- xmlNewProp(m_aNodePtr, xName, xValue);
- }
+ OUString oldValue;
+ AttrChangeType aChangeType = AttrChangeType_MODIFICATION;
+ xmlChar *xOld = xmlGetProp(m_aNodePtr, xName);
+ if (xOld == NULL)
+ {
+ aChangeType = AttrChangeType_ADDITION;
+ xmlNewProp(m_aNodePtr, xName, xValue);
+ }
+ else
+ {
+ oldValue = OUString((char*)xOld, strlen((char*)xOld), RTL_TEXTENCODING_UTF8);
+ xmlSetProp(m_aNodePtr, xName, xValue);
+ }
+
+ // dispatch DOMAttrModified event
+
+
+ events::CMutationEvent *pEvent = new events::CMutationEvent;
+ pEvent->initMutationEvent(EventType_DOMAttrModified, sal_True,
+ sal_False, Reference< XNode >(getAttributeNode(name), UNO_QUERY),
+ oldValue, value, name, aChangeType);
+ pEvent->m_target = Reference< XEventTarget >(this);
+ dispatchEvent(Reference< XEvent >(static_cast< events::CEvent* >(pEvent)));
+ }
}
/**
@@ -386,11 +421,33 @@ namespace DOM if (strcmp((char*)pNs->href, (char*)xURI) == 0)
{
// found namespace matches
- xmlNewNsProp(m_aNodePtr, pNs, xLName, xValue);
+
+ OUString oldValue;
+ AttrChangeType aChangeType = AttrChangeType_MODIFICATION;
+ xmlChar *xOld = xmlGetNsProp(m_aNodePtr, xLName, pNs->href);
+ if (xOld == NULL)
+ {
+ aChangeType = AttrChangeType_ADDITION;
+ xmlNewNsProp(m_aNodePtr, pNs, xLName, xValue);
+ }
+ else
+ {
+ oldValue = OUString((char *)xOld, strlen((char *)xOld), RTL_TEXTENCODING_UTF8);
+ xmlSetNsProp(m_aNodePtr, pNs, xLName, xValue);
+ }
+ // dispatch DOMAttrModified event
+ events::CMutationEvent *pEvent = new events::CMutationEvent;
+ pEvent->initMutationEvent(EventType_DOMAttrModified, sal_True, sal_False,
+ Reference< XNode >(getAttributeNodeNS(namespaceURI, OUString((char*)xLName, strlen((char*)xLName), RTL_TEXTENCODING_UTF8)), UNO_QUERY),
+ oldValue, value, qualifiedName, aChangeType);
+ pEvent->m_target = Reference< XEventTarget >(this);
+ dispatchEvent(Reference< XEvent >(static_cast< events::CEvent* >(pEvent)));
+
} else {
// ambigious ns prefix
throw RuntimeException();
}
+
}
}
diff --git a/unoxml/source/dom/node.cxx b/unoxml/source/dom/node.cxx index b867effe3ef9..065c5a3a447d 100644 --- a/unoxml/source/dom/node.cxx +++ b/unoxml/source/dom/node.cxx @@ -2,9 +2,9 @@ *
* $RCSfile: node.cxx,v $
*
- * $Revision: 1.1 $
+ * $Revision: 1.2 $
*
- * last change: $Author: lo $ $Date: 2004-01-28 16:31:36 $
+ * last change: $Author: lo $ $Date: 2004-02-16 16:41:47 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -75,6 +75,9 @@ #include "childlist.hxx"
#include "attr.hxx"
+#include "../events/eventdispatcher.hxx"
+#include "../events/mutationevent.hxx"
+
namespace DOM
{
nodemap_t CNode::theNodeMap;
@@ -275,6 +278,20 @@ namespace DOM Reference< XUnoTunnel > tun(newChild, UNO_QUERY);
xmlNodePtr cur = (xmlNodePtr)(tun->getSomething(Sequence <sal_Int8>()));
+ // error checks:
+ // from other document
+ if (cur->doc != m_aNodePtr->doc)
+ throw (RuntimeException(OUString::createFromAscii(
+ "appended node belongs to other document"), Reference<XInterface>()));
+ // same node
+ if (cur == m_aNodePtr)
+ throw (RuntimeException(OUString::createFromAscii(
+ "appended node is same as parent"), Reference<XInterface>()));
+ // already has parant and is not attribute
+ if (cur->parent != NULL && cur->type != XML_ATTRIBUTE_NODE)
+ throw (RuntimeException(OUString::createFromAscii(
+ "appended node has other parent"), Reference<XInterface>()));
+
// check whether this is an attribute node so we remove it's
// carrier node
xmlNodePtr res = NULL;
@@ -309,6 +326,19 @@ namespace DOM aNode = Reference< XNode>(CNode::get(res));
}
//XXX check for errors
+
+ // dispatch DOMNodeInserted event, target is the new node
+ // this node is the related node
+ // does bubble
+ if (aNode.is())
+ {
+ events::CMutationEvent *pEvent = new events::CMutationEvent;
+ pEvent->initMutationEvent(EventType_DOMNodeInserted, sal_True,
+ sal_False, Reference< XNode >(CNode::get(m_aNodePtr)),
+ OUString(), OUString(), OUString(), (AttrChangeType)0 );
+ pEvent->m_target = Reference< XEventTarget >(aNode, UNO_QUERY);
+ dispatchEvent(Reference< XEvent >(static_cast< events::CEvent* >(pEvent)));
+ }
return aNode;
}
@@ -643,6 +673,24 @@ namespace DOM }
cur = cur->next;
}
+
+ /*DOMNodeRemoved
+ * Fired when a node is being removed from its parent node.
+ * This event is dispatched before the node is removed from the tree.
+ * The target of this event is the node being removed.
+ * Bubbles: Yes
+ * Cancelable: No
+ * Context Info: relatedNode holds the parent node
+ */
+ if (oldChild.is())
+ {
+ events::CMutationEvent *pEvent = new events::CMutationEvent;
+ pEvent->initMutationEvent(EventType_DOMNodeRemoved, sal_True,
+ sal_False, Reference< XNode >(CNode::get(m_aNodePtr)),
+ OUString(), OUString(), OUString(), (AttrChangeType)0 );
+ pEvent->m_target = Reference< XEventTarget >(oldChild, UNO_QUERY);
+ dispatchEvent(Reference< XEvent >(static_cast< events::CEvent* >(pEvent)));
+ }
return oldChild;
}
@@ -656,6 +704,10 @@ namespace DOM {
// XXX check node types
+
+ Reference< XNode > aNode = removeChild(oldChild);
+ appendChild(newChild);
+/*
Reference< XUnoTunnel > tOld(oldChild, UNO_QUERY);
xmlNodePtr pOld = (xmlNodePtr)tOld->getSomething(Sequence< sal_Int8>());
Reference< XUnoTunnel > tNew(newChild, UNO_QUERY);
@@ -678,7 +730,17 @@ namespace DOM }
cur = cur->next;
}
- return oldChild;
+*/
+ // dispatch DOMSubtreeModified
+ // target is _this_ node
+ events::CMutationEvent *pEvent = new events::CMutationEvent;
+ pEvent->initMutationEvent(EventType_DOMSubtreeModified, sal_True,
+ sal_False, Reference< XNode >(),
+ OUString(), OUString(), OUString(), (AttrChangeType)0 );
+ pEvent->m_target = Reference< XEventTarget >(this);
+ dispatchEvent(Reference< XEvent >(static_cast< events::CEvent* >(pEvent)));
+
+ return aNode;
}
/**
@@ -718,5 +780,30 @@ namespace DOM // XXX check ID
return (sal_Int64)m_aNodePtr;
}
+
+
+ // --- XEventTarget
+ void SAL_CALL CNode::addEventListener(EventType eventType,
+ const Reference< XEventListener >& listener,
+ sal_Bool useCapture)
+ throw (RuntimeException)
+ {
+ events::CEventDispatcher::addListener(m_aNodePtr, eventType, listener, useCapture);
+ }
+
+ void SAL_CALL CNode::removeEventListener(EventType eventType,
+ const Reference< XEventListener >& listener,
+ sal_Bool useCapture)
+ throw (RuntimeException)
+ {
+ events::CEventDispatcher::removeListener(m_aNodePtr, eventType, listener, useCapture);
+ }
+
+ sal_Bool SAL_CALL CNode::dispatchEvent(const Reference< XEvent >& evt)
+ throw(EventException)
+ {
+ events::CEventDispatcher::dispatchEvent(m_aNodePtr, evt);
+ return sal_True;
+ }
}
diff --git a/unoxml/source/dom/node.hxx b/unoxml/source/dom/node.hxx index 3425d0d962b1..06edfece7e09 100644 --- a/unoxml/source/dom/node.hxx +++ b/unoxml/source/dom/node.hxx @@ -2,9 +2,9 @@ *
* $RCSfile: node.hxx,v $
*
- * $Revision: 1.1 $
+ * $Revision: 1.2 $
*
- * last change: $Author: lo $ $Date: 2004-01-28 16:31:37 $
+ * last change: $Author: lo $ $Date: 2004-02-16 16:41:47 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -66,21 +66,24 @@ #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/XNode.hpp>
#include <com/sun/star/xml/dom/XNodeList.hpp>
#include <com/sun/star/xml/dom/XNamedNodeMap.hpp>
#include <com/sun/star/xml/dom/NodeType.hpp>
+#include <com/sun/star/xml/dom/events/XEventTarget.hpp>
#include <com/sun/star/lang/XUnoTunnel.hpp>
#include <com/sun/star/uno/Sequence.h>
-
+#include <com/sun/star/xml/dom/events/XEventTarget.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
{
@@ -88,7 +91,7 @@ namespace DOM typedef std::map< const xmlNodePtr, CNode* > nodemap_t;
- class CNode : public cppu::WeakImplHelper2< XNode, XUnoTunnel >
+ class CNode : public cppu::WeakImplHelper3< XNode, XUnoTunnel, XEventTarget >
{
friend class CDocument;
friend class CElement;
@@ -290,6 +293,20 @@ namespace DOM // --- XUnoTunnel
virtual sal_Int64 SAL_CALL getSomething(const Sequence< sal_Int8 >& id) throw (RuntimeException);
+ // --- XEventTarget
+ virtual void SAL_CALL addEventListener(EventType eventType,
+ const Reference< XEventListener >& listener,
+ sal_Bool useCapture)
+ throw (RuntimeException);
+
+ virtual void SAL_CALL removeEventListener(EventType eventType,
+ const Reference< XEventListener >& listener,
+ sal_Bool useCapture)
+ throw (RuntimeException);
+
+ virtual sal_Bool SAL_CALL dispatchEvent(const Reference< XEvent >& evt)
+ throw(EventException);
+
};
}
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
diff --git a/unoxml/source/service/makefile.mk b/unoxml/source/service/makefile.mk index 9fc907879a2b..4e79e3681d50 100644 --- a/unoxml/source/service/makefile.mk +++ b/unoxml/source/service/makefile.mk @@ -2,9 +2,9 @@ #
# $RCSfile: makefile.mk,v $
#
-# $Revision: 1.1 $
+# $Revision: 1.2 $
#
-# last change: $Author: lo $ $Date: 2004-01-28 16:31:51 $
+# 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
@@ -91,7 +91,8 @@ DEF1NAME=$(SHL1TARGET) SHL1LIBS= \
$(SLB)$/domimpl.lib \
- $(SLB)$/xpathimpl.lib
+ $(SLB)$/xpathimpl.lib \
+ $(SLB)$/eventsimpl.lib
.IF "$(GUI)" == "WNT"
SHL1STDLIBS= \
diff --git a/unoxml/source/service/services.cxx b/unoxml/source/service/services.cxx index ea44bfe0bed6..d8d41f2a334c 100644 --- a/unoxml/source/service/services.cxx +++ b/unoxml/source/service/services.cxx @@ -2,9 +2,9 @@ *
* $RCSfile: services.cxx,v $
*
- * $Revision: 1.1 $
+ * $Revision: 1.2 $
*
- * last change: $Author: lo $ $Date: 2004-01-28 16:31:53 $
+ * last change: $Author: lo $ $Date: 2004-02-16 16:41:55 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -72,10 +72,12 @@ #include "../dom/documentbuilder.hxx"
#include "../dom/saxbuilder.hxx"
#include "../xpath/xpathapi.hxx"
+#include "../events/testlistener.hxx"
extern "C"
{
using namespace ::DOM;
+using namespace ::DOM::events;
using namespace ::XPath;
using namespace ::rtl;
using namespace ::com::sun::star::uno;
@@ -116,6 +118,14 @@ component_writeInfo(void *pServiceManager, void *pRegistryKey) xNewKey = xKey->createKey(aImpl);
xNewKey->createKey(CXPathAPI::_getSupportedServiceNames()[0]);
+ // register EventTest service
+ aImpl = OUString(RTL_CONSTASCII_USTRINGPARAM("/"));
+ aImpl += CTestListener::_getImplementationName();
+ aImpl += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES"));
+ xNewKey = xKey->createKey(aImpl);
+ xNewKey->createKey(CTestListener::_getSupportedServiceNames()[0]);
+
+
return sal_True;
}
@@ -151,6 +161,13 @@ component_getFactory(const sal_Char *pImplementationName, void *pServiceManager, xServiceManager, CXPathAPI::_getImplementationName(),
CXPathAPI::_getInstance, CXPathAPI::_getSupportedServiceNames()));
}
+ else if (CTestListener::_getImplementationName().compareToAscii( pImplementationName ) == 0 )
+ {
+ xFactory = Reference< XSingleServiceFactory >(
+ cppu::createSingleFactory(
+ xServiceManager, CTestListener::_getImplementationName(),
+ CTestListener::_getInstance, CTestListener::_getSupportedServiceNames()));
+ }
// Factory is valid - service was found.
if ( xFactory.is() )
|