1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 
27 #include <accfrmobjmap.hxx>
28 #include <accframe.hxx>
29 #include <accmap.hxx>
30 #include <acccontext.hxx>
31 
32 #include <viewsh.hxx>
33 #include <doc.hxx>
34 #include <frmfmt.hxx>
35 #include <pagefrm.hxx>
36 #include <txtfrm.hxx>
37 #include <node.hxx>
38 #include <sortedobjs.hxx>
39 #include <anchoredobject.hxx>
40 
41 #include <svx/svdobj.hxx>
42 
43 using namespace sw::access;
44 
45 SwAccessibleChildMap::SwAccessibleChildMap( const SwRect& rVisArea,
46                                             const SwFrm& rFrm,
47                                             SwAccessibleMap& rAccMap )
48     : nHellId( rAccMap.GetShell()->GetDoc()->GetHellId() )
49     , nControlsId( rAccMap.GetShell()->GetDoc()->GetControlsId() )
50 {
51     const bool bVisibleChildrenOnly = SwAccessibleChild( &rFrm ).IsVisibleChildrenOnly();
52 
53     sal_uInt32 nPos = 0;
54     SwAccessibleChild aLower( rFrm.GetLower() );
55     while( aLower.GetSwFrm() )
56     {
57         if ( !bVisibleChildrenOnly ||
58              aLower.AlwaysIncludeAsChild() ||
59              aLower.GetBox( rAccMap ).IsOver( rVisArea ) )
60         {
61             insert( nPos++, SwAccessibleChildMapKey::TEXT, aLower );
62         }
63 
64         aLower = aLower.GetSwFrm()->GetNext();
65     }
66 
67     if ( rFrm.IsPageFrm() )
68     {
69         ASSERT( bVisibleChildrenOnly, "page frame within tab frame???" );
70         const SwPageFrm *pPgFrm =
71             static_cast< const SwPageFrm * >( &rFrm );
72         const SwSortedObjs *pObjs = pPgFrm->GetSortedObjs();
73         if ( pObjs )
74         {
75             for( sal_uInt16 i=0; i<pObjs->Count(); i++ )
76             {
77                 aLower = (*pObjs)[i]->GetDrawObj();
78                 if ( aLower.GetBox( rAccMap ).IsOver( rVisArea ) )
79                 {
80                     insert( aLower.GetDrawObject(), aLower );
81                 }
82             }
83         }
84     }
85     else if( rFrm.IsTxtFrm() )
86     {
87         const SwSortedObjs *pObjs = rFrm.GetDrawObjs();
88         if ( pObjs )
89         {
90             for( sal_uInt16 i=0; i<pObjs->Count(); i++ )
91             {
92                 aLower = (*pObjs)[i]->GetDrawObj();
93                 if ( aLower.IsBoundAsChar() &&
94                      ( !bVisibleChildrenOnly ||
95                        aLower.AlwaysIncludeAsChild() ||
96                        aLower.GetBox( rAccMap ).IsOver( rVisArea ) ) )
97                 {
98                     insert( aLower.GetDrawObject(), aLower );
99                 }
100             }
101         }
102 
103         {
104             ::vos::ORef < SwAccessibleContext > xAccImpl =
105                                 rAccMap.GetContextImpl( &rFrm, sal_False );
106             if( xAccImpl.isValid() )
107             {
108                 SwAccessibleContext* pAccImpl = xAccImpl.getBodyPtr();
109                 if ( pAccImpl &&
110                      pAccImpl->HasAdditionalAccessibleChildren() )
111                 {
112                     std::vector< Window* >* pAdditionalChildren =
113                                                 new std::vector< Window* >();
114                     pAccImpl->GetAdditionalAccessibleChildren( pAdditionalChildren );
115 
116                     sal_Int32 nCounter( 0 );
117                     for ( std::vector< Window* >::iterator aIter = pAdditionalChildren->begin();
118                           aIter != pAdditionalChildren->end();
119                           ++aIter )
120                     {
121                         aLower = (*aIter);
122                         insert( ++nCounter, SwAccessibleChildMapKey::XWINDOW, aLower );
123                     }
124 
125                     delete pAdditionalChildren;
126                 }
127             }
128         }
129     }
130 }
131 
132 ::std::pair< SwAccessibleChildMap::iterator, bool > SwAccessibleChildMap::insert(
133                                                 const sal_uInt32 nPos,
134                                                 const SwAccessibleChildMapKey::LayerId eLayerId,
135                                                 const SwAccessibleChild& rLower )
136 {
137     SwAccessibleChildMapKey aKey( eLayerId, nPos );
138 	value_type aEntry( aKey, rLower );
139     return _SwAccessibleChildMap::insert( aEntry );
140 }
141 
142 ::std::pair< SwAccessibleChildMap::iterator, bool > SwAccessibleChildMap::insert(
143                                                 const SdrObject *pObj,
144                                                 const SwAccessibleChild& rLower )
145 {
146     const SdrLayerID nLayer = pObj->GetLayer();
147     SwAccessibleChildMapKey::LayerId eLayerId =
148                     (nHellId == nLayer)
149                     ? SwAccessibleChildMapKey::HELL
150                     : ( (nControlsId == nLayer)
151                         ? SwAccessibleChildMapKey::CONTROLS
152                         : SwAccessibleChildMapKey::HEAVEN );
153     SwAccessibleChildMapKey aKey( eLayerId, pObj->GetOrdNum() );
154 	value_type aEntry( aKey, rLower );
155     return _SwAccessibleChildMap::insert( aEntry );
156 }
157 
158 /* static */ sal_Bool SwAccessibleChildMap::IsSortingRequired( const SwFrm& rFrm )
159 {
160     return ( rFrm.IsPageFrm() &&
161              static_cast< const SwPageFrm& >( rFrm ).GetSortedObjs() ) ||
162            ( rFrm.IsTxtFrm() &&
163              rFrm.GetDrawObjs() );
164 }
165 
166 /* MT: The two insert methods had been introduced in the IA2 CWS (OOO310m11), but meanwhile we also have some in DEV300m80 (above)
167        Not sure if they have something which needs to be update in above methods.
168        Also, since there is no SwFrmOrObjMap CTOR anymore, the updated code in DEV300 might need some of the changes flagged with
169 ::std::pair< SwFrmOrObjMap::iterator, bool > SwFrmOrObjMap::insert(
170 		sal_uInt32 nOrd,  Point nPos, const SwFrmOrObj& rLower )
171 {
172 	SwFrmOrObjMapKey aKey( SwFrmOrObjMapKey::TEXT, nOrd, nPos );
173 	value_type aEntry( aKey, rLower );
174 	return _SwFrmOrObjMap::insert( aEntry );
175 }
176 
177 ::std::pair< SwFrmOrObjMap::iterator, bool > SwFrmOrObjMap::insert(
178 		const SdrObject *pObj, const SwFrmOrObj& rLower, const SwDoc *pDoc , Point nPos)
179 {
180 	if( !bLayerIdsValid )
181 	{
182 		nHellId = pDoc->GetHellId();
183 		nControlsId = pDoc->GetControlsId();
184 		bLayerIdsValid = sal_True;
185 	}
186 
187 	SdrLayerID nLayer = pObj->GetLayer();
188 	SwFrmOrObjMapKey::LayerId eLayerId = (nHellId == nLayer)
189 					? SwFrmOrObjMapKey::HELL
190 					: ((nControlsId == nLayer) ? SwFrmOrObjMapKey::CONTROLS
191 											   : SwFrmOrObjMapKey::HEAVEN);
192 	SwFrmOrObjMapKey aKey( eLayerId, pObj->GetOrdNum(), nPos );
193 	value_type aEntry( aKey, rLower );
194 	return _SwFrmOrObjMap::insert( aEntry );
195 }
196 
197 SwFrmOrObjMap::SwFrmOrObjMap(
198 		const SwRect& rVisArea, const SwFrm *pFrm ) :
199 	bLayerIdsValid( sal_False )
200 {
201 	SwFrmOrObj aFrm( pFrm );
202 	sal_Bool bVisibleOnly = aFrm.IsVisibleChildrenOnly();
203 
204 	sal_uInt32 nPos = 0;
205 	SwFrmOrObj aLower( pFrm->GetLower() );
206 	while( aLower.GetSwFrm() )
207 	{
208 		if( !bVisibleOnly || aLower.GetBox().IsOver( rVisArea ) )
209 			insert( nPos++, aLower.GetBounds().Pos(), aLower );
210 		aLower = aLower.GetSwFrm()->GetNext();
211 	}
212 
213 	if( pFrm->IsPageFrm() )
214 	{
215 		ASSERT( bVisibleOnly, "page frame within tab frame???" );
216 		const SwPageFrm *pPgFrm =
217 			static_cast< const SwPageFrm * >( pFrm );
218         const SwSortedObjs *pObjs = pPgFrm->GetSortedObjs();
219 		if( pObjs )
220 		{
221 			const SwDoc *pDoc = pPgFrm->GetFmt()->GetDoc();
222 			for( sal_uInt16 i=0; i<pObjs->Count(); i++ )
223 			{
224                 aLower = (*pObjs)[i]->GetDrawObj();
225 				if( aLower.GetBox().IsOver( rVisArea ) )
226 					insert( aLower.GetSdrObject(), aLower, pDoc , aLower.GetBounds().Pos() );
227 			}
228 		}
229 	}
230 	else if( pFrm->IsTxtFrm() )
231 	{
232 		const SwDoc *pDoc = static_cast< const SwTxtFrm * >( pFrm )->GetNode()
233 																   ->GetDoc();
234         const SwSortedObjs *pObjs = pFrm->GetDrawObjs();
235 		if( pObjs )
236 		{
237 			for( sal_uInt16 i=0; i<pObjs->Count(); i++ )
238 			{
239                 aLower = (*pObjs)[i]->GetDrawObj();
240 				if( aLower.IsBoundAsChar() &&
241 					(!bVisibleOnly || aLower.GetBox().IsOver( rVisArea )) )
242 					insert( aLower.GetSdrObject(), aLower, pDoc , Point(aLower.GetAnchorPosition(),0) );
243 			}
244 		}
245 	}
246 }
247 
248 */
249 
250