1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <quartz/utils.h>
21 #include "a11ycomponentwrapper.h"
22 #include "a11yrolehelper.h"
23 #include <com/sun/star/accessibility/AccessibleRole.hpp>
25 using namespace ::com::sun::star::accessibility;
26 using namespace ::com::sun::star::awt;
27 using namespace ::com::sun::star::uno;
29 // Wrapper for XAccessibleComponent and XAccessibleExtendedComponent
31 @implementation AquaA11yComponentWrapper : NSObject
33 +(id)sizeAttributeForElement:(AquaA11yWrapper *)wrapper {
34 Size size = [ wrapper accessibleComponent ] -> getSize();
35 NSSize nsSize = NSMakeSize ( static_cast<float>(size.Width), static_cast<float>(size.Height) );
36 return [ NSValue valueWithSize: nsSize ];
39 // TODO: should be merged with AquaSalFrame::VCLToCocoa... to a general helper method
40 +(id)positionAttributeForElement:(AquaA11yWrapper *)wrapper {
41 // VCL coordinates are in upper-left-notation, Cocoa likes it the Cartesian way (lower-left)
42 NSRect screenRect = [ [ NSScreen mainScreen ] frame ];
43 Size size = [ wrapper accessibleComponent ] -> getSize();
44 Point location = [ wrapper accessibleComponent ] -> getLocationOnScreen();
45 NSPoint nsPoint = NSMakePoint ( static_cast<float>(location.X), static_cast<float>( screenRect.size.height - size.Height - location.Y ) );
46 return [ NSValue valueWithPoint: nsPoint ];
49 +(id)descriptionAttributeForElement:(AquaA11yWrapper *)wrapper {
50 if ( [ wrapper accessibleExtendedComponent ] ) {
51 // Related tdf#158914: explicitly call autorelease selector
52 // CreateNSString() is not a getter. It expects the caller to
53 // release the returned string.
54 return [ CreateNSString ( [ wrapper accessibleExtendedComponent ] -> getToolTipText() ) autorelease ];
60 +(void)addAttributeNamesTo:(NSMutableArray *)attributeNames {
61 NSAutoreleasePool * pool = [ [ NSAutoreleasePool alloc ] init ];
62 [ attributeNames addObjectsFromArray: [ NSArray arrayWithObjects:
63 NSAccessibilitySizeAttribute,
64 NSAccessibilityPositionAttribute,
65 NSAccessibilityFocusedAttribute,
66 NSAccessibilityEnabledAttribute,
71 +(BOOL)isAttributeSettable:(NSString *)attribute forElement:(AquaA11yWrapper *)wrapper {
72 bool isSettable = false;
73 NSAutoreleasePool * pool = [ [ NSAutoreleasePool alloc ] init ];
74 if ( [ attribute isEqualToString: NSAccessibilityFocusedAttribute ]
75 && ! [ [ AquaA11yRoleHelper getNativeRoleFrom: [ wrapper accessibleContext ] ] isEqualToString: NSAccessibilityScrollBarRole ]
76 && ! [ [ AquaA11yRoleHelper getNativeRoleFrom: [ wrapper accessibleContext ] ] isEqualToString: NSAccessibilityStaticTextRole ] ) {
83 +(void)setFocusedAttributeForElement:(AquaA11yWrapper *)wrapper to:(id)value {
84 if ( [ value boolValue ] == YES ) {
85 if ( [ wrapper accessibleContext ] -> getAccessibleRole() == AccessibleRole::COMBO_BOX ) {
86 // special treatment for comboboxes: find the corresponding PANEL and set focus to it
87 Reference < XAccessible > rxParent = [ wrapper accessibleContext ] -> getAccessibleParent();
88 if ( rxParent.is() ) {
89 Reference < XAccessibleContext > rxContext = rxParent->getAccessibleContext();
90 if ( rxContext.is() && rxContext -> getAccessibleRole() == AccessibleRole::PANEL ) {
91 Reference < XAccessibleComponent > rxComponent( rxParent -> getAccessibleContext(), UNO_QUERY );
92 if ( rxComponent.is() ) {
93 rxComponent -> grabFocus();
98 [ wrapper accessibleComponent ] -> grabFocus();
105 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */