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