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 #include <comphelper/accessibleselectionhelper.hxx>
21 
22 
23 namespace comphelper
24 {
25 
26 
27     using namespace ::com::sun::star::uno;
28     using namespace ::com::sun::star::awt;
29     using namespace ::com::sun::star::lang;
30     using namespace ::com::sun::star::accessibility;
31 
OCommonAccessibleSelection()32     OCommonAccessibleSelection::OCommonAccessibleSelection( )
33     {
34     }
35 
~OCommonAccessibleSelection()36     OCommonAccessibleSelection::~OCommonAccessibleSelection() {}
37 
38 
selectAccessibleChild(sal_Int32 nChildIndex)39     void OCommonAccessibleSelection::selectAccessibleChild( sal_Int32 nChildIndex )
40     {
41         implSelect( nChildIndex, true );
42     }
43 
44 
isAccessibleChildSelected(sal_Int32 nChildIndex)45     bool OCommonAccessibleSelection::isAccessibleChildSelected( sal_Int32 nChildIndex )
46     {
47         return implIsSelected( nChildIndex );
48     }
49 
50 
clearAccessibleSelection()51     void OCommonAccessibleSelection::clearAccessibleSelection(  )
52     {
53         implSelect( ACCESSIBLE_SELECTION_CHILD_ALL, false );
54     }
55 
56 
selectAllAccessibleChildren()57     void OCommonAccessibleSelection::selectAllAccessibleChildren(  )
58     {
59         implSelect( ACCESSIBLE_SELECTION_CHILD_ALL, true );
60     }
61 
62 
getSelectedAccessibleChildCount()63     sal_Int32 OCommonAccessibleSelection::getSelectedAccessibleChildCount(  )
64     {
65         sal_Int32                       nRet = 0;
66         Reference< XAccessibleContext > xParentContext( implGetAccessibleContext() );
67 
68         OSL_ENSURE( xParentContext.is(), "OCommonAccessibleSelection::getSelectedAccessibleChildCount: no parent context!" );
69 
70         if( xParentContext.is() )
71         {
72             for( sal_Int32 i = 0, nChildCount = xParentContext->getAccessibleChildCount(); i < nChildCount; i++ )
73                 if( implIsSelected( i ) )
74                     ++nRet;
75         }
76 
77         return nRet;
78     }
79 
80 
getSelectedAccessibleChild(sal_Int32 nSelectedChildIndex)81     Reference< XAccessible > OCommonAccessibleSelection::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex )
82     {
83         Reference< XAccessible >        xRet;
84         Reference< XAccessibleContext > xParentContext( implGetAccessibleContext() );
85 
86         OSL_ENSURE( xParentContext.is(), "OCommonAccessibleSelection::getSelectedAccessibleChildCount: no parent context!" );
87 
88         if( xParentContext.is() )
89         {
90             for( sal_Int32 i = 0, nChildCount = xParentContext->getAccessibleChildCount(), nPos = 0; ( i < nChildCount ) && !xRet.is(); i++ )
91                 if( implIsSelected( i ) && ( nPos++ == nSelectedChildIndex ) )
92                     xRet = xParentContext->getAccessibleChild( i );
93         }
94 
95         return xRet;
96     }
97 
98 
deselectAccessibleChild(sal_Int32 nSelectedChildIndex)99     void OCommonAccessibleSelection::deselectAccessibleChild( sal_Int32 nSelectedChildIndex )
100     {
101         implSelect( nSelectedChildIndex, false );
102     }
103 
OAccessibleSelectionHelper()104     OAccessibleSelectionHelper::OAccessibleSelectionHelper()
105     {
106     }
107 
108 
IMPLEMENT_FORWARD_XINTERFACE2(OAccessibleSelectionHelper,OAccessibleComponentHelper,OAccessibleSelectionHelper_Base)109     IMPLEMENT_FORWARD_XINTERFACE2( OAccessibleSelectionHelper, OAccessibleComponentHelper, OAccessibleSelectionHelper_Base )
110     IMPLEMENT_FORWARD_XTYPEPROVIDER2( OAccessibleSelectionHelper, OAccessibleComponentHelper, OAccessibleSelectionHelper_Base )
111     // (order matters: the first is the class name, the second is the class doing the ref counting)
112 
113 
114     Reference< XAccessibleContext > OAccessibleSelectionHelper::implGetAccessibleContext()
115     {
116         return this;
117     }
118 
119 
selectAccessibleChild(sal_Int32 nChildIndex)120     void SAL_CALL OAccessibleSelectionHelper::selectAccessibleChild( sal_Int32 nChildIndex )
121     {
122         OExternalLockGuard aGuard( this );
123         OCommonAccessibleSelection::selectAccessibleChild( nChildIndex );
124     }
125 
126 
isAccessibleChildSelected(sal_Int32 nChildIndex)127     sal_Bool SAL_CALL OAccessibleSelectionHelper::isAccessibleChildSelected( sal_Int32 nChildIndex )
128     {
129         OExternalLockGuard aGuard( this );
130         return OCommonAccessibleSelection::isAccessibleChildSelected( nChildIndex );
131     }
132 
133 
clearAccessibleSelection()134     void SAL_CALL OAccessibleSelectionHelper::clearAccessibleSelection(  )
135     {
136         OExternalLockGuard aGuard( this );
137         OCommonAccessibleSelection::clearAccessibleSelection();
138     }
139 
140 
selectAllAccessibleChildren()141     void SAL_CALL OAccessibleSelectionHelper::selectAllAccessibleChildren(  )
142     {
143         OExternalLockGuard aGuard( this );
144         OCommonAccessibleSelection::selectAllAccessibleChildren();
145     }
146 
147 
getSelectedAccessibleChildCount()148     sal_Int32 SAL_CALL OAccessibleSelectionHelper::getSelectedAccessibleChildCount(  )
149     {
150         OExternalLockGuard aGuard( this );
151         return OCommonAccessibleSelection::getSelectedAccessibleChildCount();
152     }
153 
154 
getSelectedAccessibleChild(sal_Int32 nSelectedChildIndex)155     Reference< XAccessible > SAL_CALL OAccessibleSelectionHelper::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex )
156     {
157         OExternalLockGuard aGuard( this );
158         return OCommonAccessibleSelection::getSelectedAccessibleChild( nSelectedChildIndex );
159     }
160 
161 
deselectAccessibleChild(sal_Int32 nSelectedChildIndex)162     void SAL_CALL OAccessibleSelectionHelper::deselectAccessibleChild( sal_Int32 nSelectedChildIndex )
163     {
164         OExternalLockGuard aGuard( this );
165         OCommonAccessibleSelection::deselectAccessibleChild( nSelectedChildIndex );
166     }
167 
168 
169 }   // namespace comphelper
170 
171 
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
173