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 return CreateNSString ( [ wrapper accessibleExtendedComponent ] -> getToolTipText() );
57 +(void)addAttributeNamesTo:(NSMutableArray *)attributeNames {
58 NSAutoreleasePool * pool = [ [ NSAutoreleasePool alloc ] init ];
59 [ attributeNames addObjectsFromArray: [ NSArray arrayWithObjects:
60 NSAccessibilitySizeAttribute,
61 NSAccessibilityPositionAttribute,
62 NSAccessibilityFocusedAttribute,
63 NSAccessibilityEnabledAttribute,
68 +(BOOL)isAttributeSettable:(NSString *)attribute forElement:(AquaA11yWrapper *)wrapper {
69 bool isSettable = false;
70 NSAutoreleasePool * pool = [ [ NSAutoreleasePool alloc ] init ];
71 if ( [ attribute isEqualToString: NSAccessibilityFocusedAttribute ]
72 && ! [ [ AquaA11yRoleHelper getNativeRoleFrom: [ wrapper accessibleContext ] ] isEqualToString: NSAccessibilityScrollBarRole ]
73 && ! [ [ AquaA11yRoleHelper getNativeRoleFrom: [ wrapper accessibleContext ] ] isEqualToString: NSAccessibilityStaticTextRole ] ) {
80 +(void)setFocusedAttributeForElement:(AquaA11yWrapper *)wrapper to:(id)value {
81 if ( [ value boolValue ] == YES ) {
82 if ( [ wrapper accessibleContext ] -> getAccessibleRole() == AccessibleRole::COMBO_BOX ) {
83 // special treatment for comboboxes: find the corresponding PANEL and set focus to it
84 Reference < XAccessible > rxParent = [ wrapper accessibleContext ] -> getAccessibleParent();
85 if ( rxParent.is() ) {
86 Reference < XAccessibleContext > rxContext = rxParent->getAccessibleContext();
87 if ( rxContext.is() && rxContext -> getAccessibleRole() == AccessibleRole::PANEL ) {
88 Reference < XAccessibleComponent > rxComponent( rxParent -> getAccessibleContext(), UNO_QUERY );
89 if ( rxComponent.is() ) {
90 rxComponent -> grabFocus();
95 [ wrapper accessibleComponent ] -> grabFocus();
102 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */