xref: /trunk/main/sw/source/core/access/accfrmobjmap.cxx (revision ffad8df045fe8db79e3e50f731c1fa6ab6501c83)
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 //IAccessibility2 Implementation 2009-----
169 
170 //IAccessibility2 Implementation 2009-----
171 ::std::pair< SwFrmOrObjMap::iterator, bool > SwFrmOrObjMap::insert(
172         sal_uInt32 nOrd,  Point nPos, const SwFrmOrObj& rLower )
173 {
174     SwFrmOrObjMapKey aKey( SwFrmOrObjMapKey::TEXT, nOrd, nPos );
175     value_type aEntry( aKey, rLower );
176     return _SwFrmOrObjMap::insert( aEntry );
177 }
178 
179 ::std::pair< SwFrmOrObjMap::iterator, bool > SwFrmOrObjMap::insert(
180         const SdrObject *pObj, const SwFrmOrObj& rLower, const SwDoc *pDoc , Point nPos)
181 {
182     if( !bLayerIdsValid )
183     {
184         nHellId = pDoc->GetHellId();
185         nControlsId = pDoc->GetControlsId();
186         bLayerIdsValid = sal_True;
187     }
188 
189     SdrLayerID nLayer = pObj->GetLayer();
190     SwFrmOrObjMapKey::LayerId eLayerId = (nHellId == nLayer)
191                     ? SwFrmOrObjMapKey::HELL
192                     : ((nControlsId == nLayer) ? SwFrmOrObjMapKey::CONTROLS
193                                                : SwFrmOrObjMapKey::HEAVEN);
194     SwFrmOrObjMapKey aKey( eLayerId, pObj->GetOrdNum(), nPos );
195     value_type aEntry( aKey, rLower );
196     return _SwFrmOrObjMap::insert( aEntry );
197 }
198 //-----IAccessibility2 Implementation 2009
199 
200 SwFrmOrObjMap::SwFrmOrObjMap(
201         const SwRect& rVisArea, const SwFrm *pFrm ) :
202     bLayerIdsValid( sal_False )
203 {
204     SwFrmOrObj aFrm( pFrm );
205     sal_Bool bVisibleOnly = aFrm.IsVisibleChildrenOnly();
206 
207     sal_uInt32 nPos = 0;
208     SwFrmOrObj aLower( pFrm->GetLower() );
209     while( aLower.GetSwFrm() )
210     {
211         //IAccessibility2 Implementation 2009-----
212         if( !bVisibleOnly || aLower.GetBox().IsOver( rVisArea ) )
213             insert( nPos++, aLower.GetBounds().Pos(), aLower );
214         //-----IAccessibility2 Implementation 2009
215         aLower = aLower.GetSwFrm()->GetNext();
216     }
217 
218     if( pFrm->IsPageFrm() )
219     {
220         ASSERT( bVisibleOnly, "page frame within tab frame???" );
221         const SwPageFrm *pPgFrm =
222             static_cast< const SwPageFrm * >( pFrm );
223         const SwSortedObjs *pObjs = pPgFrm->GetSortedObjs();
224         if( pObjs )
225         {
226             const SwDoc *pDoc = pPgFrm->GetFmt()->GetDoc();
227             for( sal_uInt16 i=0; i<pObjs->Count(); i++ )
228             {
229                 aLower = (*pObjs)[i]->GetDrawObj();
230                 //IAccessibility2 Implementation 2009-----
231                 if( aLower.GetBox().IsOver( rVisArea ) )
232                     insert( aLower.GetSdrObject(), aLower, pDoc , aLower.GetBounds().Pos() );
233                 //-----IAccessibility2 Implementation 2009
234             }
235         }
236     }
237     else if( pFrm->IsTxtFrm() )
238     {
239         const SwDoc *pDoc = static_cast< const SwTxtFrm * >( pFrm )->GetNode()
240                                                                    ->GetDoc();
241         const SwSortedObjs *pObjs = pFrm->GetDrawObjs();
242         if( pObjs )
243         {
244             for( sal_uInt16 i=0; i<pObjs->Count(); i++ )
245             {
246                 aLower = (*pObjs)[i]->GetDrawObj();
247                 //IAccessibility2 Implementation 2009-----
248                 if( aLower.IsBoundAsChar() &&
249                     (!bVisibleOnly || aLower.GetBox().IsOver( rVisArea )) )
250                     insert( aLower.GetSdrObject(), aLower, pDoc , Point(aLower.GetAnchorPosition(),0) );
251                 //-----IAccessibility2 Implementation 2009
252             }
253         }
254     }
255 }
256 
257 */
258 
259