Branch libreoffice-5-0-4
[LibreOffice.git] / vcl / osx / a11ylistener.cxx
blob630a126dc7a9f27ff20f743665e5f7d51aede83c
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 "osx/salinst.h"
21 #include "osx/a11ylistener.hxx"
22 #include "osx/a11yfactory.h"
23 #include "osx/a11yfocustracker.hxx"
24 #include "osx/a11ywrapper.h"
26 #include "a11ytextwrapper.h"
28 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
29 #include <com/sun/star/accessibility/AccessibleRole.hpp>
30 #include <com/sun/star/accessibility/AccessibleTableModelChange.hpp>
31 #include <com/sun/star/accessibility/AccessibleTableModelChangeType.hpp>
33 using namespace ::com::sun::star::accessibility;
34 using namespace ::com::sun::star::awt;
35 using namespace ::com::sun::star::lang;
36 using namespace ::com::sun::star::uno;
38 NSString * getTableNotification( const AccessibleEventObject& aEvent )
40 AccessibleTableModelChange aChange;
41 NSString * notification = nil;
43 if( (aEvent.NewValue >>= aChange) &&
44 ( AccessibleTableModelChangeType::INSERT == aChange.Type || AccessibleTableModelChangeType::DELETE == aChange.Type ) &&
45 aChange.FirstRow != aChange.LastRow )
47 notification = NSAccessibilityRowCountChangedNotification;
50 return notification;
53 AquaA11yEventListener::AquaA11yEventListener(id wrapperObject, sal_Int16 role) : m_wrapperObject(wrapperObject), m_role(role)
55 [ m_wrapperObject retain ];
58 AquaA11yEventListener::~AquaA11yEventListener()
60 [ m_wrapperObject release ];
63 void SAL_CALL
64 AquaA11yEventListener::disposing( const EventObject& ) throw( RuntimeException, std::exception )
66 [ AquaA11yFactory removeFromWrapperRepositoryFor: [ (AquaA11yWrapper *) m_wrapperObject accessibleContext ] ];
69 void SAL_CALL
70 AquaA11yEventListener::notifyEvent( const AccessibleEventObject& aEvent ) throw( RuntimeException, std::exception )
72 NSString * notification = nil;
73 id element = m_wrapperObject;
74 ::css::awt::Rectangle bounds;
76 // TODO: NSAccessibilityValueChanged, NSAccessibilitySelectedRowsChangedNotification
77 switch( aEvent.EventId )
79 case AccessibleEventId::ACTIVE_DESCENDANT_CHANGED:
80 if( m_role != AccessibleRole::LIST ) {
81 Reference< XAccessible > xAccessible;
82 if( aEvent.NewValue >>= xAccessible )
83 AquaA11yFocusTracker::get().setFocusedObject( xAccessible );
85 break;
87 case AccessibleEventId::NAME_CHANGED:
88 notification = NSAccessibilityTitleChangedNotification;
89 break;
91 case AccessibleEventId::CHILD:
92 // only needed for tooltips (says Apple)
93 if ( m_role == AccessibleRole::TOOL_TIP ) {
94 if(aEvent.NewValue.hasValue()) {
95 notification = NSAccessibilityCreatedNotification;
96 } else if(aEvent.OldValue.hasValue()) {
97 notification = NSAccessibilityUIElementDestroyedNotification;
100 break;
102 case AccessibleEventId::INVALIDATE_ALL_CHILDREN:
103 // TODO: depricate or remember all children
104 break;
106 case AccessibleEventId::BOUNDRECT_CHANGED:
107 bounds = [ element accessibleComponent ] -> getBounds();
108 if ( m_oldBounds.X != 0 && ( bounds.X != m_oldBounds.X || bounds.Y != m_oldBounds.Y ) ) {
109 NSAccessibilityPostNotification(element, NSAccessibilityMovedNotification); // post directly since both cases can happen simultaneously
111 if ( m_oldBounds.X != 0 && ( bounds.Width != m_oldBounds.Width || bounds.Height != m_oldBounds.Height ) ) {
112 NSAccessibilityPostNotification(element, NSAccessibilityResizedNotification); // post directly since both cases can happen simultaneously
114 m_oldBounds = bounds;
115 break;
117 case AccessibleEventId::SELECTION_CHANGED:
118 notification = NSAccessibilitySelectedChildrenChangedNotification;
119 break;
121 case AccessibleEventId::TEXT_SELECTION_CHANGED:
122 notification = NSAccessibilitySelectedTextChangedNotification;
123 break;
125 case AccessibleEventId::TABLE_MODEL_CHANGED:
126 notification = getTableNotification(aEvent);
127 break;
129 case AccessibleEventId::CARET_CHANGED:
130 notification = NSAccessibilitySelectedTextChangedNotification;
131 break;
133 case AccessibleEventId::TEXT_CHANGED:
134 notification = NSAccessibilityValueChangedNotification;
135 break;
137 default:
138 break;
141 if( nil != notification )
142 NSAccessibilityPostNotification(element, notification);
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */