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(com::sun::star::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 ::com::sun::star::accessibility::AccessibleEventObject
& aEvent
)
60 throw (::com::sun::star::uno::RuntimeException
)
64 switch (aEvent
.EventId
)
66 case AccessibleEventId::NAME_CHANGED
:
67 HandleNameChangedEvent(aEvent
.NewValue
);
69 case AccessibleEventId::DESCRIPTION_CHANGED
:
70 HandleDescriptionChangedEvent(aEvent
.NewValue
);
72 case AccessibleEventId::STATE_CHANGED
:
73 HandleStateChangedEvent(aEvent
.OldValue
, aEvent
.NewValue
);
81 * handle the NAME_CHANGED event
82 * @param name the new name with changed.
84 void AccEventListener::HandleNameChangedEvent(Any name
)
86 if (pAgent
->IsTopWinAcc(m_xAccessible
.get()))
88 XAccessible
* pAccDoc
= pAgent
->GetAccDocByAccTopWin(m_xAccessible
.get());
91 pAgent
->UpdateAccName(pAccDoc
);
92 pAgent
->NotifyAccEvent(UM_EVENT_OBJECT_NAMECHANGE
, pAccDoc
);
96 pAgent
->UpdateAccName(m_xAccessible
.get(), name
);
97 pAgent
->NotifyAccEvent(UM_EVENT_OBJECT_NAMECHANGE
, m_xAccessible
.get());
101 * handle the DESCRIPTION_CHANGED event
102 * @param desc the new description
104 void AccEventListener::HandleDescriptionChangedEvent(Any desc
)
106 pAgent
->UpdateDescription(m_xAccessible
.get(), desc
);
107 pAgent
->NotifyAccEvent(UM_EVENT_OBJECT_DESCRIPTIONCHANGE
, m_xAccessible
.get());
111 * handle the BOUNDRECT_CHANGED event
113 void AccEventListener::HandleBoundrectChangedEvent()
115 pAgent
->UpdateLocation(m_xAccessible
.get());
116 pAgent
->NotifyAccEvent(UM_EVENT_BOUNDRECT_CHANGED
, m_xAccessible
.get());
120 * handle the VISIBLE_DATA_CHANGED event
122 void AccEventListener::HandleVisibleDataChangedEvent()
124 pAgent
->UpdateValue(m_xAccessible
.get());
125 pAgent
->NotifyAccEvent(UM_EVENT_VISIBLE_DATA_CHANGED
, m_xAccessible
.get());
129 * handle the STATE_CHANGED event
130 * @param oldValue the old state of the source of event
131 * @param newValue the new state of the source of event
133 void AccEventListener::HandleStateChangedEvent(Any oldValue
, Any newValue
)
136 if( newValue
>>= newV
)
138 SetComponentState(newV
, true);
140 else if (oldValue
>>= oldV
)
142 SetComponentState(oldV
, false);
147 * set the new state and fire the MSAA event
148 * @param state new state id
149 * @param enable true if state is set, false if state is unset
151 void AccEventListener::SetComponentState(short state
, bool enable
)
155 case AccessibleStateType::FOCUSED
:
156 FireStateFocusedChange(enable
);
159 FireStatePropertyChange(state
, enable
);
165 * handle the focused event
166 * @param enable true if get focus, false if lose focus
168 void AccEventListener::FireStateFocusedChange(bool enable
)
172 pAgent
->IncreaseState(m_xAccessible
.get(), AccessibleStateType::FOCUSED
);
173 pAgent
->NotifyAccEvent(UM_EVENT_STATE_FOCUSED
, m_xAccessible
.get());
177 // no focus lost event in MSAA
183 * fire the MSAA state changed event
184 * @param state the state id
185 * @param set true if state is set, false if state is unset
187 void AccEventListener::FireStatePropertyChange(short /*state*/, bool set
)
200 * get the role of accessible object which is observed
202 short AccEventListener::GetRole()
204 css::uno::Reference
<com::sun::star::accessibility::XAccessibleContext
> const
205 xContext(m_xAccessible
->getAccessibleContext());
208 return xContext
->getAccessibleRole();
214 * get the role of accessible parent object which is observed
216 short AccEventListener::GetParentRole()
218 if (m_xAccessible
.is())
220 return pAgent
->GetParentRole(m_xAccessible
.get());
225 * remove the listener from accessible object
227 void AccEventListener::RemoveMeFromBroadcaster()
231 if (!m_xAccessible
.is())
237 css::uno::Reference
<XAccessibleEventBroadcaster
> const xBroadcaster(
238 m_xAccessible
->getAccessibleContext(), UNO_QUERY
);
239 if (xBroadcaster
.is())
241 //remove the lister from accessible object
242 xBroadcaster
->removeAccessibleEventListener(this);
245 catch (Exception
const&)
246 { // may throw if it's already disposed - ignore that
248 pAgent
->NotifyDestroy(m_xAccessible
.get());
249 m_xAccessible
.clear(); // release cyclic reference
259 * this method is invoked before listener is disposed
261 void AccEventListener::disposing( const ::com::sun::star::lang::EventObject
& /*Source*/ )
262 throw (::com::sun::star::uno::RuntimeException
)
266 RemoveMeFromBroadcaster();
269 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */