LibreOffice Module sw (master)  1
trvlfrm.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 <hints.hxx>
21 #include <comphelper/flagguard.hxx>
22 #include <tools/line.hxx>
23 #include <editeng/opaqitem.hxx>
24 #include <editeng/protitem.hxx>
25 #include <vcl/settings.hxx>
26 #include <fmtpdsc.hxx>
27 #include <fmtsrnd.hxx>
28 #include <pagedesc.hxx>
29 #include <pagefrm.hxx>
30 #include <rootfrm.hxx>
31 #include <ftnfrm.hxx>
32 #include <flyfrm.hxx>
33 #include <tabfrm.hxx>
34 #include <rowfrm.hxx>
35 #include <cellfrm.hxx>
36 #include <txtfrm.hxx>
37 #include <notxtfrm.hxx>
38 #include <viewopt.hxx>
40 #include <viscrs.hxx>
41 #include <dflyobj.hxx>
42 #include <crstate.hxx>
43 #include <dcontact.hxx>
44 #include <sortedobjs.hxx>
45 #include <txatbase.hxx>
46 #include <fmtfld.hxx>
47 #include <fldbas.hxx>
48 #include <frmatr.hxx>
49 #include <frmtool.hxx>
50 #include <ndtxt.hxx>
51 #include <undobj.hxx>
52 
53 #include <swselectionlist.hxx>
54 #include <comphelper/lok.hxx>
55 
56 namespace {
57  bool lcl_GetModelPositionForViewPoint_Objects( const SwPageFrame* pPageFrame, bool bSearchBackground,
58  SwPosition *pPos, Point const & rPoint, SwCursorMoveState* pCMS )
59  {
60  bool bRet = false;
61  Point aPoint( rPoint );
62  SwOrderIter aIter( pPageFrame );
63  aIter.Top();
64  while ( aIter() )
65  {
66  const SwVirtFlyDrawObj* pObj =
67  static_cast<const SwVirtFlyDrawObj*>(aIter());
68  const SwAnchoredObject* pAnchoredObj = GetUserCall( aIter() )->GetAnchoredObj( aIter() );
69  const SwFormatSurround& rSurround = pAnchoredObj->GetFrameFormat().GetSurround();
70  const SvxOpaqueItem& rOpaque = pAnchoredObj->GetFrameFormat().GetOpaque();
71  bool bInBackground = ( rSurround.GetSurround() == css::text::WrapTextMode_THROUGH ) && !rOpaque.GetValue();
72 
73  bool bBackgroundMatches = bInBackground == bSearchBackground;
74 
75  const SwFlyFrame* pFly = pObj ? pObj->GetFlyFrame() : nullptr;
76  if ( pFly && bBackgroundMatches &&
77  ( ( pCMS && pCMS->m_bSetInReadOnly ) ||
78  !pFly->IsProtected() ) &&
79  pFly->GetModelPositionForViewPoint( pPos, aPoint, pCMS ) )
80  {
81  bRet = true;
82  break;
83  }
84 
85  if ( pCMS && pCMS->m_bStop )
86  return false;
87  aIter.Prev();
88  }
89  return bRet;
90  }
91 
92  double lcl_getDistance( const SwRect& rRect, const Point& rPoint )
93  {
94  double nDist = 0.0;
95 
96  // If the point is inside the rectangle, then distance is 0
97  // Otherwise, compute the distance to the center of the rectangle.
98  if ( !rRect.IsInside( rPoint ) )
99  {
100  tools::Line aLine( rPoint, rRect.Center( ) );
101  nDist = aLine.GetLength( );
102  }
103 
104  return nDist;
105  }
106 }
107 
108 namespace {
109 
110 //For SwFlyFrame::GetModelPositionForViewPoint
111 class SwCursorOszControl
112 {
113 public:
114  // So the compiler can initialize the class already. No DTOR and member
115  // as public members
116  const SwFlyFrame *pEntry;
117  const SwFlyFrame *pStack1;
118  const SwFlyFrame *pStack2;
119 
120  bool ChkOsz( const SwFlyFrame *pFly )
121  {
122  bool bRet = true;
123  if ( pFly != pStack1 && pFly != pStack2 )
124  {
125  pStack1 = pStack2;
126  pStack2 = pFly;
127  bRet = false;
128  }
129  return bRet;
130  }
131 
132  void Entry( const SwFlyFrame *pFly )
133  {
134  if ( !pEntry )
135  pEntry = pStack1 = pFly;
136  }
137 
138  void Exit( const SwFlyFrame *pFly )
139  {
140  if ( pFly == pEntry )
141  pEntry = pStack1 = pStack2 = nullptr;
142  }
143 };
144 
145 }
146 
147 static SwCursorOszControl g_OszCtrl = { nullptr, nullptr, nullptr };
148 
151  SwCursorMoveState* pCMS, bool ) const
152 {
153  vcl::RenderContext* pRenderContext = getRootFrame()->GetCurrShell()->GetOut();
154  bool bRet = false;
155  const SwFrame *pFrame = Lower();
156  while ( !bRet && pFrame )
157  {
158  pFrame->Calc(pRenderContext);
159 
160  // #i43742# New function
161  const bool bContentCheck = pFrame->IsTextFrame() && pCMS && pCMS->m_bContentCheck;
162  const SwRect aPaintRect( bContentCheck ?
163  pFrame->UnionFrame() :
164  pFrame->GetPaintArea() );
165 
166  if ( aPaintRect.IsInside( rPoint ) &&
167  ( bContentCheck || pFrame->GetModelPositionForViewPoint( pPos, rPoint, pCMS ) ) )
168  bRet = true;
169  else
170  pFrame = pFrame->GetNext();
171  if ( pCMS && pCMS->m_bStop )
172  return false;
173  }
174  return bRet;
175 }
176 
180  SwCursorMoveState* pCMS, bool bTestBackground ) const
181 {
182  Point aPoint( rPoint );
183 
184  // check, if we have to adjust the point
185  if ( !getFrameArea().IsInside( aPoint ) )
186  {
187  aPoint.setX( std::max( aPoint.X(), getFrameArea().Left() ) );
188  aPoint.setX( std::min( aPoint.X(), getFrameArea().Right() ) );
189  aPoint.setY( std::max( aPoint.Y(), getFrameArea().Top() ) );
190  aPoint.setY( std::min( aPoint.Y(), getFrameArea().Bottom() ) );
191  }
192 
193  bool bRet = false;
194  //Could it be a free flying one?
195  //If his content should be protected, we can't set the Cursor in it, thus
196  //all changes should be impossible.
197  if ( GetSortedObjs() )
198  {
199  bRet = lcl_GetModelPositionForViewPoint_Objects( this, false, pPos, rPoint, pCMS );
200  }
201 
202  if ( !bRet )
203  {
204  SwPosition aBackPos( *pPos );
205  SwPosition aTextPos( *pPos );
206 
207  //We fix the StartPoint if no Content below the page 'answers' and then
208  //start all over again one page before the current one.
209  //However we can't use Flys in such a case.
210  if (!SwLayoutFrame::GetModelPositionForViewPoint(&aTextPos, aPoint, pCMS))
211  {
212  if ( pCMS && (pCMS->m_bStop || pCMS->m_bExactOnly) )
213  {
214  pCMS->m_bStop = true;
215  return false;
216  }
217 
218  const SwContentFrame *pCnt = GetContentPos( aPoint, false, false, pCMS, false );
219  // GetContentPos may have modified pCMS
220  if ( pCMS && pCMS->m_bStop )
221  return false;
222 
223  bool bTextRet = false;
224 
225  OSL_ENSURE( pCnt, "Cursor is gone to a Black hole" );
226  if( pCMS && pCMS->m_pFill && pCnt->IsTextFrame() )
227  bTextRet = pCnt->GetModelPositionForViewPoint( &aTextPos, rPoint, pCMS );
228  else
229  bTextRet = pCnt->GetModelPositionForViewPoint( &aTextPos, aPoint, pCMS );
230 
231  if ( !bTextRet )
232  {
233  // Set point to pCnt, delete mark
234  // this may happen, if pCnt is hidden
235  if (pCnt->IsTextFrame())
236  {
237  aTextPos = static_cast<SwTextFrame const*>(pCnt)->MapViewToModelPos(TextFrameIndex(0));
238  }
239  else
240  {
241  assert(pCnt->IsNoTextFrame());
242  aTextPos = SwPosition( *static_cast<SwNoTextFrame const*>(pCnt)->GetNode() );
243  }
244  }
245  }
246 
247  SwContentNode* pContentNode = aTextPos.nNode.GetNode().GetContentNode();
248  bool bConsiderBackground = true;
249  // If the text position is a clickable field, then that should have priority.
250  if (pContentNode && pContentNode->IsTextNode())
251  {
252  SwTextNode* pTextNd = pContentNode->GetTextNode();
253  SwTextAttr* pTextAttr = pTextNd->GetTextAttrForCharAt(aTextPos.nContent.GetIndex(), RES_TXTATR_FIELD);
254  if (pTextAttr)
255  {
256  const SwField* pField = pTextAttr->GetFormatField().GetField();
257  if (pField->IsClickable())
258  bConsiderBackground = false;
259  }
260  }
261 
262  bool bBackRet = false;
263  // Check objects in the background if nothing else matched
264  if ( GetSortedObjs() )
265  {
266  bBackRet = lcl_GetModelPositionForViewPoint_Objects( this, true, &aBackPos, rPoint, pCMS );
267  }
268 
269  if (bConsiderBackground && bTestBackground && bBackRet)
270  {
271  (*pPos) = aBackPos;
272  }
273  else if (!bBackRet)
274  {
275  (*pPos) = aTextPos;
276  }
277  else // bBackRet && !(bConsiderBackground && bTestBackground)
278  {
279  /* In order to provide a selection as accurate as possible when we have both
280  * text and background object, then we compute the distance between both
281  * would-be positions and the click point. The shortest distance wins.
282  */
283  double nTextDistance = 0;
284  bool bValidTextDistance = false;
285  if (pContentNode)
286  {
287  SwContentFrame* pTextFrame = pContentNode->getLayoutFrame( getRootFrame( ) );
288 
289  // try this again but prefer the "previous" position
290  SwCursorMoveState aMoveState;
291  SwCursorMoveState *const pState(pCMS ? pCMS : &aMoveState);
293  pState->m_bPosMatchesBounds, true);
294  SwPosition prevTextPos(*pPos);
295  SwLayoutFrame::GetModelPositionForViewPoint(&prevTextPos, aPoint, pState);
296 
297  SwRect aTextRect;
298  pTextFrame->GetCharRect(aTextRect, prevTextPos);
299 
300  if (prevTextPos.nContent < pContentNode->Len())
301  {
302  // aRextRect is just a line on the left edge of the
303  // previous character; to get a better measure from
304  // lcl_getDistance, extend that to a rectangle over
305  // the entire character.
306  SwPosition const nextTextPos(prevTextPos.nNode,
307  SwIndex(prevTextPos.nContent, +1));
308  SwRect nextTextRect;
309  pTextFrame->GetCharRect(nextTextRect, nextTextPos);
310  SwRectFnSet aRectFnSet(pTextFrame);
311  if (aRectFnSet.GetTop(aTextRect) ==
312  aRectFnSet.GetTop(nextTextRect)) // same line?
313  {
314  // need to handle mixed RTL/LTR portions somehow
315  if (aRectFnSet.GetLeft(aTextRect) <
316  aRectFnSet.GetLeft(nextTextRect))
317  {
318  aRectFnSet.SetRight( aTextRect,
319  aRectFnSet.GetLeft(nextTextRect));
320  }
321  else // RTL
322  {
323  aRectFnSet.SetLeft( aTextRect,
324  aRectFnSet.GetLeft(nextTextRect));
325  }
326  }
327  }
328 
329  nTextDistance = lcl_getDistance(aTextRect, rPoint);
330  bValidTextDistance = true;
331  }
332 
333  double nBackDistance = 0;
334  bool bValidBackDistance = false;
335  SwContentNode* pBackNd = aBackPos.nNode.GetNode( ).GetContentNode( );
336  if ( pBackNd && bConsiderBackground)
337  {
338  // FIXME There are still cases were we don't have the proper node here.
339  SwContentFrame* pBackFrame = pBackNd->getLayoutFrame( getRootFrame( ) );
340  SwRect rBackRect;
341  if (pBackFrame)
342  {
343  pBackFrame->GetCharRect( rBackRect, aBackPos );
344 
345  nBackDistance = lcl_getDistance( rBackRect, rPoint );
346  bValidBackDistance = true;
347  }
348  }
349 
350  if ( bValidTextDistance && bValidBackDistance && basegfx::fTools::more( nTextDistance, nBackDistance ) )
351  {
352  (*pPos) = aBackPos;
353  }
354  else
355  {
356  (*pPos) = aTextPos;
357  }
358  }
359  }
360 
361  rPoint = aPoint;
362  return true;
363 }
364 
365 bool SwLayoutFrame::FillSelection( SwSelectionList& rList, const SwRect& rRect ) const
366 {
367  if( rRect.IsOver(GetPaintArea()) )
368  {
369  const SwFrame* pFrame = Lower();
370  while( pFrame )
371  {
372  pFrame->FillSelection( rList, rRect );
373  pFrame = pFrame->GetNext();
374  }
375  }
376  return false;
377 }
378 
379 bool SwPageFrame::FillSelection( SwSelectionList& rList, const SwRect& rRect ) const
380 {
381  bool bRet = false;
382  if( rRect.IsOver(GetPaintArea()) )
383  {
384  bRet = SwLayoutFrame::FillSelection( rList, rRect );
385  if( GetSortedObjs() )
386  {
387  const SwSortedObjs &rObjs = *GetSortedObjs();
388  for (SwAnchoredObject* pAnchoredObj : rObjs)
389  {
390  if( dynamic_cast< const SwFlyFrame *>( pAnchoredObj ) == nullptr )
391  continue;
392  const SwFlyFrame* pFly = static_cast<const SwFlyFrame*>(pAnchoredObj);
393  if( pFly->FillSelection( rList, rRect ) )
394  bRet = true;
395  }
396  }
397  }
398  return bRet;
399 }
400 
401 bool SwRootFrame::FillSelection( SwSelectionList& aSelList, const SwRect& rRect) const
402 {
403  const SwFrame *pPage = Lower();
404  const long nBottom = rRect.Bottom();
405  while( pPage )
406  {
407  if( pPage->getFrameArea().Top() < nBottom )
408  {
409  if( pPage->getFrameArea().Bottom() > rRect.Top() )
410  pPage->FillSelection( aSelList, rRect );
411  pPage = pPage->GetNext();
412  }
413  else
414  pPage = nullptr;
415  }
416  return !aSelList.isEmpty();
417 }
418 
424  SwCursorMoveState* pCMS, bool bTestBackground ) const
425 {
426  const bool bOldAction = IsCallbackActionEnabled();
427  const_cast<SwRootFrame*>(this)->SetCallbackActionEnabled( false );
428  OSL_ENSURE( (Lower() && Lower()->IsPageFrame()), "No PageFrame found." );
429  if( pCMS && pCMS->m_pFill )
430  pCMS->m_bFillRet = false;
431  Point aOldPoint = rPoint;
432 
433  // search for page containing rPoint. The borders around the pages are considered
434  const SwPageFrame* pPage = GetPageAtPos( rPoint, nullptr, true );
435 
436  // #i95626#
437  // special handling for <rPoint> beyond root frames area
438  if ( !pPage &&
439  rPoint.X() > getFrameArea().Right() &&
440  rPoint.Y() > getFrameArea().Bottom() )
441  {
442  pPage = dynamic_cast<const SwPageFrame*>(Lower());
443  while ( pPage && pPage->GetNext() )
444  {
445  pPage = dynamic_cast<const SwPageFrame*>(pPage->GetNext());
446  }
447  }
448  if ( pPage )
449  {
450  pPage->SwPageFrame::GetModelPositionForViewPoint( pPos, rPoint, pCMS, bTestBackground );
451  }
452 
453  const_cast<SwRootFrame*>(this)->SetCallbackActionEnabled( bOldAction );
454  if( pCMS )
455  {
456  if( pCMS->m_bStop )
457  return false;
458  if( pCMS->m_pFill )
459  return pCMS->m_bFillRet;
460  }
461  return aOldPoint == rPoint;
462 }
463 
471  SwCursorMoveState* pCMS, bool ) const
472 {
473  vcl::RenderContext* pRenderContext = getRootFrame()->GetCurrShell()->GetOut();
474  // cell frame does not necessarily have a lower (split table cell)
475  if ( !Lower() )
476  return false;
477 
478  if ( !(pCMS && pCMS->m_bSetInReadOnly) &&
479  GetFormat()->GetProtect().IsContentProtected() )
480  return false;
481 
482  if ( pCMS && pCMS->m_eState == CursorMoveState::TableSel )
483  {
484  const SwTabFrame *pTab = FindTabFrame();
485  if ( pTab->IsFollow() && pTab->IsInHeadline( *this ) )
486  {
487  pCMS->m_bStop = true;
488  return false;
489  }
490  }
491 
492  if ( Lower() )
493  {
494  if ( Lower()->IsLayoutFrame() )
495  return SwLayoutFrame::GetModelPositionForViewPoint( pPos, rPoint, pCMS );
496  else
497  {
498  Calc(pRenderContext);
499  bool bRet = false;
500 
501  const SwFrame *pFrame = Lower();
502  while ( pFrame && !bRet )
503  {
504  pFrame->Calc(pRenderContext);
505  if ( pFrame->getFrameArea().IsInside( rPoint ) )
506  {
507  bRet = pFrame->GetModelPositionForViewPoint( pPos, rPoint, pCMS );
508  if ( pCMS && pCMS->m_bStop )
509  return false;
510  }
511  pFrame = pFrame->GetNext();
512  }
513  if ( !bRet )
514  {
515  const bool bFill = pCMS && pCMS->m_pFill;
516  Point aPoint( rPoint );
517  const SwContentFrame *pCnt = GetContentPos( rPoint, true );
518  if( bFill && pCnt->IsTextFrame() )
519  {
520  rPoint = aPoint;
521  }
522  pCnt->GetModelPositionForViewPoint( pPos, rPoint, pCMS );
523  }
524  return true;
525  }
526  }
527 
528  return false;
529 }
530 
531 //Problem: If two Flys have the same size and share the same position then
532 //they end inside each other.
533 //Because we recursively check if a Point doesn't randomly lie inside another
534 //fly which lies completely inside the current Fly we could trigger an endless
535 //loop with the mentioned situation above.
536 //Using the helper class SwCursorOszControl we prevent the recursion. During
537 //a recursion GetModelPositionForViewPoint picks the one which lies on top.
539  SwCursorMoveState* pCMS, bool ) const
540 {
541  vcl::RenderContext* pRenderContext = getRootFrame()->GetCurrShell()->GetOut();
542  g_OszCtrl.Entry( this );
543 
544  //If the Points lies inside the Fly, we try hard to set the Cursor inside it.
545  //However if the Point sits inside a Fly which is completely located inside
546  //the current one, we call GetModelPositionForViewPoint for it.
547  Calc(pRenderContext);
548  bool bInside = getFrameArea().IsInside( rPoint ) && Lower();
549  bool bRet = false;
550 
551  //If a Frame contains a graphic, but only text was requested, it basically
552  //won't accept the Cursor.
553  if ( bInside && pCMS && pCMS->m_eState == CursorMoveState::SetOnlyText &&
554  (!Lower() || Lower()->IsNoTextFrame()) )
555  bInside = false;
556 
557  const SwPageFrame *pPage = FindPageFrame();
558  if ( bInside && pPage && pPage->GetSortedObjs() )
559  {
560  SwOrderIter aIter( pPage );
561  aIter.Top();
562  while ( aIter() && !bRet )
563  {
564  const SwVirtFlyDrawObj* pObj = static_cast<const SwVirtFlyDrawObj*>(aIter());
565  const SwFlyFrame* pFly = pObj ? pObj->GetFlyFrame() : nullptr;
566  if ( pFly && pFly->getFrameArea().IsInside( rPoint ) &&
567  getFrameArea().IsInside( pFly->getFrameArea() ) )
568  {
569  if (g_OszCtrl.ChkOsz(pFly))
570  break;
571  bRet = pFly->GetModelPositionForViewPoint( pPos, rPoint, pCMS );
572  if ( bRet )
573  break;
574  if ( pCMS && pCMS->m_bStop )
575  return false;
576  }
577  aIter.Next();
578  }
579  }
580 
581  while ( bInside && !bRet )
582  {
583  const SwFrame *pFrame = Lower();
584  while ( pFrame && !bRet )
585  {
586  pFrame->Calc(pRenderContext);
587  if ( pFrame->getFrameArea().IsInside( rPoint ) )
588  {
589  bRet = pFrame->GetModelPositionForViewPoint( pPos, rPoint, pCMS );
590  if ( pCMS && pCMS->m_bStop )
591  return false;
592  }
593  pFrame = pFrame->GetNext();
594  }
595  if ( !bRet )
596  {
597  const bool bFill = pCMS && pCMS->m_pFill;
598  Point aPoint( rPoint );
599  const SwContentFrame *pCnt = GetContentPos( rPoint, true, false, pCMS );
600  if ( pCMS && pCMS->m_bStop )
601  return false;
602  if( bFill && pCnt->IsTextFrame() )
603  {
604  rPoint = aPoint;
605  }
606  pCnt->GetModelPositionForViewPoint( pPos, rPoint, pCMS );
607  bRet = true;
608  }
609  }
610  g_OszCtrl.Exit( this );
611  return bRet;
612 }
613 
616 {
617  if( &pPam->GetNode() != GetNode() )
618  return false;
619  const_cast<SwContentNode*>(GetNode())->
620  MakeStartIndex(&pPam->GetPoint()->nContent);
621  return true;
622 }
623 
624 bool SwNoTextFrame::RightMargin(SwPaM *pPam, bool) const
625 {
626  if( &pPam->GetNode() != GetNode() )
627  return false;
628  const_cast<SwContentNode*>(GetNode())->
629  MakeEndIndex(&pPam->GetPoint()->nContent);
630  return true;
631 }
632 
633 static const SwContentFrame *lcl_GetNxtCnt( const SwContentFrame* pCnt )
634 {
635  return pCnt->GetNextContentFrame();
636 }
637 
638 static const SwContentFrame *lcl_GetPrvCnt( const SwContentFrame* pCnt )
639 {
640  return pCnt->GetPrevContentFrame();
641 }
642 
643 typedef const SwContentFrame *(*GetNxtPrvCnt)( const SwContentFrame* );
644 
646 static bool lcl_IsInRepeatedHeadline( const SwFrame *pFrame,
647  const SwTabFrame** ppTFrame = nullptr )
648 {
649  const SwTabFrame *pTab = pFrame->FindTabFrame();
650  if( ppTFrame )
651  *ppTFrame = pTab;
652  return pTab && pTab->IsFollow() && pTab->IsInHeadline( *pFrame );
653 }
654 
656 //MA 1998-01-26: Chg also skip other protected areas
657 //FME: Skip follow flow cells
659  GetNxtPrvCnt fnNxtPrv,
660  bool bMissHeadline,
661  bool bInReadOnly,
662  bool bMissFollowFlowLine )
663 {
664  if ( pCnt && pCnt->IsInTab() )
665  {
666  bool bProtect = true;
667  while ( pCnt && bProtect )
668  {
669  const SwLayoutFrame *pCell = pCnt->GetUpper();
670  while ( pCell && !pCell->IsCellFrame() )
671  pCell = pCell->GetUpper();
672  if ( !pCell ||
673  ( ( bInReadOnly || !pCell->GetFormat()->GetProtect().IsContentProtected() ) &&
674  ( !bMissHeadline || !lcl_IsInRepeatedHeadline( pCell ) ) &&
675  ( !bMissFollowFlowLine || !pCell->IsInFollowFlowRow() ) &&
676  !pCell->IsCoveredCell() ) )
677  bProtect = false;
678  else
679  pCnt = (*fnNxtPrv)( pCnt );
680  }
681  }
682  else if ( !bInReadOnly )
683  while ( pCnt && pCnt->IsProtected() )
684  pCnt = (*fnNxtPrv)( pCnt );
685 
686  return pCnt;
687 }
688 
689 static bool lcl_UpDown( SwPaM *pPam, const SwContentFrame *pStart,
690  GetNxtPrvCnt fnNxtPrv, bool bInReadOnly )
691 {
692  OSL_ENSURE( FrameContainsNode(*pStart, pPam->GetNode().GetIndex()),
693  "lcl_UpDown doesn't work for others." );
694 
695  const SwContentFrame *pCnt = nullptr;
696 
697  //We have to cheat a little bit during a table selection: Go to the
698  //beginning of the cell while going up and go to the end of the cell while
699  //going down.
700  bool bTableSel = false;
701  if ( pStart->IsInTab() &&
702  pPam->GetNode().StartOfSectionNode() !=
703  pPam->GetNode( false ).StartOfSectionNode() )
704  {
705  bTableSel = true;
706  const SwLayoutFrame *pCell = pStart->GetUpper();
707  while ( !pCell->IsCellFrame() )
708  pCell = pCell->GetUpper();
709 
710  // Check, if cell has a Prev/Follow cell:
711  const bool bFwd = ( fnNxtPrv == lcl_GetNxtCnt );
712  const SwLayoutFrame* pTmpCell = bFwd ?
713  static_cast<const SwCellFrame*>(pCell)->GetFollowCell() :
714  static_cast<const SwCellFrame*>(pCell)->GetPreviousCell();
715 
716  const SwContentFrame* pTmpStart = pStart;
717  while ( pTmpCell && nullptr != ( pTmpStart = pTmpCell->ContainsContent() ) )
718  {
719  pCell = pTmpCell;
720  pTmpCell = bFwd ?
721  static_cast<const SwCellFrame*>(pCell)->GetFollowCell() :
722  static_cast<const SwCellFrame*>(pCell)->GetPreviousCell();
723  }
724  const SwContentFrame *pNxt = pCnt = pTmpStart;
725 
726  while ( pCell->IsAnLower( pNxt ) )
727  {
728  pCnt = pNxt;
729  pNxt = (*fnNxtPrv)( pNxt );
730  }
731  }
732 
733  pCnt = (*fnNxtPrv)( pCnt ? pCnt : pStart );
734  pCnt = ::lcl_MissProtectedFrames( pCnt, fnNxtPrv, true, bInReadOnly, bTableSel );
735 
736  const SwTabFrame *pStTab = pStart->FindTabFrame();
737  const SwTabFrame *pTable = nullptr;
738  const bool bTab = pStTab || (pCnt && pCnt->IsInTab());
739  bool bEnd = !bTab;
740 
741  const SwFrame* pVertRefFrame = pStart;
742  if ( bTableSel && pStTab )
743  pVertRefFrame = pStTab;
744  SwRectFnSet aRectFnSet(pVertRefFrame);
745 
746  SwTwips nX = 0;
747  if ( bTab )
748  {
749  // pStart or pCnt is inside a table. nX will be used for travelling:
750  SwRect aRect( pStart->getFrameArea() );
751  pStart->GetCharRect( aRect, *pPam->GetPoint() );
752  Point aCenter = aRect.Center();
753  nX = aRectFnSet.IsVert() ? aCenter.Y() : aCenter.X();
754 
755  pTable = pCnt ? pCnt->FindTabFrame() : nullptr;
756  if ( !pTable )
757  pTable = pStTab;
758 
759  if ( pStTab &&
760  !pStTab->GetUpper()->IsInTab() &&
761  !pTable->GetUpper()->IsInTab() )
762  {
763  const SwFrame *pCell = pStart->GetUpper();
764  while ( pCell && !pCell->IsCellFrame() )
765  pCell = pCell->GetUpper();
766  OSL_ENSURE( pCell, "could not find the cell" );
767  nX = aRectFnSet.XInc(aRectFnSet.GetLeft(pCell->getFrameArea()),
768  aRectFnSet.GetWidth(pCell->getFrameArea()) / 2);
769 
770  //The flow leads from one table to the next. The X-value needs to be
771  //corrected based on the middle of the starting cell by the amount
772  //of the offset of the tables.
773  if ( pStTab != pTable )
774  {
775  nX += aRectFnSet.GetLeft(pTable->getFrameArea()) -
776  aRectFnSet.GetLeft(pStTab->getFrameArea());
777  }
778  }
779 
780  // Restrict nX to the left and right borders of pTab:
781  // (is this really necessary?)
782  if (pTable && !pTable->GetUpper()->IsInTab())
783  {
784  const bool bRTL = pTable->IsRightToLeft();
785  const long nPrtLeft = bRTL ?
786  aRectFnSet.GetPrtRight(*pTable) :
787  aRectFnSet.GetPrtLeft(*pTable);
788  if (bRTL != (aRectFnSet.XDiff(nPrtLeft, nX) > 0))
789  nX = nPrtLeft;
790  else
791  {
792  const long nPrtRight = bRTL ?
793  aRectFnSet.GetPrtLeft(*pTable) :
794  aRectFnSet.GetPrtRight(*pTable);
795  if (bRTL != (aRectFnSet.XDiff(nX, nPrtRight) > 0))
796  nX = nPrtRight;
797  }
798  }
799  }
800 
801  do
802  {
803  //If I'm in the DocumentBody, I want to stay there.
804  if ( pStart->IsInDocBody() )
805  {
806  while ( pCnt && (!pCnt->IsInDocBody() ||
807  (pCnt->IsTextFrame() && static_cast<const SwTextFrame*>(pCnt)->IsHiddenNow())))
808  {
809  pCnt = (*fnNxtPrv)( pCnt );
810  pCnt = ::lcl_MissProtectedFrames( pCnt, fnNxtPrv, true, bInReadOnly, bTableSel );
811  }
812  }
813 
814  //If I'm in the FootNoteArea, I try to reach the next FootNoteArea in
815  //case of necessity.
816  else if ( pStart->IsInFootnote() )
817  {
818  while ( pCnt && (!pCnt->IsInFootnote() ||
819  (pCnt->IsTextFrame() && static_cast<const SwTextFrame*>(pCnt)->IsHiddenNow())))
820  {
821  pCnt = (*fnNxtPrv)( pCnt );
822  pCnt = ::lcl_MissProtectedFrames( pCnt, fnNxtPrv, true, bInReadOnly, bTableSel );
823  }
824  }
825 
826  //In Flys we can go ahead blindly as long as we find a Content.
827  else if ( pStart->IsInFly() )
828  {
829  if ( pCnt && pCnt->IsTextFrame() && static_cast<const SwTextFrame*>(pCnt)->IsHiddenNow() )
830  {
831  pCnt = (*fnNxtPrv)( pCnt );
832  pCnt = ::lcl_MissProtectedFrames( pCnt, fnNxtPrv, true, bInReadOnly, bTableSel );
833  }
834  }
835 
836  //Otherwise I'll just refuse to leave to current area.
837  else if ( pCnt )
838  {
839  const SwFrame *pUp = pStart->GetUpper();
840  while (pUp && pUp->GetUpper() && !(pUp->GetType() & FRM_HEADFOOT))
841  pUp = pUp->GetUpper();
842  bool bSame = false;
843  const SwFrame *pCntUp = pCnt->GetUpper();
844  while ( pCntUp && !bSame )
845  {
846  if ( pUp == pCntUp )
847  bSame = true;
848  else
849  pCntUp = pCntUp->GetUpper();
850  }
851  if ( !bSame )
852  pCnt = nullptr;
853  else if (pCnt->IsTextFrame() && static_cast<const SwTextFrame*>(pCnt)->IsHiddenNow()) // i73332
854  {
855  pCnt = (*fnNxtPrv)( pCnt );
856  pCnt = ::lcl_MissProtectedFrames( pCnt, fnNxtPrv, true, bInReadOnly, bTableSel );
857  }
858  }
859 
860  if ( bTab )
861  {
862  if ( !pCnt )
863  bEnd = true;
864  else
865  {
866  const SwTabFrame *pTab = pCnt->FindTabFrame();
867  if( !pTab )
868  bEnd = true;
869  else
870  {
871  if ( pTab != pTable )
872  {
873  //The flow leads from one table to the next. The X-value
874  //needs to be corrected by the amount of the offset of
875  //the tables
876  if ( pTable &&
877  !pTab->GetUpper()->IsInTab() &&
878  !pTable->GetUpper()->IsInTab() )
879  nX += pTab->getFrameArea().Left() - pTable->getFrameArea().Left();
880  pTable = pTab;
881  }
882  const SwLayoutFrame *pCell = pCnt->GetUpper();
883  while ( pCell && !pCell->IsCellFrame() )
884  pCell = pCell->GetUpper();
885 
886  Point aInsideCell;
887  Point aInsideCnt;
888  if ( pCell )
889  {
890  long nTmpTop = aRectFnSet.GetTop(pCell->getFrameArea());
891  if ( aRectFnSet.IsVert() )
892  {
893  if ( nTmpTop )
894  nTmpTop = aRectFnSet.XInc(nTmpTop, -1);
895 
896  aInsideCell = Point( nTmpTop, nX );
897  }
898  else
899  aInsideCell = Point( nX, nTmpTop );
900  }
901 
902  long nTmpTop = aRectFnSet.GetTop(pCnt->getFrameArea());
903  if ( aRectFnSet.IsVert() )
904  {
905  if ( nTmpTop )
906  nTmpTop = aRectFnSet.XInc(nTmpTop, -1);
907 
908  aInsideCnt = Point( nTmpTop, nX );
909  }
910  else
911  aInsideCnt = Point( nX, nTmpTop );
912 
913  if ( pCell && pCell->getFrameArea().IsInside( aInsideCell ) )
914  {
915  bEnd = true;
916  //Get the right Content out of the cell.
917  if ( !pCnt->getFrameArea().IsInside( aInsideCnt ) )
918  {
919  pCnt = pCell->ContainsContent();
920  if ( fnNxtPrv == lcl_GetPrvCnt )
921  while ( pCell->IsAnLower(pCnt->GetNextContentFrame()) )
922  pCnt = pCnt->GetNextContentFrame();
923  }
924  }
925  else if ( pCnt->getFrameArea().IsInside( aInsideCnt ) )
926  bEnd = true;
927  }
928  }
929  if ( !bEnd )
930  {
931  pCnt = (*fnNxtPrv)( pCnt );
932  pCnt = ::lcl_MissProtectedFrames( pCnt, fnNxtPrv, true, bInReadOnly, bTableSel );
933  }
934  }
935 
936  } while ( !bEnd ||
937  (pCnt && pCnt->IsTextFrame() && static_cast<const SwTextFrame*>(pCnt)->IsHiddenNow()));
938 
939  if (pCnt == nullptr)
940  {
941  return false;
942  }
943  if (pCnt->IsTextFrame())
944  {
945  SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(pCnt));
946  *pPam->GetPoint() = pFrame->MapViewToModelPos(TextFrameIndex(
947  fnNxtPrv == lcl_GetPrvCnt
948  ? pFrame->GetText().getLength()
949  : 0));
950  }
951  else
952  { // set the Point on the Content-Node
953  assert(pCnt->IsNoTextFrame());
954  SwContentNode *const pCNd = const_cast<SwContentNode*>(static_cast<SwNoTextFrame const*>(pCnt)->GetNode());
955  pPam->GetPoint()->nNode = *pCNd;
956  if ( fnNxtPrv == lcl_GetPrvCnt )
957  pCNd->MakeEndIndex( &pPam->GetPoint()->nContent );
958  else
959  pCNd->MakeStartIndex( &pPam->GetPoint()->nContent );
960  }
961  return true;
962 }
963 
964 bool SwContentFrame::UnitUp( SwPaM* pPam, const SwTwips, bool bInReadOnly ) const
965 {
966  return ::lcl_UpDown( pPam, this, lcl_GetPrvCnt, bInReadOnly );
967 }
968 
969 bool SwContentFrame::UnitDown( SwPaM* pPam, const SwTwips, bool bInReadOnly ) const
970 {
971  return ::lcl_UpDown( pPam, this, lcl_GetNxtCnt, bInReadOnly );
972 }
973 
979 sal_uInt16 SwRootFrame::GetCurrPage( const SwPaM *pActualCursor ) const
980 {
981  OSL_ENSURE( pActualCursor, "got no page cursor" );
982  SwFrame const*const pActFrame = pActualCursor->GetPoint()->nNode.GetNode().
984  pActualCursor->GetPoint());
985  return pActFrame->FindPageFrame()->GetPhyPageNum();
986 }
987 
995 sal_uInt16 SwRootFrame::SetCurrPage( SwCursor* pToSet, sal_uInt16 nPageNum )
996 {
997  vcl::RenderContext* pRenderContext = GetCurrShell() ? GetCurrShell()->GetOut() : nullptr;
998  OSL_ENSURE( Lower() && Lower()->IsPageFrame(), "No page available." );
999 
1000  SwPageFrame *pPage = static_cast<SwPageFrame*>(Lower());
1001  bool bEnd =false;
1002  while ( !bEnd && pPage->GetPhyPageNum() != nPageNum )
1003  { if ( pPage->GetNext() )
1004  pPage = static_cast<SwPageFrame*>(pPage->GetNext());
1005  else
1006  { //Search the first ContentFrame and format until a new page is started
1007  //or until the ContentFrame are all done.
1008  const SwContentFrame *pContent = pPage->ContainsContent();
1009  while ( pContent && pPage->IsAnLower( pContent ) )
1010  {
1011  pContent->Calc(pRenderContext);
1012  pContent = pContent->GetNextContentFrame();
1013  }
1014  //Either this is a new page or we found the last page.
1015  if ( pPage->GetNext() )
1016  pPage = static_cast<SwPageFrame*>(pPage->GetNext());
1017  else
1018  bEnd = true;
1019  }
1020  }
1021  //pPage now points to the 'requested' page. Now we have to create the PaM
1022  //on the beginning of the first ContentFrame in the body-text.
1023  //If this is a footnote-page, the PaM will be set in the first footnote.
1024  const SwContentFrame *pContent = pPage->ContainsContent();
1025  if ( pPage->IsFootnotePage() )
1026  while ( pContent && !pContent->IsInFootnote() )
1027  pContent = pContent->GetNextContentFrame();
1028  else
1029  while ( pContent && !pContent->IsInDocBody() )
1030  pContent = pContent->GetNextContentFrame();
1031  if ( pContent )
1032  {
1033  assert(pContent->IsTextFrame());
1034  SwTextFrame const*const pFrame(static_cast<const SwTextFrame*>(pContent));
1035  *pToSet->GetPoint() = pFrame->MapViewToModelPos(pFrame->GetOffset());
1036 
1037  SwShellCursor* pSCursor = dynamic_cast<SwShellCursor*>(pToSet);
1038  if( pSCursor )
1039  {
1040  Point &rPt = pSCursor->GetPtPos();
1041  rPt = pContent->getFrameArea().Pos();
1042  rPt += pContent->getFramePrintArea().Pos();
1043  }
1044  return pPage->GetPhyPageNum();
1045  }
1046  return 0;
1047 }
1048 
1050 {
1051  return const_cast<SwPageFrame*>(static_cast<const SwPageFrame*>(pLayout))->FindFirstBodyContent();
1052 }
1053 
1055 {
1056  return const_cast<SwPageFrame*>(static_cast<const SwPageFrame*>(pLayout))->FindLastBodyContent();
1057 }
1058 
1060 {
1061  SwLayoutFrame *pNext =
1062  (pFrame->GetNext() && pFrame->GetNext()->IsLayoutFrame()) ?
1063  const_cast<SwLayoutFrame*>(static_cast<const SwLayoutFrame*>(pFrame->GetNext())) : nullptr;
1064  // #i39402# in case of an empty page
1065  if(pNext && !pNext->ContainsContent())
1066  pNext = (pNext->GetNext() && pNext->GetNext()->IsLayoutFrame()) ?
1067  static_cast<SwLayoutFrame*>(pNext->GetNext()) : nullptr;
1068  return pNext;
1069 }
1070 
1072 {
1073  return const_cast<SwLayoutFrame*>(pFrame);
1074 }
1075 
1077 {
1078  SwLayoutFrame *pPrev =
1079  (pFrame->GetPrev() && pFrame->GetPrev()->IsLayoutFrame()) ?
1080  const_cast<SwLayoutFrame*>(static_cast<const SwLayoutFrame*>(pFrame->GetPrev())) : nullptr;
1081  // #i39402# in case of an empty page
1082  if(pPrev && !pPrev->ContainsContent())
1083  pPrev = (pPrev->GetPrev() && pPrev->GetPrev()->IsLayoutFrame()) ?
1084  static_cast<SwLayoutFrame*>(pPrev->GetPrev()) : nullptr;
1085  return pPrev;
1086 }
1087 
1092 bool GetFrameInPage( const SwContentFrame *pCnt, SwWhichPage fnWhichPage,
1093  SwPosPage fnPosPage, SwPaM *pPam )
1094 {
1095  //First find the requested page, at first the current, then the one which
1096  //was requests through fnWichPage.
1097  const SwLayoutFrame *pLayoutFrame = pCnt->FindPageFrame();
1098  if ( !pLayoutFrame || (nullptr == (pLayoutFrame = (*fnWhichPage)(pLayoutFrame))) )
1099  return false;
1100 
1101  //Now the desired ContentFrame below the page
1102  pCnt = (*fnPosPage)(pLayoutFrame);
1103  if( nullptr == pCnt )
1104  return false;
1105  else
1106  {
1107  // repeated headlines in tables
1108  if ( pCnt->IsInTab() && fnPosPage == GetFirstSub )
1109  {
1110  const SwTabFrame* pTab = pCnt->FindTabFrame();
1111  if ( pTab->IsFollow() )
1112  {
1113  if ( pTab->IsInHeadline( *pCnt ) )
1114  {
1115  SwLayoutFrame* pRow = pTab->GetFirstNonHeadlineRow();
1116  if ( pRow )
1117  {
1118  // We are in the first line of a follow table
1119  // with repeated headings.
1120  // To actually make a "real" move we take the first content
1121  // of the next row
1122  pCnt = pRow->ContainsContent();
1123  if ( ! pCnt )
1124  return false;
1125  }
1126  }
1127  }
1128  }
1129 
1130  assert(pCnt->IsTextFrame());
1131  SwTextFrame const*const pFrame(static_cast<const SwTextFrame*>(pCnt));
1132  TextFrameIndex const nIdx((fnPosPage == GetFirstSub)
1133  ? pFrame->GetOffset()
1134  : (pFrame->GetFollow())
1135  ? pFrame->GetFollow()->GetOffset() - TextFrameIndex(1)
1136  : TextFrameIndex(pFrame->GetText().getLength()));
1137  *pPam->GetPoint() = pFrame->MapViewToModelPos(nIdx);
1138  return true;
1139  }
1140 }
1141 
1142 static sal_uInt64 CalcDiff(const Point &rPt1, const Point &rPt2)
1143 {
1144  //Calculate the distance between the two points.
1145  //'delta' X^2 + 'delta'Y^2 = 'distance'^2
1146  sal_uInt64 dX = std::max( rPt1.X(), rPt2.X() ) -
1147  std::min( rPt1.X(), rPt2.X() ),
1148  dY = std::max( rPt1.Y(), rPt2.Y() ) -
1149  std::min( rPt1.Y(), rPt2.Y() );
1150  return (dX * dX) + (dY * dY);
1151 }
1152 
1159 static const SwLayoutFrame* lcl_Inside( const SwContentFrame *pCnt, Point const & rPt )
1160 {
1161  const SwLayoutFrame* pUp = pCnt->GetUpper();
1162  while( pUp )
1163  {
1164  if( pUp->IsPageBodyFrame() || pUp->IsFooterFrame() || pUp->IsHeaderFrame() )
1165  {
1166  if( rPt.Y() >= pUp->getFrameArea().Top() && rPt.Y() <= pUp->getFrameArea().Bottom() )
1167  return pUp;
1168  return nullptr;
1169  }
1170  if( pUp->IsFootnoteContFrame() )
1171  return pUp->getFrameArea().IsInside( rPt ) ? pUp : nullptr;
1172  pUp = pUp->GetUpper();
1173  }
1174  return nullptr;
1175 }
1176 
1185  const bool bDontLeave,
1186  const bool bBodyOnly,
1187  SwCursorMoveState *pCMS,
1188  const bool bDefaultExpand ) const
1189 {
1190  //Determine the first ContentFrame.
1191  const SwLayoutFrame *pStart = (!bDontLeave && bDefaultExpand && GetPrev()) ?
1192  static_cast<const SwLayoutFrame*>(GetPrev()) : this;
1193  const SwContentFrame *pContent = pStart->ContainsContent();
1194 
1195  if ( !pContent && (GetPrev() && !bDontLeave) )
1196  pContent = ContainsContent();
1197 
1198  if ( bBodyOnly && pContent && !pContent->IsInDocBody() )
1199  while ( pContent && !pContent->IsInDocBody() )
1200  pContent = pContent->GetNextContentFrame();
1201 
1202  const SwContentFrame *pActual= pContent;
1203  const SwLayoutFrame *pInside = nullptr;
1204  sal_uInt16 nMaxPage = GetPhyPageNum() + (bDefaultExpand ? 1 : 0);
1205  Point aPoint = rPoint;
1206  sal_uInt64 nDistance = SAL_MAX_UINT64;
1207 
1208  while ( true ) //A loop to be sure we always find one.
1209  {
1210  while ( pContent &&
1211  ((!bDontLeave || IsAnLower( pContent )) &&
1212  (pContent->GetPhyPageNum() <= nMaxPage)) )
1213  {
1214  if ( pContent->getFrameArea().Width() &&
1215  ( !bBodyOnly || pContent->IsInDocBody() ) )
1216  {
1217  //If the Content lies in a protected area (cell, Footnote, section),
1218  //we search the next Content which is not protected.
1219  const SwContentFrame *pComp = pContent;
1220  pContent = ::lcl_MissProtectedFrames( pContent, lcl_GetNxtCnt, false,
1221  pCMS && pCMS->m_bSetInReadOnly, false );
1222  if ( pComp != pContent )
1223  continue;
1224 
1225  if ( !pContent->IsTextFrame() || !static_cast<const SwTextFrame*>(pContent)->IsHiddenNow() )
1226  {
1227  SwRect aContentFrame( pContent->UnionFrame() );
1228  if ( aContentFrame.IsInside( rPoint ) )
1229  {
1230  pActual = pContent;
1231  aPoint = rPoint;
1232  break;
1233  }
1234  //The distance from rPoint to the nearest Point of pContent
1235  //will now be calculated.
1236  Point aContentPoint( rPoint );
1237 
1238  //First set the vertical position
1239  if ( aContentFrame.Top() > aContentPoint.Y() )
1240  aContentPoint.setY( aContentFrame.Top() );
1241  else if ( aContentFrame.Bottom() < aContentPoint.Y() )
1242  aContentPoint.setY( aContentFrame.Bottom() );
1243 
1244  //Now the horizontal position
1245  if ( aContentFrame.Left() > aContentPoint.X() )
1246  aContentPoint.setX( aContentFrame.Left() );
1247  else if ( aContentFrame.Right() < aContentPoint.X() )
1248  aContentPoint.setX( aContentFrame.Right() );
1249 
1250  // pInside is a page area in which the point lies. As soon
1251  // as pInside != 0 only frames are accepted which are
1252  // placed inside.
1253  if( !pInside || ( pInside->IsAnLower( pContent ) &&
1254  ( !pContent->IsInFootnote() || pInside->IsFootnoteContFrame() ) ) )
1255  {
1256  const sal_uInt64 nDiff = ::CalcDiff(aContentPoint, rPoint);
1257  bool bBetter = nDiff < nDistance; // This one is nearer
1258  if( !pInside )
1259  {
1260  pInside = lcl_Inside( pContent, rPoint );
1261  if( pInside ) // In the "right" page area
1262  bBetter = true;
1263  }
1264  if( bBetter )
1265  {
1266  aPoint = aContentPoint;
1267  nDistance = nDiff;
1268  pActual = pContent;
1269  }
1270  }
1271  }
1272  }
1273  pContent = pContent->GetNextContentFrame();
1274  if ( bBodyOnly )
1275  while ( pContent && !pContent->IsInDocBody() )
1276  pContent = pContent->GetNextContentFrame();
1277  }
1278  if ( !pActual )
1279  { //If we not yet found one we have to expand the searched
1280  //area, sometime we will find one!
1281  //MA 1997-01-09: Opt for many empty pages - if we only search inside
1282  //the body, we can expand the searched area sufficiently in one step.
1283  if ( bBodyOnly )
1284  {
1285  while ( !pContent && pStart->GetPrev() )
1286  {
1287  ++nMaxPage;
1288  if( !pStart->GetPrev()->IsLayoutFrame() )
1289  return nullptr;
1290  pStart = static_cast<const SwLayoutFrame*>(pStart->GetPrev());
1291  pContent = pStart->IsInDocBody()
1292  ? pStart->ContainsContent()
1293  : pStart->FindPageFrame()->FindFirstBodyContent();
1294  }
1295  if ( !pContent ) // Somewhere down the road we have to start with one!
1296  {
1297  pContent = pStart->FindPageFrame()->GetUpper()->ContainsContent();
1298  while ( pContent && !pContent->IsInDocBody() )
1299  pContent = pContent->GetNextContentFrame();
1300  if ( !pContent )
1301  return nullptr; // There is no document content yet!
1302  }
1303  }
1304  else
1305  {
1306  ++nMaxPage;
1307  if ( pStart->GetPrev() )
1308  {
1309  if( !pStart->GetPrev()->IsLayoutFrame() )
1310  return nullptr;
1311  pStart = static_cast<const SwLayoutFrame*>(pStart->GetPrev());
1312  pContent = pStart->ContainsContent();
1313  }
1314  else // Somewhere down the road we have to start with one!
1315  pContent = pStart->FindPageFrame()->GetUpper()->ContainsContent();
1316  }
1317  pActual = pContent;
1318  }
1319  else
1320  break;
1321  }
1322 
1323  OSL_ENSURE( pActual, "no Content found." );
1324  OSL_ENSURE( !bBodyOnly || pActual->IsInDocBody(), "Content not in Body." );
1325 
1326  //Special case for selecting tables not in repeated TableHeadlines.
1327  if ( pActual->IsInTab() && pCMS && pCMS->m_eState == CursorMoveState::TableSel )
1328  {
1329  const SwTabFrame *pTab = pActual->FindTabFrame();
1330  if ( pTab->IsFollow() && pTab->IsInHeadline( *pActual ) )
1331  {
1332  pCMS->m_bStop = true;
1333  return nullptr;
1334  }
1335  }
1336 
1337  //A small correction at the first/last
1338  Size aActualSize( pActual->getFramePrintArea().SSize() );
1339  if ( aActualSize.Height() > pActual->GetUpper()->getFramePrintArea().Height() )
1340  aActualSize.setHeight( pActual->GetUpper()->getFramePrintArea().Height() );
1341 
1342  SwRectFnSet aRectFnSet(pActual);
1343  if ( !pActual->GetPrev() &&
1344  aRectFnSet.YDiff( aRectFnSet.GetPrtTop(*pActual),
1345  aRectFnSet.IsVert() ? rPoint.X() : rPoint.Y() ) > 0 )
1346  {
1347  aPoint.setY( pActual->getFrameArea().Top() + pActual->getFramePrintArea().Top() );
1348  aPoint.setX( pActual->getFrameArea().Left() +
1349  ( pActual->IsRightToLeft() || aRectFnSet.IsVert() ?
1350  pActual->getFramePrintArea().Right() :
1351  pActual->getFramePrintArea().Left() ) );
1352  }
1353  else if ( !pActual->GetNext() &&
1354  aRectFnSet.YDiff( aRectFnSet.GetPrtBottom(*pActual),
1355  aRectFnSet.IsVert() ? rPoint.X() : rPoint.Y() ) < 0 )
1356  {
1357  aPoint.setY( pActual->getFrameArea().Top() + pActual->getFramePrintArea().Bottom() );
1358  aPoint.setX( pActual->getFrameArea().Left() +
1359  ( pActual->IsRightToLeft() || aRectFnSet.IsVert() ?
1360  pActual->getFramePrintArea().Left() :
1361  pActual->getFramePrintArea().Right() ) );
1362  }
1363 
1364  //Bring the Point into the PrtArea
1365  const SwRect aRect( pActual->getFrameArea().Pos() + pActual->getFramePrintArea().Pos(),
1366  aActualSize );
1367  if ( aPoint.Y() < aRect.Top() )
1368  aPoint.setY( aRect.Top() );
1369  else if ( aPoint.Y() > aRect.Bottom() )
1370  aPoint.setY( aRect.Bottom() );
1371  if ( aPoint.X() < aRect.Left() )
1372  aPoint.setX( aRect.Left() );
1373  else if ( aPoint.X() > aRect.Right() )
1374  aPoint.setX( aRect.Right() );
1375  rPoint = aPoint;
1376  return pActual;
1377 }
1378 
1380 void SwPageFrame::GetContentPosition( const Point &rPt, SwPosition &rPos ) const
1381 {
1382  //Determine the first ContentFrame.
1384  if ( pContent )
1385  {
1386  //Look back one more (if possible).
1387  const SwContentFrame *pTmp = pContent->GetPrevContentFrame();
1388  while ( pTmp && !pTmp->IsInDocBody() )
1389  pTmp = pTmp->GetPrevContentFrame();
1390  if ( pTmp )
1391  pContent = pTmp;
1392  }
1393  else
1394  pContent = GetUpper()->ContainsContent();
1395 
1396  const SwContentFrame *pAct = pContent;
1397  Point aAct = rPt;
1398  sal_uInt64 nDist = SAL_MAX_UINT64;
1399 
1400  while ( pContent )
1401  {
1402  SwRect aContentFrame( pContent->UnionFrame() );
1403  if ( aContentFrame.IsInside( rPt ) )
1404  {
1405  //This is the nearest one.
1406  pAct = pContent;
1407  break;
1408  }
1409 
1410  //Calculate the distance from rPt to the nearest point of pContent.
1411  Point aPoint( rPt );
1412 
1413  //Calculate the vertical position first
1414  if ( aContentFrame.Top() > rPt.Y() )
1415  aPoint.setY( aContentFrame.Top() );
1416  else if ( aContentFrame.Bottom() < rPt.Y() )
1417  aPoint.setY( aContentFrame.Bottom() );
1418 
1419  //And now the horizontal position
1420  if ( aContentFrame.Left() > rPt.X() )
1421  aPoint.setX( aContentFrame.Left() );
1422  else if ( aContentFrame.Right() < rPt.X() )
1423  aPoint.setX( aContentFrame.Right() );
1424 
1425  const sal_uInt64 nDiff = ::CalcDiff( aPoint, rPt );
1426  if ( nDiff < nDist )
1427  {
1428  aAct = aPoint;
1429  nDist = nDiff;
1430  pAct = pContent;
1431  }
1432  else if ( aContentFrame.Top() > getFrameArea().Bottom() )
1433  //In terms of fields, it's not possible to be closer any more!
1434  break;
1435 
1436  pContent = pContent->GetNextContentFrame();
1437  while ( pContent && !pContent->IsInDocBody() )
1438  pContent = pContent->GetNextContentFrame();
1439  }
1440 
1441  //Bring the point into the PrtArea.
1442  const SwRect aRect( pAct->getFrameArea().Pos() + pAct->getFramePrintArea().Pos(), pAct->getFramePrintArea().SSize() );
1443  if ( aAct.Y() < aRect.Top() )
1444  aAct.setY( aRect.Top() );
1445  else if ( aAct.Y() > aRect.Bottom() )
1446  aAct.setY( aRect.Bottom() );
1447  if ( aAct.X() < aRect.Left() )
1448  aAct.setX( aRect.Left() );
1449  else if ( aAct.X() > aRect.Right() )
1450  aAct.setX( aRect.Right() );
1451 
1452  if (!pAct->isFrameAreaDefinitionValid() ||
1453  (pAct->IsTextFrame() && !static_cast<SwTextFrame const*>(pAct)->HasPara()))
1454  {
1455  // ContentFrame not formatted -> always on node-beginning
1456  // tdf#100635 also if the SwTextFrame would require reformatting,
1457  // which is unwanted in case this is called from text formatting code
1458  rPos = static_cast<SwTextFrame const*>(pAct)->MapViewToModelPos(TextFrameIndex(0));
1459  }
1460  else
1461  {
1463  pAct->GetModelPositionForViewPoint( &rPos, aAct, &aTmpState );
1464  }
1465 }
1466 
1473 Point SwRootFrame::GetNextPrevContentPos( const Point& rPoint, bool bNext ) const
1474 {
1475  vcl::RenderContext* pRenderContext = GetCurrShell() ? GetCurrShell()->GetOut() : nullptr;
1476  // #123110# - disable creation of an action by a callback
1477  // event during processing of this method. Needed because formatting is
1478  // triggered by this method.
1479  DisableCallbackAction aDisableCallbackAction(const_cast<SwRootFrame&>(*this));
1480  //Search the first ContentFrame and his successor in the body area.
1481  //To be efficient (and not formatting too much) we'll start at the correct
1482  //page.
1483  const SwLayoutFrame *pPage = static_cast<const SwLayoutFrame*>(Lower());
1484  if( pPage )
1485  while( pPage->GetNext() && pPage->getFrameArea().Bottom() < rPoint.Y() )
1486  pPage = static_cast<const SwLayoutFrame*>(pPage->GetNext());
1487 
1488  const SwContentFrame *pCnt = pPage ? pPage->ContainsContent() : ContainsContent();
1489  while ( pCnt && !pCnt->IsInDocBody() )
1490  pCnt = pCnt->GetNextContentFrame();
1491 
1492  if ( !pCnt )
1493  return Point( 0, 0 );
1494 
1495  pCnt->Calc(pRenderContext);
1496  if( !bNext )
1497  {
1498  // As long as the point lies before the first ContentFrame and there are
1499  // still precedent pages I'll go to the next page.
1500  while ( rPoint.Y() < pCnt->getFrameArea().Top() && pPage->GetPrev() )
1501  {
1502  pPage = static_cast<const SwLayoutFrame*>(pPage->GetPrev());
1503  pCnt = pPage->ContainsContent();
1504  while ( !pCnt )
1505  {
1506  pPage = static_cast<const SwLayoutFrame*>(pPage->GetPrev());
1507  if ( pPage )
1508  pCnt = pPage->ContainsContent();
1509  else
1510  return ContainsContent()->UnionFrame().Pos();
1511  }
1512  pCnt->Calc(pRenderContext);
1513  }
1514  }
1515 
1516  //Does the point lie above the first ContentFrame?
1517  if ( rPoint.Y() < pCnt->getFrameArea().Top() && !lcl_IsInRepeatedHeadline( pCnt ) )
1518  return pCnt->UnionFrame().Pos();
1519 
1520  Point aRet(0, 0);
1521  do
1522  {
1523  //Does the point lie in the current ContentFrame?
1524  SwRect aContentFrame( pCnt->UnionFrame() );
1525  if ( aContentFrame.IsInside( rPoint ) && !lcl_IsInRepeatedHeadline( pCnt ))
1526  {
1527  aRet = rPoint;
1528  break;
1529  }
1530 
1531  //Is the current one the last ContentFrame?
1532  //If the next ContentFrame lies behind the point, then the current on is the
1533  //one we searched.
1534  const SwContentFrame *pNxt = pCnt->GetNextContentFrame();
1535  while ( pNxt && !pNxt->IsInDocBody() )
1536  pNxt = pNxt->GetNextContentFrame();
1537 
1538  //Does the point lie behind the last ContentFrame?
1539  if ( !pNxt )
1540  {
1541  aRet = Point( aContentFrame.Right(), aContentFrame.Bottom() );
1542  break;
1543  }
1544 
1545  //If the next ContentFrame lies behind the point then it is the one we
1546  //searched.
1547  const SwTabFrame* pTFrame;
1548  pNxt->Calc(pRenderContext);
1549  if( pNxt->getFrameArea().Top() > rPoint.Y() &&
1550  !lcl_IsInRepeatedHeadline( pCnt, &pTFrame ) &&
1551  ( !pTFrame || pNxt->getFrameArea().Left() > rPoint.X() ))
1552  {
1553  if (bNext)
1554  aRet = pNxt->getFrameArea().Pos();
1555  else
1556  aRet = Point( aContentFrame.Right(), aContentFrame.Bottom() );
1557  break;
1558  }
1559  pCnt = pNxt;
1560  }
1561  while (pCnt);
1562  return aRet;
1563 }
1564 
1572 Point SwRootFrame::GetPagePos( sal_uInt16 nPageNum ) const
1573 {
1574  OSL_ENSURE( Lower() && Lower()->IsPageFrame(), "No page available." );
1575 
1576  const SwPageFrame *pPage = static_cast<const SwPageFrame*>(Lower());
1577  while ( true )
1578  {
1579  if ( pPage->GetPhyPageNum() >= nPageNum || !pPage->GetNext() )
1580  break;
1581  pPage = static_cast<const SwPageFrame*>(pPage->GetNext());
1582  }
1583  return pPage->getFrameArea().Pos();
1584 }
1585 
1590 SwPageFrame* SwRootFrame::GetPageByPageNum( sal_uInt16 _nPageNum ) const
1591 {
1592  const SwPageFrame* pPageFrame = static_cast<const SwPageFrame*>( Lower() );
1593  while ( pPageFrame && pPageFrame->GetPhyPageNum() < _nPageNum )
1594  {
1595  pPageFrame = static_cast<const SwPageFrame*>( pPageFrame->GetNext() );
1596  }
1597 
1598  if ( pPageFrame && pPageFrame->GetPhyPageNum() == _nPageNum )
1599  {
1600  return const_cast<SwPageFrame*>( pPageFrame );
1601  }
1602  else
1603  {
1604  return nullptr;
1605  }
1606 }
1607 
1611 bool SwRootFrame::IsDummyPage( sal_uInt16 nPageNum ) const
1612 {
1613  if( !Lower() || !nPageNum || nPageNum > GetPageNum() )
1614  return true;
1615 
1616  const SwPageFrame *pPage = static_cast<const SwPageFrame*>(Lower());
1617  while( pPage && nPageNum < pPage->GetPhyPageNum() )
1618  pPage = static_cast<const SwPageFrame*>(pPage->GetNext());
1619  return !pPage || pPage->IsEmptyPage();
1620 }
1621 
1627 {
1628  if (IsTextFrame())
1629  {
1630  const SwDoc *pDoc = &static_cast<const SwTextFrame*>(this)->GetDoc();
1631  bool isFormProtected=pDoc->GetDocumentSettingManager().get(DocumentSettingId::PROTECT_FORM );
1632  if (isFormProtected)
1633  {
1634  return false; // TODO a hack for now, well deal with it later, I we return true here we have a "double" locking
1635  }
1636  }
1637  //The Frame can be protected in borders, cells or sections.
1638  //Also goes up FlyFrames recursive and from footnote to anchor.
1639  const SwFrame *pFrame = this;
1640  do
1641  {
1642  if (pFrame->IsTextFrame())
1643  { // sw_redlinehide: redlines can't overlap section nodes, so any node will do
1644  if (static_cast<SwTextFrame const*>(pFrame)->GetTextNodeFirst()->IsInProtectSect())
1645  {
1646  return true;
1647  }
1648  }
1649  else if ( pFrame->IsContentFrame() )
1650  {
1651  assert(pFrame->IsNoTextFrame());
1652  if (static_cast<const SwNoTextFrame*>(pFrame)->GetNode() &&
1653  static_cast<const SwNoTextFrame*>(pFrame)->GetNode()->IsInProtectSect())
1654  {
1655  return true;
1656  }
1657  }
1658  else
1659  {
1660  if ( static_cast<const SwLayoutFrame*>(pFrame)->GetFormat() &&
1661  static_cast<const SwLayoutFrame*>(pFrame)->GetFormat()->
1662  GetProtect().IsContentProtected() )
1663  return true;
1664  if ( pFrame->IsCoveredCell() )
1665  return true;
1666  }
1667  if ( pFrame->IsFlyFrame() )
1668  {
1669  //In a chain the protection of the content can be specified by the
1670  //master of the chain.
1671  if ( static_cast<const SwFlyFrame*>(pFrame)->GetPrevLink() )
1672  {
1673  const SwFlyFrame *pMaster = static_cast<const SwFlyFrame*>(pFrame);
1674  do
1675  { pMaster = pMaster->GetPrevLink();
1676  } while ( pMaster->GetPrevLink() );
1677  if ( pMaster->IsProtected() )
1678  return true;
1679  }
1680  pFrame = static_cast<const SwFlyFrame*>(pFrame)->GetAnchorFrame();
1681  }
1682  else if ( pFrame->IsFootnoteFrame() )
1683  pFrame = static_cast<const SwFootnoteFrame*>(pFrame)->GetRef();
1684  else
1685  pFrame = pFrame->GetUpper();
1686 
1687  } while ( pFrame );
1688 
1689  return false;
1690 }
1691 
1693 sal_uInt16 SwFrame::GetPhyPageNum() const
1694 {
1695  const SwPageFrame *pPage = FindPageFrame();
1696  return pPage ? pPage->GetPhyPageNum() : 0;
1697 }
1698 
1713 {
1714  const SwPageFrame *pPage = FindPageFrame();
1715  if ( !pPage || !pPage->GetUpper() )
1716  return true;
1717 
1718  const SwFrame *pFlow = pPage->FindFirstBodyContent();
1719  const SwPageDesc *pDesc = nullptr;
1720  ::std::optional<sal_uInt16> oPgNum;
1721  if ( pFlow )
1722  {
1723  if ( pFlow->IsInTab() )
1724  pFlow = pFlow->FindTabFrame();
1725  const SwFlowFrame *pTmp = SwFlowFrame::CastFlowFrame( pFlow );
1726  if ( !pTmp->IsFollow() )
1727  {
1728  const SwFormatPageDesc& rPgDesc = pFlow->GetPageDescItem();
1729  pDesc = rPgDesc.GetPageDesc();
1730  oPgNum = rPgDesc.GetNumOffset();
1731  }
1732  }
1733  if ( !pDesc )
1734  {
1735  SwPageFrame *pPrv = const_cast<SwPageFrame*>(static_cast<const SwPageFrame*>(pPage->GetPrev()));
1736  if( pPrv && pPrv->IsEmptyPage() )
1737  pPrv = static_cast<SwPageFrame*>(pPrv->GetPrev());
1738  if( pPrv )
1739  pDesc = pPrv->GetPageDesc()->GetFollow();
1740  else
1741  {
1742  const SwDoc* pDoc = pPage->GetFormat()->GetDoc();
1743  pDesc = &pDoc->GetPageDesc( 0 );
1744  }
1745  }
1746  OSL_ENSURE( pDesc, "No pagedescriptor" );
1747  bool isRightPage;
1748  if( oPgNum )
1749  isRightPage = sw::IsRightPageByNumber(*mpRoot, *oPgNum);
1750  else
1751  {
1752  isRightPage = pPage->OnRightPage();
1753  if( pPage->GetPrev() && static_cast<const SwPageFrame*>(pPage->GetPrev())->IsEmptyPage() )
1754  isRightPage = !isRightPage;
1755  }
1756  if( !pPage->IsEmptyPage() )
1757  {
1758  if( !pDesc->GetRightFormat() )
1759  isRightPage = false;
1760  else if( !pDesc->GetLeftFormat() )
1761  isRightPage = true;
1762  }
1763  return isRightPage;
1764 }
1765 
1767 {
1768  bool bRet = false;
1769  const SwPageFrame *pPage = FindPageFrame();
1770 
1771  if (pPage)
1772  {
1773  const SwPageFrame* pPrevFrame = dynamic_cast<const SwPageFrame*>(pPage->GetPrev());
1774  if (pPrevFrame)
1775  {
1776  // first page of layout may be empty page, but only if it starts with "Left Page" style
1777  const SwPageDesc* pDesc = pPage->GetPageDesc();
1778  bRet = pPrevFrame->GetPageDesc() != pDesc;
1779  }
1780  else
1781  bRet = true;
1782  }
1783  return bRet;
1784 }
1785 
1786 void SwFrame::Calc(vcl::RenderContext* pRenderContext) const
1787 {
1789  {
1790  const_cast<SwFrame*>(this)->PrepareMake(pRenderContext);
1791  }
1792 }
1793 
1795 {
1796  Point aRet( getFrameArea().Pos() );
1797  // here we cast since SwLayoutFrame is declared only as forwarded
1798  aRet -= GetUpper()->getFramePrintArea().Pos();
1799  aRet -= GetUpper()->getFrameArea().Pos();
1800  return aRet;
1801 }
1802 
1804 sal_uInt16 SwFrame::GetVirtPageNum() const
1805 {
1806  const SwPageFrame *pPage = FindPageFrame();
1807  if ( !pPage || !pPage->GetUpper() )
1808  return 0;
1809 
1810  sal_uInt16 nPhyPage = pPage->GetPhyPageNum();
1811  if ( !static_cast<const SwRootFrame*>(pPage->GetUpper())->IsVirtPageNum() )
1812  return nPhyPage;
1813 
1814  //Search the nearest section using the virtual page number.
1815  //Because searching backwards needs a lot of time we search specific using
1816  //the dependencies. From the PageDescs we get the attributes and from the
1817  //attributes we get the sections.
1818  const SwPageFrame *pVirtPage = nullptr;
1819  const SwFrame *pFrame = nullptr;
1820  const SfxItemPool &rPool = pPage->GetFormat()->GetDoc()->GetAttrPool();
1821  for (const SfxPoolItem* pItem : rPool.GetItemSurrogates(RES_PAGEDESC))
1822  {
1823  const SwFormatPageDesc *pDesc = dynamic_cast<const SwFormatPageDesc*>(pItem);
1824  if ( !pDesc )
1825  continue;
1826 
1827  if ( pDesc->GetNumOffset() && pDesc->GetDefinedIn() )
1828  {
1829  const SwModify *pMod = pDesc->GetDefinedIn();
1830  SwVirtPageNumInfo aInfo( pPage );
1831  pMod->GetInfo( aInfo );
1832  if ( aInfo.GetPage() )
1833  {
1834  if( !pVirtPage || aInfo.GetPage()->GetPhyPageNum() > pVirtPage->GetPhyPageNum() )
1835  {
1836  pVirtPage = aInfo.GetPage();
1837  pFrame = aInfo.GetFrame();
1838  }
1839  }
1840  }
1841  }
1842  if ( pFrame )
1843  {
1844  ::std::optional<sal_uInt16> oNumOffset = pFrame->GetPageDescItem().GetNumOffset();
1845  if (oNumOffset)
1846  {
1847  return nPhyPage - pFrame->GetPhyPageNum() + *oNumOffset;
1848  }
1849  else
1850  {
1851  return nPhyPage - pFrame->GetPhyPageNum();
1852  }
1853  }
1854  return nPhyPage;
1855 }
1856 
1859 {
1860  //Find Union-Rects and tables (Follows) of the selection.
1861  OSL_ENSURE( rTableCursor.GetContentNode() && rTableCursor.GetContentNode( false ),
1862  "Tabselection not on Cnt." );
1863 
1864  bool bRet = false;
1865 
1866  // For new table models there's no need to ask the layout...
1867  if( rTableCursor.NewTableSelection() )
1868  return true;
1869 
1870  Point aPtPt, aMkPt;
1871  {
1872  SwShellCursor* pShCursor = dynamic_cast<SwShellCursor*>(&rTableCursor);
1873 
1874  if( pShCursor )
1875  {
1876  aPtPt = pShCursor->GetPtPos();
1877  aMkPt = pShCursor->GetMkPos();
1878  }
1879  }
1880 
1881  // #151012# Made code robust here
1882  const SwContentNode* pTmpStartNode = rTableCursor.GetContentNode();
1883  const SwContentNode* pTmpEndNode = rTableCursor.GetContentNode(false);
1884 
1885  std::pair<Point, bool> tmp(aPtPt, false);
1886  const SwFrame *const pTmpStartFrame = pTmpStartNode ? pTmpStartNode->getLayoutFrame(this, nullptr, &tmp) : nullptr;
1887  tmp.first = aMkPt;
1888  const SwFrame *const pTmpEndFrame = pTmpEndNode ? pTmpEndNode->getLayoutFrame(this, nullptr, &tmp) : nullptr;
1889 
1890  const SwLayoutFrame* pStart = pTmpStartFrame ? pTmpStartFrame->GetUpper() : nullptr;
1891  const SwLayoutFrame* pEnd = pTmpEndFrame ? pTmpEndFrame->GetUpper() : nullptr;
1892 
1893  OSL_ENSURE( pStart && pEnd, "MakeTableCursors: Good to have the code robust here!" );
1894 
1895  /* #109590# Only change table boxes if the frames are
1896  valid. Needed because otherwise the table cursor after moving
1897  table cells by dnd resulted in an empty tables cursor. */
1898  if ( pStart && pEnd && pStart->isFrameAreaDefinitionValid() && pEnd->isFrameAreaDefinitionValid())
1899  {
1900  SwSelUnions aUnions;
1901  ::MakeSelUnions( aUnions, pStart, pEnd );
1902 
1903  SwSelBoxes aNew;
1904 
1905  const bool bReadOnlyAvailable = rTableCursor.IsReadOnlyAvailable();
1906 
1907  for (SwSelUnion & rUnion : aUnions)
1908  {
1909  const SwTabFrame *pTable = rUnion.GetTable();
1910 
1911  // Skip any repeated headlines in the follow:
1912  SwLayoutFrame* pRow = pTable->IsFollow() ?
1913  pTable->GetFirstNonHeadlineRow() :
1914  const_cast<SwLayoutFrame*>(static_cast<const SwLayoutFrame*>(pTable->Lower()));
1915 
1916  while ( pRow )
1917  {
1918  if ( pRow->getFrameArea().IsOver( rUnion.GetUnion() ) )
1919  {
1920  const SwLayoutFrame *pCell = pRow->FirstCell();
1921 
1922  while ( pCell && pRow->IsAnLower( pCell ) )
1923  {
1924  OSL_ENSURE( pCell->IsCellFrame(), "Frame without cell" );
1925  if( IsFrameInTableSel( rUnion.GetUnion(), pCell ) &&
1926  (bReadOnlyAvailable ||
1927  !pCell->GetFormat()->GetProtect().IsContentProtected()))
1928  {
1929  SwTableBox* pInsBox = const_cast<SwTableBox*>(
1930  static_cast<const SwCellFrame*>(pCell)->GetTabBox());
1931  aNew.insert( pInsBox );
1932  }
1933  if ( pCell->GetNext() )
1934  {
1935  pCell = static_cast<const SwLayoutFrame*>(pCell->GetNext());
1936  if ( pCell->Lower() && pCell->Lower()->IsRowFrame() )
1937  pCell = pCell->FirstCell();
1938  }
1939  else
1940  {
1941  const SwLayoutFrame* pLastCell = pCell;
1942  do
1943  {
1944  pCell = pCell->GetNextLayoutLeaf();
1945  } while ( pCell && pLastCell->IsAnLower( pCell ) );
1946  // For sections with columns
1947  if( pCell && pCell->IsInTab() )
1948  {
1949  while( !pCell->IsCellFrame() )
1950  {
1951  pCell = pCell->GetUpper();
1952  OSL_ENSURE( pCell, "Where's my cell?" );
1953  }
1954  }
1955  }
1956  }
1957  }
1958  pRow = static_cast<SwLayoutFrame*>(pRow->GetNext());
1959  }
1960  }
1961 
1962  rTableCursor.ActualizeSelection( aNew );
1963  bRet = true;
1964  }
1965 
1966  return bRet;
1967 }
1968 
1969 static void Sub( SwRegionRects& rRegion, const SwRect& rRect )
1970 {
1971  if( rRect.Width() > 1 && rRect.Height() > 1 &&
1972  rRect.IsOver( rRegion.GetOrigin() ))
1973  rRegion -= rRect;
1974 }
1975 
1976 static void Add( SwRegionRects& rRegion, const SwRect& rRect )
1977 {
1978  if( rRect.Width() > 1 && rRect.Height() > 1 )
1979  rRegion += rRect;
1980 }
1981 
1982 /*
1983  * The following situations can happen:
1984  * 1. Start and end lie in one screen-row and in the same node
1985  * -> one rectangle out of start and end; and we're okay
1986  * 2. Start and end lie in one frame (therefore in the same node!)
1987  * -> expand start to the right, end to the left and if more than two
1988  * screen-rows are involved - calculate the in-between
1989  * 3. Start and end lie in different frames
1990  * -> expand start to the right until frame-end, calculate Rect
1991  * expand end to the left until frame-start, calculate Rect
1992  * and if more than two frames are involved add the PrtArea of all
1993  * frames which lie in between
1994  *
1995  * Big reorganization because of the FlyFrame - those need to be locked out.
1996  * Exceptions: - The Fly in which the selection took place (if it took place
1997  * in a Fly)
1998  * - The Flys which are underrun by the text
1999  * - The Flys which are anchored to somewhere inside the selection.
2000  * Functioning: First a SwRegion with a root gets initialized.
2001  * Out of the region the inverted sections are cut out. The
2002  * section gets compressed and finally inverted and thereby the
2003  * inverted rectangles are available.
2004  * In the end the Flys are cut out of the section.
2005  */
2007 {
2008  SwPosition *pStartPos = rCursor.Start(),
2009  *pEndPos = rCursor.GetPoint() == pStartPos ? rCursor.GetMark() : rCursor.GetPoint();
2010 
2011  SwViewShell *pSh = GetCurrShell();
2012 
2013  bool bIgnoreVisArea = true;
2014  if (pSh)
2015  bIgnoreVisArea = pSh->GetViewOptions()->IsPDFExport() || comphelper::LibreOfficeKit::isActive();
2016 
2017  // #i12836# enhanced pdf
2018  SwRegionRects aRegion( !bIgnoreVisArea ?
2019  pSh->VisArea() :
2020  getFrameArea() );
2021  if( !pStartPos->nNode.GetNode().IsContentNode() ||
2022  !pStartPos->nNode.GetNode().GetContentNode()->getLayoutFrame(this) ||
2023  ( pStartPos->nNode != pEndPos->nNode &&
2024  ( !pEndPos->nNode.GetNode().IsContentNode() ||
2025  !pEndPos->nNode.GetNode().GetContentNode()->getLayoutFrame(this) ) ) )
2026  {
2027  return;
2028  }
2029 
2030  DisableCallbackAction a(*this); // the GetCharRect below may format
2031 
2032  //First obtain the ContentFrames for the start and the end - those are needed
2033  //anyway.
2034  std::pair<Point, bool> tmp(rCursor.GetSttPos(), true);
2035  SwContentFrame* pStartFrame = pStartPos->nNode.GetNode().
2036  GetContentNode()->getLayoutFrame(this, pStartPos, &tmp);
2037 
2038  tmp.first = rCursor.GetEndPos();
2039  SwContentFrame* pEndFrame = pEndPos->nNode.GetNode().
2040  GetContentNode()->getLayoutFrame(this, pEndPos, &tmp);
2041 
2042  assert(pStartFrame && pEndFrame && "No ContentFrames found.");
2043  //tdf#119224 start and end are expected to exist for the scope of this function
2044  SwFrameDeleteGuard aStartFrameGuard(pStartFrame), aEndFrameGuard(pEndFrame);
2045 
2046  //Do not subtract the FlyFrames in which selected Frames lie.
2047  SwSortedObjs aSortObjs;
2048  if ( pStartFrame->IsInFly() )
2049  {
2050  const SwAnchoredObject* pObj = pStartFrame->FindFlyFrame();
2051  OSL_ENSURE( pObj, "No Start Object." );
2052  if (pObj) aSortObjs.Insert( *const_cast<SwAnchoredObject*>(pObj) );
2053  const SwAnchoredObject* pObj2 = pEndFrame->FindFlyFrame();
2054  OSL_ENSURE( pObj2, "SwRootFrame::CalcFrameRects(..) - FlyFrame missing - looks like an invalid selection" );
2055  if ( pObj2 != nullptr && pObj2 != pObj )
2056  {
2057  aSortObjs.Insert( *const_cast<SwAnchoredObject*>(pObj2) );
2058  }
2059  }
2060 
2061  // if a selection which is not allowed exists, we correct what is not
2062  // allowed (header/footer/table-headline) for two pages.
2063  do { // middle check loop
2064  const SwLayoutFrame* pSttLFrame = pStartFrame->GetUpper();
2066  while( pSttLFrame &&
2067  ! (cHdFtTableHd & pSttLFrame->GetType() ))
2068  pSttLFrame = pSttLFrame->GetUpper();
2069  if( !pSttLFrame )
2070  break;
2071  const SwLayoutFrame* pEndLFrame = pEndFrame->GetUpper();
2072  while( pEndLFrame &&
2073  ! (cHdFtTableHd & pEndLFrame->GetType() ))
2074  pEndLFrame = pEndLFrame->GetUpper();
2075  if( !pEndLFrame )
2076  break;
2077 
2078  OSL_ENSURE( pEndLFrame->GetType() == pSttLFrame->GetType(),
2079  "Selection over different content" );
2080  switch( pSttLFrame->GetType() )
2081  {
2082  case SwFrameType::Header:
2083  case SwFrameType::Footer:
2084  // On different pages? Then always on the start-page
2085  if( pEndLFrame->FindPageFrame() != pSttLFrame->FindPageFrame() )
2086  {
2087  // Set end- to the start-ContentFrame
2088  if( pStartPos == rCursor.GetPoint() )
2089  pEndFrame = pStartFrame;
2090  else
2091  pStartFrame = pEndFrame;
2092  }
2093  break;
2094  case SwFrameType::Tab:
2095  // On different pages? Then check for table-headline
2096  {
2097  const SwTabFrame* pTabFrame = static_cast<const SwTabFrame*>(pSttLFrame);
2098  if( ( pTabFrame->GetFollow() ||
2099  static_cast<const SwTabFrame*>(pEndLFrame)->GetFollow() ) &&
2100  pTabFrame->GetTable()->GetRowsToRepeat() > 0 &&
2101  pTabFrame->GetLower() != static_cast<const SwTabFrame*>(pEndLFrame)->GetLower() &&
2102  ( lcl_IsInRepeatedHeadline( pStartFrame ) ||
2103  lcl_IsInRepeatedHeadline( pEndFrame ) ) )
2104  {
2105  // Set end- to the start-ContentFrame
2106  if( pStartPos == rCursor.GetPoint() )
2107  pEndFrame = pStartFrame;
2108  else
2109  pStartFrame = pEndFrame;
2110  }
2111  }
2112  break;
2113  default: break;
2114  }
2115  } while( false );
2116 
2118  aTmpState.m_b2Lines = true;
2119  aTmpState.m_bNoScroll = true;
2120  aTmpState.m_nCursorBidiLevel = pStartFrame->IsRightToLeft() ? 1 : 0;
2121 
2122  //ContentRects to Start- and EndFrames.
2123  SwRect aStRect, aEndRect;
2124  pStartFrame->GetCharRect( aStRect, *pStartPos, &aTmpState );
2125  std::unique_ptr<Sw2LinesPos> pSt2Pos = std::move(aTmpState.m_p2Lines);
2126  aTmpState.m_nCursorBidiLevel = pEndFrame->IsRightToLeft() ? 1 : 0;
2127 
2128  pEndFrame->GetCharRect( aEndRect, *pEndPos, &aTmpState );
2129  std::unique_ptr<Sw2LinesPos> pEnd2Pos = std::move(aTmpState.m_p2Lines);
2130 
2131  SwRect aStFrame ( pStartFrame->UnionFrame( true ) );
2132  aStFrame.Intersection( pStartFrame->GetPaintArea() );
2133  SwRect aEndFrame( pStartFrame == pEndFrame ? aStFrame : pEndFrame->UnionFrame( true ) );
2134  if( pStartFrame != pEndFrame )
2135  {
2136  aEndFrame.Intersection( pEndFrame->GetPaintArea() );
2137  }
2138  SwRectFnSet aRectFnSet(pStartFrame);
2139  const bool bR2L = pStartFrame->IsRightToLeft();
2140  const bool bEndR2L = pEndFrame->IsRightToLeft();
2141  const bool bB2T = pStartFrame->IsVertLRBT();
2142 
2143  // If there's no doubleline portion involved or start and end are both
2144  // in the same doubleline portion, all works fine, but otherwise
2145  // we need the following...
2146  if( pSt2Pos != pEnd2Pos && ( !pSt2Pos || !pEnd2Pos ||
2147  pSt2Pos->aPortion != pEnd2Pos->aPortion ) )
2148  {
2149  // If we have a start(end) position inside a doubleline portion
2150  // the surrounded part of the doubleline portion is subtracted
2151  // from the region and the aStRect(aEndRect) is set to the
2152  // end(start) of the doubleline portion.
2153  if( pSt2Pos )
2154  {
2155  SwRect aTmp( aStRect );
2156 
2157  // BiDi-Portions are swimming against the current.
2158  const bool bPorR2L = ( MultiPortionType::BIDI == pSt2Pos->nMultiType ) ?
2159  ! bR2L :
2160  bR2L;
2161 
2162  if( MultiPortionType::BIDI == pSt2Pos->nMultiType &&
2163  aRectFnSet.GetWidth(pSt2Pos->aPortion2) )
2164  {
2165  // nested bidi portion
2166  long nRightAbs = aRectFnSet.GetRight(pSt2Pos->aPortion);
2167  nRightAbs -= aRectFnSet.GetLeft(pSt2Pos->aPortion2);
2168  long nLeftAbs = nRightAbs - aRectFnSet.GetWidth(pSt2Pos->aPortion2);
2169 
2170  aRectFnSet.SetRight( aTmp, nRightAbs );
2171 
2172  if ( ! pEnd2Pos || pEnd2Pos->aPortion != pSt2Pos->aPortion )
2173  {
2174  SwRect aTmp2( pSt2Pos->aPortion );
2175  aRectFnSet.SetRight( aTmp2, nLeftAbs );
2176  aTmp2.Intersection( aEndFrame );
2177  Sub( aRegion, aTmp2 );
2178  }
2179  }
2180  else
2181  {
2182  if( bPorR2L )
2183  aRectFnSet.SetLeft( aTmp, aRectFnSet.GetLeft(pSt2Pos->aPortion) );
2184  else
2185  aRectFnSet.SetRight( aTmp, aRectFnSet.GetRight(pSt2Pos->aPortion) );
2186  }
2187 
2188  if( MultiPortionType::ROT_90 == pSt2Pos->nMultiType ||
2189  aRectFnSet.GetTop(pSt2Pos->aPortion) ==
2190  aRectFnSet.GetTop(aTmp) )
2191  {
2192  aRectFnSet.SetTop( aTmp, aRectFnSet.GetTop(pSt2Pos->aLine) );
2193  }
2194 
2195  aTmp.Intersection( aStFrame );
2196  Sub( aRegion, aTmp );
2197 
2198  SwTwips nTmp = aRectFnSet.GetBottom(pSt2Pos->aLine);
2199  if( MultiPortionType::ROT_90 != pSt2Pos->nMultiType &&
2200  aRectFnSet.BottomDist( aStRect, nTmp ) > 0 )
2201  {
2202  aRectFnSet.SetTop( aTmp, aRectFnSet.GetBottom(aTmp) );
2203  aRectFnSet.SetBottom( aTmp, nTmp );
2204  if( aRectFnSet.BottomDist( aStRect, aRectFnSet.GetBottom(pSt2Pos->aPortion) ) > 0 )
2205  {
2206  if( bPorR2L )
2207  aRectFnSet.SetRight( aTmp, aRectFnSet.GetRight(pSt2Pos->aPortion) );
2208  else
2209  aRectFnSet.SetLeft( aTmp, aRectFnSet.GetLeft(pSt2Pos->aPortion) );
2210  }
2211  aTmp.Intersection( aStFrame );
2212  Sub( aRegion, aTmp );
2213  }
2214 
2215  aStRect = pSt2Pos->aLine;
2216  aRectFnSet.SetLeft( aStRect, bR2L ?
2217  aRectFnSet.GetLeft(pSt2Pos->aPortion) :
2218  aRectFnSet.GetRight(pSt2Pos->aPortion) );
2219  aRectFnSet.SetWidth( aStRect, 1 );
2220  }
2221 
2222  if( pEnd2Pos )
2223  {
2224  SwRectFnSet fnRectX(pEndFrame);
2225  SwRect aTmp( aEndRect );
2226 
2227  // BiDi-Portions are swimming against the current.
2228  const bool bPorR2L = ( MultiPortionType::BIDI == pEnd2Pos->nMultiType ) ?
2229  ! bEndR2L :
2230  bEndR2L;
2231 
2232  if( MultiPortionType::BIDI == pEnd2Pos->nMultiType &&
2233  fnRectX.GetWidth(pEnd2Pos->aPortion2) )
2234  {
2235  // nested bidi portion
2236  long nRightAbs = fnRectX.GetRight(pEnd2Pos->aPortion);
2237  nRightAbs = nRightAbs - fnRectX.GetLeft(pEnd2Pos->aPortion2);
2238  long nLeftAbs = nRightAbs - fnRectX.GetWidth(pEnd2Pos->aPortion2);
2239 
2240  fnRectX.SetLeft( aTmp, nLeftAbs );
2241 
2242  if ( ! pSt2Pos || pSt2Pos->aPortion != pEnd2Pos->aPortion )
2243  {
2244  SwRect aTmp2( pEnd2Pos->aPortion );
2245  fnRectX.SetLeft( aTmp2, nRightAbs );
2246  aTmp2.Intersection( aEndFrame );
2247  Sub( aRegion, aTmp2 );
2248  }
2249  }
2250  else
2251  {
2252  if ( bPorR2L )
2253  fnRectX.SetRight( aTmp, fnRectX.GetRight(pEnd2Pos->aPortion) );
2254  else
2255  fnRectX.SetLeft( aTmp, fnRectX.GetLeft(pEnd2Pos->aPortion) );
2256  }
2257 
2258  if( MultiPortionType::ROT_90 == pEnd2Pos->nMultiType ||
2259  fnRectX.GetBottom(pEnd2Pos->aPortion) ==
2260  fnRectX.GetBottom(aEndRect) )
2261  {
2262  fnRectX.SetBottom( aTmp, fnRectX.GetBottom(pEnd2Pos->aLine) );
2263  }
2264 
2265  aTmp.Intersection( aEndFrame );
2266  Sub( aRegion, aTmp );
2267 
2268  // The next statement means neither ruby nor rotate(90):
2269  if( MultiPortionType::RUBY != pEnd2Pos->nMultiType && MultiPortionType::ROT_90 != pEnd2Pos->nMultiType )
2270  {
2271  SwTwips nTmp = fnRectX.GetTop(pEnd2Pos->aLine);
2272  if( fnRectX.GetTop(aEndRect) != nTmp )
2273  {
2274  fnRectX.SetBottom( aTmp, fnRectX.GetTop(aTmp) );
2275  fnRectX.SetTop( aTmp, nTmp );
2276  if( fnRectX.GetTop(aEndRect) !=
2277  fnRectX.GetTop(pEnd2Pos->aPortion) )
2278  {
2279  if( bPorR2L )
2280  fnRectX.SetLeft( aTmp, fnRectX.GetLeft(pEnd2Pos->aPortion) );
2281  else
2282  fnRectX.SetRight( aTmp, fnRectX.GetRight(pEnd2Pos->aPortion) );
2283  }
2284  aTmp.Intersection( aEndFrame );
2285  Sub( aRegion, aTmp );
2286  }
2287  }
2288 
2289  aEndRect = pEnd2Pos->aLine;
2290  fnRectX.SetLeft( aEndRect, bEndR2L ?
2291  fnRectX.GetRight(pEnd2Pos->aPortion) :
2292  fnRectX.GetLeft(pEnd2Pos->aPortion) );
2293  fnRectX.SetWidth( aEndRect, 1 );
2294  }
2295  }
2296  else if( pSt2Pos && pEnd2Pos &&
2297  MultiPortionType::BIDI == pSt2Pos->nMultiType &&
2298  MultiPortionType::BIDI == pEnd2Pos->nMultiType &&
2299  pSt2Pos->aPortion == pEnd2Pos->aPortion &&
2300  pSt2Pos->aPortion2 != pEnd2Pos->aPortion2 )
2301  {
2302  // This is the ugly special case, where the selection starts and
2303  // ends in the same bidi portion but one start or end is inside a
2304  // nested bidi portion.
2305 
2306  if ( aRectFnSet.GetWidth(pSt2Pos->aPortion2) )
2307  {
2308  SwRect aTmp( aStRect );
2309  long nRightAbs = aRectFnSet.GetRight(pSt2Pos->aPortion);
2310  nRightAbs -= aRectFnSet.GetLeft(pSt2Pos->aPortion2);
2311  long nLeftAbs = nRightAbs - aRectFnSet.GetWidth(pSt2Pos->aPortion2);
2312 
2313  aRectFnSet.SetRight( aTmp, nRightAbs );
2314  aTmp.Intersection( aStFrame );
2315  Sub( aRegion, aTmp );
2316 
2317  aStRect = pSt2Pos->aLine;
2318  aRectFnSet.SetLeft( aStRect, bR2L ? nRightAbs : nLeftAbs );
2319  aRectFnSet.SetWidth( aStRect, 1 );
2320  }
2321 
2322  SwRectFnSet fnRectX(pEndFrame);
2323  if ( fnRectX.GetWidth(pEnd2Pos->aPortion2) )
2324  {
2325  SwRect aTmp( aEndRect );
2326  long nRightAbs = fnRectX.GetRight(pEnd2Pos->aPortion);
2327  nRightAbs -= fnRectX.GetLeft(pEnd2Pos->aPortion2);
2328  long nLeftAbs = nRightAbs - fnRectX.GetWidth(pEnd2Pos->aPortion2);
2329 
2330  fnRectX.SetLeft( aTmp, nLeftAbs );
2331  aTmp.Intersection( aEndFrame );
2332  Sub( aRegion, aTmp );
2333 
2334  aEndRect = pEnd2Pos->aLine;
2335  fnRectX.SetLeft( aEndRect, bEndR2L ? nLeftAbs : nRightAbs );
2336  fnRectX.SetWidth( aEndRect, 1 );
2337  }
2338  }
2339 
2340  // The charrect may be outside the paintarea (for cursortravelling)
2341  // but the selection has to be restricted to the paintarea
2342  if( aStRect.Left() < aStFrame.Left() )
2343  aStRect.Left( aStFrame.Left() );
2344  else if( aStRect.Left() > aStFrame.Right() )
2345  aStRect.Left( aStFrame.Right() );
2346  SwTwips nTmp = aStRect.Right();
2347  if( nTmp < aStFrame.Left() )
2348  aStRect.Right( aStFrame.Left() );
2349  else if( nTmp > aStFrame.Right() )
2350  aStRect.Right( aStFrame.Right() );
2351  if( aEndRect.Left() < aEndFrame.Left() )
2352  aEndRect.Left( aEndFrame.Left() );
2353  else if( aEndRect.Left() > aEndFrame.Right() )
2354  aEndRect.Left( aEndFrame.Right() );
2355  nTmp = aEndRect.Right();
2356  if( nTmp < aEndFrame.Left() )
2357  aEndRect.Right( aEndFrame.Left() );
2358  else if( nTmp > aEndFrame.Right() )
2359  aEndRect.Right( aEndFrame.Right() );
2360 
2361  if( pStartFrame == pEndFrame )
2362  {
2363  bool bSameRotatedOrBidi = pSt2Pos && pEnd2Pos &&
2364  ( MultiPortionType::BIDI == pSt2Pos->nMultiType ||
2365  MultiPortionType::ROT_270 == pSt2Pos->nMultiType ||
2366  MultiPortionType::ROT_90 == pSt2Pos->nMultiType ) &&
2367  pSt2Pos->aPortion == pEnd2Pos->aPortion;
2368  //case 1: (Same frame and same row)
2369  if( bSameRotatedOrBidi ||
2370  aRectFnSet.GetTop(aStRect) == aRectFnSet.GetTop(aEndRect) )
2371  {
2372  Point aTmpSt( aStRect.Pos() );
2373  Point aTmpEnd( aEndRect.Right(), aEndRect.Bottom() );
2374  if (bSameRotatedOrBidi || bR2L || bB2T)
2375  {
2376  if( aTmpSt.Y() > aTmpEnd.Y() )
2377  {
2378  long nTmpY = aTmpEnd.Y();
2379  aTmpEnd.setY( aTmpSt.Y() );
2380  aTmpSt.setY( nTmpY );
2381  }
2382  if( aTmpSt.X() > aTmpEnd.X() )
2383  {
2384  long nTmpX = aTmpEnd.X();
2385  aTmpEnd.setX( aTmpSt.X() );
2386  aTmpSt.setX( nTmpX );
2387  }
2388  }
2389 
2390  SwRect aTmp( aTmpSt, aTmpEnd );
2391  // Bug 34888: If content is selected which doesn't take space
2392  // away (i.e. PostIts, RefMarks, TOXMarks), then at
2393  // least set the width of the Cursor.
2394  if( 1 == aRectFnSet.GetWidth(aTmp) &&
2395  pStartPos->nContent.GetIndex() !=
2396  pEndPos->nContent.GetIndex() )
2397  {
2398  OutputDevice* pOut = pSh->GetOut();
2399  long nCursorWidth = pOut->GetSettings().GetStyleSettings().
2400  GetCursorSize();
2401  aRectFnSet.SetWidth( aTmp, pOut->PixelToLogic(
2402  Size( nCursorWidth, 0 ) ).Width() );
2403  }
2404  aTmp.Intersection( aStFrame );
2405  Sub( aRegion, aTmp );
2406  }
2407  //case 2: (Same frame, but not the same line)
2408  else
2409  {
2410  SwTwips lLeft, lRight;
2411  if( pSt2Pos && pEnd2Pos && pSt2Pos->aPortion == pEnd2Pos->aPortion )
2412  {
2413  lLeft = aRectFnSet.GetLeft(pSt2Pos->aPortion);
2414  lRight = aRectFnSet.GetRight(pSt2Pos->aPortion);
2415  }
2416  else
2417  {
2418  lLeft = aRectFnSet.GetLeft(pStartFrame->getFrameArea()) +
2419  aRectFnSet.GetLeft(pStartFrame->getFramePrintArea());
2420  lRight = aRectFnSet.GetRight(aEndFrame);
2421  }
2422  if( lLeft < aRectFnSet.GetLeft(aStFrame) )
2423  lLeft = aRectFnSet.GetLeft(aStFrame);
2424  if( lRight > aRectFnSet.GetRight(aStFrame) )
2425  lRight = aRectFnSet.GetRight(aStFrame);
2426  SwRect aSubRect( aStRect );
2427  //First line
2428  if( bR2L )
2429  aRectFnSet.SetLeft( aSubRect, lLeft );
2430  else
2431  aRectFnSet.SetRight( aSubRect, lRight );
2432  Sub( aRegion, aSubRect );
2433 
2434  //If there's at least a twips between start- and endline,
2435  //so the whole area between will be added.
2436  SwTwips aTmpBottom = aRectFnSet.GetBottom(aStRect);
2437  SwTwips aTmpTop = aRectFnSet.GetTop(aEndRect);
2438  if( aTmpBottom != aTmpTop )
2439  {
2440  aRectFnSet.SetLeft( aSubRect, lLeft );
2441  aRectFnSet.SetRight( aSubRect, lRight );
2442  aRectFnSet.SetTop( aSubRect, aTmpBottom );
2443  aRectFnSet.SetBottom( aSubRect, aTmpTop );
2444  Sub( aRegion, aSubRect );
2445  }
2446  //and the last line
2447  aSubRect = aEndRect;
2448  if( bR2L )
2449  aRectFnSet.SetRight( aSubRect, lRight );
2450  else
2451  aRectFnSet.SetLeft( aSubRect, lLeft );
2452  Sub( aRegion, aSubRect );
2453  }
2454  }
2455  //case 3: (Different frames, maybe with other frames between)
2456  else
2457  {
2458  //The startframe first...
2459  SwRect aSubRect( aStRect );
2460  if( bR2L )
2461  aRectFnSet.SetLeft( aSubRect, aRectFnSet.GetLeft(aStFrame));
2462  else
2463  aRectFnSet.SetRight( aSubRect, aRectFnSet.GetRight(aStFrame));
2464  Sub( aRegion, aSubRect );
2465  SwTwips nTmpTwips = aRectFnSet.GetBottom(aStRect);
2466  if( aRectFnSet.GetBottom(aStFrame) != nTmpTwips )
2467  {
2468  aSubRect = aStFrame;
2469  aRectFnSet.SetTop( aSubRect, nTmpTwips );
2470  Sub( aRegion, aSubRect );
2471  }
2472 
2473  //Now the frames between, if there are any
2474  bool const bBody = pStartFrame->IsInDocBody();
2475  const SwTableBox* pCellBox = pStartFrame->GetUpper()->IsCellFrame() ?
2476  static_cast<const SwCellFrame*>(pStartFrame->GetUpper())->GetTabBox() : nullptr;
2477  if (pSh->IsSelectAll())
2478  pCellBox = nullptr;
2479 
2480  const SwContentFrame *pContent = pStartFrame->GetNextContentFrame();
2481  SwRect aPrvRect;
2482 
2483  OSL_ENSURE( pContent,
2484  "<SwRootFrame::CalcFrameRects(..)> - no content frame. This is a serious defect" );
2485  while ( pContent && pContent != pEndFrame )
2486  {
2487  if ( pContent->IsInFly() )
2488  {
2489  const SwAnchoredObject* pObj = pContent->FindFlyFrame();
2490  if (!aSortObjs.Contains(*pObj))
2491  { // is this even possible, assuming valid cursor pos.?
2492  aSortObjs.Insert( *const_cast<SwAnchoredObject*>(pObj) );
2493  }
2494  }
2495 
2496  // Consider only frames which have the same IsInDocBody value like pStartFrame
2497  // If pStartFrame is inside a SwCellFrame, consider only frames which are inside the
2498  // same cell frame (or its follow cell)
2499  const SwTableBox* pTmpCellBox = pContent->GetUpper()->IsCellFrame() ?
2500  static_cast<const SwCellFrame*>(pContent->GetUpper())->GetTabBox() : nullptr;
2501  if (pSh->IsSelectAll())
2502  pTmpCellBox = nullptr;
2503  if ( bBody == pContent->IsInDocBody() &&
2504  ( !pCellBox || pCellBox == pTmpCellBox ) )
2505  {
2506  SwRect aCRect( pContent->UnionFrame( true ) );
2507  aCRect.Intersection( pContent->GetPaintArea() );
2508  if( aCRect.IsOver( aRegion.GetOrigin() ))
2509  {
2510  SwRect aTmp( aPrvRect );
2511  aTmp.Union( aCRect );
2512  if ( (aPrvRect.Height() * aPrvRect.Width() +
2513  aCRect.Height() * aCRect.Width()) ==
2514  (aTmp.Height() * aTmp.Width()) )
2515  {
2516  aPrvRect.Union( aCRect );
2517  }
2518  else
2519  {
2520  if ( aPrvRect.HasArea() )
2521  Sub( aRegion, aPrvRect );
2522  aPrvRect = aCRect;
2523  }
2524  }
2525  }
2526  pContent = pContent->GetNextContentFrame();
2527  OSL_ENSURE( pContent,
2528  "<SwRootFrame::CalcFrameRects(..)> - no content frame. This is a serious defect!" );
2529  }
2530  if ( aPrvRect.HasArea() )
2531  Sub( aRegion, aPrvRect );
2532 
2533  //At least the endframe...
2534  aRectFnSet.Refresh(pEndFrame);
2535  nTmpTwips = aRectFnSet.GetTop(aEndRect);
2536  if( aRectFnSet.GetTop(aEndFrame) != nTmpTwips )
2537  {
2538  aSubRect = aEndFrame;
2539  aRectFnSet.SetBottom( aSubRect, nTmpTwips );
2540  Sub( aRegion, aSubRect );
2541  }
2542  aSubRect = aEndRect;
2543  if( bEndR2L )
2544  aRectFnSet.SetRight(aSubRect, aRectFnSet.GetRight(aEndFrame));
2545  else
2546  aRectFnSet.SetLeft( aSubRect, aRectFnSet.GetLeft(aEndFrame) );
2547  Sub( aRegion, aSubRect );
2548  }
2549 
2550  aRegion.Invert();
2551  pSt2Pos.reset();
2552  pEnd2Pos.reset();
2553 
2554  // Cut out Flys during loop. We don't cut out Flys when:
2555  // - the Lower is StartFrame/EndFrame (FlyInCnt and all other Flys which again
2556  // sit in it)
2557  // - if in the Z-order we have Flys above those in which the StartFrame is
2558  // placed
2559  // - if they are anchored to inside the selection and thus part of it
2560  const SwPageFrame *pPage = pStartFrame->FindPageFrame();
2561  const SwPageFrame *pEndPage = pEndFrame->FindPageFrame();
2562 
2563  while ( pPage )
2564  {
2565  if ( pPage->GetSortedObjs() )
2566  {
2567  const SwSortedObjs &rObjs = *pPage->GetSortedObjs();
2568  for (SwAnchoredObject* pAnchoredObj : rObjs)
2569  {
2570  if ( dynamic_cast< const SwFlyFrame *>( pAnchoredObj ) == nullptr )
2571  continue;
2572  const SwFlyFrame* pFly = static_cast<const SwFlyFrame*>(pAnchoredObj);
2573  const SwVirtFlyDrawObj* pObj = pFly->GetVirtDrawObj();
2574  const SwFormatSurround &rSur = pFly->GetFormat()->GetSurround();
2575  SwFormatAnchor const& rAnchor(pAnchoredObj->GetFrameFormat().GetAnchor());
2576  const SwPosition* anchoredAt = rAnchor.GetContentAnchor();
2577  bool inSelection = (
2578  anchoredAt != nullptr
2579  && ( (rAnchor.GetAnchorId() == RndStdIds::FLY_AT_CHAR
2580  && IsDestroyFrameAnchoredAtChar(*anchoredAt, *pStartPos, *pEndPos))
2581  || (rAnchor.GetAnchorId() == RndStdIds::FLY_AT_PARA
2582  && IsSelectFrameAnchoredAtPara(*anchoredAt, *pStartPos, *pEndPos))));
2583  if( inSelection )
2584  Add( aRegion, pFly->getFrameArea() );
2585  else if ( !pFly->IsAnLower( pStartFrame ) &&
2586  (rSur.GetSurround() != css::text::WrapTextMode_THROUGH &&
2587  !rSur.IsContour()) )
2588  {
2589  if ( aSortObjs.Contains( *pAnchoredObj ) )
2590  continue;
2591 
2592  bool bSub = true;
2593  const sal_uInt32 nPos = pObj->GetOrdNum();
2594  for ( size_t k = 0; bSub && k < aSortObjs.size(); ++k )
2595  {
2596  OSL_ENSURE( dynamic_cast< const SwFlyFrame *>( aSortObjs[k] ) != nullptr,
2597  "<SwRootFrame::CalcFrameRects(..)> - object in <aSortObjs> of unexpected type" );
2598  const SwFlyFrame* pTmp = static_cast<SwFlyFrame*>(aSortObjs[k]);
2599  do
2600  {
2601  if ( nPos < pTmp->GetVirtDrawObj()->GetOrdNumDirect() )
2602  {
2603  bSub = false;
2604  }
2605  else
2606  {
2607  pTmp = pTmp->GetAnchorFrame()->FindFlyFrame();
2608  }
2609  } while ( bSub && pTmp );
2610  }
2611  if ( bSub )
2612  Sub( aRegion, pFly->getFrameArea() );
2613  }
2614  }
2615  }
2616  if ( pPage == pEndPage )
2617  break;
2618  else
2619  pPage = static_cast<const SwPageFrame*>(pPage->GetNext());
2620  }
2621 
2622  //Because it looks better, we close the DropCaps.
2623  SwRect aDropRect;
2624  if ( pStartFrame->IsTextFrame() )
2625  {
2626  if ( static_cast<const SwTextFrame*>(pStartFrame)->GetDropRect( aDropRect ) )
2627  Sub( aRegion, aDropRect );
2628  }
2629  if ( pEndFrame != pStartFrame && pEndFrame->IsTextFrame() )
2630  {
2631  if ( static_cast<const SwTextFrame*>(pEndFrame)->GetDropRect( aDropRect ) )
2632  Sub( aRegion, aDropRect );
2633  }
2634 
2635  rCursor.assign( aRegion.begin(), aRegion.end() );
2636 }
2637 
2638 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsAnLower(const SwFrame *) const
Definition: findfrm.cxx:206
vcl::RenderContext * GetOut() const
Definition: viewsh.hxx:339
bool IsContour() const
Definition: fmtsrnd.hxx:53
const SwVirtFlyDrawObj * GetVirtDrawObj() const
Definition: fly.cxx:2711
Base class of the Writer layout elements.
Definition: frame.hxx:297
Base class that provides the general functionalities for frames that are allowed at page breaks (flow...
Definition: flowfrm.hxx:58
Represents the visualization of a paragraph.
Definition: txtfrm.hxx:151
virtual sal_Int32 Len() const
Definition: node.cxx:1223
constexpr TypedWhichId< SwFormatPageDesc > RES_PAGEDESC(93)
virtual bool GetModelPositionForViewPoint(SwPosition *, Point &, SwCursorMoveState *=nullptr, bool bTestBackground=false) const override
Searches the page containing the searched point.
Definition: trvlfrm.cxx:179
const ::std::optional< sal_uInt16 > & GetNumOffset() const
Definition: fmtpdsc.hxx:65
long BottomDist(const SwRect &rRect, long nPos) const
Definition: frame.hxx:1392
const SdrObject * Next()
Definition: frmtool.cxx:2601
sal_uLong GetIndex() const
Definition: node.hxx:282
SwNode & GetNode(bool bPoint=true) const
Definition: pam.hxx:223
bool IsFollow() const
Definition: flowfrm.hxx:166
virtual bool RightMargin(SwPaM *, bool bAPI=false) const override
Definition: trvlfrm.cxx:624
virtual const SwFlyFrameFormat * GetFormat() const override
Definition: fly.cxx:2800
void SetCallbackActionEnabled(bool b)
Definition: rootfrm.hxx:381
void GetContentPosition(const Point &rPt, SwPosition &rPos) const
Same as SwLayoutFrame::GetContentPos().
Definition: trvlfrm.cxx:1380
Marks a position in the document model.
Definition: pam.hxx:35
const SwRect & GetOrigin() const
Definition: swregion.hxx:47
SwContentFrame * GetNextContentFrame() const
Definition: cntfrm.hxx:98
const SwField * GetField() const
Definition: fmtfld.hxx:111
SwContentNode * GetNode(SwPaM &rPam, bool &rbFirst, SwMoveFnCollection const &fnMove, bool const bInReadOnly, SwRootFrame const *const i_pLayout)
This function returns the next node in direction of search.
Definition: pam.cxx:816
bool IsInDocBody() const
Definition: frame.hxx:921
static bool lcl_IsInRepeatedHeadline(const SwFrame *pFrame, const SwTabFrame **ppTFrame=nullptr)
Frame in repeated headline?
Definition: trvlfrm.cxx:646
const SwPageFrame * GetPageAtPos(const Point &rPt, const Size *pSize=nullptr, bool bExtend=false) const
Point rPt: The point that should be used to find the page Size pSize: If given, we return the (first)...
Definition: findfrm.cxx:572
bool IsInFly() const
Definition: frame.hxx:939
SwRect & Union(const SwRect &rRect)
Definition: swrect.cxx:41
Pagedescriptor Client of SwPageDesc that is "described" by the attribute.
Definition: fmtpdsc.hxx:35
SwRootFrame * mpRoot
Definition: frame.hxx:319
SwPageDesc * GetPageDesc()
Definition: fmtpdsc.hxx:62
virtual bool get(DocumentSettingId id) const override
Return the specified document setting.
sal_uInt16 GetCurrPage(const SwPaM *) const
Query/set the current Page and the collective Page count We'll format as much as necessary.
Definition: trvlfrm.cxx:979
static bool more(const double &rfValA, const double &rfValB)
const SwTable * GetTable() const
Definition: tabfrm.hxx:144
SwNodeIndex nNode
Definition: pam.hxx:37
void Refresh(const SwFrame *pFrame)
Definition: frame.hxx:1337
bool IsInFootnote() const
Definition: frame.hxx:927
sal_uInt16 char char * pDesc
SwFrameType GetType() const
Definition: frame.hxx:500
SwLayoutFrame * GetPrevFrame(const SwLayoutFrame *pFrame)
Definition: trvlfrm.cxx:1076
const SwRect & getFramePrintArea() const
Definition: frame.hxx:178
const StyleSettings & GetStyleSettings() const
const SwPosition * GetMark() const
Definition: pam.hxx:209
Base class of all fields.
Definition: fldbas.hxx:293
SwTabFrame is one table in the document layout, containing rows (which contain cells).
Definition: tabfrm.hxx:30
sal_uInt8 m_nCursorBidiLevel
Definition: crstate.hxx:139
SwContentFrame * getLayoutFrame(const SwRootFrame *, const SwPosition *pPos=nullptr, std::pair< Point, bool > const *pViewPosAndCalcFrame=nullptr) const
Definition: node.cxx:1190
Definition: doc.hxx:184
helper class to disable creation of an action by a callback event in particular, change event from a ...
Definition: rootfrm.hxx:440
static SwContentNode * GetContentNode(SwDoc *pDoc, SwNodeIndex &rIdx, bool bNext)
Definition: fltshell.cxx:54
bool m_bSetInReadOnly
ReadOnly areas may be entered.
Definition: crstate.hxx:148
void Height(long nNew)
Definition: swrect.hxx:191
long GetBottom(const SwRect &rRect) const
Definition: frame.hxx:1356
const Point & GetSttPos() const
Definition: viscrs.hxx:146
bool m_bExactOnly
let GetModelPositionForViewPoint look for exact matches only, i.e.
Definition: crstate.hxx:145
SwNode & GetNode() const
Definition: ndindex.hxx:119
long SwTwips
Definition: swtypes.hxx:49
bool IsSelectFrameAnchoredAtPara(SwPosition const &rAnchorPos, SwPosition const &rStart, SwPosition const &rEnd, DelContentType const nDelContentType)
is a fly anchored at paragraph at rAnchorPos selected?
Definition: undobj.cxx:1621
This class is used as parameter for creation of a block cursor selection.
bool IsVert() const
Definition: frame.hxx:1345
sal_uInt16 GetRowsToRepeat() const
Definition: swtable.hxx:193
void Pos(const Point &rNew)
Definition: swrect.hxx:169
virtual void Calc(vcl::RenderContext *pRenderContext) const
Definition: trvlfrm.cxx:1786
bool IsCellFrame() const
Definition: frame.hxx:1204
bool IsFootnotePage() const
Foot note interface.
Definition: pagefrm.hxx:185
void Top()
Definition: frmtool.cxx:2548
Of course Writer needs its own rectangles.
Definition: swrect.hxx:35
SwContentFrame * FindFirstBodyContent()
Definition: pagefrm.hxx:333
const OUString & GetText() const
Returns the text portion we want to edit (for inline see underneath)
Definition: txtfrm.cxx:1278
virtual const SwFormatPageDesc & GetPageDescItem() const
Definition: findfrm.cxx:659
long GetPrtTop(const SwFrame &rFrame) const
Definition: frame.hxx:1387
bool IsDestroyFrameAnchoredAtChar(SwPosition const &rAnchorPos, SwPosition const &rStart, SwPosition const &rEnd, DelContentType const nDelContentType)
will DelContentIndex destroy a frame anchored at character at rAnchorPos?
Definition: undobj.cxx:1580
static SwFlowFrame * CastFlowFrame(SwFrame *pFrame)
Definition: flowfrm.cxx:2624
SwLayoutFrame * GetThisFrame(const SwLayoutFrame *pFrame)
Definition: trvlfrm.cxx:1071
The root element of a Writer document layout.
Definition: rootfrm.hxx:79
SwContact * GetUserCall(const SdrObject *pObj)
Returns the UserCall if applicable from the group object.
Definition: dcontact.cxx:171
virtual bool GetInfo(SfxPoolItem &) const override
Definition: calbck.cxx:206
bool IsFootnoteFrame() const
Definition: frame.hxx:1180
bool isFrameAreaDefinitionValid() const
Definition: frame.hxx:169
static void Sub(SwRegionRects &rRegion, const SwRect &rRect)
Definition: trvlfrm.cxx:1969
SwLayoutFrame * GetNextFrame(const SwLayoutFrame *pFrame)
Definition: trvlfrm.cxx:1059
bool m_bFillRet
only used temporary in FillMode
Definition: crstate.hxx:147
static SwCursorOszControl g_OszCtrl
Definition: trvlfrm.cxx:147
not in repeated headlines
void PrepareMake(vcl::RenderContext *pRenderContext)
Prepares the Frame for "formatting" (MakeAll()).
Definition: calcmove.cxx:241
sal_uInt16 GetPhyPageNum() const
Definition: pagefrm.hxx:190
bool IsSelectAll() const
Definition: viewsh.hxx:566
SwContentNode * GetContentNode(bool bPoint=true) const
Definition: pam.hxx:229
virtual bool GetModelPositionForViewPoint(SwPosition *, Point &, SwCursorMoveState *=nullptr, bool bTestBackground=false) const
Definition: unusedf.cxx:46
SwTextAttr * GetTextAttrForCharAt(const sal_Int32 nIndex, const sal_uInt16 nWhich=RES_TXTATR_END) const
get the text attribute at position nIndex which owns the dummy character CH_TXTATR_* at that position...
Definition: ndtxt.cxx:3051
long YDiff(long n1, long n2) const
Definition: frame.hxx:1401
SwRect GetPaintArea() const
|* The paintarea is the area, in which the content of a frame is allowed |* to be displayed...
Definition: ssfrm.cxx:581
bool WannaRightPage() const
Decides if the page want to be a right page or not.
Definition: trvlfrm.cxx:1712
virtual bool GetModelPositionForViewPoint(SwPosition *, Point &, SwCursorMoveState *=nullptr, bool bTestBackground=false) const override
Primary passes the call to the first page.
Definition: trvlfrm.cxx:423
bool IsFlyFrame() const
Definition: frame.hxx:1188
wrapper class for the positioning of Writer fly frames and drawing objects
long GetPrtBottom(const SwFrame &rFrame) const
Definition: frame.hxx:1388
const SwPageFrame * GetPage() const
Definition: hints.hxx:271
void Top(const long nTop)
Definition: swrect.hxx:204
SwIndex nContent
Definition: pam.hxx:38
const SwRect & getFrameArea() const
Definition: frame.hxx:177
SwFlyFrame * GetPrevLink() const
Definition: flyfrm.hxx:172
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
bool IsEmptyPage() const
Definition: pagefrm.hxx:143
bool IsInTab() const
Definition: frame.hxx:933
SwRect & Intersection(const SwRect &rRect)
Definition: swrect.cxx:56
virtual bool FillSelection(SwSelectionList &rList, const SwRect &rRect) const override
Definition: trvlfrm.cxx:379
void CalcFrameRects(SwShellCursor &)
Definition: trvlfrm.cxx:2006
bool IsTextFrame() const
Definition: frame.hxx:1212
virtual bool UnitUp(SwPaM *, const SwTwips nOffset, bool bSetInReadOnly) const
Definition: trvlfrm.cxx:964
oslFileHandle & pOut
const SwContentFrame *(* GetNxtPrvCnt)(const SwContentFrame *)
Definition: trvlfrm.cxx:643
bool OnRightPage() const
Definition: frame.hxx:713
const SwFormatSurround & GetSurround(bool=true) const
Definition: fmtsrnd.hxx:66
static const SwContentFrame * lcl_GetNxtCnt(const SwContentFrame *pCnt)
Definition: trvlfrm.cxx:633
bool IsPageBodyFrame() const
Definition: layfrm.hxx:214
const SwFormatField & GetFormatField() const
Definition: txatbase.hxx:191
virtual bool FillSelection(SwSelectionList &rList, const SwRect &rRect) const
Definition: unusedf.cxx:40
SwContentFrame * GetPrevContentFrame() const
Definition: cntfrm.hxx:106
SwFlyFrame * FindFlyFrame()
Definition: frame.hxx:1089
long GetLeft(const SwRect &rRect) const
Definition: frame.hxx:1357
long GetRight(const SwRect &rRect) const
Definition: frame.hxx:1358
void Right(const long nRight)
Definition: swrect.hxx:200
virtual bool UnitDown(SwPaM *, const SwTwips nOffset, bool bSetInReadOnly) const
Definition: trvlfrm.cxx:969
virtual bool LeftMargin(SwPaM *) const override
Layout dependent cursor travelling.
Definition: trvlfrm.cxx:615
SwPageFrame * GetPageByPageNum(sal_uInt16 _nPageNum) const
Get page frame by physical page number looping through the lowers, which are page frame...
Definition: trvlfrm.cxx:1590
void SetBottom(SwRect &rRect, long nNew) const
Definition: frame.hxx:1365
virtual bool GetCharRect(SwRect &, const SwPosition &, SwCursorMoveState *=nullptr, bool bAllowFarAway=true) const
Definition: unusedf.cxx:71
sal_uInt16 GetVirtPageNum() const
Definition: trvlfrm.cxx:1804
bool IsContentNode() const
Definition: node.hxx:628
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
bool FrameContainsNode(SwContentFrame const &rFrame, sal_uLong nNodeIndex)
Definition: txtfrm.cxx:284
Point GetRelPos() const
Definition: trvlfrm.cxx:1794
constexpr TypedWhichId< SwFormatField > RES_TXTATR_FIELD(RES_TXTATR_NOEND_BEGIN)
virtual bool FillSelection(SwSelectionList &rList, const SwRect &rRect) const override
Definition: trvlfrm.cxx:401
void SetWidth(SwRect &rRect, long nNew) const
Definition: frame.hxx:1368
bool IsContentFrame() const
Definition: frame.hxx:1208
void SetTop(SwRect &rRect, long nNew) const
Definition: frame.hxx:1364
double GetLength() const
const SwSortedObjs * GetSortedObjs() const
Definition: pagefrm.hxx:118
#define SAL_MAX_UINT64
const SwFormatAnchor & GetAnchor(bool=true) const
Definition: fmtanchr.hxx:81
virtual bool GetModelPositionForViewPoint(SwPosition *, Point &, SwCursorMoveState *=nullptr, bool bTestBackground=false) const override
Searches the ContentFrame owning the PrtArea containing the point.
Definition: trvlfrm.cxx:538
long XInc(long n1, long n2) const
Definition: frame.hxx:1402
const SwRect & VisArea() const
Definition: viewsh.cxx:560
#define FRM_HEADFOOT
Definition: frame.hxx:106
uno_Any a
SwContentFrame * GetLastSub(const SwLayoutFrame *pLayout)
Definition: trvlfrm.cxx:1054
const SwStartNode * StartOfSectionNode() const
Definition: node.hxx:131
const SwPosition * GetPoint() const
Definition: pam.hxx:207
long XDiff(long n1, long n2) const
Definition: frame.hxx:1400
SwFrameType
Definition: frame.hxx:72
bool Insert(SwAnchoredObject &_rAnchoredObj)
Definition: sortedobjs.cxx:207
virtual bool IsCoveredCell() const
Definition: tabfrm.cxx:5777
const SwPageDesc & GetPageDesc(const size_t i) const
Definition: doc.hxx:878
static bool lcl_UpDown(SwPaM *pPam, const SwContentFrame *pStart, GetNxtPrvCnt fnNxtPrv, bool bInReadOnly)
Definition: trvlfrm.cxx:689
size_t size() const
Definition: sortedobjs.cxx:42
SwPageFrame * FindPageFrame()
Definition: frame.hxx:660
SwLayoutFrame *(* SwWhichPage)(const SwLayoutFrame *)
Definition: cshtyp.hxx:34
SwFrameFormat * GetLeftFormat(bool const bFirst=false)
Definition: pagedesc.cxx:362
bool IsDummyPage(sal_uInt16 nPageNum) const
Definition: trvlfrm.cxx:1611
bool isEmpty() const
Reports if the list does not contain any text portion.
const SwFrame * Lower() const
Definition: layfrm.hxx:101
SwPageDesc * GetPageDesc()
Definition: pagefrm.hxx:129
SwContentNode * GetContentNode()
Definition: node.hxx:615
FlyAnchors.
Definition: fmtanchr.hxx:34
SwLayoutFrame * GetUpper()
Definition: frame.hxx:658
bool HasArea() const
Definition: swrect.hxx:288
static const SwContentFrame * lcl_MissProtectedFrames(const SwContentFrame *pCnt, GetNxtPrvCnt fnNxtPrv, bool bMissHeadline, bool bInReadOnly, bool bMissFollowFlowLine)
Skip protected table cells. Optionally also skip repeated headlines.
Definition: trvlfrm.cxx:658
bool isFramePrintAreaValid() const
Definition: frame.hxx:166
Marks a character position inside a document model node.
Definition: index.hxx:37
::rtl::Reference< Content > pContent
bool IsRowFrame() const
Definition: frame.hxx:1200
sal_uInt32 GetOrdNum() const
static const SwLayoutFrame * lcl_Inside(const SwContentFrame *pCnt, Point const &rPt)
Check if the point lies inside the page part in which also the ContentFrame lies. ...
Definition: trvlfrm.cxx:1159
css::text::WrapTextMode GetSurround() const
Definition: fmtsrnd.hxx:51
SwFrame * GetPrev()
Definition: frame.hxx:657
const Point & GetMkPos() const
Definition: viscrs.hxx:144
bool IsContentProtected() const
const SwRowFrame * IsInFollowFlowRow() const
Definition: findfrm.cxx:1774
void MakeSelUnions(SwSelUnions &rUnions, const SwLayoutFrame *pStart, const SwLayoutFrame *pEnd, const SwTableSearchType eSearchType)
Definition: tblsel.cxx:1771
bool IsPDFExport() const
Definition: viewopt.hxx:390
const AllSettings & GetSettings() const
bool isFrameAreaPositionValid() const
Definition: frame.hxx:164
static sal_uInt64 CalcDiff(const Point &rPt1, const Point &rPt2)
Definition: trvlfrm.cxx:1142
const SwDoc * GetDoc() const
The document is set in SwAttrPool now, therefore you always can access it.
Definition: format.hxx:119
void SSize(const Size &rNew)
Definition: swrect.hxx:178
SwRect UnionFrame(bool bBorder=false) const
|* The unionframe is the framearea (getFrameArea()) of a frame expanded by the |* printarea...
Definition: ssfrm.cxx:688
bool isFrameAreaSizeValid() const
Definition: frame.hxx:165
virtual const SwAnchoredObject * GetAnchoredObj(const SdrObject *_pSdrObj) const =0
A page of the document layout.
Definition: pagefrm.hxx:40
bool m_bNoScroll
No scrolling of undersized textframes.
Definition: crstate.hxx:151
bool m_b2Lines
Check 2line portions and fill p2Lines.
Definition: crstate.hxx:150
long GetPrtRight(const SwFrame &rFrame) const
Definition: frame.hxx:1390
stay with the cursor inside text
const SwModify * GetDefinedIn() const
Query / set where attribute is anchored.
Definition: fmtpdsc.hxx:69
bool MakeTableCursors(SwTableCursor &)
Calculates the cells included from the current selection.
Definition: trvlfrm.cxx:1858
SwContentFrame * GetFirstSub(const SwLayoutFrame *pLayout)
Definition: trvlfrm.cxx:1049
const SwPosition * Start() const
Definition: pam.hxx:212
std::unique_ptr< Sw2LinesPos > m_p2Lines
for selections inside/around 2line portions
Definition: crstate.hxx:135
Point Center() const
Definition: swrect.cxx:35
bool IsInProtectSect() const
Is node in a protected area?
Definition: node.cxx:411
const SwPageDesc * GetFollow() const
Definition: pagedesc.hxx:246
const SwFrame * GetFrame() const
Definition: hints.hxx:273
const SwCellFrame * FirstCell() const
Calls ContainsAny first to reach the innermost cell.
Definition: findfrm.cxx:112
Point PixelToLogic(const Point &rDevicePt) const
void SetLeft(SwRect &rRect, long nNew) const
Definition: frame.hxx:1366
long GetPrtLeft(const SwFrame &rFrame) const
Definition: frame.hxx:1389
SwFillCursorPos * m_pFill
for automatic filling with tabs etc
Definition: crstate.hxx:134
long GetWidth(const SwRect &rRect) const
Definition: frame.hxx:1359
virtual bool IsReadOnlyAvailable() const
Definition: swcrsr.cxx:151
bool IsLayoutFrame() const
Definition: frame.hxx:1148
void Left(const long nLeft)
Definition: swrect.hxx:195
static void Add(SwRegionRects &rRegion, const SwRect &rRect)
Definition: trvlfrm.cxx:1976
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:80
void Bottom(const long nBottom)
Definition: swrect.hxx:209
const SwContentNode * GetNode() const
Definition: notxtfrm.hxx:66
SwFlyFrame * GetFlyFrame()
Definition: dflyobj.hxx:130
SwContentFrame * FindLastBodyContent()
Searches the last ContentFrame in BodyText below the page.
Definition: findfrm.cxx:51
SwRowFrame * GetFirstNonHeadlineRow() const
Definition: tabfrm.cxx:5432
SwContentFrame *(* SwPosPage)(const SwLayoutFrame *)
Definition: cshtyp.hxx:38
const SvxOpaqueItem & GetOpaque(bool=true) const
Definition: frmatr.hxx:80
general base class for all free-flowing frames
Definition: flyfrm.hxx:60
bool IsFrameInTableSel(const SwRect &rUnion, const SwFrame *pCell)
Definition: tblsel.cxx:670
bool IsRightPageByNumber(SwRootFrame const &rLayout, sal_uInt16 nPageNum)
Definition: frmtool.cxx:2970
sal_uInt16 SetCurrPage(SwCursor *, sal_uInt16 nPageNum)
Returns a PaM which sits at the beginning of the requested page.
Definition: trvlfrm.cxx:995
virtual SwFrameFormat & GetFrameFormat()=0
bool GetFrameInPage(const SwContentFrame *pCnt, SwWhichPage fnWhichPage, SwPosPage fnPosPage, SwPaM *pPam)
Returns the first/last Contentframe (controlled using the parameter fnPosPage) of the current/previou...
Definition: trvlfrm.cxx:1092
sal_uInt16 GetPhyPageNum() const
Definition: trvlfrm.cxx:1693
const SwViewOption * GetViewOptions() const
Definition: viewsh.hxx:424
void Width(long nNew)
Definition: swrect.hxx:187
virtual bool GetModelPositionForViewPoint(SwPosition *, Point &, SwCursorMoveState *=nullptr, bool bTestBackground=false) const override
Searches the ContentFrame owning the PrtArea containing the point.
Definition: trvlfrm.cxx:150
std::vector< SwSelUnion > SwSelUnions
Definition: tblsel.hxx:138
sal_Int32 GetIndex() const
Definition: index.hxx:95
bool IsInside(const Point &rPOINT) const
Definition: swrect.cxx:105
SwFrameFormat * GetRightFormat(bool const bFirst=false)
Layout uses the following methods to obtain a format in order to be able to create a page...
Definition: pagedesc.cxx:369
bool IsNoTextFrame() const
Definition: frame.hxx:1216
Item2Range GetItemSurrogates(sal_uInt16 nWhich) const
bool IsRightToLeft() const
Definition: frame.hxx:965
::sw::DocumentSettingManager & GetDocumentSettingManager()
Definition: doc.cxx:185
SwTableBox is one table cell in the document model.
Definition: swtable.hxx:386
SwFrame * GetLower()
Definition: findfrm.cxx:169
bool IsPageFrame() const
Definition: frame.hxx:1156
const Point & GetPtPos() const
Definition: viscrs.hxx:142
void SetRight(SwRect &rRect, long nNew) const
Definition: frame.hxx:1367
CursorMoveState m_eState
Definition: crstate.hxx:138
bool m_bPosMatchesBounds
GetModelPositionForViewPoint should not return the next position if screen position is inside second ...
Definition: crstate.hxx:152
bool OnFirstPage() const
Definition: trvlfrm.cxx:1766
const SwTabFrame * GetFollow() const
Definition: tabfrm.hxx:243
bool Contains(const SwAnchoredObject &_rAnchoredObj) const
Definition: sortedobjs.cxx:244
const Point & GetEndPos() const
Definition: viscrs.hxx:148
virtual void Calc(vcl::RenderContext *pRenderContext) const override
Definition: fly.cxx:2810
long GetTop(const SwRect &rRect) const
Definition: frame.hxx:1355
void ActualizeSelection(const SwSelBoxes &rBoxes)
Definition: swcrsr.cxx:2493
const SvxProtectItem & GetProtect(bool=true) const
Definition: frmatr.hxx:82
A layout frame is a frame that contains other frames (m_pLower), e.g. SwPageFrame or SwTabFrame...
Definition: layfrm.hxx:35
const SwFrame * GetAnchorFrame() const
const SwLayoutFrame * GetNextLayoutLeaf() const
Definition: frame.hxx:998
Point GetPagePos(sal_uInt16 nPageNum) const
Returns the absolute document position of the desired page.
Definition: trvlfrm.cxx:1572
std::pair< const_iterator, bool > insert(Value &&x)
bool IsFootnoteContFrame() const
Definition: frame.hxx:1176
bool IsOver(const SwRect &rRect) const
Definition: swrect.cxx:123
const SwContentFrame * ContainsContent() const
Checks if the frame contains one or more ContentFrame's anywhere in his subsidiary structure; if so t...
Definition: findfrm.cxx:66
Point GetNextPrevContentPos(const Point &rPoint, bool bNext) const
Search the nearest Content to the passed point.
Definition: trvlfrm.cxx:1473
SwTableLine * GetUpper()
Definition: swtable.hxx:421
SwViewShell * GetCurrShell() const
Definition: rootfrm.hxx:204
o3tl::strong_int< sal_Int32, struct Tag_TextFrameIndex > TextFrameIndex
Denotes a character index in a text frame at a layout level, after extent mapping from a text node at...
class for collecting anchored objects
Definition: sortedobjs.hxx:48
bool NewTableSelection()
Definition: swcrsr.cxx:2472
const SwContentFrame * GetContentPos(Point &rPoint, const bool bDontLeave, const bool bBodyOnly=false, SwCursorMoveState *pCMS=nullptr, const bool bDefaultExpand=true) const
Finds the closest Content for the SPoint Is used for Pages, Flys and Cells if GetModelPositionForView...
Definition: trvlfrm.cxx:1184
bool IsTextNode() const
Definition: node.hxx:636
SwPosition MapViewToModelPos(TextFrameIndex nIndex) const
Definition: txtfrm.cxx:1233
bool IsClickable() const
Is this field clickable?
Definition: fldbas.cxx:797
sal_uInt16 GetPageNum() const
Definition: rootfrm.hxx:307
bool IsFooterFrame() const
Definition: frame.hxx:1172
static const SwContentFrame * lcl_GetPrvCnt(const SwContentFrame *pCnt)
Definition: trvlfrm.cxx:638
SwRootFrame * getRootFrame()
Definition: frame.hxx:659
virtual bool GetModelPositionForViewPoint(SwPosition *, Point &, SwCursorMoveState *=nullptr, bool bTestBackground=false) const override
If this is about a Content-carrying cell the Cursor will be force inserted into one of the ContentFra...
Definition: trvlfrm.cxx:470
SwCellFrame is one table cell in the document layout.
Definition: cellfrm.hxx:30
bool IsCallbackActionEnabled() const
Definition: rootfrm.hxx:382
sal_uInt16 nPos
const SwAttrPool & GetAttrPool() const
Definition: doc.hxx:1315
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:836
bool IsHeaderFrame() const
Definition: frame.hxx:1168
virtual bool FillSelection(SwSelectionList &rList, const SwRect &rRect) const override
Definition: trvlfrm.cxx:365
bool IsInHeadline(const SwFrame &rFrame) const
Definition: tabfrm.cxx:5413
virtual const SwFrameFormat * GetFormat() const
Definition: ssfrm.cxx:393
bool IsProtected() const
Is the Frame or rather the Section in which it lies protected?
Definition: trvlfrm.cxx:1626
SwTabFrame * FindTabFrame()
Definition: frame.hxx:1077
SwFrame * GetNext()
Definition: frame.hxx:656
void setHeight(long nHeight)