1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef EVENT_EVENT_DISPATCHER_HXX 25 #define EVENT_EVENT_DISPATCHER_HXX 26 27 #include <map> 28 #include <vector> 29 30 #include <libxml/tree.h> 31 32 #include <rtl/ustring.hxx> 33 34 #include <com/sun/star/uno/Reference.h> 35 #include <com/sun/star/xml/dom/XNode.hpp> 36 #include <com/sun/star/xml/dom/events/EventType.hpp> 37 #include <com/sun/star/xml/dom/events/PhaseType.hpp> 38 #include <com/sun/star/xml/dom/events/XEvent.hpp> 39 40 41 using namespace com::sun::star::uno; 42 using namespace com::sun::star::xml::dom; 43 using namespace com::sun::star::xml::dom::events; 44 45 namespace DOM { 46 47 class CDocument; 48 49 namespace events { 50 51 typedef std::multimap< xmlNodePtr, Reference< com::sun::star::xml::dom::events::XEventListener> > ListenerMap; 52 typedef std::map< ::rtl::OUString, ListenerMap*> TypeListenerMap; 53 typedef std::vector<ListenerMap::value_type> ListenerPairVector; 54 55 class CEventDispatcher 56 { 57 private: 58 TypeListenerMap m_CaptureListeners; 59 TypeListenerMap m_TargetListeners; 60 61 public: 62 void addListener( 63 xmlNodePtr pNode, 64 ::rtl::OUString aType, 65 const Reference<com::sun::star::xml::dom::events::XEventListener>& aListener, 66 sal_Bool bCapture); 67 68 void removeListener( 69 xmlNodePtr pNode, 70 ::rtl::OUString aType, 71 const Reference<com::sun::star::xml::dom::events::XEventListener>& aListener, 72 sal_Bool bCapture); 73 74 static void callListeners( 75 TypeListenerMap const& rTMap, 76 xmlNodePtr const pNode, 77 ::rtl::OUString aType, 78 const Reference< XEvent >& xEvent); 79 80 bool dispatchEvent( 81 DOM::CDocument & rDocument, 82 ::osl::Mutex & rMutex, 83 xmlNodePtr const pNode, 84 Reference<XNode> const& xNode, 85 Reference< XEvent > const& xEvent) const; 86 }; 87 88 }} 89 90 #endif 91 92