1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_comphelper.hxx"
30 #include <comphelper/accessibleselectionhelper.hxx>
31 
32 //.........................................................................
33 namespace comphelper
34 {
35 //.........................................................................
36 
37 	using namespace ::com::sun::star::uno;
38 	using namespace ::com::sun::star::awt;
39 	using namespace ::com::sun::star::lang;
40 	using namespace ::com::sun::star::accessibility;
41 
42 	//=====================================================================
43 	//= OCommonAccessibleSelection
44 	//=====================================================================
45 	//---------------------------------------------------------------------
46 	OCommonAccessibleSelection::OCommonAccessibleSelection( )
47 	{
48 	}
49 
50 	//--------------------------------------------------------------------
51     void SAL_CALL OCommonAccessibleSelection::selectAccessibleChild( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
52 	{
53         implSelect( nChildIndex, sal_True );
54 	}
55 
56 	//--------------------------------------------------------------------
57 	sal_Bool SAL_CALL OCommonAccessibleSelection::isAccessibleChildSelected( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
58 	{
59         return( implIsSelected( nChildIndex ) );
60 	}
61 
62 	//--------------------------------------------------------------------
63 	void SAL_CALL OCommonAccessibleSelection::clearAccessibleSelection(  ) throw (RuntimeException)
64     {
65         implSelect( ACCESSIBLE_SELECTION_CHILD_ALL, sal_False );
66     }
67 
68 	//--------------------------------------------------------------------
69 	void SAL_CALL OCommonAccessibleSelection::selectAllAccessibleChildren(  ) throw (RuntimeException)
70     {
71         implSelect( ACCESSIBLE_SELECTION_CHILD_ALL, sal_True );
72     }
73 
74 	//--------------------------------------------------------------------
75 	sal_Int32 SAL_CALL OCommonAccessibleSelection::getSelectedAccessibleChildCount(  ) throw (RuntimeException)
76     {
77         sal_Int32                       nRet = 0;
78         Reference< XAccessibleContext > xParentContext( implGetAccessibleContext() );
79 
80 		OSL_ENSURE( xParentContext.is(), "OCommonAccessibleSelection::getSelectedAccessibleChildCount: no parent context!" );
81 
82         if( xParentContext.is() )
83         {
84             for( sal_Int32 i = 0, nChildCount = xParentContext->getAccessibleChildCount(); i < nChildCount; i++ )
85                 if( implIsSelected( i ) )
86                     ++nRet;
87         }
88 
89         return( nRet );
90     }
91 
92 	//--------------------------------------------------------------------
93 	Reference< XAccessible > SAL_CALL OCommonAccessibleSelection::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
94     {
95         Reference< XAccessible >        xRet;
96         Reference< XAccessibleContext > xParentContext( implGetAccessibleContext() );
97 
98 		OSL_ENSURE( xParentContext.is(), "OCommonAccessibleSelection::getSelectedAccessibleChildCount: no parent context!" );
99 
100         if( xParentContext.is() )
101         {
102             for( sal_Int32 i = 0, nChildCount = xParentContext->getAccessibleChildCount(), nPos = 0; ( i < nChildCount ) && !xRet.is(); i++ )
103                 if( implIsSelected( i ) && ( nPos++ == nSelectedChildIndex ) )
104                     xRet = xParentContext->getAccessibleChild( i );
105         }
106 
107         return( xRet );
108     }
109 
110 	//--------------------------------------------------------------------
111 	void SAL_CALL OCommonAccessibleSelection::deselectAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
112     {
113         implSelect( nSelectedChildIndex, sal_False );
114     }
115 
116 	//=====================================================================
117 	//= OAccessibleSelectionHelper
118 	//=====================================================================
119 	//---------------------------------------------------------------------
120 	OAccessibleSelectionHelper::OAccessibleSelectionHelper( )
121 	{
122 	}
123 
124 	//--------------------------------------------------------------------
125 	OAccessibleSelectionHelper::OAccessibleSelectionHelper( IMutex* _pExternalLock ) : OAccessibleComponentHelper(_pExternalLock)
126 	{
127 	}
128 
129 	//--------------------------------------------------------------------
130 	IMPLEMENT_FORWARD_XINTERFACE2( OAccessibleSelectionHelper, OAccessibleComponentHelper, OAccessibleSelectionHelper_Base )
131 	IMPLEMENT_FORWARD_XTYPEPROVIDER2( OAccessibleSelectionHelper, OAccessibleComponentHelper, OAccessibleSelectionHelper_Base )
132 	// (order matters: the first is the class name, the second is the class doing the ref counting)
133 
134 	//--------------------------------------------------------------------
135     Reference< XAccessibleContext > OAccessibleSelectionHelper::implGetAccessibleContext() throw ( RuntimeException )
136     {
137         return( this );
138     }
139 
140 	//--------------------------------------------------------------------
141     void SAL_CALL OAccessibleSelectionHelper::selectAccessibleChild( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
142 	{
143 		OExternalLockGuard aGuard( this );
144         OCommonAccessibleSelection::selectAccessibleChild( nChildIndex );
145 	}
146 
147 	//--------------------------------------------------------------------
148 	sal_Bool SAL_CALL OAccessibleSelectionHelper::isAccessibleChildSelected( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
149 	{
150 		OExternalLockGuard aGuard( this );
151         return( OCommonAccessibleSelection::isAccessibleChildSelected( nChildIndex ) );
152 	}
153 
154 	//--------------------------------------------------------------------
155 	void SAL_CALL OAccessibleSelectionHelper::clearAccessibleSelection(  ) throw (RuntimeException)
156     {
157 		OExternalLockGuard aGuard( this );
158         OCommonAccessibleSelection::clearAccessibleSelection();
159     }
160 
161 	//--------------------------------------------------------------------
162 	void SAL_CALL OAccessibleSelectionHelper::selectAllAccessibleChildren(  ) throw (RuntimeException)
163     {
164 		OExternalLockGuard aGuard( this );
165         OCommonAccessibleSelection::selectAllAccessibleChildren();
166     }
167 
168 	//--------------------------------------------------------------------
169 	sal_Int32 SAL_CALL OAccessibleSelectionHelper::getSelectedAccessibleChildCount(  ) throw (RuntimeException)
170     {
171 		OExternalLockGuard aGuard( this );
172         return( OCommonAccessibleSelection::getSelectedAccessibleChildCount() );
173     }
174 
175 	//--------------------------------------------------------------------
176 	Reference< XAccessible > SAL_CALL OAccessibleSelectionHelper::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
177     {
178 		OExternalLockGuard aGuard( this );
179         return( OCommonAccessibleSelection::getSelectedAccessibleChild( nSelectedChildIndex ) );
180     }
181 
182 	//--------------------------------------------------------------------
183 	void SAL_CALL OAccessibleSelectionHelper::deselectAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
184     {
185 		OExternalLockGuard aGuard( this );
186         OCommonAccessibleSelection::deselectAccessibleChild( nSelectedChildIndex );
187     }
188 
189 //.........................................................................
190 }	// namespace comphelper
191 //.........................................................................
192 
193