1/*************************************************************************
2 *
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
6 *
7 * OpenOffice.org - a multi-platform office productivity suite
8 *
9 * This file is part of OpenOffice.org.
10 *
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
14 *
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
20 *
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org.  If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
25 *
26 ************************************************************************/
27
28// MARKER(update_precomp.py): autogen include statement, do not remove
29#include "precompiled_vcl.hxx"
30
31#include "aqua/salinst.h"
32
33#include "aqua11ywrappercombobox.h"
34#include "aqua11yrolehelper.h"
35
36#include <com/sun/star/accessibility/AccessibleStateType.hpp>
37
38using namespace ::com::sun::star::accessibility;
39using namespace ::com::sun::star::uno;
40
41// Wrapper for AXCombobox role
42
43@implementation AquaA11yWrapperComboBox : AquaA11yWrapper
44
45#pragma mark -
46#pragma mark Specialized Init Method
47
48-(id)initWithAccessibleContext: (Reference < XAccessibleContext >) rxAccessibleContext {
49    self = [ super initWithAccessibleContext: rxAccessibleContext ];
50    if ( self != nil )
51    {
52        textArea = nil;
53    }
54    return self;
55}
56
57#pragma mark -
58#pragma mark Private Helper Method
59
60-(AquaA11yWrapper *)textArea {
61    // FIXME: May cause problems when stored. Then get dynamically each time (bad performance!)
62    if ( textArea == nil ) {
63        NSAutoreleasePool * pool = [ [ NSAutoreleasePool alloc ] init ];
64        NSArray * elementChildren = [ super childrenAttribute ];
65        if ( [ elementChildren count ] > 0 ) {
66            NSEnumerator * enumerator = [ elementChildren objectEnumerator ];
67            id child;
68            while ( ( child = [ enumerator nextObject ] ) ) {
69                AquaA11yWrapper * element = ( AquaA11yWrapper * ) child;
70                if ( [ [ AquaA11yRoleHelper getNativeRoleFrom: [ element accessibleContext ] ] isEqualToString: NSAccessibilityTextAreaRole ] ) {
71                    textArea = element;
72                    break;
73                }
74            }
75        }
76        [ pool release ];
77    }
78    return textArea;
79}
80
81#pragma mark -
82#pragma mark Wrapped Attributes From Contained Text Area
83
84-(id)valueAttribute {
85    if ( [ self textArea ] != nil ) {
86        return [ [ self textArea ] valueAttribute ];
87    }
88    return @"";
89}
90
91-(id)numberOfCharactersAttribute {
92    if ( [ self textArea ] != nil ) {
93        return [ [ self textArea ] numberOfCharactersAttribute ];
94    }
95    return [ NSNumber numberWithInt: 0 ];
96}
97
98-(id)selectedTextAttribute {
99    if ( [ self textArea ] != nil ) {
100        return [ [ self textArea ] selectedTextAttribute ];
101    }
102    return @"";
103}
104
105-(id)selectedTextRangeAttribute {
106    if ( [ self textArea ] != nil ) {
107        return [ [ self textArea ] selectedTextRangeAttribute ];
108    }
109    return [ NSValue valueWithRange: NSMakeRange ( 0, 0 ) ];
110}
111
112-(id)visibleCharacterRangeAttribute {
113    if ( [ self textArea ] != nil ) {
114        return [ [ self textArea ] visibleCharacterRangeAttribute ];
115    }
116    return [ NSValue valueWithRange: NSMakeRange ( 0, 0 ) ];
117}
118
119#pragma mark -
120#pragma mark Accessibility Protocol
121
122-(BOOL)accessibilityIsAttributeSettable:(NSString *)attribute {
123    if ( [ self textArea ] != nil && (
124         [ attribute isEqualToString: NSAccessibilitySelectedTextAttribute ]
125      || [ attribute isEqualToString: NSAccessibilitySelectedTextRangeAttribute ]
126      || [ attribute isEqualToString: NSAccessibilityVisibleCharacterRangeAttribute ] ) ) {
127        return [ [ self textArea ] accessibilityIsAttributeSettable: attribute ];
128    }
129    return [ super accessibilityIsAttributeSettable: attribute ];
130}
131
132-(void)accessibilitySetValue:(id)value forAttribute:(NSString *)attribute {
133    if ( [ self textArea ] != nil && (
134         [ attribute isEqualToString: NSAccessibilitySelectedTextAttribute ]
135      || [ attribute isEqualToString: NSAccessibilitySelectedTextRangeAttribute ]
136      || [ attribute isEqualToString: NSAccessibilityVisibleCharacterRangeAttribute ] ) ) {
137        return [ [ self textArea ] accessibilitySetValue: value forAttribute: attribute ];
138    }
139    return [ super accessibilitySetValue: value forAttribute: attribute ];
140}
141
142-(NSArray *)accessibilityAttributeNames {
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,
149            nil ]
150    ];
151    [ attributeNames addObjectsFromArray: [ NSArray arrayWithObjects:
152            NSAccessibilityExpandedAttribute,
153            NSAccessibilityValueAttribute,
154            NSAccessibilityNumberOfCharactersAttribute,
155            NSAccessibilitySelectedTextAttribute,
156            NSAccessibilitySelectedTextRangeAttribute,
157            NSAccessibilityVisibleCharacterRangeAttribute,
158            nil ]
159    ];
160    return attributeNames;
161}
162
163@end
164