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 <com/sun/star/accessibility/XAccessible.hpp>
21 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
22 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
23 #include <com/sun/star/accessibility/AccessibleRole.hpp>
24 #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
26 #include <vcl/svapp.hxx>
28 #include <AccDescendantManagerEventListener.hxx>
29 #include <AccObjectManagerAgent.hxx>
30 #include <unomsaaevent.hxx>
32 using namespace com::sun::star::uno
;
33 using namespace com::sun::star::accessibility
;
35 AccDescendantManagerEventListener::AccDescendantManagerEventListener(css::accessibility::XAccessible
* pAcc
, AccObjectManagerAgent
* Agent
)
36 : AccComponentEventListener(pAcc
, Agent
)
40 AccDescendantManagerEventListener::~AccDescendantManagerEventListener()
45 * Uno's event notifier when event is captured
46 * @param AccessibleEventObject the event object which contains information about event
48 void AccDescendantManagerEventListener::notifyEvent( const css::accessibility::AccessibleEventObject
& aEvent
)
52 switch (aEvent
.EventId
)
54 case AccessibleEventId::SELECTION_CHANGED
:
55 HandleSelectionChangedEvent(aEvent
.OldValue
, aEvent
.NewValue
);
57 case AccessibleEventId::CHILD
:
58 HandleChildChangedEvent(aEvent
.OldValue
, aEvent
.NewValue
);
60 case AccessibleEventId::ACTIVE_DESCENDANT_CHANGED_NOFOCUS
:
61 HandleChildChangedNoFocusEvent(aEvent
.OldValue
, aEvent
.NewValue
);
63 case AccessibleEventId::SELECTION_CHANGED_ADD
:
64 HandleSelectionChangedAddEvent(aEvent
.OldValue
, aEvent
.NewValue
);
66 case AccessibleEventId::SELECTION_CHANGED_REMOVE
:
67 HandleSelectionChangedRemoveEvent(aEvent
.OldValue
, aEvent
.NewValue
);
69 case AccessibleEventId::SELECTION_CHANGED_WITHIN
:
70 HandleSelectionChangedWithinEvent(aEvent
.OldValue
, aEvent
.NewValue
);
73 AccComponentEventListener::notifyEvent(aEvent
);
79 * handle the CHILD event
80 * @param oldValue the child to be deleted
81 * @param newValue the child to be added
83 void AccDescendantManagerEventListener::HandleChildChangedEvent(Any oldValue
, Any newValue
)
86 Reference
< XAccessible
> xChild
;
87 if( newValue
>>= xChild
)
92 XAccessible
* pAcc
= xChild
.get();
93 pAgent
->InsertAccObj(pAcc
, m_xAccessible
.get());
94 pAgent
->InsertChildrenAccObj(pAcc
);
96 pAgent
->NotifyAccEvent(UnoMSAAEvent::CHILD_ADDED
, pAcc
);
101 if (oldValue
>>= xChild
)
105 XAccessible
* pAcc
= xChild
.get();
107 pAgent
->NotifyAccEvent(UnoMSAAEvent::CHILD_REMOVED
, pAcc
);
108 pAgent
->DeleteChildrenAccObj( pAcc
);
109 pAgent
->DeleteAccObj( pAcc
);
116 * handle the SELECTION_CHANGED event
118 void AccDescendantManagerEventListener::HandleSelectionChangedEvent(Any oldValue
, Any newValue
)
121 Reference
< XAccessible
> xChild
;
122 if(newValue
>>= xChild
)
126 XAccessible
* pAcc
= xChild
.get();
127 //if the Role is the SC cell ,don't add the selected state.
128 if (pAgent
->GetRole(pAcc
) != AccessibleRole::TABLE_CELL
)
130 pAgent
->IncreaseState( pAcc
, AccessibleStateType::SELECTED
);
133 pAgent
->NotifyAccEvent(UnoMSAAEvent::SELECTION_CHANGED
, pAcc
);
137 if(oldValue
>>= xChild
)
141 XAccessible
* pAcc
= xChild
.get();
142 pAgent
->DecreaseState( pAcc
, AccessibleStateType::SELECTED
);
147 pAgent
->NotifyAccEvent(UnoMSAAEvent::SELECTION_CHANGED
, m_xAccessible
.get());
152 void AccDescendantManagerEventListener::HandleChildChangedNoFocusEvent(Any oldValue
, Any newValue
)
154 Reference
< XAccessible
> xChild
;
155 if(newValue
>>= xChild
)
159 XAccessible
* pAcc
= xChild
.get();
161 pAgent
->InsertAccObj(pAcc
, m_xAccessible
.get());
162 pAgent
->InsertChildrenAccObj(pAcc
);
165 if (oldValue
>>= xChild
)
169 XAccessible
* pAcc
= xChild
.get();
170 pAgent
->DeleteChildrenAccObj( pAcc
);
171 pAgent
->DeleteAccObj( pAcc
);
176 bool AccDescendantManagerEventListener::NotifyChildEvent(UnoMSAAEvent eWinEvent
, const Any
& Value
)
178 Reference
< XAccessible
> xChild
;
179 if(Value
>>= xChild
)
183 XAccessible
* pAcc
= xChild
.get();
184 pAgent
->NotifyAccEvent(eWinEvent
, pAcc
);
186 if (pAgent
->IsStateManageDescendant(m_xAccessible
.get()))
188 if (eWinEvent
== UnoMSAAEvent::SELECTION_CHANGED_REMOVE
)
190 // The object has just been sent in a SELECTION_CHANGED_REMOVE event
191 // and accessibility tools may query for the object and call methods on
192 // it as a response to this.
193 // Therefore, don't delete the object yet, but remember it for deletion
194 // once the next event of a different type occurs.
195 m_aUnselectedChildrenForDeletion
.push_back(pAcc
);
199 // handle any pending deletions for objects previously removed from selection
200 for (XAccessible
* pAcc2
: m_aUnselectedChildrenForDeletion
)
201 pAgent
->DeleteAccObj(pAcc2
);
202 m_aUnselectedChildrenForDeletion
.clear();
210 void AccDescendantManagerEventListener::HandleSelectionChangedAddEvent(const Any
& /*oldValue*/, const Any
&newValue
)
212 if (NotifyChildEvent(UnoMSAAEvent::SELECTION_CHANGED_ADD
, newValue
))
216 pAgent
->NotifyAccEvent(UnoMSAAEvent::SELECTION_CHANGED_ADD
, m_xAccessible
.get());
219 void AccDescendantManagerEventListener::HandleSelectionChangedRemoveEvent(const Any
& /*oldValue*/, const Any
&newValue
)
221 if (NotifyChildEvent(UnoMSAAEvent::SELECTION_CHANGED_REMOVE
, newValue
))
225 pAgent
->NotifyAccEvent(UnoMSAAEvent::SELECTION_CHANGED_REMOVE
, m_xAccessible
.get());
228 void AccDescendantManagerEventListener::HandleSelectionChangedWithinEvent(const Any
& /*oldValue*/, const Any
&newValue
)
230 if (NotifyChildEvent(UnoMSAAEvent::SELECTION_CHANGED_WITHIN
, newValue
))
234 pAgent
->NotifyAccEvent(UnoMSAAEvent::SELECTION_CHANGED_WITHIN
, m_xAccessible
.get());
237 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */