1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <editeng/brushitem.hxx>
22 #include <sectfrm.hxx>
23 #include <section.hxx>
25 #include <viewopt.hxx>
27 #include <pagefrm.hxx>
28 #include <pagedesc.hxx>
31 #include "accfrmobjslist.hxx"
32 #include "accfrmobjmap.hxx"
33 #include "accframe.hxx"
35 using namespace sw::access
;
37 // Regarding visibility (or in terms of accessibility: regarding the showing
38 // state): A frame is visible and therefore contained in the tree if its frame
39 // size overlaps with the visible area. The bounding box however is the
40 // frame's paint area.
41 sal_Int32
SwAccessibleFrame::GetChildCount( SwAccessibleMap
& rAccMap
,
42 const SwRect
& rVisArea
,
43 const SwFrame
*pFrame
,
48 const SwAccessibleChildSList
aVisList( rVisArea
, *pFrame
, rAccMap
);
50 SwAccessibleChildSList::const_iterator
aIter( aVisList
.begin() );
51 while( aIter
!= aVisList
.end() )
53 const SwAccessibleChild
& rLower
= *aIter
;
54 if( rLower
.IsAccessible( bInPagePreview
) )
58 else if( rLower
.GetSwFrame() )
60 // There are no unaccessible SdrObjects that count
61 nCount
+= GetChildCount( rAccMap
,
62 rVisArea
, rLower
.GetSwFrame(),
71 SwAccessibleChild
SwAccessibleFrame::GetChild(
72 SwAccessibleMap
& rAccMap
,
73 const SwRect
& rVisArea
,
74 const SwFrame
& rFrame
,
78 SwAccessibleChild aRet
;
82 if( SwAccessibleChildMap::IsSortingRequired( rFrame
) )
84 // We need a sorted list here
85 const SwAccessibleChildMap
aVisMap( rVisArea
, rFrame
, rAccMap
);
86 SwAccessibleChildMap::const_iterator
aIter( aVisMap
.cbegin() );
87 while( aIter
!= aVisMap
.cend() && !aRet
.IsValid() )
89 const SwAccessibleChild
& rLower
= (*aIter
).second
;
90 if( rLower
.IsAccessible( bInPagePreview
) )
97 else if( rLower
.GetSwFrame() )
99 // There are no unaccessible SdrObjects that count
100 aRet
= GetChild( rAccMap
,
101 rVisArea
, *(rLower
.GetSwFrame()), rPos
,
109 // The unsorted list is sorted enough, because it returns lower
110 // frames in the correct order.
111 const SwAccessibleChildSList
aVisList( rVisArea
, rFrame
, rAccMap
);
112 SwAccessibleChildSList::const_iterator
aIter( aVisList
.begin() );
113 while( aIter
!= aVisList
.end() && !aRet
.IsValid() )
115 const SwAccessibleChild
& rLower
= *aIter
;
116 if( rLower
.IsAccessible( bInPagePreview
) )
123 else if( rLower
.GetSwFrame() )
125 // There are no unaccessible SdrObjects that count
126 aRet
= GetChild( rAccMap
,
127 rVisArea
, *(rLower
.GetSwFrame()), rPos
,
138 bool SwAccessibleFrame::GetChildIndex(
139 SwAccessibleMap
& rAccMap
,
140 const SwRect
& rVisArea
,
141 const SwFrame
& rFrame
,
142 const SwAccessibleChild
& rChild
,
144 bool bInPagePreview
)
148 if( SwAccessibleChildMap::IsSortingRequired( rFrame
) )
150 // We need a sorted list here
151 const SwAccessibleChildMap
aVisMap( rVisArea
, rFrame
, rAccMap
);
152 SwAccessibleChildMap::const_iterator
aIter( aVisMap
.cbegin() );
153 while( aIter
!= aVisMap
.cend() && !bFound
)
155 const SwAccessibleChild
& rLower
= (*aIter
).second
;
156 if( rLower
.IsAccessible( bInPagePreview
) )
158 if( rChild
== rLower
)
163 else if( rLower
.GetSwFrame() )
165 // There are no unaccessible SdrObjects that count
166 bFound
= GetChildIndex( rAccMap
,
167 rVisArea
, *(rLower
.GetSwFrame()), rChild
,
168 rPos
, bInPagePreview
);
175 // The unsorted list is sorted enough, because it returns lower
176 // frames in the correct order.
178 const SwAccessibleChildSList
aVisList( rVisArea
, rFrame
, rAccMap
);
179 SwAccessibleChildSList::const_iterator
aIter( aVisList
.begin() );
180 while( aIter
!= aVisList
.end() && !bFound
)
182 const SwAccessibleChild
& rLower
= *aIter
;
183 if( rLower
.IsAccessible( bInPagePreview
) )
185 if( rChild
== rLower
)
190 else if( rLower
.GetSwFrame() )
192 // There are no unaccessible SdrObjects that count
193 bFound
= GetChildIndex( rAccMap
,
194 rVisArea
, *(rLower
.GetSwFrame()), rChild
,
195 rPos
, bInPagePreview
);
204 SwAccessibleChild
SwAccessibleFrame::GetChildAtPixel( const SwRect
& rVisArea
,
205 const SwFrame
& rFrame
,
206 const Point
& rPixPos
,
208 SwAccessibleMap
& rAccMap
)
210 SwAccessibleChild aRet
;
212 if( SwAccessibleChildMap::IsSortingRequired( rFrame
) )
214 // We need a sorted list here, and we have to reverse iterate,
215 // because objects in front should be returned.
216 const SwAccessibleChildMap
aVisMap( rVisArea
, rFrame
, rAccMap
);
217 SwAccessibleChildMap::const_reverse_iterator
aRIter( aVisMap
.crbegin() );
218 while( aRIter
!= aVisMap
.crend() && !aRet
.IsValid() )
220 const SwAccessibleChild
& rLower
= (*aRIter
).second
;
221 // A frame is returned if it's frame size is inside the visarea
222 // and the position is inside the frame's paint area.
223 if( rLower
.IsAccessible( bInPagePreview
) )
225 SwRect
aLogBounds( rLower
.GetBounds( rAccMap
) );
226 if( !aLogBounds
.IsEmpty() )
228 tools::Rectangle
aPixBounds( rAccMap
.CoreToPixel( aLogBounds
) );
229 if( aPixBounds
.Contains( rPixPos
) )
233 else if( rLower
.GetSwFrame() )
235 // There are no unaccessible SdrObjects that count
236 aRet
= GetChildAtPixel( rVisArea
, *(rLower
.GetSwFrame()), rPixPos
,
237 bInPagePreview
, rAccMap
);
244 // The unsorted list is sorted enough, because it returns lower
245 // frames in the correct order. Moreover, we can iterate forward,
246 // because the lowers don't overlap!
247 const SwAccessibleChildSList
aVisList( rVisArea
, rFrame
, rAccMap
);
248 SwAccessibleChildSList::const_iterator
aIter( aVisList
.begin() );
249 while( aIter
!= aVisList
.end() && !aRet
.IsValid() )
251 const SwAccessibleChild
& rLower
= *aIter
;
252 // A frame is returned if it's frame size is inside the visarea
253 // and the position is inside the frame's paint area.
254 if( rLower
.IsAccessible( bInPagePreview
) )
256 SwRect
aLogBounds( rLower
.GetBounds( rAccMap
) );
257 if( !aLogBounds
.IsEmpty() )
259 tools::Rectangle
aPixBounds( rAccMap
.CoreToPixel( aLogBounds
) );
260 if( aPixBounds
.Contains( rPixPos
) )
264 else if( rLower
.GetSwFrame() )
266 // There are no unaccessible SdrObjects that count
267 aRet
= GetChildAtPixel( rVisArea
, *(rLower
.GetSwFrame()), rPixPos
,
268 bInPagePreview
, rAccMap
);
277 void SwAccessibleFrame::GetChildren( SwAccessibleMap
& rAccMap
,
278 const SwRect
& rVisArea
,
279 const SwFrame
& rFrame
,
280 std::list
< SwAccessibleChild
>& rChildren
,
281 bool bInPagePreview
)
283 if( SwAccessibleChildMap::IsSortingRequired( rFrame
) )
285 // We need a sorted list here
286 const SwAccessibleChildMap
aVisMap( rVisArea
, rFrame
, rAccMap
);
287 SwAccessibleChildMap::const_iterator
aIter( aVisMap
.cbegin() );
288 while( aIter
!= aVisMap
.cend() )
290 const SwAccessibleChild
& rLower
= (*aIter
).second
;
291 if( rLower
.IsAccessible( bInPagePreview
) )
293 rChildren
.push_back( rLower
);
295 else if( rLower
.GetSwFrame() )
297 // There are no unaccessible SdrObjects that count
298 GetChildren( rAccMap
, rVisArea
, *(rLower
.GetSwFrame()),
299 rChildren
, bInPagePreview
);
306 // The unsorted list is sorted enough, because it returns lower
307 // frames in the correct order.
308 const SwAccessibleChildSList
aVisList( rVisArea
, rFrame
, rAccMap
);
309 SwAccessibleChildSList::const_iterator
aIter( aVisList
.begin() );
310 while( aIter
!= aVisList
.end() )
312 const SwAccessibleChild
& rLower
= *aIter
;
313 if( rLower
.IsAccessible( bInPagePreview
) )
315 rChildren
.push_back( rLower
);
317 else if( rLower
.GetSwFrame() )
319 // There are no unaccessible SdrObjects that count
320 GetChildren( rAccMap
, rVisArea
, *(rLower
.GetSwFrame()),
321 rChildren
, bInPagePreview
);
328 SwRect
SwAccessibleFrame::GetBounds( const SwAccessibleMap
& rAccMap
,
329 const SwFrame
*pFrame
)
334 SwAccessibleChild
aFrame( pFrame
);
335 SwRect
aBounds( aFrame
.GetBounds( rAccMap
).Intersection( maVisArea
) );
339 bool SwAccessibleFrame::IsEditable( SwViewShell
const *pVSh
) const
341 const SwFrame
*pFrame
= GetFrame();
345 OSL_ENSURE( pVSh
, "no view shell" );
346 if( pVSh
&& (pVSh
->GetViewOptions()->IsReadonly() ||
350 if( !pFrame
->IsRootFrame() && pFrame
->IsProtected() )
356 bool SwAccessibleFrame::IsOpaque( SwViewShell
const *pVSh
) const
358 SwAccessibleChild
aFrame( GetFrame() );
359 if( !aFrame
.GetSwFrame() )
362 OSL_ENSURE( pVSh
, "no view shell" );
366 const SwViewOption
*pVOpt
= pVSh
->GetViewOptions();
369 const SwFrame
*pFrame
= aFrame
.GetSwFrame();
370 if( pFrame
->IsRootFrame() )
373 if( pFrame
->IsPageFrame() && !pVOpt
->IsPageBack() )
376 const SvxBrushItem
&rBack
= pFrame
->GetAttrSet()->GetBackground();
377 if( !rBack
.GetColor().IsTransparent() ||
378 rBack
.GetGraphicPos() != GPOS_NONE
)
381 // If a fly frame has a transparent background color, we have to consider the background.
382 // But a background color "no fill"/"auto fill" should *not* be considered.
383 if( pFrame
->IsFlyFrame() &&
384 rBack
.GetColor().IsTransparent() &&
385 rBack
.GetColor() != COL_TRANSPARENT
389 if( pFrame
->IsSctFrame() )
391 const SwSection
* pSection
= static_cast<const SwSectionFrame
*>(pFrame
)->GetSection();
392 if( pSection
&& ( SectionType::ToxHeader
== pSection
->GetType() ||
393 SectionType::ToxContent
== pSection
->GetType() ) &&
394 !pVOpt
->IsReadonly() &&
395 pVOpt
->IsIndexShadings() )
398 if( pFrame
->IsFlyFrame() )
399 aFrame
= static_cast<const SwFlyFrame
*>(pFrame
)->GetAnchorFrame();
401 aFrame
= pFrame
->GetUpper();
402 } while( aFrame
.GetSwFrame() && !aFrame
.IsAccessible( IsInPagePreview() ) );
407 SwAccessibleFrame::SwAccessibleFrame( const SwRect
& rVisArea
,
409 bool bIsPagePreview
) :
410 maVisArea( rVisArea
),
412 mbIsInPagePreview( bIsPagePreview
)
417 SwAccessibleFrame::~SwAccessibleFrame()
421 const SwFrame
* SwAccessibleFrame::GetParent( const SwAccessibleChild
& rFrameOrObj
,
422 bool bInPagePreview
)
424 return rFrameOrObj
.GetParent( bInPagePreview
);
427 OUString
SwAccessibleFrame::GetFormattedPageNumber() const
429 sal_uInt16 nPageNum
= GetFrame()->GetVirtPageNum();
430 SvxNumType nFormat
= GetFrame()->FindPageFrame()->GetPageDesc()
431 ->GetNumType().GetNumberingType();
432 if( SVX_NUM_NUMBER_NONE
== nFormat
)
433 nFormat
= SVX_NUM_ARABIC
;
435 OUString
sRet( FormatNumber( nPageNum
, nFormat
) );
439 sal_Int32
SwAccessibleFrame::GetChildCount( SwAccessibleMap
& rAccMap
) const
441 return GetChildCount( rAccMap
, maVisArea
, mpFrame
, IsInPagePreview() );
444 sw::access::SwAccessibleChild
SwAccessibleFrame::GetChild(
445 SwAccessibleMap
& rAccMap
,
446 sal_Int32 nPos
) const
448 return SwAccessibleFrame::GetChild( rAccMap
, maVisArea
, *mpFrame
, nPos
, IsInPagePreview() );
451 sal_Int32
SwAccessibleFrame::GetChildIndex( SwAccessibleMap
& rAccMap
,
452 const sw::access::SwAccessibleChild
& rChild
) const
455 return GetChildIndex( rAccMap
, maVisArea
, *mpFrame
, rChild
, nPos
, IsInPagePreview() )
460 sw::access::SwAccessibleChild
SwAccessibleFrame::GetChildAtPixel(
462 SwAccessibleMap
& rAccMap
) const
464 return GetChildAtPixel( maVisArea
, *mpFrame
, rPos
, IsInPagePreview(), rAccMap
);
467 void SwAccessibleFrame::GetChildren( SwAccessibleMap
& rAccMap
,
468 std::list
< sw::access::SwAccessibleChild
>& rChildren
) const
470 GetChildren( rAccMap
, maVisArea
, *mpFrame
, rChildren
, IsInPagePreview() );
473 bool SwAccessibleFrame::IsShowing( const SwAccessibleMap
& rAccMap
,
474 const sw::access::SwAccessibleChild
& rFrameOrObj
) const
476 return IsShowing( rFrameOrObj
.GetBox( rAccMap
) );
479 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */