merge the formfield patch from ooo-build
[ooovba.git] / vcl / aqua / source / a11y / aqua11ylistener.cxx
blob411510c9b2213477c28a5e305dee673a06b05d95
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: aqua11ylistener.cxx,v $
11 * $Revision: 1.3 $
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"
37 #include "salinst.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;
61 return notification;
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 //------------------------------------------------------------------------------
80 void SAL_CALL
81 AquaA11yEventListener::disposing( const EventObject& Source ) throw( RuntimeException )
83 [ AquaA11yFactory removeFromWrapperRepositoryFor: [ (AquaA11yWrapper *) m_wrapperObject accessibleContext ] ];
86 //------------------------------------------------------------------------------
88 void SAL_CALL
89 AquaA11yEventListener::notifyEvent( const AccessibleEventObject& aEvent ) throw( RuntimeException )
91 NSString * notification = nil;
92 id element = m_wrapperObject;
93 Rectangle bounds;
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 );
104 break;
106 case AccessibleEventId::NAME_CHANGED:
107 notification = NSAccessibilityTitleChangedNotification;
108 break;
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;
119 break;
121 case AccessibleEventId::INVALIDATE_ALL_CHILDREN:
122 // TODO: depricate or remember all children
123 break;
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;
134 break;
136 case AccessibleEventId::SELECTION_CHANGED:
137 notification = NSAccessibilitySelectedChildrenChangedNotification;
138 break;
140 case AccessibleEventId::TEXT_SELECTION_CHANGED:
141 notification = NSAccessibilitySelectedTextChangedNotification;
142 break;
144 case AccessibleEventId::TABLE_MODEL_CHANGED:
145 notification = getTableNotification(aEvent);
146 break;
148 case AccessibleEventId::CARET_CHANGED:
149 notification = NSAccessibilitySelectedTextChangedNotification;
150 break;
152 case AccessibleEventId::TEXT_CHANGED:
153 notification = NSAccessibilityValueChangedNotification;
154 break;
156 default:
157 break;
160 if( nil != notification )
161 NSAccessibilityPostNotification(element, notification);