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 .
21 #include <vcl/svapp.hxx>
22 #include <osx/salinst.h>
24 #include "a11ywrappercombobox.h"
25 #include "a11yrolehelper.h"
27 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
29 using namespace ::com::sun::star::accessibility;
30 using namespace ::com::sun::star::uno;
32 // Wrapper for AXCombobox role
34 @implementation AquaA11yWrapperComboBox : AquaA11yWrapper
37 #pragma mark Specialized Init Method
39 -(id)initWithAccessibleContext: (Reference < XAccessibleContext >) rxAccessibleContext {
40 self = [ super initWithAccessibleContext: rxAccessibleContext ];
49 #pragma mark Private Helper Method
51 -(AquaA11yWrapper *)textArea {
52 // FIXME: May cause problems when stored. Then get dynamically each time (bad performance!)
53 if ( textArea == nil ) {
54 NSAutoreleasePool * pool = [ [ NSAutoreleasePool alloc ] init ];
55 NSArray * elementChildren = [ super childrenAttribute ];
56 if ( [ elementChildren count ] > 0 ) {
57 NSEnumerator * enumerator = [ elementChildren objectEnumerator ];
59 while ( ( child = [ enumerator nextObject ] ) ) {
60 AquaA11yWrapper * element = static_cast<AquaA11yWrapper *>(child);
61 if ( [ [ AquaA11yRoleHelper getNativeRoleFrom: [ element accessibleContext ] ] isEqualToString: NSAccessibilityTextAreaRole ] ) {
73 #pragma mark Wrapped Attributes From Contained Text Area
76 if ( [ self textArea ] != nil ) {
77 return [ [ self textArea ] valueAttribute ];
82 -(id)numberOfCharactersAttribute {
83 if ( [ self textArea ] != nil ) {
84 return [ [ self textArea ] numberOfCharactersAttribute ];
86 return [ NSNumber numberWithInt: 0 ];
89 -(id)selectedTextAttribute {
90 if ( [ self textArea ] != nil ) {
91 return [ [ self textArea ] selectedTextAttribute ];
96 -(id)selectedTextRangeAttribute {
97 if ( [ self textArea ] != nil ) {
98 return [ [ self textArea ] selectedTextRangeAttribute ];
100 return [ NSValue valueWithRange: NSMakeRange ( 0, 0 ) ];
103 -(id)visibleCharacterRangeAttribute {
104 if ( [ self textArea ] != nil ) {
105 return [ [ self textArea ] visibleCharacterRangeAttribute ];
107 return [ NSValue valueWithRange: NSMakeRange ( 0, 0 ) ];
111 #pragma mark Accessibility Protocol
113 -(BOOL)accessibilityIsAttributeSettable:(NSString *)attribute {
114 // Related: tdf#148453 Acquire solar mutex during native accessibility calls
115 SolarMutexGuard aGuard;
117 if ( [ self textArea ] != nil && (
118 [ attribute isEqualToString: NSAccessibilitySelectedTextAttribute ]
119 || [ attribute isEqualToString: NSAccessibilitySelectedTextRangeAttribute ]
120 || [ attribute isEqualToString: NSAccessibilityVisibleCharacterRangeAttribute ] ) ) {
121 return [ [ self textArea ] accessibilityIsAttributeSettable: attribute ];
123 return [ super accessibilityIsAttributeSettable: attribute ];
126 -(void)accessibilitySetValue:(id)value forAttribute:(NSString *)attribute {
127 // Related: tdf#148453 Acquire solar mutex during native accessibility calls
128 SolarMutexGuard aGuard;
130 if ( [ self textArea ] != nil && (
131 [ attribute isEqualToString: NSAccessibilitySelectedTextAttribute ]
132 || [ attribute isEqualToString: NSAccessibilitySelectedTextRangeAttribute ]
133 || [ attribute isEqualToString: NSAccessibilityVisibleCharacterRangeAttribute ] ) ) {
134 return [ [ self textArea ] accessibilitySetValue: value forAttribute: attribute ];
136 return [ super accessibilitySetValue: value forAttribute: attribute ];
139 -(NSArray *)accessibilityAttributeNames {
140 // Related: tdf#148453 Acquire solar mutex during native accessibility calls
141 SolarMutexGuard aGuard;
143 // Default Attributes
144 NSMutableArray * attributeNames = [ NSMutableArray arrayWithArray: [ super accessibilityAttributeNames ] ];
145 // Special Attributes and removing unwanted attributes depending on role
146 [ attributeNames removeObjectsInArray: [ NSArray arrayWithObjects:
147 NSAccessibilityTitleAttribute,
148 NSAccessibilityChildrenAttribute,
151 [ attributeNames addObjectsFromArray: [ NSArray arrayWithObjects:
152 NSAccessibilityExpandedAttribute,
153 NSAccessibilityValueAttribute,
154 NSAccessibilityNumberOfCharactersAttribute,
155 NSAccessibilitySelectedTextAttribute,
156 NSAccessibilitySelectedTextRangeAttribute,
157 NSAccessibilityVisibleCharacterRangeAttribute,
160 return attributeNames;
165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */