1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: aqua11ylistener.cxx,v $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 #include "aqua11ylistener.hxx"
33 #include "aqua11yfactory.h"
34 #include "aqua11yfocustracker.hxx"
35 #include "aqua11ytextwrapper.h"
36 #include "aqua11ywrapper.h"
39 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
40 #include <com/sun/star/accessibility/AccessibleRole.hpp>
41 #include <com/sun/star/accessibility/AccessibleTableModelChange.hpp>
42 #include <com/sun/star/accessibility/AccessibleTableModelChangeType.hpp>
44 using namespace ::com::sun::star::accessibility
;
45 using namespace ::com::sun::star::awt
;
46 using namespace ::com::sun::star::lang
;
47 using namespace ::com::sun::star::uno
;
49 NSString
* getTableNotification( const AccessibleEventObject
& aEvent
)
51 AccessibleTableModelChange aChange
;
52 NSString
* notification
= nil
;
54 if( (aEvent
.NewValue
>>= aChange
) &&
55 ( AccessibleTableModelChangeType::INSERT
== aChange
.Type
|| AccessibleTableModelChangeType::DELETE
== aChange
.Type
) &&
56 aChange
.FirstRow
!= aChange
.LastRow
)
58 notification
= NSAccessibilityRowCountChangedNotification
;
64 //------------------------------------------------------------------------------
66 AquaA11yEventListener::AquaA11yEventListener(id wrapperObject
, sal_Int16 role
) : m_wrapperObject(wrapperObject
), m_role(role
)
68 [ m_wrapperObject retain
];
71 //------------------------------------------------------------------------------
73 AquaA11yEventListener::~AquaA11yEventListener()
75 [ m_wrapperObject release
];
78 //------------------------------------------------------------------------------
81 AquaA11yEventListener::disposing( const EventObject
& Source
) throw( RuntimeException
)
83 [ AquaA11yFactory removeFromWrapperRepositoryFor
: [ (AquaA11yWrapper
*) m_wrapperObject accessibleContext
] ];
86 //------------------------------------------------------------------------------
89 AquaA11yEventListener::notifyEvent( const AccessibleEventObject
& aEvent
) throw( RuntimeException
)
91 NSString
* notification
= nil
;
92 id element
= m_wrapperObject
;
95 // TODO: NSAccessibilityValueChanged, NSAccessibilitySelectedRowsChangedNotification
96 switch( aEvent
.EventId
)
98 case AccessibleEventId::ACTIVE_DESCENDANT_CHANGED
:
99 if( m_role
!= AccessibleRole::LIST
) {
100 Reference
< XAccessible
> xAccessible
;
101 if( aEvent
.NewValue
>>= xAccessible
)
102 AquaA11yFocusTracker::get().setFocusedObject( xAccessible
);
106 case AccessibleEventId::NAME_CHANGED
:
107 notification
= NSAccessibilityTitleChangedNotification
;
110 case AccessibleEventId::CHILD
:
111 // only needed for tooltips (says Apple)
112 if ( m_role
== AccessibleRole::TOOL_TIP
) {
113 if(aEvent
.NewValue
.hasValue()) {
114 notification
= NSAccessibilityCreatedNotification
;
115 } else if(aEvent
.OldValue
.hasValue()) {
116 notification
= NSAccessibilityUIElementDestroyedNotification
;
121 case AccessibleEventId::INVALIDATE_ALL_CHILDREN
:
122 // TODO: depricate or remember all children
125 case AccessibleEventId::BOUNDRECT_CHANGED
:
126 bounds
= [ element accessibleComponent
] -> getBounds();
127 if ( m_oldBounds
.X
!= 0 && ( bounds
.X
!= m_oldBounds
.X
|| bounds
.Y
!= m_oldBounds
.Y
) ) {
128 NSAccessibilityPostNotification(element
, NSAccessibilityMovedNotification
); // post directly since both cases can happen simultaneously
130 if ( m_oldBounds
.X
!= 0 && ( bounds
.Width
!= m_oldBounds
.Width
|| bounds
.Height
!= m_oldBounds
.Height
) ) {
131 NSAccessibilityPostNotification(element
, NSAccessibilityResizedNotification
); // post directly since both cases can happen simultaneously
133 m_oldBounds
= bounds
;
136 case AccessibleEventId::SELECTION_CHANGED
:
137 notification
= NSAccessibilitySelectedChildrenChangedNotification
;
140 case AccessibleEventId::TEXT_SELECTION_CHANGED
:
141 notification
= NSAccessibilitySelectedTextChangedNotification
;
144 case AccessibleEventId::TABLE_MODEL_CHANGED
:
145 notification
= getTableNotification(aEvent
);
148 case AccessibleEventId::CARET_CHANGED
:
149 notification
= NSAccessibilitySelectedTextChangedNotification
;
152 case AccessibleEventId::TEXT_CHANGED
:
153 notification
= NSAccessibilityValueChangedNotification
;
160 if( nil
!= notification
)
161 NSAccessibilityPostNotification(element
, notification
);