1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_comphelper.hxx"
30 
31 #include "comphelper/accessibleeventbuffer.hxx"
32 
33 #include "com/sun/star/uno/Reference.hxx"
34 #include "com/sun/star/uno/RuntimeException.hpp"
35 #include "com/sun/star/uno/Sequence.hxx"
36 #include "com/sun/star/uno/XInterface.hpp"
37 #include "com/sun/star/accessibility/AccessibleEventObject.hpp"
38 #include "com/sun/star/accessibility/XAccessibleEventListener.hpp"
39 #include "osl/diagnose.h"
40 #include "rtl/textenc.h"
41 #include "rtl/ustring.hxx"
42 #include "sal/types.h"
43 
44 namespace css = ::com::sun::star;
45 
46 using comphelper::AccessibleEventBuffer;
47 
48 struct AccessibleEventBuffer::Entry
49 {
50     inline Entry(::css::accessibility::AccessibleEventObject const & rEvent,
51                  ::css::uno::Sequence< ::css::uno::Reference<
52                  ::css::uno::XInterface > > const & rListeners):
53         m_aEvent(rEvent), m_aListeners(rListeners) {}
54 
55     ::css::accessibility::AccessibleEventObject m_aEvent;
56 
57     ::css::uno::Sequence<
58         ::css::uno::Reference< ::css::uno::XInterface > > m_aListeners;
59 };
60 
61 AccessibleEventBuffer::AccessibleEventBuffer()
62 {}
63 
64 AccessibleEventBuffer::AccessibleEventBuffer(
65     AccessibleEventBuffer const & rOther):
66     m_aEntries(rOther.m_aEntries)
67 {}
68 
69 AccessibleEventBuffer::~AccessibleEventBuffer()
70 {}
71 
72 AccessibleEventBuffer
73 AccessibleEventBuffer::operator =(AccessibleEventBuffer const & rOther)
74 {
75     m_aEntries = rOther.m_aEntries;
76     return *this;
77 }
78 
79 void AccessibleEventBuffer::addEvent(
80     ::css::accessibility::AccessibleEventObject const & rEvent,
81     ::css::uno::Sequence< ::css::uno::Reference< ::css::uno::XInterface > >
82     const & rListeners)
83 {
84     m_aEntries.push_back(Entry(rEvent, rListeners));
85 }
86 
87 void AccessibleEventBuffer::sendEvents() const
88 {
89     for (Entries::const_iterator aIt(m_aEntries.begin());
90          aIt != m_aEntries.end(); ++aIt)
91         for (::sal_Int32 i = 0; i < aIt->m_aListeners.getLength(); ++i)
92         {
93             ::css::uno::Reference<
94                   ::css::accessibility::XAccessibleEventListener > xListener(
95                       aIt->m_aListeners[i], ::css::uno::UNO_QUERY);
96             if (xListener.is())
97                 try
98                 {
99                     xListener->notifyEvent(aIt->m_aEvent);
100                 }
101                 catch (::css::uno::RuntimeException & rEx)
102                 {
103                     OSL_TRACE(
104                         "comphelper::AccessibleEventBuffer::sendEvents:"
105                         " caught %s\n",
106                         ::rtl::OUStringToOString(
107                             rEx.Message, RTL_TEXTENCODING_UTF8).getStr());
108                 }
109         }
110 }
111