LibreOffice Module sw (master)  1
PostItMgr.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 <boost/property_tree/json_parser.hpp>
21 
22 #include <PostItMgr.hxx>
23 #include <postithelper.hxx>
24 
25 #include <AnnotationWin.hxx>
27 #include <accmap.hxx>
28 
29 #include <SidebarWindowsConsts.hxx>
30 #include "AnchorOverlayObject.hxx"
31 #include "ShadowOverlayObject.hxx"
32 
33 #include <vcl/svapp.hxx>
34 #include <vcl/outdev.hxx>
35 #include <vcl/settings.hxx>
36 
37 #include <chrdlgmodes.hxx>
38 #include <viewopt.hxx>
39 #include <view.hxx>
40 #include <docsh.hxx>
41 #include <wrtsh.hxx>
42 #include <doc.hxx>
45 #include <fldbas.hxx>
46 #include <fmtfld.hxx>
47 #include <docufld.hxx>
48 #include <edtwin.hxx>
49 #include <txtfld.hxx>
50 #include <txtannotationfld.hxx>
51 #include <rootfrm.hxx>
52 #include <SwRewriter.hxx>
53 #include <tools/color.hxx>
54 #include <unotools/datetime.hxx>
55 
56 #include <swmodule.hxx>
57 #include <strings.hrc>
58 #include <cmdid.h>
59 
60 #include <sfx2/request.hxx>
61 #include <sfx2/event.hxx>
62 #include <svl/srchitem.hxx>
63 
64 #include <svl/languageoptions.hxx>
65 #include <svl/hint.hxx>
66 
67 #include <svx/svdview.hxx>
68 #include <editeng/eeitem.hxx>
69 #include <editeng/langitem.hxx>
70 #include <editeng/outliner.hxx>
71 #include <editeng/outlobj.hxx>
72 
73 #include <comphelper/lok.hxx>
74 #include <comphelper/string.hxx>
75 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
76 
77 #include <annotsh.hxx>
78 #include <swabstdlg.hxx>
79 #include <memory>
80 
81 // distance between Anchor Y and initial note position
82 #define POSTIT_INITIAL_ANCHOR_DISTANCE 20
83 //distance between two postits
84 #define POSTIT_SPACE_BETWEEN 8
85 #define POSTIT_MINIMUMSIZE_WITH_META 60
86 #define POSTIT_SCROLL_SIDEBAR_HEIGHT 20
87 
88 // if we layout more often we stop, this should never happen
89 #define MAX_LOOP_COUNT 50
90 
91 using namespace sw::sidebarwindows;
92 using namespace sw::annotation;
93 
94 namespace {
95 
96  enum class CommentNotificationType { Add, Remove, Modify, Resolve };
97 
98  bool comp_pos(const std::unique_ptr<SwSidebarItem>& a, const std::unique_ptr<SwSidebarItem>& b)
99  {
100  // sort by anchor position
101  SwPosition aPosAnchorA = a->GetAnchorPosition();
102  SwPosition aPosAnchorB = b->GetAnchorPosition();
103 
104  bool aAnchorAInFooter = false;
105  bool aAnchorBInFooter = false;
106 
107  // is the anchor placed in Footnote or the Footer?
108  if( aPosAnchorA.nNode.GetNode().FindFootnoteStartNode() || aPosAnchorA.nNode.GetNode().FindFooterStartNode() )
109  aAnchorAInFooter = true;
110  if( aPosAnchorB.nNode.GetNode().FindFootnoteStartNode() || aPosAnchorB.nNode.GetNode().FindFooterStartNode() )
111  aAnchorBInFooter = true;
112 
113  // fdo#34800
114  // if AnchorA is in footnote, and AnchorB isn't
115  // we do not want to change over the position
116  if( aAnchorAInFooter && !aAnchorBInFooter )
117  return false;
118  // if aAnchorA is not placed in a footnote, and aAnchorB is
119  // force a change over
120  else if( !aAnchorAInFooter && aAnchorBInFooter )
121  return true;
122  // If neither or both are in the footer, compare the positions.
123  // Since footnotes are in Inserts section of nodes array and footers
124  // in Autotext section, all footnotes precede any footers so no need
125  // to check that.
126  else
127  return aPosAnchorA < aPosAnchorB;
128  }
129 
131  void lcl_CommentNotification(const SwView* pView, const CommentNotificationType nType, const SwSidebarItem* pItem, const sal_uInt32 nPostItId)
132  {
134  return;
135 
136  boost::property_tree::ptree aAnnotation;
137  aAnnotation.put("action", (nType == CommentNotificationType::Add ? "Add" :
138  (nType == CommentNotificationType::Remove ? "Remove" :
139  (nType == CommentNotificationType::Modify ? "Modify" :
140  (nType == CommentNotificationType::Resolve ? "Resolve" : "???")))));
141  aAnnotation.put("id", nPostItId);
142  if (nType != CommentNotificationType::Remove && pItem != nullptr)
143  {
145 
146  const SwPostItField* pField = pWin->GetPostItField();
147  const SwRect& aRect = pWin->GetAnchorRect();
148  tools::Rectangle aSVRect(aRect.Pos().getX(),
149  aRect.Pos().getY(),
150  aRect.Pos().getX() + aRect.SSize().Width(),
151  aRect.Pos().getY() + aRect.SSize().Height());
152 
154  {
155  // Comments on frames: anchor position is the corner position, not the whole frame.
156  aSVRect.SetSize(Size(0, 0));
157  }
158 
159  std::vector<OString> aRects;
160  for (const basegfx::B2DRange& aRange : pWin->GetAnnotationTextRanges())
161  {
162  const SwRect rect(aRange.getMinX(), aRange.getMinY(), aRange.getWidth(), aRange.getHeight());
163  aRects.push_back(rect.SVRect().toString());
164  }
165  const OString sRects = comphelper::string::join("; ", aRects);
166 
167  aAnnotation.put("id", pField->GetPostItId());
168  aAnnotation.put("parent", pWin->CalcParent());
169  aAnnotation.put("author", pField->GetPar1().toUtf8().getStr());
170  aAnnotation.put("text", pField->GetPar2().toUtf8().getStr());
171  aAnnotation.put("resolved", pField->GetResolved() ? "true" : "false");
172  aAnnotation.put("dateTime", utl::toISO8601(pField->GetDateTime().GetUNODateTime()));
173  aAnnotation.put("anchorPos", aSVRect.toString());
174  aAnnotation.put("textRange", sRects.getStr());
175  }
176 
177  boost::property_tree::ptree aTree;
178  aTree.add_child("comment", aAnnotation);
179  std::stringstream aStream;
180  boost::property_tree::write_json(aStream, aTree);
181  std::string aPayload = aStream.str();
182 
183  if (pView)
184  {
185  pView->libreOfficeKitViewCallback(LOK_CALLBACK_COMMENT, aPayload.c_str());
186  }
187  }
188 
189 } // anonymous namespace
190 
192  : mpView(pView)
193  , mpWrtShell(mpView->GetDocShell()->GetWrtShell())
194  , mpEditWin(&mpView->GetEditWin())
195  , mnEventId(nullptr)
196  , mbWaitingForCalcRects(false)
197  , mpActivePostIt(nullptr)
198  , mbLayout(false)
199  , mbLayoutHeight(0)
200  , mbLayouting(false)
201  , mbReadOnly(mpView->GetDocShell()->IsReadOnly())
202  , mbDeleteNote(true)
203  , mpAnswer(nullptr)
204  , mbIsShowAnchor( false )
205 {
206  if(!mpView->GetDrawView() )
208 
209  SwNoteProps aProps;
210  mbIsShowAnchor = aProps.IsShowAnchor();
211 
212  //make sure we get the colour yellow always, even if not the first one of comments or redlining
213  SW_MOD()->GetRedlineAuthor();
214 
215  // collect all PostIts and redline comments that exist after loading the document
216  // don't check for existence for any of them, don't focus them
217  AddPostIts(false,false);
218  /* this code can be used once we want redline comments in the Sidebar
219  AddRedlineComments(false,false);
220  */
221  // we want to receive stuff like SfxHintId::DocChanged
223  if (!mvPostItFields.empty())
224  {
225  mbWaitingForCalcRects = true;
227  }
228 }
229 
231 {
232  if ( mnEventId )
234  // forget about all our Sidebar windows
237 
238  mPages.clear();
239 }
240 
242 {
244  bool bRemoved = false;
245  auto it = mvPostItFields.begin();
246  while(it != mvPostItFields.end())
247  {
248  if (!(*it)->UseElement(*mpWrtShell->GetLayout(), rIDRA))
249  {
250  EndListening(const_cast<SfxBroadcaster&>(*(*it)->GetBroadcaster()));
251  std::unique_ptr<SwSidebarItem> p = std::move(*it);
252  it = mvPostItFields.erase(it);
253  if (GetActiveSidebarWin() == p->pPostIt)
254  SetActiveSidebarWin(nullptr);
255  p->pPostIt.disposeAndClear();
256  bRemoved = true;
257  }
258  else
259  ++it;
260  }
261 
262  if ( bRemoved )
263  {
264  // make sure that no deleted items remain in page lists
265  // todo: only remove deleted ones?!
266  if ( mvPostItFields.empty() )
267  {
269  PrepareView();
270  }
271  else
272  // if postits are their make sure that page lists are not empty
273  // otherwise sudden paints can cause pain (in BorderOverPageBorder)
274  CalcRects();
275  }
276 }
277 
278 SwSidebarItem* SwPostItMgr::InsertItem(SfxBroadcaster* pItem, bool bCheckExistence, bool bFocus)
279 {
280  if (bCheckExistence)
281  {
282  for (auto const& postItField : mvPostItFields)
283  {
284  if ( postItField->GetBroadcaster() == pItem )
285  return nullptr;
286  }
287  }
288  mbLayout = bFocus;
289 
290  SwSidebarItem* pAnnotationItem = nullptr;
291  if (dynamic_cast< const SwFormatField *>( pItem ) != nullptr)
292  {
293  mvPostItFields.push_back(std::make_unique<SwAnnotationItem>(static_cast<SwFormatField&>(*pItem), bFocus));
294  pAnnotationItem = mvPostItFields.back().get();
295  }
296  OSL_ENSURE(dynamic_cast< const SwFormatField *>( pItem ) != nullptr,"Mgr::InsertItem: seems like new stuff was added");
297  StartListening(*pItem);
298  return pAnnotationItem;
299 }
300 
302 {
303  EndListening(*pBroadcast);
304  auto i = std::find_if(mvPostItFields.begin(), mvPostItFields.end(),
305  [&pBroadcast](const std::unique_ptr<SwSidebarItem>& pField) { return pField->GetBroadcaster() == pBroadcast; });
306  if (i != mvPostItFields.end())
307  {
308  std::unique_ptr<SwSidebarItem> p = std::move(*i);
309  // tdf#120487 remove from list before dispose, so comment window
310  // won't be recreated due to the entry still in the list if focus
311  // transferring from the pPostIt triggers relayout of postits
312  // tdf#133348 remove from list before calling SetActiveSidebarWin
313  // so GetNextPostIt won't deal with mvPostItFields containing empty unique_ptr
314  mvPostItFields.erase(i);
315  if (GetActiveSidebarWin() == p->pPostIt)
316  SetActiveSidebarWin(nullptr);
317  p->pPostIt.disposeAndClear();
318  }
319  mbLayout = true;
320  PrepareView();
321 }
322 
323 void SwPostItMgr::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
324 {
325  if ( const SfxEventHint* pSfxEventHint = dynamic_cast<const SfxEventHint*>(&rHint) )
326  {
327  if ( pSfxEventHint->GetEventId() == SfxEventHintId::SwEventLayoutFinished )
328  {
329  if ( !mbWaitingForCalcRects && !mvPostItFields.empty())
330  {
331  mbWaitingForCalcRects = true;
333  }
334  }
335  }
336  else if ( const SwFormatFieldHint * pFormatHint = dynamic_cast<const SwFormatFieldHint*>(&rHint) )
337  {
338  SwFormatField* pField = const_cast <SwFormatField*>( pFormatHint->GetField() );
339  switch ( pFormatHint->Which() )
340  {
342  {
343  if (!pField)
344  {
345  AddPostIts();
346  break;
347  }
348  // get field to be inserted from hint
349  if ( pField->IsFieldInDoc() )
350  {
351  bool bEmpty = !HasNotes();
352  SwSidebarItem* pItem = InsertItem( pField, true, false );
353 
354  if (bEmpty && !mvPostItFields.empty())
355  PrepareView(true);
356 
357  // True until the layout of this post it finishes
358  if (pItem)
359  pItem->bPendingLayout = true;
360  }
361  else
362  {
363  OSL_FAIL("Inserted field not in document!" );
364  }
365  break;
366  }
368  {
369  if (mbDeleteNote)
370  {
371  if (!pField)
372  {
374  break;
375  }
376  RemoveItem(pField);
377 
378  // If LOK has disabled tiled annotations, emit annotation callbacks
380  {
381  SwPostItField* pPostItField = static_cast<SwPostItField*>(pField->GetField());
382  lcl_CommentNotification(mpView, CommentNotificationType::Remove, nullptr, pPostItField->GetPostItId());
383  }
384  }
385  break;
386  }
388  {
389  if (pFormatHint->GetView()== mpView)
390  Focus(rBC);
391  break;
392  }
395  {
396  SwFormatField* pFormatField = dynamic_cast<SwFormatField*>(&rBC);
397  for (auto const& postItField : mvPostItFields)
398  {
399  if ( pFormatField == postItField->GetBroadcaster() )
400  {
401  if (postItField->pPostIt)
402  {
403  postItField->pPostIt->SetPostItText();
404  mbLayout = true;
405  }
406 
407  // If LOK has disabled tiled annotations, emit annotation callbacks
409  {
410  if(SwFormatFieldHintWhich::CHANGED == pFormatHint->Which())
411  lcl_CommentNotification(mpView, CommentNotificationType::Modify, postItField.get(), 0);
412  else
413  lcl_CommentNotification(mpView, CommentNotificationType::Resolve, postItField.get(), 0);
414  }
415  break;
416  }
417  }
418  break;
419  }
420 
422  {
423  SwFormatField* pFormatField = dynamic_cast<SwFormatField*>(&rBC);
424  for (auto const& postItField : mvPostItFields)
425  {
426  if ( pFormatField == postItField->GetBroadcaster() )
427  {
428  if (postItField->pPostIt)
429  {
430  const SvtScriptType nScriptType = SvtLanguageOptions::GetScriptTypeOfLanguage( postItField->GetFormatField().GetField()->GetLanguage() );
431  sal_uInt16 nLangWhichId = 0;
432  switch (nScriptType)
433  {
434  case SvtScriptType::LATIN : nLangWhichId = EE_CHAR_LANGUAGE ; break;
435  case SvtScriptType::ASIAN : nLangWhichId = EE_CHAR_LANGUAGE_CJK; break;
436  case SvtScriptType::COMPLEX : nLangWhichId = EE_CHAR_LANGUAGE_CTL; break;
437  default: break;
438  }
439  postItField->pPostIt->SetLanguage(
441  postItField->GetFormatField().GetField()->GetLanguage(),
442  nLangWhichId) );
443  }
444  break;
445  }
446  }
447  break;
448  }
449  }
450  }
451  else
452  {
453  SfxHintId nId = rHint.GetId();
454  switch ( nId )
455  {
456  case SfxHintId::ModeChanged:
457  {
458  if ( mbReadOnly != mpView->GetDocShell()->IsReadOnly() )
459  {
462  mbLayout = true;
463  }
464  break;
465  }
466  case SfxHintId::DocChanged:
467  {
468  if ( mpView->GetDocShell() == &rBC )
469  {
470  if ( !mbWaitingForCalcRects && !mvPostItFields.empty())
471  {
472  mbWaitingForCalcRects = true;
474  }
475  }
476  break;
477  }
478  case SfxHintId::SwSplitNodeOperation:
479  {
480  // if we are in a SplitNode/Cut operation, do not delete note and then add again, as this will flicker
482  break;
483  }
484  case SfxHintId::Dying:
485  {
486  if ( mpView->GetDocShell() != &rBC )
487  {
488  // field to be removed is the broadcaster
489  OSL_FAIL("Notification for removed SwFormatField was not sent!");
490  RemoveItem(&rBC);
491  }
492  break;
493  }
494  default: break;
495  }
496  }
497 }
498 
500 {
502  {
503  SfxRequest aRequest(mpView->GetViewFrame(), SID_TOGGLE_NOTES);
504  mpView->ExecViewOptions(aRequest);
505  }
506 
507  for (auto const& postItField : mvPostItFields)
508  {
509  // field to get the focus is the broadcaster
510  if ( &rBC == postItField->GetBroadcaster() )
511  {
512  if (postItField->pPostIt)
513  {
514  postItField->pPostIt->GrabFocus();
515  MakeVisible(postItField->pPostIt);
516  }
517  else
518  {
519  // when the layout algorithm starts, this postit is created and receives focus
520  postItField->bFocus = true;
521  }
522  }
523  }
524 }
525 
527 {
528  if ( mnEventId )
529  {
530  // if CalcRects() was forced and an event is still pending: remove it
531  // it is superfluous and also may cause reentrance problems if triggered while layouting
533  mnEventId = nullptr;
534  }
535 
536  bool bChange = false;
537  bool bRepair = false;
539  if ( !mvPostItFields.empty() )
540  {
542  for (auto const& pItem : mvPostItFields)
543  {
544  if (!pItem->UseElement(*mpWrtShell->GetLayout(), rIDRA))
545  {
546  OSL_FAIL("PostIt is not in doc or other wrong use");
547  bRepair = true;
548  continue;
549  }
550  const SwRect aOldAnchorRect( pItem->maLayoutInfo.mPosition );
551  const SwPostItHelper::SwLayoutStatus eOldLayoutStatus = pItem->mLayoutStatus;
552  const sal_uLong nOldStartNodeIdx( pItem->maLayoutInfo.mnStartNodeIdx );
553  const sal_Int32 nOldStartContent( pItem->maLayoutInfo.mnStartContent );
554  {
555  // update layout information
556  const SwTextAnnotationField* pTextAnnotationField =
557  dynamic_cast< const SwTextAnnotationField* >( pItem->GetFormatField().GetTextField() );
558  const ::sw::mark::IMark* pAnnotationMark =
559  pTextAnnotationField != nullptr ? pTextAnnotationField->GetAnnotationMark() : nullptr;
560  if ( pAnnotationMark != nullptr )
561  {
562  pItem->mLayoutStatus =
564  pItem->maLayoutInfo,
565  pItem->GetAnchorPosition(),
566  pAnnotationMark );
567  }
568  else
569  {
570  pItem->mLayoutStatus =
572  }
573  }
574  bChange = bChange
575  || pItem->maLayoutInfo.mPosition != aOldAnchorRect
576  || pItem->mLayoutStatus != eOldLayoutStatus
577  || pItem->maLayoutInfo.mnStartNodeIdx != nOldStartNodeIdx
578  || pItem->maLayoutInfo.mnStartContent != nOldStartContent;
579  }
580 
581  // show notes in right order in navigator
582  //prevent Anchors during layout to overlap, e.g. when moving a frame
583  if (mvPostItFields.size()>1 )
584  std::stable_sort(mvPostItFields.begin(), mvPostItFields.end(), comp_pos);
585 
586  // sort the items into the right page vector, so layout can be done by page
587  for (auto const& pItem : mvPostItFields)
588  {
590  {
591  if (pItem->pPostIt)
592  pItem->pPostIt->HideNote();
593  continue;
594  }
595 
596  if( SwPostItHelper::HIDDEN == pItem->mLayoutStatus )
597  {
599  {
600  if (pItem->pPostIt)
601  pItem->pPostIt->HideNote();
602  continue;
603  }
604  }
605 
606  const unsigned long aPageNum = pItem->maLayoutInfo.mnPageNumber;
607  if (aPageNum > mPages.size())
608  {
609  const unsigned long nNumberOfPages = mPages.size();
610  mPages.reserve(aPageNum);
611  for (unsigned long j=0; j<aPageNum - nNumberOfPages; ++j)
612  mPages.emplace_back( new SwPostItPageItem());
613  }
614  mPages[aPageNum-1]->mvSidebarItems.push_back(pItem.get());
615  mPages[aPageNum-1]->mPageRect = pItem->maLayoutInfo.mPageFrame;
616  mPages[aPageNum-1]->eSidebarPosition = pItem->maLayoutInfo.meSidebarPosition;
617  }
618 
620  {
621  long nLayoutHeight = SwPostItHelper::getLayoutHeight( mpWrtShell->GetLayout() );
622  if( nLayoutHeight > mbLayoutHeight )
623  {
624  if (mPages[0]->bScrollbar || HasScrollbars())
625  bChange = true;
626  }
627  else if( nLayoutHeight < mbLayoutHeight )
628  {
629  if (mPages[0]->bScrollbar || !BorderOverPageBorder(1))
630  bChange = true;
631  }
632  }
633  }
634 
635  if ( bRepair )
637 
639  mbWaitingForCalcRects = false;
640  return bChange;
641 }
642 
644 {
645  for (auto const& postItField : mvPostItFields)
646  {
647  if (postItField->bShow && postItField->pPostIt && postItField->pPostIt->HasScrollbar())
648  return true;
649  }
650  return false;
651 }
652 
654 {
655  // we do not just delete the SwPostItPageItem, so offset/scrollbar is not lost
656  long lPageSize = mpWrtShell->GetNumPages();
657  long lContainerSize = mPages.size();
658 
659  if (lContainerSize < lPageSize)
660  {
661  mPages.reserve(lPageSize);
662  for (long i=0; i<lPageSize - lContainerSize;i++)
663  mPages.emplace_back( new SwPostItPageItem());
664  }
665  else if (lContainerSize > lPageSize)
666  {
667  for (int i=mPages.size()-1; i >= lPageSize;--i)
668  {
669  mPages.pop_back();
670  }
671  }
672  // only clear the list, DO NOT delete the objects itself
673  for (auto const& page : mPages)
674  {
675  page->mvSidebarItems.clear();
676  if (mvPostItFields.empty())
677  page->bScrollbar = false;
678  }
679 }
680 
682 {
683  bool bEnableMapMode = comphelper::LibreOfficeKit::isActive() && !mpEditWin->IsMapModeEnabled();
684  if (bEnableMapMode)
686 
687  if ( !mvPostItFields.empty() && !mbWaitingForCalcRects )
688  {
689  mbLayouting = true;
690 
691  //loop over all pages and do the layout
692  // - create SwPostIt if necessary
693  // - place SwPostIts on their initial position
694  // - calculate necessary height for all PostIts together
695  bool bUpdate = false;
696  for (std::unique_ptr<SwPostItPageItem>& pPage : mPages)
697  {
698  // only layout if there are notes on this page
699  if (!pPage->mvSidebarItems.empty())
700  {
701  std::vector<SwAnnotationWin*> aVisiblePostItList;
702  unsigned long lNeededHeight = 0;
703  long mlPageBorder = 0;
704  long mlPageEnd = 0;
705 
706  for (auto const& pItem : pPage->mvSidebarItems)
707  {
708  VclPtr<SwAnnotationWin> pPostIt = pItem->pPostIt;
709 
710  if (pPage->eSidebarPosition == sw::sidebarwindows::SidebarPosition::LEFT )
711  {
712  // x value for notes positioning
713  mlPageBorder = mpEditWin->LogicToPixel( Point( pPage->mPageRect.Left(), 0)).X() - GetSidebarWidth(true);// - GetSidebarBorderWidth(true);
714  //bending point
715  mlPageEnd =
717  ? pItem->maLayoutInfo.mPagePrtArea.Left()
718  : pPage->mPageRect.Left() + 350;
719  }
720  else if (pPage->eSidebarPosition == sw::sidebarwindows::SidebarPosition::RIGHT )
721  {
722  // x value for notes positioning
723  mlPageBorder = mpEditWin->LogicToPixel( Point(pPage->mPageRect.Right(), 0)).X() + GetSidebarBorderWidth(true);
724  //bending point
725  mlPageEnd =
727  ? pItem->maLayoutInfo.mPagePrtArea.Right() :
728  pPage->mPageRect.Right() - 350;
729  }
730 
731  if (pItem->bShow)
732  {
733  long Y = mpEditWin->LogicToPixel( Point(0,pItem->maLayoutInfo.mPosition.Bottom())).Y();
734  long aPostItHeight = 0;
735  if (!pPostIt)
736  {
737  pPostIt = pItem->GetSidebarWindow( mpView->GetEditWin(),
738  *this );
739  pPostIt->InitControls();
740  pPostIt->SetReadonly(mbReadOnly);
741  pItem->pPostIt = pPostIt;
742  if (mpAnswer)
743  {
744  if (static_cast<bool>(pPostIt->CalcParent())) //do we really have another note in front of this one
745  pPostIt->InitAnswer(mpAnswer);
746  delete mpAnswer;
747  mpAnswer = nullptr;
748  }
749  }
750 
751  pPostIt->SetChangeTracking(
752  pItem->mLayoutStatus,
754  pPostIt->SetSidebarPosition(pPage->eSidebarPosition);
755  pPostIt->SetFollow(static_cast<bool>(pPostIt->CalcParent()));
756  aPostItHeight = ( pPostIt->GetPostItTextHeight() < pPostIt->GetMinimumSizeWithoutMeta()
757  ? pPostIt->GetMinimumSizeWithoutMeta()
758  : pPostIt->GetPostItTextHeight() )
759  + pPostIt->GetMetaHeight();
760  pPostIt->SetPosSizePixelRect( mlPageBorder ,
762  GetSidebarWidth(true),
763  aPostItHeight,
764  pItem->maLayoutInfo.mPosition,
765  mlPageEnd );
766  pPostIt->ChangeSidebarItem( *pItem );
767 
768  if (pItem->bFocus)
769  {
770  mbLayout = true;
771  pPostIt->GrabFocus();
772  pItem->bFocus = false;
773  }
774  // only the visible postits are used for the final layout
775  aVisiblePostItList.push_back(pPostIt);
776  lNeededHeight += pPostIt->IsFollow() ? aPostItHeight : aPostItHeight+GetSpaceBetween();
777  }
778  else // we don't want to see it
779  {
780  if (pPostIt)
781  pPostIt->HideNote();
782  }
783  }
784 
785  if ((!aVisiblePostItList.empty()) && ShowNotes())
786  {
787  bool bOldScrollbar = pPage->bScrollbar;
788  if (ShowNotes())
789  pPage->bScrollbar = LayoutByPage(aVisiblePostItList, pPage->mPageRect.SVRect(), lNeededHeight);
790  else
791  pPage->bScrollbar = false;
792  if (!pPage->bScrollbar)
793  {
794  pPage->lOffset = 0;
795  }
796  else if (sal_Int32 nScrollSize = GetScrollSize())
797  {
798  //when we changed our zoom level, the offset value can be too big, so lets check for the largest possible zoom value
799  long aAvailableHeight = mpEditWin->LogicToPixel(Size(0,pPage->mPageRect.Height())).Height() - 2 * GetSidebarScrollerHeight();
800  long lOffset = -1 * nScrollSize * (aVisiblePostItList.size() - aAvailableHeight / nScrollSize);
801  if (pPage->lOffset < lOffset)
802  pPage->lOffset = lOffset;
803  }
804  bUpdate = (bOldScrollbar != pPage->bScrollbar) || bUpdate;
805  const long aSidebarheight = pPage->bScrollbar ? mpEditWin->PixelToLogic(Size(0,GetSidebarScrollerHeight())).Height() : 0;
806  /*
807  TODO
808  - enlarge all notes till GetNextBorder(), as we resized to average value before
809  */
810  //lets hide the ones which overlap the page
811  for (auto const& visiblePostIt : aVisiblePostItList)
812  {
813  if (pPage->lOffset != 0)
814  visiblePostIt->TranslateTopPosition(pPage->lOffset);
815 
816  bool bBottom = mpEditWin->PixelToLogic(Point(0,visiblePostIt->VirtualPos().Y()+visiblePostIt->VirtualSize().Height())).Y() <= (pPage->mPageRect.Bottom()-aSidebarheight);
817  bool bTop = mpEditWin->PixelToLogic(Point(0,visiblePostIt->VirtualPos().Y())).Y() >= (pPage->mPageRect.Top()+aSidebarheight);
818  if ( bBottom && bTop )
819  {
820  // When tiled rendering, make sure that only the
821  // view that has the comment focus emits callbacks,
822  // so the editing view jumps to the comment, but
823  // not the others.
824  bool bTiledPainting = comphelper::LibreOfficeKit::isTiledPainting();
825  if (!bTiledPainting)
826  // No focus -> disable callbacks.
827  comphelper::LibreOfficeKit::setTiledPainting(!visiblePostIt->HasChildPathFocus());
828  visiblePostIt->ShowNote();
829  if (!bTiledPainting)
830  {
832  visiblePostIt->InvalidateControl();
833  }
834  }
835  else
836  {
837  if (mpEditWin->PixelToLogic(Point(0,visiblePostIt->VirtualPos().Y())).Y() < (pPage->mPageRect.Top()+aSidebarheight))
838  {
839  if ( pPage->eSidebarPosition == sw::sidebarwindows::SidebarPosition::LEFT )
840  visiblePostIt->ShowAnchorOnly(Point( pPage->mPageRect.Left(),
841  pPage->mPageRect.Top()));
842  else if ( pPage->eSidebarPosition == sw::sidebarwindows::SidebarPosition::RIGHT )
843  visiblePostIt->ShowAnchorOnly(Point( pPage->mPageRect.Right(),
844  pPage->mPageRect.Top()));
845  }
846  else
847  {
848  if ( pPage->eSidebarPosition == sw::sidebarwindows::SidebarPosition::LEFT )
849  visiblePostIt->ShowAnchorOnly(Point(pPage->mPageRect.Left(),
850  pPage->mPageRect.Bottom()));
851  else if ( pPage->eSidebarPosition == sw::sidebarwindows::SidebarPosition::RIGHT )
852  visiblePostIt->ShowAnchorOnly(Point(pPage->mPageRect.Right(),
853  pPage->mPageRect.Bottom()));
854  }
855  OSL_ENSURE(pPage->bScrollbar,"SwPostItMgr::LayoutByPage(): note overlaps, but bScrollbar is not true");
856  }
857  }
858  }
859  else
860  {
861  for (auto const& visiblePostIt : aVisiblePostItList)
862  {
863  visiblePostIt->SetPosAndSize();
864  }
865 
866  bool bOldScrollbar = pPage->bScrollbar;
867  pPage->bScrollbar = false;
868  bUpdate = (bOldScrollbar != pPage->bScrollbar) || bUpdate;
869  }
870 
871  for (auto const& visiblePostIt : aVisiblePostItList)
872  {
874  {
875  if (visiblePostIt->GetSidebarItem().bPendingLayout)
876  lcl_CommentNotification(mpView, CommentNotificationType::Add, &visiblePostIt->GetSidebarItem(), 0);
877  else if (visiblePostIt->IsAnchorRectChanged())
878  {
879  lcl_CommentNotification(mpView, CommentNotificationType::Modify, &visiblePostIt->GetSidebarItem(), 0);
880  visiblePostIt->ResetAnchorRectChanged();
881  }
882  }
883 
884  // Layout for this post it finished now
885  visiblePostIt->GetSidebarItem().bPendingLayout = false;
886  }
887  }
888  else
889  {
890  if (pPage->bScrollbar)
891  bUpdate = true;
892  pPage->bScrollbar = false;
893  }
894  }
895 
896  if (!ShowNotes())
897  { // we do not want to see the notes anymore -> Options-Writer-View-Notes
899  bool bRepair = false;
900  for (auto const& postItField : mvPostItFields)
901  {
902  if (!postItField->UseElement(*mpWrtShell->GetLayout(), rIDRA))
903  {
904  OSL_FAIL("PostIt is not in doc!");
905  bRepair = true;
906  continue;
907  }
908 
909  if (postItField->pPostIt)
910  {
911  postItField->pPostIt->HideNote();
912  if (postItField->pPostIt->HasChildPathFocus())
913  {
914  SetActiveSidebarWin(nullptr);
915  postItField->pPostIt->GrabFocusToDocument();
916  }
917  }
918  }
919 
920  if ( bRepair )
922  }
923 
924  // notes scrollbar is otherwise not drawn correctly for some cases
925  // scrollbar area is enough
926  if (bUpdate)
927  mpEditWin->Invalidate(); /*This is a super expensive relayout and render of the entire page*/
928 
929  mbLayouting = false;
930  }
931 
932  if (bEnableMapMode)
933  mpEditWin->EnableMapMode(false);
934 }
935 
936 bool SwPostItMgr::BorderOverPageBorder(unsigned long aPage) const
937 {
938  if ( mPages[aPage-1]->mvSidebarItems.empty() )
939  {
940  OSL_FAIL("Notes SidePane painted but no rects and page lists calculated!");
941  return false;
942  }
943 
944  auto aItem = mPages[aPage-1]->mvSidebarItems.end();
945  --aItem;
946  OSL_ENSURE ((*aItem)->pPostIt,"BorderOverPageBorder: NULL postIt, should never happen");
947  if ((*aItem)->pPostIt)
948  {
949  const long aSidebarheight = mPages[aPage-1]->bScrollbar ? mpEditWin->PixelToLogic(Size(0,GetSidebarScrollerHeight())).Height() : 0;
950  const long aEndValue = mpEditWin->PixelToLogic(Point(0,(*aItem)->pPostIt->GetPosPixel().Y()+(*aItem)->pPostIt->GetSizePixel().Height())).Y();
951  return aEndValue <= mPages[aPage-1]->mPageRect.Bottom()-aSidebarheight;
952  }
953  else
954  return false;
955 }
956 
957 void SwPostItMgr::DrawNotesForPage(OutputDevice *pOutDev, sal_uInt32 nPage)
958 {
959  assert(nPage < mPages.size());
960  if (nPage >= mPages.size())
961  return;
962  for (auto const& pItem : mPages[nPage]->mvSidebarItems)
963  {
964  SwAnnotationWin* pPostIt = pItem->pPostIt;
965  if (!pPostIt)
966  continue;
967  Point aPoint(mpEditWin->PixelToLogic(pPostIt->GetPosPixel()));
968  pPostIt->Draw(pOutDev, aPoint, DrawFlags::NONE);
969  }
970 }
971 
973 {
974  for (const std::unique_ptr<SwSidebarItem>& pItem : mvPostItFields)
975  {
976  SwAnnotationWin* pPostIt = pItem->pPostIt;
977  if (!pPostIt)
978  continue;
979 
980  bool bEnableMapMode = !mpEditWin->IsMapModeEnabled();
982  rRenderContext.Push(PushFlags::MAPMODE);
983  Point aOffset(mpEditWin->PixelToLogic(pPostIt->GetPosPixel()));
984  MapMode aMapMode(rRenderContext.GetMapMode());
985  aMapMode.SetOrigin(aMapMode.GetOrigin() + aOffset);
986  rRenderContext.SetMapMode(aMapMode);
987  Size aSize(rRenderContext.PixelToLogic(pPostIt->GetSizePixel()));
988  tools::Rectangle aRectangle(Point(0, 0), aSize);
989 
990  pPostIt->PaintTile(rRenderContext, aRectangle);
991 
992  rRenderContext.Pop();
993  if (bEnableMapMode)
994  mpEditWin->EnableMapMode(false);
995  }
996 }
997 
998 void SwPostItMgr::Scroll(const long lScroll,const unsigned long aPage)
999 {
1000  OSL_ENSURE((lScroll % GetScrollSize() )==0,"SwPostItMgr::Scroll: scrolling by wrong value");
1001  // do not scroll more than necessary up or down
1002  if ( ((mPages[aPage-1]->lOffset == 0) && (lScroll>0)) || ( BorderOverPageBorder(aPage) && (lScroll<0)) )
1003  return;
1004 
1005  const bool bOldUp = ArrowEnabled(KEY_PAGEUP,aPage);
1006  const bool bOldDown = ArrowEnabled(KEY_PAGEDOWN,aPage);
1007  const long aSidebarheight = mpEditWin->PixelToLogic(Size(0,GetSidebarScrollerHeight())).Height();
1008  for (auto const& item : mPages[aPage-1]->mvSidebarItems)
1009  {
1010  SwAnnotationWin* pPostIt = item->pPostIt;
1011  // if this is an answer, we should take the normal position and not the real, slightly moved position
1012  pPostIt->SetVirtualPosSize(pPostIt->GetPosPixel(),pPostIt->GetSizePixel());
1013  pPostIt->TranslateTopPosition(lScroll);
1014 
1015  if (item->bShow)
1016  {
1017  bool bBottom = mpEditWin->PixelToLogic(Point(0,pPostIt->VirtualPos().Y()+pPostIt->VirtualSize().Height())).Y() <= (mPages[aPage-1]->mPageRect.Bottom()-aSidebarheight);
1018  bool bTop = mpEditWin->PixelToLogic(Point(0,pPostIt->VirtualPos().Y())).Y() >= (mPages[aPage-1]->mPageRect.Top()+aSidebarheight);
1019  if ( bBottom && bTop)
1020  {
1021  pPostIt->ShowNote();
1022  }
1023  else
1024  {
1025  if ( mpEditWin->PixelToLogic(Point(0,pPostIt->VirtualPos().Y())).Y() < (mPages[aPage-1]->mPageRect.Top()+aSidebarheight))
1026  {
1027  if (mPages[aPage-1]->eSidebarPosition == sw::sidebarwindows::SidebarPosition::LEFT)
1028  pPostIt->ShowAnchorOnly(Point(mPages[aPage-1]->mPageRect.Left(),mPages[aPage-1]->mPageRect.Top()));
1029  else if (mPages[aPage-1]->eSidebarPosition == sw::sidebarwindows::SidebarPosition::RIGHT)
1030  pPostIt->ShowAnchorOnly(Point(mPages[aPage-1]->mPageRect.Right(),mPages[aPage-1]->mPageRect.Top()));
1031  }
1032  else
1033  {
1034  if (mPages[aPage-1]->eSidebarPosition == sw::sidebarwindows::SidebarPosition::LEFT)
1035  pPostIt->ShowAnchorOnly(Point(mPages[aPage-1]->mPageRect.Left(),mPages[aPage-1]->mPageRect.Bottom()));
1036  else if (mPages[aPage-1]->eSidebarPosition == sw::sidebarwindows::SidebarPosition::RIGHT)
1037  pPostIt->ShowAnchorOnly(Point(mPages[aPage-1]->mPageRect.Right(),mPages[aPage-1]->mPageRect.Bottom()));
1038  }
1039  }
1040  }
1041  }
1042  mPages[aPage-1]->lOffset += lScroll;
1043  if ( (bOldUp != ArrowEnabled(KEY_PAGEUP,aPage)) ||(bOldDown != ArrowEnabled(KEY_PAGEDOWN,aPage)) )
1044  {
1047  }
1048 }
1049 
1050 void SwPostItMgr::AutoScroll(const SwAnnotationWin* pPostIt,const unsigned long aPage )
1051 {
1052  // otherwise all notes are visible
1053  if (mPages[aPage-1]->bScrollbar)
1054  {
1055  const long aSidebarheight = mpEditWin->PixelToLogic(Size(0,GetSidebarScrollerHeight())).Height();
1056  const bool bBottom = mpEditWin->PixelToLogic(Point(0,pPostIt->GetPosPixel().Y()+pPostIt->GetSizePixel().Height())).Y() <= (mPages[aPage-1]->mPageRect.Bottom()-aSidebarheight);
1057  const bool bTop = mpEditWin->PixelToLogic(Point(0,pPostIt->GetPosPixel().Y())).Y() >= (mPages[aPage-1]->mPageRect.Top()+aSidebarheight);
1058  if ( !(bBottom && bTop))
1059  {
1060  const long aDiff = bBottom ? mpEditWin->LogicToPixel(Point(0,mPages[aPage-1]->mPageRect.Top() + aSidebarheight)).Y() - pPostIt->GetPosPixel().Y() :
1061  mpEditWin->LogicToPixel(Point(0,mPages[aPage-1]->mPageRect.Bottom() - aSidebarheight)).Y() - (pPostIt->GetPosPixel().Y()+pPostIt->GetSizePixel().Height());
1062  // this just adds the missing value to get the next a* GetScrollSize() after aDiff
1063  // e.g aDiff= 61 POSTIT_SCROLL=50 --> lScroll = 100
1064  const auto nScrollSize = GetScrollSize();
1065  assert(nScrollSize);
1066  const long lScroll = bBottom ? (aDiff + ( nScrollSize - (aDiff % nScrollSize))) : (aDiff - (nScrollSize + (aDiff % nScrollSize)));
1067  Scroll(lScroll, aPage);
1068  }
1069  }
1070 }
1071 
1073 {
1074  long aPage = -1;
1075  // we don't know the page yet, lets find it ourselves
1076  std::vector<SwPostItPageItem*>::size_type n=0;
1077  for (auto const& page : mPages)
1078  {
1079  for (auto const& item : page->mvSidebarItems)
1080  {
1081  if (item->pPostIt==pPostIt)
1082  {
1083  aPage = n+1;
1084  break;
1085  }
1086  }
1087  ++n;
1088  }
1089  if (aPage!=-1)
1090  AutoScroll(pPostIt,aPage);
1091  tools::Rectangle aNoteRect (Point(pPostIt->GetPosPixel().X(),pPostIt->GetPosPixel().Y()-5),pPostIt->GetSizePixel());
1092  if (!aNoteRect.IsEmpty())
1094 }
1095 
1096 bool SwPostItMgr::ArrowEnabled(sal_uInt16 aDirection,unsigned long aPage) const
1097 {
1098  switch (aDirection)
1099  {
1100  case KEY_PAGEUP:
1101  {
1102  return (mPages[aPage-1]->lOffset != 0);
1103  }
1104  case KEY_PAGEDOWN:
1105  {
1106  return (!BorderOverPageBorder(aPage));
1107  }
1108  default: return false;
1109  }
1110 }
1111 
1112 Color SwPostItMgr::GetArrowColor(sal_uInt16 aDirection,unsigned long aPage) const
1113 {
1114  if (ArrowEnabled(aDirection,aPage))
1115  {
1116  if (Application::GetSettings().GetStyleSettings().GetHighContrastMode())
1117  return COL_WHITE;
1118  else
1120  }
1121  else
1122  {
1124  }
1125 }
1126 
1127 bool SwPostItMgr::LayoutByPage(std::vector<SwAnnotationWin*> &aVisiblePostItList, const tools::Rectangle& rBorder, long lNeededHeight)
1128 {
1129  /*** General layout idea:***/
1130  // - if we have space left, we always move the current one up,
1131  // otherwise the next one down
1132  // - first all notes are resized
1133  // - then the real layout starts
1134 
1135  //rBorder is the page rect
1136  const tools::Rectangle aBorder = mpEditWin->LogicToPixel(rBorder);
1137  long lTopBorder = aBorder.Top() + 5;
1138  long lBottomBorder = aBorder.Bottom() - 5;
1139  const long lVisibleHeight = lBottomBorder - lTopBorder; //aBorder.GetHeight() ;
1140  const size_t nPostItListSize = aVisiblePostItList.size();
1141  long lTranslatePos = 0;
1142  bool bScrollbars = false;
1143 
1144  // do all necessary resizings
1145  if (nPostItListSize > 0 && lVisibleHeight < lNeededHeight)
1146  {
1147  // ok, now we have to really resize and adding scrollbars
1148  const long lAverageHeight = (lVisibleHeight - nPostItListSize*GetSpaceBetween()) / nPostItListSize;
1149  if (lAverageHeight<GetMinimumSizeWithMeta())
1150  {
1151  bScrollbars = true;
1152  lTopBorder += GetSidebarScrollerHeight() + 10;
1153  lBottomBorder -= (GetSidebarScrollerHeight() + 10);
1154  for (auto const& visiblePostIt : aVisiblePostItList)
1155  visiblePostIt->SetSize(Size(visiblePostIt->VirtualSize().getWidth(),visiblePostIt->GetMinimumSizeWithMeta()));
1156  }
1157  else
1158  {
1159  for (auto const& visiblePostIt : aVisiblePostItList)
1160  {
1161  if ( visiblePostIt->VirtualSize().getHeight() > lAverageHeight)
1162  visiblePostIt->SetSize(Size(visiblePostIt->VirtualSize().getWidth(),lAverageHeight));
1163  }
1164  }
1165  }
1166 
1167  //start the real layout so nothing overlaps anymore
1168  if (aVisiblePostItList.size()>1)
1169  {
1170  int loop = 0;
1171  bool bDone = false;
1172  // if no window is moved anymore we are finished
1173  while (!bDone)
1174  {
1175  loop++;
1176  bDone = true;
1177  long lSpaceUsed = lTopBorder + GetSpaceBetween();
1178  for(auto i = aVisiblePostItList.begin(); i != aVisiblePostItList.end() ; ++i)
1179  {
1180  auto aNextPostIt = i;
1181  ++aNextPostIt;
1182 
1183  if (aNextPostIt != aVisiblePostItList.end())
1184  {
1185  lTranslatePos = ( (*i)->VirtualPos().Y() + (*i)->VirtualSize().Height()) - (*aNextPostIt)->VirtualPos().Y();
1186  if (lTranslatePos > 0) // note windows overlaps the next one
1187  {
1188  // we are not done yet, loop at least once more
1189  bDone = false;
1190  // if there is space left, move the current note up
1191  // it could also happen that there is no space left for the first note due to a scrollbar
1192  // then we also jump into, so we move the current one up and the next one down
1193  if ( (lSpaceUsed <= (*i)->VirtualPos().Y()) || (i==aVisiblePostItList.begin()))
1194  {
1195  // we have space left, so let's move the current one up
1196  if ( ((*i)->VirtualPos().Y()- lTranslatePos - GetSpaceBetween()) > lTopBorder)
1197  {
1198  if ((*aNextPostIt)->IsFollow())
1199  (*i)->TranslateTopPosition(-1*(lTranslatePos+ANCHORLINE_WIDTH));
1200  else
1201  (*i)->TranslateTopPosition(-1*(lTranslatePos+GetSpaceBetween()));
1202  }
1203  else
1204  {
1205  long lMoveUp = (*i)->VirtualPos().Y() - lTopBorder;
1206  (*i)->TranslateTopPosition(-1* lMoveUp);
1207  if ((*aNextPostIt)->IsFollow())
1208  (*aNextPostIt)->TranslateTopPosition( (lTranslatePos+ANCHORLINE_WIDTH) - lMoveUp);
1209  else
1210  (*aNextPostIt)->TranslateTopPosition( (lTranslatePos+GetSpaceBetween()) - lMoveUp);
1211  }
1212  }
1213  else
1214  {
1215  // no space left, left move the next one down
1216  if ((*aNextPostIt)->IsFollow())
1217  (*aNextPostIt)->TranslateTopPosition(lTranslatePos+ANCHORLINE_WIDTH);
1218  else
1219  (*aNextPostIt)->TranslateTopPosition(lTranslatePos+GetSpaceBetween());
1220  }
1221  }
1222  else
1223  {
1224  // the first one could overlap the topborder instead of a second note
1225  if (i==aVisiblePostItList.begin())
1226  {
1227  long lMoveDown = lTopBorder - (*i)->VirtualPos().Y();
1228  if (lMoveDown>0)
1229  {
1230  bDone = false;
1231  (*i)->TranslateTopPosition( lMoveDown);
1232  }
1233  }
1234  }
1235  if ( (*aNextPostIt)->IsFollow() )
1236  lSpaceUsed += (*i)->VirtualSize().Height() + ANCHORLINE_WIDTH;
1237  else
1238  lSpaceUsed += (*i)->VirtualSize().Height() + GetSpaceBetween();
1239  }
1240  else
1241  {
1242  //(*i) is the last visible item
1243  auto aPrevPostIt = i;
1244  --aPrevPostIt;
1245  lTranslatePos = ( (*aPrevPostIt)->VirtualPos().Y() + (*aPrevPostIt)->VirtualSize().Height() ) - (*i)->VirtualPos().Y();
1246  if (lTranslatePos > 0)
1247  {
1248  bDone = false;
1249  if ( ((*i)->VirtualPos().Y()+ (*i)->VirtualSize().Height()+lTranslatePos) < lBottomBorder)
1250  {
1251  if ( (*i)->IsFollow() )
1252  (*i)->TranslateTopPosition(lTranslatePos+ANCHORLINE_WIDTH);
1253  else
1254  (*i)->TranslateTopPosition(lTranslatePos+GetSpaceBetween());
1255  }
1256  else
1257  {
1258  (*i)->TranslateTopPosition(lBottomBorder - ((*i)->VirtualPos().Y()+ (*i)->VirtualSize().Height()) );
1259  }
1260  }
1261  else
1262  {
1263  // note does not overlap, but we might be over the lower border
1264  // only do this if there are no scrollbars, otherwise notes are supposed to overlap the border
1265  if (!bScrollbars && ((*i)->VirtualPos().Y()+ (*i)->VirtualSize().Height() > lBottomBorder) )
1266  {
1267  bDone = false;
1268  (*i)->TranslateTopPosition(lBottomBorder - ((*i)->VirtualPos().Y()+ (*i)->VirtualSize().Height()));
1269  }
1270  }
1271  }
1272  }
1273  // security check so we don't loop forever
1274  if (loop>MAX_LOOP_COUNT)
1275  {
1276  OSL_FAIL("PostItMgr::Layout(): We are looping forever");
1277  break;
1278  }
1279  }
1280  }
1281  else
1282  {
1283  // only one left, make sure it is not hidden at the top or bottom
1284  auto i = aVisiblePostItList.begin();
1285  lTranslatePos = lTopBorder - (*i)->VirtualPos().Y();
1286  if (lTranslatePos>0)
1287  {
1288  (*i)->TranslateTopPosition(lTranslatePos+GetSpaceBetween());
1289  }
1290  lTranslatePos = lBottomBorder - ((*i)->VirtualPos().Y()+ (*i)->VirtualSize().Height());
1291  if (lTranslatePos<0)
1292  {
1293  (*i)->TranslateTopPosition(lTranslatePos);
1294  }
1295  }
1296  return bScrollbars;
1297  }
1298 
1299 void SwPostItMgr::AddPostIts(const bool bCheckExistence, const bool bFocus)
1300 {
1301  const bool bEmpty = mvPostItFields.empty();
1304  std::vector<SwFormatField*> vFormatFields;
1305  pType->CollectPostIts(vFormatFields, rIDRA, mpWrtShell->GetLayout()->IsHideRedlines());
1306  for(auto pFormatField : vFormatFields)
1307  InsertItem(pFormatField, bCheckExistence, bFocus);
1308  // if we just added the first one we have to update the view for centering
1309  if (bEmpty && !mvPostItFields.empty())
1310  PrepareView(true);
1311 }
1312 
1314 {
1315  for (auto& postItField : mvPostItFields)
1316  {
1317  EndListening( *const_cast<SfxBroadcaster*>(postItField->GetBroadcaster()) );
1318  postItField->pPostIt.disposeAndClear();
1319  postItField.reset();
1320  }
1321  mvPostItFields.clear();
1322 
1323  // all postits removed, no items should be left in pages
1325 }
1326 
1327 namespace {
1328 
1329 class FilterFunctor
1330 {
1331 public:
1332  virtual bool operator()(const SwFormatField* pField) const = 0;
1333  virtual ~FilterFunctor() {}
1334 };
1335 
1336 class IsPostitField : public FilterFunctor
1337 {
1338 public:
1339  bool operator()(const SwFormatField* pField) const override
1340  {
1341  return pField->GetField()->GetTyp()->Which() == SwFieldIds::Postit;
1342  }
1343 };
1344 
1345 class IsPostitFieldWithAuthorOf : public FilterFunctor
1346 {
1347  OUString m_sAuthor;
1348 public:
1349  explicit IsPostitFieldWithAuthorOf(const OUString &rAuthor)
1350  : m_sAuthor(rAuthor)
1351  {
1352  }
1353  bool operator()(const SwFormatField* pField) const override
1354  {
1355  if (pField->GetField()->GetTyp()->Which() != SwFieldIds::Postit)
1356  return false;
1357  return static_cast<const SwPostItField*>(pField->GetField())->GetPar1() == m_sAuthor;
1358  }
1359 };
1360 
1361 class IsPostitFieldWithPostitId : public FilterFunctor
1362 {
1363  sal_uInt32 m_nPostItId;
1364 public:
1365  explicit IsPostitFieldWithPostitId(sal_uInt32 nPostItId)
1366  : m_nPostItId(nPostItId)
1367  {}
1368 
1369  bool operator()(const SwFormatField* pField) const override
1370  {
1371  if (pField->GetField()->GetTyp()->Which() != SwFieldIds::Postit)
1372  return false;
1373  return static_cast<const SwPostItField*>(pField->GetField())->GetPostItId() == m_nPostItId;
1374  }
1375 };
1376 
1377 class IsFieldNotDeleted : public FilterFunctor
1378 {
1379 private:
1380  IDocumentRedlineAccess const& m_rIDRA;
1381  FilterFunctor const& m_rNext;
1382 
1383 public:
1384  IsFieldNotDeleted(IDocumentRedlineAccess const& rIDRA,
1385  const FilterFunctor & rNext)
1386  : m_rIDRA(rIDRA)
1387  , m_rNext(rNext)
1388  {
1389  }
1390  bool operator()(const SwFormatField* pField) const override
1391  {
1392  if (!m_rNext(pField))
1393  return false;
1394  if (!pField->GetTextField())
1395  return false;
1396  return !sw::IsFieldDeletedInModel(m_rIDRA, *pField->GetTextField());
1397  }
1398 };
1399 
1400 //Manages the passed in vector by automatically removing entries if they are deleted
1401 //and automatically adding entries if they appear in the document and match the
1402 //functor.
1403 //
1404 //This will completely refill in the case of a "anonymous" NULL pField stating
1405 //rather unhelpfully that "something changed" so you may process the same
1406 //Fields more than once.
1407 class FieldDocWatchingStack : public SfxListener
1408 {
1409  std::vector<std::unique_ptr<SwSidebarItem>>& sidebarItemVector;
1410  std::vector<const SwFormatField*> v;
1411  SwDocShell& m_rDocShell;
1412  FilterFunctor& m_rFilter;
1413 
1414  virtual void Notify(SfxBroadcaster&, const SfxHint& rHint) override
1415  {
1416  const SwFormatFieldHint* pHint = dynamic_cast<const SwFormatFieldHint*>(&rHint);
1417  if (pHint)
1418  {
1419  bool bAllInvalidated = false;
1420  if (pHint->Which() == SwFormatFieldHintWhich::REMOVED)
1421  {
1422  const SwFormatField* pField = pHint->GetField();
1423  bAllInvalidated = pField == nullptr;
1424  if (!bAllInvalidated && m_rFilter(pField))
1425  {
1426  EndListening(const_cast<SwFormatField&>(*pField));
1427  v.erase(std::remove(v.begin(), v.end(), pField), v.end());
1428  }
1429  }
1430  else if (pHint->Which() == SwFormatFieldHintWhich::INSERTED)
1431  {
1432  const SwFormatField* pField = pHint->GetField();
1433  bAllInvalidated = pField == nullptr;
1434  if (!bAllInvalidated && m_rFilter(pField))
1435  {
1436  StartListening(const_cast<SwFormatField&>(*pField));
1437  v.push_back(pField);
1438  }
1439  }
1440 
1441  if (bAllInvalidated)
1442  FillVector();
1443 
1444  return;
1445  }
1446  }
1447 
1448 public:
1449  FieldDocWatchingStack(std::vector<std::unique_ptr<SwSidebarItem>>& in, SwDocShell &rDocShell, FilterFunctor& rFilter)
1450  : sidebarItemVector(in)
1451  , m_rDocShell(rDocShell)
1452  , m_rFilter(rFilter)
1453  {
1454  FillVector();
1455  StartListening(m_rDocShell);
1456  }
1457  void FillVector()
1458  {
1459  EndListeningToAllFields();
1460  v.clear();
1461  v.reserve(sidebarItemVector.size());
1462  for (auto const& p : sidebarItemVector)
1463  {
1464  const SwFormatField& rField = p->GetFormatField();
1465  if (!m_rFilter(&rField))
1466  continue;
1467  StartListening(const_cast<SwFormatField&>(rField));
1468  v.push_back(&rField);
1469  }
1470  }
1471  void EndListeningToAllFields()
1472  {
1473  for (auto const& pField : v)
1474  {
1475  EndListening(const_cast<SwFormatField&>(*pField));
1476  }
1477  }
1478  virtual ~FieldDocWatchingStack() override
1479  {
1480  EndListeningToAllFields();
1481  EndListening(m_rDocShell);
1482  }
1483  const SwFormatField* pop()
1484  {
1485  if (v.empty())
1486  return nullptr;
1487  const SwFormatField* p = v.back();
1488  EndListening(const_cast<SwFormatField&>(*p));
1489  v.pop_back();
1490  return p;
1491  }
1492 };
1493 
1494 }
1495 
1496 // copy to new vector, otherwise RemoveItem would operate and delete stuff on mvPostItFields as well
1497 // RemoveItem will clean up the core field and visible postit if necessary
1498 // we cannot just delete everything as before, as postits could move into change tracking
1499 void SwPostItMgr::Delete(const OUString& rAuthor)
1500 {
1502  if (HasActiveSidebarWin() && (GetActiveSidebarWin()->GetAuthor() == rAuthor))
1503  {
1504  SetActiveSidebarWin(nullptr);
1505  }
1506  SwRewriter aRewriter;
1507  aRewriter.AddRule(UndoArg1, SwResId(STR_DELETE_AUTHOR_NOTES) + rAuthor);
1508  mpWrtShell->StartUndo( SwUndoId::DELETE, &aRewriter );
1509 
1510  IsPostitFieldWithAuthorOf aFilter(rAuthor);
1512  IsFieldNotDeleted aFilter2(rIDRA, aFilter);
1513  FieldDocWatchingStack aStack(mvPostItFields, *mpView->GetDocShell(), aFilter2);
1514  while (const SwFormatField* pField = aStack.pop())
1515  {
1516  if (mpWrtShell->GotoField(*pField))
1517  mpWrtShell->DelRight();
1518  }
1519  mpWrtShell->EndUndo();
1520  PrepareView();
1522  mbLayout = true;
1523  CalcRects();
1524  LayoutPostIts();
1525 }
1526 
1527 void SwPostItMgr::Delete(sal_uInt32 nPostItId)
1528 {
1530  if (HasActiveSidebarWin() &&
1531  mpActivePostIt->GetPostItField()->GetPostItId() == nPostItId)
1532  {
1533  SetActiveSidebarWin(nullptr);
1534  }
1535  SwRewriter aRewriter;
1536  aRewriter.AddRule(UndoArg1, SwResId(STR_CONTENT_TYPE_SINGLE_POSTIT));
1537  mpWrtShell->StartUndo( SwUndoId::DELETE, &aRewriter );
1538 
1539  IsPostitFieldWithPostitId aFilter(nPostItId);
1541  IsFieldNotDeleted aFilter2(rIDRA, aFilter);
1542  FieldDocWatchingStack aStack(mvPostItFields, *mpView->GetDocShell(), aFilter2);
1543  const SwFormatField* pField = aStack.pop();
1544  if (pField && mpWrtShell->GotoField(*pField))
1545  mpWrtShell->DelRight();
1546  mpWrtShell->EndUndo();
1547  PrepareView();
1549  mbLayout = true;
1550  CalcRects();
1551  LayoutPostIts();
1552 }
1553 
1554 void SwPostItMgr::ToggleResolvedForThread(sal_uInt32 nPostItId)
1555 {
1557 
1558  SwRewriter aRewriter;
1559  aRewriter.AddRule(UndoArg1, SwResId(STR_CONTENT_TYPE_SINGLE_POSTIT));
1560 
1561  // We have no undo ID at the moment.
1562 
1563  IsPostitFieldWithPostitId aFilter(nPostItId);
1564  FieldDocWatchingStack aStack(mvPostItFields, *mpView->GetDocShell(), aFilter);
1565  const SwFormatField* pField = aStack.pop();
1566  // pField now contains our AnnotationWin object
1567  if (pField) {
1568  SwAnnotationWin* pWin = GetSidebarWin(pField);
1569  pWin->ToggleResolvedForThread();
1570  }
1571 
1572  PrepareView();
1574  mbLayout = true;
1575  CalcRects();
1576  LayoutPostIts();
1577 }
1578 
1579 
1581 {
1583  SetActiveSidebarWin(nullptr);
1584  SwRewriter aRewriter;
1585  aRewriter.AddRule(UndoArg1, SwResId(STR_DELETE_ALL_NOTES) );
1586  mpWrtShell->StartUndo( SwUndoId::DELETE, &aRewriter );
1587 
1588  IsPostitField aFilter;
1590  IsFieldNotDeleted aFilter2(rIDRA, aFilter);
1591  FieldDocWatchingStack aStack(mvPostItFields, *mpView->GetDocShell(),
1592  aFilter2);
1593  while (const SwFormatField* pField = aStack.pop())
1594  {
1595  if (mpWrtShell->GotoField(*pField))
1596  mpWrtShell->DelRight();
1597  }
1598 
1599  mpWrtShell->EndUndo();
1600  PrepareView();
1602  mbLayout = true;
1603  CalcRects();
1604  LayoutPostIts();
1605 }
1606 
1608 {
1609  if (mvPostItFields.empty())
1610  return;
1612  sw::annotation::SwAnnotationWin *pWin = pOrigActiveWin;
1613  if (!pWin)
1614  {
1615  for (auto const& postItField : mvPostItFields)
1616  {
1617  pWin = postItField->pPostIt;
1618  if (pWin)
1619  break;
1620  }
1621  }
1622  if (!pWin)
1623  return;
1624  SetActiveSidebarWin(pWin);
1625  OutlinerView* pOLV = pWin->GetOutlinerView();
1626  SfxItemSet aEditAttr(pOLV->GetAttribs());
1629  aDlgAttr.Put(aEditAttr);
1632  sal_uInt16 nRet = pDlg->Execute();
1633  if (RET_OK == nRet)
1634  {
1635  aDlgAttr.Put(*pDlg->GetOutputItemSet());
1636  FormatAll(aDlgAttr);
1637  }
1638  pDlg.disposeAndClear();
1639  SetActiveSidebarWin(pOrigActiveWin);
1640 }
1641 
1642 void SwPostItMgr::FormatAll(const SfxItemSet &rNewAttr)
1643 {
1645  SwRewriter aRewriter;
1646  aRewriter.AddRule(UndoArg1, SwResId(STR_FORMAT_ALL_NOTES) );
1647  mpWrtShell->StartUndo( SwUndoId::INSATTR, &aRewriter );
1648 
1649  for (auto const& postItField : mvPostItFields)
1650  {
1651  if (!postItField->pPostIt)
1652  continue;
1653  OutlinerView* pOLV = postItField->pPostIt->GetOutlinerView();
1654  //save old selection
1655  ESelection aOrigSel(pOLV->GetSelection());
1656  //select all
1657  Outliner *pOutliner = pOLV->GetOutliner();
1658  if (pOutliner)
1659  {
1660  sal_Int32 nParaCount = pOutliner->GetParagraphCount();
1661  if (nParaCount > 0)
1662  pOLV->SelectRange(0, nParaCount);
1663  }
1664  //set new char properties
1665  pOLV->SetAttribs(rNewAttr);
1666  //restore old selection
1667  pOLV->SetSelection(aOrigSel);
1668  // tdf#91596 store updated formatting in SwField
1669  postItField->pPostIt->UpdateData();
1670  }
1671 
1672  mpWrtShell->EndUndo();
1673  PrepareView();
1675  mbLayout = true;
1676  CalcRects();
1677  LayoutPostIts();
1678 }
1679 
1680 void SwPostItMgr::Hide( const OUString& rAuthor )
1681 {
1682  for (auto const& postItField : mvPostItFields)
1683  {
1684  if ( postItField->pPostIt && (postItField->pPostIt->GetAuthor() == rAuthor) )
1685  {
1686  postItField->bShow = false;
1687  postItField->pPostIt->HideNote();
1688  }
1689  }
1690 
1691  LayoutPostIts();
1692 }
1693 
1695 {
1696  for (auto const& postItField : mvPostItFields)
1697  {
1698  postItField->bShow = false;
1699  postItField->pPostIt->HideNote();
1700  }
1701 }
1702 
1704 {
1705  for (auto const& postItField : mvPostItFields)
1706  {
1707  postItField->bShow = true;
1708  }
1709  LayoutPostIts();
1710 }
1711 
1713 {
1714  for (auto const& postItField : mvPostItFields)
1715  {
1716  if ( postItField->GetBroadcaster() == pBroadcaster)
1717  return postItField->pPostIt;
1718  }
1719  return nullptr;
1720 }
1721 
1723 {
1724  for (auto const& postItField : mvPostItFields)
1725  {
1726  if ( postItField->GetFormatField().GetField() == pField )
1727  return postItField->pPostIt.get();
1728  }
1729  return nullptr;
1730 }
1731 
1733 {
1734  for (auto const& postItField : mvPostItFields)
1735  {
1736  if ( static_cast<const SwPostItField*>(postItField->GetFormatField().GetField())->GetPostItId() == nPostItId )
1737  return postItField->pPostIt.get();
1738  }
1739  return nullptr;
1740 }
1741 
1743  SwAnnotationWin* aPostIt )
1744 {
1745  if (mvPostItFields.size()>1)
1746  {
1747  auto i = std::find_if(mvPostItFields.begin(), mvPostItFields.end(),
1748  [&aPostIt](const std::unique_ptr<SwSidebarItem>& pField) { return pField->pPostIt == aPostIt; });
1749  if (i == mvPostItFields.end())
1750  return nullptr;
1751 
1752  auto iNextPostIt = i;
1753  if (aDirection == KEY_PAGEUP)
1754  {
1755  if ( iNextPostIt == mvPostItFields.begin() )
1756  {
1757  return nullptr;
1758  }
1759  --iNextPostIt;
1760  }
1761  else
1762  {
1763  ++iNextPostIt;
1764  if ( iNextPostIt == mvPostItFields.end() )
1765  {
1766  return nullptr;
1767  }
1768  }
1769  // lets quit, we are back at the beginning
1770  if ( (*iNextPostIt)->pPostIt == aPostIt)
1771  return nullptr;
1772  return (*iNextPostIt)->pPostIt;
1773  }
1774  else
1775  return nullptr;
1776 }
1777 
1779 {
1780  for (auto const& pPage : mPages)
1781  {
1782  for(auto b = pPage->mvSidebarItems.begin(); b!= pPage->mvSidebarItems.end(); ++b)
1783  {
1784  if ((*b)->pPostIt == mpActivePostIt)
1785  {
1786  auto aNext = b;
1787  ++aNext;
1788  bool bFollow = (aNext != pPage->mvSidebarItems.end()) && (*aNext)->pPostIt->IsFollow();
1789  if ( pPage->bScrollbar || bFollow )
1790  {
1791  return -1;
1792  }
1793  else
1794  {
1795  //if this is the last item, return the bottom border otherwise the next item
1796  if (aNext == pPage->mvSidebarItems.end())
1797  return mpEditWin->LogicToPixel(Point(0,pPage->mPageRect.Bottom())).Y() - GetSpaceBetween();
1798  else
1799  return (*aNext)->pPostIt->GetPosPixel().Y() - GetSpaceBetween();
1800  }
1801  }
1802  }
1803  }
1804 
1805  OSL_FAIL("SwPostItMgr::GetNextBorder(): We have to find a next border here");
1806  return -1;
1807 }
1808 
1809 void SwPostItMgr::SetShadowState(const SwPostItField* pField,bool bCursor)
1810 {
1811  if (pField)
1812  {
1813  if (pField !=mShadowState.mpShadowField)
1814  {
1816  {
1817  // reset old one if still alive
1818  // TODO: does not work properly if mouse and cursor was set
1819  sw::annotation::SwAnnotationWin* pOldPostIt =
1821  if (pOldPostIt && pOldPostIt->Shadow() && (pOldPostIt->Shadow()->GetShadowState() != SS_EDIT))
1822  pOldPostIt->SetViewState(ViewState::NORMAL);
1823  }
1824  //set new one, if it is not currently edited
1825  sw::annotation::SwAnnotationWin* pNewPostIt = GetAnnotationWin(pField);
1826  if (pNewPostIt && pNewPostIt->Shadow() && (pNewPostIt->Shadow()->GetShadowState() != SS_EDIT))
1827  {
1828  pNewPostIt->SetViewState(ViewState::VIEW);
1829  //remember our new field
1830  mShadowState.mpShadowField = pField;
1831  mShadowState.bCursor = false;
1832  mShadowState.bMouse = false;
1833  }
1834  }
1835  if (bCursor)
1836  mShadowState.bCursor = true;
1837  else
1838  mShadowState.bMouse = true;
1839  }
1840  else
1841  {
1843  {
1844  if (bCursor)
1845  mShadowState.bCursor = false;
1846  else
1847  mShadowState.bMouse = false;
1849  {
1850  // reset old one if still alive
1852  if (pOldPostIt && pOldPostIt->Shadow() && (pOldPostIt->Shadow()->GetShadowState() != SS_EDIT))
1853  {
1854  pOldPostIt->SetViewState(ViewState::NORMAL);
1855  mShadowState.mpShadowField = nullptr;
1856  }
1857  }
1858  }
1859  }
1860 }
1861 
1862 void SwPostItMgr::PrepareView(bool bIgnoreCount)
1863 {
1864  if (!HasNotes() || bIgnoreCount)
1865  {
1867  SwRootFrame* pLayout = mpWrtShell->GetLayout();
1868  if ( pLayout )
1872  }
1873 }
1874 
1875 bool SwPostItMgr::ShowScrollbar(const unsigned long aPage) const
1876 {
1877  if (mPages.size() > aPage-1)
1878  return (mPages[aPage-1]->bScrollbar && !mbWaitingForCalcRects);
1879  else
1880  return false;
1881 }
1882 
1883 bool SwPostItMgr::IsHit(const Point &aPointPixel)
1884 {
1885  if (HasNotes() && ShowNotes())
1886  {
1887  const Point aPoint = mpEditWin->PixelToLogic(aPointPixel);
1888  const SwRootFrame* pLayout = mpWrtShell->GetLayout();
1889  SwRect aPageFrame;
1890  const unsigned long nPageNum = SwPostItHelper::getPageInfo( aPageFrame, pLayout, aPoint );
1891  if( nPageNum )
1892  {
1893  tools::Rectangle aRect;
1894  OSL_ENSURE(mPages.size()>nPageNum-1,"SwPostitMgr:: page container size wrong");
1895  aRect = mPages[nPageNum-1]->eSidebarPosition == sw::sidebarwindows::SidebarPosition::LEFT
1896  ? tools::Rectangle(Point(aPageFrame.Left()-GetSidebarWidth()-GetSidebarBorderWidth(),aPageFrame.Top()),Size(GetSidebarWidth(),aPageFrame.Height()))
1897  : tools::Rectangle( Point(aPageFrame.Right()+GetSidebarBorderWidth(),aPageFrame.Top()) , Size(GetSidebarWidth(),aPageFrame.Height()));
1898  if (aRect.IsInside(aPoint))
1899  {
1900  // we hit the note's sidebar
1901  // lets now test for the arrow area
1902  if (mPages[nPageNum-1]->bScrollbar)
1903  return ScrollbarHit(nPageNum,aPoint);
1904  else
1905  return false;
1906  }
1907  }
1908  }
1909  return false;
1910 }
1911 
1913 {
1914  vcl::Window* pRet = nullptr;
1915 
1916  if (HasNotes() && ShowNotes())
1917  {
1918  bool bEnableMapMode = !mpEditWin->IsMapModeEnabled();
1919  if (bEnableMapMode)
1921 
1922  for (const std::unique_ptr<SwSidebarItem>& pItem : mvPostItFields)
1923  {
1924  SwAnnotationWin* pPostIt = pItem->pPostIt;
1925  if (!pPostIt)
1926  continue;
1927 
1928  if (pPostIt->IsHitWindow(rPointLogic))
1929  {
1930  pRet = pPostIt;
1931  break;
1932  }
1933  }
1934 
1935  if (bEnableMapMode)
1936  mpEditWin->EnableMapMode(false);
1937  }
1938 
1939  return pRet;
1940 }
1941 
1942 tools::Rectangle SwPostItMgr::GetBottomScrollRect(const unsigned long aPage) const
1943 {
1944  SwRect aPageRect = mPages[aPage-1]->mPageRect;
1945  Point aPointBottom = mPages[aPage-1]->eSidebarPosition == sw::sidebarwindows::SidebarPosition::LEFT
1946  ? Point(aPageRect.Left() - GetSidebarWidth() - GetSidebarBorderWidth() + mpEditWin->PixelToLogic(Size(2,0)).Width(),aPageRect.Bottom()- mpEditWin->PixelToLogic(Size(0,2+GetSidebarScrollerHeight())).Height())
1947  : Point(aPageRect.Right() + GetSidebarBorderWidth() + mpEditWin->PixelToLogic(Size(2,0)).Width(),aPageRect.Bottom()- mpEditWin->PixelToLogic(Size(0,2+GetSidebarScrollerHeight())).Height());
1949  return tools::Rectangle(aPointBottom,aSize);
1950 }
1951 
1952 tools::Rectangle SwPostItMgr::GetTopScrollRect(const unsigned long aPage) const
1953 {
1954  SwRect aPageRect = mPages[aPage-1]->mPageRect;
1955  Point aPointTop = mPages[aPage-1]->eSidebarPosition == sw::sidebarwindows::SidebarPosition::LEFT
1956  ? Point(aPageRect.Left() - GetSidebarWidth() -GetSidebarBorderWidth()+ mpEditWin->PixelToLogic(Size(2,0)).Width(),aPageRect.Top() + mpEditWin->PixelToLogic(Size(0,2)).Height())
1957  : Point(aPageRect.Right() + GetSidebarBorderWidth() + mpEditWin->PixelToLogic(Size(2,0)).Width(),aPageRect.Top() + mpEditWin->PixelToLogic(Size(0,2)).Height());
1959  return tools::Rectangle(aPointTop,aSize);
1960 }
1961 
1962 //IMPORTANT: if you change the rects here, also change SwPageFrame::PaintNotesSidebar()
1963 bool SwPostItMgr::ScrollbarHit(const unsigned long aPage,const Point &aPoint)
1964 {
1965  SwRect aPageRect = mPages[aPage-1]->mPageRect;
1966  Point aPointBottom = mPages[aPage-1]->eSidebarPosition == sw::sidebarwindows::SidebarPosition::LEFT
1967  ? Point(aPageRect.Left() - GetSidebarWidth()-GetSidebarBorderWidth() + mpEditWin->PixelToLogic(Size(2,0)).Width(),aPageRect.Bottom()- mpEditWin->PixelToLogic(Size(0,2+GetSidebarScrollerHeight())).Height())
1968  : Point(aPageRect.Right() + GetSidebarBorderWidth()+ mpEditWin->PixelToLogic(Size(2,0)).Width(),aPageRect.Bottom()- mpEditWin->PixelToLogic(Size(0,2+GetSidebarScrollerHeight())).Height());
1969 
1970  Point aPointTop = mPages[aPage-1]->eSidebarPosition == sw::sidebarwindows::SidebarPosition::LEFT
1971  ? Point(aPageRect.Left() - GetSidebarWidth()-GetSidebarBorderWidth()+ mpEditWin->PixelToLogic(Size(2,0)).Width(),aPageRect.Top() + mpEditWin->PixelToLogic(Size(0,2)).Height())
1972  : Point(aPageRect.Right()+GetSidebarBorderWidth()+ mpEditWin->PixelToLogic(Size(2,0)).Width(),aPageRect.Top() + mpEditWin->PixelToLogic(Size(0,2)).Height());
1973 
1974  tools::Rectangle aRectBottom(GetBottomScrollRect(aPage));
1975  tools::Rectangle aRectTop(GetTopScrollRect(aPage));
1976 
1977  if (aRectBottom.IsInside(aPoint))
1978  {
1979  if (aPoint.X() < long((aPointBottom.X() + GetSidebarWidth()/3)))
1980  Scroll( GetScrollSize(),aPage);
1981  else
1982  Scroll( -1*GetScrollSize(), aPage);
1983  return true;
1984  }
1985  else if (aRectTop.IsInside(aPoint))
1986  {
1987  if (aPoint.X() < long((aPointTop.X() + GetSidebarWidth()/3*2)))
1988  Scroll(GetScrollSize(), aPage);
1989  else
1990  Scroll(-1*GetScrollSize(), aPage);
1991  return true;
1992  }
1993  return false;
1994 }
1995 
1997 {
1998  if ( mbWaitingForCalcRects || mbLayouting || mvPostItFields.empty() )
1999  return;
2000 
2001  // find first valid note
2002  SwAnnotationWin *pFirstPostIt = nullptr;
2003  for (auto const& postItField : mvPostItFields)
2004  {
2005  pFirstPostIt = postItField->pPostIt;
2006  if (pFirstPostIt)
2007  break;
2008  }
2009 
2010  //if we have not found a valid note, forget about it and leave
2011  if (!pFirstPostIt)
2012  return;
2013 
2014  // yeah, I know, if this is a left page it could be wrong, but finding the page and the note is probably not even faster than just doing it
2015  // check, if anchor overlay object exists.
2016  const long aAnchorX = pFirstPostIt->Anchor()
2017  ? mpEditWin->LogicToPixel( Point(static_cast<long>(pFirstPostIt->Anchor()->GetSixthPosition().getX()),0)).X()
2018  : 0;
2019  const long aAnchorY = pFirstPostIt->Anchor()
2020  ? mpEditWin->LogicToPixel( Point(0,static_cast<long>(pFirstPostIt->Anchor()->GetSixthPosition().getY()))).Y() + 1
2021  : 0;
2022  if (Point(aAnchorX,aAnchorY) != pFirstPostIt->GetPosPixel())
2023  {
2024  long aAnchorPosX = 0;
2025  long aAnchorPosY = 0;
2026  for (const std::unique_ptr<SwPostItPageItem>& pPage : mPages)
2027  {
2028  for (auto const& item : pPage->mvSidebarItems)
2029  {
2030  // check, if anchor overlay object exists.
2031  if ( item->bShow && item->pPostIt && item->pPostIt->Anchor() )
2032  {
2033  aAnchorPosX = pPage->eSidebarPosition == sw::sidebarwindows::SidebarPosition::LEFT
2034  ? mpEditWin->LogicToPixel( Point(static_cast<long>(item->pPostIt->Anchor()->GetSeventhPosition().getX()),0)).X()
2035  : mpEditWin->LogicToPixel( Point(static_cast<long>(item->pPostIt->Anchor()->GetSixthPosition().getX()),0)).X();
2036  aAnchorPosY = mpEditWin->LogicToPixel( Point(0,static_cast<long>(item->pPostIt->Anchor()->GetSixthPosition().getY()))).Y() + 1;
2037  item->pPostIt->SetPosPixel(Point(aAnchorPosX,aAnchorPosY));
2038  }
2039  }
2040  }
2041  }
2042 }
2043 
2045 {
2046  // we only want to see notes if Options - Writer - View - Notes is ticked
2047  return mpWrtShell->GetViewOptions()->IsPostIts();
2048 }
2049 
2051 {
2052  return !mvPostItFields.empty();
2053 }
2054 
2055 unsigned long SwPostItMgr::GetSidebarWidth(bool bPx) const
2056 {
2057  bool bEnableMapMode = !mpWrtShell->GetOut()->IsMapModeEnabled();
2058  sal_uInt16 nZoom = mpWrtShell->GetViewOptions()->GetZoom();
2059  if (comphelper::LibreOfficeKit::isActive() && !bEnableMapMode)
2060  {
2061  // The output device is the tile and contains the real wanted scale factor.
2062  double fScaleX = double(mpWrtShell->GetOut()->GetMapMode().GetScaleX());
2063  nZoom = fScaleX * 100;
2064  }
2065  unsigned long aWidth = static_cast<unsigned long>(nZoom * 1.8);
2066 
2067  if (bPx)
2068  return aWidth;
2069  else
2070  {
2071  if (bEnableMapMode)
2072  // The output device is the window.
2074  long nRet = mpWrtShell->GetOut()->PixelToLogic(Size(aWidth, 0)).Width();
2075  if (bEnableMapMode)
2076  mpWrtShell->GetOut()->EnableMapMode(false);
2077  return nRet;
2078  }
2079 }
2080 
2081 unsigned long SwPostItMgr::GetSidebarBorderWidth(bool bPx) const
2082 {
2083  if (bPx)
2084  return 2;
2085  else
2086  return mpWrtShell->GetOut()->PixelToLogic(Size(2,0)).Width();
2087 }
2088 
2089 Color SwPostItMgr::GetColorDark(std::size_t aAuthorIndex)
2090 {
2091  if (!Application::GetSettings().GetStyleSettings().GetHighContrastMode())
2092  {
2093  static const Color aArrayNormal[] = {
2097 
2098  return aArrayNormal[ aAuthorIndex % SAL_N_ELEMENTS( aArrayNormal )];
2099  }
2100  else
2101  return COL_WHITE;
2102 }
2103 
2104 Color SwPostItMgr::GetColorLight(std::size_t aAuthorIndex)
2105 {
2106  if (!Application::GetSettings().GetStyleSettings().GetHighContrastMode())
2107  {
2108  static const Color aArrayLight[] = {
2112 
2113  return aArrayLight[ aAuthorIndex % SAL_N_ELEMENTS( aArrayLight )];
2114  }
2115  else
2116  return COL_WHITE;
2117 }
2118 
2119 Color SwPostItMgr::GetColorAnchor(std::size_t aAuthorIndex)
2120 {
2121  if (!Application::GetSettings().GetStyleSettings().GetHighContrastMode())
2122  {
2123  static const Color aArrayAnchor[] = {
2127 
2128  return aArrayAnchor[ aAuthorIndex % SAL_N_ELEMENTS( aArrayAnchor )];
2129  }
2130  else
2131  return COL_WHITE;
2132 }
2133 
2135 {
2136  if ( p != mpActivePostIt )
2137  {
2138  // we need the temp variable so we can set mpActivePostIt before we call DeactivatePostIt
2139  // therefore we get a new layout in DOCCHANGED when switching from postit to document,
2140  // otherwise, GetActivePostIt() would still hold our old postit
2141  SwAnnotationWin* pActive = mpActivePostIt;
2142  mpActivePostIt = p;
2143  if (pActive)
2144  {
2145  pActive->DeactivatePostIt();
2146  mShadowState.mpShadowField = nullptr;
2147  }
2148  if (mpActivePostIt)
2149  {
2151  mpView->AttrChangedNotify(nullptr);
2153  }
2154  }
2155 }
2156 
2157 IMPL_LINK_NOARG( SwPostItMgr, CalcHdl, void*, void )
2158 {
2159  mnEventId = nullptr;
2160  if ( mbLayouting )
2161  {
2162  OSL_FAIL("Reentrance problem in Layout Manager!");
2163  mbWaitingForCalcRects = false;
2164  return;
2165  }
2166 
2167  // do not change order, even if it would seem so in the first place, we need the calcrects always
2168  if (CalcRects() || mbLayout)
2169  {
2170  mbLayout = false;
2171  LayoutPostIts();
2172  }
2173 }
2174 
2176 {
2177  for (auto const& postItField : mvPostItFields)
2178  if ( postItField->pPostIt )
2179  postItField->pPostIt->Rescale();
2180 }
2181 
2183 {
2184  const Fraction& f( mpEditWin->GetMapMode().GetScaleY() );
2185  return sal_Int32(POSTIT_INITIAL_ANCHOR_DISTANCE * f);
2186 }
2187 
2189 {
2190  const Fraction& f( mpEditWin->GetMapMode().GetScaleY() );
2191  return sal_Int32(POSTIT_SPACE_BETWEEN * f);
2192 }
2193 
2195 {
2196  const Fraction& f( mpEditWin->GetMapMode().GetScaleY() );
2197  return sal_Int32((POSTIT_SPACE_BETWEEN + POSTIT_MINIMUMSIZE_WITH_META) * f);
2198 }
2199 
2201 {
2202  const Fraction& f( mpEditWin->GetMapMode().GetScaleY() );
2203  return sal_Int32(POSTIT_MINIMUMSIZE_WITH_META * f);
2204 }
2205 
2207 {
2208  const Fraction& f( mpEditWin->GetMapMode().GetScaleY() );
2209  return sal_Int32(POSTIT_SCROLL_SIDEBAR_HEIGHT * f);
2210 }
2211 
2213 {
2214  for (auto const& postItField : mvPostItFields)
2215  if ( postItField->pPostIt )
2216  postItField->pPostIt->SetSpellChecking();
2217 }
2218 
2220 {
2221  for (auto const& postItField : mvPostItFields)
2222  if ( postItField->pPostIt )
2223  postItField->pPostIt->SetReadonly( mbReadOnly );
2224 }
2225 
2227 {
2228  for (auto const& postItField : mvPostItFields)
2229  if ( postItField->pPostIt )
2230  postItField->pPostIt->CheckMetaText();
2231 
2232 }
2233 
2234 sal_uInt16 SwPostItMgr::Replace(SvxSearchItem const * pItem)
2235 {
2237  sal_uInt16 aResult = pWin->GetOutlinerView()->StartSearchAndReplace( *pItem );
2238  if (!aResult)
2239  SetActiveSidebarWin(nullptr);
2240  return aResult;
2241 }
2242 
2243 sal_uInt16 SwPostItMgr::FinishSearchReplace(const i18nutil::SearchOptions2& rSearchOptions, bool bSrchForward)
2244 {
2246  SvxSearchItem aItem(SID_SEARCH_ITEM );
2247  aItem.SetSearchOptions(rSearchOptions);
2248  aItem.SetBackward(!bSrchForward);
2249  sal_uInt16 aResult = pWin->GetOutlinerView()->StartSearchAndReplace( aItem );
2250  if (!aResult)
2251  SetActiveSidebarWin(nullptr);
2252  return aResult;
2253 }
2254 
2255 sal_uInt16 SwPostItMgr::SearchReplace(const SwFormatField &pField, const i18nutil::SearchOptions2& rSearchOptions, bool bSrchForward)
2256 {
2257  sal_uInt16 aResult = 0;
2258  SwAnnotationWin* pWin = GetSidebarWin(&pField);
2259  if (pWin)
2260  {
2261  ESelection aOldSelection = pWin->GetOutlinerView()->GetSelection();
2262  if (bSrchForward)
2263  pWin->GetOutlinerView()->SetSelection(ESelection(0,0,0,0));
2264  else
2265  pWin->GetOutlinerView()->SetSelection(
2267  SvxSearchItem aItem(SID_SEARCH_ITEM );
2268  aItem.SetSearchOptions(rSearchOptions);
2269  aItem.SetBackward(!bSrchForward);
2270  aResult = pWin->GetOutlinerView()->StartSearchAndReplace( aItem );
2271  if (!aResult)
2272  pWin->GetOutlinerView()->SetSelection(aOldSelection);
2273  else
2274  {
2275  SetActiveSidebarWin(pWin);
2276  MakeVisible(pWin);
2277  }
2278  }
2279  return aResult;
2280 }
2281 
2283 {
2284  // deselect any drawing or frame and leave editing mode
2285  SdrView* pSdrView = mpWrtShell->GetDrawView();
2286  if ( pSdrView && pSdrView->IsTextEdit() )
2287  {
2288  bool bLockView = mpWrtShell->IsViewLocked();
2289  mpWrtShell->LockView( true );
2291  mpWrtShell->LockView( bLockView );
2292  }
2293 
2295  {
2300 
2303  }
2304 }
2305 
2307 {
2308  return mpActivePostIt != nullptr;
2309 }
2310 
2312 {
2313  return HasActiveSidebarWin() &&
2314  mpActivePostIt != nullptr;
2315 }
2316 
2318 {
2319  if ( HasActiveSidebarWin() )
2320  {
2322  }
2323 }
2324 
2326 {
2327  if ( HasActiveSidebarWin() )
2328  {
2330  }
2331 }
2332 
2334 {
2335  if ( HasActiveSidebarWin() )
2336  {
2338  }
2339 }
2340 
2342 {
2343  if ( HasActiveSidebarWin() )
2344  {
2345  mpActivePostIt->Hide();
2346  }
2347 }
2348 
2350 {
2351  if ( HasActiveSidebarWin() )
2352  {
2354  }
2355 }
2356 
2358  const SwFormatField& rFormatField,
2359  SwAnnotationWin& rSidebarWin )
2360 {
2361  if ( mpFrameSidebarWinContainer == nullptr )
2362  {
2364  }
2365 
2366  const bool bInserted = mpFrameSidebarWinContainer->insert( rFrame, rFormatField, rSidebarWin );
2367  if ( bInserted &&
2369  {
2370  mpWrtShell->GetAccessibleMap()->InvalidatePosOrSize( nullptr, nullptr, &rSidebarWin, SwRect() );
2371  }
2372 }
2373 
2375  SwAnnotationWin& rSidebarWin )
2376 {
2377  if ( mpFrameSidebarWinContainer != nullptr )
2378  {
2379  const bool bRemoved = mpFrameSidebarWinContainer->remove( rFrame, rSidebarWin );
2380  if ( bRemoved &&
2382  {
2383  mpWrtShell->GetAccessibleMap()->A11yDispose( nullptr, nullptr, &rSidebarWin );
2384  }
2385  }
2386 }
2387 
2389 {
2390  bool bRet( false );
2391 
2392  if ( mpFrameSidebarWinContainer != nullptr )
2393  {
2394  bRet = !mpFrameSidebarWinContainer->empty( rFrame );
2395  }
2396 
2397  return bRet;
2398 }
2399 
2401  const sal_Int32 nIndex )
2402 {
2403  vcl::Window* pSidebarWin( nullptr );
2404 
2405  if ( mpFrameSidebarWinContainer != nullptr )
2406  {
2407  pSidebarWin = mpFrameSidebarWinContainer->get( rFrame, nIndex );
2408  }
2409 
2410  return pSidebarWin;
2411 }
2412 
2414  std::vector< vcl::Window* >* pChildren )
2415 {
2416  if ( mpFrameSidebarWinContainer != nullptr )
2417  {
2418  mpFrameSidebarWinContainer->getAll( rFrame, pChildren );
2419  }
2420 }
2421 
2423  for (auto const& pPage : mPages)
2424  {
2425  for(auto b = pPage->mvSidebarItems.begin(); b!= pPage->mvSidebarItems.end(); ++b)
2426  {
2427  if ((*b)->pPostIt->IsThreadResolved())
2428  {
2429  (*b)->pPostIt->SetResolved(true);
2430  (*b)->pPostIt->GetSidebarItem().bShow = visible;
2431  }
2432  }
2433  }
2434  LayoutPostIts();
2435 }
2436 
2438  // Given the topmost note as an argument, scans over all notes and sets the
2439  // 'resolved' state of each descendant of the top notes to the resolved state
2440  // of the top note.
2441  bool resolved = topNote->IsResolved();
2442  for (auto const& pPage : mPages)
2443  {
2444  for(auto b = pPage->mvSidebarItems.begin(); b!= pPage->mvSidebarItems.end(); ++b)
2445  {
2446  if((*b)->pPostIt->GetTopReplyNote() == topNote) {
2447  (*b)->pPostIt->SetResolved(resolved);
2448  }
2449  }
2450  }
2451 }
2452 
2454 void SwNoteProps::Notify( const css::uno::Sequence< OUString >& ) {}
2455 
2456 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual Point GetPosPixel() const
vcl::RenderContext * GetOut() const
Definition: viewsh.hxx:339
SfxViewFrame * GetViewFrame() const
const Fraction & GetScaleX() const
Instances of SwFields and those derived from it occur 0 to n times.
Definition: fldbas.hxx:240
void StopShellTimer()
Definition: view.cxx:1749
bool IsHit(const Point &aPointPixel)
Definition: PostItMgr.cxx:1883
Base class of the Writer layout elements.
Definition: frame.hxx:297
bool mbWaitingForCalcRects
Definition: PostItMgr.hxx:132
void CheckForRemovedPostIts()
Definition: PostItMgr.cxx:241
SfxHintId
Marks a position in the document model.
Definition: pam.hxx:35
vcl::Window * GetSidebarWinForFrameByIndex(const SwFrame &rFrame, const sal_Int32 nIndex)
Definition: PostItMgr.cxx:2400
void SetViewState(::sw::sidebarwindows::ViewState bViewState)
void HideActiveSidebarWin()
Definition: PostItMgr.cxx:2341
const SwField * GetField() const
Definition: fmtfld.hxx:111
virtual void DrawSelChanged() override
Definition: wrtsh3.cxx:104
void FormatAll(const SfxItemSet &rNewAttr)
Definition: PostItMgr.cxx:1642
SdrView * GetDrawView()
Definition: vnew.cxx:375
constexpr::Color COL_AUTHOR9_LIGHT(255, 231, 199)
const OUStringLiteral IsReadOnly("IsReadOnly")
bool ScrollbarHit(const unsigned long aPage, const Point &aPoint)
Definition: PostItMgr.cxx:1963
const SwStartNode * FindFooterStartNode() const
Definition: node.hxx:204
virtual ~SwPostItMgr() override
Definition: PostItMgr.cxx:230
OUString toISO8601(const css::util::DateTime &rDateTime)
const SwRect & GetAnchorRect() const
bool ArrowEnabled(sal_uInt16 aDirection, unsigned long aPage) const
Definition: PostItMgr.cxx:1096
constexpr::Color COL_AUTHOR6_LIGHT(230, 250, 250)
virtual const SfxItemSet * GetOutputItemSet() const =0
sal_Int32 GetInitialAnchorDistance() const
Definition: PostItMgr.cxx:2182
constexpr::Color COL_AUTHOR3_NORMAL(218, 248, 193)
long Height() const
#define POSTIT_INITIAL_ANCHOR_DISTANCE
Definition: PostItMgr.cxx:82
void CollectPostIts(std::vector< SwFormatField * > &rvFormatFields, IDocumentRedlineAccess const &rIDRA, bool HideRedlines)
Definition: fldbas.cxx:171
virtual SwFieldType * GetFieldType(SwFieldIds nResId, const OUString &rName, bool bDbFieldMatching) const =0
SwNodeIndex nNode
Definition: pam.hxx:37
IMPL_LINK_NOARG(SwPostItMgr, CalcHdl, void *, void)
Definition: PostItMgr.cxx:2157
CommentNotificationType
bool HasScrollbars() const
Definition: PostItMgr.cxx:643
sal_Int32 StartSearchAndReplace(const SvxSearchItem &rSearchItem)
void SetSearchOptions(const i18nutil::SearchOptions2 &rOpt)
sal_uIntPtr sal_uLong
void disposeAndClear()
bool IsPostIts() const
Definition: viewopt.hxx:268
constexpr::Color COL_AUTHOR6_NORMAL(210, 246, 246)
static const AllSettings & GetSettings()
std::size_t mRedlineAuthor
SwFormatFieldHintWhich Which() const
Definition: fmtfld.hxx:177
bool IsMapModeEnabled() const
double getX() const
sal_Int64 n
virtual Size GetSizePixel() const
constexpr::Color COL_AUTHOR2_LIGHT(233, 242, 255)
sal_Int32 GetMinimumSizeWithoutMeta() const
void Height(long nNew)
Definition: swrect.hxx:191
constexpr::Color COL_AUTHOR4_DARK(105, 43, 157)
#define POSTIT_MINIMUMSIZE_WITH_META
Definition: PostItMgr.cxx:85
sw::annotation::SwAnnotationWin * GetSidebarWin(const SfxBroadcaster *pBroadcaster) const
Definition: PostItMgr.cxx:1712
sal_Int16 nId
VclPtr< sw::annotation::SwAnnotationWin > mpActivePostIt
Definition: PostItMgr.hxx:133
constexpr::Color COL_AUTHOR8_NORMAL(211, 222, 232)
virtual OUString GetPar1() const override
Author.
Definition: docufld.cxx:1799
SwUndoId EndUndo(SwUndoId eUndoId=SwUndoId::EMPTY, const SwRewriter *pRewriter=nullptr)
Closes parenthesis of nUndoId, not used by UI.
Definition: edws.cxx:234
static ImplSVEvent * PostUserEvent(const Link< void *, void > &rLink, void *pCaller=nullptr, bool bReferenceLink=false)
const MapMode & GetMapMode() const
const IDocumentSettingAccess & getIDocumentSettingAccess() const
Provides access to the document setting interface.
Definition: viewsh.cxx:2583
double getY() const
SwNode & GetNode() const
Definition: ndindex.hxx:119
void SetActiveSidebarWin(sw::annotation::SwAnnotationWin *p)
Definition: PostItMgr.cxx:2134
vcl::Window * IsHitSidebarWindow(const Point &rPointLogic)
Get the matching window that is responsible for handling mouse events of rPointLogic, if any.
Definition: PostItMgr.cxx:1912
void EnterStdMode()
Definition: select.cxx:550
SwEditWin & GetEditWin()
Definition: view.hxx:401
sal_Int32 GetParagraphCount() const
void Pos(const Point &rNew)
Definition: swrect.hxx:169
bool mPositionFromCommentAnchor
If true, the overlay arrow points to the comment anchor, otherwise it points to the commented frame...
static Color GetColorAnchor(std::size_t aAuthorIndex)
Definition: PostItMgr.cxx:2119
bool HasActiveAnnotationWin() const
Definition: PostItMgr.cxx:2311
OString join(const OString &rSeparator, const std::vector< OString > &rSequence)
constexpr TypedWhichId< SvxLanguageItem > EE_CHAR_LANGUAGE_CJK(EE_CHAR_START+15)
SwSidebarItem * InsertItem(SfxBroadcaster *pItem, bool bCheckExistence, bool bFocus)
Definition: PostItMgr.cxx:278
void EnableMapMode(bool bEnable=true)
Of course Writer needs its own rectangles.
Definition: swrect.hxx:35
bool IsHitWindow(const Point &rPointLogic)
Is there a matching sub-widget inside this sidebar widget for rPointLogic?
void setTiledPainting(bool bTiledPainting)
constexpr::Color COL_AUTHOR2_NORMAL(216, 232, 255)
unsigned long GetSidebarBorderWidth(bool bPx=false) const
Definition: PostItMgr.cxx:2081
void EndAllAction()
Definition: edws.cxx:97
The root element of a Writer document layout.
Definition: rootfrm.hxx:79
constexpr::Color COL_AUTHOR7_NORMAL(237, 252, 163)
void TranslateTopPosition(const long aAmount)
void SetMapMode()
SfxHintId GetId() const
bool DelRight()
Definition: delete.cxx:292
SwWrtShell & GetWrtShell() const
Definition: view.hxx:398
const SwPostItField * GetPostItField() const
const sal_Int8 ANCHORLINE_WIDTH
void ShowHideResolvedNotes(bool visible)
Definition: PostItMgr.cxx:2422
IDocumentFieldsAccess const & getIDocumentFieldsAccess() const
Definition: doc.cxx:356
void PaintTile(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect)
void InvalidatePosOrSize(const SwFrame *pFrame, const SdrObject *pObj, vcl::Window *pWindow, const SwRect &rOldFrame)
Definition: accmap.cxx:2350
bool mbDeleteNote
Definition: PostItMgr.hxx:138
std::unique_ptr< sw::sidebarwindows::SwFrameSidebarWinContainer > mpFrameSidebarWinContainer
Definition: PostItMgr.hxx:145
VclPtr< sw::annotation::SwAnnotationWin > pPostIt
#define COL_NOTES_SIDEPANE_ARROW_DISABLED
Definition: PostItMgr.hxx:60
void SetSidebarPosition(sw::sidebarwindows::SidebarPosition eSidebarPosition)
const SwView & GetView() const
Definition: wrtsh.hxx:428
void Top(const long nTop)
Definition: swrect.hxx:204
constexpr::Color COL_AUTHOR8_LIGHT(226, 234, 241)
#define MAX_LOOP_COUNT
Definition: PostItMgr.cxx:89
void DisconnectSidebarWinFromFrame(const SwFrame &rFrame, sw::annotation::SwAnnotationWin &rSidebarWin)
Definition: PostItMgr.cxx:2374
SwAccessibleMap * GetAccessibleMap()
Definition: viewsh.cxx:2455
constexpr::Color COL_AUTHOR4_NORMAL(228, 210, 245)
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
const Fraction & GetScaleY() const
const SwTextField * GetTextField() const
Definition: fmtfld.hxx:129
void DrawNotesForPage(OutputDevice *pOutDev, sal_uInt32 nPage)
Definition: PostItMgr.cxx:957
SW_DLLPUBLIC void UpdateDataOnActiveSidebarWin()
Definition: PostItMgr.cxx:2325
#define X
constexpr::Color COL_AUTHOR7_LIGHT(242, 254, 181)
void SelectRange(sal_Int32 nFirst, sal_Int32 nCount)
SwView * mpView
Definition: PostItMgr.hxx:126
constexpr sal_uInt16 KEY_PAGEUP
static Color GetColorDark(std::size_t aAuthorIndex)
Definition: PostItMgr.cxx:2089
void libreOfficeKitViewCallback(int nType, const char *pPayload) const override
constexpr::Color COL_AUTHOR6_DARK(0, 128, 128)
void ExecViewOptions(SfxRequest &)
Definition: view0.cxx:352
constexpr::Color COL_AUTHOR8_DARK(53, 85, 107)
constexpr::Color COL_AUTHOR2_DARK(6, 70, 162)
long Top() const
static SvtScriptType GetScriptTypeOfLanguage(LanguageType nLang)
void Right(const long nRight)
Definition: swrect.hxx:200
const IDocumentRedlineAccess & getIDocumentRedlineAccess() const
Provides access to the document redline interface.
Definition: viewsh.cxx:2591
void AutoScroll(const sw::annotation::SwAnnotationWin *pPostIt, const unsigned long aPage)
Definition: PostItMgr.cxx:1050
constexpr::Color COL_AUTHOR1_LIGHT(255, 255, 195)
void PrepareView(bool bIgnoreCount=false)
Definition: PostItMgr.cxx:1862
OutlinerParaObject * mpAnswer
Definition: PostItMgr.hxx:140
#define POSTIT_SPACE_BETWEEN
Definition: PostItMgr.cxx:84
void MakeVisible(const SwRect &)
Definition: viewsh.cxx:567
void PaintTile(OutputDevice &rRenderContext)
Definition: PostItMgr.cxx:972
ImplSVEvent * mnEventId
Definition: PostItMgr.hxx:131
void SetBackward(bool bNewBackward)
void GetAllSidebarWinForFrame(const SwFrame &rFrame, std::vector< vcl::Window * > *pChildren)
Definition: PostItMgr.cxx:2413
#define SAL_N_ELEMENTS(arr)
sal_Int32 GetSpaceBetween() const
Definition: PostItMgr.cxx:2188
css::util::DateTime GetUNODateTime() const
long GetNextBorder()
Definition: PostItMgr.cxx:1778
static void RemoveUserEvent(ImplSVEvent *nUserEvent)
bool CalcRects()
Definition: PostItMgr.cxx:526
SwDoc * GetDoc()
returns Doc. But be careful!
Definition: docsh.hxx:203
void ConnectSidebarWinToFrame(const SwFrame &rFrame, const SwFormatField &rFormatField, sw::annotation::SwAnnotationWin &rSidebarWin)
Definition: PostItMgr.cxx:2357
sal_uInt32 GetPostItId() const
Definition: docufld.hxx:476
#define POSTIT_SCROLL_SIDEBAR_HEIGHT
Definition: PostItMgr.cxx:86
const DateTime & GetDateTime() const
Definition: docufld.hxx:473
SvtScriptType
#define SW_MOD()
Definition: swmodule.hxx:255
constexpr::Color COL_AUTHOR1_NORMAL(255, 255, 158)
void SetAttribs(const SfxItemSet &)
Color GetArrowColor(sal_uInt16 aDirection, unsigned long aPage) const
Definition: PostItMgr.cxx:1112
int i
::sw::mark::IMark * GetAnnotationMark() const
Definition: atrfld.cxx:718
const SwFormatField * GetField() const
Definition: fmtfld.hxx:176
void InitAnswer(OutlinerParaObject const *pText)
virtual void Draw(OutputDevice *pDev, const Point &, DrawFlags) override
SwRect mPageFrame
void DeleteActiveSidebarWin()
Definition: PostItMgr.cxx:2333
sal_uInt16 SearchReplace(const SwFormatField &pField, const i18nutil::SearchOptions2 &rSearchOptions, bool bSrchForward)
Definition: PostItMgr.cxx:2255
FieldShadowState mShadowState
Definition: PostItMgr.hxx:139
SwRect mPagePrtArea
void Focus(SfxBroadcaster &rBC)
Definition: PostItMgr.cxx:499
void SetSize(const Size &rSize)
bool ShowScrollbar(const unsigned long aPage) const
Definition: PostItMgr.cxx:1875
constexpr::Color COL_AUTHOR9_DARK(209, 118, 0)
virtual void Invalidate(InvalidateFlags nFlags=InvalidateFlags::NONE)
void AddPostIts(bool bCheckExistence=true, bool bFocus=true)
Definition: PostItMgr.cxx:1299
void Scroll(const long lScroll, const unsigned long aPage)
Definition: PostItMgr.cxx:998
long getLayoutHeight(const SwRootFrame *pRoot)
SwUndoId StartUndo(SwUndoId eUndoId=SwUndoId::EMPTY, const SwRewriter *pRewriter=nullptr)
Undo: set up Undo parenthesis, return nUndoId of this parenthesis.
Definition: edws.cxx:223
void MakeVisible(const sw::annotation::SwAnnotationWin *pPostIt)
Definition: PostItMgr.cxx:1072
void AddRule(SwUndoArg eWhat, const OUString &rWith)
Definition: SwRewriter.cxx:29
long Bottom() const
constexpr sal_uInt16 KEY_PAGEDOWN
void SetVirtualPosSize(const Point &aPoint, const Size &aSize)
bool IsInside(const Point &rPOINT) const
Outliner * GetOutliner() const
static SwAbstractDialogFactory * Create()
Definition: swabstdlg.cxx:36
const sal_Int16 mnEventId
sal_uLong mnStartNodeIdx
unsigned long mnPageNumber
void StartListening(SfxBroadcaster &rBroadcaster, DuplicateHandling eDuplicateHanding=DuplicateHandling::Unexpected)
OUString SwResId(const char *pId)
Definition: swmodule.cxx:178
constexpr::Color COL_AUTHOR4_LIGHT(239, 228, 248)
void SSize(const Size &rNew)
Definition: swrect.hxx:178
void LeaveDrawCreate()
Definition: view.hxx:523
VclPtr< SwEditWin > mpEditWin
Definition: PostItMgr.hxx:128
void GrabFocus()
constexpr::Color COL_AUTHOR3_LIGHT(226, 250, 207)
#define Y
sal_uInt32 CalcParent()
Calculate parent postit id of current annotation window.
SwDocShell * GetDocShell()
Definition: view.cxx:1107
const SwPostItField * mpShadowField
Definition: PostItMgr.hxx:76
bool IsReadOnly() const
bool HasFrameConnectedSidebarWins(const SwFrame &rFrame)
Definition: PostItMgr.cxx:2388
SwLayoutInfo maLayoutInfo
SwFieldType * GetTyp() const
Definition: fldbas.hxx:396
void Delete()
Definition: PostItMgr.cxx:1580
::sw::sidebarwindows::AnchorOverlayObject * Anchor()
SW_DLLPUBLIC bool HasActiveSidebarWin() const
Definition: PostItMgr.cxx:2306
void RemoveSidebarWin()
Definition: PostItMgr.cxx:1313
void LayoutPostIts()
Definition: PostItMgr.cxx:681
Point PixelToLogic(const Point &rDevicePt) const
Point LogicToPixel(const Point &rLogicPt) const
void CheckMetaText()
Definition: PostItMgr.cxx:2226
void PreparePageContainer()
Definition: PostItMgr.cxx:653
ESelection GetSelection() const
void ExecuteFormatAllDialog(SwView &rView)
Definition: PostItMgr.cxx:1607
SwPostItHelper::SwLayoutStatus mLayoutStatus
constexpr TypedWhichId< SvxLanguageItem > EE_CHAR_LANGUAGE_CTL(EE_CHAR_START+16)
constexpr::Color COL_AUTHOR1_DARK(198, 146, 0)
float v
void A11yDispose(const SwFrame *pFrame, const SdrObject *pObj, vcl::Window *pWindow, bool bRecursive=false, bool bCanSkipInvisible=true)
Definition: accmap.cxx:2224
void SetFollow(bool bIsFollow)
void ChangeSidebarItem(SwSidebarItem const &rSidebarItem)
void Left(const long nLeft)
Definition: swrect.hxx:195
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint)
bool IsFieldInDoc() const
Definition: atrfld.cxx:394
sal_uInt16 GetNumPages() const
Definition: viewsh.cxx:622
void Bottom(const long nBottom)
Definition: swrect.hxx:209
void AssureStdModeAtShell()
Definition: PostItMgr.cxx:2282
void ShowAnchorOnly(const Point &aPoint)
void GrabFocusOnActiveSidebarWin()
Definition: PostItMgr.cxx:2317
void SetSelection(const ESelection &)
sal_uInt16 Replace(SvxSearchItem const *pItem)
Definition: PostItMgr.cxx:2234
void ToggleInsModeOnActiveSidebarWin()
Definition: PostItMgr.cxx:2349
bool GotoField(const SwFormatField &rField)
Definition: wrtsh3.cxx:65
void MakeDrawView()
Definition: vnew.cxx:365
void SetReadOnlyState()
Definition: PostItMgr.cxx:2219
virtual bool IsTextEdit() const final override
const basegfx::B2DPoint & GetSixthPosition() const
weld::Window * GetFrameWeld() const
sal_Int32 GetSidebarScrollerHeight() const
Definition: PostItMgr.cxx:2206
static Color GetColorLight(std::size_t aAuthorIndex)
Definition: PostItMgr.cxx:2104
virtual VclPtr< sw::annotation::SwAnnotationWin > GetSidebarWindow(SwEditWin &rEditWin, SwPostItMgr &aMgr)=0
const std::vector< basegfx::B2DRange > & GetAnnotationTextRanges() const
virtual void ImplCommit() override
Definition: PostItMgr.cxx:2453
bool IsFieldDeletedInModel(IDocumentRedlineAccess const &rIDRA, SwTextField const &rTextField)
void CorrectPositions()
Definition: PostItMgr.cxx:1996
sal_Int32 GetScrollSize() const
Definition: PostItMgr.cxx:2194
virtual SwPosition GetAnchorPosition() const =0
void SetPosSizePixelRect(long nX, long nY, long nWidth, long nHeight, const SwRect &aAnchorRect, const long PageBorder)
sw::sidebarwindows::SidebarPosition meSidebarPosition
void LockView(bool b)
Definition: viewsh.hxx:463
const SwViewOption * GetViewOptions() const
Definition: viewsh.hxx:424
#define COL_NOTES_SIDEPANE_ARROW_ENABLED
Definition: PostItMgr.hxx:59
constexpr::Color COL_AUTHOR5_DARK(197, 0, 11)
bool mbLayouting
Definition: PostItMgr.hxx:136
virtual bool UseElement(SwRootFrame const &, IDocumentRedlineAccess const &)=0
void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: PostItMgr.cxx:323
void SetChangeTracking(const SwPostItHelper::SwLayoutStatus aStatus, const Color &aColor)
RET_OK
void UpdateResolvedStatus(const sw::annotation::SwAnnotationWin *topNote)
Definition: PostItMgr.cxx:2437
bool mbIsShowAnchor
Definition: PostItMgr.hxx:142
void EndListening(SfxBroadcaster &rBroadcaster, bool bRemoveAllDuplicates=false)
sal_Int32 GetMinimumSizeWithMeta() const
Definition: PostItMgr.cxx:2200
constexpr::Color COL_AUTHOR9_NORMAL(255, 226, 185)
sal_uInt16 GetZoom() const
Definition: viewopt.hxx:478
void EndTextEdit()
Deletes object if required.
Definition: feshview.cxx:1218
size_t IsObjSelected() const
Definition: feshview.cxx:1150
void * p
constexpr::Color COL_AUTHOR7_DARK(140, 132, 0)
void UnSelectFrame()
Definition: select.cxx:322
#define EE_TEXTPOS_MAX_COUNT
void Rescale()
Definition: PostItMgr.cxx:2175
bool HasNotes() const
Definition: PostItMgr.cxx:2050
constexpr TypedWhichId< SvxLanguageItem > EE_CHAR_LANGUAGE(EE_CHAR_START+14)
constexpr::Color COL_WHITE(0xFF, 0xFF, 0xFF)
UnoViewSharedPtr mpView
bool IsHideRedlines() const
Replacement for sw::DocumentRedlineManager::GetRedlineFlags() (this is layout-level redline hiding)...
Definition: rootfrm.hxx:416
void setSidebarChanged(SwRootFrame *pRoot, bool bBrowseMode)
virtual bool get(DocumentSettingId id) const =0
Return the specified document setting.
sw::annotation::SwAnnotationWin * GetActiveSidebarWin()
Definition: PostItMgr.hxx:232
void LeaveSelFrameMode()
Definition: select.cxx:719
void SetSpellChecking()
Definition: PostItMgr.cxx:2212
std::vector< std::unique_ptr< SwPostItPageItem > > mPages
Definition: PostItMgr.hxx:130
long mbLayoutHeight
Definition: PostItMgr.hxx:135
sw::annotation::SwAnnotationWin * GetNextPostIt(sal_uInt16 aDirection, sw::annotation::SwAnnotationWin *aPostIt)
Definition: PostItMgr.cxx:1742
tools::Rectangle GetBottomScrollRect(const unsigned long aPage) const
Definition: PostItMgr.cxx:1942
unsigned long GetSidebarWidth(bool bPx=false) const
Definition: PostItMgr.cxx:2055
SwPostItMgr(SwView *aDoc)
Definition: PostItMgr.cxx:191
reference_type * get() const
virtual OUString GetPar2() const override
Text.
Definition: docufld.cxx:1811
bool LayoutByPage(std::vector< sw::annotation::SwAnnotationWin * > &aVisiblePostItList, const tools::Rectangle &rBorder, long lNeededHeight)
Definition: PostItMgr.cxx:1127
SfxItemSet GetAttribs()
void(* f)(TrueTypeTable *)
sal_Int32 mnStartContent
bool mbReadOnly
Definition: PostItMgr.hxx:137
constexpr::Color COL_AUTHOR5_LIGHT(255, 227, 229)
bool IsShowAnchor() const
Definition: PostItMgr.hxx:104
bool BorderOverPageBorder(unsigned long aPage) const
Definition: PostItMgr.cxx:936
bool IsShowHiddenChar(bool bHard=false) const
Definition: viewopt.hxx:294
::sw::sidebarwindows::ShadowOverlayObject * Shadow()
virtual SdrView * GetDrawView() const override
Definition: viewdraw.cxx:612
virtual VclPtr< SfxAbstractTabDialog > CreateSwCharDlg(weld::Window *pParent, SwView &pVw, const SfxItemSet &rCoreSet, SwCharDlgMode nDialogMode, const OUString *pFormatStr=nullptr)=0
bool ShowNotes() const
Definition: PostItMgr.cxx:2044
#define EE_PARA_MAX_COUNT
void SetShadowState(const SwPostItField *pField, bool bCursor=true)
Definition: PostItMgr.cxx:1809
void StartAllAction()
For all views of this document.
Definition: edws.cxx:86
constexpr::Color COL_AUTHOR3_DARK(87, 157, 28)
SwRootFrame * GetLayout() const
Definition: viewsh.cxx:2069
void Push(PushFlags nFlags=PushFlags::ALL)
static SfxItemPool * GetAnnotationPool(SwView const &rV)
Definition: annotsh.cxx:125
SwLayoutStatus getLayoutInfos(SwLayoutInfo &o_rInfo, const SwPosition &rAnchorPos, const sw::mark::IMark *pAnnotationMark=nullptr)
virtual const SwFormatField & GetFormatField() const =0
virtual void Notify(const css::uno::Sequence< OUString > &aPropertyNames) override
Definition: PostItMgr.cxx:2454
SwFieldIds Which() const
Definition: fldbas.hxx:272
void ToggleResolvedForThread(sal_uInt32 nPostItId)
Definition: PostItMgr.cxx:1554
constexpr::Color COL_AUTHOR5_NORMAL(254, 205, 208)
std::vector< std::unique_ptr< SwSidebarItem > > mvPostItFields
Definition: PostItMgr.hxx:129
sw::annotation::SwAnnotationWin * GetAnnotationWin(const SwPostItField *pField) const
Definition: PostItMgr.cxx:1722
tools::Rectangle GetTopScrollRect(const unsigned long aPage) const
Definition: PostItMgr.cxx:1952
unsigned long getPageInfo(SwRect &rPageFrame, const SwRootFrame *, const Point &)
const SwStartNode * FindFootnoteStartNode() const
Definition: node.hxx:200
bool IsViewLocked() const
Definition: viewsh.hxx:462
SwRect mPosition
void RemoveItem(SfxBroadcaster *pBroadcast)
Definition: PostItMgr.cxx:301
Definition: view.hxx:144
bool GetResolved() const
Definition: docufld.cxx:1775
sal_uInt16 FinishSearchReplace(const i18nutil::SearchOptions2 &rSearchOptions, bool bSrchForward)
Definition: PostItMgr.cxx:2243
SwWrtShell * mpWrtShell
Definition: PostItMgr.hxx:127
bool IsSelFrameMode() const
Definition: wrtsh.hxx:170