1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
21#include <osx/salinst.h>
22#include <osx/a11yfactory.h>
23
24#include "a11yselectionwrapper.h"
25
26using namespace ::com::sun::star::accessibility;
27using namespace ::com::sun::star::uno;
28
29@implementation AquaA11ySelectionWrapper : NSObject
30
31+(id)selectedChildrenAttributeForElement:(AquaA11yWrapper *)wrapper
32{
33    Reference< XAccessibleSelection > xAccessibleSelection = [ wrapper accessibleSelection ];
34    if( xAccessibleSelection.is() )
35    {
36        NSMutableArray * children = [ [ NSMutableArray alloc ] init ];
37        try {
38            sal_Int32 n = xAccessibleSelection -> getSelectedAccessibleChildCount();
39            for ( sal_Int32 i=0 ; i < n ; ++i ) {
40                [ children addObject: [ AquaA11yFactory wrapperForAccessible: xAccessibleSelection -> getSelectedAccessibleChild( i ) ] ];
41            }
42
43            return children;
44
45        } catch ( Exception&)
46        {
47        }
48    }
49
50    return nil;
51}
52
53
54+(void)addAttributeNamesTo:(NSMutableArray *)attributeNames
55{
56    [ attributeNames addObject: NSAccessibilitySelectedChildrenAttribute ];
57}
58
59+(BOOL)isAttributeSettable:(NSString *)attribute forElement:(AquaA11yWrapper *)wrapper
60{
61    (void)wrapper;
62    if ( [ attribute isEqualToString: NSAccessibilitySelectedChildrenAttribute ] )
63    {
64        return YES;
65    }
66    else
67    {
68        return NO;
69    }
70}
71
72+(void)setSelectedChildrenAttributeForElement:(AquaA11yWrapper *)wrapper to:(id)value
73{
74    Reference< XAccessibleSelection > xAccessibleSelection = [ wrapper accessibleSelection ];
75    try {
76        xAccessibleSelection -> clearAccessibleSelection();
77
78        unsigned c = [ value count ];
79        for ( unsigned i = 0 ; i < c ; ++i ) {
80            xAccessibleSelection -> selectAccessibleChild( [ [ value objectAtIndex: i ] accessibleContext ] -> getAccessibleIndexInParent() );
81        }
82    } catch ( Exception&) {
83    }
84}
85
86@end
87
88/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
89