1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <cppuhelper/bootstrap.hxx>
21 #include <com/sun/star/bridge/XUnoUrlResolver.hpp>
22 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
24 #include <vcl/svapp.hxx>
26 #include <AccEventListener.hxx>
27 #include <AccObjectWinManager.hxx>
28 #include <unomsaaevent.hxx>
30 #include <com/sun/star/accessibility/XAccessible.hpp>
31 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
32 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
33 #include <com/sun/star/accessibility/AccessibleRole.hpp>
34 #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
35 #include <com/sun/star/accessibility/XAccessibleComponent.hpp>
39 using namespace com::sun::star::uno
;
40 using namespace com::sun::star::accessibility
;
43 AccEventListener::AccEventListener(css::accessibility::XAccessible
* pAcc
,
44 AccObjectWinManager
& rManager
)
46 , m_rObjManager(rManager
)
50 AccEventListener::~AccEventListener() {}
53 * Uno's event notifier when event is captured
54 * @param AccessibleEventObject the event object which contains information about event
56 void AccEventListener::notifyEvent(const css::accessibility::AccessibleEventObject
& aEvent
)
60 switch (aEvent
.EventId
)
62 case AccessibleEventId::CHILD
:
63 HandleChildChangedEvent(aEvent
.OldValue
, aEvent
.NewValue
);
65 case AccessibleEventId::NAME_CHANGED
:
66 HandleNameChangedEvent();
68 case AccessibleEventId::DESCRIPTION_CHANGED
:
69 HandleDescriptionChangedEvent();
71 case AccessibleEventId::STATE_CHANGED
:
72 HandleStateChangedEvent(aEvent
.OldValue
, aEvent
.NewValue
);
80 * handle the NAME_CHANGED event
82 void AccEventListener::HandleNameChangedEvent()
84 if (m_rObjManager
.IsTopWinAcc(m_xAccessible
.get()))
86 XAccessible
* pAccDoc
= m_rObjManager
.GetAccDocByAccTopWin(m_xAccessible
.get());
88 m_rObjManager
.NotifyAccEvent(pAccDoc
, UnoMSAAEvent::OBJECT_NAMECHANGE
);
91 m_rObjManager
.NotifyAccEvent(m_xAccessible
.get(), UnoMSAAEvent::OBJECT_NAMECHANGE
);
95 * Handle the CHILD event
96 * @param oldValue the child to be deleted
97 * @param newValue the child to be added
99 void AccEventListener::HandleChildChangedEvent(css::uno::Any oldValue
, css::uno::Any newValue
)
101 Reference
<XAccessible
> xChild
;
102 if (newValue
>>= xChild
)
106 XAccessible
* pAcc
= xChild
.get();
107 m_rObjManager
.InsertAccObj(pAcc
, m_xAccessible
.get());
108 m_rObjManager
.InsertChildrenAccObj(pAcc
);
109 m_rObjManager
.NotifyAccEvent(pAcc
, UnoMSAAEvent::CHILD_ADDED
);
112 else if (oldValue
>>= xChild
)
116 XAccessible
* pAcc
= xChild
.get();
117 m_rObjManager
.NotifyAccEvent(pAcc
, UnoMSAAEvent::CHILD_REMOVED
);
118 m_rObjManager
.DeleteChildrenAccObj(pAcc
);
119 m_rObjManager
.DeleteAccObj(pAcc
);
125 * handle the DESCRIPTION_CHANGED event
127 void AccEventListener::HandleDescriptionChangedEvent()
129 m_rObjManager
.NotifyAccEvent(m_xAccessible
.get(), UnoMSAAEvent::OBJECT_DESCRIPTIONCHANGE
);
133 * handle the BOUNDRECT_CHANGED event
135 void AccEventListener::HandleBoundrectChangedEvent()
137 m_rObjManager
.NotifyAccEvent(m_xAccessible
.get(), UnoMSAAEvent::BOUNDRECT_CHANGED
);
141 * handle the VISIBLE_DATA_CHANGED event
143 void AccEventListener::HandleVisibleDataChangedEvent()
145 m_rObjManager
.UpdateValue(m_xAccessible
.get());
146 m_rObjManager
.NotifyAccEvent(m_xAccessible
.get(), UnoMSAAEvent::VISIBLE_DATA_CHANGED
);
150 * handle the STATE_CHANGED event
151 * @param oldValue the old state of the source of event
152 * @param newValue the new state of the source of event
154 void AccEventListener::HandleStateChangedEvent(Any oldValue
, Any newValue
)
156 sal_Int64 newV
, oldV
;
157 if (newValue
>>= newV
)
159 SetComponentState(newV
, true);
161 else if (oldValue
>>= oldV
)
163 SetComponentState(oldV
, false);
168 * set the new state and fire the MSAA event
169 * @param state new state id
170 * @param enable true if state is set, false if state is unset
172 void AccEventListener::SetComponentState(sal_Int64 state
, bool enable
)
176 case AccessibleStateType::FOCUSED
:
177 FireStateFocusedChange(enable
);
180 FireStatePropertyChange(state
, enable
);
186 * handle the focused event
187 * @param enable true if get focus, false if lose focus
189 void AccEventListener::FireStateFocusedChange(bool enable
)
193 m_rObjManager
.IncreaseState(m_xAccessible
.get(), AccessibleStateType::FOCUSED
);
194 m_rObjManager
.NotifyAccEvent(m_xAccessible
.get(), UnoMSAAEvent::STATE_FOCUSED
);
198 // no focus lost event in MSAA
203 * fire the MSAA state changed event
204 * @param state the state id
205 * @param set true if state is set, false if state is unset
207 void AccEventListener::FireStatePropertyChange(sal_Int64
/*state*/, bool set
)
220 * get the role of accessible object which is observed
222 short AccEventListener::GetRole()
224 css::uno::Reference
<css::accessibility::XAccessibleContext
> const xContext(
225 m_xAccessible
->getAccessibleContext());
228 return xContext
->getAccessibleRole();
230 return AccessibleRole::UNKNOWN
;
234 * get the role of accessible parent object which is observed
236 short AccEventListener::GetParentRole()
238 if (m_xAccessible
.is())
240 return m_rObjManager
.GetParentRole(m_xAccessible
.get());
245 * remove the listener from accessible object
247 void AccEventListener::RemoveMeFromBroadcaster(bool const isNotifyDestroy
)
251 if (!m_xAccessible
.is())
257 css::uno::Reference
<XAccessibleEventBroadcaster
> const xBroadcaster(
258 m_xAccessible
->getAccessibleContext(), UNO_QUERY
);
259 if (xBroadcaster
.is())
261 //remove the lister from accessible object
262 xBroadcaster
->removeAccessibleEventListener(this);
265 catch (Exception
const&)
266 { // may throw if it's already disposed - ignore that
270 m_rObjManager
.NotifyDestroy(m_xAccessible
.get());
272 m_xAccessible
.clear(); // release cyclic reference
281 * this method is invoked before listener is disposed
283 void AccEventListener::disposing(const css::lang::EventObject
& /*Source*/)
287 RemoveMeFromBroadcaster(true);
290 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */