1efeef26fSAndrew Rist /**************************************************************
2efeef26fSAndrew Rist  *
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
10efeef26fSAndrew Rist  *
11efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12efeef26fSAndrew Rist  *
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.
19efeef26fSAndrew Rist  *
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 #include <accfrmobjmap.hxx>
28cdf0e10cSrcweir #include <accframe.hxx>
29cdf0e10cSrcweir #include <accmap.hxx>
30cdf0e10cSrcweir #include <acccontext.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <viewsh.hxx>
33cdf0e10cSrcweir #include <doc.hxx>
34cdf0e10cSrcweir #include <frmfmt.hxx>
35cdf0e10cSrcweir #include <pagefrm.hxx>
36cdf0e10cSrcweir #include <txtfrm.hxx>
37cdf0e10cSrcweir #include <node.hxx>
38cdf0e10cSrcweir #include <sortedobjs.hxx>
39cdf0e10cSrcweir #include <anchoredobject.hxx>
40cdf0e10cSrcweir 
41cdf0e10cSrcweir #include <svx/svdobj.hxx>
42cdf0e10cSrcweir 
43cdf0e10cSrcweir using namespace sw::access;
44cdf0e10cSrcweir 
SwAccessibleChildMap(const SwRect & rVisArea,const SwFrm & rFrm,SwAccessibleMap & rAccMap)45cdf0e10cSrcweir SwAccessibleChildMap::SwAccessibleChildMap( const SwRect& rVisArea,
46cdf0e10cSrcweir                                             const SwFrm& rFrm,
47cdf0e10cSrcweir                                             SwAccessibleMap& rAccMap )
48cdf0e10cSrcweir     : nHellId( rAccMap.GetShell()->GetDoc()->GetHellId() )
49cdf0e10cSrcweir     , nControlsId( rAccMap.GetShell()->GetDoc()->GetControlsId() )
50cdf0e10cSrcweir {
51cdf0e10cSrcweir     const bool bVisibleChildrenOnly = SwAccessibleChild( &rFrm ).IsVisibleChildrenOnly();
52cdf0e10cSrcweir 
53cdf0e10cSrcweir     sal_uInt32 nPos = 0;
54cdf0e10cSrcweir     SwAccessibleChild aLower( rFrm.GetLower() );
55cdf0e10cSrcweir     while( aLower.GetSwFrm() )
56cdf0e10cSrcweir     {
57cdf0e10cSrcweir         if ( !bVisibleChildrenOnly ||
58cdf0e10cSrcweir              aLower.AlwaysIncludeAsChild() ||
59cdf0e10cSrcweir              aLower.GetBox( rAccMap ).IsOver( rVisArea ) )
60cdf0e10cSrcweir         {
61cdf0e10cSrcweir             insert( nPos++, SwAccessibleChildMapKey::TEXT, aLower );
62cdf0e10cSrcweir         }
63cdf0e10cSrcweir 
64cdf0e10cSrcweir         aLower = aLower.GetSwFrm()->GetNext();
65cdf0e10cSrcweir     }
66cdf0e10cSrcweir 
67cdf0e10cSrcweir     if ( rFrm.IsPageFrm() )
68cdf0e10cSrcweir     {
69cdf0e10cSrcweir         ASSERT( bVisibleChildrenOnly, "page frame within tab frame???" );
70cdf0e10cSrcweir         const SwPageFrm *pPgFrm =
71cdf0e10cSrcweir             static_cast< const SwPageFrm * >( &rFrm );
72cdf0e10cSrcweir         const SwSortedObjs *pObjs = pPgFrm->GetSortedObjs();
73cdf0e10cSrcweir         if ( pObjs )
74cdf0e10cSrcweir         {
75cdf0e10cSrcweir             for( sal_uInt16 i=0; i<pObjs->Count(); i++ )
76cdf0e10cSrcweir             {
77cdf0e10cSrcweir                 aLower = (*pObjs)[i]->GetDrawObj();
78cdf0e10cSrcweir                 if ( aLower.GetBox( rAccMap ).IsOver( rVisArea ) )
79cdf0e10cSrcweir                 {
80cdf0e10cSrcweir                     insert( aLower.GetDrawObject(), aLower );
81cdf0e10cSrcweir                 }
82cdf0e10cSrcweir             }
83cdf0e10cSrcweir         }
84cdf0e10cSrcweir     }
85cdf0e10cSrcweir     else if( rFrm.IsTxtFrm() )
86cdf0e10cSrcweir     {
87cdf0e10cSrcweir         const SwSortedObjs *pObjs = rFrm.GetDrawObjs();
88cdf0e10cSrcweir         if ( pObjs )
89cdf0e10cSrcweir         {
90cdf0e10cSrcweir             for( sal_uInt16 i=0; i<pObjs->Count(); i++ )
91cdf0e10cSrcweir             {
92cdf0e10cSrcweir                 aLower = (*pObjs)[i]->GetDrawObj();
93cdf0e10cSrcweir                 if ( aLower.IsBoundAsChar() &&
94cdf0e10cSrcweir                      ( !bVisibleChildrenOnly ||
95cdf0e10cSrcweir                        aLower.AlwaysIncludeAsChild() ||
96cdf0e10cSrcweir                        aLower.GetBox( rAccMap ).IsOver( rVisArea ) ) )
97cdf0e10cSrcweir                 {
98cdf0e10cSrcweir                     insert( aLower.GetDrawObject(), aLower );
99cdf0e10cSrcweir                 }
100cdf0e10cSrcweir             }
101cdf0e10cSrcweir         }
102cdf0e10cSrcweir 
103cdf0e10cSrcweir         {
104cdf0e10cSrcweir             ::vos::ORef < SwAccessibleContext > xAccImpl =
105cdf0e10cSrcweir                                 rAccMap.GetContextImpl( &rFrm, sal_False );
106cdf0e10cSrcweir             if( xAccImpl.isValid() )
107cdf0e10cSrcweir             {
108cdf0e10cSrcweir                 SwAccessibleContext* pAccImpl = xAccImpl.getBodyPtr();
109cdf0e10cSrcweir                 if ( pAccImpl &&
110cdf0e10cSrcweir                      pAccImpl->HasAdditionalAccessibleChildren() )
111cdf0e10cSrcweir                 {
112cdf0e10cSrcweir                     std::vector< Window* >* pAdditionalChildren =
113cdf0e10cSrcweir                                                 new std::vector< Window* >();
114cdf0e10cSrcweir                     pAccImpl->GetAdditionalAccessibleChildren( pAdditionalChildren );
115cdf0e10cSrcweir 
116cdf0e10cSrcweir                     sal_Int32 nCounter( 0 );
117cdf0e10cSrcweir                     for ( std::vector< Window* >::iterator aIter = pAdditionalChildren->begin();
118cdf0e10cSrcweir                           aIter != pAdditionalChildren->end();
119cdf0e10cSrcweir                           ++aIter )
120cdf0e10cSrcweir                     {
121cdf0e10cSrcweir                         aLower = (*aIter);
122cdf0e10cSrcweir                         insert( ++nCounter, SwAccessibleChildMapKey::XWINDOW, aLower );
123cdf0e10cSrcweir                     }
124cdf0e10cSrcweir 
125cdf0e10cSrcweir                     delete pAdditionalChildren;
126cdf0e10cSrcweir                 }
127cdf0e10cSrcweir             }
128cdf0e10cSrcweir         }
129cdf0e10cSrcweir     }
130cdf0e10cSrcweir }
131cdf0e10cSrcweir 
insert(const sal_uInt32 nPos,const SwAccessibleChildMapKey::LayerId eLayerId,const SwAccessibleChild & rLower)132cdf0e10cSrcweir ::std::pair< SwAccessibleChildMap::iterator, bool > SwAccessibleChildMap::insert(
133cdf0e10cSrcweir                                                 const sal_uInt32 nPos,
134cdf0e10cSrcweir                                                 const SwAccessibleChildMapKey::LayerId eLayerId,
135cdf0e10cSrcweir                                                 const SwAccessibleChild& rLower )
136cdf0e10cSrcweir {
137cdf0e10cSrcweir     SwAccessibleChildMapKey aKey( eLayerId, nPos );
138cdf0e10cSrcweir 	value_type aEntry( aKey, rLower );
139cdf0e10cSrcweir     return _SwAccessibleChildMap::insert( aEntry );
140cdf0e10cSrcweir }
141cdf0e10cSrcweir 
insert(const SdrObject * pObj,const SwAccessibleChild & rLower)142cdf0e10cSrcweir ::std::pair< SwAccessibleChildMap::iterator, bool > SwAccessibleChildMap::insert(
143cdf0e10cSrcweir                                                 const SdrObject *pObj,
144cdf0e10cSrcweir                                                 const SwAccessibleChild& rLower )
145cdf0e10cSrcweir {
146cdf0e10cSrcweir     const SdrLayerID nLayer = pObj->GetLayer();
147cdf0e10cSrcweir     SwAccessibleChildMapKey::LayerId eLayerId =
148cdf0e10cSrcweir                     (nHellId == nLayer)
149cdf0e10cSrcweir                     ? SwAccessibleChildMapKey::HELL
150cdf0e10cSrcweir                     : ( (nControlsId == nLayer)
151cdf0e10cSrcweir                         ? SwAccessibleChildMapKey::CONTROLS
152cdf0e10cSrcweir                         : SwAccessibleChildMapKey::HEAVEN );
153cdf0e10cSrcweir     SwAccessibleChildMapKey aKey( eLayerId, pObj->GetOrdNum() );
154cdf0e10cSrcweir 	value_type aEntry( aKey, rLower );
155cdf0e10cSrcweir     return _SwAccessibleChildMap::insert( aEntry );
156cdf0e10cSrcweir }
157cdf0e10cSrcweir 
IsSortingRequired(const SwFrm & rFrm)158cdf0e10cSrcweir /* static */ sal_Bool SwAccessibleChildMap::IsSortingRequired( const SwFrm& rFrm )
159cdf0e10cSrcweir {
160cdf0e10cSrcweir     return ( rFrm.IsPageFrm() &&
161cdf0e10cSrcweir              static_cast< const SwPageFrm& >( rFrm ).GetSortedObjs() ) ||
162cdf0e10cSrcweir            ( rFrm.IsTxtFrm() &&
163cdf0e10cSrcweir              rFrm.GetDrawObjs() );
164cdf0e10cSrcweir }
165*ca62e2c2SSteve Yin 
166