LibreOffice Module sw (master)  1
viscrs.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 <config_features.h>
21 
22 #include <vcl/weld.hxx>
23 #include <vcl/svapp.hxx>
24 #include <vcl/settings.hxx>
25 #include <viewopt.hxx>
26 #include <frmtool.hxx>
27 #include <viscrs.hxx>
28 #include <crsrsh.hxx>
29 #include <doc.hxx>
30 #include <swtable.hxx>
31 #include <viewimp.hxx>
32 #include <dview.hxx>
33 #include <rootfrm.hxx>
34 #include <txtfrm.hxx>
35 #include <ndtxt.hxx>
36 #include <txtfld.hxx>
37 #include <scriptinfo.hxx>
38 #include <view.hxx>
40 
42 #include <svx/sdrpaintwindow.hxx>
43 #include <svx/srchdlg.hxx>
45 #include "overlayrangesoutline.hxx"
46 
47 #include <memory>
48 
49 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
50 #include <comphelper/lok.hxx>
51 #include <sfx2/lokhelper.hxx>
52 #include <comphelper/string.hxx>
53 #include <paintfrm.hxx>
54 #include <PostItMgr.hxx>
55 
56 #include <cellfrm.hxx>
57 
58 // Here static members are defined. They will get changed on alteration of the
59 // MapMode. This is done so that on ShowCursor the same size does not have to be
60 // expensively determined again and again.
61 
65 
66 // Starting from here: classes / methods for the non-text-cursor
68  : m_pCursorShell( pCShell )
69  , m_nPageLastTime(0)
70 {
71  pCShell->GetWin()->SetCursor( &m_aTextCursor );
73  m_bIsDragCursor = false;
75 }
76 
78 {
81 
82  m_pCursorShell->GetWin()->SetCursor( nullptr );
83 }
84 
86 {
87  if( !m_bIsVisible )
88  {
89  m_bIsVisible = true;
90 
91  // display at all?
93  SetPosAndShow(nullptr);
94  }
95 }
96 
98 {
99  if( m_bIsVisible )
100  {
101  m_bIsVisible = false;
102 
103  if( m_aTextCursor.IsVisible() ) // Shouldn't the flags be in effect?
105  }
106 }
107 
109 {
110  SwRect aRect;
111  long nTmpY = m_pCursorShell->m_aCursorHeight.getY();
112  if( 0 > nTmpY )
113  {
114  nTmpY = -nTmpY;
116  aRect = SwRect( m_pCursorShell->m_aCharRect.Pos(),
117  Size( m_pCursorShell->m_aCharRect.Height(), nTmpY ) );
118  aRect.Pos().setX(aRect.Pos().getX() + m_pCursorShell->m_aCursorHeight.getX());
120  aRect.Pos().setY(aRect.Pos().getY() + aRect.Width());
121  }
122  else
123  {
125  aRect = SwRect( m_pCursorShell->m_aCharRect.Pos(),
126  Size( m_pCursorShell->m_aCharRect.Width(), nTmpY ) );
127  aRect.Pos().setY(aRect.Pos().getY() + m_pCursorShell->m_aCursorHeight.getX());
128  }
129 
130  // check if cursor should show the current cursor bidi level
132  const SwCursor* pTmpCursor = m_pCursorShell->GetCursor_();
133 
134  if ( pTmpCursor && !m_pCursorShell->IsOverwriteCursor() )
135  {
136  SwNode& rNode = pTmpCursor->GetPoint()->nNode.GetNode();
137  if( rNode.IsTextNode() )
138  {
139  const SwTextNode& rTNd = *rNode.GetTextNode();
140  const SwFrame* pFrame = rTNd.getLayoutFrame(m_pCursorShell->GetLayout(), nullptr, nullptr);
141  if ( pFrame )
142  {
143  const SwScriptInfo* pSI = static_cast<const SwTextFrame*>(pFrame)->GetScriptInfo();
144  // cursor level has to be shown
145  if ( pSI && pSI->CountDirChg() > 1 )
146  {
148  ( pTmpCursor->GetCursorBidiLevel() % 2 ) ?
149  CursorDirection::RTL :
150  CursorDirection::LTR );
151  }
152  if ( pFrame->IsRightToLeft() )
153  {
154  const OutputDevice *pOut = m_pCursorShell->GetOut();
155  if ( pOut )
156  {
157  long nSize = pOut->GetSettings().GetStyleSettings().GetCursorSize();
158  Size aSize( nSize, nSize );
159  aSize = pOut->PixelToLogic( aSize );
160  aRect.Left( aRect.Left() - aSize.Width() );
161  }
162  }
163  }
164  }
165  }
166 
167  if( aRect.Height())
168  {
170 
171  // Disable pixel alignment when tiled rendering, so that twip values of
172  // the cursor don't depend on statics.
174  ::SwAlignRect( aRect, static_cast<SwViewShell const *>(m_pCursorShell), m_pCursorShell->GetOut() );
175  }
178  aRect.Width( 0 );
179 
180  m_aTextCursor.SetSize( aRect.SSize() );
181 
182  m_aTextCursor.SetPos( aRect.Pos() );
183 
184  bool bPostItActive = false;
185  if (auto pView = dynamic_cast<SwView*>(m_pCursorShell->GetSfxViewShell()))
186  {
187  if (SwPostItMgr* pPostItMgr = pView->GetPostItMgr())
188  bPostItActive = pPostItMgr->GetActiveSidebarWin() != nullptr;
189  }
190 
191  if (comphelper::LibreOfficeKit::isActive() && !bPostItActive)
192  {
193  // notify about page number change (if that happened)
194  sal_uInt16 nPage, nVirtPage;
195  // bCalcFrame=false is important to avoid calculating the layout when
196  // we're in the middle of doing that already.
197  const_cast<SwCursorShell*>(m_pCursorShell)->GetPageNum(nPage, nVirtPage, /*bAtCursorPos=*/true, /*bCalcFrame=*/false);
198  if (nPage != m_nPageLastTime)
199  {
200  m_nPageLastTime = nPage;
201  OString aPayload = OString::number(nPage - 1);
202  m_pCursorShell->GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_SET_PART, aPayload.getStr());
203  }
204 
205  // notify about the cursor position & size
206  tools::Rectangle aSVRect(aRect.Pos().getX(), aRect.Pos().getY(), aRect.Pos().getX() + aRect.SSize().Width(), aRect.Pos().getY() + aRect.SSize().Height());
207  OString sRect = aSVRect.toString();
208  if (pViewShell)
209  {
210  if (pViewShell == m_pCursorShell->GetSfxViewShell())
211  {
213  }
214  else
215  SfxLokHelper::notifyOtherView(m_pCursorShell->GetSfxViewShell(), pViewShell, LOK_CALLBACK_INVALIDATE_VIEW_CURSOR, "rectangle", sRect);
216  }
217  else
218  {
220  SfxLokHelper::notifyOtherViews(m_pCursorShell->GetSfxViewShell(), LOK_CALLBACK_INVALIDATE_VIEW_CURSOR, "rectangle", sRect);
221  }
222  }
223 
225  {
226  if ( m_pCursorShell->GetDrawView() )
227  const_cast<SwDrawView*>(static_cast<const SwDrawView*>(m_pCursorShell->GetDrawView()))->SetAnimationEnabled(
229 
230  sal_uInt16 nStyle = m_bIsDragCursor ? CURSOR_SHADOW : 0;
231  if( nStyle != m_aTextCursor.GetStyle() )
232  {
233  m_aTextCursor.SetStyle( nStyle );
235  }
236 
238  }
239 }
240 
242  : SwRects()
243  , m_pCursorShell( &rCSh )
244 #if HAVE_FEATURE_DESKTOP
245  , m_bShowTextInputFieldOverlay(true)
246 #endif
247 {
248 }
249 
251 {
252  Hide();
253 }
254 
256 {
257  SwRects::swap(rSwap);
258 
259 #if HAVE_FEATURE_DESKTOP
260  // #i75172# also swap m_pCursorOverlay
261  std::swap(m_pCursorOverlay, rSwap.m_pCursorOverlay);
264 #endif
265 }
266 
268 {
269 #if HAVE_FEATURE_DESKTOP
270  m_pCursorOverlay.reset();
271  m_pTextInputFieldOverlay.reset();
272 #endif
273 
274  SwRects::clear();
275 }
276 
285 static SwRect lcl_getLayoutRect(const Point& rPoint, const SwPosition& rPosition)
286 {
287  const SwContentNode* pNode = rPosition.nNode.GetNode().GetContentNode();
288  std::pair<Point, bool> const tmp(rPoint, true);
289  const SwContentFrame* pFrame = pNode->getLayoutFrame(
291  &rPosition, &tmp);
292  SwRect aRect;
293  pFrame->GetCharRect(aRect, rPosition);
294  return aRect;
295 }
296 
297 void SwShellCursor::FillStartEnd(SwRect& rStart, SwRect& rEnd) const
298 {
299  const SwShellCursor* pCursor = GetShell()->getShellCursor(false);
300  rStart = lcl_getLayoutRect(pCursor->GetSttPos(), *pCursor->Start());
301  rEnd = lcl_getLayoutRect(pCursor->GetEndPos(), *pCursor->End());
302 }
303 
304 void SwSelPaintRects::Show(std::vector<OString>* pSelectionRectangles)
305 {
306  SdrView *const pView = const_cast<SdrView*>(m_pCursorShell->GetDrawView());
307 
308  if(pView && pView->PaintWindowCount())
309  {
310  // reset rects
311  SwRects::clear();
312  FillRects();
313 
314 #if HAVE_FEATURE_DESKTOP
315  // get new rects
316  std::vector< basegfx::B2DRange > aNewRanges;
317  aNewRanges.reserve(size());
318  for(size_type a = 0; a < size(); ++a)
319  {
320  const SwRect aNextRect((*this)[a]);
321  const tools::Rectangle aPntRect(aNextRect.SVRect());
322 
323  aNewRanges.emplace_back(
324  aPntRect.Left(), aPntRect.Top(),
325  aPntRect.Right() + 1, aPntRect.Bottom() + 1);
326  }
327 
328  if (m_pCursorOverlay)
329  {
330  if(!aNewRanges.empty())
331  {
332  static_cast<sdr::overlay::OverlaySelection*>(m_pCursorOverlay.get())->setRanges(aNewRanges);
333  }
334  else
335  {
336  m_pCursorOverlay.reset();
337  }
338  }
339  else if(!empty())
340  {
341  SdrPaintWindow* pCandidate = pView->GetPaintWindow(0);
342  const rtl::Reference< sdr::overlay::OverlayManager >& xTargetOverlay = pCandidate->GetOverlayManager();
343 
344  if (xTargetOverlay.is())
345  {
346  // get the system's highlight color
347  const SvtOptionsDrawinglayer aSvtOptionsDrawinglayer;
348  const Color aHighlight(aSvtOptionsDrawinglayer.getHilightColor());
349 
350  // create correct selection
351  m_pCursorOverlay.reset( new sdr::overlay::OverlaySelection(
353  aHighlight,
354  aNewRanges,
355  true) );
356 
357  xTargetOverlay->add(*m_pCursorOverlay);
358  }
359  }
360 
362 #endif
363 
364  // Tiled editing does not expose the draw and writer cursor, it just
365  // talks about "the" cursor at the moment. As long as that's true,
366  // don't say anything about the Writer cursor till a draw object is
367  // being edited.
369  {
370  // If pSelectionRectangles is set, we're just collecting the text selections -> don't emit start/end.
371  if (!empty() && !pSelectionRectangles)
372  {
373  // The selection may be a complex polygon, emit the logical
374  // start/end cursor rectangle of the selection as separate
375  // events, if there is a real selection.
376  // This can be used to easily show selection handles on the
377  // client side.
378  SwRect aStartRect;
379  SwRect aEndRect;
380  FillStartEnd(aStartRect, aEndRect);
381 
382  if (aStartRect.HasArea())
383  {
384  OString sRect = aStartRect.SVRect().toString();
385  GetShell()->GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_TEXT_SELECTION_START, sRect.getStr());
386  }
387  if (aEndRect.HasArea())
388  {
389  OString sRect = aEndRect.SVRect().toString();
390  GetShell()->GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_TEXT_SELECTION_END, sRect.getStr());
391  }
392  }
393 
394  std::vector<OString> aRect;
395  aRect.reserve(size());
396  for (size_type i = 0; i < size(); ++i)
397  {
398  const SwRect& rRect = (*this)[i];
399  aRect.push_back(rRect.SVRect().toString());
400  }
401  OString sRect = comphelper::string::join("; ", aRect);
402  if (!pSelectionRectangles)
403  {
404  GetShell()->GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_TEXT_SELECTION, sRect.getStr());
405  SfxLokHelper::notifyOtherViews(GetShell()->GetSfxViewShell(), LOK_CALLBACK_TEXT_VIEW_SELECTION, "selection", sRect);
406  }
407  else
408  pSelectionRectangles->push_back(sRect);
409  }
410  }
411 }
412 
414 {
415  std::vector< basegfx::B2DRange > aInputFieldRanges;
416 
418  {
419  SwTextInputField* pCurTextInputFieldAtCursor =
420  dynamic_cast<SwTextInputField*>(SwCursorShell::GetTextFieldAtPos( GetShell()->GetCursor()->Start(), false ));
421  if ( pCurTextInputFieldAtCursor != nullptr )
422  {
423  SwTextNode* pTextNode = pCurTextInputFieldAtCursor->GetpTextNode();
424  std::unique_ptr<SwShellCursor> pCursorForInputTextField(
425  new SwShellCursor( *GetShell(), SwPosition( *pTextNode, pCurTextInputFieldAtCursor->GetStart() ) ) );
426  pCursorForInputTextField->SetMark();
427  pCursorForInputTextField->GetMark()->nNode = *pTextNode;
428  pCursorForInputTextField->GetMark()->nContent.Assign( pTextNode, *(pCurTextInputFieldAtCursor->End()) );
429 
430  pCursorForInputTextField->FillRects();
431  SwRects* pRects = static_cast<SwRects*>(pCursorForInputTextField.get());
432  for (const SwRect & rNextRect : *pRects)
433  {
434  const tools::Rectangle aPntRect(rNextRect.SVRect());
435 
436  aInputFieldRanges.emplace_back(
437  aPntRect.Left(), aPntRect.Top(),
438  aPntRect.Right() + 1, aPntRect.Bottom() + 1);
439  }
440  }
441  }
442 
443  if ( !aInputFieldRanges.empty() )
444  {
445  if (m_pTextInputFieldOverlay != nullptr)
446  {
447  m_pTextInputFieldOverlay->setRanges( aInputFieldRanges );
448  }
449  else
450  {
451  SdrView* pView = const_cast<SdrView*>(GetShell()->GetDrawView());
452  SdrPaintWindow* pCandidate = pView->GetPaintWindow(0);
453  const rtl::Reference<sdr::overlay::OverlayManager>& xTargetOverlay = pCandidate->GetOverlayManager();
454 
455  if (xTargetOverlay.is())
456  {
457  // use system's highlight color with decreased luminance as highlight color
458  const SvtOptionsDrawinglayer aSvtOptionsDrawinglayer;
459  Color aHighlight(aSvtOptionsDrawinglayer.getHilightColor());
460  aHighlight.DecreaseLuminance( 128 );
461 
463  aHighlight, aInputFieldRanges ) );
464  xTargetOverlay->add( *m_pTextInputFieldOverlay );
465  }
466  }
467  }
468  else
469  {
470  m_pTextInputFieldOverlay.reset();
471  }
472 }
473 
475 {
476  size_type nSz = size();
477  if( !nSz )
478  return;
479 
480  SwRegionRects aReg( GetShell()->VisArea() );
481  aReg.assign( begin(), end() );
482  aReg -= rRect;
483  SwRects::erase( begin(), begin() + nSz );
484  SwRects::insert( begin(), aReg.begin(), aReg.end() );
485 
486  // If the selection is to the right or at the bottom, outside the
487  // visible area, it is never aligned on one pixel at the right/bottom.
488  // This has to be determined here and if that is the case the
489  // rectangle has to be expanded.
490  if( GetShell()->m_bVisPortChgd && 0 != ( nSz = size()) )
491  {
493  iterator it = begin();
494  for( ; nSz--; ++it )
495  {
496  SwRect& rRectIt = *it;
497  if( rRectIt.Right() == GetShell()->m_aOldRBPos.X() )
498  rRectIt.Right( rRectIt.Right() + s_nPixPtX );
499  if( rRectIt.Bottom() == GetShell()->m_aOldRBPos.Y() )
500  rRectIt.Bottom( rRectIt.Bottom() + s_nPixPtY );
501  }
502  }
503 }
504 
505 // check current MapMode of the shell and set possibly the static members.
506 // Optional set the parameters pX, pY
508  long* pX, long* pY )
509 {
510  const OutputDevice* pOut = rSh.GetWin();
511  if ( ! pOut )
512  pOut = rSh.GetOut();
513 
514  const MapMode& rMM = pOut->GetMapMode();
515  if (s_pMapMode->GetMapUnit() != rMM.GetMapUnit() ||
516  s_pMapMode->GetScaleX() != rMM.GetScaleX() ||
517  s_pMapMode->GetScaleY() != rMM.GetScaleY())
518  {
519  *s_pMapMode = rMM;
520  Size aTmp( 1, 1 );
521  aTmp = pOut->PixelToLogic( aTmp );
522  s_nPixPtX = aTmp.Width();
523  s_nPixPtY = aTmp.Height();
524  }
525  if( pX )
526  *pX = s_nPixPtX;
527  if( pY )
528  *pY = s_nPixPtY;
529 }
530 
532  const SwCursorShell& rCShell,
533  const SwPosition &rPos )
534  : SwCursor(rPos,nullptr)
535  , SwSelPaintRects(rCShell)
536  , m_pInitialPoint(SwPaM::GetPoint())
537 {}
538 
540  const SwCursorShell& rCShell,
541  const SwPosition &rPos,
542  const Point& rPtPos,
543  SwPaM* pRing )
544  : SwCursor(rPos, pRing)
545  , SwSelPaintRects(rCShell)
546  , m_MarkPt(rPtPos)
547  , m_PointPt(rPtPos)
548  , m_pInitialPoint(SwPaM::GetPoint())
549 {}
550 
552  : SwCursor(rICursor, &rICursor)
553  , SwSelPaintRects(*rICursor.GetShell())
554  , m_MarkPt(rICursor.GetMkPos())
555  , m_PointPt(rICursor.GetPtPos())
556  , m_pInitialPoint(SwPaM::GetPoint())
557 {}
558 
560 {}
561 
563 {
564  return GetShell()->IsReadOnlyAvailable();
565 }
566 
568 {
571  else
573  SwPaM::SetMark();
574 }
575 
577 {
578  // calculate the new rectangles
579  if( HasMark() &&
580  GetPoint()->nNode.GetNode().IsContentNode() &&
581  GetPoint()->nNode.GetNode().GetContentNode()->getLayoutFrame( GetShell()->GetLayout() ) &&
582  (GetMark()->nNode == GetPoint()->nNode ||
584  GetMark()->nNode.GetNode().GetContentNode()->getLayoutFrame( GetShell()->GetLayout() ) ) ))
585  GetShell()->GetLayout()->CalcFrameRects( *this );
586 }
587 
588 void SwShellCursor::Show(SfxViewShell const * pViewShell)
589 {
590  std::vector<OString> aSelectionRectangles;
591  for(SwPaM& rPaM : GetRingContainer())
592  {
593  SwShellCursor* pShCursor = dynamic_cast<SwShellCursor*>(&rPaM);
594  if(pShCursor)
595  pShCursor->SwSelPaintRects::Show(&aSelectionRectangles);
596  }
597 
599  {
600  std::vector<OString> aRect;
601  for (const OString & rSelectionRectangle : aSelectionRectangles)
602  {
603  if (rSelectionRectangle.isEmpty())
604  continue;
605  aRect.push_back(rSelectionRectangle);
606  }
607  OString sRect = comphelper::string::join("; ", aRect);
608  if (pViewShell)
609  {
610  // Just notify pViewShell about our existing selection.
611  if (pViewShell != GetShell()->GetSfxViewShell())
612  SfxLokHelper::notifyOtherView(GetShell()->GetSfxViewShell(), pViewShell, LOK_CALLBACK_TEXT_VIEW_SELECTION, "selection", sRect);
613  }
614  else
615  {
616  GetShell()->GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_TEXT_SELECTION, sRect.getStr());
617  SfxLokHelper::notifyOtherViews(GetShell()->GetSfxViewShell(), LOK_CALLBACK_TEXT_VIEW_SELECTION, "selection", sRect);
618  }
619  }
620 }
621 
622 // This rectangle gets painted anew, therefore the SSelection in this
623 // area is invalid.
624 void SwShellCursor::Invalidate( const SwRect& rRect )
625 {
626  for(SwPaM& rPaM : GetRingContainer())
627  {
628  SwShellCursor* pShCursor = dynamic_cast<SwShellCursor*>(&rPaM);
629  // skip any non SwShellCursor objects in the ring
630  // see also: SwAutoFormat::DeleteSel()
631  if(pShCursor)
632  pShCursor->SwSelPaintRects::Invalidate(rRect);
633  }
634 }
635 
637 {
638  for(SwPaM& rPaM : GetRingContainer())
639  {
640  SwShellCursor* pShCursor = dynamic_cast<SwShellCursor*>(&rPaM);
641  if(pShCursor)
642  pShCursor->SwSelPaintRects::Hide();
643  }
644 }
645 
647 {
648  return new SwShellCursor( *GetShell(), *GetPoint(), GetPtPos(), pRing );
649 }
650 
652 {
653  short nRet = RET_YES;
655  if( pDlg )
656  {
657  // Terminate old actions. The table-frames get constructed and
658  // a SSelection can be created.
659  std::vector<sal_uInt16> vActionCounts;
660  for(SwViewShell& rShell : const_cast< SwCursorShell* >( GetShell() )->GetRingContainer())
661  {
662  sal_uInt16 nActCnt = 0;
663  while(rShell.ActionPend())
664  {
665  rShell.EndAction();
666  ++nActCnt;
667  }
668  vActionCounts.push_back(nActCnt);
669  }
670  std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(pDlg->getDialog(), "modules/swriter/ui/asksearchdialog.ui"));
671  std::unique_ptr<weld::MessageDialog> xDialog(xBuilder->weld_message_dialog("AskSearchDialog"));
672  nRet = xDialog->run();
673  auto pActionCount = vActionCounts.begin();
674  for(SwViewShell& rShell : const_cast< SwCursorShell* >( GetShell() )->GetRingContainer())
675  {
676  while(*pActionCount)
677  {
678  rShell.StartAction();
679  --(*pActionCount);
680  }
681  ++pActionCount;
682  }
683  }
684  else
685  // otherwise from the Basic, and then switch to RET_YES
686  nRet = RET_YES;
687 
688  return nRet;
689 }
690 
692 {
693  const_cast<SwCursorShell*>(GetShell())->SaveTableBoxContent( pPos );
694 }
695 
696 bool SwShellCursor::UpDown( bool bUp, sal_uInt16 nCnt )
697 {
698  return SwCursor::UpDown( bUp, nCnt,
699  &GetPtPos(), GetShell()->GetUpDownX(),
700  *GetShell()->GetLayout());
701 }
702 
703 // if <true> than the cursor can be set to the position.
704 bool SwShellCursor::IsAtValidPos( bool bPoint ) const
705 {
706  if( GetShell() && ( GetShell()->IsAllProtect() ||
707  GetShell()->GetViewOptions()->IsReadonly() ||
708  ( GetShell()->Imp()->GetDrawView() &&
709  GetShell()->Imp()->GetDrawView()->GetMarkedObjectList().GetMarkCount() )))
710  return true;
711 
712  return SwCursor::IsAtValidPos( bPoint );
713 }
714 
716  const SwPosition& rPos )
717  : SwCursor(rPos,nullptr), SwShellCursor(rCursorSh, rPos), SwTableCursor(rPos)
718 {
719 }
720 
722  const SwPosition& rMkPos, const Point& rMkPt,
723  const SwPosition& rPtPos, const Point& rPtPt )
724  : SwCursor(rPtPos,nullptr), SwShellCursor(rCursorSh, rPtPos), SwTableCursor(rPtPos)
725 {
726  SetMark();
727  *GetMark() = rMkPos;
728  GetMkPos() = rMkPt;
729  GetPtPos() = rPtPt;
730 }
731 
733 
735 
737 {
738  return SwShellCursor::Create( pRing );
739 }
740 
742 {
744 }
745 
747 {
749 }
750 
752 {
753  // Calculate the new rectangles. If the cursor is still "parked" do nothing
755  return;
756 
757  bool bStart = true;
758  SwRegionRects aReg( GetShell()->VisArea() );
761  SwNodes& rNds = GetDoc()->GetNodes();
762  SwFrame* pEndFrame = nullptr;
763  for (size_t n = 0; n < m_SelectedBoxes.size(); ++n)
764  {
765  const SwStartNode* pSttNd = m_SelectedBoxes[n]->GetSttNd();
766  const SwTableNode* pSelTableNd = pSttNd->FindTableNode();
767 
768  SwNodeIndex aIdx( *pSttNd );
769  SwContentNode* pCNd = rNds.GoNextSection( &aIdx, true, false );
770 
771  // table in table
772  // (see also lcl_FindTopLevelTable in unoobj2.cxx for a different
773  // version to do this)
774  const SwTableNode* pCurTableNd = pCNd ? pCNd->FindTableNode() : nullptr;
775  while ( pSelTableNd != pCurTableNd && pCurTableNd )
776  {
777  aIdx = pCurTableNd->EndOfSectionIndex();
778  pCNd = rNds.GoNextSection( &aIdx, true, false );
779  pCurTableNd = pCNd->FindTableNode();
780  }
781 
782  if( !pCNd )
783  continue;
784 
785  std::pair<Point, bool> const tmp(GetSttPos(), true);
786  SwFrame* pFrame = pCNd->getLayoutFrame(GetShell()->GetLayout(), nullptr, &tmp);
787  while( pFrame && !pFrame->IsCellFrame() )
788  pFrame = pFrame->GetUpper();
789 
790  OSL_ENSURE( pFrame, "Node not in a table" );
791 
792  while ( pFrame )
793  {
794  if( aReg.GetOrigin().IsOver( pFrame->getFrameArea() ) )
795  {
796  aReg -= pFrame->getFrameArea();
797  if (bStart)
798  {
799  bStart = false;
800  m_aStart = SwRect(pFrame->getFrameArea().Left(), pFrame->getFrameArea().Top(), 1, pFrame->getFrameArea().Height());
801  }
802  }
803 
804  pEndFrame = pFrame;
805  pFrame = pFrame->GetNextCellLeaf();
806  }
807  }
808  if (pEndFrame)
809  m_aEnd = SwRect(pEndFrame->getFrameArea().Right(), pEndFrame->getFrameArea().Top(), 1, pEndFrame->getFrameArea().Height());
810  aReg.Invert();
811  insert( begin(), aReg.begin(), aReg.end() );
812 }
813 
815 {
816  rStart = m_aStart;
817  rEnd = m_aEnd;
818 }
819 
820 // Check if the SPoint is within the Table-SSelection.
821 bool SwShellTableCursor::IsInside( const Point& rPt ) const
822 {
823  // Calculate the new rectangles. If the cursor is still "parked" do nothing
825  return false;
826 
827  SwNodes& rNds = GetDoc()->GetNodes();
828  for (size_t n = 0; n < m_SelectedBoxes.size(); ++n)
829  {
830  SwNodeIndex aIdx( *m_SelectedBoxes[n]->GetSttNd() );
831  SwContentNode* pCNd = rNds.GoNextSection( &aIdx, true, false );
832  if( !pCNd )
833  continue;
834 
835  std::pair<Point, bool> const tmp(GetPtPos(), true);
836  SwFrame* pFrame = pCNd->getLayoutFrame(GetShell()->GetLayout(), nullptr, &tmp);
837  while( pFrame && !pFrame->IsCellFrame() )
838  pFrame = pFrame->GetUpper();
839  OSL_ENSURE( pFrame, "Node not in a table" );
840  if( pFrame && pFrame->getFrameArea().IsInside( rPt ) )
841  return true;
842 
843  for ( SwCellFrame* pCellFrame = static_cast<SwCellFrame*>(pFrame); pCellFrame; pCellFrame = pCellFrame->GetFollowCell() )
844  {
845  if( pCellFrame->getFrameArea().IsInside( rPt ) )
846  return true;
847  }
848  }
849  return false;
850 }
851 
852 bool SwShellTableCursor::IsAtValidPos( bool bPoint ) const
853 {
854  return SwShellCursor::IsAtValidPos( bPoint );
855 }
856 
857 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool m_bIsVisible
Definition: viscrs.hxx:41
vcl::RenderContext * GetOut() const
Definition: viewsh.hxx:341
static SwRect lcl_getLayoutRect(const Point &rPoint, const SwPosition &rPosition)
Return a layout rectangle (typically with minimal width) that represents a cursor at rPosition...
Definition: viscrs.cxx:285
const Fraction & GetScaleX() const
long Width() const
virtual short MaxReplaceArived() override
Definition: viscrs.cxx:741
Starts a section of nodes in the document model.
Definition: node.hxx:303
Base class of the Writer layout elements.
Definition: frame.hxx:295
Represents the visualization of a paragraph.
Definition: txtfrm.hxx:149
void SetOrientation(short nOrientation=0)
Marks a position in the document model.
Definition: pam.hxx:35
static long s_nPixPtY
Definition: viscrs.hxx:72
const SwRect & GetOrigin() const
Definition: swregion.hxx:47
const SwPosition * m_pInitialPoint
Definition: viscrs.hxx:120
SdrView * GetDrawView()
Definition: vnew.cxx:376
void SwCalcPixStatics(vcl::RenderContext const *pOut)
Set borders alignment statics Adjustment for 'small' twip-to-pixel relations: For 'small' twip-to-pix...
Definition: paintfrm.cxx:366
virtual bool IsAtValidPos(bool bPoint=true) const override
Return if cursor can be set to this position.
Definition: viscrs.cxx:704
void SetPos(const Point &rNewPos)
virtual const SwRootFrame * GetCurrentLayout() const =0
rtl::Reference< sdr::overlay::OverlayManager > const & GetOverlayManager() const
long Height() const
SwNodeIndex nNode
Definition: pam.hxx:37
SwShellCursor * getShellCursor(bool bBlock)
Delivers the current shell cursor.
Definition: crsrsh.cxx:2999
sal_uInt16 GetStyle() const
SdrTextObj * GetTextEditObject() const
virtual void SaveTableBoxContent(const SwPosition *pPos) override
Definition: viscrs.cxx:746
const StyleSettings & GetStyleSettings() const
const SwPosition * GetMark() const
Definition: pam.hxx:209
void SetWidth(long nNewWidth)
SwContentFrame * getLayoutFrame(const SwRootFrame *, const SwPosition *pPos=nullptr, std::pair< Point, bool > const *pViewPosAndCalcFrame=nullptr) const
Definition: node.cxx:1148
virtual void SetMark() override
Unless this is called, the getter method of Mark will return Point.
Definition: viscrs.cxx:567
static SvxSearchDialog * GetSearchDialog()
Definition: viewsrch.cxx:860
void Height(long nNew)
Definition: swrect.hxx:189
virtual SwCursor * Create(SwPaM *pRing=nullptr) const override
Definition: viscrs.cxx:736
sal_uInt8 GetCursorBidiLevel() const
Definition: swcrsr.hxx:209
const Point & GetSttPos() const
Definition: viscrs.hxx:144
const MapMode & GetMapMode() const
SwNode & GetNode() const
Definition: ndindex.hxx:118
SwRect m_aEnd
Right edge of the selection end (bottom right cell).
Definition: viscrs.hxx:174
SwTextNode * GetpTextNode() const
Definition: txtfld.hxx:49
void Pos(const Point &rNew)
Definition: swrect.hxx:167
bool m_bVisPortChgd
in VisPortChg-Call
Definition: crsrsh.hxx:213
OString join(const OString &rSeparator, const std::vector< OString > &rSequence)
bool IsCellFrame() const
Definition: frame.hxx:1202
Of course Writer needs its own rectangles.
Definition: swrect.hxx:34
SfxViewShell * GetSfxViewShell() const
Definition: viewsh.hxx:444
static void notifyOtherViews(SfxViewShell *pThisView, int nType, const OString &rKey, const OString &rPayload)
void Hide()
Definition: viscrs.cxx:636
virtual bool IsAtValidPos(bool bPoint=true) const override
Return if cursor can be set to this position.
Definition: viscrs.cxx:852
virtual void SaveTableBoxContent(const SwPosition *pPos) override
Definition: viscrs.cxx:691
void Invalidate(const SwRect &rRect)
Definition: viscrs.cxx:474
bool m_bShowTextInputFieldOverlay
Definition: viscrs.hxx:81
static void notifyVisCursorInvalidation(OutlinerViewShell const *pThisView, const OString &rRectangle)
static long s_nPixPtX
Definition: viscrs.hxx:72
RET_YES
void Top(const long nTop)
Definition: swrect.hxx:202
Point m_PointPt
Definition: viscrs.hxx:119
void SwAlignRect(SwRect &rRect, const SwViewShell *pSh, const vcl::RenderContext *pRenderContext)
Function is also used outside this file.
Definition: paintfrm.cxx:1103
enumrange< T >::Iterator begin(enumrange< T >)
const SwRect & getFrameArea() const
Definition: frame.hxx:175
const Fraction & GetScaleY() const
sal_uLong GetIndex() const
Definition: ndindex.hxx:151
void CalcFrameRects(SwShellCursor &)
Definition: trvlfrm.cxx:2008
void libreOfficeKitViewCallback(int nType, const char *pPayload) const override
sal_Int32 GetStart() const
Definition: txatbase.hxx:82
void Invert()
invert current rectangle
Definition: swregion.cxx:121
virtual void FillRects() override
Definition: viscrs.cxx:751
SwShellTableCursor(const SwCursorShell &rCursorSh, const SwPosition &rPos)
Definition: viscrs.cxx:715
#define CURSOR_SHADOW
Point m_aOldRBPos
Right/Bottom of last VisArea.
Definition: crsrsh.hxx:170
virtual void FillRects() override
Definition: viscrs.cxx:576
void SetStyle(sal_uInt16 nStyle)
void Right(const long nRight)
Definition: swrect.hxx:198
virtual short MaxReplaceArived() override
Definition: viscrs.cxx:651
void Show(SfxViewShell const *pViewShell)
Definition: viscrs.cxx:588
size_type size() const
void Invalidate(const SwRect &rRect)
Definition: viscrs.cxx:624
if(nullptr==pCandidateA||nullptr==pCandidateB)
virtual void FillStartEnd(SwRect &rStart, SwRect &rEnd) const =0
Fill rStart and rEnd with a rectangle that represents the start and end for selection handles...
SwLayoutFrame * GetNextCellLeaf()
Definition: findfrm.cxx:1511
virtual bool GetCharRect(SwRect &, const SwPosition &, SwCursorMoveState *=nullptr, bool bAllowFarAway=true) const
Definition: unusedf.cxx:71
sal_uInt32 PaintWindowCount() const
long getY() const
SwShellCursor * GetCursor_()
Definition: crsrsh.hxx:331
static MapMode * s_pMapMode
Definition: viscrs.hxx:73
long getX() const
SwVisibleCursor(const SwCursorShell *pCShell)
Definition: viscrs.cxx:67
bool IsContentNode() const
Definition: node.hxx:628
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
bool IsSelection() const
Definition: crsrsh.hxx:878
virtual ~SwShellTableCursor() override
Definition: viscrs.cxx:732
const SwCursorShell * m_pCursorShell
Definition: viscrs.hxx:75
const SwCursorShell * GetShell() const
Definition: viscrs.hxx:107
SwShellCursor(const SwCursorShell &rCursorSh, const SwPosition &rPos)
Definition: viscrs.cxx:531
long GetCursorSize() const
void SetPosAndShow(SfxViewShell const *pViewShell)
Definition: viscrs.cxx:108
Shell * GetShell()
void DecreaseLuminance(sal_uInt8 cLumDec)
const SwRect & VisArea() const
Definition: viewsh.cxx:569
const SwPosition * GetPoint() const
Definition: pam.hxx:207
bool UpDown(bool bUp, sal_uInt16 nCnt)
Definition: viscrs.cxx:696
int i
SwContentNode * GetContentNode()
Definition: node.hxx:615
bool HasMark() const
A PaM marks a selection if Point and Mark are distinct positions.
Definition: pam.hxx:205
SwDoc * GetDoc()
Definition: node.hxx:702
SwDoc * GetDoc() const
Definition: pam.hxx:243
SwLayoutFrame * GetUpper()
Definition: frame.hxx:656
virtual ~SwShellCursor() override
Definition: viscrs.cxx:559
bool HasArea() const
Definition: swrect.hxx:290
void Hide()
Definition: viscrs.cxx:97
void SetWindow(vcl::Window *pWindow)
void HighlightInputField()
Definition: viscrs.cxx:413
bool IsCursorReadonly() const
Definition: crsrsh.cxx:3252
virtual void FillStartEnd(SwRect &rStart, SwRect &rEnd) const override
Definition: viscrs.cxx:814
bool IsInside(const Point &rPt) const
Definition: viscrs.cxx:821
virtual void SetMark() override
Unless this is called, the getter method of Mark will return Point.
Definition: viscrs.cxx:734
const Point & GetMkPos() const
Definition: viscrs.hxx:142
size
Marks a node in the document model.
Definition: ndindex.hxx:31
void SetSize(const Size &rNewSize)
const AllSettings & GetSettings() const
bool IsOverwriteCursor() const
Definition: crsrsh.hxx:462
ring_container GetRingContainer()
MapUnit GetMapUnit() const
bool empty() const
void SSize(const Size &rNew)
Definition: swrect.hxx:176
void Show(std::vector< OString > *pSelectionRectangles=nullptr)
Definition: viscrs.cxx:304
SwCellFrame * GetFollowCell() const
Definition: findfrm.cxx:1579
long X() const
const IDocumentLayoutAccess & getIDocumentLayoutAccess() const
Provides access to the document layout interface.
Definition: viewsh.cxx:2597
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:437
enumrange< T >::Iterator end(enumrange< T >)
const SwPosition * Start() const
Definition: pam.hxx:212
SwSelPaintRects(const SwCursorShell &rCSh)
Definition: viscrs.cxx:241
Point PixelToLogic(const Point &rDevicePt) const
virtual void FillStartEnd(SwRect &rStart, SwRect &rEnd) const override
Definition: viscrs.cxx:297
virtual ~SwSelPaintRects()
Definition: viscrs.cxx:250
virtual void FillRects()=0
static void Get1PixelInLogic(const SwViewShell &rSh, long *pX=nullptr, long *pY=nullptr)
Definition: viscrs.cxx:507
void Left(const long nLeft)
Definition: swrect.hxx:193
sal_uLong EndOfSectionIndex() const
Definition: node.hxx:677
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:79
void Bottom(const long nBottom)
Definition: swrect.hxx:207
SwSelBoxes m_SelectedBoxes
Definition: swcrsr.hxx:259
std::vector< SwRect > SwRects
Definition: swregion.hxx:26
bool IsReadOnlyAvailable() const
Definition: crsrsh.hxx:477
tools::Rectangle SVRect() const
Definition: swrect.hxx:282
Point m_aCursorHeight
height & offset from visible Cursor
Definition: crsrsh.hxx:169
bool UpDown(bool bUp, sal_uInt16 nCnt, Point const *pPt, long nUpDownX, SwRootFrame &rLayout)
Definition: swcrsr.cxx:1923
bool m_bIsDragCursor
Definition: viscrs.hxx:42
const SwViewOption * GetViewOptions() const
Definition: viewsh.hxx:426
void SetCursor(vcl::Cursor *pCursor)
void Width(long nNew)
Definition: swrect.hxx:185
static void notifyOtherView(SfxViewShell *pThisView, SfxViewShell const *pOtherView, int nType, const OString &rKey, const OString &rPayload)
vcl::Window * GetWin() const
Definition: viewsh.hxx:340
vcl::Cursor m_aTextCursor
Definition: viscrs.hxx:44
size_t CountDirChg() const
Definition: scriptinfo.hxx:134
bool IsInside(const Point &rPOINT) const
Definition: swrect.cxx:107
SwNodes & GetNodes()
Definition: doc.hxx:402
bool m_bParked
Definition: swcrsr.hxx:261
const SwPosition * End() const
Definition: pam.hxx:217
bool IsRightToLeft() const
Definition: frame.hxx:963
const sal_Int32 * End() const
Definition: txatbase.hxx:148
virtual SwCursor * Create(SwPaM *pRing=nullptr) const override
Definition: viscrs.cxx:646
const Point & GetPtPos() const
Definition: viscrs.hxx:140
bool IsVisible() const
SwTableNode * FindTableNode()
Search table node, in which it is.
Definition: node.cxx:351
void Show()
Definition: viscrs.cxx:85
virtual bool IsAtValidPos(bool bPoint=true) const
Return if cursor can be set to this position.
Definition: swcrsr.cxx:693
const Point & GetEndPos() const
Definition: viscrs.hxx:146
SwRect m_aStart
Left edge of the selection start (top left cell).
Definition: viscrs.hxx:172
static weld::Builder * CreateBuilder(weld::Widget *pParent, const OUString &rUIFile)
SwContentNode * GoNextSection(SwNodeIndex *, bool bSkipHidden=true, bool bSkipProtect=true) const
Go to next content-node that is not protected or hidden (Both set FALSE ==> GoNext/GoPrevious!!!).
Definition: nodes.cxx:1923
sal_uInt16 m_nPageLastTime
For LibreOfficeKit only - remember what page we were at the last time.
Definition: viscrs.hxx:48
virtual void SetMark()
Unless this is called, the getter method of Mark will return Point.
Definition: pam.cxx:455
const SwCursorShell * m_pCursorShell
Definition: viscrs.hxx:45
virtual bool IsReadOnlyAvailable() const override
Definition: viscrs.cxx:562
SwRect m_aCharRect
Char-SRectangle on which the cursor is located.
Definition: crsrsh.hxx:168
Point m_MarkPt
Definition: viscrs.hxx:118
bool IsOver(const SwRect &rRect) const
Definition: swrect.cxx:125
rtl::OString toString() const
SwRootFrame * GetLayout() const
Definition: viewsh.cxx:2071
void swapContent(SwSelPaintRects &rSwap)
Definition: viscrs.cxx:255
void SetDirection(CursorDirection nDirection=CursorDirection::NONE)
bool IsTextNode() const
Definition: node.hxx:636
std::unique_ptr< sw::overlay::OverlayRangesOutline > m_pTextInputFieldOverlay
Definition: viscrs.hxx:82
SdrPaintWindow * GetPaintWindow(sal_uInt32 nIndex) const
SwCellFrame is one table cell in the document layout.
Definition: cellfrm.hxx:30
long Y() const
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:843
bool IsSelectionInReadonly() const
Definition: viewopt.hxx:427
Color getHilightColor() const
static SwTextField * GetTextFieldAtPos(const SwPosition *pPos, const bool bIncludeInputFieldAtStart)
Definition: crstrvl.cxx:879
Base class of the Writer document model elements.
Definition: node.hxx:79