LibreOffice Module winaccessibility (master) 1
AccEventListener.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
21#include <com/sun/star/bridge/XUnoUrlResolver.hpp>
22#include <com/sun/star/lang/XMultiServiceFactory.hpp>
23
24#include <vcl/svapp.hxx>
25
26#include <AccEventListener.hxx>
28#include <unomsaaevent.hxx>
29
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>
36
37#include <stdio.h>
38
39using namespace com::sun::star::uno;
40using namespace com::sun::star::accessibility;
41using namespace cppu;
42
43AccEventListener::AccEventListener(css::accessibility::XAccessible* pAcc,
45 : m_xAccessible(pAcc)
46 , pAgent(Agent)
47{
48}
49
51
56void AccEventListener::notifyEvent(const css::accessibility::AccessibleEventObject& aEvent)
57{
59
60 switch (aEvent.EventId)
61 {
62 case AccessibleEventId::NAME_CHANGED:
64 break;
65 case AccessibleEventId::DESCRIPTION_CHANGED:
67 break;
68 case AccessibleEventId::STATE_CHANGED:
69 HandleStateChangedEvent(aEvent.OldValue, aEvent.NewValue);
70 break;
71 default:
72 break;
73 }
74}
75
81{
83 {
84 XAccessible* pAccDoc = pAgent->GetAccDocByAccTopWin(m_xAccessible.get());
85 if (pAccDoc)
86 {
87 pAgent->UpdateAccName(pAccDoc);
89 }
90 }
91
94}
95
100{
102}
103
108{
110}
111
116{
119}
120
126void AccEventListener::HandleStateChangedEvent(Any oldValue, Any newValue)
127{
128 sal_Int64 newV, oldV;
129 if (newValue >>= newV)
130 {
131 SetComponentState(newV, true);
132 }
133 else if (oldValue >>= oldV)
134 {
135 SetComponentState(oldV, false);
136 }
137}
138
144void AccEventListener::SetComponentState(sal_Int64 state, bool enable)
145{
146 switch (state)
147 {
148 case AccessibleStateType::FOCUSED:
150 break;
151 default:
152 FireStatePropertyChange(state, enable);
153 break;
154 }
155}
156
162{
163 if (enable)
164 {
165 pAgent->IncreaseState(m_xAccessible.get(), AccessibleStateType::FOCUSED);
167 }
168 else
169 {
170 // no focus lost event in MSAA
171 }
172}
173
179void AccEventListener::FireStatePropertyChange(sal_Int64 /*state*/, bool set)
180{
181 if (set)
182 {
183 //get new state
184 }
185 else
186 {
187 //lose old state
188 }
189}
190
195{
196 css::uno::Reference<css::accessibility::XAccessibleContext> const xContext(
197 m_xAccessible->getAccessibleContext());
198 if (xContext.is())
199 {
200 return xContext->getAccessibleRole();
201 }
202 return -1;
203}
204
209{
210 if (m_xAccessible.is())
211 {
212 return pAgent->GetParentRole(m_xAccessible.get());
213 }
214 return -1;
215}
219void AccEventListener::RemoveMeFromBroadcaster(bool const isNotifyDestroy)
220{
221 try
222 {
223 if (!m_xAccessible.is())
224 {
225 return;
226 }
227 try
228 {
229 css::uno::Reference<XAccessibleEventBroadcaster> const xBroadcaster(
230 m_xAccessible->getAccessibleContext(), UNO_QUERY);
231 if (xBroadcaster.is())
232 {
233 //remove the lister from accessible object
234 xBroadcaster->removeAccessibleEventListener(this);
235 }
236 }
237 catch (Exception const&)
238 { // may throw if it's already disposed - ignore that
239 }
240 if (isNotifyDestroy)
241 {
243 }
244 m_xAccessible.clear(); // release cyclic reference
245 }
246 catch (...)
247 {
248 return;
249 }
250}
251
255void AccEventListener::disposing(const css::lang::EventObject& /*Source*/)
256{
258
260}
261
262/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
AnyEventRef aEvent
virtual short GetRole()
get the role of accessible object which is observed
virtual void SetComponentState(sal_Int64 state, bool enable)
set the new state and fire the MSAA event
virtual void HandleDescriptionChangedEvent()
handle the DESCRIPTION_CHANGED event
virtual void HandleNameChangedEvent(css::uno::Any name)
handle the NAME_CHANGED event
virtual void HandleVisibleDataChangedEvent()
handle the VISIBLE_DATA_CHANGED event
virtual void FireStateFocusedChange(bool enable)
handle the focused event
virtual ~AccEventListener() override
virtual short GetParentRole()
get the role of accessible parent object which is observed
AccObjectManagerAgent * pAgent
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
this method is invoked before listener is disposed
AccEventListener(css::accessibility::XAccessible *pAcc, AccObjectManagerAgent *Agent)
virtual void FireStatePropertyChange(sal_Int64 state, bool set)
fire the MSAA state changed event
virtual void HandleBoundrectChangedEvent()
handle the BOUNDRECT_CHANGED event
virtual void SAL_CALL notifyEvent(const css::accessibility::AccessibleEventObject &aEvent) override
Uno's event notifier when event is captured.
void RemoveMeFromBroadcaster(bool isNotifyDestroy)
remove the listener from accessible object
virtual void HandleStateChangedEvent(css::uno::Any oldValue, css::uno::Any newValue)
handle the STATE_CHANGED event
css::uno::Reference< css::accessibility::XAccessible > m_xAccessible
short GetParentRole(css::accessibility::XAccessible *pXAcc)
css::accessibility::XAccessible * GetAccDocByAccTopWin(css::accessibility::XAccessible *pXAcc)
void UpdateValue(css::accessibility::XAccessible *pXAcc)
void UpdateAccName(css::accessibility::XAccessible *pXAcc, css::uno::Any newName)
void IncreaseState(css::accessibility::XAccessible *pXAcc, sal_Int64 pState)
Interface of increasing MSAA name when some UNO state is increased.
bool NotifyAccEvent(UnoMSAAEvent eEvent, css::accessibility::XAccessible *pXAcc=nullptr)
Interface of notify MSAA event when some UNO event occurred.
bool IsTopWinAcc(css::accessibility::XAccessible *pXAcc)
void NotifyDestroy(css::accessibility::XAccessible *pXAcc)
Notify manager when a XAccessible object is destroying.
const char * name
void set(css::uno::UnoInterfaceReference const &value)
@ Exception
@ OBJECT_DESCRIPTIONCHANGE