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 <accfrmobjslist.hxx>
28 #include <accmap.hxx>
29 #include <acccontext.hxx>
30 
31 #include <pagefrm.hxx>
32 #include <sortedobjs.hxx>
33 #include <anchoredobject.hxx>
34 
35 using namespace ::sw::access;
36 
SwAccessibleChildSList_const_iterator(const SwAccessibleChildSList & rLst,SwAccessibleMap & rAccMap)37 SwAccessibleChildSList_const_iterator::SwAccessibleChildSList_const_iterator(
38     const SwAccessibleChildSList& rLst,
39     SwAccessibleMap& rAccMap )
40     : rList( rLst ),
41       aCurr( rList.GetFrm().GetLower() ),
42       nNextObj( 0 )
43 {
44 	if( !aCurr.GetSwFrm() )
45 	{
46         const SwFrm& rFrm = rList.GetFrm();
47         if( rFrm.IsPageFrm() )
48 		{
49             const SwPageFrm& rPgFrm = static_cast< const SwPageFrm& >( rFrm );
50             const SwSortedObjs *pObjs = rPgFrm.GetSortedObjs();
51 			if( pObjs && pObjs->Count() )
52             {
53                 aCurr = (*pObjs)[nNextObj++]->GetDrawObj();
54             }
55 		}
56         else if( rFrm.IsTxtFrm() )
57 		{
58             const SwSortedObjs *pObjs = rFrm.GetDrawObjs();
59             if ( pObjs && pObjs->Count() )
60 			{
61                 aCurr = (*pObjs)[nNextObj++]->GetDrawObj();
62 				while( aCurr.IsValid() && !aCurr.IsBoundAsChar() )
63                 {
64 					aCurr = (nNextObj < pObjs->Count())
65                             ? (*pObjs)[nNextObj++]->GetDrawObj()
66                             : static_cast< const SdrObject *>( 0 );
67                 }
68 			}
69             if ( !aCurr.IsValid() )
70             {
71                 ::vos::ORef < SwAccessibleContext > xAccImpl =
72                                     rAccMap.GetContextImpl( &rFrm, sal_False );
73                 if( xAccImpl.isValid() )
74                 {
75                     SwAccessibleContext* pAccImpl = xAccImpl.getBodyPtr();
76                     aCurr = SwAccessibleChild( pAccImpl->GetAdditionalAccessibleChild( 0 ) );
77                     ++nNextObj;
78                 }
79             }
80 		}
81 	}
82 
83     if( rList.IsVisibleChildrenOnly() )
84 	{
85 		// Find the first visible
86 		while( aCurr.IsValid() &&
87                !aCurr.AlwaysIncludeAsChild() &&
88                !aCurr.GetBox( rAccMap ).IsOver( rList.GetVisArea() ) )
89         {
90 			next();
91         }
92 	}
93 }
94 
next()95 SwAccessibleChildSList_const_iterator& SwAccessibleChildSList_const_iterator::next()
96 {
97     bool bNextTaken( true );
98     if( aCurr.GetDrawObject() || aCurr.GetWindow() )
99 	{
100         bNextTaken = false;
101 	}
102 	else if( aCurr.GetSwFrm() )
103 	{
104 		aCurr = aCurr.GetSwFrm()->GetNext();
105 		if( !aCurr.GetSwFrm() )
106         {
107             bNextTaken = false;
108         }
109 	}
110 
111     if( !bNextTaken )
112 	{
113         const SwFrm& rFrm = rList.GetFrm();
114         if( rFrm.IsPageFrm() )
115 		{
116             const SwPageFrm& rPgFrm = static_cast< const SwPageFrm& >( rFrm );
117             const SwSortedObjs *pObjs = rPgFrm.GetSortedObjs();
118             aCurr = ( pObjs && nNextObj < pObjs->Count() )
119                     ? (*pObjs)[nNextObj++]->GetDrawObj()
120                     : static_cast< const SdrObject *>( 0 );
121         }
122         else if( rFrm.IsTxtFrm() )
123         {
124             const SwSortedObjs* pObjs = rFrm.GetDrawObjs();
125             const sal_uInt32 nObjsCount = pObjs ? pObjs->Count() : 0;
126             aCurr = ( pObjs && nNextObj < nObjsCount )
127                     ? (*pObjs)[nNextObj++]->GetDrawObj()
128                     : static_cast< const SdrObject *>( 0 );
129             while( aCurr.IsValid() && !aCurr.IsBoundAsChar() )
130             {
131                 aCurr = ( nNextObj < nObjsCount )
132                         ? (*pObjs)[nNextObj++]->GetDrawObj()
133                         : static_cast< const SdrObject *>( 0 );
134             }
135             if ( !aCurr.IsValid() )
136             {
137                 ::vos::ORef < SwAccessibleContext > xAccImpl =
138                                     rList.GetAccMap().GetContextImpl( &rFrm, sal_False );
139                 if( xAccImpl.isValid() )
140                 {
141                     SwAccessibleContext* pAccImpl = xAccImpl.getBodyPtr();
142                     aCurr = SwAccessibleChild( pAccImpl->GetAdditionalAccessibleChild( nNextObj - nObjsCount ) );
143                     ++nNextObj;
144                 }
145             }
146         }
147 	}
148 
149 	return *this;
150 }
151 
next_visible()152 SwAccessibleChildSList_const_iterator& SwAccessibleChildSList_const_iterator::next_visible()
153 {
154 	next();
155 	while( aCurr.IsValid() &&
156            !aCurr.AlwaysIncludeAsChild() &&
157            !aCurr.GetBox( rList.GetAccMap() ).IsOver( rList.GetVisArea() ) )
158     {
159 		next();
160     }
161 
162 	return *this;
163 }
164 
operator ++()165 SwAccessibleChildSList_const_iterator& SwAccessibleChildSList_const_iterator::operator++()
166 {
167     return rList.IsVisibleChildrenOnly() ? next_visible() : next();
168 }
169 
170