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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_comphelper.hxx"
26
27 #include "comphelper/accessibleeventbuffer.hxx"
28
29 #include "com/sun/star/uno/Reference.hxx"
30 #include "com/sun/star/uno/RuntimeException.hpp"
31 #include "com/sun/star/uno/Sequence.hxx"
32 #include "com/sun/star/uno/XInterface.hpp"
33 #include "com/sun/star/accessibility/AccessibleEventObject.hpp"
34 #include "com/sun/star/accessibility/XAccessibleEventListener.hpp"
35 #include "osl/diagnose.h"
36 #include "rtl/textenc.h"
37 #include "rtl/ustring.hxx"
38 #include "sal/types.h"
39
40 namespace css = ::com::sun::star;
41
42 using comphelper::AccessibleEventBuffer;
43
44 struct AccessibleEventBuffer::Entry
45 {
EntryAccessibleEventBuffer::Entry46 inline Entry(::css::accessibility::AccessibleEventObject const & rEvent,
47 ::css::uno::Sequence< ::css::uno::Reference<
48 ::css::uno::XInterface > > const & rListeners):
49 m_aEvent(rEvent), m_aListeners(rListeners) {}
50
51 ::css::accessibility::AccessibleEventObject m_aEvent;
52
53 ::css::uno::Sequence<
54 ::css::uno::Reference< ::css::uno::XInterface > > m_aListeners;
55 };
56
AccessibleEventBuffer()57 AccessibleEventBuffer::AccessibleEventBuffer()
58 {}
59
AccessibleEventBuffer(AccessibleEventBuffer const & rOther)60 AccessibleEventBuffer::AccessibleEventBuffer(
61 AccessibleEventBuffer const & rOther):
62 m_aEntries(rOther.m_aEntries)
63 {}
64
~AccessibleEventBuffer()65 AccessibleEventBuffer::~AccessibleEventBuffer()
66 {}
67
68 AccessibleEventBuffer
operator =(AccessibleEventBuffer const & rOther)69 AccessibleEventBuffer::operator =(AccessibleEventBuffer const & rOther)
70 {
71 m_aEntries = rOther.m_aEntries;
72 return *this;
73 }
74
addEvent(::css::accessibility::AccessibleEventObject const & rEvent,::css::uno::Sequence<::css::uno::Reference<::css::uno::XInterface>> const & rListeners)75 void AccessibleEventBuffer::addEvent(
76 ::css::accessibility::AccessibleEventObject const & rEvent,
77 ::css::uno::Sequence< ::css::uno::Reference< ::css::uno::XInterface > >
78 const & rListeners)
79 {
80 m_aEntries.push_back(Entry(rEvent, rListeners));
81 }
82
sendEvents() const83 void AccessibleEventBuffer::sendEvents() const
84 {
85 for (Entries::const_iterator aIt(m_aEntries.begin());
86 aIt != m_aEntries.end(); ++aIt)
87 for (::sal_Int32 i = 0; i < aIt->m_aListeners.getLength(); ++i)
88 {
89 ::css::uno::Reference<
90 ::css::accessibility::XAccessibleEventListener > xListener(
91 aIt->m_aListeners[i], ::css::uno::UNO_QUERY);
92 if (xListener.is())
93 try
94 {
95 xListener->notifyEvent(aIt->m_aEvent);
96 }
97 catch (::css::uno::RuntimeException & rEx)
98 {
99 OSL_TRACE(
100 "comphelper::AccessibleEventBuffer::sendEvents:"
101 " caught %s\n",
102 ::rtl::OUStringToOString(
103 rEx.Message, RTL_TEXTENCODING_UTF8).getStr());
104 }
105 }
106 }
107