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->mpPostIt)
254  SetActiveSidebarWin(nullptr);
255  p->mpPostIt.disposeAndClear();
256  bRemoved = true;
257  }
258  else
259  ++it;
260  }
261 
262  if ( !bRemoved )
263  return;
264 
265  // make sure that no deleted items remain in page lists
266  // todo: only remove deleted ones?!
267  if ( mvPostItFields.empty() )
268  {
270  PrepareView();
271  }
272  else
273  // if postits are their make sure that page lists are not empty
274  // otherwise sudden paints can cause pain (in BorderOverPageBorder)
275  CalcRects();
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 (auto pSwFormatField = dynamic_cast< SwFormatField *>( pItem ))
292  {
293  mvPostItFields.push_back(std::make_unique<SwAnnotationItem>(*pSwFormatField, 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->mpPostIt)
316  SetActiveSidebarWin(nullptr);
317  p->mpPostIt.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->mbPendingLayout = 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->mpPostIt)
402  {
403  postItField->mpPostIt->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->mpPostIt)
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->mpPostIt->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->mpPostIt)
513  {
514  postItField->mpPostIt->GrabFocus();
515  MakeVisible(postItField->mpPostIt);
516  }
517  else
518  {
519  // when the layout algorithm starts, this postit is created and receives focus
520  postItField->mbFocus = 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->mpPostIt)
592  pItem->mpPostIt->HideNote();
593  continue;
594  }
595 
596  if( SwPostItHelper::HIDDEN == pItem->mLayoutStatus )
597  {
599  {
600  if (pItem->mpPostIt)
601  pItem->mpPostIt->HideNote();
602  continue;
603  }
604  }
605 
606  const tools::ULong aPageNum = pItem->maLayoutInfo.mnPageNumber;
607  if (aPageNum > mPages.size())
608  {
609  const tools::ULong nNumberOfPages = mPages.size();
610  mPages.reserve(aPageNum);
611  for (tools::ULong 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  {
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->mbShow && postItField->mpPostIt && postItField->mpPostIt->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  tools::Long lPageSize = mpWrtShell->GetNumPages();
657  tools::Long lContainerSize = mPages.size();
658 
659  if (lContainerSize < lPageSize)
660  {
661  mPages.reserve(lPageSize);
662  for (tools::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  tools::ULong lNeededHeight = 0;
703  tools::Long mlPageBorder = 0;
704  tools::Long mlPageEnd = 0;
705 
706  for (auto const& pItem : pPage->mvSidebarItems)
707  {
708  VclPtr<SwAnnotationWin> pPostIt = pItem->mpPostIt;
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->mbShow)
732  {
734  tools::Long aPostItHeight = 0;
735  if (!pPostIt)
736  {
737  pPostIt = pItem->GetSidebarWindow( mpView->GetEditWin(),
738  *this );
739  pPostIt->InitControls();
740  pPostIt->SetReadonly(mbReadOnly);
741  pItem->mpPostIt = 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->mbFocus)
769  {
770  mbLayout = true;
771  pPostIt->GrabFocus();
772  pItem->mbFocus = 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  tools::Long aAvailableHeight = mpEditWin->LogicToPixel(Size(0,pPage->mPageRect.Height())).Height() - 2 * GetSidebarScrollerHeight();
800  tools::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 tools::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)
831  }
832  else
833  {
834  if (mpEditWin->PixelToLogic(Point(0,visiblePostIt->VirtualPos().Y())).Y() < (pPage->mPageRect.Top()+aSidebarheight))
835  {
836  if ( pPage->eSidebarPosition == sw::sidebarwindows::SidebarPosition::LEFT )
837  visiblePostIt->ShowAnchorOnly(Point( pPage->mPageRect.Left(),
838  pPage->mPageRect.Top()));
839  else if ( pPage->eSidebarPosition == sw::sidebarwindows::SidebarPosition::RIGHT )
840  visiblePostIt->ShowAnchorOnly(Point( pPage->mPageRect.Right(),
841  pPage->mPageRect.Top()));
842  }
843  else
844  {
845  if ( pPage->eSidebarPosition == sw::sidebarwindows::SidebarPosition::LEFT )
846  visiblePostIt->ShowAnchorOnly(Point(pPage->mPageRect.Left(),
847  pPage->mPageRect.Bottom()));
848  else if ( pPage->eSidebarPosition == sw::sidebarwindows::SidebarPosition::RIGHT )
849  visiblePostIt->ShowAnchorOnly(Point(pPage->mPageRect.Right(),
850  pPage->mPageRect.Bottom()));
851  }
852  OSL_ENSURE(pPage->bScrollbar,"SwPostItMgr::LayoutByPage(): note overlaps, but bScrollbar is not true");
853  }
854  }
855  }
856  else
857  {
858  for (auto const& visiblePostIt : aVisiblePostItList)
859  {
860  visiblePostIt->SetPosAndSize();
861  }
862 
863  bool bOldScrollbar = pPage->bScrollbar;
864  pPage->bScrollbar = false;
865  bUpdate = (bOldScrollbar != pPage->bScrollbar) || bUpdate;
866  }
867 
868  for (auto const& visiblePostIt : aVisiblePostItList)
869  {
871  {
872  if (visiblePostIt->GetSidebarItem().mbPendingLayout)
873  lcl_CommentNotification(mpView, CommentNotificationType::Add, &visiblePostIt->GetSidebarItem(), 0);
874  else if (visiblePostIt->IsAnchorRectChanged())
875  {
876  lcl_CommentNotification(mpView, CommentNotificationType::Modify, &visiblePostIt->GetSidebarItem(), 0);
877  visiblePostIt->ResetAnchorRectChanged();
878  }
879  }
880 
881  // Layout for this post it finished now
882  visiblePostIt->GetSidebarItem().mbPendingLayout = false;
883  }
884  }
885  else
886  {
887  if (pPage->bScrollbar)
888  bUpdate = true;
889  pPage->bScrollbar = false;
890  }
891  }
892 
893  if (!ShowNotes())
894  { // we do not want to see the notes anymore -> Options-Writer-View-Notes
896  bool bRepair = false;
897  for (auto const& postItField : mvPostItFields)
898  {
899  if (!postItField->UseElement(*mpWrtShell->GetLayout(), rIDRA))
900  {
901  OSL_FAIL("PostIt is not in doc!");
902  bRepair = true;
903  continue;
904  }
905 
906  if (postItField->mpPostIt)
907  {
908  postItField->mpPostIt->HideNote();
909  if (postItField->mpPostIt->HasChildPathFocus())
910  {
911  SetActiveSidebarWin(nullptr);
912  postItField->mpPostIt->GrabFocusToDocument();
913  }
914  }
915  }
916 
917  if ( bRepair )
919  }
920 
921  // notes scrollbar is otherwise not drawn correctly for some cases
922  // scrollbar area is enough
923  if (bUpdate)
924  mpEditWin->Invalidate(); /*This is a super expensive relayout and render of the entire page*/
925 
926  mbLayouting = false;
927  }
928 
929  if (bEnableMapMode)
930  mpEditWin->EnableMapMode(false);
931 }
932 
934 {
935  if ( mPages[aPage-1]->mvSidebarItems.empty() )
936  {
937  OSL_FAIL("Notes SidePane painted but no rects and page lists calculated!");
938  return false;
939  }
940 
941  auto aItem = mPages[aPage-1]->mvSidebarItems.end();
942  --aItem;
943  OSL_ENSURE ((*aItem)->mpPostIt,"BorderOverPageBorder: NULL postIt, should never happen");
944  if ((*aItem)->mpPostIt)
945  {
946  const tools::Long aSidebarheight = mPages[aPage-1]->bScrollbar ? mpEditWin->PixelToLogic(Size(0,GetSidebarScrollerHeight())).Height() : 0;
947  const tools::Long aEndValue = mpEditWin->PixelToLogic(Point(0,(*aItem)->mpPostIt->GetPosPixel().Y()+(*aItem)->mpPostIt->GetSizePixel().Height())).Y();
948  return aEndValue <= mPages[aPage-1]->mPageRect.Bottom()-aSidebarheight;
949  }
950  else
951  return false;
952 }
953 
954 void SwPostItMgr::DrawNotesForPage(OutputDevice *pOutDev, sal_uInt32 nPage)
955 {
956  assert(nPage < mPages.size());
957  if (nPage >= mPages.size())
958  return;
959  for (auto const& pItem : mPages[nPage]->mvSidebarItems)
960  {
961  SwAnnotationWin* pPostIt = pItem->mpPostIt;
962  if (!pPostIt)
963  continue;
964  Point aPoint(mpEditWin->PixelToLogic(pPostIt->GetPosPixel()));
965  pPostIt->DrawForPage(pOutDev, aPoint);
966  }
967 }
968 
970 {
971  for (const std::unique_ptr<SwSidebarItem>& pItem : mvPostItFields)
972  {
973  SwAnnotationWin* pPostIt = pItem->mpPostIt;
974  if (!pPostIt)
975  continue;
976 
977  bool bEnableMapMode = !mpEditWin->IsMapModeEnabled();
979  rRenderContext.Push(PushFlags::MAPMODE);
980  Point aOffset(mpEditWin->PixelToLogic(pPostIt->GetPosPixel()));
981  MapMode aMapMode(rRenderContext.GetMapMode());
982  aMapMode.SetOrigin(aMapMode.GetOrigin() + aOffset);
983  rRenderContext.SetMapMode(aMapMode);
984  Size aSize(rRenderContext.PixelToLogic(pPostIt->GetSizePixel()));
985  tools::Rectangle aRectangle(Point(0, 0), aSize);
986 
987  pPostIt->PaintTile(rRenderContext, aRectangle);
988 
989  rRenderContext.Pop();
990  if (bEnableMapMode)
991  mpEditWin->EnableMapMode(false);
992  }
993 }
994 
995 void SwPostItMgr::Scroll(const tools::Long lScroll,const tools::ULong aPage)
996 {
997  OSL_ENSURE((lScroll % GetScrollSize() )==0,"SwPostItMgr::Scroll: scrolling by wrong value");
998  // do not scroll more than necessary up or down
999  if ( ((mPages[aPage-1]->lOffset == 0) && (lScroll>0)) || ( BorderOverPageBorder(aPage) && (lScroll<0)) )
1000  return;
1001 
1002  const bool bOldUp = ArrowEnabled(KEY_PAGEUP,aPage);
1003  const bool bOldDown = ArrowEnabled(KEY_PAGEDOWN,aPage);
1004  const tools::Long aSidebarheight = mpEditWin->PixelToLogic(Size(0,GetSidebarScrollerHeight())).Height();
1005  for (auto const& item : mPages[aPage-1]->mvSidebarItems)
1006  {
1007  SwAnnotationWin* pPostIt = item->mpPostIt;
1008  // if this is an answer, we should take the normal position and not the real, slightly moved position
1009  pPostIt->SetVirtualPosSize(pPostIt->GetPosPixel(),pPostIt->GetSizePixel());
1010  pPostIt->TranslateTopPosition(lScroll);
1011 
1012  if (item->mbShow)
1013  {
1014  bool bBottom = mpEditWin->PixelToLogic(Point(0,pPostIt->VirtualPos().Y()+pPostIt->VirtualSize().Height())).Y() <= (mPages[aPage-1]->mPageRect.Bottom()-aSidebarheight);
1015  bool bTop = mpEditWin->PixelToLogic(Point(0,pPostIt->VirtualPos().Y())).Y() >= (mPages[aPage-1]->mPageRect.Top()+aSidebarheight);
1016  if ( bBottom && bTop)
1017  {
1018  pPostIt->ShowNote();
1019  }
1020  else
1021  {
1022  if ( mpEditWin->PixelToLogic(Point(0,pPostIt->VirtualPos().Y())).Y() < (mPages[aPage-1]->mPageRect.Top()+aSidebarheight))
1023  {
1024  if (mPages[aPage-1]->eSidebarPosition == sw::sidebarwindows::SidebarPosition::LEFT)
1025  pPostIt->ShowAnchorOnly(Point(mPages[aPage-1]->mPageRect.Left(),mPages[aPage-1]->mPageRect.Top()));
1026  else if (mPages[aPage-1]->eSidebarPosition == sw::sidebarwindows::SidebarPosition::RIGHT)
1027  pPostIt->ShowAnchorOnly(Point(mPages[aPage-1]->mPageRect.Right(),mPages[aPage-1]->mPageRect.Top()));
1028  }
1029  else
1030  {
1031  if (mPages[aPage-1]->eSidebarPosition == sw::sidebarwindows::SidebarPosition::LEFT)
1032  pPostIt->ShowAnchorOnly(Point(mPages[aPage-1]->mPageRect.Left(),mPages[aPage-1]->mPageRect.Bottom()));
1033  else if (mPages[aPage-1]->eSidebarPosition == sw::sidebarwindows::SidebarPosition::RIGHT)
1034  pPostIt->ShowAnchorOnly(Point(mPages[aPage-1]->mPageRect.Right(),mPages[aPage-1]->mPageRect.Bottom()));
1035  }
1036  }
1037  }
1038  }
1039  mPages[aPage-1]->lOffset += lScroll;
1040  if ( (bOldUp != ArrowEnabled(KEY_PAGEUP,aPage)) ||(bOldDown != ArrowEnabled(KEY_PAGEDOWN,aPage)) )
1041  {
1044  }
1045 }
1046 
1047 void SwPostItMgr::AutoScroll(const SwAnnotationWin* pPostIt,const tools::ULong aPage )
1048 {
1049  // otherwise all notes are visible
1050  if (!mPages[aPage-1]->bScrollbar)
1051  return;
1052 
1053  const tools::Long aSidebarheight = mpEditWin->PixelToLogic(Size(0,GetSidebarScrollerHeight())).Height();
1054  const bool bBottom = mpEditWin->PixelToLogic(Point(0,pPostIt->GetPosPixel().Y()+pPostIt->GetSizePixel().Height())).Y() <= (mPages[aPage-1]->mPageRect.Bottom()-aSidebarheight);
1055  const bool bTop = mpEditWin->PixelToLogic(Point(0,pPostIt->GetPosPixel().Y())).Y() >= (mPages[aPage-1]->mPageRect.Top()+aSidebarheight);
1056  if ( !(bBottom && bTop))
1057  {
1058  const tools::Long aDiff = bBottom ? mpEditWin->LogicToPixel(Point(0,mPages[aPage-1]->mPageRect.Top() + aSidebarheight)).Y() - pPostIt->GetPosPixel().Y() :
1059  mpEditWin->LogicToPixel(Point(0,mPages[aPage-1]->mPageRect.Bottom() - aSidebarheight)).Y() - (pPostIt->GetPosPixel().Y()+pPostIt->GetSizePixel().Height());
1060  // this just adds the missing value to get the next a* GetScrollSize() after aDiff
1061  // e.g aDiff= 61 POSTIT_SCROLL=50 --> lScroll = 100
1062  const auto nScrollSize = GetScrollSize();
1063  assert(nScrollSize);
1064  const tools::Long lScroll = bBottom ? (aDiff + ( nScrollSize - (aDiff % nScrollSize))) : (aDiff - (nScrollSize + (aDiff % nScrollSize)));
1065  Scroll(lScroll, aPage);
1066  }
1067 }
1068 
1070 {
1071  tools::Long aPage = -1;
1072  // we don't know the page yet, lets find it ourselves
1073  std::vector<SwPostItPageItem*>::size_type n=0;
1074  for (auto const& page : mPages)
1075  {
1076  for (auto const& item : page->mvSidebarItems)
1077  {
1078  if (item->mpPostIt==pPostIt)
1079  {
1080  aPage = n+1;
1081  break;
1082  }
1083  }
1084  ++n;
1085  }
1086  if (aPage!=-1)
1087  AutoScroll(pPostIt,aPage);
1088  tools::Rectangle aNoteRect (Point(pPostIt->GetPosPixel().X(),pPostIt->GetPosPixel().Y()-5),pPostIt->GetSizePixel());
1089  if (!aNoteRect.IsEmpty())
1091 }
1092 
1093 bool SwPostItMgr::ArrowEnabled(sal_uInt16 aDirection,tools::ULong aPage) const
1094 {
1095  switch (aDirection)
1096  {
1097  case KEY_PAGEUP:
1098  {
1099  return (mPages[aPage-1]->lOffset != 0);
1100  }
1101  case KEY_PAGEDOWN:
1102  {
1103  return (!BorderOverPageBorder(aPage));
1104  }
1105  default: return false;
1106  }
1107 }
1108 
1109 Color SwPostItMgr::GetArrowColor(sal_uInt16 aDirection,tools::ULong aPage) const
1110 {
1111  if (ArrowEnabled(aDirection,aPage))
1112  {
1113  if (Application::GetSettings().GetStyleSettings().GetHighContrastMode())
1114  return COL_WHITE;
1115  else
1117  }
1118  else
1119  {
1121  }
1122 }
1123 
1124 bool SwPostItMgr::LayoutByPage(std::vector<SwAnnotationWin*> &aVisiblePostItList, const tools::Rectangle& rBorder, tools::Long lNeededHeight)
1125 {
1126  /*** General layout idea:***/
1127  // - if we have space left, we always move the current one up,
1128  // otherwise the next one down
1129  // - first all notes are resized
1130  // - then the real layout starts
1131 
1132  //rBorder is the page rect
1133  const tools::Rectangle aBorder = mpEditWin->LogicToPixel(rBorder);
1134  tools::Long lTopBorder = aBorder.Top() + 5;
1135  tools::Long lBottomBorder = aBorder.Bottom() - 5;
1136  const tools::Long lVisibleHeight = lBottomBorder - lTopBorder; //aBorder.GetHeight() ;
1137  const size_t nPostItListSize = aVisiblePostItList.size();
1138  tools::Long lTranslatePos = 0;
1139  bool bScrollbars = false;
1140 
1141  // do all necessary resizings
1142  if (nPostItListSize > 0 && lVisibleHeight < lNeededHeight)
1143  {
1144  // ok, now we have to really resize and adding scrollbars
1145  const tools::Long lAverageHeight = (lVisibleHeight - nPostItListSize*GetSpaceBetween()) / nPostItListSize;
1146  if (lAverageHeight<GetMinimumSizeWithMeta())
1147  {
1148  bScrollbars = true;
1149  lTopBorder += GetSidebarScrollerHeight() + 10;
1150  lBottomBorder -= (GetSidebarScrollerHeight() + 10);
1151  for (auto const& visiblePostIt : aVisiblePostItList)
1152  visiblePostIt->SetSize(Size(visiblePostIt->VirtualSize().getWidth(),visiblePostIt->GetMinimumSizeWithMeta()));
1153  }
1154  else
1155  {
1156  for (auto const& visiblePostIt : aVisiblePostItList)
1157  {
1158  if ( visiblePostIt->VirtualSize().getHeight() > lAverageHeight)
1159  visiblePostIt->SetSize(Size(visiblePostIt->VirtualSize().getWidth(),lAverageHeight));
1160  }
1161  }
1162  }
1163 
1164  //start the real layout so nothing overlaps anymore
1165  if (aVisiblePostItList.size()>1)
1166  {
1167  int loop = 0;
1168  bool bDone = false;
1169  // if no window is moved anymore we are finished
1170  while (!bDone)
1171  {
1172  loop++;
1173  bDone = true;
1174  tools::Long lSpaceUsed = lTopBorder + GetSpaceBetween();
1175  for(auto i = aVisiblePostItList.begin(); i != aVisiblePostItList.end() ; ++i)
1176  {
1177  auto aNextPostIt = i;
1178  ++aNextPostIt;
1179 
1180  if (aNextPostIt != aVisiblePostItList.end())
1181  {
1182  lTranslatePos = ( (*i)->VirtualPos().Y() + (*i)->VirtualSize().Height()) - (*aNextPostIt)->VirtualPos().Y();
1183  if (lTranslatePos > 0) // note windows overlaps the next one
1184  {
1185  // we are not done yet, loop at least once more
1186  bDone = false;
1187  // if there is space left, move the current note up
1188  // it could also happen that there is no space left for the first note due to a scrollbar
1189  // then we also jump into, so we move the current one up and the next one down
1190  if ( (lSpaceUsed <= (*i)->VirtualPos().Y()) || (i==aVisiblePostItList.begin()))
1191  {
1192  // we have space left, so let's move the current one up
1193  if ( ((*i)->VirtualPos().Y()- lTranslatePos - GetSpaceBetween()) > lTopBorder)
1194  {
1195  if ((*aNextPostIt)->IsFollow())
1196  (*i)->TranslateTopPosition(-1*(lTranslatePos+ANCHORLINE_WIDTH));
1197  else
1198  (*i)->TranslateTopPosition(-1*(lTranslatePos+GetSpaceBetween()));
1199  }
1200  else
1201  {
1202  tools::Long lMoveUp = (*i)->VirtualPos().Y() - lTopBorder;
1203  (*i)->TranslateTopPosition(-1* lMoveUp);
1204  if ((*aNextPostIt)->IsFollow())
1205  (*aNextPostIt)->TranslateTopPosition( (lTranslatePos+ANCHORLINE_WIDTH) - lMoveUp);
1206  else
1207  (*aNextPostIt)->TranslateTopPosition( (lTranslatePos+GetSpaceBetween()) - lMoveUp);
1208  }
1209  }
1210  else
1211  {
1212  // no space left, left move the next one down
1213  if ((*aNextPostIt)->IsFollow())
1214  (*aNextPostIt)->TranslateTopPosition(lTranslatePos+ANCHORLINE_WIDTH);
1215  else
1216  (*aNextPostIt)->TranslateTopPosition(lTranslatePos+GetSpaceBetween());
1217  }
1218  }
1219  else
1220  {
1221  // the first one could overlap the topborder instead of a second note
1222  if (i==aVisiblePostItList.begin())
1223  {
1224  tools::Long lMoveDown = lTopBorder - (*i)->VirtualPos().Y();
1225  if (lMoveDown>0)
1226  {
1227  bDone = false;
1228  (*i)->TranslateTopPosition( lMoveDown);
1229  }
1230  }
1231  }
1232  if ( (*aNextPostIt)->IsFollow() )
1233  lSpaceUsed += (*i)->VirtualSize().Height() + ANCHORLINE_WIDTH;
1234  else
1235  lSpaceUsed += (*i)->VirtualSize().Height() + GetSpaceBetween();
1236  }
1237  else
1238  {
1239  //(*i) is the last visible item
1240  auto aPrevPostIt = i;
1241  --aPrevPostIt;
1242  lTranslatePos = ( (*aPrevPostIt)->VirtualPos().Y() + (*aPrevPostIt)->VirtualSize().Height() ) - (*i)->VirtualPos().Y();
1243  if (lTranslatePos > 0)
1244  {
1245  bDone = false;
1246  if ( ((*i)->VirtualPos().Y()+ (*i)->VirtualSize().Height()+lTranslatePos) < lBottomBorder)
1247  {
1248  if ( (*i)->IsFollow() )
1249  (*i)->TranslateTopPosition(lTranslatePos+ANCHORLINE_WIDTH);
1250  else
1251  (*i)->TranslateTopPosition(lTranslatePos+GetSpaceBetween());
1252  }
1253  else
1254  {
1255  (*i)->TranslateTopPosition(lBottomBorder - ((*i)->VirtualPos().Y()+ (*i)->VirtualSize().Height()) );
1256  }
1257  }
1258  else
1259  {
1260  // note does not overlap, but we might be over the lower border
1261  // only do this if there are no scrollbars, otherwise notes are supposed to overlap the border
1262  if (!bScrollbars && ((*i)->VirtualPos().Y()+ (*i)->VirtualSize().Height() > lBottomBorder) )
1263  {
1264  bDone = false;
1265  (*i)->TranslateTopPosition(lBottomBorder - ((*i)->VirtualPos().Y()+ (*i)->VirtualSize().Height()));
1266  }
1267  }
1268  }
1269  }
1270  // security check so we don't loop forever
1271  if (loop>MAX_LOOP_COUNT)
1272  {
1273  OSL_FAIL("PostItMgr::Layout(): We are looping forever");
1274  break;
1275  }
1276  }
1277  }
1278  else
1279  {
1280  // only one left, make sure it is not hidden at the top or bottom
1281  auto i = aVisiblePostItList.begin();
1282  lTranslatePos = lTopBorder - (*i)->VirtualPos().Y();
1283  if (lTranslatePos>0)
1284  {
1285  (*i)->TranslateTopPosition(lTranslatePos+GetSpaceBetween());
1286  }
1287  lTranslatePos = lBottomBorder - ((*i)->VirtualPos().Y()+ (*i)->VirtualSize().Height());
1288  if (lTranslatePos<0)
1289  {
1290  (*i)->TranslateTopPosition(lTranslatePos);
1291  }
1292  }
1293  return bScrollbars;
1294  }
1295 
1296 void SwPostItMgr::AddPostIts(const bool bCheckExistence, const bool bFocus)
1297 {
1298  const bool bEmpty = mvPostItFields.empty();
1301  std::vector<SwFormatField*> vFormatFields;
1302  pType->CollectPostIts(vFormatFields, rIDRA, mpWrtShell->GetLayout()->IsHideRedlines());
1303  for(auto pFormatField : vFormatFields)
1304  InsertItem(pFormatField, bCheckExistence, bFocus);
1305  // if we just added the first one we have to update the view for centering
1306  if (bEmpty && !mvPostItFields.empty())
1307  PrepareView(true);
1308 }
1309 
1311 {
1312  for (auto& postItField : mvPostItFields)
1313  {
1314  EndListening( *const_cast<SfxBroadcaster*>(postItField->GetBroadcaster()) );
1315  postItField->mpPostIt.disposeAndClear();
1316  postItField.reset();
1317  }
1318  mvPostItFields.clear();
1319 
1320  // all postits removed, no items should be left in pages
1322 }
1323 
1324 namespace {
1325 
1326 class FilterFunctor
1327 {
1328 public:
1329  virtual bool operator()(const SwFormatField* pField) const = 0;
1330  virtual ~FilterFunctor() {}
1331 };
1332 
1333 class IsPostitField : public FilterFunctor
1334 {
1335 public:
1336  bool operator()(const SwFormatField* pField) const override
1337  {
1338  return pField->GetField()->GetTyp()->Which() == SwFieldIds::Postit;
1339  }
1340 };
1341 
1342 class IsPostitFieldWithAuthorOf : public FilterFunctor
1343 {
1344  OUString m_sAuthor;
1345 public:
1346  explicit IsPostitFieldWithAuthorOf(const OUString &rAuthor)
1347  : m_sAuthor(rAuthor)
1348  {
1349  }
1350  bool operator()(const SwFormatField* pField) const override
1351  {
1352  if (pField->GetField()->GetTyp()->Which() != SwFieldIds::Postit)
1353  return false;
1354  return static_cast<const SwPostItField*>(pField->GetField())->GetPar1() == m_sAuthor;
1355  }
1356 };
1357 
1358 class IsPostitFieldWithPostitId : public FilterFunctor
1359 {
1360  sal_uInt32 m_nPostItId;
1361 public:
1362  explicit IsPostitFieldWithPostitId(sal_uInt32 nPostItId)
1363  : m_nPostItId(nPostItId)
1364  {}
1365 
1366  bool operator()(const SwFormatField* pField) const override
1367  {
1368  if (pField->GetField()->GetTyp()->Which() != SwFieldIds::Postit)
1369  return false;
1370  return static_cast<const SwPostItField*>(pField->GetField())->GetPostItId() == m_nPostItId;
1371  }
1372 };
1373 
1374 class IsFieldNotDeleted : public FilterFunctor
1375 {
1376 private:
1377  IDocumentRedlineAccess const& m_rIDRA;
1378  FilterFunctor const& m_rNext;
1379 
1380 public:
1381  IsFieldNotDeleted(IDocumentRedlineAccess const& rIDRA,
1382  const FilterFunctor & rNext)
1383  : m_rIDRA(rIDRA)
1384  , m_rNext(rNext)
1385  {
1386  }
1387  bool operator()(const SwFormatField* pField) const override
1388  {
1389  if (!m_rNext(pField))
1390  return false;
1391  if (!pField->GetTextField())
1392  return false;
1393  return !sw::IsFieldDeletedInModel(m_rIDRA, *pField->GetTextField());
1394  }
1395 };
1396 
1397 //Manages the passed in vector by automatically removing entries if they are deleted
1398 //and automatically adding entries if they appear in the document and match the
1399 //functor.
1400 //
1401 //This will completely refill in the case of a "anonymous" NULL pField stating
1402 //rather unhelpfully that "something changed" so you may process the same
1403 //Fields more than once.
1404 class FieldDocWatchingStack : public SfxListener
1405 {
1406  std::vector<std::unique_ptr<SwSidebarItem>>& sidebarItemVector;
1407  std::vector<const SwFormatField*> v;
1408  SwDocShell& m_rDocShell;
1409  FilterFunctor& m_rFilter;
1410 
1411  virtual void Notify(SfxBroadcaster&, const SfxHint& rHint) override
1412  {
1413  const SwFormatFieldHint* pHint = dynamic_cast<const SwFormatFieldHint*>(&rHint);
1414  if (!pHint)
1415  return;
1416 
1417  bool bAllInvalidated = false;
1418  if (pHint->Which() == SwFormatFieldHintWhich::REMOVED)
1419  {
1420  const SwFormatField* pField = pHint->GetField();
1421  bAllInvalidated = pField == nullptr;
1422  if (!bAllInvalidated && m_rFilter(pField))
1423  {
1424  EndListening(const_cast<SwFormatField&>(*pField));
1425  v.erase(std::remove(v.begin(), v.end(), pField), v.end());
1426  }
1427  }
1428  else if (pHint->Which() == SwFormatFieldHintWhich::INSERTED)
1429  {
1430  const SwFormatField* pField = pHint->GetField();
1431  bAllInvalidated = pField == nullptr;
1432  if (!bAllInvalidated && m_rFilter(pField))
1433  {
1434  StartListening(const_cast<SwFormatField&>(*pField));
1435  v.push_back(pField);
1436  }
1437  }
1438 
1439  if (bAllInvalidated)
1440  FillVector();
1441 
1442  return;
1443  }
1444 
1445 public:
1446  FieldDocWatchingStack(std::vector<std::unique_ptr<SwSidebarItem>>& in, SwDocShell &rDocShell, FilterFunctor& rFilter)
1447  : sidebarItemVector(in)
1448  , m_rDocShell(rDocShell)
1449  , m_rFilter(rFilter)
1450  {
1451  FillVector();
1452  StartListening(m_rDocShell);
1453  }
1454  void FillVector()
1455  {
1456  EndListeningToAllFields();
1457  v.clear();
1458  v.reserve(sidebarItemVector.size());
1459  for (auto const& p : sidebarItemVector)
1460  {
1461  const SwFormatField& rField = p->GetFormatField();
1462  if (!m_rFilter(&rField))
1463  continue;
1464  StartListening(const_cast<SwFormatField&>(rField));
1465  v.push_back(&rField);
1466  }
1467  }
1468  void EndListeningToAllFields()
1469  {
1470  for (auto const& pField : v)
1471  {
1472  EndListening(const_cast<SwFormatField&>(*pField));
1473  }
1474  }
1475  virtual ~FieldDocWatchingStack() override
1476  {
1477  EndListeningToAllFields();
1478  EndListening(m_rDocShell);
1479  }
1480  const SwFormatField* pop()
1481  {
1482  if (v.empty())
1483  return nullptr;
1484  const SwFormatField* p = v.back();
1485  EndListening(const_cast<SwFormatField&>(*p));
1486  v.pop_back();
1487  return p;
1488  }
1489 };
1490 
1491 }
1492 
1493 // copy to new vector, otherwise RemoveItem would operate and delete stuff on mvPostItFields as well
1494 // RemoveItem will clean up the core field and visible postit if necessary
1495 // we cannot just delete everything as before, as postits could move into change tracking
1496 void SwPostItMgr::Delete(const OUString& rAuthor)
1497 {
1499  if (HasActiveSidebarWin() && (GetActiveSidebarWin()->GetAuthor() == rAuthor))
1500  {
1501  SetActiveSidebarWin(nullptr);
1502  }
1503  SwRewriter aRewriter;
1504  aRewriter.AddRule(UndoArg1, SwResId(STR_DELETE_AUTHOR_NOTES) + rAuthor);
1505  mpWrtShell->StartUndo( SwUndoId::DELETE, &aRewriter );
1506 
1507  IsPostitFieldWithAuthorOf aFilter(rAuthor);
1509  IsFieldNotDeleted aFilter2(rIDRA, aFilter);
1510  FieldDocWatchingStack aStack(mvPostItFields, *mpView->GetDocShell(), aFilter2);
1511  while (const SwFormatField* pField = aStack.pop())
1512  {
1513  if (mpWrtShell->GotoField(*pField))
1514  mpWrtShell->DelRight();
1515  }
1516  mpWrtShell->EndUndo();
1517  PrepareView();
1519  mbLayout = true;
1520  CalcRects();
1521  LayoutPostIts();
1522 }
1523 
1524 void SwPostItMgr::Delete(sal_uInt32 nPostItId)
1525 {
1527  if (HasActiveSidebarWin() &&
1528  mpActivePostIt->GetPostItField()->GetPostItId() == nPostItId)
1529  {
1530  SetActiveSidebarWin(nullptr);
1531  }
1532  SwRewriter aRewriter;
1533  aRewriter.AddRule(UndoArg1, SwResId(STR_CONTENT_TYPE_SINGLE_POSTIT));
1534  mpWrtShell->StartUndo( SwUndoId::DELETE, &aRewriter );
1535 
1536  IsPostitFieldWithPostitId aFilter(nPostItId);
1538  IsFieldNotDeleted aFilter2(rIDRA, aFilter);
1539  FieldDocWatchingStack aStack(mvPostItFields, *mpView->GetDocShell(), aFilter2);
1540  const SwFormatField* pField = aStack.pop();
1541  if (pField && mpWrtShell->GotoField(*pField))
1542  mpWrtShell->DelRight();
1543  mpWrtShell->EndUndo();
1544  PrepareView();
1546  mbLayout = true;
1547  CalcRects();
1548  LayoutPostIts();
1549 }
1550 
1551 void SwPostItMgr::DeleteCommentThread(sal_uInt32 nPostItId)
1552 {
1554 
1555  SwRewriter aRewriter;
1556  aRewriter.AddRule(UndoArg1, SwResId(STR_CONTENT_TYPE_SINGLE_POSTIT));
1557 
1558  // We have no undo ID at the moment.
1559 
1560  IsPostitFieldWithPostitId aFilter(nPostItId);
1561  FieldDocWatchingStack aStack(mvPostItFields, *mpView->GetDocShell(), aFilter);
1562  const SwFormatField* pField = aStack.pop();
1563  // pField now contains our AnnotationWin object
1564  if (pField) {
1565  SwAnnotationWin* pWin = GetSidebarWin(pField);
1566  pWin->DeleteThread();
1567  }
1568  PrepareView();
1570  mbLayout = true;
1571  CalcRects();
1572  LayoutPostIts();
1573 }
1574 
1575 void SwPostItMgr::ToggleResolved(sal_uInt32 nPostItId)
1576 {
1578 
1579  SwRewriter aRewriter;
1580  aRewriter.AddRule(UndoArg1, SwResId(STR_CONTENT_TYPE_SINGLE_POSTIT));
1581 
1582  // We have no undo ID at the moment.
1583 
1584  IsPostitFieldWithPostitId aFilter(nPostItId);
1585  FieldDocWatchingStack aStack(mvPostItFields, *mpView->GetDocShell(), aFilter);
1586  const SwFormatField* pField = aStack.pop();
1587  // pField now contains our AnnotationWin object
1588  if (pField) {
1589  SwAnnotationWin* pWin = GetSidebarWin(pField);
1590  pWin->ToggleResolved();
1591  }
1592 
1593  PrepareView();
1595  mbLayout = true;
1596  CalcRects();
1597  LayoutPostIts();
1598 }
1599 
1600 void SwPostItMgr::ToggleResolvedForThread(sal_uInt32 nPostItId)
1601 {
1603 
1604  SwRewriter aRewriter;
1605  aRewriter.AddRule(UndoArg1, SwResId(STR_CONTENT_TYPE_SINGLE_POSTIT));
1606 
1607  // We have no undo ID at the moment.
1608 
1609  IsPostitFieldWithPostitId aFilter(nPostItId);
1610  FieldDocWatchingStack aStack(mvPostItFields, *mpView->GetDocShell(), aFilter);
1611  const SwFormatField* pField = aStack.pop();
1612  // pField now contains our AnnotationWin object
1613  if (pField) {
1614  SwAnnotationWin* pWin = GetSidebarWin(pField);
1615  pWin->ToggleResolvedForThread();
1616  }
1617 
1618  PrepareView();
1620  mbLayout = true;
1621  CalcRects();
1622  LayoutPostIts();
1623 }
1624 
1625 
1627 {
1629  SetActiveSidebarWin(nullptr);
1630  SwRewriter aRewriter;
1631  aRewriter.AddRule(UndoArg1, SwResId(STR_DELETE_ALL_NOTES) );
1632  mpWrtShell->StartUndo( SwUndoId::DELETE, &aRewriter );
1633 
1634  IsPostitField aFilter;
1636  IsFieldNotDeleted aFilter2(rIDRA, aFilter);
1637  FieldDocWatchingStack aStack(mvPostItFields, *mpView->GetDocShell(),
1638  aFilter2);
1639  while (const SwFormatField* pField = aStack.pop())
1640  {
1641  if (mpWrtShell->GotoField(*pField))
1642  mpWrtShell->DelRight();
1643  }
1644 
1645  mpWrtShell->EndUndo();
1646  PrepareView();
1648  mbLayout = true;
1649  CalcRects();
1650  LayoutPostIts();
1651 }
1652 
1654 {
1655  if (mvPostItFields.empty())
1656  return;
1658  sw::annotation::SwAnnotationWin *pWin = pOrigActiveWin;
1659  if (!pWin)
1660  {
1661  for (auto const& postItField : mvPostItFields)
1662  {
1663  pWin = postItField->mpPostIt;
1664  if (pWin)
1665  break;
1666  }
1667  }
1668  if (!pWin)
1669  return;
1670  SetActiveSidebarWin(pWin);
1671  OutlinerView* pOLV = pWin->GetOutlinerView();
1672  SfxItemSet aEditAttr(pOLV->GetAttribs());
1675  aDlgAttr.Put(aEditAttr);
1678  sal_uInt16 nRet = pDlg->Execute();
1679  if (RET_OK == nRet)
1680  {
1681  aDlgAttr.Put(*pDlg->GetOutputItemSet());
1682  FormatAll(aDlgAttr);
1683  }
1684  pDlg.disposeAndClear();
1685  SetActiveSidebarWin(pOrigActiveWin);
1686 }
1687 
1688 void SwPostItMgr::FormatAll(const SfxItemSet &rNewAttr)
1689 {
1691  SwRewriter aRewriter;
1692  aRewriter.AddRule(UndoArg1, SwResId(STR_FORMAT_ALL_NOTES) );
1693  mpWrtShell->StartUndo( SwUndoId::INSATTR, &aRewriter );
1694 
1695  for (auto const& postItField : mvPostItFields)
1696  {
1697  if (!postItField->mpPostIt)
1698  continue;
1699  OutlinerView* pOLV = postItField->mpPostIt->GetOutlinerView();
1700  //save old selection
1701  ESelection aOrigSel(pOLV->GetSelection());
1702  //select all
1703  Outliner *pOutliner = pOLV->GetOutliner();
1704  if (pOutliner)
1705  {
1706  sal_Int32 nParaCount = pOutliner->GetParagraphCount();
1707  if (nParaCount > 0)
1708  pOLV->SelectRange(0, nParaCount);
1709  }
1710  //set new char properties
1711  pOLV->SetAttribs(rNewAttr);
1712  //restore old selection
1713  pOLV->SetSelection(aOrigSel);
1714  // tdf#91596 store updated formatting in SwField
1715  postItField->mpPostIt->UpdateData();
1716  }
1717 
1718  mpWrtShell->EndUndo();
1719  PrepareView();
1721  mbLayout = true;
1722  CalcRects();
1723  LayoutPostIts();
1724 }
1725 
1726 void SwPostItMgr::Hide( std::u16string_view rAuthor )
1727 {
1728  for (auto const& postItField : mvPostItFields)
1729  {
1730  if ( postItField->mpPostIt && (postItField->mpPostIt->GetAuthor() == rAuthor) )
1731  {
1732  postItField->mbShow = false;
1733  postItField->mpPostIt->HideNote();
1734  }
1735  }
1736 
1737  LayoutPostIts();
1738 }
1739 
1741 {
1742  for (auto const& postItField : mvPostItFields)
1743  {
1744  postItField->mbShow = false;
1745  postItField->mpPostIt->HideNote();
1746  }
1747 }
1748 
1750 {
1751  for (auto const& postItField : mvPostItFields)
1752  {
1753  postItField->mbShow = true;
1754  }
1755  LayoutPostIts();
1756 }
1757 
1759 {
1760  for (auto const& postItField : mvPostItFields)
1761  {
1762  if ( postItField->GetBroadcaster() == pBroadcaster)
1763  return postItField->mpPostIt;
1764  }
1765  return nullptr;
1766 }
1767 
1769 {
1770  for (auto const& postItField : mvPostItFields)
1771  {
1772  if ( postItField->GetFormatField().GetField() == pField )
1773  return postItField->mpPostIt.get();
1774  }
1775  return nullptr;
1776 }
1777 
1779 {
1780  for (auto const& postItField : mvPostItFields)
1781  {
1782  if ( static_cast<const SwPostItField*>(postItField->GetFormatField().GetField())->GetPostItId() == nPostItId )
1783  return postItField->mpPostIt.get();
1784  }
1785  return nullptr;
1786 }
1787 
1789  SwAnnotationWin* aPostIt )
1790 {
1791  if (mvPostItFields.size()>1)
1792  {
1793  auto i = std::find_if(mvPostItFields.begin(), mvPostItFields.end(),
1794  [&aPostIt](const std::unique_ptr<SwSidebarItem>& pField) { return pField->mpPostIt == aPostIt; });
1795  if (i == mvPostItFields.end())
1796  return nullptr;
1797 
1798  auto iNextPostIt = i;
1799  if (aDirection == KEY_PAGEUP)
1800  {
1801  if ( iNextPostIt == mvPostItFields.begin() )
1802  {
1803  return nullptr;
1804  }
1805  --iNextPostIt;
1806  }
1807  else
1808  {
1809  ++iNextPostIt;
1810  if ( iNextPostIt == mvPostItFields.end() )
1811  {
1812  return nullptr;
1813  }
1814  }
1815  // lets quit, we are back at the beginning
1816  if ( (*iNextPostIt)->mpPostIt == aPostIt)
1817  return nullptr;
1818  return (*iNextPostIt)->mpPostIt;
1819  }
1820  else
1821  return nullptr;
1822 }
1823 
1825 {
1826  for (auto const& pPage : mPages)
1827  {
1828  for(auto b = pPage->mvSidebarItems.begin(); b!= pPage->mvSidebarItems.end(); ++b)
1829  {
1830  if ((*b)->mpPostIt == mpActivePostIt)
1831  {
1832  auto aNext = b;
1833  ++aNext;
1834  bool bFollow = (aNext != pPage->mvSidebarItems.end()) && (*aNext)->mpPostIt->IsFollow();
1835  if ( pPage->bScrollbar || bFollow )
1836  {
1837  return -1;
1838  }
1839  else
1840  {
1841  //if this is the last item, return the bottom border otherwise the next item
1842  if (aNext == pPage->mvSidebarItems.end())
1843  return mpEditWin->LogicToPixel(Point(0,pPage->mPageRect.Bottom())).Y() - GetSpaceBetween();
1844  else
1845  return (*aNext)->mpPostIt->GetPosPixel().Y() - GetSpaceBetween();
1846  }
1847  }
1848  }
1849  }
1850 
1851  OSL_FAIL("SwPostItMgr::GetNextBorder(): We have to find a next border here");
1852  return -1;
1853 }
1854 
1855 void SwPostItMgr::SetShadowState(const SwPostItField* pField,bool bCursor)
1856 {
1857  if (pField)
1858  {
1859  if (pField !=mShadowState.mpShadowField)
1860  {
1862  {
1863  // reset old one if still alive
1864  // TODO: does not work properly if mouse and cursor was set
1865  sw::annotation::SwAnnotationWin* pOldPostIt =
1867  if (pOldPostIt && pOldPostIt->Shadow() && (pOldPostIt->Shadow()->GetShadowState() != SS_EDIT))
1868  pOldPostIt->SetViewState(ViewState::NORMAL);
1869  }
1870  //set new one, if it is not currently edited
1871  sw::annotation::SwAnnotationWin* pNewPostIt = GetAnnotationWin(pField);
1872  if (pNewPostIt && pNewPostIt->Shadow() && (pNewPostIt->Shadow()->GetShadowState() != SS_EDIT))
1873  {
1874  pNewPostIt->SetViewState(ViewState::VIEW);
1875  //remember our new field
1876  mShadowState.mpShadowField = pField;
1877  mShadowState.bCursor = false;
1878  mShadowState.bMouse = false;
1879  }
1880  }
1881  if (bCursor)
1882  mShadowState.bCursor = true;
1883  else
1884  mShadowState.bMouse = true;
1885  }
1886  else
1887  {
1889  {
1890  if (bCursor)
1891  mShadowState.bCursor = false;
1892  else
1893  mShadowState.bMouse = false;
1895  {
1896  // reset old one if still alive
1898  if (pOldPostIt && pOldPostIt->Shadow() && (pOldPostIt->Shadow()->GetShadowState() != SS_EDIT))
1899  {
1900  pOldPostIt->SetViewState(ViewState::NORMAL);
1901  mShadowState.mpShadowField = nullptr;
1902  }
1903  }
1904  }
1905  }
1906 }
1907 
1908 void SwPostItMgr::PrepareView(bool bIgnoreCount)
1909 {
1910  if (!HasNotes() || bIgnoreCount)
1911  {
1913  SwRootFrame* pLayout = mpWrtShell->GetLayout();
1914  if ( pLayout )
1918  }
1919 }
1920 
1922 {
1923  if (mPages.size() > aPage-1)
1924  return (mPages[aPage-1]->bScrollbar && !mbWaitingForCalcRects);
1925  else
1926  return false;
1927 }
1928 
1929 bool SwPostItMgr::IsHit(const Point &aPointPixel)
1930 {
1931  if (HasNotes() && ShowNotes())
1932  {
1933  const Point aPoint = mpEditWin->PixelToLogic(aPointPixel);
1934  const SwRootFrame* pLayout = mpWrtShell->GetLayout();
1935  SwRect aPageFrame;
1936  const tools::ULong nPageNum = SwPostItHelper::getPageInfo( aPageFrame, pLayout, aPoint );
1937  if( nPageNum )
1938  {
1939  tools::Rectangle aRect;
1940  OSL_ENSURE(mPages.size()>nPageNum-1,"SwPostitMgr:: page container size wrong");
1941  aRect = mPages[nPageNum-1]->eSidebarPosition == sw::sidebarwindows::SidebarPosition::LEFT
1942  ? tools::Rectangle(Point(aPageFrame.Left()-GetSidebarWidth()-GetSidebarBorderWidth(),aPageFrame.Top()),Size(GetSidebarWidth(),aPageFrame.Height()))
1943  : tools::Rectangle( Point(aPageFrame.Right()+GetSidebarBorderWidth(),aPageFrame.Top()) , Size(GetSidebarWidth(),aPageFrame.Height()));
1944  if (aRect.IsInside(aPoint))
1945  {
1946  // we hit the note's sidebar
1947  // lets now test for the arrow area
1948  if (mPages[nPageNum-1]->bScrollbar)
1949  return ScrollbarHit(nPageNum,aPoint);
1950  else
1951  return false;
1952  }
1953  }
1954  }
1955  return false;
1956 }
1957 
1959 {
1960  vcl::Window* pRet = nullptr;
1961 
1962  if (HasNotes() && ShowNotes())
1963  {
1964  bool bEnableMapMode = !mpEditWin->IsMapModeEnabled();
1965  if (bEnableMapMode)
1967 
1968  for (const std::unique_ptr<SwSidebarItem>& pItem : mvPostItFields)
1969  {
1970  SwAnnotationWin* pPostIt = pItem->mpPostIt;
1971  if (!pPostIt)
1972  continue;
1973 
1974  if (pPostIt->IsHitWindow(rPointLogic))
1975  {
1976  pRet = pPostIt;
1977  break;
1978  }
1979  }
1980 
1981  if (bEnableMapMode)
1982  mpEditWin->EnableMapMode(false);
1983  }
1984 
1985  return pRet;
1986 }
1987 
1989 {
1990  SwRect aPageRect = mPages[aPage-1]->mPageRect;
1991  Point aPointBottom = mPages[aPage-1]->eSidebarPosition == sw::sidebarwindows::SidebarPosition::LEFT
1992  ? Point(aPageRect.Left() - GetSidebarWidth() - GetSidebarBorderWidth() + mpEditWin->PixelToLogic(Size(2,0)).Width(),aPageRect.Bottom()- mpEditWin->PixelToLogic(Size(0,2+GetSidebarScrollerHeight())).Height())
1993  : Point(aPageRect.Right() + GetSidebarBorderWidth() + mpEditWin->PixelToLogic(Size(2,0)).Width(),aPageRect.Bottom()- mpEditWin->PixelToLogic(Size(0,2+GetSidebarScrollerHeight())).Height());
1995  return tools::Rectangle(aPointBottom,aSize);
1996 }
1997 
1999 {
2000  SwRect aPageRect = mPages[aPage-1]->mPageRect;
2001  Point aPointTop = mPages[aPage-1]->eSidebarPosition == sw::sidebarwindows::SidebarPosition::LEFT
2002  ? Point(aPageRect.Left() - GetSidebarWidth() -GetSidebarBorderWidth()+ mpEditWin->PixelToLogic(Size(2,0)).Width(),aPageRect.Top() + mpEditWin->PixelToLogic(Size(0,2)).Height())
2003  : Point(aPageRect.Right() + GetSidebarBorderWidth() + mpEditWin->PixelToLogic(Size(2,0)).Width(),aPageRect.Top() + mpEditWin->PixelToLogic(Size(0,2)).Height());
2005  return tools::Rectangle(aPointTop,aSize);
2006 }
2007 
2008 //IMPORTANT: if you change the rects here, also change SwPageFrame::PaintNotesSidebar()
2009 bool SwPostItMgr::ScrollbarHit(const tools::ULong aPage,const Point &aPoint)
2010 {
2011  SwRect aPageRect = mPages[aPage-1]->mPageRect;
2012  Point aPointBottom = mPages[aPage-1]->eSidebarPosition == sw::sidebarwindows::SidebarPosition::LEFT
2013  ? Point(aPageRect.Left() - GetSidebarWidth()-GetSidebarBorderWidth() + mpEditWin->PixelToLogic(Size(2,0)).Width(),aPageRect.Bottom()- mpEditWin->PixelToLogic(Size(0,2+GetSidebarScrollerHeight())).Height())
2014  : Point(aPageRect.Right() + GetSidebarBorderWidth()+ mpEditWin->PixelToLogic(Size(2,0)).Width(),aPageRect.Bottom()- mpEditWin->PixelToLogic(Size(0,2+GetSidebarScrollerHeight())).Height());
2015 
2016  Point aPointTop = mPages[aPage-1]->eSidebarPosition == sw::sidebarwindows::SidebarPosition::LEFT
2017  ? Point(aPageRect.Left() - GetSidebarWidth()-GetSidebarBorderWidth()+ mpEditWin->PixelToLogic(Size(2,0)).Width(),aPageRect.Top() + mpEditWin->PixelToLogic(Size(0,2)).Height())
2018  : Point(aPageRect.Right()+GetSidebarBorderWidth()+ mpEditWin->PixelToLogic(Size(2,0)).Width(),aPageRect.Top() + mpEditWin->PixelToLogic(Size(0,2)).Height());
2019 
2020  tools::Rectangle aRectBottom(GetBottomScrollRect(aPage));
2021  tools::Rectangle aRectTop(GetTopScrollRect(aPage));
2022 
2023  if (aRectBottom.IsInside(aPoint))
2024  {
2025  if (aPoint.X() < tools::Long((aPointBottom.X() + GetSidebarWidth()/3)))
2026  Scroll( GetScrollSize(),aPage);
2027  else
2028  Scroll( -1*GetScrollSize(), aPage);
2029  return true;
2030  }
2031  else if (aRectTop.IsInside(aPoint))
2032  {
2033  if (aPoint.X() < tools::Long((aPointTop.X() + GetSidebarWidth()/3*2)))
2034  Scroll(GetScrollSize(), aPage);
2035  else
2036  Scroll(-1*GetScrollSize(), aPage);
2037  return true;
2038  }
2039  return false;
2040 }
2041 
2043 {
2044  if ( mbWaitingForCalcRects || mbLayouting || mvPostItFields.empty() )
2045  return;
2046 
2047  // find first valid note
2048  SwAnnotationWin *pFirstPostIt = nullptr;
2049  for (auto const& postItField : mvPostItFields)
2050  {
2051  pFirstPostIt = postItField->mpPostIt;
2052  if (pFirstPostIt)
2053  break;
2054  }
2055 
2056  //if we have not found a valid note, forget about it and leave
2057  if (!pFirstPostIt)
2058  return;
2059 
2060  // 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
2061  // check, if anchor overlay object exists.
2062  const tools::Long aAnchorX = pFirstPostIt->Anchor()
2063  ? mpEditWin->LogicToPixel( Point(static_cast<tools::Long>(pFirstPostIt->Anchor()->GetSixthPosition().getX()),0)).X()
2064  : 0;
2065  const tools::Long aAnchorY = pFirstPostIt->Anchor()
2066  ? mpEditWin->LogicToPixel( Point(0,static_cast<tools::Long>(pFirstPostIt->Anchor()->GetSixthPosition().getY()))).Y() + 1
2067  : 0;
2068  if (Point(aAnchorX,aAnchorY) == pFirstPostIt->GetPosPixel())
2069  return;
2070 
2071  tools::Long aAnchorPosX = 0;
2072  tools::Long aAnchorPosY = 0;
2073  for (const std::unique_ptr<SwPostItPageItem>& pPage : mPages)
2074  {
2075  for (auto const& item : pPage->mvSidebarItems)
2076  {
2077  // check, if anchor overlay object exists.
2078  if ( item->mbShow && item->mpPostIt && item->mpPostIt->Anchor() )
2079  {
2080  aAnchorPosX = pPage->eSidebarPosition == sw::sidebarwindows::SidebarPosition::LEFT
2081  ? mpEditWin->LogicToPixel( Point(static_cast<tools::Long>(item->mpPostIt->Anchor()->GetSeventhPosition().getX()),0)).X()
2082  : mpEditWin->LogicToPixel( Point(static_cast<tools::Long>(item->mpPostIt->Anchor()->GetSixthPosition().getX()),0)).X();
2083  aAnchorPosY = mpEditWin->LogicToPixel( Point(0,static_cast<tools::Long>(item->mpPostIt->Anchor()->GetSixthPosition().getY()))).Y() + 1;
2084  item->mpPostIt->SetPosPixel(Point(aAnchorPosX,aAnchorPosY));
2085  }
2086  }
2087  }
2088 }
2089 
2091 {
2092  // we only want to see notes if Options - Writer - View - Notes is ticked
2093  return mpWrtShell->GetViewOptions()->IsPostIts();
2094 }
2095 
2097 {
2098  return !mvPostItFields.empty();
2099 }
2100 
2102 {
2103  bool bEnableMapMode = !mpWrtShell->GetOut()->IsMapModeEnabled();
2104  sal_uInt16 nZoom = mpWrtShell->GetViewOptions()->GetZoom();
2105  if (comphelper::LibreOfficeKit::isActive() && !bEnableMapMode)
2106  {
2107  // The output device is the tile and contains the real wanted scale factor.
2108  double fScaleX = double(mpWrtShell->GetOut()->GetMapMode().GetScaleX());
2109  nZoom = fScaleX * 100;
2110  }
2111  tools::ULong aWidth = static_cast<tools::ULong>(nZoom * 1.8);
2112 
2113  if (bPx)
2114  return aWidth;
2115  else
2116  {
2117  if (bEnableMapMode)
2118  // The output device is the window.
2120  tools::Long nRet = mpWrtShell->GetOut()->PixelToLogic(Size(aWidth, 0)).Width();
2121  if (bEnableMapMode)
2122  mpWrtShell->GetOut()->EnableMapMode(false);
2123  return nRet;
2124  }
2125 }
2126 
2128 {
2129  if (bPx)
2130  return 2;
2131  else
2132  return mpWrtShell->GetOut()->PixelToLogic(Size(2,0)).Width();
2133 }
2134 
2135 Color SwPostItMgr::GetColorDark(std::size_t aAuthorIndex)
2136 {
2137  if (!Application::GetSettings().GetStyleSettings().GetHighContrastMode())
2138  {
2139  static const Color aArrayNormal[] = {
2143 
2144  return aArrayNormal[ aAuthorIndex % SAL_N_ELEMENTS( aArrayNormal )];
2145  }
2146  else
2147  return COL_WHITE;
2148 }
2149 
2150 Color SwPostItMgr::GetColorLight(std::size_t aAuthorIndex)
2151 {
2152  if (!Application::GetSettings().GetStyleSettings().GetHighContrastMode())
2153  {
2154  static const Color aArrayLight[] = {
2158 
2159  return aArrayLight[ aAuthorIndex % SAL_N_ELEMENTS( aArrayLight )];
2160  }
2161  else
2162  return COL_WHITE;
2163 }
2164 
2165 Color SwPostItMgr::GetColorAnchor(std::size_t aAuthorIndex)
2166 {
2167  if (!Application::GetSettings().GetStyleSettings().GetHighContrastMode())
2168  {
2169  static const Color aArrayAnchor[] = {
2173 
2174  return aArrayAnchor[ aAuthorIndex % SAL_N_ELEMENTS( aArrayAnchor )];
2175  }
2176  else
2177  return COL_WHITE;
2178 }
2179 
2181 {
2182  if ( p == mpActivePostIt )
2183  return;
2184 
2185  // we need the temp variable so we can set mpActivePostIt before we call DeactivatePostIt
2186  // therefore we get a new layout in DOCCHANGED when switching from postit to document,
2187  // otherwise, GetActivePostIt() would still hold our old postit
2188  SwAnnotationWin* pActive = mpActivePostIt;
2189  mpActivePostIt = p;
2190  if (pActive)
2191  {
2192  pActive->DeactivatePostIt();
2193  mShadowState.mpShadowField = nullptr;
2194  }
2195  if (mpActivePostIt)
2196  {
2198  mpView->AttrChangedNotify(nullptr);
2200  }
2201 }
2202 
2203 IMPL_LINK_NOARG( SwPostItMgr, CalcHdl, void*, void )
2204 {
2205  mnEventId = nullptr;
2206  if ( mbLayouting )
2207  {
2208  OSL_FAIL("Reentrance problem in Layout Manager!");
2209  mbWaitingForCalcRects = false;
2210  return;
2211  }
2212 
2213  // do not change order, even if it would seem so in the first place, we need the calcrects always
2214  if (CalcRects() || mbLayout)
2215  {
2216  mbLayout = false;
2217  LayoutPostIts();
2218  }
2219 }
2220 
2222 {
2223  for (auto const& postItField : mvPostItFields)
2224  if ( postItField->mpPostIt )
2225  postItField->mpPostIt->Rescale();
2226 }
2227 
2229 {
2230  const Fraction& f( mpEditWin->GetMapMode().GetScaleY() );
2231  return sal_Int32(POSTIT_INITIAL_ANCHOR_DISTANCE * f);
2232 }
2233 
2235 {
2236  const Fraction& f( mpEditWin->GetMapMode().GetScaleY() );
2237  return sal_Int32(POSTIT_SPACE_BETWEEN * f);
2238 }
2239 
2241 {
2242  const Fraction& f( mpEditWin->GetMapMode().GetScaleY() );
2243  return sal_Int32((POSTIT_SPACE_BETWEEN + POSTIT_MINIMUMSIZE_WITH_META) * f);
2244 }
2245 
2247 {
2248  const Fraction& f( mpEditWin->GetMapMode().GetScaleY() );
2249  return sal_Int32(POSTIT_MINIMUMSIZE_WITH_META * f);
2250 }
2251 
2253 {
2254  const Fraction& f( mpEditWin->GetMapMode().GetScaleY() );
2255  return sal_Int32(POSTIT_SCROLL_SIDEBAR_HEIGHT * f);
2256 }
2257 
2259 {
2260  for (auto const& postItField : mvPostItFields)
2261  if ( postItField->mpPostIt )
2262  postItField->mpPostIt->SetSpellChecking();
2263 }
2264 
2266 {
2267  for (auto const& postItField : mvPostItFields)
2268  if ( postItField->mpPostIt )
2269  postItField->mpPostIt->SetReadonly( mbReadOnly );
2270 }
2271 
2273 {
2274  for (auto const& postItField : mvPostItFields)
2275  if ( postItField->mpPostIt )
2276  postItField->mpPostIt->CheckMetaText();
2277 
2278 }
2279 
2280 sal_uInt16 SwPostItMgr::Replace(SvxSearchItem const * pItem)
2281 {
2283  sal_uInt16 aResult = pWin->GetOutlinerView()->StartSearchAndReplace( *pItem );
2284  if (!aResult)
2285  SetActiveSidebarWin(nullptr);
2286  return aResult;
2287 }
2288 
2289 sal_uInt16 SwPostItMgr::FinishSearchReplace(const i18nutil::SearchOptions2& rSearchOptions, bool bSrchForward)
2290 {
2292  SvxSearchItem aItem(SID_SEARCH_ITEM );
2293  aItem.SetSearchOptions(rSearchOptions);
2294  aItem.SetBackward(!bSrchForward);
2295  sal_uInt16 aResult = pWin->GetOutlinerView()->StartSearchAndReplace( aItem );
2296  if (!aResult)
2297  SetActiveSidebarWin(nullptr);
2298  return aResult;
2299 }
2300 
2301 sal_uInt16 SwPostItMgr::SearchReplace(const SwFormatField &pField, const i18nutil::SearchOptions2& rSearchOptions, bool bSrchForward)
2302 {
2303  sal_uInt16 aResult = 0;
2304  SwAnnotationWin* pWin = GetSidebarWin(&pField);
2305  if (pWin)
2306  {
2307  ESelection aOldSelection = pWin->GetOutlinerView()->GetSelection();
2308  if (bSrchForward)
2309  pWin->GetOutlinerView()->SetSelection(ESelection(0,0,0,0));
2310  else
2311  pWin->GetOutlinerView()->SetSelection(
2313  SvxSearchItem aItem(SID_SEARCH_ITEM );
2314  aItem.SetSearchOptions(rSearchOptions);
2315  aItem.SetBackward(!bSrchForward);
2316  aResult = pWin->GetOutlinerView()->StartSearchAndReplace( aItem );
2317  if (!aResult)
2318  pWin->GetOutlinerView()->SetSelection(aOldSelection);
2319  else
2320  {
2321  SetActiveSidebarWin(pWin);
2322  MakeVisible(pWin);
2323  }
2324  }
2325  return aResult;
2326 }
2327 
2329 {
2330  // deselect any drawing or frame and leave editing mode
2331  SdrView* pSdrView = mpWrtShell->GetDrawView();
2332  if ( pSdrView && pSdrView->IsTextEdit() )
2333  {
2334  bool bLockView = mpWrtShell->IsViewLocked();
2335  mpWrtShell->LockView( true );
2337  mpWrtShell->LockView( bLockView );
2338  }
2339 
2341  {
2346 
2349  }
2350 }
2351 
2353 {
2354  return mpActivePostIt != nullptr;
2355 }
2356 
2358 {
2359  return HasActiveSidebarWin() &&
2360  mpActivePostIt != nullptr;
2361 }
2362 
2364 {
2365  if ( HasActiveSidebarWin() )
2366  {
2368  }
2369 }
2370 
2372 {
2373  if ( HasActiveSidebarWin() )
2374  {
2376  }
2377 }
2378 
2380 {
2381  if ( HasActiveSidebarWin() )
2382  {
2384  }
2385 }
2386 
2388 {
2389  if ( HasActiveSidebarWin() )
2390  {
2391  mpActivePostIt->Hide();
2392  }
2393 }
2394 
2396 {
2397  if ( HasActiveSidebarWin() )
2398  {
2400  }
2401 }
2402 
2404  const SwFormatField& rFormatField,
2405  SwAnnotationWin& rSidebarWin )
2406 {
2407  if ( mpFrameSidebarWinContainer == nullptr )
2408  {
2410  }
2411 
2412  const bool bInserted = mpFrameSidebarWinContainer->insert( rFrame, rFormatField, rSidebarWin );
2413  if ( bInserted &&
2415  {
2416  mpWrtShell->GetAccessibleMap()->InvalidatePosOrSize( nullptr, nullptr, &rSidebarWin, SwRect() );
2417  }
2418 }
2419 
2421  SwAnnotationWin& rSidebarWin )
2422 {
2423  if ( mpFrameSidebarWinContainer != nullptr )
2424  {
2425  const bool bRemoved = mpFrameSidebarWinContainer->remove( rFrame, rSidebarWin );
2426  if ( bRemoved &&
2428  {
2429  mpWrtShell->GetAccessibleMap()->A11yDispose( nullptr, nullptr, &rSidebarWin );
2430  }
2431  }
2432 }
2433 
2435 {
2436  bool bRet( false );
2437 
2438  if ( mpFrameSidebarWinContainer != nullptr )
2439  {
2440  bRet = !mpFrameSidebarWinContainer->empty( rFrame );
2441  }
2442 
2443  return bRet;
2444 }
2445 
2447  const sal_Int32 nIndex )
2448 {
2449  vcl::Window* pSidebarWin( nullptr );
2450 
2451  if ( mpFrameSidebarWinContainer != nullptr )
2452  {
2453  pSidebarWin = mpFrameSidebarWinContainer->get( rFrame, nIndex );
2454  }
2455 
2456  return pSidebarWin;
2457 }
2458 
2460  std::vector< vcl::Window* >* pChildren )
2461 {
2462  if ( mpFrameSidebarWinContainer != nullptr )
2463  {
2464  mpFrameSidebarWinContainer->getAll( rFrame, pChildren );
2465  }
2466 }
2467 
2469  for (auto const& pPage : mPages)
2470  {
2471  for(auto b = pPage->mvSidebarItems.begin(); b!= pPage->mvSidebarItems.end(); ++b)
2472  {
2473  if ((*b)->mpPostIt->IsResolved())
2474  {
2475  (*b)->mpPostIt->SetResolved(true);
2476  (*b)->mpPostIt->GetSidebarItem().mbShow = visible;
2477  }
2478  }
2479  }
2480  LayoutPostIts();
2481 }
2482 
2484  // Given the topmost note as an argument, scans over all notes and sets the
2485  // 'resolved' state of each descendant of the top notes to the resolved state
2486  // of the top note.
2487  bool resolved = topNote->IsResolved();
2488  for (auto const& pPage : mPages)
2489  {
2490  for(auto b = pPage->mvSidebarItems.begin(); b!= pPage->mvSidebarItems.end(); ++b)
2491  {
2492  if((*b)->mpPostIt->GetTopReplyNote() == topNote) {
2493  (*b)->mpPostIt->SetResolved(resolved);
2494  }
2495  }
2496  }
2497 }
2498 
2500 void SwNoteProps::Notify( const css::uno::Sequence< OUString >& ) {}
2501 
2502 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual Point GetPosPixel() const
vcl::RenderContext * GetOut() const
Definition: viewsh.hxx:338
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:1784
bool IsHit(const Point &aPointPixel)
Definition: PostItMgr.cxx:1929
Base class of the Writer layout elements.
Definition: frame.hxx:298
bool mbWaitingForCalcRects
Definition: PostItMgr.hxx:132
void CheckForRemovedPostIts()
Definition: PostItMgr.cxx:241
SfxHintId
void Right(const tools::Long nRight)
Definition: swrect.hxx:200
Marks a position in the document model.
Definition: pam.hxx:35
vcl::Window * GetSidebarWinForFrameByIndex(const SwFrame &rFrame, const sal_Int32 nIndex)
Definition: PostItMgr.cxx:2446
void SetViewState(::sw::sidebarwindows::ViewState bViewState)
void HideActiveSidebarWin()
Definition: PostItMgr.cxx:2387
const SwField * GetField() const
Definition: fmtfld.hxx:110
virtual void DrawSelChanged() override
Definition: wrtsh3.cxx:105
void FormatAll(const SfxItemSet &rNewAttr)
Definition: PostItMgr.cxx:1688
SdrView * GetDrawView()
Definition: vnew.cxx:376
constexpr::Color COL_AUTHOR9_LIGHT(255, 231, 199)
const SwStartNode * FindFooterStartNode() const
Definition: node.hxx:205
virtual ~SwPostItMgr() override
Definition: PostItMgr.cxx:230
OUString toISO8601(const css::util::DateTime &rDateTime)
const SwRect & GetAnchorRect() const
constexpr::Color COL_AUTHOR6_LIGHT(230, 250, 250)
virtual const SfxItemSet * GetOutputItemSet() const =0
sal_Int32 GetInitialAnchorDistance() const
Definition: PostItMgr.cxx:2228
constexpr::Color COL_AUTHOR3_NORMAL(218, 248, 193)
#define POSTIT_INITIAL_ANCHOR_DISTANCE
Definition: PostItMgr.cxx:82
void CollectPostIts(std::vector< SwFormatField * > &rvFormatFields, IDocumentRedlineAccess const &rIDRA, bool HideRedlines)
Definition: fldbas.cxx:183
virtual SwFieldType * GetFieldType(SwFieldIds nResId, const OUString &rName, bool bDbFieldMatching) const =0
void Left(const tools::Long nLeft)
Definition: swrect.hxx:195
SwNodeIndex nNode
Definition: pam.hxx:37
IMPL_LINK_NOARG(SwPostItMgr, CalcHdl, void *, void)
Definition: PostItMgr.cxx:2203
CommentNotificationType
bool HasScrollbars() const
Definition: PostItMgr.cxx:643
sal_Int32 StartSearchAndReplace(const SvxSearchItem &rSearchItem)
void SetSearchOptions(const i18nutil::SearchOptions2 &rOpt)
sal_uIntPtr sal_uLong
long Long
void disposeAndClear()
bool IsPostIts() const
Definition: viewopt.hxx:273
constexpr::Color COL_AUTHOR6_NORMAL(210, 246, 246)
static const AllSettings & GetSettings()
std::size_t mRedlineAuthor
SwFormatFieldHintWhich Which() const
Definition: fmtfld.hxx:176
bool IsMapModeEnabled() const
double getX() const
sal_Int64 n
virtual Size GetSizePixel() const
tools::ULong getPageInfo(SwRect &rPageFrame, const SwRootFrame *, const Point &)
constexpr::Color COL_AUTHOR2_LIGHT(233, 242, 255)
sal_Int32 GetMinimumSizeWithoutMeta() const
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:1758
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:1798
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:2661
double getY() const
SwNode & GetNode() const
Definition: ndindex.hxx:119
void SetActiveSidebarWin(sw::annotation::SwAnnotationWin *p)
Definition: PostItMgr.cxx:2180
vcl::Window * IsHitSidebarWindow(const Point &rPointLogic)
Get the matching window that is responsible for handling mouse events of rPointLogic, if any.
Definition: PostItMgr.cxx:1958
void EnterStdMode()
Definition: select.cxx:551
SwEditWin & GetEditWin()
Definition: view.hxx:416
sal_Int32 GetParagraphCount() const
tools::Long getLayoutHeight(const SwRootFrame *pRoot)
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:2165
bool HasActiveAnnotationWin() const
Definition: PostItMgr.cxx:2357
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)
void EndAllAction()
Definition: edws.cxx:97
The root element of a Writer document layout.
Definition: rootfrm.hxx:82
constexpr::Color COL_AUTHOR7_NORMAL(237, 252, 163)
void SetMapMode()
SfxHintId GetId() const
bool LayoutByPage(std::vector< sw::annotation::SwAnnotationWin * > &aVisiblePostItList, const tools::Rectangle &rBorder, tools::Long lNeededHeight)
Definition: PostItMgr.cxx:1124
bool DelRight()
Definition: delete.cxx:292
SwWrtShell & GetWrtShell() const
Definition: view.hxx:413
const SwPostItField * GetPostItField() const
const sal_Int8 ANCHORLINE_WIDTH
void ShowHideResolvedNotes(bool visible)
Definition: PostItMgr.cxx:2468
IDocumentFieldsAccess const & getIDocumentFieldsAccess() const
Definition: doc.cxx:357
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:2301
bool mbDeleteNote
Definition: PostItMgr.hxx:138
std::unique_ptr< sw::sidebarwindows::SwFrameSidebarWinContainer > mpFrameSidebarWinContainer
Definition: PostItMgr.hxx:145
#define COL_NOTES_SIDEPANE_ARROW_DISABLED
Definition: PostItMgr.hxx:60
void SetSidebarPosition(sw::sidebarwindows::SidebarPosition eSidebarPosition)
const SwView & GetView() const
Definition: wrtsh.hxx:429
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:2420
SwAccessibleMap * GetAccessibleMap()
Definition: viewsh.cxx:2516
constexpr::Color COL_AUTHOR4_NORMAL(228, 210, 245)
OString join(std::string_view rSeparator, const std::vector< OString > &rSequence)
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
const Fraction & GetScaleY() const
constexpr OUStringLiteral IsReadOnly(u"IsReadOnly")
const SwTextField * GetTextField() const
Definition: fmtfld.hxx:128
unsigned long ULong
void DrawNotesForPage(OutputDevice *pOutDev, sal_uInt32 nPage)
Definition: PostItMgr.cxx:954
SW_DLLPUBLIC void UpdateDataOnActiveSidebarWin()
Definition: PostItMgr.cxx:2371
constexpr::Color COL_AUTHOR7_LIGHT(242, 254, 181)
VclPtr< sw::annotation::SwAnnotationWin > mpPostIt
void SelectRange(sal_Int32 nFirst, sal_Int32 nCount)
SwView * mpView
Definition: PostItMgr.hxx:126
constexpr sal_uInt16 KEY_PAGEUP
tools::Long Bottom() const
static Color GetColorDark(std::size_t aAuthorIndex)
Definition: PostItMgr.cxx:2135
void libreOfficeKitViewCallback(int nType, const char *pPayload) const override
constexpr::Color COL_AUTHOR6_DARK(0, 128, 128)
void ExecViewOptions(SfxRequest &)
Definition: view0.cxx:361
constexpr::Color COL_AUTHOR8_DARK(53, 85, 107)
constexpr::Color COL_AUTHOR2_DARK(6, 70, 162)
static SvtScriptType GetScriptTypeOfLanguage(LanguageType nLang)
const IDocumentRedlineAccess & getIDocumentRedlineAccess() const
Provides access to the document redline interface.
Definition: viewsh.cxx:2669
constexpr::Color COL_AUTHOR1_LIGHT(255, 255, 195)
void PrepareView(bool bIgnoreCount=false)
Definition: PostItMgr.cxx:1908
OutlinerParaObject * mpAnswer
Definition: PostItMgr.hxx:140
#define POSTIT_SPACE_BETWEEN
Definition: PostItMgr.cxx:84
void MakeVisible(const SwRect &)
Definition: viewsh.cxx:570
void PaintTile(OutputDevice &rRenderContext)
Definition: PostItMgr.cxx:969
ImplSVEvent * mnEventId
Definition: PostItMgr.hxx:131
void SetBackward(bool bNewBackward)
void GetAllSidebarWinForFrame(const SwFrame &rFrame, std::vector< vcl::Window * > *pChildren)
Definition: PostItMgr.cxx:2459
#define SAL_N_ELEMENTS(arr)
sal_Int32 GetSpaceBetween() const
Definition: PostItMgr.cxx:2234
css::util::DateTime GetUNODateTime() const
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:2403
sal_uInt32 GetPostItId() const
Definition: docufld.hxx:480
#define POSTIT_SCROLL_SIDEBAR_HEIGHT
Definition: PostItMgr.cxx:86
const DateTime & GetDateTime() const
Definition: docufld.hxx:477
void DeleteCommentThread(sal_uInt32 nPostItId)
Definition: PostItMgr.cxx:1551
SvtScriptType
void ToggleResolved(sal_uInt32 nPostItId)
Definition: PostItMgr.cxx:1575
#define SW_MOD()
Definition: swmodule.hxx:255
constexpr::Color COL_AUTHOR1_NORMAL(255, 255, 158)
void SetAttribs(const SfxItemSet &)
int i
::sw::mark::IMark * GetAnnotationMark() const
Definition: atrfld.cxx:713
const SwFormatField * GetField() const
Definition: fmtfld.hxx:175
void InitAnswer(OutlinerParaObject const *pText)
SwRect mPageFrame
void DeleteActiveSidebarWin()
Definition: PostItMgr.cxx:2379
void Scroll(const tools::Long lScroll, const tools::ULong aPage)
Definition: PostItMgr.cxx:995
sal_uInt16 SearchReplace(const SwFormatField &pField, const i18nutil::SearchOptions2 &rSearchOptions, bool bSrchForward)
Definition: PostItMgr.cxx:2301
FieldShadowState mShadowState
Definition: PostItMgr.hxx:139
bool BorderOverPageBorder(tools::ULong aPage) const
Definition: PostItMgr.cxx:933
SwRect mPagePrtArea
void Focus(SfxBroadcaster &rBC)
Definition: PostItMgr.cxx:499
void SetSize(const Size &rSize)
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:1296
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:1069
void AddRule(SwUndoArg eWhat, const OUString &rWith)
Definition: SwRewriter.cxx:27
void AutoScroll(const sw::annotation::SwAnnotationWin *pPostIt, const tools::ULong aPage)
Definition: PostItMgr.cxx:1047
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
tools::ULong GetSidebarBorderWidth(bool bPx=false) const
Definition: PostItMgr.cxx:2127
const sal_Int16 mnEventId
sal_uLong mnStartNodeIdx
void StartListening(SfxBroadcaster &rBroadcaster, DuplicateHandling eDuplicateHanding=DuplicateHandling::Unexpected)
OUString SwResId(const char *pId)
Definition: swmodule.cxx:166
constexpr::Color COL_AUTHOR4_LIGHT(239, 228, 248)
void SSize(const Size &rNew)
Definition: swrect.hxx:178
void LeaveDrawCreate()
Definition: view.hxx:538
tools::Long Top() const
tools::ULong GetSidebarWidth(bool bPx=false) const
Definition: PostItMgr.cxx:2101
VclPtr< SwEditWin > mpEditWin
Definition: PostItMgr.hxx:128
void GrabFocus()
tools::ULong mnPageNumber
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:1126
const SwPostItField * mpShadowField
Definition: PostItMgr.hxx:76
bool IsReadOnly() const
bool HasFrameConnectedSidebarWins(const SwFrame &rFrame)
Definition: PostItMgr.cxx:2434
SwLayoutInfo maLayoutInfo
SwFieldType * GetTyp() const
Definition: fldbas.hxx:392
void Delete()
Definition: PostItMgr.cxx:1626
::sw::sidebarwindows::AnchorOverlayObject * Anchor()
SW_DLLPUBLIC bool HasActiveSidebarWin() const
Definition: PostItMgr.cxx:2352
void RemoveSidebarWin()
Definition: PostItMgr.cxx:1310
void LayoutPostIts()
Definition: PostItMgr.cxx:681
Point PixelToLogic(const Point &rDevicePt) const
Point LogicToPixel(const Point &rLogicPt) const
bool ScrollbarHit(const tools::ULong aPage, const Point &aPoint)
Definition: PostItMgr.cxx:2009
void CheckMetaText()
Definition: PostItMgr.cxx:2272
void PreparePageContainer()
Definition: PostItMgr.cxx:653
ESelection GetSelection() const
void ExecuteFormatAllDialog(SwView &rView)
Definition: PostItMgr.cxx:1653
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:2175
void DrawForPage(OutputDevice *pDev, const Point &rPos)
void SetFollow(bool bIsFollow)
void ChangeSidebarItem(SwSidebarItem const &rSidebarItem)
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint)
bool IsFieldInDoc() const
Definition: atrfld.cxx:393
void TranslateTopPosition(const tools::Long aAmount)
sal_uInt16 GetNumPages() const
Definition: viewsh.cxx:625
void Bottom(const tools::Long nBottom)
Definition: swrect.hxx:209
void AssureStdModeAtShell()
Definition: PostItMgr.cxx:2328
void ShowAnchorOnly(const Point &aPoint)
void GrabFocusOnActiveSidebarWin()
Definition: PostItMgr.cxx:2363
void SetSelection(const ESelection &)
sal_uInt16 Replace(SvxSearchItem const *pItem)
Definition: PostItMgr.cxx:2280
void ToggleInsModeOnActiveSidebarWin()
Definition: PostItMgr.cxx:2395
bool GotoField(const SwFormatField &rField)
Definition: wrtsh3.cxx:66
void MakeDrawView()
Definition: vnew.cxx:366
void SetReadOnlyState()
Definition: PostItMgr.cxx:2265
virtual bool IsTextEdit() const final override
const basegfx::B2DPoint & GetSixthPosition() const
weld::Window * GetFrameWeld() const
sal_Int32 GetSidebarScrollerHeight() const
Definition: PostItMgr.cxx:2252
static Color GetColorLight(std::size_t aAuthorIndex)
Definition: PostItMgr.cxx:2150
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:2499
bool IsFieldDeletedInModel(IDocumentRedlineAccess const &rIDRA, SwTextField const &rTextField)
void CorrectPositions()
Definition: PostItMgr.cxx:2042
sal_Int32 GetScrollSize() const
Definition: PostItMgr.cxx:2240
constexpr tools::Long Height() const
virtual SwPosition GetAnchorPosition() const =0
sw::sidebarwindows::SidebarPosition meSidebarPosition
void LockView(bool b)
Definition: viewsh.hxx:462
const SwViewOption * GetViewOptions() const
Definition: viewsh.hxx:423
#define COL_NOTES_SIDEPANE_ARROW_ENABLED
Definition: PostItMgr.hxx:59
constexpr::Color COL_AUTHOR5_DARK(197, 0, 11)
bool mbLayouting
Definition: PostItMgr.hxx:136
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_WHITE
virtual bool UseElement(SwRootFrame const &, IDocumentRedlineAccess const &)=0
bool ArrowEnabled(sal_uInt16 aDirection, tools::ULong aPage) const
Definition: PostItMgr.cxx:1093
bool ShowScrollbar(const tools::ULong aPage) const
Definition: PostItMgr.cxx:1921
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:2483
bool mbIsShowAnchor
Definition: PostItMgr.hxx:142
void EndListening(SfxBroadcaster &rBroadcaster, bool bRemoveAllDuplicates=false)
sal_Int32 GetMinimumSizeWithMeta() const
Definition: PostItMgr.cxx:2246
void Top(const tools::Long nTop)
Definition: swrect.hxx:204
constexpr::Color COL_AUTHOR9_NORMAL(255, 226, 185)
sal_uInt16 GetZoom() const
Definition: viewopt.hxx:505
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:323
#define EE_TEXTPOS_MAX_COUNT
void Rescale()
Definition: PostItMgr.cxx:2221
bool HasNotes() const
Definition: PostItMgr.cxx:2096
constexpr TypedWhichId< SvxLanguageItem > EE_CHAR_LANGUAGE(EE_CHAR_START+14)
UnoViewSharedPtr mpView
bool IsHideRedlines() const
Replacement for sw::DocumentRedlineManager::GetRedlineFlags() (this is layout-level redline hiding)...
Definition: rootfrm.hxx:420
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:233
void LeaveSelFrameMode()
Definition: select.cxx:720
void SetSpellChecking()
Definition: PostItMgr.cxx:2258
std::vector< std::unique_ptr< SwPostItPageItem > > mPages
Definition: PostItMgr.hxx:130
tools::Rectangle GetTopScrollRect(const tools::ULong aPage) const
Definition: PostItMgr.cxx:1998
sw::annotation::SwAnnotationWin * GetNextPostIt(sal_uInt16 aDirection, sw::annotation::SwAnnotationWin *aPostIt)
Definition: PostItMgr.cxx:1788
tools::Long mbLayoutHeight
Definition: PostItMgr.hxx:135
SwPostItMgr(SwView *aDoc)
Definition: PostItMgr.cxx:191
reference_type * get() const
virtual OUString GetPar2() const override
Text.
Definition: docufld.cxx:1810
void SetPosSizePixelRect(tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight, const SwRect &aAnchorRect, const tools::Long PageBorder)
SfxItemSet GetAttribs()
Color GetArrowColor(sal_uInt16 aDirection, tools::ULong aPage) const
Definition: PostItMgr.cxx:1109
void(* f)(TrueTypeTable *)
sal_Int32 mnStartContent
tools::Long GetNextBorder()
Definition: PostItMgr.cxx:1824
bool mbReadOnly
Definition: PostItMgr.hxx:137
constexpr::Color COL_AUTHOR5_LIGHT(255, 227, 229)
bool IsShowAnchor() const
Definition: PostItMgr.hxx:104
bool IsShowHiddenChar(bool bHard=false) const
Definition: viewopt.hxx:321
::sw::sidebarwindows::ShadowOverlayObject * Shadow()
virtual SdrView * GetDrawView() const override
Definition: viewdraw.cxx:618
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:2090
#define EE_PARA_MAX_COUNT
void SetShadowState(const SwPostItField *pField, bool bCursor=true)
Definition: PostItMgr.cxx:1855
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:2067
void Push(PushFlags nFlags=PushFlags::ALL)
static SfxItemPool * GetAnnotationPool(SwView const &rV)
Definition: annotsh.cxx:122
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:2500
void Height(tools::Long nNew)
Definition: swrect.hxx:191
SwFieldIds Which() const
Definition: fldbas.hxx:272
void ToggleResolvedForThread(sal_uInt32 nPostItId)
Definition: PostItMgr.cxx:1600
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:1768
const SwStartNode * FindFootnoteStartNode() const
Definition: node.hxx:201
bool IsViewLocked() const
Definition: viewsh.hxx:461
SwRect mPosition
void RemoveItem(SfxBroadcaster *pBroadcast)
Definition: PostItMgr.cxx:301
Definition: view.hxx:144
bool GetResolved() const
Definition: docufld.cxx:1774
sal_uInt16 FinishSearchReplace(const i18nutil::SearchOptions2 &rSearchOptions, bool bSrchForward)
Definition: PostItMgr.cxx:2289
SwWrtShell * mpWrtShell
Definition: PostItMgr.hxx:127
bool IsSelFrameMode() const
Definition: wrtsh.hxx:171
tools::Rectangle GetBottomScrollRect(const tools::ULong aPage) const
Definition: PostItMgr.cxx:1988