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(UM_EVENT_CHILD_ADDED
, pAcc
);
101 if (oldValue
>>= xChild
)
105 XAccessible
* pAcc
= xChild
.get();
107 pAgent
->NotifyAccEvent(UM_EVENT_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(UM_EVENT_SELECTION_CHANGED
, pAcc
);
137 if(oldValue
>>= xChild
)
141 XAccessible
* pAcc
= xChild
.get();
142 pAgent
->DecreaseState( pAcc
, AccessibleStateType::SELECTED
);
147 pAgent
->NotifyAccEvent(UM_EVENT_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(short nWinEvent
,const Any
&Value
)
178 Reference
< XAccessible
> xChild
;
179 if(Value
>>= xChild
)
183 XAccessible
* pAcc
= xChild
.get();
184 pAgent
->NotifyAccEvent(nWinEvent
, pAcc
);
186 if (pAgent
->IsStateManageDescendant(m_xAccessible
.get())
187 && (nWinEvent
== UM_EVENT_SELECTION_CHANGED_REMOVE
))
189 pAgent
->DeleteAccObj( pAcc
);
196 void AccDescendantManagerEventListener::HandleSelectionChangedAddEvent(const Any
& /*oldValue*/, const Any
&newValue
)
198 if(NotifyChildEvent(UM_EVENT_SELECTION_CHANGED_ADD
,newValue
))
202 pAgent
->NotifyAccEvent(UM_EVENT_SELECTION_CHANGED_ADD
, m_xAccessible
.get());
205 void AccDescendantManagerEventListener::HandleSelectionChangedRemoveEvent(const Any
& /*oldValue*/, const Any
&newValue
)
207 if(NotifyChildEvent(UM_EVENT_SELECTION_CHANGED_REMOVE
,newValue
))
211 pAgent
->NotifyAccEvent(UM_EVENT_SELECTION_CHANGED_REMOVE
, m_xAccessible
.get());
214 void AccDescendantManagerEventListener::HandleSelectionChangedWithinEvent(const Any
& /*oldValue*/, const Any
&newValue
)
216 if(NotifyChildEvent(UM_EVENT_SELECTION_CHANGED_WITHIN
,newValue
))
220 pAgent
->NotifyAccEvent(UM_EVENT_SELECTION_CHANGED_WITHIN
, m_xAccessible
.get());
223 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */