xref: /AOO41X/main/vcl/aqua/source/a11y/aqua11yvaluewrapper.mm (revision 323de322b8e3c385116436869e4ba6b658fb6405)
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 "aqua11yvaluewrapper.h"
28cdf0e10cSrcweir#include "aqua11ywrapperstatictext.h"
29cdf0e10cSrcweir
30cdf0e10cSrcweirusing namespace ::com::sun::star::uno;
31cdf0e10cSrcweir
32cdf0e10cSrcweir// Wrapper for XAccessibleValue
33cdf0e10cSrcweir// Remember: A UNO-Value is a single numeric value. Regarding the Mac A11y-API, a value can be anything!
34cdf0e10cSrcweir
35cdf0e10cSrcweir@implementation AquaA11yValueWrapper : NSObject
36cdf0e10cSrcweir
37cdf0e10cSrcweir+(id)valueAttributeForElement:(AquaA11yWrapper *)wrapper {
38cdf0e10cSrcweir    // TODO: Detect Type from Any
39cdf0e10cSrcweir    if ( [ wrapper accessibleValue ] != nil ) {
40cdf0e10cSrcweir        long value = 0;
41cdf0e10cSrcweir        [ wrapper accessibleValue ] -> getCurrentValue() >>= value;
42cdf0e10cSrcweir        return [ NSNumber numberWithLong: value ];
43cdf0e10cSrcweir    }
44cdf0e10cSrcweir    return [ NSNumber numberWithLong: 0 ];
45cdf0e10cSrcweir}
46cdf0e10cSrcweir
47cdf0e10cSrcweir+(id)minValueAttributeForElement:(AquaA11yWrapper *)wrapper {
48cdf0e10cSrcweir    // TODO: Detect Type from Any
49cdf0e10cSrcweir    if ( [ wrapper accessibleValue ] != nil ) {
50cdf0e10cSrcweir        long value = 0;
51cdf0e10cSrcweir        [ wrapper accessibleValue ] -> getMinimumValue() >>= value;
52cdf0e10cSrcweir        return [ NSNumber numberWithLong: value ];
53cdf0e10cSrcweir    }
54cdf0e10cSrcweir    return [ NSNumber numberWithLong: 0 ];
55cdf0e10cSrcweir}
56cdf0e10cSrcweir
57cdf0e10cSrcweir+(id)maxValueAttributeForElement:(AquaA11yWrapper *)wrapper {
58cdf0e10cSrcweir    // TODO: Detect Type from Any
59cdf0e10cSrcweir    if ( [ wrapper accessibleValue ] != nil ) {
60cdf0e10cSrcweir        long value = 0;
61cdf0e10cSrcweir        [ wrapper accessibleValue ] -> getMaximumValue() >>= value;
62cdf0e10cSrcweir        return [ NSNumber numberWithLong: value ];
63cdf0e10cSrcweir    }
64cdf0e10cSrcweir    return [ NSNumber numberWithLong: 0 ];
65cdf0e10cSrcweir}
66cdf0e10cSrcweir
67cdf0e10cSrcweir+(void)setValueAttributeForElement:(AquaA11yWrapper *)wrapper to:(id)value {
68cdf0e10cSrcweir    // TODO: Detect Type from NSNumber
69cdf0e10cSrcweir    if ( [ value isKindOfClass: [ NSNumber class ] ]
70cdf0e10cSrcweir      && [ wrapper accessibleValue ] != nil ) {
71cdf0e10cSrcweir        NSNumber * number = (NSNumber *) value;
72cdf0e10cSrcweir        Any numberAny ( [ number longValue ] );
73cdf0e10cSrcweir        [ wrapper accessibleValue ] -> setCurrentValue ( numberAny );
74cdf0e10cSrcweir    }
75cdf0e10cSrcweir}
76cdf0e10cSrcweir
77cdf0e10cSrcweir+(void)addAttributeNamesTo:(NSMutableArray *)attributeNames {
78cdf0e10cSrcweir    [ attributeNames addObject: NSAccessibilityValueAttribute ];
79cdf0e10cSrcweir}
80cdf0e10cSrcweir
81cdf0e10cSrcweir+(BOOL)isAttributeSettable:(NSString *)attribute forElement:(AquaA11yWrapper *)wrapper {
82cdf0e10cSrcweir    BOOL isSettable = NO;
83cdf0e10cSrcweir    if ( [ wrapper accessibleValue ] != nil
84cdf0e10cSrcweir      && [ attribute isEqualToString: NSAccessibilityValueAttribute ]
85cdf0e10cSrcweir      && ! [ wrapper isKindOfClass: [ AquaA11yWrapperStaticText class ] ] ) {
86cdf0e10cSrcweir        isSettable = YES;
87cdf0e10cSrcweir    }
88cdf0e10cSrcweir    return isSettable;
89cdf0e10cSrcweir}
90cdf0e10cSrcweir
91cdf0e10cSrcweir@end
92