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 {
243  return m_aTextCursor;
244 }
245 
247  : SwRects()
248  , m_pCursorShell( &rCSh )
249 #if HAVE_FEATURE_DESKTOP
250  , m_bShowTextInputFieldOverlay(true)
251 #endif
252 {
253 }
254 
256 {
257  Hide();
258 }
259 
261 {
262  SwRects::swap(rSwap);
263 
264 #if HAVE_FEATURE_DESKTOP
265  // #i75172# also swap m_pCursorOverlay
266  std::swap(m_pCursorOverlay, rSwap.m_pCursorOverlay);
269 #endif
270 }
271 
273 {
274 #if HAVE_FEATURE_DESKTOP
275  m_pCursorOverlay.reset();
276  m_pTextInputFieldOverlay.reset();
277 #endif
278 
279  SwRects::clear();
280 }
281 
290 static SwRect lcl_getLayoutRect(const Point& rPoint, const SwPosition& rPosition)
291 {
292  const SwContentNode* pNode = rPosition.nNode.GetNode().GetContentNode();
293  std::pair<Point, bool> const tmp(rPoint, true);
294  const SwContentFrame* pFrame = pNode->getLayoutFrame(
296  &rPosition, &tmp);
297  SwRect aRect;
298  pFrame->GetCharRect(aRect, rPosition);
299  return aRect;
300 }
301 
302 void SwShellCursor::FillStartEnd(SwRect& rStart, SwRect& rEnd) const
303 {
304  const SwShellCursor* pCursor = GetShell()->getShellCursor(false);
305  rStart = lcl_getLayoutRect(pCursor->GetSttPos(), *pCursor->Start());
306  rEnd = lcl_getLayoutRect(pCursor->GetEndPos(), *pCursor->End());
307 }
308 
309 void SwSelPaintRects::Show(std::vector<OString>* pSelectionRectangles)
310 {
311  SdrView *const pView = const_cast<SdrView*>(m_pCursorShell->GetDrawView());
312 
313  if(pView && pView->PaintWindowCount())
314  {
315  // reset rects
316  SwRects::clear();
317  FillRects();
318 
319 #if HAVE_FEATURE_DESKTOP
320  // get new rects
321  std::vector< basegfx::B2DRange > aNewRanges;
322  aNewRanges.reserve(size());
323  for(size_type a = 0; a < size(); ++a)
324  {
325  const SwRect aNextRect((*this)[a]);
326  const tools::Rectangle aPntRect(aNextRect.SVRect());
327 
328  aNewRanges.emplace_back(
329  aPntRect.Left(), aPntRect.Top(),
330  aPntRect.Right() + 1, aPntRect.Bottom() + 1);
331  }
332 
333  if (m_pCursorOverlay)
334  {
335  if(!aNewRanges.empty())
336  {
337  static_cast<sdr::overlay::OverlaySelection*>(m_pCursorOverlay.get())->setRanges(aNewRanges);
338  }
339  else
340  {
341  m_pCursorOverlay.reset();
342  }
343  }
344  else if(!empty())
345  {
346  SdrPaintWindow* pCandidate = pView->GetPaintWindow(0);
347  const rtl::Reference< sdr::overlay::OverlayManager >& xTargetOverlay = pCandidate->GetOverlayManager();
348 
349  if (xTargetOverlay.is())
350  {
351  // get the system's highlight color
352  const SvtOptionsDrawinglayer aSvtOptionsDrawinglayer;
353  const Color aHighlight(aSvtOptionsDrawinglayer.getHilightColor());
354 
355  // create correct selection
356  m_pCursorOverlay.reset( new sdr::overlay::OverlaySelection(
358  aHighlight,
359  aNewRanges,
360  true) );
361 
362  xTargetOverlay->add(*m_pCursorOverlay);
363  }
364  }
365 
367 #endif
368 
369  // Tiled editing does not expose the draw and writer cursor, it just
370  // talks about "the" cursor at the moment. As long as that's true,
371  // don't say anything about the Writer cursor till a draw object is
372  // being edited.
374  {
375  // If pSelectionRectangles is set, we're just collecting the text selections -> don't emit start/end.
376  if (!empty() && !pSelectionRectangles)
377  {
378  // The selection may be a complex polygon, emit the logical
379  // start/end cursor rectangle of the selection as separate
380  // events, if there is a real selection.
381  // This can be used to easily show selection handles on the
382  // client side.
383  SwRect aStartRect;
384  SwRect aEndRect;
385  FillStartEnd(aStartRect, aEndRect);
386 
387  if (aStartRect.HasArea())
388  {
389  OString sRect = aStartRect.SVRect().toString();
390  GetShell()->GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_TEXT_SELECTION_START, sRect.getStr());
391  }
392  if (aEndRect.HasArea())
393  {
394  OString sRect = aEndRect.SVRect().toString();
395  GetShell()->GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_TEXT_SELECTION_END, sRect.getStr());
396  }
397  }
398 
399  std::vector<OString> aRect;
400  aRect.reserve(size());
401  for (size_type i = 0; i < size(); ++i)
402  {
403  const SwRect& rRect = (*this)[i];
404  aRect.push_back(rRect.SVRect().toString());
405  }
406  OString sRect = comphelper::string::join("; ", aRect);
407  if (!pSelectionRectangles)
408  {
409  GetShell()->GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_TEXT_SELECTION, sRect.getStr());
410  SfxLokHelper::notifyOtherViews(GetShell()->GetSfxViewShell(), LOK_CALLBACK_TEXT_VIEW_SELECTION, "selection", sRect);
411  }
412  else
413  pSelectionRectangles->push_back(sRect);
414  }
415  }
416 }
417 
419 {
420  std::vector< basegfx::B2DRange > aInputFieldRanges;
421 
423  {
424  SwTextInputField* pCurTextInputFieldAtCursor =
425  dynamic_cast<SwTextInputField*>(SwCursorShell::GetTextFieldAtPos( GetShell()->GetCursor()->Start(), false ));
426  if ( pCurTextInputFieldAtCursor != nullptr )
427  {
428  SwTextNode* pTextNode = pCurTextInputFieldAtCursor->GetpTextNode();
429  std::unique_ptr<SwShellCursor> pCursorForInputTextField(
430  new SwShellCursor( *GetShell(), SwPosition( *pTextNode, pCurTextInputFieldAtCursor->GetStart() ) ) );
431  pCursorForInputTextField->SetMark();
432  pCursorForInputTextField->GetMark()->nNode = *pTextNode;
433  pCursorForInputTextField->GetMark()->nContent.Assign( pTextNode, *(pCurTextInputFieldAtCursor->End()) );
434 
435  pCursorForInputTextField->FillRects();
436  SwRects* pRects = static_cast<SwRects*>(pCursorForInputTextField.get());
437  for (const SwRect & rNextRect : *pRects)
438  {
439  const tools::Rectangle aPntRect(rNextRect.SVRect());
440 
441  aInputFieldRanges.emplace_back(
442  aPntRect.Left(), aPntRect.Top(),
443  aPntRect.Right() + 1, aPntRect.Bottom() + 1);
444  }
445  }
446  }
447 
448  if ( !aInputFieldRanges.empty() )
449  {
450  if (m_pTextInputFieldOverlay != nullptr)
451  {
452  m_pTextInputFieldOverlay->setRanges( aInputFieldRanges );
453  }
454  else
455  {
456  SdrView* pView = const_cast<SdrView*>(GetShell()->GetDrawView());
457  SdrPaintWindow* pCandidate = pView->GetPaintWindow(0);
458  const rtl::Reference<sdr::overlay::OverlayManager>& xTargetOverlay = pCandidate->GetOverlayManager();
459 
460  if (xTargetOverlay.is())
461  {
462  // use system's highlight color with decreased luminance as highlight color
463  const SvtOptionsDrawinglayer aSvtOptionsDrawinglayer;
464  Color aHighlight(aSvtOptionsDrawinglayer.getHilightColor());
465  aHighlight.DecreaseLuminance( 128 );
466 
468  aHighlight, aInputFieldRanges ) );
469  xTargetOverlay->add( *m_pTextInputFieldOverlay );
470  }
471  }
472  }
473  else
474  {
475  m_pTextInputFieldOverlay.reset();
476  }
477 }
478 
480 {
481  size_type nSz = size();
482  if( !nSz )
483  return;
484 
485  SwRegionRects aReg( GetShell()->VisArea() );
486  aReg.assign( begin(), end() );
487  aReg -= rRect;
488  SwRects::erase( begin(), begin() + nSz );
489  SwRects::insert( begin(), aReg.begin(), aReg.end() );
490 
491  // If the selection is to the right or at the bottom, outside the
492  // visible area, it is never aligned on one pixel at the right/bottom.
493  // This has to be determined here and if that is the case the
494  // rectangle has to be expanded.
495  if( GetShell()->m_bVisPortChgd && 0 != ( nSz = size()) )
496  {
498  iterator it = begin();
499  for( ; nSz--; ++it )
500  {
501  SwRect& rRectIt = *it;
502  if( rRectIt.Right() == GetShell()->m_aOldRBPos.X() )
503  rRectIt.Right( rRectIt.Right() + s_nPixPtX );
504  if( rRectIt.Bottom() == GetShell()->m_aOldRBPos.Y() )
505  rRectIt.Bottom( rRectIt.Bottom() + s_nPixPtY );
506  }
507  }
508 }
509 
510 // check current MapMode of the shell and set possibly the static members.
511 // Optional set the parameters pX, pY
513  long* pX, long* pY )
514 {
515  const OutputDevice* pOut = rSh.GetWin();
516  if ( ! pOut )
517  pOut = rSh.GetOut();
518 
519  const MapMode& rMM = pOut->GetMapMode();
520  if (s_pMapMode->GetMapUnit() != rMM.GetMapUnit() ||
521  s_pMapMode->GetScaleX() != rMM.GetScaleX() ||
522  s_pMapMode->GetScaleY() != rMM.GetScaleY())
523  {
524  *s_pMapMode = rMM;
525  Size aTmp( 1, 1 );
526  aTmp = pOut->PixelToLogic( aTmp );
527  s_nPixPtX = aTmp.Width();
528  s_nPixPtY = aTmp.Height();
529  }
530  if( pX )
531  *pX = s_nPixPtX;
532  if( pY )
533  *pY = s_nPixPtY;
534 }
535 
537  const SwCursorShell& rCShell,
538  const SwPosition &rPos )
539  : SwCursor(rPos,nullptr)
540  , SwSelPaintRects(rCShell)
541  , m_pInitialPoint(SwPaM::GetPoint())
542 {}
543 
545  const SwCursorShell& rCShell,
546  const SwPosition &rPos,
547  const Point& rPtPos,
548  SwPaM* pRing )
549  : SwCursor(rPos, pRing)
550  , SwSelPaintRects(rCShell)
551  , m_MarkPt(rPtPos)
552  , m_PointPt(rPtPos)
553  , m_pInitialPoint(SwPaM::GetPoint())
554 {}
555 
557  : SwCursor(rICursor, &rICursor)
558  , SwSelPaintRects(*rICursor.GetShell())
559  , m_MarkPt(rICursor.GetMkPos())
560  , m_PointPt(rICursor.GetPtPos())
561  , m_pInitialPoint(SwPaM::GetPoint())
562 {}
563 
565 {}
566 
568 {
569  return GetShell()->IsReadOnlyAvailable();
570 }
571 
573 {
576  else
578  SwPaM::SetMark();
579 }
580 
582 {
583  // calculate the new rectangles
584  if( HasMark() &&
585  GetPoint()->nNode.GetNode().IsContentNode() &&
586  GetPoint()->nNode.GetNode().GetContentNode()->getLayoutFrame( GetShell()->GetLayout() ) &&
587  (GetMark()->nNode == GetPoint()->nNode ||
589  GetMark()->nNode.GetNode().GetContentNode()->getLayoutFrame( GetShell()->GetLayout() ) ) ))
590  GetShell()->GetLayout()->CalcFrameRects( *this );
591 }
592 
593 void SwShellCursor::Show(SfxViewShell const * pViewShell)
594 {
595  std::vector<OString> aSelectionRectangles;
596  for(SwPaM& rPaM : GetRingContainer())
597  {
598  SwShellCursor* pShCursor = dynamic_cast<SwShellCursor*>(&rPaM);
599  if(pShCursor)
600  pShCursor->SwSelPaintRects::Show(&aSelectionRectangles);
601  }
602 
604  {
605  std::vector<OString> aRect;
606  for (const OString & rSelectionRectangle : aSelectionRectangles)
607  {
608  if (rSelectionRectangle.isEmpty())
609  continue;
610  aRect.push_back(rSelectionRectangle);
611  }
612  OString sRect = comphelper::string::join("; ", aRect);
613  if (pViewShell)
614  {
615  // Just notify pViewShell about our existing selection.
616  if (pViewShell != GetShell()->GetSfxViewShell())
617  SfxLokHelper::notifyOtherView(GetShell()->GetSfxViewShell(), pViewShell, LOK_CALLBACK_TEXT_VIEW_SELECTION, "selection", sRect);
618  }
619  else
620  {
621  GetShell()->GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_TEXT_SELECTION, sRect.getStr());
622  SfxLokHelper::notifyOtherViews(GetShell()->GetSfxViewShell(), LOK_CALLBACK_TEXT_VIEW_SELECTION, "selection", sRect);
623  }
624  }
625 }
626 
627 // This rectangle gets painted anew, therefore the SSelection in this
628 // area is invalid.
629 void SwShellCursor::Invalidate( const SwRect& rRect )
630 {
631  for(SwPaM& rPaM : GetRingContainer())
632  {
633  SwShellCursor* pShCursor = dynamic_cast<SwShellCursor*>(&rPaM);
634  // skip any non SwShellCursor objects in the ring
635  // see also: SwAutoFormat::DeleteSel()
636  if(pShCursor)
637  pShCursor->SwSelPaintRects::Invalidate(rRect);
638  }
639 }
640 
642 {
643  for(SwPaM& rPaM : GetRingContainer())
644  {
645  SwShellCursor* pShCursor = dynamic_cast<SwShellCursor*>(&rPaM);
646  if(pShCursor)
647  pShCursor->SwSelPaintRects::Hide();
648  }
649 }
650 
652 {
653  return new SwShellCursor( *GetShell(), *GetPoint(), GetPtPos(), pRing );
654 }
655 
657 {
658  short nRet = RET_YES;
660  if( pDlg )
661  {
662  // Terminate old actions. The table-frames get constructed and
663  // a SSelection can be created.
664  std::vector<sal_uInt16> vActionCounts;
665  for(SwViewShell& rShell : const_cast< SwCursorShell* >( GetShell() )->GetRingContainer())
666  {
667  sal_uInt16 nActCnt = 0;
668  while(rShell.ActionPend())
669  {
670  rShell.EndAction();
671  ++nActCnt;
672  }
673  vActionCounts.push_back(nActCnt);
674  }
675  std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(pDlg->getDialog(), "modules/swriter/ui/asksearchdialog.ui"));
676  std::unique_ptr<weld::MessageDialog> xDialog(xBuilder->weld_message_dialog("AskSearchDialog"));
677  nRet = xDialog->run();
678  auto pActionCount = vActionCounts.begin();
679  for(SwViewShell& rShell : const_cast< SwCursorShell* >( GetShell() )->GetRingContainer())
680  {
681  while(*pActionCount)
682  {
683  rShell.StartAction();
684  --(*pActionCount);
685  }
686  ++pActionCount;
687  }
688  }
689  else
690  // otherwise from the Basic, and then switch to RET_YES
691  nRet = RET_YES;
692 
693  return nRet;
694 }
695 
697 {
698  const_cast<SwCursorShell*>(GetShell())->SaveTableBoxContent( pPos );
699 }
700 
701 bool SwShellCursor::UpDown( bool bUp, sal_uInt16 nCnt )
702 {
703  return SwCursor::UpDown( bUp, nCnt,
704  &GetPtPos(), GetShell()->GetUpDownX(),
705  *GetShell()->GetLayout());
706 }
707 
708 // if <true> than the cursor can be set to the position.
709 bool SwShellCursor::IsAtValidPos( bool bPoint ) const
710 {
711  if( GetShell() && ( GetShell()->IsAllProtect() ||
712  GetShell()->GetViewOptions()->IsReadonly() ||
713  ( GetShell()->Imp()->GetDrawView() &&
714  GetShell()->Imp()->GetDrawView()->GetMarkedObjectList().GetMarkCount() )))
715  return true;
716 
717  return SwCursor::IsAtValidPos( bPoint );
718 }
719 
721  const SwPosition& rPos )
722  : SwCursor(rPos,nullptr), SwShellCursor(rCursorSh, rPos), SwTableCursor(rPos)
723 {
724 }
725 
727  const SwPosition& rMkPos, const Point& rMkPt,
728  const SwPosition& rPtPos, const Point& rPtPt )
729  : SwCursor(rPtPos,nullptr), SwShellCursor(rCursorSh, rPtPos), SwTableCursor(rPtPos)
730 {
731  SetMark();
732  *GetMark() = rMkPos;
733  GetMkPos() = rMkPt;
734  GetPtPos() = rPtPt;
735 }
736 
738 
740 
742 {
743  return SwShellCursor::Create( pRing );
744 }
745 
747 {
749 }
750 
752 {
754 }
755 
757 {
758  // Calculate the new rectangles. If the cursor is still "parked" do nothing
760  return;
761 
762  bool bStart = true;
763  SwRegionRects aReg( GetShell()->VisArea() );
766  SwNodes& rNds = GetDoc()->GetNodes();
767  SwFrame* pEndFrame = nullptr;
768  for (size_t n = 0; n < m_SelectedBoxes.size(); ++n)
769  {
770  const SwStartNode* pSttNd = m_SelectedBoxes[n]->GetSttNd();
771  const SwTableNode* pSelTableNd = pSttNd->FindTableNode();
772 
773  SwNodeIndex aIdx( *pSttNd );
774  SwContentNode* pCNd = rNds.GoNextSection( &aIdx, true, false );
775 
776  // table in table
777  // (see also lcl_FindTopLevelTable in unoobj2.cxx for a different
778  // version to do this)
779  const SwTableNode* pCurTableNd = pCNd ? pCNd->FindTableNode() : nullptr;
780  while ( pSelTableNd != pCurTableNd && pCurTableNd )
781  {
782  aIdx = pCurTableNd->EndOfSectionIndex();
783  pCNd = rNds.GoNextSection( &aIdx, true, false );
784  pCurTableNd = pCNd->FindTableNode();
785  }
786 
787  if( !pCNd )
788  continue;
789 
790  std::pair<Point, bool> const tmp(GetSttPos(), true);
791  SwFrame* pFrame = pCNd->getLayoutFrame(GetShell()->GetLayout(), nullptr, &tmp);
792  while( pFrame && !pFrame->IsCellFrame() )
793  pFrame = pFrame->GetUpper();
794 
795  OSL_ENSURE( pFrame, "Node not in a table" );
796 
797  while ( pFrame )
798  {
799  if( aReg.GetOrigin().IsOver( pFrame->getFrameArea() ) )
800  {
801  aReg -= pFrame->getFrameArea();
802  if (bStart)
803  {
804  bStart = false;
805  m_aStart = SwRect(pFrame->getFrameArea().Left(), pFrame->getFrameArea().Top(), 1, pFrame->getFrameArea().Height());
806  }
807  }
808 
809  pEndFrame = pFrame;
810  pFrame = pFrame->GetNextCellLeaf();
811  }
812  }
813  if (pEndFrame)
814  m_aEnd = SwRect(pEndFrame->getFrameArea().Right(), pEndFrame->getFrameArea().Top(), 1, pEndFrame->getFrameArea().Height());
815  aReg.Invert();
816  insert( begin(), aReg.begin(), aReg.end() );
817 }
818 
820 {
821  rStart = m_aStart;
822  rEnd = m_aEnd;
823 }
824 
825 // Check if the SPoint is within the Table-SSelection.
826 bool SwShellTableCursor::IsInside( const Point& rPt ) const
827 {
828  // Calculate the new rectangles. If the cursor is still "parked" do nothing
830  return false;
831 
832  SwNodes& rNds = GetDoc()->GetNodes();
833  for (size_t n = 0; n < m_SelectedBoxes.size(); ++n)
834  {
835  SwNodeIndex aIdx( *m_SelectedBoxes[n]->GetSttNd() );
836  SwContentNode* pCNd = rNds.GoNextSection( &aIdx, true, false );
837  if( !pCNd )
838  continue;
839 
840  std::pair<Point, bool> const tmp(GetPtPos(), true);
841  SwFrame* pFrame = pCNd->getLayoutFrame(GetShell()->GetLayout(), nullptr, &tmp);
842  while( pFrame && !pFrame->IsCellFrame() )
843  pFrame = pFrame->GetUpper();
844  OSL_ENSURE( pFrame, "Node not in a table" );
845  if( pFrame && pFrame->getFrameArea().IsInside( rPt ) )
846  return true;
847 
848  for ( SwCellFrame* pCellFrame = static_cast<SwCellFrame*>(pFrame); pCellFrame; pCellFrame = pCellFrame->GetFollowCell() )
849  {
850  if( pCellFrame->getFrameArea().IsInside( rPt ) )
851  return true;
852  }
853  }
854  return false;
855 }
856 
857 bool SwShellTableCursor::IsAtValidPos( bool bPoint ) const
858 {
859  return SwShellCursor::IsAtValidPos( bPoint );
860 }
861 
862 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool m_bIsVisible
Definition: viscrs.hxx:42
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:290
const Fraction & GetScaleX() const
long Width() const
virtual short MaxReplaceArived() override
Definition: viscrs.cxx:746
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:74
const SwRect & GetOrigin() const
Definition: swregion.hxx:47
const SwPosition * m_pInitialPoint
Definition: viscrs.hxx:122
SdrView * GetDrawView()
Definition: vnew.cxx:375
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:709
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:3006
sal_uInt16 GetStyle() const
SdrTextObj * GetTextEditObject() const
virtual void SaveTableBoxContent(const SwPosition *pPos) override
Definition: viscrs.cxx:751
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:1147
virtual void SetMark() override
Unless this is called, the getter method of Mark will return Point.
Definition: viscrs.cxx:572
static SvxSearchDialog * GetSearchDialog()
Definition: viewsrch.cxx:859
void Height(long nNew)
Definition: swrect.hxx:189
virtual SwCursor * Create(SwPaM *pRing=nullptr) const override
Definition: viscrs.cxx:741
sal_uInt8 GetCursorBidiLevel() const
Definition: swcrsr.hxx:209
const Point & GetSttPos() const
Definition: viscrs.hxx:146
const MapMode & GetMapMode() const
SwNode & GetNode() const
Definition: ndindex.hxx:119
SwRect m_aEnd
Right edge of the selection end (bottom right cell).
Definition: viscrs.hxx:176
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:214
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:641
virtual bool IsAtValidPos(bool bPoint=true) const override
Return if cursor can be set to this position.
Definition: viscrs.cxx:857
virtual void SaveTableBoxContent(const SwPosition *pPos) override
Definition: viscrs.cxx:696
void Invalidate(const SwRect &rRect)
Definition: viscrs.cxx:479
bool m_bShowTextInputFieldOverlay
Definition: viscrs.hxx:83
static void notifyVisCursorInvalidation(OutlinerViewShell const *pThisView, const OString &rRectangle)
static long s_nPixPtX
Definition: viscrs.hxx:74
RET_YES
void Top(const long nTop)
Definition: swrect.hxx:202
Point m_PointPt
Definition: viscrs.hxx:121
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:152
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:756
SwShellTableCursor(const SwCursorShell &rCursorSh, const SwPosition &rPos)
Definition: viscrs.cxx:720
#define CURSOR_SHADOW
Point m_aOldRBPos
Right/Bottom of last VisArea.
Definition: crsrsh.hxx:170
virtual void FillRects() override
Definition: viscrs.cxx:581
void SetStyle(sal_uInt16 nStyle)
void Right(const long nRight)
Definition: swrect.hxx:198
virtual short MaxReplaceArived() override
Definition: viscrs.cxx:656
void Show(SfxViewShell const *pViewShell)
Definition: viscrs.cxx:593
size_type size() const
void Invalidate(const SwRect &rRect)
Definition: viscrs.cxx:629
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:332
static MapMode * s_pMapMode
Definition: viscrs.hxx:75
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:883
virtual ~SwShellTableCursor() override
Definition: viscrs.cxx:737
const SwCursorShell * m_pCursorShell
Definition: viscrs.hxx:77
const SwCursorShell * GetShell() const
Definition: viscrs.hxx:109
SwShellCursor(const SwCursorShell &rCursorSh, const SwPosition &rPos)
Definition: viscrs.cxx:536
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:571
const SwPosition * GetPoint() const
Definition: pam.hxx:207
bool UpDown(bool bUp, sal_uInt16 nCnt)
Definition: viscrs.cxx:701
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:564
bool HasArea() const
Definition: swrect.hxx:290
void Hide()
Definition: viscrs.cxx:97
void SetWindow(vcl::Window *pWindow)
void HighlightInputField()
Definition: viscrs.cxx:418
bool IsCursorReadonly() const
Definition: crsrsh.cxx:3259
virtual void FillStartEnd(SwRect &rStart, SwRect &rEnd) const override
Definition: viscrs.cxx:819
bool IsInside(const Point &rPt) const
Definition: viscrs.cxx:826
virtual void SetMark() override
Unless this is called, the getter method of Mark will return Point.
Definition: viscrs.cxx:739
const Point & GetMkPos() const
Definition: viscrs.hxx:144
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:463
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:309
SwCellFrame * GetFollowCell() const
Definition: findfrm.cxx:1579
long X() const
const IDocumentLayoutAccess & getIDocumentLayoutAccess() const
Provides access to the document layout interface.
Definition: viewsh.cxx:2601
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:404
enumrange< T >::Iterator end(enumrange< T >)
const SwPosition * Start() const
Definition: pam.hxx:212
SwSelPaintRects(const SwCursorShell &rCSh)
Definition: viscrs.cxx:246
Point PixelToLogic(const Point &rDevicePt) const
virtual void FillStartEnd(SwRect &rStart, SwRect &rEnd) const override
Definition: viscrs.cxx:302
virtual ~SwSelPaintRects()
Definition: viscrs.cxx:255
virtual void FillRects()=0
static void Get1PixelInLogic(const SwViewShell &rSh, long *pX=nullptr, long *pY=nullptr)
Definition: viscrs.cxx:512
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:478
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:43
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:45
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:651
const Point & GetPtPos() const
Definition: viscrs.hxx:142
bool IsVisible() const
SwTableNode * FindTableNode()
Search table node, in which it is.
Definition: node.cxx:349
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:148
SwRect m_aStart
Left edge of the selection start (top left cell).
Definition: viscrs.hxx:174
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:1921
sal_uInt16 m_nPageLastTime
For LibreOfficeKit only - remember what page we were at the last time.
Definition: viscrs.hxx:49
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:46
virtual bool IsReadOnlyAvailable() const override
Definition: viscrs.cxx:567
SwRect m_aCharRect
Char-SRectangle on which the cursor is located.
Definition: crsrsh.hxx:168
Point m_MarkPt
Definition: viscrs.hxx:120
bool IsOver(const SwRect &rRect) const
Definition: swrect.cxx:125
rtl::OString toString() const
const vcl::Cursor & GetTextCursor() const
Definition: viscrs.cxx:241
SwRootFrame * GetLayout() const
Definition: viewsh.cxx:2075
void swapContent(SwSelPaintRects &rSwap)
Definition: viscrs.cxx:260
void SetDirection(CursorDirection nDirection=CursorDirection::NONE)
bool IsTextNode() const
Definition: node.hxx:636
std::unique_ptr< sw::overlay::OverlayRangesOutline > m_pTextInputFieldOverlay
Definition: viscrs.hxx:84
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:842
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