1  /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 
31 #include <accfrmobjmap.hxx>
32 #include <accframe.hxx>
33 #include <accmap.hxx>
34 #include <acccontext.hxx>
35 
36 #include <viewsh.hxx>
37 #include <doc.hxx>
38 #include <frmfmt.hxx>
39 #include <pagefrm.hxx>
40 #include <txtfrm.hxx>
41 #include <node.hxx>
42 #include <sortedobjs.hxx>
43 #include <anchoredobject.hxx>
44 
45 #include <svx/svdobj.hxx>
46 
47 using namespace sw::access;
48 
49 SwAccessibleChildMap::SwAccessibleChildMap( const SwRect& rVisArea,
50                                             const SwFrm& rFrm,
51                                             SwAccessibleMap& rAccMap )
52     : nHellId( rAccMap.GetShell()->GetDoc()->GetHellId() )
53     , nControlsId( rAccMap.GetShell()->GetDoc()->GetControlsId() )
54 {
55     const bool bVisibleChildrenOnly = SwAccessibleChild( &rFrm ).IsVisibleChildrenOnly();
56 
57     sal_uInt32 nPos = 0;
58     SwAccessibleChild aLower( rFrm.GetLower() );
59     while( aLower.GetSwFrm() )
60     {
61         if ( !bVisibleChildrenOnly ||
62              aLower.AlwaysIncludeAsChild() ||
63              aLower.GetBox( rAccMap ).IsOver( rVisArea ) )
64         {
65             insert( nPos++, SwAccessibleChildMapKey::TEXT, aLower );
66         }
67 
68         aLower = aLower.GetSwFrm()->GetNext();
69     }
70 
71     if ( rFrm.IsPageFrm() )
72     {
73         ASSERT( bVisibleChildrenOnly, "page frame within tab frame???" );
74         const SwPageFrm *pPgFrm =
75             static_cast< const SwPageFrm * >( &rFrm );
76         const SwSortedObjs *pObjs = pPgFrm->GetSortedObjs();
77         if ( pObjs )
78         {
79             for( sal_uInt16 i=0; i<pObjs->Count(); i++ )
80             {
81                 aLower = (*pObjs)[i]->GetDrawObj();
82                 if ( aLower.GetBox( rAccMap ).IsOver( rVisArea ) )
83                 {
84                     insert( aLower.GetDrawObject(), aLower );
85                 }
86             }
87         }
88     }
89     else if( rFrm.IsTxtFrm() )
90     {
91         const SwSortedObjs *pObjs = rFrm.GetDrawObjs();
92         if ( pObjs )
93         {
94             for( sal_uInt16 i=0; i<pObjs->Count(); i++ )
95             {
96                 aLower = (*pObjs)[i]->GetDrawObj();
97                 if ( aLower.IsBoundAsChar() &&
98                      ( !bVisibleChildrenOnly ||
99                        aLower.AlwaysIncludeAsChild() ||
100                        aLower.GetBox( rAccMap ).IsOver( rVisArea ) ) )
101                 {
102                     insert( aLower.GetDrawObject(), aLower );
103                 }
104             }
105         }
106 
107         {
108             ::vos::ORef < SwAccessibleContext > xAccImpl =
109                                 rAccMap.GetContextImpl( &rFrm, sal_False );
110             if( xAccImpl.isValid() )
111             {
112                 SwAccessibleContext* pAccImpl = xAccImpl.getBodyPtr();
113                 if ( pAccImpl &&
114                      pAccImpl->HasAdditionalAccessibleChildren() )
115                 {
116                     std::vector< Window* >* pAdditionalChildren =
117                                                 new std::vector< Window* >();
118                     pAccImpl->GetAdditionalAccessibleChildren( pAdditionalChildren );
119 
120                     sal_Int32 nCounter( 0 );
121                     for ( std::vector< Window* >::iterator aIter = pAdditionalChildren->begin();
122                           aIter != pAdditionalChildren->end();
123                           ++aIter )
124                     {
125                         aLower = (*aIter);
126                         insert( ++nCounter, SwAccessibleChildMapKey::XWINDOW, aLower );
127                     }
128 
129                     delete pAdditionalChildren;
130                 }
131             }
132         }
133     }
134 }
135 
136 ::std::pair< SwAccessibleChildMap::iterator, bool > SwAccessibleChildMap::insert(
137                                                 const sal_uInt32 nPos,
138                                                 const SwAccessibleChildMapKey::LayerId eLayerId,
139                                                 const SwAccessibleChild& rLower )
140 {
141     SwAccessibleChildMapKey aKey( eLayerId, nPos );
142 	value_type aEntry( aKey, rLower );
143     return _SwAccessibleChildMap::insert( aEntry );
144 }
145 
146 ::std::pair< SwAccessibleChildMap::iterator, bool > SwAccessibleChildMap::insert(
147                                                 const SdrObject *pObj,
148                                                 const SwAccessibleChild& rLower )
149 {
150     const SdrLayerID nLayer = pObj->GetLayer();
151     SwAccessibleChildMapKey::LayerId eLayerId =
152                     (nHellId == nLayer)
153                     ? SwAccessibleChildMapKey::HELL
154                     : ( (nControlsId == nLayer)
155                         ? SwAccessibleChildMapKey::CONTROLS
156                         : SwAccessibleChildMapKey::HEAVEN );
157     SwAccessibleChildMapKey aKey( eLayerId, pObj->GetOrdNum() );
158 	value_type aEntry( aKey, rLower );
159     return _SwAccessibleChildMap::insert( aEntry );
160 }
161 
162 /* static */ sal_Bool SwAccessibleChildMap::IsSortingRequired( const SwFrm& rFrm )
163 {
164     return ( rFrm.IsPageFrm() &&
165              static_cast< const SwPageFrm& >( rFrm ).GetSortedObjs() ) ||
166            ( rFrm.IsTxtFrm() &&
167              rFrm.GetDrawObjs() );
168 }
169