android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / source / core / access / accframe.cxx
blob637c379825c55b8fbf9d2d0f2a29b3306ef6568a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
21 #include <flyfrm.hxx>
22 #include <sectfrm.hxx>
23 #include <section.hxx>
24 #include <viewsh.hxx>
25 #include <viewopt.hxx>
26 #include <frmatr.hxx>
27 #include <pagefrm.hxx>
28 #include <pagedesc.hxx>
29 #include <fldbas.hxx>
30 #include <accmap.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,
44 bool bInPagePreview )
46 sal_Int32 nCount = 0;
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 ) )
56 nCount++;
58 else if( rLower.GetSwFrame() )
60 // There are no unaccessible SdrObjects that count
61 nCount += GetChildCount( rAccMap,
62 rVisArea, rLower.GetSwFrame(),
63 bInPagePreview );
65 ++aIter;
68 return nCount;
71 SwAccessibleChild SwAccessibleFrame::GetChild(
72 SwAccessibleMap& rAccMap,
73 const SwRect& rVisArea,
74 const SwFrame& rFrame,
75 sal_Int32& rPos,
76 bool bInPagePreview )
78 SwAccessibleChild aRet;
80 if( rPos >= 0 )
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 ) )
92 if( 0 == rPos )
93 aRet = rLower;
94 else
95 rPos--;
97 else if( rLower.GetSwFrame() )
99 // There are no unaccessible SdrObjects that count
100 aRet = GetChild( rAccMap,
101 rVisArea, *(rLower.GetSwFrame()), rPos,
102 bInPagePreview );
104 ++aIter;
107 else
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 ) )
118 if( 0 == rPos )
119 aRet = rLower;
120 else
121 rPos--;
123 else if( rLower.GetSwFrame() )
125 // There are no unaccessible SdrObjects that count
126 aRet = GetChild( rAccMap,
127 rVisArea, *(rLower.GetSwFrame()), rPos,
128 bInPagePreview );
130 ++aIter;
135 return aRet;
138 bool SwAccessibleFrame::GetChildIndex(
139 SwAccessibleMap& rAccMap,
140 const SwRect& rVisArea,
141 const SwFrame& rFrame,
142 const SwAccessibleChild& rChild,
143 sal_Int32& rPos,
144 bool bInPagePreview )
146 bool bFound = false;
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 )
159 bFound = true;
160 else
161 rPos++;
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 );
170 ++aIter;
173 else
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 )
186 bFound = true;
187 else
188 rPos++;
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 );
197 ++aIter;
201 return bFound;
204 SwAccessibleChild SwAccessibleFrame::GetChildAtPixel( const SwRect& rVisArea,
205 const SwFrame& rFrame,
206 const Point& rPixPos,
207 bool bInPagePreview,
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 ) )
230 aRet = rLower;
233 else if( rLower.GetSwFrame() )
235 // There are no unaccessible SdrObjects that count
236 aRet = GetChildAtPixel( rVisArea, *(rLower.GetSwFrame()), rPixPos,
237 bInPagePreview, rAccMap );
239 ++aRIter;
242 else
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 ) )
261 aRet = rLower;
264 else if( rLower.GetSwFrame() )
266 // There are no unaccessible SdrObjects that count
267 aRet = GetChildAtPixel( rVisArea, *(rLower.GetSwFrame()), rPixPos,
268 bInPagePreview, rAccMap );
270 ++aIter;
274 return aRet;
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 );
301 ++aIter;
304 else
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 );
323 ++aIter;
328 SwRect SwAccessibleFrame::GetBounds( const SwAccessibleMap& rAccMap,
329 const SwFrame *pFrame )
331 if( !pFrame )
332 pFrame = GetFrame();
334 SwAccessibleChild aFrame( pFrame );
335 SwRect aBounds( aFrame.GetBounds( rAccMap ).Intersection( maVisArea ) );
336 return aBounds;
339 bool SwAccessibleFrame::IsEditable( SwViewShell const *pVSh ) const
341 const SwFrame *pFrame = GetFrame();
342 if( !pFrame )
343 return false;
345 OSL_ENSURE( pVSh, "no view shell" );
346 if( pVSh && (pVSh->GetViewOptions()->IsReadonly() ||
347 pVSh->IsPreview()) )
348 return false;
350 if( !pFrame->IsRootFrame() && pFrame->IsProtected() )
351 return false;
353 return true;
356 bool SwAccessibleFrame::IsOpaque( SwViewShell const *pVSh ) const
358 SwAccessibleChild aFrame( GetFrame() );
359 if( !aFrame.GetSwFrame() )
360 return false;
362 OSL_ENSURE( pVSh, "no view shell" );
363 if( !pVSh )
364 return false;
366 const SwViewOption *pVOpt = pVSh->GetViewOptions();
369 const SwFrame *pFrame = aFrame.GetSwFrame();
370 if( pFrame->IsRootFrame() )
371 return true;
373 if( pFrame->IsPageFrame() && !pVOpt->IsPageBack() )
374 return false;
376 const SvxBrushItem &rBack = pFrame->GetAttrSet()->GetBackground();
377 if( !rBack.GetColor().IsTransparent() ||
378 rBack.GetGraphicPos() != GPOS_NONE )
379 return true;
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
387 return true;
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() )
396 return true;
398 if( pFrame->IsFlyFrame() )
399 aFrame = static_cast<const SwFlyFrame*>(pFrame)->GetAnchorFrame();
400 else
401 aFrame = pFrame->GetUpper();
402 } while( aFrame.GetSwFrame() && !aFrame.IsAccessible( IsInPagePreview() ) );
404 return false;
407 SwAccessibleFrame::SwAccessibleFrame( const SwRect& rVisArea,
408 const SwFrame *pF,
409 bool bIsPagePreview ) :
410 maVisArea( rVisArea ),
411 mpFrame( pF ),
412 mbIsInPagePreview( bIsPagePreview )
414 assert(mpFrame);
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 ) );
436 return sRet;
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
454 sal_Int32 nPos = 0;
455 return GetChildIndex( rAccMap, maVisArea, *mpFrame, rChild, nPos, IsInPagePreview() )
456 ? nPos
457 : -1;
460 sw::access::SwAccessibleChild SwAccessibleFrame::GetChildAtPixel(
461 const Point& rPos,
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: */