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