LibreOffice Module sw (master) 1
accframe.cxx
Go to the documentation of this file.
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 <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"
34
35using namespace sw::access;
36
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.
42 const SwRect& rVisArea,
43 const SwFrame *pFrame,
44 bool bInPagePreview )
45{
46 sal_Int32 nCount = 0;
47
48 const SwAccessibleChildSList aVisList( rVisArea, *pFrame, rAccMap );
49
51 while( aIter != aVisList.end() )
52 {
53 const SwAccessibleChild& rLower = *aIter;
54 if( rLower.IsAccessible( bInPagePreview ) )
55 {
56 nCount++;
57 }
58 else if( rLower.GetSwFrame() )
59 {
60 // There are no unaccessible SdrObjects that count
61 nCount += GetChildCount( rAccMap,
62 rVisArea, rLower.GetSwFrame(),
63 bInPagePreview );
64 }
65 ++aIter;
66 }
67
68 return nCount;
69}
70
72 SwAccessibleMap& rAccMap,
73 const SwRect& rVisArea,
74 const SwFrame& rFrame,
75 sal_Int32& rPos,
76 bool bInPagePreview )
77{
79
80 if( rPos >= 0 )
81 {
83 {
84 // We need a sorted list here
85 const SwAccessibleChildMap aVisMap( rVisArea, rFrame, rAccMap );
87 while( aIter != aVisMap.cend() && !aRet.IsValid() )
88 {
89 const SwAccessibleChild& rLower = (*aIter).second;
90 if( rLower.IsAccessible( bInPagePreview ) )
91 {
92 if( 0 == rPos )
93 aRet = rLower;
94 else
95 rPos--;
96 }
97 else if( rLower.GetSwFrame() )
98 {
99 // There are no unaccessible SdrObjects that count
100 aRet = GetChild( rAccMap,
101 rVisArea, *(rLower.GetSwFrame()), rPos,
102 bInPagePreview );
103 }
104 ++aIter;
105 }
106 }
107 else
108 {
109 // The unsorted list is sorted enough, because it returns lower
110 // frames in the correct order.
111 const SwAccessibleChildSList aVisList( rVisArea, rFrame, rAccMap );
113 while( aIter != aVisList.end() && !aRet.IsValid() )
114 {
115 const SwAccessibleChild& rLower = *aIter;
116 if( rLower.IsAccessible( bInPagePreview ) )
117 {
118 if( 0 == rPos )
119 aRet = rLower;
120 else
121 rPos--;
122 }
123 else if( rLower.GetSwFrame() )
124 {
125 // There are no unaccessible SdrObjects that count
126 aRet = GetChild( rAccMap,
127 rVisArea, *(rLower.GetSwFrame()), rPos,
128 bInPagePreview );
129 }
130 ++aIter;
131 }
132 }
133 }
134
135 return aRet;
136}
137
139 SwAccessibleMap& rAccMap,
140 const SwRect& rVisArea,
141 const SwFrame& rFrame,
142 const SwAccessibleChild& rChild,
143 sal_Int32& rPos,
144 bool bInPagePreview )
145{
146 bool bFound = false;
147
149 {
150 // We need a sorted list here
151 const SwAccessibleChildMap aVisMap( rVisArea, rFrame, rAccMap );
153 while( aIter != aVisMap.cend() && !bFound )
154 {
155 const SwAccessibleChild& rLower = (*aIter).second;
156 if( rLower.IsAccessible( bInPagePreview ) )
157 {
158 if( rChild == rLower )
159 bFound = true;
160 else
161 rPos++;
162 }
163 else if( rLower.GetSwFrame() )
164 {
165 // There are no unaccessible SdrObjects that count
166 bFound = GetChildIndex( rAccMap,
167 rVisArea, *(rLower.GetSwFrame()), rChild,
168 rPos, bInPagePreview );
169 }
170 ++aIter;
171 }
172 }
173 else
174 {
175 // The unsorted list is sorted enough, because it returns lower
176 // frames in the correct order.
177
178 const SwAccessibleChildSList aVisList( rVisArea, rFrame, rAccMap );
180 while( aIter != aVisList.end() && !bFound )
181 {
182 const SwAccessibleChild& rLower = *aIter;
183 if( rLower.IsAccessible( bInPagePreview ) )
184 {
185 if( rChild == rLower )
186 bFound = true;
187 else
188 rPos++;
189 }
190 else if( rLower.GetSwFrame() )
191 {
192 // There are no unaccessible SdrObjects that count
193 bFound = GetChildIndex( rAccMap,
194 rVisArea, *(rLower.GetSwFrame()), rChild,
195 rPos, bInPagePreview );
196 }
197 ++aIter;
198 }
199 }
200
201 return bFound;
202}
203
205 const SwFrame& rFrame,
206 const Point& rPixPos,
207 bool bInPagePreview,
208 SwAccessibleMap& rAccMap )
209{
211
213 {
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 );
218 while( aRIter != aVisMap.crend() && !aRet.IsValid() )
219 {
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 ) )
224 {
225 SwRect aLogBounds( rLower.GetBounds( rAccMap ) );
226 if( !aLogBounds.IsEmpty() )
227 {
228 tools::Rectangle aPixBounds( rAccMap.CoreToPixel( aLogBounds ) );
229 if( aPixBounds.Contains( rPixPos ) )
230 aRet = rLower;
231 }
232 }
233 else if( rLower.GetSwFrame() )
234 {
235 // There are no unaccessible SdrObjects that count
236 aRet = GetChildAtPixel( rVisArea, *(rLower.GetSwFrame()), rPixPos,
237 bInPagePreview, rAccMap );
238 }
239 ++aRIter;
240 }
241 }
242 else
243 {
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 );
249 while( aIter != aVisList.end() && !aRet.IsValid() )
250 {
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 ) )
255 {
256 SwRect aLogBounds( rLower.GetBounds( rAccMap ) );
257 if( !aLogBounds.IsEmpty() )
258 {
259 tools::Rectangle aPixBounds( rAccMap.CoreToPixel( aLogBounds ) );
260 if( aPixBounds.Contains( rPixPos ) )
261 aRet = rLower;
262 }
263 }
264 else if( rLower.GetSwFrame() )
265 {
266 // There are no unaccessible SdrObjects that count
267 aRet = GetChildAtPixel( rVisArea, *(rLower.GetSwFrame()), rPixPos,
268 bInPagePreview, rAccMap );
269 }
270 ++aIter;
271 }
272 }
273
274 return aRet;
275}
276
278 const SwRect& rVisArea,
279 const SwFrame& rFrame,
280 std::list< SwAccessibleChild >& rChildren,
281 bool bInPagePreview )
282{
284 {
285 // We need a sorted list here
286 const SwAccessibleChildMap aVisMap( rVisArea, rFrame, rAccMap );
288 while( aIter != aVisMap.cend() )
289 {
290 const SwAccessibleChild& rLower = (*aIter).second;
291 if( rLower.IsAccessible( bInPagePreview ) )
292 {
293 rChildren.push_back( rLower );
294 }
295 else if( rLower.GetSwFrame() )
296 {
297 // There are no unaccessible SdrObjects that count
298 GetChildren( rAccMap, rVisArea, *(rLower.GetSwFrame()),
299 rChildren, bInPagePreview );
300 }
301 ++aIter;
302 }
303 }
304 else
305 {
306 // The unsorted list is sorted enough, because it returns lower
307 // frames in the correct order.
308 const SwAccessibleChildSList aVisList( rVisArea, rFrame, rAccMap );
310 while( aIter != aVisList.end() )
311 {
312 const SwAccessibleChild& rLower = *aIter;
313 if( rLower.IsAccessible( bInPagePreview ) )
314 {
315 rChildren.push_back( rLower );
316 }
317 else if( rLower.GetSwFrame() )
318 {
319 // There are no unaccessible SdrObjects that count
320 GetChildren( rAccMap, rVisArea, *(rLower.GetSwFrame()),
321 rChildren, bInPagePreview );
322 }
323 ++aIter;
324 }
325 }
326}
327
329 const SwFrame *pFrame )
330{
331 if( !pFrame )
332 pFrame = GetFrame();
333
334 SwAccessibleChild aFrame( pFrame );
335 SwRect aBounds( aFrame.GetBounds( rAccMap ).Intersection( maVisArea ) );
336 return aBounds;
337}
338
340{
341 const SwFrame *pFrame = GetFrame();
342 if( !pFrame )
343 return false;
344
345 OSL_ENSURE( pVSh, "no view shell" );
346 if( pVSh && (pVSh->GetViewOptions()->IsReadonly() ||
347 pVSh->IsPreview()) )
348 return false;
349
350 if( !pFrame->IsRootFrame() && pFrame->IsProtected() )
351 return false;
352
353 return true;
354}
355
357{
358 SwAccessibleChild aFrame( GetFrame() );
359 if( !aFrame.GetSwFrame() )
360 return false;
361
362 OSL_ENSURE( pVSh, "no view shell" );
363 if( !pVSh )
364 return false;
365
366 const SwViewOption *pVOpt = pVSh->GetViewOptions();
367 do
368 {
369 const SwFrame *pFrame = aFrame.GetSwFrame();
370 if( pFrame->IsRootFrame() )
371 return true;
372
373 if( pFrame->IsPageFrame() && !pVOpt->IsPageBack() )
374 return false;
375
376 const SvxBrushItem &rBack = pFrame->GetAttrSet()->GetBackground();
377 if( !rBack.GetColor().IsTransparent() ||
378 rBack.GetGraphicPos() != GPOS_NONE )
379 return true;
380
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
386 )
387 return true;
388
389 if( pFrame->IsSctFrame() )
390 {
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;
397 }
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() ) );
403
404 return false;
405}
406
408 const SwFrame *pF,
409 bool bIsPagePreview ) :
410 maVisArea( rVisArea ),
411 mpFrame( pF ),
412 mbIsInPagePreview( bIsPagePreview )
413{
414 assert(mpFrame);
415}
416
418{
419}
420
422 bool bInPagePreview )
423{
424 return rFrameOrObj.GetParent( bInPagePreview );
425}
426
428{
429 sal_uInt16 nPageNum = GetFrame()->GetVirtPageNum();
432 if( SVX_NUM_NUMBER_NONE == nFormat )
433 nFormat = SVX_NUM_ARABIC;
434
435 OUString sRet( FormatNumber( nPageNum, nFormat ) );
436 return sRet;
437}
438
440{
441 return GetChildCount( rAccMap, maVisArea, mpFrame, IsInPagePreview() );
442}
443
445 SwAccessibleMap& rAccMap,
446 sal_Int32 nPos ) const
447{
449}
450
452 const sw::access::SwAccessibleChild& rChild ) const
453{
454 sal_Int32 nPos = 0;
455 return GetChildIndex( rAccMap, maVisArea, *mpFrame, rChild, nPos, IsInPagePreview() )
456 ? nPos
457 : -1;
458}
459
461 const Point& rPos,
462 SwAccessibleMap& rAccMap ) const
463{
464 return GetChildAtPixel( maVisArea, *mpFrame, rPos, IsInPagePreview(), rAccMap );
465}
466
468 std::list< sw::access::SwAccessibleChild >& rChildren ) const
469{
470 GetChildren( rAccMap, maVisArea, *mpFrame, rChildren, IsInPagePreview() );
471}
472
474 const sw::access::SwAccessibleChild& rFrameOrObj ) const
475{
476 return IsShowing( rFrameOrObj.GetBox( rAccMap ) );
477}
478
479/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
GPOS_NONE
bool IsTransparent() const
const Color & GetColor() const
SvxGraphicPosition GetGraphicPos() const
SvxNumType GetNumberingType() const
const_reverse_iterator crbegin() const
const_iterator cend() const
const_iterator cbegin() const
std::map< key_type, mapped_type, key_compare >::const_iterator const_iterator
static bool IsSortingRequired(const SwFrame &rFrame)
std::map< key_type, mapped_type, key_compare >::const_reverse_iterator const_reverse_iterator
const_reverse_iterator crend() const
const_iterator end() const
const_iterator begin() const
SwRect GetBounds(const SwAccessibleMap &rAccMap, const SwFrame *pFrame=nullptr)
Definition: accframe.cxx:328
bool IsInPagePreview() const
Definition: accframe.hxx:86
static void GetChildren(SwAccessibleMap &rAccMap, const SwRect &rVisArea, const SwFrame &rFrame, std::list< sw::access::SwAccessibleChild > &rChildren, bool bInPagePreview)
Definition: accframe.cxx:277
bool IsEditable(SwViewShell const *pVSh) const
Definition: accframe.cxx:339
static sal_Int32 GetChildCount(SwAccessibleMap &rAccMap, const SwRect &rVisArea, const SwFrame *pFrame, bool bInPagePreviewr)
Definition: accframe.cxx:41
static sw::access::SwAccessibleChild GetChildAtPixel(const SwRect &rVisArea, const SwFrame &rFrame, const Point &rPos, bool bInPagePreview, SwAccessibleMap &rAccMap)
Definition: accframe.cxx:204
static bool GetChildIndex(SwAccessibleMap &rAccMap, const SwRect &rVisArea, const SwFrame &rFrame, const sw::access::SwAccessibleChild &rChild, sal_Int32 &rPos, bool bInPagePreview)
Definition: accframe.cxx:138
bool IsOpaque(SwViewShell const *pVSh) const
Definition: accframe.cxx:356
bool IsShowing(const SwAccessibleMap &rAccMap, const sw::access::SwAccessibleChild &rFrameOrObj) const
Definition: accframe.cxx:473
static sw::access::SwAccessibleChild GetChild(SwAccessibleMap &rAccMap, const SwRect &rVisArea, const SwFrame &rFrame, sal_Int32 &rPos, bool bInPagePreview)
Definition: accframe.cxx:71
const SwFrame * GetFrame() const
Definition: accframe.hxx:102
const SwFrame * GetParent() const
Definition: accframe.hxx:154
SwAccessibleFrame(const SwRect &rVisArea, const SwFrame *pFrame, bool bIsPagePreview)
Definition: accframe.cxx:407
virtual ~SwAccessibleFrame()
Definition: accframe.cxx:417
OUString GetFormattedPageNumber() const
Definition: accframe.cxx:427
const SwFrame * mpFrame
Definition: accframe.hxx:39
tools::Rectangle CoreToPixel(const SwRect &rRect) const
Definition: accmap.cxx:3174
const SwFrame * GetAnchorFrame() const
const SvxBrushItem & GetBackground(bool=true) const
Definition: frmatr.hxx:70
general base class for all free-flowing frames
Definition: flyfrm.hxx:79
Base class of the Writer layout elements.
Definition: frame.hxx:315
sal_uInt16 GetVirtPageNum() const
Definition: trvlfrm.cxx:1817
bool IsPageFrame() const
Definition: frame.hxx:1184
bool IsProtected() const
Is the Frame or rather the Section in which it lies protected?
Definition: trvlfrm.cxx:1639
const SwAttrSet * GetAttrSet() const
WARNING: this may not return correct RES_PAGEDESC/RES_BREAK items for SwTextFrame,...
Definition: findfrm.cxx:762
bool IsRootFrame() const
Definition: frame.hxx:1180
SwLayoutFrame * GetUpper()
Definition: frame.hxx:684
bool IsFlyFrame() const
Definition: frame.hxx:1216
bool IsSctFrame() const
Definition: frame.hxx:1220
SwPageFrame * FindPageFrame()
Definition: frame.hxx:686
const SvxNumberType & GetNumType() const
Definition: pagedesc.hxx:202
SwPageDesc * GetPageDesc()
Definition: pagefrm.hxx:147
Of course Writer needs its own rectangles.
Definition: swrect.hxx:35
SwRect & Intersection(const SwRect &rRect)
Definition: swrect.cxx:57
bool IsEmpty() const
Definition: swrect.hxx:304
SectionType GetType() const
Definition: section.hxx:173
bool IsReadonly() const
Definition: viewopt.hxx:627
bool IsIndexShadings() const
Definition: viewopt.hxx:832
bool IsPageBack() const
Definition: viewopt.hxx:504
bool IsPreview() const
Definition: viewsh.hxx:517
const SwViewOption * GetViewOptions() const
Definition: viewsh.hxx:452
bool IsAccessible(bool bPagePreview) const
Definition: accfrmobj.cxx:120
SwRect GetBox(const SwAccessibleMap &rAccMap) const
Definition: accfrmobj.cxx:213
const SwFrame * GetSwFrame() const
Definition: accfrmobj.hxx:63
const SwFrame * GetParent(const bool bInPagePreview) const
Definition: accfrmobj.cxx:302
SwRect GetBounds(const SwAccessibleMap &rAccMap) const
Definition: accfrmobj.cxx:264
bool Contains(const Point &rPOINT) const
constexpr ::Color COL_TRANSPARENT(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
int nCount
OUString FormatNumber(sal_uInt32 nNum, SvxNumType nFormat, LanguageType nLang)
expand numbering
Definition: fldbas.cxx:523
sal_uInt16 nPos
SvxNumType
SVX_NUM_NUMBER_NONE
SVX_NUM_ARABIC