Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <hintids.hxx>
21 : #include <editeng/brushitem.hxx>
22 : #include <flyfrm.hxx>
23 : #include <rootfrm.hxx>
24 : #include <txtfrm.hxx>
25 : #include <sectfrm.hxx>
26 : #include <section.hxx>
27 : #include <viewsh.hxx>
28 : #include <viewopt.hxx>
29 : #include <doc.hxx>
30 : #include <frmatr.hxx>
31 : #include <pagefrm.hxx>
32 : #include <pagedesc.hxx>
33 : #include <fmtanchr.hxx>
34 : #include <fldbas.hxx>
35 : #include <dcontact.hxx>
36 : #include <accmap.hxx>
37 : #include <accfrmobjslist.hxx>
38 : #include <accfrmobjmap.hxx>
39 : #include <accframe.hxx>
40 :
41 : using namespace sw::access;
42 :
43 : // Regarding visibility (or in terms of accessibility: regarding the showing
44 : // state): A frame is visible and therefore contained in the tree if its frame
45 : // size overlaps with the visible area. The bounding box however is the
46 : // frame's paint area.
47 0 : sal_Int32 SwAccessibleFrame::GetChildCount( SwAccessibleMap& rAccMap,
48 : const SwRect& rVisArea,
49 : const SwFrm *pFrm,
50 : sal_Bool bInPagePreview )
51 : {
52 0 : sal_Int32 nCount = 0;
53 :
54 0 : const SwAccessibleChildSList aVisList( rVisArea, *pFrm, rAccMap );
55 :
56 0 : SwAccessibleChildSList::const_iterator aIter( aVisList.begin() );
57 0 : while( aIter != aVisList.end() )
58 : {
59 0 : const SwAccessibleChild& rLower = *aIter;
60 0 : if( rLower.IsAccessible( bInPagePreview ) )
61 : {
62 0 : nCount++;
63 : }
64 0 : else if( rLower.GetSwFrm() )
65 : {
66 : // There are no unaccessible SdrObjects that count
67 : nCount += GetChildCount( rAccMap,
68 : rVisArea, rLower.GetSwFrm(),
69 0 : bInPagePreview );
70 : }
71 0 : ++aIter;
72 : }
73 :
74 0 : return nCount;
75 : }
76 :
77 0 : SwAccessibleChild SwAccessibleFrame::GetChild(
78 : SwAccessibleMap& rAccMap,
79 : const SwRect& rVisArea,
80 : const SwFrm& rFrm,
81 : sal_Int32& rPos,
82 : sal_Bool bInPagePreview )
83 : {
84 0 : SwAccessibleChild aRet;
85 :
86 0 : if( rPos >= 0 )
87 : {
88 0 : if( SwAccessibleChildMap::IsSortingRequired( rFrm ) )
89 : {
90 : // We need a sorted list here
91 0 : const SwAccessibleChildMap aVisMap( rVisArea, rFrm, rAccMap );
92 0 : SwAccessibleChildMap::const_iterator aIter( aVisMap.begin() );
93 0 : while( aIter != aVisMap.end() && !aRet.IsValid() )
94 : {
95 0 : const SwAccessibleChild& rLower = (*aIter).second;
96 0 : if( rLower.IsAccessible( bInPagePreview ) )
97 : {
98 0 : if( 0 == rPos )
99 0 : aRet = rLower;
100 : else
101 0 : rPos--;
102 : }
103 0 : else if( rLower.GetSwFrm() )
104 : {
105 : // There are no unaccessible SdrObjects that count
106 0 : aRet = GetChild( rAccMap,
107 0 : rVisArea, *(rLower.GetSwFrm()), rPos,
108 0 : bInPagePreview );
109 : }
110 0 : ++aIter;
111 0 : }
112 : }
113 : else
114 : {
115 : // The unsorted list is sorted enough, because it returns lower
116 : // frames in the correct order.
117 0 : const SwAccessibleChildSList aVisList( rVisArea, rFrm, rAccMap );
118 0 : SwAccessibleChildSList::const_iterator aIter( aVisList.begin() );
119 0 : while( aIter != aVisList.end() && !aRet.IsValid() )
120 : {
121 0 : const SwAccessibleChild& rLower = *aIter;
122 0 : if( rLower.IsAccessible( bInPagePreview ) )
123 : {
124 0 : if( 0 == rPos )
125 0 : aRet = rLower;
126 : else
127 0 : rPos--;
128 : }
129 0 : else if( rLower.GetSwFrm() )
130 : {
131 : // There are no unaccessible SdrObjects that count
132 0 : aRet = GetChild( rAccMap,
133 0 : rVisArea, *(rLower.GetSwFrm()), rPos,
134 0 : bInPagePreview );
135 : }
136 0 : ++aIter;
137 : }
138 : }
139 : }
140 :
141 0 : return aRet;
142 : }
143 :
144 0 : sal_Bool SwAccessibleFrame::GetChildIndex(
145 : SwAccessibleMap& rAccMap,
146 : const SwRect& rVisArea,
147 : const SwFrm& rFrm,
148 : const SwAccessibleChild& rChild,
149 : sal_Int32& rPos,
150 : sal_Bool bInPagePreview )
151 : {
152 0 : sal_Bool bFound = sal_False;
153 :
154 0 : if( SwAccessibleChildMap::IsSortingRequired( rFrm ) )
155 : {
156 : // We need a sorted list here
157 0 : const SwAccessibleChildMap aVisMap( rVisArea, rFrm, rAccMap );
158 0 : SwAccessibleChildMap::const_iterator aIter( aVisMap.begin() );
159 0 : while( aIter != aVisMap.end() && !bFound )
160 : {
161 0 : const SwAccessibleChild& rLower = (*aIter).second;
162 0 : if( rLower.IsAccessible( bInPagePreview ) )
163 : {
164 0 : if( rChild == rLower )
165 0 : bFound = sal_True;
166 : else
167 0 : rPos++;
168 : }
169 0 : else if( rLower.GetSwFrm() )
170 : {
171 : // There are no unaccessible SdrObjects that count
172 : bFound = GetChildIndex( rAccMap,
173 0 : rVisArea, *(rLower.GetSwFrm()), rChild,
174 0 : rPos, bInPagePreview );
175 : }
176 0 : ++aIter;
177 0 : }
178 : }
179 : else
180 : {
181 : // The unsorted list is sorted enough, because it returns lower
182 : // frames in the correct order.
183 :
184 0 : const SwAccessibleChildSList aVisList( rVisArea, rFrm, rAccMap );
185 0 : SwAccessibleChildSList::const_iterator aIter( aVisList.begin() );
186 0 : while( aIter != aVisList.end() && !bFound )
187 : {
188 0 : const SwAccessibleChild& rLower = *aIter;
189 0 : if( rLower.IsAccessible( bInPagePreview ) )
190 : {
191 0 : if( rChild == rLower )
192 0 : bFound = sal_True;
193 : else
194 0 : rPos++;
195 : }
196 0 : else if( rLower.GetSwFrm() )
197 : {
198 : // There are no unaccessible SdrObjects that count
199 : bFound = GetChildIndex( rAccMap,
200 0 : rVisArea, *(rLower.GetSwFrm()), rChild,
201 0 : rPos, bInPagePreview );
202 : }
203 0 : ++aIter;
204 : }
205 : }
206 :
207 0 : return bFound;
208 : }
209 :
210 0 : SwAccessibleChild SwAccessibleFrame::GetChildAtPixel( const SwRect& rVisArea,
211 : const SwFrm& rFrm,
212 : const Point& rPixPos,
213 : sal_Bool bInPagePreview,
214 : SwAccessibleMap& rAccMap )
215 : {
216 0 : SwAccessibleChild aRet;
217 :
218 0 : if( SwAccessibleChildMap::IsSortingRequired( rFrm ) )
219 : {
220 : // We need a sorted list here, and we have to reverse iterate,
221 : // because objects in front should be returned.
222 0 : const SwAccessibleChildMap aVisMap( rVisArea, rFrm, rAccMap );
223 0 : SwAccessibleChildMap::const_reverse_iterator aRIter( aVisMap.rbegin() );
224 0 : while( aRIter != aVisMap.rend() && !aRet.IsValid() )
225 : {
226 0 : const SwAccessibleChild& rLower = (*aRIter).second;
227 : // A frame is returned if it's frame size is inside the visarea
228 : // and the positiion is inside the frame's paint area.
229 0 : if( rLower.IsAccessible( bInPagePreview ) )
230 : {
231 0 : SwRect aLogBounds( rLower.GetBounds( rAccMap ) );
232 0 : if( !aLogBounds.IsEmpty() )
233 : {
234 0 : Rectangle aPixBounds( rAccMap.CoreToPixel( aLogBounds.SVRect() ) );
235 0 : if( aPixBounds.IsInside( rPixPos ) )
236 0 : aRet = rLower;
237 : }
238 : }
239 0 : else if( rLower.GetSwFrm() )
240 : {
241 : // There are no unaccessible SdrObjects that count
242 0 : aRet = GetChildAtPixel( rVisArea, *(rLower.GetSwFrm()), rPixPos,
243 0 : bInPagePreview, rAccMap );
244 : }
245 0 : ++aRIter;
246 0 : }
247 : }
248 : else
249 : {
250 : // The unsorted list is sorted enough, because it returns lower
251 : // frames in the correct order. Morover, we can iterate forward,
252 : // because the lowers don't overlap!
253 0 : const SwAccessibleChildSList aVisList( rVisArea, rFrm, rAccMap );
254 0 : SwAccessibleChildSList::const_iterator aIter( aVisList.begin() );
255 0 : while( aIter != aVisList.end() && !aRet.IsValid() )
256 : {
257 0 : const SwAccessibleChild& rLower = *aIter;
258 : // A frame is returned if it's frame size is inside the visarea
259 : // and the positiion is inside the frame's paint area.
260 0 : if( rLower.IsAccessible( bInPagePreview ) )
261 : {
262 0 : SwRect aLogBounds( rLower.GetBounds( rAccMap ) );
263 0 : if( !aLogBounds.IsEmpty() )
264 : {
265 0 : Rectangle aPixBounds( rAccMap.CoreToPixel( aLogBounds.SVRect() ) );
266 0 : if( aPixBounds.IsInside( rPixPos ) )
267 0 : aRet = rLower;
268 : }
269 : }
270 0 : else if( rLower.GetSwFrm() )
271 : {
272 : // There are no unaccessible SdrObjects that count
273 0 : aRet = GetChildAtPixel( rVisArea, *(rLower.GetSwFrm()), rPixPos,
274 0 : bInPagePreview, rAccMap );
275 : }
276 0 : ++aIter;
277 : }
278 : }
279 :
280 0 : return aRet;
281 : }
282 :
283 0 : void SwAccessibleFrame::GetChildren( SwAccessibleMap& rAccMap,
284 : const SwRect& rVisArea,
285 : const SwFrm& rFrm,
286 : ::std::list< SwAccessibleChild >& rChildren,
287 : sal_Bool bInPagePreview )
288 : {
289 0 : if( SwAccessibleChildMap::IsSortingRequired( rFrm ) )
290 : {
291 : // We need a sorted list here
292 0 : const SwAccessibleChildMap aVisMap( rVisArea, rFrm, rAccMap );
293 0 : SwAccessibleChildMap::const_iterator aIter( aVisMap.begin() );
294 0 : while( aIter != aVisMap.end() )
295 : {
296 0 : const SwAccessibleChild& rLower = (*aIter).second;
297 0 : if( rLower.IsAccessible( bInPagePreview ) )
298 : {
299 0 : rChildren.push_back( rLower );
300 : }
301 0 : else if( rLower.GetSwFrm() )
302 : {
303 : // There are no unaccessible SdrObjects that count
304 0 : GetChildren( rAccMap, rVisArea, *(rLower.GetSwFrm()),
305 0 : rChildren, bInPagePreview );
306 : }
307 0 : ++aIter;
308 0 : }
309 : }
310 : else
311 : {
312 : // The unsorted list is sorted enough, because it returns lower
313 : // frames in the correct order.
314 0 : const SwAccessibleChildSList aVisList( rVisArea, rFrm, rAccMap );
315 0 : SwAccessibleChildSList::const_iterator aIter( aVisList.begin() );
316 0 : while( aIter != aVisList.end() )
317 : {
318 0 : const SwAccessibleChild& rLower = *aIter;
319 0 : if( rLower.IsAccessible( bInPagePreview ) )
320 : {
321 0 : rChildren.push_back( rLower );
322 : }
323 0 : else if( rLower.GetSwFrm() )
324 : {
325 : // There are no unaccessible SdrObjects that count
326 0 : GetChildren( rAccMap, rVisArea, *(rLower.GetSwFrm()),
327 0 : rChildren, bInPagePreview );
328 : }
329 0 : ++aIter;
330 : }
331 : }
332 0 : }
333 :
334 0 : SwRect SwAccessibleFrame::GetBounds( const SwAccessibleMap& rAccMap,
335 : const SwFrm *pFrm )
336 : {
337 0 : if( !pFrm )
338 0 : pFrm = GetFrm();
339 :
340 0 : SwAccessibleChild aFrm( pFrm );
341 0 : SwRect aBounds( aFrm.GetBounds( rAccMap ).Intersection( maVisArea ) );
342 0 : return aBounds;
343 : }
344 :
345 0 : sal_Bool SwAccessibleFrame::IsEditable( SwViewShell *pVSh ) const
346 : {
347 0 : const SwFrm *pFrm = GetFrm();
348 0 : if( !pFrm )
349 0 : return sal_False;
350 :
351 : OSL_ENSURE( pVSh, "no view shell" );
352 0 : if( pVSh && (pVSh->GetViewOptions()->IsReadonly() ||
353 0 : pVSh->IsPreview()) )
354 0 : return sal_False;
355 :
356 0 : if( !pFrm->IsRootFrm() && pFrm->IsProtected() )
357 0 : return sal_False;
358 :
359 0 : return sal_True;
360 : }
361 :
362 0 : sal_Bool SwAccessibleFrame::IsOpaque( SwViewShell *pVSh ) const
363 : {
364 0 : SwAccessibleChild aFrm( GetFrm() );
365 0 : if( !aFrm.GetSwFrm() )
366 0 : return sal_False;
367 :
368 : OSL_ENSURE( pVSh, "no view shell" );
369 0 : if( !pVSh )
370 0 : return sal_False;
371 :
372 0 : const SwViewOption *pVOpt = pVSh->GetViewOptions();
373 0 : do
374 : {
375 0 : const SwFrm *pFrm = aFrm.GetSwFrm();
376 0 : if( pFrm->IsRootFrm() )
377 0 : return sal_True;
378 :
379 0 : if( pFrm->IsPageFrm() && !pVOpt->IsPageBack() )
380 0 : return sal_False;
381 :
382 0 : const SvxBrushItem &rBack = pFrm->GetAttrSet()->GetBackground();
383 0 : if( !rBack.GetColor().GetTransparency() ||
384 0 : rBack.GetGraphicPos() != GPOS_NONE )
385 0 : return sal_True;
386 :
387 : // If a fly frame has a transparent background color, we have to consider the background.
388 : // But a background color "no fill"/"auto fill" should *not* be considered.
389 0 : if( pFrm->IsFlyFrm() &&
390 0 : (rBack.GetColor().GetTransparency() != 0) &&
391 0 : (rBack.GetColor() != COL_TRANSPARENT)
392 : )
393 0 : return sal_True;
394 :
395 0 : if( pFrm->IsSctFrm() )
396 : {
397 0 : const SwSection* pSection = ((SwSectionFrm*)pFrm)->GetSection();
398 0 : if( pSection && ( TOX_HEADER_SECTION == pSection->GetType() ||
399 0 : TOX_CONTENT_SECTION == pSection->GetType() ) &&
400 0 : !pVOpt->IsReadonly() &&
401 0 : SwViewOption::IsIndexShadings() )
402 0 : return sal_True;
403 : }
404 0 : if( pFrm->IsFlyFrm() )
405 0 : aFrm = static_cast<const SwFlyFrm*>(pFrm)->GetAnchorFrm();
406 : else
407 0 : aFrm = pFrm->GetUpper();
408 0 : } while( aFrm.GetSwFrm() && !aFrm.IsAccessible( IsInPagePreview() ) );
409 :
410 0 : return sal_False;
411 : }
412 :
413 0 : SwAccessibleFrame::SwAccessibleFrame( const SwRect& rVisArea,
414 : const SwFrm *pF,
415 : sal_Bool bIsPagePreview ) :
416 : maVisArea( rVisArea ),
417 : mpFrm( pF ),
418 : mbIsInPagePreview( bIsPagePreview ),
419 0 : bIsAccDocUse( sal_False )
420 : {
421 0 : }
422 :
423 0 : SwAccessibleFrame::~SwAccessibleFrame()
424 : {
425 0 : }
426 :
427 0 : const SwFrm* SwAccessibleFrame::GetParent( const SwAccessibleChild& rFrmOrObj,
428 : sal_Bool bInPagePreview )
429 : {
430 0 : return rFrmOrObj.GetParent( bInPagePreview );
431 : }
432 :
433 0 : OUString SwAccessibleFrame::GetFormattedPageNumber() const
434 : {
435 0 : sal_uInt16 nPageNum = GetFrm()->GetVirtPageNum();
436 : sal_uInt32 nFmt = GetFrm()->FindPageFrm()->GetPageDesc()
437 0 : ->GetNumType().GetNumberingType();
438 0 : if( SVX_NUM_NUMBER_NONE == nFmt )
439 0 : nFmt = SVX_NUM_ARABIC;
440 :
441 0 : OUString sRet( FormatNumber( nPageNum, nFmt ) );
442 0 : return sRet;
443 : }
444 :
445 0 : sal_Int32 SwAccessibleFrame::GetChildCount( SwAccessibleMap& rAccMap ) const
446 : {
447 0 : return GetChildCount( rAccMap, maVisArea, mpFrm, IsInPagePreview() );
448 : }
449 :
450 0 : sw::access::SwAccessibleChild SwAccessibleFrame::GetChild(
451 : SwAccessibleMap& rAccMap,
452 : sal_Int32 nPos ) const
453 : {
454 0 : return SwAccessibleFrame::GetChild( rAccMap, maVisArea, *mpFrm, nPos, IsInPagePreview() );
455 : }
456 :
457 0 : sal_Int32 SwAccessibleFrame::GetChildIndex( SwAccessibleMap& rAccMap,
458 : const sw::access::SwAccessibleChild& rChild ) const
459 : {
460 0 : sal_Int32 nPos = 0;
461 0 : return GetChildIndex( rAccMap, maVisArea, *mpFrm, rChild, nPos, IsInPagePreview() )
462 : ? nPos
463 0 : : -1L;
464 : }
465 :
466 0 : sw::access::SwAccessibleChild SwAccessibleFrame::GetChildAtPixel(
467 : const Point& rPos,
468 : SwAccessibleMap& rAccMap ) const
469 : {
470 0 : return GetChildAtPixel( maVisArea, *mpFrm, rPos, IsInPagePreview(), rAccMap );
471 : }
472 :
473 0 : void SwAccessibleFrame::GetChildren( SwAccessibleMap& rAccMap,
474 : ::std::list< sw::access::SwAccessibleChild >& rChildren ) const
475 : {
476 0 : GetChildren( rAccMap, maVisArea, *mpFrm, rChildren, IsInPagePreview() );
477 0 : }
478 :
479 0 : sal_Bool SwAccessibleFrame::IsShowing( const SwAccessibleMap& rAccMap,
480 : const sw::access::SwAccessibleChild& rFrmOrObj ) const
481 : {
482 0 : return IsShowing( rFrmOrObj.GetBox( rAccMap ) );
483 : }
484 :
485 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|