bump product version to 5.0.4.1
[LibreOffice.git] / winaccessibility / source / service / AccEventListener.cxx
blob7b8811625754b7d73995d0101fa246baf5eb0a88
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
39 #include <stdio.h>
41 using namespace com::sun::star::uno;
42 using namespace com::sun::star::accessibility;
43 using namespace cppu;
45 AccEventListener::AccEventListener(com::sun::star::accessibility::XAccessible* pAcc,
46 AccObjectManagerAgent* Agent)
47 : m_xAccessible(pAcc)
48 , pAgent(Agent)
51 AccEventListener::~AccEventListener()
55 /**
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)
62 SolarMutexGuard g;
64 switch (aEvent.EventId)
66 case AccessibleEventId::NAME_CHANGED:
67 HandleNameChangedEvent(aEvent.NewValue);
68 break;
69 case AccessibleEventId::DESCRIPTION_CHANGED:
70 HandleDescriptionChangedEvent(aEvent.NewValue);
71 break;
72 case AccessibleEventId::STATE_CHANGED:
73 HandleStateChangedEvent(aEvent.OldValue, aEvent.NewValue);
74 break;
75 default:
76 break;
80 /**
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());
89 if ( pAccDoc )
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)
135 short newV, oldV;
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 )
153 switch (state)
155 case AccessibleStateType::FOCUSED:
156 FireStateFocusedChange(enable);
157 break;
158 default:
159 FireStatePropertyChange(state, enable);
160 break;
165 * handle the focused event
166 * @param enable true if get focus, false if lose focus
168 void AccEventListener::FireStateFocusedChange(bool enable)
170 if(enable)
172 pAgent->IncreaseState(m_xAccessible.get(), AccessibleStateType::FOCUSED);
173 pAgent->NotifyAccEvent(UM_EVENT_STATE_FOCUSED, m_xAccessible.get());
175 else
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 )
189 if( set )
191 //get new state
193 else
195 //lose old state
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());
206 if(xContext.is())
208 return xContext->getAccessibleRole();
210 return -1;
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());
222 return -1;
225 * remove the listener from accessible object
227 void AccEventListener::RemoveMeFromBroadcaster()
231 if (!m_xAccessible.is())
233 return;
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
251 catch(...)
253 return;
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)
264 SolarMutexGuard g;
266 RemoveMeFromBroadcaster();
269 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */