1*323de322SAndrew Rist/************************************************************** 2cdf0e10cSrcweir * 3*323de322SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*323de322SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*323de322SAndrew Rist * distributed with this work for additional information 6*323de322SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*323de322SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*323de322SAndrew Rist * "License"); you may not use this file except in compliance 9*323de322SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*323de322SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*323de322SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*323de322SAndrew Rist * software distributed under the License is distributed on an 15*323de322SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*323de322SAndrew Rist * KIND, either express or implied. See the License for the 17*323de322SAndrew Rist * specific language governing permissions and limitations 18*323de322SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*323de322SAndrew Rist *************************************************************/ 21*323de322SAndrew Rist 22*323de322SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir// MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir#include "precompiled_vcl.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir#include "aqua11ycomponentwrapper.h" 28cdf0e10cSrcweir#include "aqua11yrolehelper.h" 29cdf0e10cSrcweir#include <com/sun/star/accessibility/AccessibleRole.hpp> 30cdf0e10cSrcweir 31cdf0e10cSrcweirusing namespace ::com::sun::star::accessibility; 32cdf0e10cSrcweirusing namespace ::com::sun::star::awt; 33cdf0e10cSrcweirusing namespace ::com::sun::star::uno; 34cdf0e10cSrcweir 35cdf0e10cSrcweir// Wrapper for XAccessibleComponent and XAccessibleExtendedComponent 36cdf0e10cSrcweir 37cdf0e10cSrcweir@implementation AquaA11yComponentWrapper : NSObject 38cdf0e10cSrcweir 39cdf0e10cSrcweir+(id)sizeAttributeForElement:(AquaA11yWrapper *)wrapper { 40cdf0e10cSrcweir Size size = [ wrapper accessibleComponent ] -> getSize(); 41cdf0e10cSrcweir NSSize nsSize = NSMakeSize ( (float) size.Width, (float) size.Height ); 42cdf0e10cSrcweir return [ NSValue valueWithSize: nsSize ]; 43cdf0e10cSrcweir} 44cdf0e10cSrcweir 45cdf0e10cSrcweir// TODO: should be merged with AquaSalFrame::VCLToCocoa... to a general helper method 46cdf0e10cSrcweir+(id)positionAttributeForElement:(AquaA11yWrapper *)wrapper { 47cdf0e10cSrcweir // VCL coordinates are in upper-left-notation, Cocoa likes it the Cartesian way (lower-left) 48cdf0e10cSrcweir NSRect screenRect = [ [ NSScreen mainScreen ] frame ]; 49cdf0e10cSrcweir Size size = [ wrapper accessibleComponent ] -> getSize(); 50cdf0e10cSrcweir Point location = [ wrapper accessibleComponent ] -> getLocationOnScreen(); 51cdf0e10cSrcweir NSPoint nsPoint = NSMakePoint ( (float) location.X, (float) ( screenRect.size.height - size.Height - location.Y ) ); 52cdf0e10cSrcweir return [ NSValue valueWithPoint: nsPoint ]; 53cdf0e10cSrcweir} 54cdf0e10cSrcweir 55cdf0e10cSrcweir+(id)descriptionAttributeForElement:(AquaA11yWrapper *)wrapper { 56cdf0e10cSrcweir if ( [ wrapper accessibleExtendedComponent ] != nil ) { 57cdf0e10cSrcweir return CreateNSString ( [ wrapper accessibleExtendedComponent ] -> getToolTipText() ); 58cdf0e10cSrcweir } else { 59cdf0e10cSrcweir return nil; 60cdf0e10cSrcweir } 61cdf0e10cSrcweir} 62cdf0e10cSrcweir 63cdf0e10cSrcweir+(void)addAttributeNamesTo:(NSMutableArray *)attributeNames { 64cdf0e10cSrcweir NSAutoreleasePool * pool = [ [ NSAutoreleasePool alloc ] init ]; 65cdf0e10cSrcweir [ attributeNames addObjectsFromArray: [ NSArray arrayWithObjects: 66cdf0e10cSrcweir NSAccessibilitySizeAttribute, 67cdf0e10cSrcweir NSAccessibilityPositionAttribute, 68cdf0e10cSrcweir NSAccessibilityFocusedAttribute, 69cdf0e10cSrcweir NSAccessibilityEnabledAttribute, 70cdf0e10cSrcweir nil ] ]; 71cdf0e10cSrcweir [ pool release ]; 72cdf0e10cSrcweir} 73cdf0e10cSrcweir 74cdf0e10cSrcweir+(BOOL)isAttributeSettable:(NSString *)attribute forElement:(AquaA11yWrapper *)wrapper { 75cdf0e10cSrcweir BOOL isSettable = NO; 76cdf0e10cSrcweir NSAutoreleasePool * pool = [ [ NSAutoreleasePool alloc ] init ]; 77cdf0e10cSrcweir if ( [ attribute isEqualToString: NSAccessibilityFocusedAttribute ] 78cdf0e10cSrcweir && ! [ [ AquaA11yRoleHelper getNativeRoleFrom: [ wrapper accessibleContext ] ] isEqualToString: NSAccessibilityScrollBarRole ] 79cdf0e10cSrcweir && ! [ [ AquaA11yRoleHelper getNativeRoleFrom: [ wrapper accessibleContext ] ] isEqualToString: NSAccessibilityStaticTextRole ] ) { 80cdf0e10cSrcweir isSettable = YES; 81cdf0e10cSrcweir } 82cdf0e10cSrcweir [ pool release ]; 83cdf0e10cSrcweir return isSettable; 84cdf0e10cSrcweir} 85cdf0e10cSrcweir 86cdf0e10cSrcweir+(void)setFocusedAttributeForElement:(AquaA11yWrapper *)wrapper to:(id)value { 87cdf0e10cSrcweir if ( [ value boolValue ] == YES ) { 88cdf0e10cSrcweir if ( [ wrapper accessibleContext ] -> getAccessibleRole() == AccessibleRole::COMBO_BOX ) { 89cdf0e10cSrcweir // special treatment for comboboxes: find the corresponding PANEL and set focus to it 90cdf0e10cSrcweir Reference < XAccessible > rxParent = [ wrapper accessibleContext ] -> getAccessibleParent(); 91cdf0e10cSrcweir if ( rxParent.is() ) { 92cdf0e10cSrcweir Reference < XAccessibleContext > rxContext = rxParent->getAccessibleContext(); 93cdf0e10cSrcweir if ( rxContext.is() && rxContext -> getAccessibleRole() == AccessibleRole::PANEL ) { 94cdf0e10cSrcweir Reference < XAccessibleComponent > rxComponent = Reference < XAccessibleComponent > ( rxParent -> getAccessibleContext(), UNO_QUERY ); 95cdf0e10cSrcweir if ( rxComponent.is() ) { 96cdf0e10cSrcweir rxComponent -> grabFocus(); 97cdf0e10cSrcweir } 98cdf0e10cSrcweir } 99cdf0e10cSrcweir } 100cdf0e10cSrcweir } else { 101cdf0e10cSrcweir [ wrapper accessibleComponent ] -> grabFocus(); 102cdf0e10cSrcweir } 103cdf0e10cSrcweir } 104cdf0e10cSrcweir} 105cdf0e10cSrcweir 106cdf0e10cSrcweir@end 107