1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: aqua11ycomponentwrapper.mm,v $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_vcl.hxx"
35 #include "aqua11ycomponentwrapper.h"
36 #include "aqua11yrolehelper.h"
37 #include <com/sun/star/accessibility/AccessibleRole.hpp>
39 using namespace ::com::sun::star::accessibility;
40 using namespace ::com::sun::star::awt;
41 using namespace ::com::sun::star::uno;
43 // Wrapper for XAccessibleComponent and XAccessibleExtendedComponent
45 @implementation AquaA11yComponentWrapper : NSObject
47 +(id)sizeAttributeForElement:(AquaA11yWrapper *)wrapper {
48 Size size = [ wrapper accessibleComponent ] -> getSize();
49 NSSize nsSize = NSMakeSize ( (float) size.Width, (float) size.Height );
50 return [ NSValue valueWithSize: nsSize ];
53 // TODO: should be merged with AquaSalFrame::VCLToCocoa... to a general helper method
54 +(id)positionAttributeForElement:(AquaA11yWrapper *)wrapper {
55 // VCL coordinates are in upper-left-notation, Cocoa likes it the Cartesian way (lower-left)
56 NSRect screenRect = [ [ NSScreen mainScreen ] frame ];
57 Size size = [ wrapper accessibleComponent ] -> getSize();
58 Point location = [ wrapper accessibleComponent ] -> getLocationOnScreen();
59 NSPoint nsPoint = NSMakePoint ( (float) location.X, (float) ( screenRect.size.height - size.Height - location.Y ) );
60 return [ NSValue valueWithPoint: nsPoint ];
63 +(id)descriptionAttributeForElement:(AquaA11yWrapper *)wrapper {
64 if ( [ wrapper accessibleExtendedComponent ] != nil ) {
65 return CreateNSString ( [ wrapper accessibleExtendedComponent ] -> getToolTipText() );
71 +(void)addAttributeNamesTo:(NSMutableArray *)attributeNames {
72 NSAutoreleasePool * pool = [ [ NSAutoreleasePool alloc ] init ];
73 [ attributeNames addObjectsFromArray: [ NSArray arrayWithObjects:
74 NSAccessibilitySizeAttribute,
75 NSAccessibilityPositionAttribute,
76 NSAccessibilityFocusedAttribute,
77 NSAccessibilityEnabledAttribute,
82 +(MacOSBOOL)isAttributeSettable:(NSString *)attribute forElement:(AquaA11yWrapper *)wrapper {
83 MacOSBOOL isSettable = NO;
84 NSAutoreleasePool * pool = [ [ NSAutoreleasePool alloc ] init ];
85 if ( [ attribute isEqualToString: NSAccessibilityFocusedAttribute ]
86 && ! [ [ AquaA11yRoleHelper getNativeRoleFrom: [ wrapper accessibleContext ] ] isEqualToString: NSAccessibilityScrollBarRole ]
87 && ! [ [ AquaA11yRoleHelper getNativeRoleFrom: [ wrapper accessibleContext ] ] isEqualToString: NSAccessibilityStaticTextRole ] ) {
94 +(void)setFocusedAttributeForElement:(AquaA11yWrapper *)wrapper to:(id)value {
95 if ( [ value boolValue ] == YES ) {
96 if ( [ wrapper accessibleContext ] -> getAccessibleRole() == AccessibleRole::COMBO_BOX ) {
97 // special treatment for comboboxes: find the corresponding PANEL and set focus to it
98 Reference < XAccessible > rxParent = [ wrapper accessibleContext ] -> getAccessibleParent();
99 if ( rxParent.is() ) {
100 Reference < XAccessibleContext > rxContext = rxParent->getAccessibleContext();
101 if ( rxContext.is() && rxContext -> getAccessibleRole() == AccessibleRole::PANEL ) {
102 Reference < XAccessibleComponent > rxComponent = Reference < XAccessibleComponent > ( rxParent -> getAccessibleContext(), UNO_QUERY );
103 if ( rxComponent.is() ) {
104 rxComponent -> grabFocus();
109 [ wrapper accessibleComponent ] -> grabFocus();