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 "aqua11ycomponentwrapper.h"
28#include "aqua11yrolehelper.h"
29#include <com/sun/star/accessibility/AccessibleRole.hpp>
30
31using namespace ::com::sun::star::accessibility;
32using namespace ::com::sun::star::awt;
33using namespace ::com::sun::star::uno;
34
35// Wrapper for XAccessibleComponent and XAccessibleExtendedComponent
36
37@implementation AquaA11yComponentWrapper : NSObject
38
39+(id)sizeAttributeForElement:(AquaA11yWrapper *)wrapper {
40    Size size = [ wrapper accessibleComponent ] -> getSize();
41    NSSize nsSize = NSMakeSize ( (float) size.Width, (float) size.Height );
42    return [ NSValue valueWithSize: nsSize ];
43}
44
45// TODO: should be merged with AquaSalFrame::VCLToCocoa... to a general helper method
46+(id)positionAttributeForElement:(AquaA11yWrapper *)wrapper {
47    // VCL coordinates are in upper-left-notation, Cocoa likes it the Cartesian way (lower-left)
48    NSRect screenRect = [ [ NSScreen mainScreen ] frame ];
49    Size size = [ wrapper accessibleComponent ] -> getSize();
50    Point location = [ wrapper accessibleComponent ] -> getLocationOnScreen();
51    NSPoint nsPoint = NSMakePoint ( (float) location.X, (float) ( screenRect.size.height - size.Height - location.Y ) );
52    return [ NSValue valueWithPoint: nsPoint ];
53}
54
55+(id)descriptionAttributeForElement:(AquaA11yWrapper *)wrapper {
56    if ( [ wrapper accessibleExtendedComponent ] != nil ) {
57        return CreateNSString ( [ wrapper accessibleExtendedComponent ] -> getToolTipText() );
58    } else {
59        return nil;
60    }
61}
62
63+(void)addAttributeNamesTo:(NSMutableArray *)attributeNames {
64    NSAutoreleasePool * pool = [ [ NSAutoreleasePool alloc ] init ];
65    [ attributeNames addObjectsFromArray: [ NSArray arrayWithObjects:
66            NSAccessibilitySizeAttribute,
67            NSAccessibilityPositionAttribute,
68            NSAccessibilityFocusedAttribute,
69            NSAccessibilityEnabledAttribute,
70            nil ] ];
71    [ pool release ];
72}
73
74+(BOOL)isAttributeSettable:(NSString *)attribute forElement:(AquaA11yWrapper *)wrapper {
75    BOOL isSettable = NO;
76    NSAutoreleasePool * pool = [ [ NSAutoreleasePool alloc ] init ];
77    if ( [ attribute isEqualToString: NSAccessibilityFocusedAttribute ]
78      && ! [ [ AquaA11yRoleHelper getNativeRoleFrom: [ wrapper accessibleContext ] ] isEqualToString: NSAccessibilityScrollBarRole ]
79      && ! [ [ AquaA11yRoleHelper getNativeRoleFrom: [ wrapper accessibleContext ] ] isEqualToString: NSAccessibilityStaticTextRole ] ) {
80        isSettable = YES;
81    }
82    [ pool release ];
83    return isSettable;
84}
85
86+(void)setFocusedAttributeForElement:(AquaA11yWrapper *)wrapper to:(id)value {
87    if ( [ value boolValue ] == YES ) {
88        if ( [ wrapper accessibleContext ] -> getAccessibleRole() == AccessibleRole::COMBO_BOX ) {
89            // special treatment for comboboxes: find the corresponding PANEL and set focus to it
90            Reference < XAccessible > rxParent = [ wrapper accessibleContext ] -> getAccessibleParent();
91            if ( rxParent.is() ) {
92                Reference < XAccessibleContext > rxContext = rxParent->getAccessibleContext();
93                if ( rxContext.is() && rxContext -> getAccessibleRole() == AccessibleRole::PANEL ) {
94                    Reference < XAccessibleComponent > rxComponent = Reference < XAccessibleComponent > ( rxParent -> getAccessibleContext(), UNO_QUERY );
95                    if ( rxComponent.is() ) {
96                        rxComponent -> grabFocus();
97                    }
98                }
99            }
100        } else {
101            [ wrapper accessibleComponent ] -> grabFocus();
102        }
103    }
104}
105
106@end
107