1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2/* 3 * This file is part of the LibreOffice project. 4 * 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/. 8 * 9 * This file incorporates work covered by the following license notice: 10 * 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 . 18 */ 19 20 21#include <osx/salinst.h> 22 23#include "a11ywrappercombobox.h" 24#include "a11yrolehelper.h" 25 26#include <com/sun/star/accessibility/AccessibleStateType.hpp> 27 28using namespace ::com::sun::star::accessibility; 29using namespace ::com::sun::star::uno; 30 31// Wrapper for AXCombobox role 32 33@implementation AquaA11yWrapperComboBox : AquaA11yWrapper 34 35#pragma mark - 36#pragma mark Specialized Init Method 37 38-(id)initWithAccessibleContext: (Reference < XAccessibleContext >) rxAccessibleContext { 39 self = [ super initWithAccessibleContext: rxAccessibleContext ]; 40 if ( self != nil ) 41 { 42 textArea = nil; 43 } 44 return self; 45} 46 47#pragma mark - 48#pragma mark Private Helper Method 49 50-(AquaA11yWrapper *)textArea { 51 // FIXME: May cause problems when stored. Then get dynamically each time (bad performance!) 52 if ( textArea == nil ) { 53 NSAutoreleasePool * pool = [ [ NSAutoreleasePool alloc ] init ]; 54 NSArray * elementChildren = [ super childrenAttribute ]; 55 if ( [ elementChildren count ] > 0 ) { 56 NSEnumerator * enumerator = [ elementChildren objectEnumerator ]; 57 id child; 58 while ( ( child = [ enumerator nextObject ] ) ) { 59 AquaA11yWrapper * element = static_cast<AquaA11yWrapper *>(child); 60 if ( [ [ AquaA11yRoleHelper getNativeRoleFrom: [ element accessibleContext ] ] isEqualToString: NSAccessibilityTextAreaRole ] ) { 61 textArea = element; 62 break; 63 } 64 } 65 } 66 [ pool release ]; 67 } 68 return textArea; 69} 70 71#pragma mark - 72#pragma mark Wrapped Attributes From Contained Text Area 73 74-(id)valueAttribute { 75 if ( [ self textArea ] != nil ) { 76 return [ [ self textArea ] valueAttribute ]; 77 } 78 return @""; 79} 80 81-(id)numberOfCharactersAttribute { 82 if ( [ self textArea ] != nil ) { 83 return [ [ self textArea ] numberOfCharactersAttribute ]; 84 } 85 return [ NSNumber numberWithInt: 0 ]; 86} 87 88-(id)selectedTextAttribute { 89 if ( [ self textArea ] != nil ) { 90 return [ [ self textArea ] selectedTextAttribute ]; 91 } 92 return @""; 93} 94 95-(id)selectedTextRangeAttribute { 96 if ( [ self textArea ] != nil ) { 97 return [ [ self textArea ] selectedTextRangeAttribute ]; 98 } 99 return [ NSValue valueWithRange: NSMakeRange ( 0, 0 ) ]; 100} 101 102-(id)visibleCharacterRangeAttribute { 103 if ( [ self textArea ] != nil ) { 104 return [ [ self textArea ] visibleCharacterRangeAttribute ]; 105 } 106 return [ NSValue valueWithRange: NSMakeRange ( 0, 0 ) ]; 107} 108 109#pragma mark - 110#pragma mark Accessibility Protocol 111 112-(BOOL)accessibilityIsAttributeSettable:(NSString *)attribute { 113 if ( [ self textArea ] != nil && ( 114 [ attribute isEqualToString: NSAccessibilitySelectedTextAttribute ] 115 || [ attribute isEqualToString: NSAccessibilitySelectedTextRangeAttribute ] 116 || [ attribute isEqualToString: NSAccessibilityVisibleCharacterRangeAttribute ] ) ) { 117 return [ [ self textArea ] accessibilityIsAttributeSettable: attribute ]; 118 } 119 return [ super accessibilityIsAttributeSettable: attribute ]; 120} 121 122-(void)accessibilitySetValue:(id)value forAttribute:(NSString *)attribute { 123 if ( [ self textArea ] != nil && ( 124 [ attribute isEqualToString: NSAccessibilitySelectedTextAttribute ] 125 || [ attribute isEqualToString: NSAccessibilitySelectedTextRangeAttribute ] 126 || [ attribute isEqualToString: NSAccessibilityVisibleCharacterRangeAttribute ] ) ) { 127 return [ [ self textArea ] accessibilitySetValue: value forAttribute: attribute ]; 128 } 129 return [ super accessibilitySetValue: value forAttribute: attribute ]; 130} 131 132-(NSArray *)accessibilityAttributeNames { 133 // Default Attributes 134 NSMutableArray * attributeNames = [ NSMutableArray arrayWithArray: [ super accessibilityAttributeNames ] ]; 135 // Special Attributes and removing unwanted attributes depending on role 136 [ attributeNames removeObjectsInArray: [ NSArray arrayWithObjects: 137 NSAccessibilityTitleAttribute, 138 NSAccessibilityChildrenAttribute, 139 nil ] 140 ]; 141 [ attributeNames addObjectsFromArray: [ NSArray arrayWithObjects: 142 NSAccessibilityExpandedAttribute, 143 NSAccessibilityValueAttribute, 144 NSAccessibilityNumberOfCharactersAttribute, 145 NSAccessibilitySelectedTextAttribute, 146 NSAccessibilitySelectedTextRangeAttribute, 147 NSAccessibilityVisibleCharacterRangeAttribute, 148 nil ] 149 ]; 150 return attributeNames; 151} 152 153@end 154 155/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 156