1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements.  See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership.  The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License.  You may obtain a copy of the License at
10 *
11 *   http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied.  See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24// MARKER(update_precomp.py): autogen include statement, do not remove
25#include "precompiled_vcl.hxx"
26
27#include "aqua/salinst.h"
28
29#include "aqua11ywrappercombobox.h"
30#include "aqua11yrolehelper.h"
31
32#include <com/sun/star/accessibility/AccessibleStateType.hpp>
33
34using namespace ::com::sun::star::accessibility;
35using namespace ::com::sun::star::uno;
36
37// Wrapper for AXCombobox role
38
39@implementation AquaA11yWrapperComboBox : AquaA11yWrapper
40
41#pragma mark -
42#pragma mark Specialized Init Method
43
44-(id)initWithAccessibleContext: (Reference < XAccessibleContext >) rxAccessibleContext {
45    self = [ super initWithAccessibleContext: rxAccessibleContext ];
46    if ( self != nil )
47    {
48        textArea = nil;
49    }
50    return self;
51}
52
53#pragma mark -
54#pragma mark Private Helper Method
55
56-(AquaA11yWrapper *)textArea {
57    // FIXME: May cause problems when stored. Then get dynamically each time (bad performance!)
58    if ( textArea == nil ) {
59        NSAutoreleasePool * pool = [ [ NSAutoreleasePool alloc ] init ];
60        NSArray * elementChildren = [ super childrenAttribute ];
61        if ( [ elementChildren count ] > 0 ) {
62            NSEnumerator * enumerator = [ elementChildren objectEnumerator ];
63            id child;
64            while ( ( child = [ enumerator nextObject ] ) ) {
65                AquaA11yWrapper * element = ( AquaA11yWrapper * ) child;
66                if ( [ [ AquaA11yRoleHelper getNativeRoleFrom: [ element accessibleContext ] ] isEqualToString: NSAccessibilityTextAreaRole ] ) {
67                    textArea = element;
68                    break;
69                }
70            }
71        }
72        [ pool release ];
73    }
74    return textArea;
75}
76
77#pragma mark -
78#pragma mark Wrapped Attributes From Contained Text Area
79
80-(id)valueAttribute {
81    if ( [ self textArea ] != nil ) {
82        return [ [ self textArea ] valueAttribute ];
83    }
84    return @"";
85}
86
87-(id)numberOfCharactersAttribute {
88    if ( [ self textArea ] != nil ) {
89        return [ [ self textArea ] numberOfCharactersAttribute ];
90    }
91    return [ NSNumber numberWithInt: 0 ];
92}
93
94-(id)selectedTextAttribute {
95    if ( [ self textArea ] != nil ) {
96        return [ [ self textArea ] selectedTextAttribute ];
97    }
98    return @"";
99}
100
101-(id)selectedTextRangeAttribute {
102    if ( [ self textArea ] != nil ) {
103        return [ [ self textArea ] selectedTextRangeAttribute ];
104    }
105    return [ NSValue valueWithRange: NSMakeRange ( 0, 0 ) ];
106}
107
108-(id)visibleCharacterRangeAttribute {
109    if ( [ self textArea ] != nil ) {
110        return [ [ self textArea ] visibleCharacterRangeAttribute ];
111    }
112    return [ NSValue valueWithRange: NSMakeRange ( 0, 0 ) ];
113}
114
115#pragma mark -
116#pragma mark Accessibility Protocol
117
118-(BOOL)accessibilityIsAttributeSettable:(NSString *)attribute {
119    if ( [ self textArea ] != nil && (
120         [ attribute isEqualToString: NSAccessibilitySelectedTextAttribute ]
121      || [ attribute isEqualToString: NSAccessibilitySelectedTextRangeAttribute ]
122      || [ attribute isEqualToString: NSAccessibilityVisibleCharacterRangeAttribute ] ) ) {
123        return [ [ self textArea ] accessibilityIsAttributeSettable: attribute ];
124    }
125    return [ super accessibilityIsAttributeSettable: attribute ];
126}
127
128-(void)accessibilitySetValue:(id)value forAttribute:(NSString *)attribute {
129    if ( [ self textArea ] != nil && (
130         [ attribute isEqualToString: NSAccessibilitySelectedTextAttribute ]
131      || [ attribute isEqualToString: NSAccessibilitySelectedTextRangeAttribute ]
132      || [ attribute isEqualToString: NSAccessibilityVisibleCharacterRangeAttribute ] ) ) {
133        return [ [ self textArea ] accessibilitySetValue: value forAttribute: attribute ];
134    }
135    return [ super accessibilitySetValue: value forAttribute: attribute ];
136}
137
138-(NSArray *)accessibilityAttributeNames {
139    // Default Attributes
140    NSMutableArray * attributeNames = [ NSMutableArray arrayWithArray: [ super accessibilityAttributeNames ] ];
141    // Special Attributes and removing unwanted attributes depending on role
142    [ attributeNames removeObjectsInArray: [ NSArray arrayWithObjects:
143            NSAccessibilityTitleAttribute,
144            NSAccessibilityChildrenAttribute,
145            nil ]
146    ];
147    [ attributeNames addObjectsFromArray: [ NSArray arrayWithObjects:
148            NSAccessibilityExpandedAttribute,
149            NSAccessibilityValueAttribute,
150            NSAccessibilityNumberOfCharactersAttribute,
151            NSAccessibilitySelectedTextAttribute,
152            NSAccessibilitySelectedTextRangeAttribute,
153            NSAccessibilityVisibleCharacterRangeAttribute,
154            nil ]
155    ];
156    return attributeNames;
157}
158
159@end
160