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 <toolkit/awt/vclxwindow.hxx>
28 #include <AccEventListener.hxx>
29 #include <AccObjectManagerAgent.hxx>
30 #include <unomsaaevent.hxx>
32 #include <com/sun/star/accessibility/XAccessible.hpp>
33 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
34 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
35 #include <com/sun/star/accessibility/AccessibleRole.hpp>
36 #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
37 #include <com/sun/star/accessibility/XAccessibleComponent.hpp>
41 using namespace com::sun::star::uno
;
42 using namespace com::sun::star::accessibility
;
45 AccEventListener::AccEventListener(css::accessibility::XAccessible
* pAcc
,
46 AccObjectManagerAgent
* Agent
)
51 AccEventListener::~AccEventListener()
56 * Uno's event notifier when event is captured
57 * @param AccessibleEventObject the event object which contains information about event
59 void AccEventListener::notifyEvent( const css::accessibility::AccessibleEventObject
& aEvent
)
63 switch (aEvent
.EventId
)
65 case AccessibleEventId::NAME_CHANGED
:
66 HandleNameChangedEvent(aEvent
.NewValue
);
68 case AccessibleEventId::DESCRIPTION_CHANGED
:
69 HandleDescriptionChangedEvent(aEvent
.NewValue
);
71 case AccessibleEventId::STATE_CHANGED
:
72 HandleStateChangedEvent(aEvent
.OldValue
, aEvent
.NewValue
);
80 * handle the NAME_CHANGED event
81 * @param name the new name with changed.
83 void AccEventListener::HandleNameChangedEvent(Any name
)
85 if (pAgent
->IsTopWinAcc(m_xAccessible
.get()))
87 XAccessible
* pAccDoc
= pAgent
->GetAccDocByAccTopWin(m_xAccessible
.get());
90 pAgent
->UpdateAccName(pAccDoc
);
91 pAgent
->NotifyAccEvent(UM_EVENT_OBJECT_NAMECHANGE
, pAccDoc
);
95 pAgent
->UpdateAccName(m_xAccessible
.get(), name
);
96 pAgent
->NotifyAccEvent(UM_EVENT_OBJECT_NAMECHANGE
, m_xAccessible
.get());
100 * handle the DESCRIPTION_CHANGED event
101 * @param desc the new description
103 void AccEventListener::HandleDescriptionChangedEvent(Any desc
)
105 pAgent
->UpdateDescription(m_xAccessible
.get(), desc
);
106 pAgent
->NotifyAccEvent(UM_EVENT_OBJECT_DESCRIPTIONCHANGE
, m_xAccessible
.get());
110 * handle the BOUNDRECT_CHANGED event
112 void AccEventListener::HandleBoundrectChangedEvent()
114 AccObjectManagerAgent::UpdateLocation(m_xAccessible
.get());
115 pAgent
->NotifyAccEvent(UM_EVENT_BOUNDRECT_CHANGED
, m_xAccessible
.get());
119 * handle the VISIBLE_DATA_CHANGED event
121 void AccEventListener::HandleVisibleDataChangedEvent()
123 pAgent
->UpdateValue(m_xAccessible
.get());
124 pAgent
->NotifyAccEvent(UM_EVENT_VISIBLE_DATA_CHANGED
, m_xAccessible
.get());
128 * handle the STATE_CHANGED event
129 * @param oldValue the old state of the source of event
130 * @param newValue the new state of the source of event
132 void AccEventListener::HandleStateChangedEvent(Any oldValue
, Any newValue
)
135 if( newValue
>>= newV
)
137 SetComponentState(newV
, true);
139 else if (oldValue
>>= oldV
)
141 SetComponentState(oldV
, false);
146 * set the new state and fire the MSAA event
147 * @param state new state id
148 * @param enable true if state is set, false if state is unset
150 void AccEventListener::SetComponentState(short state
, bool enable
)
154 case AccessibleStateType::FOCUSED
:
155 FireStateFocusedChange(enable
);
158 FireStatePropertyChange(state
, enable
);
164 * handle the focused event
165 * @param enable true if get focus, false if lose focus
167 void AccEventListener::FireStateFocusedChange(bool enable
)
171 pAgent
->IncreaseState(m_xAccessible
.get(), AccessibleStateType::FOCUSED
);
172 pAgent
->NotifyAccEvent(UM_EVENT_STATE_FOCUSED
, m_xAccessible
.get());
176 // no focus lost event in MSAA
182 * fire the MSAA state changed event
183 * @param state the state id
184 * @param set true if state is set, false if state is unset
186 void AccEventListener::FireStatePropertyChange(short /*state*/, bool set
)
199 * get the role of accessible object which is observed
201 short AccEventListener::GetRole()
203 css::uno::Reference
<css::accessibility::XAccessibleContext
> const
204 xContext(m_xAccessible
->getAccessibleContext());
207 return xContext
->getAccessibleRole();
213 * get the role of accessible parent object which is observed
215 short AccEventListener::GetParentRole()
217 if (m_xAccessible
.is())
219 return pAgent
->GetParentRole(m_xAccessible
.get());
224 * remove the listener from accessible object
226 void AccEventListener::RemoveMeFromBroadcaster()
230 if (!m_xAccessible
.is())
236 css::uno::Reference
<XAccessibleEventBroadcaster
> const xBroadcaster(
237 m_xAccessible
->getAccessibleContext(), UNO_QUERY
);
238 if (xBroadcaster
.is())
240 //remove the lister from accessible object
241 xBroadcaster
->removeAccessibleEventListener(this);
244 catch (Exception
const&)
245 { // may throw if it's already disposed - ignore that
247 pAgent
->NotifyDestroy(m_xAccessible
.get());
248 m_xAccessible
.clear(); // release cyclic reference
258 * this method is invoked before listener is disposed
260 void AccEventListener::disposing( const css::lang::EventObject
& /*Source*/ )
264 RemoveMeFromBroadcaster();
267 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */