xref: /trunk/main/sw/source/core/access/accselectionhelper.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
1efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5efeef26fSAndrew Rist  * distributed with this work for additional information
6efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17efeef26fSAndrew Rist  * specific language governing permissions and limitations
18efeef26fSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20efeef26fSAndrew Rist  *************************************************************/
21efeef26fSAndrew Rist 
22efeef26fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <com/sun/star/accessibility/XAccessibleSelection.hpp>
29cdf0e10cSrcweir #include <accselectionhelper.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <acccontext.hxx>
32cdf0e10cSrcweir #include <accmap.hxx>
33cdf0e10cSrcweir #include <svx/AccessibleShape.hxx>
34cdf0e10cSrcweir #include <viewsh.hxx>
35cdf0e10cSrcweir #include <fesh.hxx>
36cdf0e10cSrcweir #include <vcl/svapp.hxx>        // for SolarMutex
37cdf0e10cSrcweir #include <tools/debug.hxx>
38cdf0e10cSrcweir #include <flyfrm.hxx>
39cdf0e10cSrcweir 
40cdf0e10cSrcweir 
41*ca62e2c2SSteve Yin #include <com/sun/star/uno/Reference.hxx>
42*ca62e2c2SSteve Yin #include <com/sun/star/accessibility/AccessibleStateType.hpp>
43*ca62e2c2SSteve Yin #include <com/sun/star/accessibility/XAccessibleStateSet.hpp>
44*ca62e2c2SSteve Yin #include <fmtanchr.hxx>
45*ca62e2c2SSteve Yin 
46*ca62e2c2SSteve Yin using namespace ::com::sun::star::accessibility;
47cdf0e10cSrcweir using namespace ::com::sun::star;
48cdf0e10cSrcweir using namespace ::com::sun::star::uno;
49cdf0e10cSrcweir 
50cdf0e10cSrcweir using ::com::sun::star::accessibility::XAccessible;
51cdf0e10cSrcweir using ::com::sun::star::accessibility::XAccessibleContext;
52cdf0e10cSrcweir using ::com::sun::star::accessibility::XAccessibleSelection;
53cdf0e10cSrcweir 
54cdf0e10cSrcweir using namespace ::sw::access;
55cdf0e10cSrcweir 
SwAccessibleSelectionHelper(SwAccessibleContext & rCtxt)56cdf0e10cSrcweir SwAccessibleSelectionHelper::SwAccessibleSelectionHelper(
57cdf0e10cSrcweir     SwAccessibleContext& rCtxt ) :
58cdf0e10cSrcweir         rContext( rCtxt )
59cdf0e10cSrcweir {
60cdf0e10cSrcweir }
61cdf0e10cSrcweir 
~SwAccessibleSelectionHelper()62cdf0e10cSrcweir SwAccessibleSelectionHelper::~SwAccessibleSelectionHelper()
63cdf0e10cSrcweir {
64cdf0e10cSrcweir }
65cdf0e10cSrcweir 
GetFEShell()66cdf0e10cSrcweir SwFEShell* SwAccessibleSelectionHelper::GetFEShell()
67cdf0e10cSrcweir {
68cdf0e10cSrcweir     DBG_ASSERT( rContext.GetMap() != NULL, "no map?" );
69cdf0e10cSrcweir     ViewShell* pViewShell = rContext.GetMap()->GetShell();
70cdf0e10cSrcweir     DBG_ASSERT( pViewShell != NULL,
71cdf0e10cSrcweir                 "No view shell? Then what are you looking at?" );
72cdf0e10cSrcweir 
73cdf0e10cSrcweir     SwFEShell* pFEShell = NULL;
74cdf0e10cSrcweir     if( pViewShell->ISA( SwFEShell ) )
75cdf0e10cSrcweir     {
76cdf0e10cSrcweir         pFEShell = static_cast<SwFEShell*>( pViewShell );
77cdf0e10cSrcweir     }
78cdf0e10cSrcweir 
79cdf0e10cSrcweir     return pFEShell;
80cdf0e10cSrcweir }
81cdf0e10cSrcweir 
throwIndexOutOfBoundsException()82cdf0e10cSrcweir void SwAccessibleSelectionHelper::throwIndexOutOfBoundsException()
83cdf0e10cSrcweir         throw ( lang::IndexOutOfBoundsException )
84cdf0e10cSrcweir {
85cdf0e10cSrcweir     Reference < XAccessibleContext > xThis( &rContext );
86cdf0e10cSrcweir     Reference < XAccessibleSelection >xSelThis( xThis, UNO_QUERY );
87cdf0e10cSrcweir     lang::IndexOutOfBoundsException aExcept(
88cdf0e10cSrcweir                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("index out of bounds") ),
89cdf0e10cSrcweir                 xSelThis );                                     \
90cdf0e10cSrcweir     throw aExcept;
91cdf0e10cSrcweir }
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 
94cdf0e10cSrcweir //=====  XAccessibleSelection  ============================================
95cdf0e10cSrcweir 
selectAccessibleChild(sal_Int32 nChildIndex)96cdf0e10cSrcweir void SwAccessibleSelectionHelper::selectAccessibleChild(
97cdf0e10cSrcweir     sal_Int32 nChildIndex )
98cdf0e10cSrcweir     throw ( lang::IndexOutOfBoundsException,
99cdf0e10cSrcweir             RuntimeException )
100cdf0e10cSrcweir {
101cdf0e10cSrcweir     vos::OGuard aGuard(Application::GetSolarMutex());
102cdf0e10cSrcweir 
103cdf0e10cSrcweir     // Get the respective child as SwFrm (also do index checking), ...
104cdf0e10cSrcweir     const SwAccessibleChild aChild = rContext.GetChild( *(rContext.GetMap()),
105cdf0e10cSrcweir                                                         nChildIndex );
106cdf0e10cSrcweir     if( !aChild.IsValid() )
107cdf0e10cSrcweir         throwIndexOutOfBoundsException();
108cdf0e10cSrcweir 
109cdf0e10cSrcweir     // we can only select fly frames, so we ignore (should: return
110cdf0e10cSrcweir     // false) all other attempts at child selection
111cdf0e10cSrcweir     sal_Bool bRet = sal_False;
112cdf0e10cSrcweir     SwFEShell* pFEShell = GetFEShell();
113cdf0e10cSrcweir     if( pFEShell != NULL )
114cdf0e10cSrcweir     {
115cdf0e10cSrcweir         const SdrObject *pObj = aChild.GetDrawObject();
116cdf0e10cSrcweir         if( pObj )
117cdf0e10cSrcweir         {
118cdf0e10cSrcweir             bRet = rContext.Select( const_cast< SdrObject *>( pObj ), 0==aChild.GetSwFrm());
119cdf0e10cSrcweir         }
120cdf0e10cSrcweir     }
121cdf0e10cSrcweir     // no frame shell, or no frame, or no fly frame -> can't select
122cdf0e10cSrcweir 
123cdf0e10cSrcweir     // return bRet;
124cdf0e10cSrcweir }
125cdf0e10cSrcweir 
126*ca62e2c2SSteve Yin //When the selected state of the SwFrmOrObj is setted, return true.
lcl_getSelectedState(const SwAccessibleChild & aChild,SwAccessibleContext * pContext,SwAccessibleMap * pMap)127*ca62e2c2SSteve Yin static sal_Bool lcl_getSelectedState(const SwAccessibleChild& aChild,
128*ca62e2c2SSteve Yin                                      SwAccessibleContext* pContext,
129*ca62e2c2SSteve Yin                                      SwAccessibleMap* pMap)
130*ca62e2c2SSteve Yin {
131*ca62e2c2SSteve Yin     Reference< XAccessible > xAcc;
132*ca62e2c2SSteve Yin     if ( aChild.GetSwFrm() )
133*ca62e2c2SSteve Yin     {
134*ca62e2c2SSteve Yin         xAcc = pMap->GetContext( aChild.GetSwFrm(), sal_False );
135*ca62e2c2SSteve Yin     }
136*ca62e2c2SSteve Yin     else if ( aChild.GetDrawObject() )
137*ca62e2c2SSteve Yin     {
138*ca62e2c2SSteve Yin         xAcc = pMap->GetContext( aChild.GetDrawObject(), pContext, sal_False );
139*ca62e2c2SSteve Yin     }
140*ca62e2c2SSteve Yin 
141*ca62e2c2SSteve Yin     if( xAcc.is() )
142*ca62e2c2SSteve Yin     {
143*ca62e2c2SSteve Yin         Reference< XAccessibleContext > pRContext = xAcc->getAccessibleContext();
144*ca62e2c2SSteve Yin         if(!pRContext.is())
145*ca62e2c2SSteve Yin             return sal_False;
146*ca62e2c2SSteve Yin         Reference<XAccessibleStateSet> pRStateSet = pRContext->getAccessibleStateSet();
147*ca62e2c2SSteve Yin         if( pRStateSet.is() )
148*ca62e2c2SSteve Yin         {
149*ca62e2c2SSteve Yin             Sequence<short> pStates = pRStateSet->getStates();
150*ca62e2c2SSteve Yin             long count = pStates.getLength();
151*ca62e2c2SSteve Yin             for( int i = 0; i < count; i++ )
152*ca62e2c2SSteve Yin             {
153*ca62e2c2SSteve Yin                 if( pStates[i] == AccessibleStateType::SELECTED)
154*ca62e2c2SSteve Yin                     return sal_True;
155*ca62e2c2SSteve Yin             }
156*ca62e2c2SSteve Yin         }
157*ca62e2c2SSteve Yin     }
158*ca62e2c2SSteve Yin     return sal_False;
159*ca62e2c2SSteve Yin }
160*ca62e2c2SSteve Yin 
isAccessibleChildSelected(sal_Int32 nChildIndex)161cdf0e10cSrcweir sal_Bool SwAccessibleSelectionHelper::isAccessibleChildSelected(
162cdf0e10cSrcweir     sal_Int32 nChildIndex )
163cdf0e10cSrcweir     throw ( lang::IndexOutOfBoundsException,
164cdf0e10cSrcweir             RuntimeException )
165cdf0e10cSrcweir {
166cdf0e10cSrcweir     vos::OGuard aGuard(Application::GetSolarMutex());
167cdf0e10cSrcweir 
168cdf0e10cSrcweir     // Get the respective child as SwFrm (also do index checking), ...
169cdf0e10cSrcweir     const SwAccessibleChild aChild = rContext.GetChild( *(rContext.GetMap()),
170cdf0e10cSrcweir                                                         nChildIndex );
171cdf0e10cSrcweir     if( !aChild.IsValid() )
172cdf0e10cSrcweir         throwIndexOutOfBoundsException();
173cdf0e10cSrcweir 
174cdf0e10cSrcweir     // ... and compare to the currently selected frame
175cdf0e10cSrcweir     sal_Bool bRet = sal_False;
176cdf0e10cSrcweir     SwFEShell* pFEShell = GetFEShell();
177cdf0e10cSrcweir     if( pFEShell )
178cdf0e10cSrcweir     {
179cdf0e10cSrcweir         if ( aChild.GetSwFrm() != 0 )
180cdf0e10cSrcweir         {
181cdf0e10cSrcweir             bRet = (pFEShell->GetCurrFlyFrm() == aChild.GetSwFrm());
182cdf0e10cSrcweir         }
183cdf0e10cSrcweir         else if ( aChild.GetDrawObject() )
184cdf0e10cSrcweir         {
185cdf0e10cSrcweir             bRet = pFEShell->IsObjSelected( *aChild.GetDrawObject() );
186cdf0e10cSrcweir         }
187*ca62e2c2SSteve Yin         //If the SwFrmOrObj is not selected directly in the UI, we should check whether it is selected in the selection cursor.
188*ca62e2c2SSteve Yin         if( !bRet )
189*ca62e2c2SSteve Yin         {
190*ca62e2c2SSteve Yin             if( lcl_getSelectedState( aChild, &rContext, rContext.GetMap() ) == sal_True)
191*ca62e2c2SSteve Yin                 bRet = sal_True;
192*ca62e2c2SSteve Yin         }
193cdf0e10cSrcweir     }
194cdf0e10cSrcweir 
195cdf0e10cSrcweir     return bRet;
196cdf0e10cSrcweir }
197cdf0e10cSrcweir 
clearAccessibleSelection()198cdf0e10cSrcweir void SwAccessibleSelectionHelper::clearAccessibleSelection(  )
199cdf0e10cSrcweir     throw ( RuntimeException )
200cdf0e10cSrcweir {
201cdf0e10cSrcweir     // return sal_False     // we can't deselect
202cdf0e10cSrcweir }
203cdf0e10cSrcweir 
selectAllAccessibleChildren()204cdf0e10cSrcweir void SwAccessibleSelectionHelper::selectAllAccessibleChildren(  )
205cdf0e10cSrcweir     throw ( RuntimeException )
206cdf0e10cSrcweir {
207cdf0e10cSrcweir     vos::OGuard aGuard(Application::GetSolarMutex());
208cdf0e10cSrcweir 
209cdf0e10cSrcweir     // We can select only one. So iterate over the children to find
210cdf0e10cSrcweir     // the first we can select, and select it.
211cdf0e10cSrcweir 
212cdf0e10cSrcweir     SwFEShell* pFEShell = GetFEShell();
213cdf0e10cSrcweir     if( pFEShell )
214cdf0e10cSrcweir     {
215cdf0e10cSrcweir         ::std::list< SwAccessibleChild > aChildren;
216cdf0e10cSrcweir         rContext.GetChildren( *(rContext.GetMap()), aChildren );
217cdf0e10cSrcweir 
218cdf0e10cSrcweir         ::std::list< SwAccessibleChild >::const_iterator aIter = aChildren.begin();
219cdf0e10cSrcweir         ::std::list< SwAccessibleChild >::const_iterator aEndIter = aChildren.end();
220cdf0e10cSrcweir         while( aIter != aEndIter )
221cdf0e10cSrcweir         {
222cdf0e10cSrcweir             const SwAccessibleChild& rChild = *aIter;
223cdf0e10cSrcweir             const SdrObject* pObj = rChild.GetDrawObject();
224cdf0e10cSrcweir             const SwFrm* pFrm = rChild.GetSwFrm();
225cdf0e10cSrcweir             if( pObj && !(pFrm != 0 && pFEShell->IsObjSelected()) )
226cdf0e10cSrcweir             {
227cdf0e10cSrcweir                 rContext.Select( const_cast< SdrObject *>( pObj ), 0==pFrm );
228cdf0e10cSrcweir                 if( pFrm )
229cdf0e10cSrcweir                     break;
230cdf0e10cSrcweir             }
231cdf0e10cSrcweir             ++aIter;
232cdf0e10cSrcweir         }
233cdf0e10cSrcweir     }
234cdf0e10cSrcweir }
235cdf0e10cSrcweir 
getSelectedAccessibleChildCount()236cdf0e10cSrcweir sal_Int32 SwAccessibleSelectionHelper::getSelectedAccessibleChildCount(  )
237cdf0e10cSrcweir     throw ( RuntimeException )
238cdf0e10cSrcweir {
239cdf0e10cSrcweir     vos::OGuard aGuard(Application::GetSolarMutex());
240cdf0e10cSrcweir 
241cdf0e10cSrcweir     sal_Int32 nCount = 0;
242cdf0e10cSrcweir     // Only one frame can be selected at a time, and we only frames
243cdf0e10cSrcweir     // for selectable children.
244cdf0e10cSrcweir     SwFEShell* pFEShell = GetFEShell();
245cdf0e10cSrcweir     if( pFEShell != 0 )
246cdf0e10cSrcweir     {
247cdf0e10cSrcweir         const SwFlyFrm* pFlyFrm = pFEShell->GetCurrFlyFrm();
248cdf0e10cSrcweir         if( pFlyFrm )
249cdf0e10cSrcweir         {
250*ca62e2c2SSteve Yin             //if( rContext.GetParent( SwAccessibleChild(pFlyFrm), rContext.IsInPagePreview()) ==
251*ca62e2c2SSteve Yin             //        rContext.GetFrm() )
252cdf0e10cSrcweir                 nCount = 1;
253cdf0e10cSrcweir         }
254cdf0e10cSrcweir         else
255cdf0e10cSrcweir         {
256cdf0e10cSrcweir             sal_uInt16 nSelObjs = pFEShell->IsObjSelected();
257cdf0e10cSrcweir             if( nSelObjs > 0 )
258cdf0e10cSrcweir             {
259cdf0e10cSrcweir                 ::std::list< SwAccessibleChild > aChildren;
260cdf0e10cSrcweir                 rContext.GetChildren( *(rContext.GetMap()), aChildren );
261cdf0e10cSrcweir 
262cdf0e10cSrcweir                 ::std::list< SwAccessibleChild >::const_iterator aIter =
263cdf0e10cSrcweir                     aChildren.begin();
264cdf0e10cSrcweir                 ::std::list< SwAccessibleChild >::const_iterator aEndIter =
265cdf0e10cSrcweir                     aChildren.end();
266cdf0e10cSrcweir                 while( aIter != aEndIter && nCount < nSelObjs )
267cdf0e10cSrcweir                 {
268cdf0e10cSrcweir                     const SwAccessibleChild& rChild = *aIter;
269cdf0e10cSrcweir                     if( rChild.GetDrawObject() && !rChild.GetSwFrm() &&
270cdf0e10cSrcweir                         rContext.GetParent(rChild, rContext.IsInPagePreview())
271cdf0e10cSrcweir                            == rContext.GetFrm() &&
272cdf0e10cSrcweir                         pFEShell->IsObjSelected( *rChild.GetDrawObject() ) )
273cdf0e10cSrcweir                     {
274cdf0e10cSrcweir                         nCount++;
275cdf0e10cSrcweir                     }
276cdf0e10cSrcweir                     ++aIter;
277cdf0e10cSrcweir                 }
278cdf0e10cSrcweir             }
279cdf0e10cSrcweir         }
280*ca62e2c2SSteve Yin         //If the SwFrmOrObj is not selected directly in the UI,
281*ca62e2c2SSteve Yin         //we should check whether it is selected in the selection cursor.
282*ca62e2c2SSteve Yin         if( nCount == 0 )
283*ca62e2c2SSteve Yin         {
284*ca62e2c2SSteve Yin             ::std::list< SwAccessibleChild > aChildren;
285*ca62e2c2SSteve Yin             rContext.GetChildren( *(rContext.GetMap()), aChildren );
286*ca62e2c2SSteve Yin             ::std::list< SwAccessibleChild >::const_iterator aIter =
287*ca62e2c2SSteve Yin                 aChildren.begin();
288*ca62e2c2SSteve Yin             ::std::list< SwAccessibleChild >::const_iterator aEndIter =
289*ca62e2c2SSteve Yin                 aChildren.end();
290*ca62e2c2SSteve Yin             while( aIter != aEndIter )
291*ca62e2c2SSteve Yin             {
292*ca62e2c2SSteve Yin                 const SwAccessibleChild& aChild = *aIter;
293*ca62e2c2SSteve Yin                 if( lcl_getSelectedState( aChild, &rContext, rContext.GetMap() ) )
294*ca62e2c2SSteve Yin                     nCount++;
295*ca62e2c2SSteve Yin                 ++aIter;
296*ca62e2c2SSteve Yin             }
297*ca62e2c2SSteve Yin         }
298cdf0e10cSrcweir     }
299cdf0e10cSrcweir     return nCount;
300cdf0e10cSrcweir }
301cdf0e10cSrcweir 
getSelectedAccessibleChild(sal_Int32 nSelectedChildIndex)302cdf0e10cSrcweir Reference<XAccessible> SwAccessibleSelectionHelper::getSelectedAccessibleChild(
303cdf0e10cSrcweir     sal_Int32 nSelectedChildIndex )
304cdf0e10cSrcweir     throw ( lang::IndexOutOfBoundsException,
305cdf0e10cSrcweir             RuntimeException)
306cdf0e10cSrcweir {
307cdf0e10cSrcweir     vos::OGuard aGuard(Application::GetSolarMutex());
308cdf0e10cSrcweir 
309cdf0e10cSrcweir     // Since the index is relative to the selected children, and since
310cdf0e10cSrcweir     // there can be at most one selected frame child, the index must
311cdf0e10cSrcweir     // be 0, and a selection must exist, otherwise we have to throw an
312cdf0e10cSrcweir     // lang::IndexOutOfBoundsException
313cdf0e10cSrcweir     SwFEShell* pFEShell = GetFEShell();
314cdf0e10cSrcweir     if( 0 == pFEShell )
315cdf0e10cSrcweir         throwIndexOutOfBoundsException();
316cdf0e10cSrcweir 
317cdf0e10cSrcweir     SwAccessibleChild aChild;
318cdf0e10cSrcweir     const SwFlyFrm *pFlyFrm = pFEShell->GetCurrFlyFrm();
319cdf0e10cSrcweir     if( pFlyFrm )
320cdf0e10cSrcweir     {
321*ca62e2c2SSteve Yin         if( 0 == nSelectedChildIndex )
322*ca62e2c2SSteve Yin         {
323*ca62e2c2SSteve Yin             if(rContext.GetParent( SwAccessibleChild(pFlyFrm), rContext.IsInPagePreview()) == rContext.GetFrm() )
324cdf0e10cSrcweir             {
325cdf0e10cSrcweir                 aChild = pFlyFrm;
326cdf0e10cSrcweir             }
327*ca62e2c2SSteve Yin             else
328*ca62e2c2SSteve Yin             {
329*ca62e2c2SSteve Yin                 const SwFrmFmt *pFrmFmt = pFlyFrm->GetFmt();
330*ca62e2c2SSteve Yin                 if (pFrmFmt)
331*ca62e2c2SSteve Yin                 {
332*ca62e2c2SSteve Yin                     const SwFmtAnchor& pAnchor = pFrmFmt->GetAnchor();
333*ca62e2c2SSteve Yin                     if( pAnchor.GetAnchorId() == FLY_AS_CHAR )
334*ca62e2c2SSteve Yin                     {
335*ca62e2c2SSteve Yin                         const SwFrm  *pParaFrm =  rContext.GetParent( SwAccessibleChild(pFlyFrm), rContext.IsInPagePreview() );
336*ca62e2c2SSteve Yin                         aChild  = pParaFrm;
337*ca62e2c2SSteve Yin                     }
338*ca62e2c2SSteve Yin                 }
339*ca62e2c2SSteve Yin             }
340*ca62e2c2SSteve Yin         }
341cdf0e10cSrcweir     }
342cdf0e10cSrcweir     else
343cdf0e10cSrcweir     {
344cdf0e10cSrcweir         sal_uInt16 nSelObjs = pFEShell->IsObjSelected();
345cdf0e10cSrcweir         if( 0 == nSelObjs || nSelectedChildIndex >= nSelObjs )
346cdf0e10cSrcweir             throwIndexOutOfBoundsException();
347cdf0e10cSrcweir 
348cdf0e10cSrcweir         ::std::list< SwAccessibleChild > aChildren;
349cdf0e10cSrcweir         rContext.GetChildren( *(rContext.GetMap()), aChildren );
350cdf0e10cSrcweir 
351cdf0e10cSrcweir         ::std::list< SwAccessibleChild >::const_iterator aIter = aChildren.begin();
352cdf0e10cSrcweir         ::std::list< SwAccessibleChild >::const_iterator aEndIter = aChildren.end();
353cdf0e10cSrcweir         while( aIter != aEndIter && !aChild.IsValid() )
354cdf0e10cSrcweir         {
355cdf0e10cSrcweir             const SwAccessibleChild& rChild = *aIter;
356cdf0e10cSrcweir             if( rChild.GetDrawObject() && !rChild.GetSwFrm() &&
357cdf0e10cSrcweir                 rContext.GetParent(rChild, rContext.IsInPagePreview()) ==
358cdf0e10cSrcweir                     rContext.GetFrm() &&
359cdf0e10cSrcweir                 pFEShell->IsObjSelected( *rChild.GetDrawObject() ) )
360cdf0e10cSrcweir             {
361cdf0e10cSrcweir                 if( 0 == nSelectedChildIndex )
362cdf0e10cSrcweir                     aChild = rChild;
363cdf0e10cSrcweir                 else
364cdf0e10cSrcweir                     --nSelectedChildIndex;
365cdf0e10cSrcweir             }
366cdf0e10cSrcweir             ++aIter;
367cdf0e10cSrcweir         }
368cdf0e10cSrcweir     }
369cdf0e10cSrcweir 
370cdf0e10cSrcweir     if( !aChild.IsValid() )
371cdf0e10cSrcweir         throwIndexOutOfBoundsException();
372cdf0e10cSrcweir 
373cdf0e10cSrcweir     DBG_ASSERT( rContext.GetMap() != NULL, "We need the map." );
374cdf0e10cSrcweir     Reference< XAccessible > xChild;
375cdf0e10cSrcweir     if( aChild.GetSwFrm() )
376cdf0e10cSrcweir     {
377cdf0e10cSrcweir         ::vos::ORef < SwAccessibleContext > xChildImpl(
378cdf0e10cSrcweir                 rContext.GetMap()->GetContextImpl( aChild.GetSwFrm(),
379cdf0e10cSrcweir                 sal_True ) );
380cdf0e10cSrcweir         if( xChildImpl.isValid() )
381cdf0e10cSrcweir         {
382cdf0e10cSrcweir             xChildImpl->SetParent( &rContext );
383cdf0e10cSrcweir             xChild = xChildImpl.getBodyPtr();
384cdf0e10cSrcweir         }
385cdf0e10cSrcweir     }
386cdf0e10cSrcweir     else if ( aChild.GetDrawObject() )
387cdf0e10cSrcweir     {
388cdf0e10cSrcweir         ::vos::ORef < ::accessibility::AccessibleShape > xChildImpl(
389cdf0e10cSrcweir                 rContext.GetMap()->GetContextImpl( aChild.GetDrawObject(),
390cdf0e10cSrcweir                                           &rContext, sal_True )  );
391cdf0e10cSrcweir         if( xChildImpl.isValid() )
392cdf0e10cSrcweir             xChild = xChildImpl.getBodyPtr();
393cdf0e10cSrcweir     }
394cdf0e10cSrcweir     return xChild;
395cdf0e10cSrcweir }
396cdf0e10cSrcweir 
397cdf0e10cSrcweir // --> OD 2004-11-16 #111714# - index has to be treated as global child index.
deselectAccessibleChild(sal_Int32 nChildIndex)398cdf0e10cSrcweir void SwAccessibleSelectionHelper::deselectAccessibleChild(
399cdf0e10cSrcweir     sal_Int32 nChildIndex )
400cdf0e10cSrcweir     throw ( lang::IndexOutOfBoundsException,
401cdf0e10cSrcweir             RuntimeException )
402cdf0e10cSrcweir {
403cdf0e10cSrcweir     // return sal_False     // we can't deselect
404cdf0e10cSrcweir     if( nChildIndex < 0 ||
405cdf0e10cSrcweir         nChildIndex >= rContext.GetChildCount( *(rContext.GetMap()) ) )
406cdf0e10cSrcweir         throwIndexOutOfBoundsException();
407cdf0e10cSrcweir }
408