Line data Source code
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 <com/sun/star/accessibility/XAccessibleSelection.hpp>
21 : #include <accselectionhelper.hxx>
22 :
23 : #include <acccontext.hxx>
24 : #include <accmap.hxx>
25 : #include <svx/AccessibleShape.hxx>
26 : #include <viewsh.hxx>
27 : #include <fesh.hxx>
28 : #include <vcl/svapp.hxx> // for SolarMutex
29 : #include <flyfrm.hxx>
30 :
31 :
32 : using namespace ::com::sun::star;
33 : using namespace ::com::sun::star::uno;
34 :
35 : using ::com::sun::star::accessibility::XAccessible;
36 : using ::com::sun::star::accessibility::XAccessibleContext;
37 : using ::com::sun::star::accessibility::XAccessibleSelection;
38 :
39 : using namespace ::sw::access;
40 :
41 0 : SwAccessibleSelectionHelper::SwAccessibleSelectionHelper(
42 : SwAccessibleContext& rCtxt ) :
43 0 : rContext( rCtxt )
44 : {
45 0 : }
46 :
47 0 : SwAccessibleSelectionHelper::~SwAccessibleSelectionHelper()
48 : {
49 0 : }
50 :
51 0 : SwFEShell* SwAccessibleSelectionHelper::GetFEShell()
52 : {
53 : OSL_ENSURE( rContext.GetMap() != NULL, "no map?" );
54 0 : ViewShell* pViewShell = rContext.GetMap()->GetShell();
55 : OSL_ENSURE( pViewShell != NULL,
56 : "No view shell? Then what are you looking at?" );
57 :
58 0 : SwFEShell* pFEShell = NULL;
59 0 : if( pViewShell->ISA( SwFEShell ) )
60 : {
61 0 : pFEShell = static_cast<SwFEShell*>( pViewShell );
62 : }
63 :
64 0 : return pFEShell;
65 : }
66 :
67 0 : void SwAccessibleSelectionHelper::throwIndexOutOfBoundsException()
68 : throw ( lang::IndexOutOfBoundsException )
69 : {
70 0 : Reference < XAccessibleContext > xThis( &rContext );
71 0 : Reference < XAccessibleSelection >xSelThis( xThis, UNO_QUERY );
72 : lang::IndexOutOfBoundsException aExcept(
73 : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("index out of bounds") ),
74 0 : xSelThis ); \
75 0 : throw aExcept;
76 : }
77 :
78 :
79 : //===== XAccessibleSelection ============================================
80 :
81 0 : void SwAccessibleSelectionHelper::selectAccessibleChild(
82 : sal_Int32 nChildIndex )
83 : throw ( lang::IndexOutOfBoundsException,
84 : RuntimeException )
85 : {
86 0 : SolarMutexGuard aGuard;
87 :
88 : // Get the respective child as SwFrm (also do index checking), ...
89 0 : const SwAccessibleChild aChild = rContext.GetChild( *(rContext.GetMap()),
90 0 : nChildIndex );
91 0 : if( !aChild.IsValid() )
92 0 : throwIndexOutOfBoundsException();
93 :
94 : // we can only select fly frames, so we ignore (should: return
95 : // false) all other attempts at child selection
96 0 : SwFEShell* pFEShell = GetFEShell();
97 0 : if( pFEShell != NULL )
98 : {
99 0 : const SdrObject *pObj = aChild.GetDrawObject();
100 0 : if( pObj )
101 0 : rContext.Select( const_cast< SdrObject *>( pObj ), 0==aChild.GetSwFrm());
102 0 : }
103 : // no frame shell, or no frame, or no fly frame -> can't select
104 0 : }
105 :
106 0 : sal_Bool SwAccessibleSelectionHelper::isAccessibleChildSelected(
107 : sal_Int32 nChildIndex )
108 : throw ( lang::IndexOutOfBoundsException,
109 : RuntimeException )
110 : {
111 0 : SolarMutexGuard aGuard;
112 :
113 : // Get the respective child as SwFrm (also do index checking), ...
114 0 : const SwAccessibleChild aChild = rContext.GetChild( *(rContext.GetMap()),
115 0 : nChildIndex );
116 0 : if( !aChild.IsValid() )
117 0 : throwIndexOutOfBoundsException();
118 :
119 : // ... and compare to the currently selected frame
120 0 : sal_Bool bRet = sal_False;
121 0 : SwFEShell* pFEShell = GetFEShell();
122 0 : if( pFEShell )
123 : {
124 0 : if ( aChild.GetSwFrm() != 0 )
125 : {
126 0 : bRet = (pFEShell->GetCurrFlyFrm() == aChild.GetSwFrm());
127 : }
128 0 : else if ( aChild.GetDrawObject() )
129 : {
130 0 : bRet = pFEShell->IsObjSelected( *aChild.GetDrawObject() );
131 : }
132 : }
133 :
134 0 : return bRet;
135 : }
136 :
137 0 : void SwAccessibleSelectionHelper::clearAccessibleSelection( )
138 : throw ( RuntimeException )
139 : {
140 : // return sal_False // we can't deselect
141 0 : }
142 :
143 0 : void SwAccessibleSelectionHelper::selectAllAccessibleChildren( )
144 : throw ( RuntimeException )
145 : {
146 0 : SolarMutexGuard aGuard;
147 :
148 : // We can select only one. So iterate over the children to find
149 : // the first we can select, and select it.
150 :
151 0 : SwFEShell* pFEShell = GetFEShell();
152 0 : if( pFEShell )
153 : {
154 0 : ::std::list< SwAccessibleChild > aChildren;
155 0 : rContext.GetChildren( *(rContext.GetMap()), aChildren );
156 :
157 0 : ::std::list< SwAccessibleChild >::const_iterator aIter = aChildren.begin();
158 0 : ::std::list< SwAccessibleChild >::const_iterator aEndIter = aChildren.end();
159 0 : while( aIter != aEndIter )
160 : {
161 0 : const SwAccessibleChild& rChild = *aIter;
162 0 : const SdrObject* pObj = rChild.GetDrawObject();
163 0 : const SwFrm* pFrm = rChild.GetSwFrm();
164 0 : if( pObj && !(pFrm != 0 && pFEShell->IsObjSelected()) )
165 : {
166 0 : rContext.Select( const_cast< SdrObject *>( pObj ), 0==pFrm );
167 0 : if( pFrm )
168 0 : break;
169 : }
170 0 : ++aIter;
171 0 : }
172 0 : }
173 0 : }
174 :
175 0 : sal_Int32 SwAccessibleSelectionHelper::getSelectedAccessibleChildCount( )
176 : throw ( RuntimeException )
177 : {
178 0 : SolarMutexGuard aGuard;
179 :
180 0 : sal_Int32 nCount = 0;
181 : // Only one frame can be selected at a time, and we only frames
182 : // for selectable children.
183 0 : SwFEShell* pFEShell = GetFEShell();
184 0 : if( pFEShell != 0 )
185 : {
186 0 : const SwFlyFrm* pFlyFrm = pFEShell->GetCurrFlyFrm();
187 0 : if( pFlyFrm )
188 : {
189 0 : if( rContext.GetParent( SwAccessibleChild(pFlyFrm), rContext.IsInPagePreview()) ==
190 0 : rContext.GetFrm() )
191 : {
192 0 : nCount = 1;
193 : }
194 : }
195 : else
196 : {
197 0 : sal_uInt16 nSelObjs = pFEShell->IsObjSelected();
198 0 : if( nSelObjs > 0 )
199 : {
200 0 : ::std::list< SwAccessibleChild > aChildren;
201 0 : rContext.GetChildren( *(rContext.GetMap()), aChildren );
202 :
203 : ::std::list< SwAccessibleChild >::const_iterator aIter =
204 0 : aChildren.begin();
205 : ::std::list< SwAccessibleChild >::const_iterator aEndIter =
206 0 : aChildren.end();
207 0 : while( aIter != aEndIter && nCount < nSelObjs )
208 : {
209 0 : const SwAccessibleChild& rChild = *aIter;
210 0 : if( rChild.GetDrawObject() && !rChild.GetSwFrm() &&
211 0 : rContext.GetParent(rChild, rContext.IsInPagePreview())
212 0 : == rContext.GetFrm() &&
213 0 : pFEShell->IsObjSelected( *rChild.GetDrawObject() ) )
214 : {
215 0 : nCount++;
216 : }
217 0 : ++aIter;
218 0 : }
219 : }
220 : }
221 : }
222 0 : return nCount;
223 : }
224 :
225 0 : Reference<XAccessible> SwAccessibleSelectionHelper::getSelectedAccessibleChild(
226 : sal_Int32 nSelectedChildIndex )
227 : throw ( lang::IndexOutOfBoundsException,
228 : RuntimeException)
229 : {
230 0 : SolarMutexGuard aGuard;
231 :
232 : // Since the index is relative to the selected children, and since
233 : // there can be at most one selected frame child, the index must
234 : // be 0, and a selection must exist, otherwise we have to throw an
235 : // lang::IndexOutOfBoundsException
236 0 : SwFEShell* pFEShell = GetFEShell();
237 0 : if( 0 == pFEShell )
238 0 : throwIndexOutOfBoundsException();
239 :
240 0 : SwAccessibleChild aChild;
241 0 : const SwFlyFrm *pFlyFrm = pFEShell->GetCurrFlyFrm();
242 0 : if( pFlyFrm )
243 : {
244 0 : if( 0 == nSelectedChildIndex &&
245 0 : rContext.GetParent( SwAccessibleChild(pFlyFrm), rContext.IsInPagePreview()) ==
246 0 : rContext.GetFrm() )
247 : {
248 0 : aChild = pFlyFrm;
249 : }
250 : }
251 : else
252 : {
253 0 : sal_uInt16 nSelObjs = pFEShell->IsObjSelected();
254 0 : if( 0 == nSelObjs || nSelectedChildIndex >= nSelObjs )
255 0 : throwIndexOutOfBoundsException();
256 :
257 0 : ::std::list< SwAccessibleChild > aChildren;
258 0 : rContext.GetChildren( *(rContext.GetMap()), aChildren );
259 :
260 0 : ::std::list< SwAccessibleChild >::const_iterator aIter = aChildren.begin();
261 0 : ::std::list< SwAccessibleChild >::const_iterator aEndIter = aChildren.end();
262 0 : while( aIter != aEndIter && !aChild.IsValid() )
263 : {
264 0 : const SwAccessibleChild& rChild = *aIter;
265 0 : if( rChild.GetDrawObject() && !rChild.GetSwFrm() &&
266 0 : rContext.GetParent(rChild, rContext.IsInPagePreview()) ==
267 0 : rContext.GetFrm() &&
268 0 : pFEShell->IsObjSelected( *rChild.GetDrawObject() ) )
269 : {
270 0 : if( 0 == nSelectedChildIndex )
271 0 : aChild = rChild;
272 : else
273 0 : --nSelectedChildIndex;
274 : }
275 0 : ++aIter;
276 0 : }
277 : }
278 :
279 0 : if( !aChild.IsValid() )
280 0 : throwIndexOutOfBoundsException();
281 :
282 : OSL_ENSURE( rContext.GetMap() != NULL, "We need the map." );
283 0 : Reference< XAccessible > xChild;
284 0 : if( aChild.GetSwFrm() )
285 : {
286 : ::rtl::Reference < SwAccessibleContext > xChildImpl(
287 : rContext.GetMap()->GetContextImpl( aChild.GetSwFrm(),
288 0 : sal_True ) );
289 0 : if( xChildImpl.is() )
290 : {
291 0 : xChildImpl->SetParent( &rContext );
292 0 : xChild = xChildImpl.get();
293 0 : }
294 : }
295 0 : else if ( aChild.GetDrawObject() )
296 : {
297 : ::rtl::Reference < ::accessibility::AccessibleShape > xChildImpl(
298 : rContext.GetMap()->GetContextImpl( aChild.GetDrawObject(),
299 0 : &rContext, sal_True ) );
300 0 : if( xChildImpl.is() )
301 0 : xChild = xChildImpl.get();
302 : }
303 0 : return xChild;
304 : }
305 :
306 : // index has to be treated as global child index.
307 0 : void SwAccessibleSelectionHelper::deselectAccessibleChild(
308 : sal_Int32 nChildIndex )
309 : throw ( lang::IndexOutOfBoundsException,
310 : RuntimeException )
311 : {
312 : // return sal_False // we can't deselect
313 0 : if( nChildIndex < 0 ||
314 0 : nChildIndex >= rContext.GetChildCount( *(rContext.GetMap()) ) )
315 0 : throwIndexOutOfBoundsException();
316 0 : }
317 :
318 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|