1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements.  See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership.  The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License.  You may obtain a copy of the License at
10 *
11 *   http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied.  See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24// MARKER(update_precomp.py): autogen include statement, do not remove
25#include "precompiled_vcl.hxx"
26
27#include "aqua11yvaluewrapper.h"
28#include "aqua11ywrapperstatictext.h"
29
30using namespace ::com::sun::star::uno;
31
32// Wrapper for XAccessibleValue
33// Remember: A UNO-Value is a single numeric value. Regarding the Mac A11y-API, a value can be anything!
34
35@implementation AquaA11yValueWrapper : NSObject
36
37+(id)valueAttributeForElement:(AquaA11yWrapper *)wrapper {
38    // TODO: Detect Type from Any
39    if ( [ wrapper accessibleValue ] != nil ) {
40        long value = 0;
41        [ wrapper accessibleValue ] -> getCurrentValue() >>= value;
42        return [ NSNumber numberWithLong: value ];
43    }
44    return [ NSNumber numberWithLong: 0 ];
45}
46
47+(id)minValueAttributeForElement:(AquaA11yWrapper *)wrapper {
48    // TODO: Detect Type from Any
49    if ( [ wrapper accessibleValue ] != nil ) {
50        long value = 0;
51        [ wrapper accessibleValue ] -> getMinimumValue() >>= value;
52        return [ NSNumber numberWithLong: value ];
53    }
54    return [ NSNumber numberWithLong: 0 ];
55}
56
57+(id)maxValueAttributeForElement:(AquaA11yWrapper *)wrapper {
58    // TODO: Detect Type from Any
59    if ( [ wrapper accessibleValue ] != nil ) {
60        long value = 0;
61        [ wrapper accessibleValue ] -> getMaximumValue() >>= value;
62        return [ NSNumber numberWithLong: value ];
63    }
64    return [ NSNumber numberWithLong: 0 ];
65}
66
67+(void)setValueAttributeForElement:(AquaA11yWrapper *)wrapper to:(id)value {
68    // TODO: Detect Type from NSNumber
69    if ( [ value isKindOfClass: [ NSNumber class ] ]
70      && [ wrapper accessibleValue ] != nil ) {
71        NSNumber * number = (NSNumber *) value;
72        Any numberAny ( [ number longValue ] );
73        [ wrapper accessibleValue ] -> setCurrentValue ( numberAny );
74    }
75}
76
77+(void)addAttributeNamesTo:(NSMutableArray *)attributeNames {
78    [ attributeNames addObject: NSAccessibilityValueAttribute ];
79}
80
81+(BOOL)isAttributeSettable:(NSString *)attribute forElement:(AquaA11yWrapper *)wrapper {
82    BOOL isSettable = NO;
83    if ( [ wrapper accessibleValue ] != nil
84      && [ attribute isEqualToString: NSAccessibilityValueAttribute ]
85      && ! [ wrapper isKindOfClass: [ AquaA11yWrapperStaticText class ] ] ) {
86        isSettable = YES;
87    }
88    return isSettable;
89}
90
91@end
92