LibreOffice Module sw (master)  1
AnnotationWin2.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 <sal/config.h>
21 
22 #include <cstddef>
23 
24 #include "SidebarWinAcc.hxx"
25 #include <PostItMgr.hxx>
26 #include <AnnotationWin.hxx>
27 #include <IDocumentUndoRedo.hxx>
29 #include "SidebarTxtControl.hxx"
30 #include "AnchorOverlayObject.hxx"
31 #include "ShadowOverlayObject.hxx"
32 #include "OverlayRanges.hxx"
33 
34 #include <strings.hrc>
35 
36 #include <viewopt.hxx>
37 #include <cmdid.h>
38 
39 #include <editeng/fhgtitem.hxx>
40 #include <editeng/langitem.hxx>
41 #include <editeng/editview.hxx>
42 #include <editeng/outliner.hxx>
43 #include <editeng/editeng.hxx>
44 #include <editeng/eeitem.hxx>
45 #include <editeng/outlobj.hxx>
46 
47 #include <svl/undo.hxx>
48 #include <svl/stritem.hxx>
49 
50 #include <sfx2/viewfrm.hxx>
51 #include <sfx2/bindings.hxx>
52 #include <sfx2/dispatch.hxx>
53 
54 #include <vcl/decoview.hxx>
55 #include <vcl/event.hxx>
56 #include <vcl/gradient.hxx>
57 #include <vcl/svapp.hxx>
58 #include <vcl/settings.hxx>
59 #include <vcl/ptrstyle.hxx>
60 #include <vcl/uitest/logger.hxx>
62 
63 #include <edtwin.hxx>
64 #include <view.hxx>
65 #include <docsh.hxx>
66 #include <wrtsh.hxx>
67 #include <doc.hxx>
68 #include <swmodule.hxx>
69 
70 #include <SwRewriter.hxx>
71 #include <txtannotationfld.hxx>
72 #include <ndtxt.hxx>
73 
77 #include <unotools/syslocale.hxx>
78 #include <memory>
79 #include <comphelper/lok.hxx>
80 
81 using namespace sw::sidebarwindows;
82 
83 namespace
84 {
85 
86 void collectUIInformation( const OUString& aevent , const OUString& aID )
87 {
88  EventDescription aDescription;
89  aDescription.aID = aID;
90  aDescription.aParameters = {{"" , ""}};
91  aDescription.aAction = aevent;
92  aDescription.aParent = "MainWindow";
93  aDescription.aKeyWord = "SwEditWinUIObject";
94  UITestLogger::getInstance().logEvent(aDescription);
95 }
96 
97 }
98 
99 namespace sw::annotation {
100 
101 #define METABUTTON_WIDTH 16
102 #define METABUTTON_HEIGHT 18
103 #define POSTIT_META_FIELD_HEIGHT sal_Int32(15)
104 #define POSTIT_MINIMUMSIZE_WITHOUT_META 50
105 
106 void SwAnnotationWin::PaintTile(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect)
107 {
108  bool bMenuButtonVisible = mxMenuButton->get_visible();
109  // No point in showing this button till click on it are not handled.
110  if (bMenuButtonVisible)
111  mxMenuButton->hide();
112 
113  // draw left over space
114  if (Application::GetSettings().GetStyleSettings().GetHighContrastMode())
115  rRenderContext.SetFillColor(COL_BLACK);
116  else
117  rRenderContext.SetFillColor(mColorDark);
118  rRenderContext.SetLineColor();
119  rRenderContext.DrawRect(rRect);
120 
121  m_xContainer->draw(rRenderContext, rRect.TopLeft(), GetSizePixel());
122 
123  const drawinglayer::geometry::ViewInformation2D aViewInformation;
124  std::unique_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor(drawinglayer::processor2d::createBaseProcessor2DFromOutputDevice(rRenderContext, aViewInformation));
125 
126  // drawinglayer sets the map mode to pixels, not needed here.
127  rRenderContext.Pop();
128  // Work in document-global twips.
129  rRenderContext.Pop();
130  if (mpAnchor)
131  pProcessor->process(mpAnchor->getOverlayObjectPrimitive2DSequence());
132  if (mpTextRangeOverlay)
133  pProcessor->process(mpTextRangeOverlay->getOverlayObjectPrimitive2DSequence());
134 
135  rRenderContext.Push(PushFlags::NONE);
136  pProcessor.reset();
137  rRenderContext.Push(PushFlags::NONE);
138 
139  if (bMenuButtonVisible)
140  mxMenuButton->show();
141 }
142 
143 bool SwAnnotationWin::IsHitWindow(const Point& rPointLogic)
144 {
145  tools::Rectangle aRectangleLogic(EditWin().PixelToLogic(GetPosPixel()), EditWin().PixelToLogic(GetSizePixel()));
146  return aRectangleLogic.IsInside(rPointLogic);
147 }
148 
149 void SwAnnotationWin::SetCursorLogicPosition(const Point& rPosition, bool bPoint, bool bClearMark)
150 {
151  mxSidebarTextControl->SetCursorLogicPosition(rPosition, bPoint, bClearMark);
152 }
153 
154 void SwAnnotationWin::DrawForPage(OutputDevice* pDev, const Point& rPt)
155 {
156  pDev->Push();
157 
158  pDev->SetFillColor(mColorDark);
159  pDev->SetLineColor();
160 
161  pDev->SetTextColor(mColorAnchor);
162  vcl::Font aFont = maLabelFont;
163  aFont.SetFontHeight(aFont.GetFontHeight() * 20);
164  pDev->SetFont(aFont);
165 
166  Size aSz = PixelToLogic(GetSizePixel());
167  pDev->DrawRect(tools::Rectangle(rPt, aSz));
168 
169  if (mxMetadataAuthor->get_visible())
170  {
171  int x, y, width, height;
172  mxMetadataAuthor->get_extents_relative_to(*m_xContainer, x, y, width, height);
173  Point aPos(rPt + PixelToLogic(Point(x, y)));
174  Size aSize(PixelToLogic(Size(width, height)));
175 
176  pDev->Push(PushFlags::CLIPREGION);
177  pDev->IntersectClipRegion(tools::Rectangle(aPos, aSize));
178  pDev->DrawText(aPos, mxMetadataAuthor->get_label());
179  pDev->Pop();
180  }
181 
182 // m_xContainer->draw(*pDev, rPt, GetSizePixel());
183 
184  if (mxMetadataDate->get_visible())
185  {
186  int x, y, width, height;
187  mxMetadataDate->get_extents_relative_to(*m_xContainer, x, y, width, height);
188  Point aPos(rPt + PixelToLogic(Point(x, y)));
189  Size aSize(PixelToLogic(Size(width, height)));
190 
191  pDev->Push(PushFlags::CLIPREGION);
192  pDev->IntersectClipRegion(tools::Rectangle(aPos, aSize));
193  pDev->DrawText(aPos, mxMetadataDate->get_label());
194  pDev->Pop();
195  }
196 
197  if (mxMetadataResolved->get_visible())
198  {
199  int x, y, width, height;
200  mxMetadataResolved->get_extents_relative_to(*m_xContainer, x, y, width, height);
201  Point aPos(rPt + PixelToLogic(Point(x, y)));
202  Size aSize(PixelToLogic(Size(width, height)));
203 
204  pDev->Push(PushFlags::CLIPREGION);
205  pDev->IntersectClipRegion(tools::Rectangle(aPos, aSize));
206  pDev->DrawText(aPos, mxMetadataResolved->get_label());
207  pDev->Pop();
208  }
209 
210  mxSidebarTextControl->DrawForPage(pDev, rPt);
211 
212  const drawinglayer::geometry::ViewInformation2D aNewViewInfos;
213  std::unique_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor(
215  *pDev, aNewViewInfos ));
216 
217  if (mpAnchor)
218  pProcessor->process(mpAnchor->getOverlayObjectPrimitive2DSequence());
219  if (mpTextRangeOverlay)
220  pProcessor->process(mpTextRangeOverlay->getOverlayObjectPrimitive2DSequence());
221  pProcessor.reset();
222 
223  if (mxVScrollbar->get_vpolicy() != VclPolicyType::NEVER)
224  {
225  // if there is a scrollbar shown, draw "..." to indicate the comment isn't
226  // completely shown
227  int x, y, width, height;
228  mxMenuButton->get_extents_relative_to(*m_xContainer, x, y, width, height);
229  Point aPos(rPt + PixelToLogic(Point(x, y)));
230  pDev->DrawText(aPos, "...");
231  }
232 
233  pDev->Pop();
234 }
235 
236 void SwAnnotationWin::SetPosSizePixelRect(tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight,
237  const SwRect& aAnchorRect, const tools::Long aPageBorder)
238 {
239  mPosSize = tools::Rectangle(Point(nX,nY),Size(nWidth,nHeight));
240  if (!mAnchorRect.IsEmpty() && mAnchorRect != aAnchorRect)
241  mbAnchorRectChanged = true;
242  mAnchorRect = aAnchorRect;
243  mPageBorder = aPageBorder;
244 }
245 
246 void SwAnnotationWin::SetSize( const Size& rNewSize )
247 {
248  mPosSize.SetSize(rNewSize);
249 }
250 
251 void SwAnnotationWin::SetVirtualPosSize( const Point& aPoint, const Size& aSize)
252 {
253  mPosSize = tools::Rectangle(aPoint,aSize);
254 }
255 
256 void SwAnnotationWin::TranslateTopPosition(const tools::Long aAmount)
257 {
258  mPosSize.Move(0,aAmount);
259 }
260 
261 void SwAnnotationWin::ShowAnchorOnly(const Point &aPoint)
262 {
263  HideNote();
264  SetPosAndSize();
265  if (mpAnchor)
266  {
267  mpAnchor->SetSixthPosition(basegfx::B2DPoint(aPoint.X(),aPoint.Y()));
268  mpAnchor->SetSeventhPosition(basegfx::B2DPoint(aPoint.X(),aPoint.Y()));
269  mpAnchor->SetAnchorState(AnchorState::All);
270  mpAnchor->setVisible(true);
271  }
272  if (mpShadow)
273  mpShadow->setVisible(false);
274 }
275 
276 SfxItemSet SwAnnotationWin::DefaultItem()
277 {
278  SfxItemSet aItem( mrView.GetDocShell()->GetPool() );
279  aItem.Put(SvxFontHeightItem(200,100,EE_CHAR_FONTHEIGHT));
280  return aItem;
281 }
282 
283 void SwAnnotationWin::InitControls()
284 {
285  // window controls for author and date
286  mxMetadataAuthor = m_xBuilder->weld_label("author");
287  mxMetadataAuthor->set_accessible_name( SwResId( STR_ACCESS_ANNOTATION_AUTHOR_NAME ) );
288  mxMetadataAuthor->set_direction(AllSettings::GetLayoutRTL());
289 
291  maLabelFont.SetFontHeight(8);
292 
293  // we should leave this setting alone, but for this we need a better layout algo
294  // with variable meta size height
295  mxMetadataAuthor->set_font(maLabelFont);
296 
297  mxMetadataDate = m_xBuilder->weld_label("date");
298  mxMetadataDate->set_accessible_name( SwResId( STR_ACCESS_ANNOTATION_DATE_NAME ) );
299  mxMetadataDate->set_direction(AllSettings::GetLayoutRTL());
300  mxMetadataDate->connect_mouse_move(LINK(this, SwAnnotationWin, MouseMoveHdl));
301 
302  // we should leave this setting alone, but for this we need a better layout algo
303  // with variable meta size height
304  mxMetadataDate->set_font(maLabelFont);
305 
306  mxMetadataResolved = m_xBuilder->weld_label("resolved");
307  mxMetadataResolved->set_accessible_name( SwResId( STR_ACCESS_ANNOTATION_RESOLVED_NAME ) );
308  mxMetadataResolved->set_direction(AllSettings::GetLayoutRTL());
309  mxMetadataResolved->connect_mouse_move(LINK(this, SwAnnotationWin, MouseMoveHdl));
310 
311  // we should leave this setting alone, but for this we need a better layout algo
312  // with variable meta size height
313  mxMetadataResolved->set_font(maLabelFont);
314  mxMetadataResolved->set_label(SwResId(STR_ACCESS_ANNOTATION_RESOLVED_NAME));
315 
316  SwDocShell* aShell = mrView.GetDocShell();
317  mpOutliner.reset(new Outliner(&aShell->GetPool(),OutlinerMode::TextObject));
318  aShell->GetDoc()->SetCalcFieldValueHdl( mpOutliner.get() );
319  mpOutliner->SetUpdateMode( true );
320 
321  mpOutlinerView.reset(new OutlinerView(mpOutliner.get(), nullptr));
322  mpOutliner->InsertView(mpOutlinerView.get());
323 
324  //create Scrollbars
325  mxVScrollbar = m_xBuilder->weld_scrolled_window("scrolledwindow", true);
326 
327  mxMenuButton = m_xBuilder->weld_menu_button("menubutton");
328  mxMenuButton->set_size_request(METABUTTON_WIDTH, METABUTTON_HEIGHT);
329 
330  // actual window which holds the user text
331  mxSidebarTextControl.reset(new SidebarTextControl(*this, mrView, mrMgr));
332  mxSidebarTextControlWin.reset(new weld::CustomWeld(*m_xBuilder, "editview", *mxSidebarTextControl));
333  mxSidebarTextControl->SetPointer(PointerStyle::Text);
334 
335  Rescale();
336 
337  mpOutlinerView->SetBackgroundColor(COL_TRANSPARENT);
338  mpOutlinerView->SetOutputArea( PixelToLogic( tools::Rectangle(0,0,1,1) ) );
339 
340  mpOutlinerView->SetAttribs(DefaultItem());
341 
342  mxVScrollbar->set_direction(false);
343  mxVScrollbar->connect_vadjustment_changed(LINK(this, SwAnnotationWin, ScrollHdl));
344  mxVScrollbar->connect_mouse_move(LINK(this, SwAnnotationWin, MouseMoveHdl));
345 
346  const SwViewOption* pVOpt = mrView.GetWrtShellPtr()->GetViewOptions();
347  EEControlBits nCntrl = mpOutliner->GetControlWord();
348  // TODO: crash when AUTOCOMPLETE enabled
349  nCntrl |= EEControlBits::MARKFIELDS | EEControlBits::PASTESPECIAL | EEControlBits::AUTOCORRECT | EEControlBits::USECHARATTRIBS; // | EEControlBits::AUTOCOMPLETE;
351  nCntrl |= EEControlBits::MARKFIELDS;
352  else
353  nCntrl &= ~EEControlBits::MARKFIELDS;
354  if (pVOpt->IsOnlineSpell())
355  nCntrl |= EEControlBits::ONLINESPELLING;
356  else
357  nCntrl &= ~EEControlBits::ONLINESPELLING;
358  mpOutliner->SetControlWord(nCntrl);
359 
360  std::size_t aIndex = SW_MOD()->InsertRedlineAuthor(GetAuthor());
361  SetColor( SwPostItMgr::GetColorDark(aIndex),
364 
365  CheckMetaText();
366 
367  // expand %1 "Author"
368  OUString aText = mxMenuButton->get_item_label("deleteby");
369  SwRewriter aRewriter;
370  aRewriter.AddRule(UndoArg1, GetAuthor());
371  aText = aRewriter.Apply(aText);
372  mxMenuButton->set_item_label("deleteby", aText);
373 
374  mxMenuButton->set_accessible_name(SwResId(STR_ACCESS_ANNOTATION_BUTTON_NAME));
375  mxMenuButton->set_accessible_description(SwResId(STR_ACCESS_ANNOTATION_BUTTON_DESC));
376  mxMenuButton->set_tooltip_text(SwResId(STR_ACCESS_ANNOTATION_BUTTON_DESC));
377 
378  mxMenuButton->connect_toggled(LINK(this, SwAnnotationWin, ToggleHdl));
379  mxMenuButton->connect_selected(LINK(this, SwAnnotationWin, SelectHdl));
380  mxMenuButton->connect_key_press(LINK(this, SwAnnotationWin, KeyInputHdl));
381  mxMenuButton->connect_mouse_move(LINK(this, SwAnnotationWin, MouseMoveHdl));
382 
384  GetOutlinerView()->StartSpeller(mxSidebarTextControl->GetDrawingArea());
385  SetPostItText();
386  mpOutliner->CompleteOnlineSpelling();
387 
388  mxSidebarTextControl->Show();
389  mxMetadataAuthor->show();
390  mxMetadataDate->show();
391  mxMetadataResolved->set_visible(IsResolved());
392  mxVScrollbar->set_vpolicy(VclPolicyType::ALWAYS);
393 }
394 
395 void SwAnnotationWin::CheckMetaText()
396 {
397  const SvtSysLocale aSysLocale;
398  const LocaleDataWrapper& rLocalData = aSysLocale.GetLocaleData();
399  OUString sMeta = GetAuthor();
400  if (sMeta.isEmpty())
401  {
402  sMeta = SwResId(STR_NOAUTHOR);
403  }
404  else if (sMeta.getLength() > 23)
405  {
406  sMeta = OUString::Concat(sMeta.subView(0, 20)) + "...";
407  }
408  if ( mxMetadataAuthor->get_label() != sMeta )
409  {
410  mxMetadataAuthor->set_label(sMeta);
411  }
412 
413  Date aDate = GetDate();
414  if (aDate.IsValidAndGregorian() )
415  {
416  sMeta = rLocalData.getDate(aDate);
417  }
418  else
419  {
420  sMeta = SwResId(STR_NODATE);
421  }
422  if (GetTime().GetTime()!=0)
423  {
424  sMeta += " " + rLocalData.getTime( GetTime(),false );
425  }
426  if ( mxMetadataDate->get_label() != sMeta )
427  {
428  mxMetadataDate->set_label(sMeta);
429  }
430 
431  std::size_t aIndex = SW_MOD()->InsertRedlineAuthor(GetAuthor());
432  SetColor( SwPostItMgr::GetColorDark(aIndex),
435 }
436 
437 static Color ColorFromAlphaColor(const sal_uInt8 aTransparency, const Color& aFront, const Color& aBack)
438 {
439  return Color(sal_uInt8(aFront.GetRed() * aTransparency / 255.0 + aBack.GetRed() * (1 - aTransparency / 255.0)),
440  sal_uInt8(aFront.GetGreen() * aTransparency / 255.0 + aBack.GetGreen() * (1 - aTransparency / 255.0)),
441  sal_uInt8(aFront.GetBlue() * aTransparency / 255.0 + aBack.GetBlue() * (1 - aTransparency / 255.0)));
442 }
443 
444 void SwAnnotationWin::SetMenuButtonColors()
445 {
446  if (!mxMenuButton)
447  return;
448 
449  mxMenuButton->set_background(mColorDark);
450 
451  const Fraction& rFraction = mrView.GetWrtShellPtr()->GetOut()->GetMapMode().GetScaleY();
452 
454  Size aSize(tools::Long(METABUTTON_WIDTH * rFraction),
455  tools::Long(METABUTTON_HEIGHT * rFraction));
456  tools::Rectangle aRect(Point(0, 0), aSize);
457  xVirDev->SetOutputSizePixel(aSize);
458 
459  Gradient aGradient(GradientStyle::Linear,
460  ColorFromAlphaColor(15, mColorAnchor, mColorDark),
461  ColorFromAlphaColor(80, mColorAnchor, mColorDark));
462  xVirDev->DrawGradient(aRect, aGradient);
463 
464  DecorationView aDecoView(xVirDev.get());
465  aDecoView.DrawSymbol(aRect, SymbolType::SPIN_DOWN, GetTextColor(),
466  DrawSymbolFlags::NONE);
467  mxMenuButton->set_image(xVirDev);
468  mxMenuButton->set_size_request(aSize.Width() + 4, aSize.Height());
469 }
470 
471 void SwAnnotationWin::Rescale()
472 {
473  // On Android, this method leads to invoke ImpEditEngine::UpdateViews
474  // which hides the text cursor. Moreover it causes sudden document scroll
475  // when modifying a commented text. Not clear the root cause,
476  // anyway skipping this method fixes the problem, and there should be
477  // no side effect, since the client has disabled annotations rendering.
479  return;
480 
481  MapMode aMode = GetParent()->GetMapMode();
482  aMode.SetOrigin( Point() );
483  mpOutliner->SetRefMapMode( aMode );
484  SetMapMode( aMode );
485  mxSidebarTextControl->SetMapMode( aMode );
486  const Fraction& rFraction = mrView.GetWrtShellPtr()->GetOut()->GetMapMode().GetScaleY();
487 
488  vcl::Font aFont = maLabelFont;
489  sal_Int32 nHeight = tools::Long(aFont.GetFontHeight() * rFraction);
490  aFont.SetFontHeight( nHeight );
491 
492  if (mxMetadataAuthor)
493  mxMetadataAuthor->set_font(aFont);
494  if (mxMetadataDate)
495  mxMetadataDate->set_font(aFont);
496  if (mxMetadataResolved)
497  mxMetadataResolved->set_font(aFont);
498  SetMenuButtonColors();
499  if (mxVScrollbar)
500  mxVScrollbar->set_scroll_thickness(GetPrefScrollbarWidth());
501 }
502 
503 void SwAnnotationWin::SetPosAndSize()
504 {
505  bool bChange = false;
506 
507  if (GetSizePixel() != mPosSize.GetSize())
508  {
509  bChange = true;
510  SetSizePixel(mPosSize.GetSize());
511 
512  DoResize();
513  }
514 
515  if (GetPosPixel().X() != mPosSize.Left() || (std::abs(GetPosPixel().Y() - mPosSize.Top()) > 5) )
516  {
517  bChange = true;
518  SetPosPixel(mPosSize.TopLeft());
519 
520  Point aLineStart;
521  Point aLineEnd ;
522  switch ( meSidebarPosition )
523  {
525  {
526  aLineStart = EditWin().PixelToLogic( Point(GetPosPixel().X()+GetSizePixel().Width(),GetPosPixel().Y()-1) );
527  aLineEnd = EditWin().PixelToLogic( Point(GetPosPixel().X(),GetPosPixel().Y()-1) );
528  }
529  break;
531  {
532  aLineStart = EditWin().PixelToLogic( Point(GetPosPixel().X(),GetPosPixel().Y()-1) );
533  aLineEnd = EditWin().PixelToLogic( Point(GetPosPixel().X()+GetSizePixel().Width(),GetPosPixel().Y()-1) );
534  }
535  break;
536  default:
537  OSL_FAIL( "<SwAnnotationWin::SetPosAndSize()> - unexpected position of sidebar" );
538  break;
539  }
540 
541  // LOK has map mode disabled, and we still want to perform pixel ->
542  // twips conversion for the size of the line above the note.
543  if (comphelper::LibreOfficeKit::isActive() && !EditWin().IsMapModeEnabled())
544  {
545  EditWin().EnableMapMode();
546  Size aSize(aLineEnd.getX() - aLineStart.getX(), aLineEnd.getY() - aLineStart.getY());
547  aSize = EditWin().PixelToLogic(aSize);
548  aLineEnd = aLineStart;
549  aLineEnd.Move(aSize.getWidth(), aSize.getHeight());
550  EditWin().EnableMapMode(false);
551  }
552 
553  if (mpAnchor)
554  {
555  mpAnchor->SetAllPosition( basegfx::B2DPoint( mAnchorRect.Left() , mAnchorRect.Bottom() - 5* 15),
556  basegfx::B2DPoint( mAnchorRect.Left()-5*15 , mAnchorRect.Bottom()+5*15),
557  basegfx::B2DPoint( mAnchorRect.Left()+5*15 , mAnchorRect.Bottom()+5*15),
558  basegfx::B2DPoint( mAnchorRect.Left(), mAnchorRect.Bottom()+2*15),
559  basegfx::B2DPoint( mPageBorder ,mAnchorRect.Bottom()+2*15),
560  basegfx::B2DPoint( aLineStart.X(),aLineStart.Y()),
561  basegfx::B2DPoint( aLineEnd.X(),aLineEnd.Y()));
562  }
563  else
564  {
566  mAnchorRect,
567  mPageBorder,
568  aLineStart,
569  aLineEnd,
570  mColorAnchor );
571  if ( mpAnchor )
572  {
573  mpAnchor->setVisible(true);
574  mpAnchor->SetAnchorState(AnchorState::Tri);
575  if (HasChildPathFocus())
576  {
577  mpAnchor->setLineSolid(true);
578  }
579  }
580  }
581  }
582  else
583  {
584  if ( mpAnchor &&
585  ( mpAnchor->getBasePosition() != basegfx::B2DPoint( mAnchorRect.Left() , mAnchorRect.Bottom()-5*15) ) )
586  {
587  mpAnchor->SetTriPosition( basegfx::B2DPoint( mAnchorRect.Left() , mAnchorRect.Bottom() - 5* 15),
588  basegfx::B2DPoint( mAnchorRect.Left()-5*15 , mAnchorRect.Bottom()+5*15),
589  basegfx::B2DPoint( mAnchorRect.Left()+5*15 , mAnchorRect.Bottom()+5*15),
590  basegfx::B2DPoint( mAnchorRect.Left(), mAnchorRect.Bottom()+2*15),
591  basegfx::B2DPoint( mPageBorder , mAnchorRect.Bottom()+2*15));
592  }
593  }
594 
595  if (mpShadow && bChange)
596  {
597  Point aStart = EditWin().PixelToLogic(GetPosPixel()+Point(0,GetSizePixel().Height()));
598  Point aEnd = EditWin().PixelToLogic(GetPosPixel()+Point(GetSizePixel().Width()-1,GetSizePixel().Height()));
599  mpShadow->SetPosition(basegfx::B2DPoint(aStart.X(),aStart.Y()), basegfx::B2DPoint(aEnd.X(),aEnd.Y()));
600  }
601 
602  if (mrMgr.ShowNotes())
603  {
604  if (IsFollow() && !HasChildPathFocus())
605  {
606  // #i111964#
607  if ( mpAnchor )
608  {
609  mpAnchor->SetAnchorState(AnchorState::End);
610  }
611  }
612  else
613  {
614  // #i111964#
615  if ( mpAnchor )
616  {
617  mpAnchor->SetAnchorState(AnchorState::All);
618  }
619  SwAnnotationWin* pWin = GetTopReplyNote();
620  // #i111964#
621  if ( pWin != this && pWin->Anchor() )
622  {
624  }
625  }
626  }
627 
628 
629  // text range overlay
630  maAnnotationTextRanges.clear();
631  if ( mrSidebarItem.maLayoutInfo.mnStartNodeIdx != 0
632  && mrSidebarItem.maLayoutInfo.mnStartContent != -1 )
633  {
634  const SwTextAnnotationField* pTextAnnotationField =
635  dynamic_cast< const SwTextAnnotationField* >( mrSidebarItem.GetFormatField().GetTextField() );
636  SwTextNode* pTextNode = pTextAnnotationField ? pTextAnnotationField->GetpTextNode() : nullptr;
637  SwContentNode* pContentNd = nullptr;
638  if (pTextNode)
639  {
640  SwNodes& rNds = pTextNode->GetDoc().GetNodes();
641  pContentNd = rNds[mrSidebarItem.maLayoutInfo.mnStartNodeIdx]->GetContentNode();
642  }
643  if (pContentNd)
644  {
645  SwPosition aStartPos( *pContentNd, mrSidebarItem.maLayoutInfo.mnStartContent );
646  SwShellCursor* pTmpCursor = nullptr;
647  const bool bTableCursorNeeded = pTextNode->FindTableBoxStartNode() != pContentNd->FindTableBoxStartNode();
648  if ( bTableCursorNeeded )
649  {
650  SwShellTableCursor* pTableCursor = new SwShellTableCursor( mrView.GetWrtShell(), aStartPos );
651  pTableCursor->SetMark();
652  pTableCursor->GetMark()->nNode = *pTextNode;
653  pTableCursor->GetMark()->nContent.Assign( pTextNode, pTextAnnotationField->GetStart()+1 );
654  pTableCursor->NewTableSelection();
655  pTmpCursor = pTableCursor;
656  }
657  else
658  {
659  SwShellCursor* pCursor = new SwShellCursor( mrView.GetWrtShell(), aStartPos );
660  pCursor->SetMark();
661  pCursor->GetMark()->nNode = *pTextNode;
662  pCursor->GetMark()->nContent.Assign( pTextNode, pTextAnnotationField->GetStart()+1 );
663  pTmpCursor = pCursor;
664  }
665  std::unique_ptr<SwShellCursor> pTmpCursorForAnnotationTextRange( pTmpCursor );
666 
667  // For annotation text range rectangles to be calculated correctly,
668  // we need the map mode disabled
669  bool bDisableMapMode = comphelper::LibreOfficeKit::isActive() && EditWin().IsMapModeEnabled();
670  if (bDisableMapMode)
671  EditWin().EnableMapMode(false);
672 
673  if (mrSidebarItem.maLayoutInfo.mPositionFromCommentAnchor)
674  pTmpCursorForAnnotationTextRange->FillRects();
675 
676  if (bDisableMapMode)
677  EditWin().EnableMapMode();
678 
679  SwRects* pRects(pTmpCursorForAnnotationTextRange.get());
680  for(const SwRect & rNextRect : *pRects)
681  {
682  const tools::Rectangle aPntRect(rNextRect.SVRect());
683  maAnnotationTextRanges.emplace_back(
684  aPntRect.Left(), aPntRect.Top(),
685  aPntRect.Right() + 1, aPntRect.Bottom() + 1);
686  }
687  }
688  }
689 
690  if (mrMgr.ShowNotes() && !maAnnotationTextRanges.empty())
691  {
692  if ( mpTextRangeOverlay != nullptr )
693  {
694  mpTextRangeOverlay->setRanges( maAnnotationTextRanges );
695  if ( mpAnchor != nullptr && mpAnchor->getLineSolid() )
696  {
697  mpTextRangeOverlay->ShowSolidBorder();
698  }
699  else
700  {
701  mpTextRangeOverlay->HideSolidBorder();
702  }
703  }
704  else if (!IsFollow())
705  {
706  // This window is not a reply, then draw its range overlay.
707  mpTextRangeOverlay =
709  mrView,
710  mColorAnchor,
711  maAnnotationTextRanges,
712  mpAnchor && mpAnchor->getLineSolid() );
713  }
714  }
715  else
716  {
717  mpTextRangeOverlay.reset();
718  }
719 }
720 
721 void SwAnnotationWin::DoResize()
722 {
723  tools::Long aHeight = GetSizePixel().Height();
724  tools::ULong aWidth = GetSizePixel().Width();
725 
726  aHeight -= GetMetaHeight();
727 
728  mpOutliner->SetPaperSize( PixelToLogic( Size(aWidth, aHeight) ) ) ;
729  tools::Long aTextHeight = LogicToPixel( mpOutliner->CalcTextSize()).Height();
730 
731  mxMetadataAuthor->show();
732  if(IsResolved()) { mxMetadataResolved->show(); }
733  mxMetadataDate->show();
734 
735  if (aTextHeight > aHeight)
736  {
737  // we need vertical scrollbars and have to reduce the width
738  aWidth -= mxVScrollbar->get_scroll_thickness();
739  mxVScrollbar->set_vpolicy(VclPolicyType::ALWAYS);
740  }
741  else
742  {
743  mxVScrollbar->set_vpolicy(VclPolicyType::NEVER);
744  }
745 
746  tools::Rectangle aOutputArea = PixelToLogic(tools::Rectangle(0, 0, aWidth, aHeight));
747  if (mxVScrollbar->get_vpolicy() == VclPolicyType::NEVER)
748  {
749  // if we do not have a scrollbar anymore, we want to see the complete text
750  mpOutlinerView->SetVisArea(aOutputArea);
751  }
752  mpOutlinerView->SetOutputArea(aOutputArea);
753  mpOutlinerView->ShowCursor(true, true);
754 
755  // Don't leave an empty area at the bottom if we can move the text down.
756  tools::Long nMaxVisAreaTop = mpOutliner->GetTextHeight() - aOutputArea.GetHeight();
757  if (mpOutlinerView->GetVisArea().Top() > nMaxVisAreaTop)
758  {
759  GetOutlinerView()->Scroll(0, mpOutlinerView->GetVisArea().Top() - nMaxVisAreaTop);
760  }
761 
762  int nUpper = mpOutliner->GetTextHeight();
763  int nCurrentDocPos = mpOutlinerView->GetVisArea().Top();
764  int nStepIncrement = mpOutliner->GetTextHeight() / 10;
765  int nPageIncrement = PixelToLogic(Size(0,aHeight)).Height() * 8 / 10;
766  int nPageSize = PixelToLogic(Size(0,aHeight)).Height();
767 
768  /* limit the page size to below nUpper because gtk's gtk_scrolled_window_start_deceleration has
769  effectively...
770 
771  lower = gtk_adjustment_get_lower
772  upper = gtk_adjustment_get_upper - gtk_adjustment_get_page_size
773 
774  and requires that upper > lower or the deceleration animation never ends
775  */
776  nPageSize = std::min(nPageSize, nUpper);
777 
778  mxVScrollbar->vadjustment_configure(nCurrentDocPos, 0, nUpper,
779  nStepIncrement, nPageIncrement, nPageSize);
780 }
781 
782 void SwAnnotationWin::SetSizePixel( const Size& rNewSize )
783 {
785 
786  if (mpShadow)
787  {
788  Point aStart = EditWin().PixelToLogic(GetPosPixel()+Point(0,GetSizePixel().Height()));
789  Point aEnd = EditWin().PixelToLogic(GetPosPixel()+Point(GetSizePixel().Width()-1,GetSizePixel().Height()));
790  mpShadow->SetPosition(basegfx::B2DPoint(aStart.X(),aStart.Y()), basegfx::B2DPoint(aEnd.X(),aEnd.Y()));
791  }
792 }
793 
794 void SwAnnotationWin::SetScrollbar()
795 {
796  mxVScrollbar->vadjustment_set_value(mpOutlinerView->GetVisArea().Top());
797 }
798 
799 void SwAnnotationWin::ResizeIfNecessary(tools::Long aOldHeight, tools::Long aNewHeight)
800 {
801  if (aOldHeight != aNewHeight)
802  {
803  //check for lower border or next note
804  tools::Long aBorder = mrMgr.GetNextBorder();
805  if (aBorder != -1)
806  {
807  if (aNewHeight > GetMinimumSizeWithoutMeta())
808  {
809  tools::Long aNewLowerValue = GetPosPixel().Y() + aNewHeight + GetMetaHeight();
810  if (aNewLowerValue < aBorder)
811  SetSizePixel(Size(GetSizePixel().Width(),aNewHeight+GetMetaHeight()));
812  else
813  SetSizePixel(Size(GetSizePixel().Width(),aBorder - GetPosPixel().Y()));
814  DoResize();
815  Invalidate();
816  }
817  else
818  {
819  if (GetSizePixel().Height() != GetMinimumSizeWithoutMeta() + GetMetaHeight())
820  SetSizePixel(Size(GetSizePixel().Width(),GetMinimumSizeWithoutMeta() + GetMetaHeight()));
821  DoResize();
822  Invalidate();
823  }
824  }
825  else
826  {
827  DoResize();
828  Invalidate();
829  }
830  }
831  else
832  {
833  SetScrollbar();
834  }
835 }
836 
837 void SwAnnotationWin::SetColor(Color aColorDark,Color aColorLight, Color aColorAnchor)
838 {
839  mColorDark = aColorDark;
840  mColorLight = aColorLight;
841  mColorAnchor = aColorAnchor;
842 
843  if ( Application::GetSettings().GetStyleSettings().GetHighContrastMode() )
844  return;
845 
846  m_xContainer->set_background(mColorDark);
847  SetMenuButtonColors();
848 
849  mxMetadataAuthor->set_font_color(aColorAnchor);
850 
851  mxMetadataDate->set_font_color(aColorAnchor);
852 
853  mxMetadataResolved->set_font_color(aColorAnchor);
854 
855  mxVScrollbar->customize_scrollbars(mColorLight,
856  mColorAnchor,
857  mColorDark);
858 }
859 
860 void SwAnnotationWin::SetSidebarPosition(sw::sidebarwindows::SidebarPosition eSidebarPosition)
861 {
862  meSidebarPosition = eSidebarPosition;
863 }
864 
865 void SwAnnotationWin::SetReadonly(bool bSet)
866 {
867  mbReadonly = bSet;
868  GetOutlinerView()->SetReadOnly(bSet);
869 }
870 
872 {
873  IDocumentUndoRedo& rUndoRedo(
874  mrView.GetDocShell()->GetDoc()->GetIDocumentUndoRedo());
875  const bool bDocUndoEnabled = rUndoRedo.DoesUndo();
876  const bool bOutlinerUndoEnabled = mpOutliner->IsUndoEnabled();
877  const bool bOutlinerModified = mpOutliner->IsModified();
878  const bool bDisableAndRestoreUndoMode = !bDocUndoEnabled && bOutlinerUndoEnabled;
879 
880  if (bDisableAndRestoreUndoMode)
881  {
882  // doc undo is disabled, but outliner was enabled, turn outliner undo off
883  // for the duration of this function
884  mpOutliner->EnableUndo(false);
885  }
886 
887  Link<LinkParamNone*,void> aLink = mpOutliner->GetModifyHdl();
888  mpOutliner->SetModifyHdl( Link<LinkParamNone*,void>() );
889  ESelection aOld = GetOutlinerView()->GetSelection();
890 
891  ESelection aNewSelection( 0, 0, mpOutliner->GetParagraphCount()-1, EE_TEXTPOS_ALL );
892  GetOutlinerView()->SetSelection( aNewSelection );
893  SfxItemSet aEditAttr(GetOutlinerView()->GetAttribs());
894  aEditAttr.Put(rNewItem);
895  GetOutlinerView()->SetAttribs( aEditAttr );
896 
897  if (!mpOutliner->IsUndoEnabled() && !bOutlinerModified)
898  {
899  // if undo was disabled (e.g. this is a redo action) and we were
900  // originally 'unmodified' keep it that way
901  mpOutliner->ClearModifyFlag();
902  }
903 
904  GetOutlinerView()->SetSelection(aOld);
905  mpOutliner->SetModifyHdl( aLink );
906 
907  const SwViewOption* pVOpt = mrView.GetWrtShellPtr()->GetViewOptions();
908  EEControlBits nCntrl = mpOutliner->GetControlWord();
909  // turn off
910  nCntrl &= ~EEControlBits::ONLINESPELLING;
911  mpOutliner->SetControlWord(nCntrl);
912 
913  //turn back on
914  if (pVOpt->IsOnlineSpell())
915  nCntrl |= EEControlBits::ONLINESPELLING;
916  else
917  nCntrl &= ~EEControlBits::ONLINESPELLING;
918  mpOutliner->SetControlWord(nCntrl);
919 
920  mpOutliner->CompleteOnlineSpelling();
921 
922  // restore original mode
923  if (bDisableAndRestoreUndoMode)
924  mpOutliner->EnableUndo(true);
925 
926  Invalidate();
927 }
928 
929 void SwAnnotationWin::GetFocus()
930 {
931  if (mxSidebarTextControl)
932  mxSidebarTextControl->GrabFocus();
933 }
934 
935 void SwAnnotationWin::LoseFocus()
936 {
937 }
938 
939 void SwAnnotationWin::ShowNote()
940 {
941  SetPosAndSize();
942  if (!IsVisible())
943  Window::Show();
944  if (mpShadow && !mpShadow->isVisible())
945  mpShadow->setVisible(true);
946  if (mpAnchor && !mpAnchor->isVisible())
947  mpAnchor->setVisible(true);
948  if (mpTextRangeOverlay && !mpTextRangeOverlay->isVisible())
949  mpTextRangeOverlay->setVisible(true);
950 
951  collectUIInformation("SHOW",get_id());
952 }
953 
954 void SwAnnotationWin::HideNote()
955 {
956  if (IsVisible())
957  Window::Hide();
958  if (mpAnchor)
959  {
960  if (mrMgr.IsShowAnchor())
961  mpAnchor->SetAnchorState(AnchorState::Tri);
962  else
963  mpAnchor->setVisible(false);
964  }
965  if (mpShadow && mpShadow->isVisible())
966  mpShadow->setVisible(false);
967  if (mpTextRangeOverlay && mpTextRangeOverlay->isVisible())
968  mpTextRangeOverlay->setVisible(false);
969  collectUIInformation("HIDE",get_id());
970 }
971 
972 void SwAnnotationWin::ActivatePostIt()
973 {
974  mrMgr.AssureStdModeAtShell();
975 
976  mpOutliner->ClearModifyFlag();
977  mpOutliner->GetUndoManager().Clear();
978 
979  CheckMetaText();
980  SetViewState(ViewState::EDIT);
981  GetOutlinerView()->ShowCursor();
982 
983  mpOutlinerView->GetEditView().SetInsertMode(mrView.GetWrtShellPtr()->IsInsMode());
984 
986  GetOutlinerView()->SetBackgroundColor(mColorDark);
987 
988  //tdf#119130 only have the active postit as a dialog control in which pressing
989  //ctrl+tab cycles between text and button so we don't waste time searching
990  //thousands of SwAnnotationWins
991  SetStyle(GetStyle() | WB_DIALOGCONTROL);
992 }
993 
994 void SwAnnotationWin::DeactivatePostIt()
995 {
996  //tdf#119130 only have the active postit as a dialog control in which pressing
997  //ctrl+tab cycles between text and button so we don't waste time searching
998  //thousands of SwAnnotationWins
999  SetStyle(GetStyle() & ~WB_DIALOGCONTROL);
1000 
1001  // remove selection, #i87073#
1002  if (GetOutlinerView()->GetEditView().HasSelection())
1003  {
1004  ESelection aSelection = GetOutlinerView()->GetEditView().GetSelection();
1005  aSelection.nEndPara = aSelection.nStartPara;
1006  aSelection.nEndPos = aSelection.nStartPos;
1007  GetOutlinerView()->GetEditView().SetSelection(aSelection);
1008  }
1009 
1010  mpOutliner->CompleteOnlineSpelling();
1011 
1012  SetViewState(ViewState::NORMAL);
1013  // Make sure this view doesn't emit LOK callbacks during the update, as the
1014  // sidebar window's SidebarTextControl doesn't have a valid twip offset
1015  // (map mode origin) during that operation.
1016  bool bTiledPainting = comphelper::LibreOfficeKit::isTiledPainting();
1018  // write the visible text back into the SwField
1019  UpdateData();
1021 
1022  if ( !Application::GetSettings().GetStyleSettings().GetHighContrastMode() )
1023  GetOutlinerView()->SetBackgroundColor(COL_TRANSPARENT);
1024 
1025  if ( !IsProtected() && mpOutliner->GetEditEngine().GetText().isEmpty() )
1026  {
1027  mnEventId = Application::PostUserEvent( LINK( this, SwAnnotationWin, DeleteHdl), nullptr, true );
1028  }
1029 }
1030 
1031 void SwAnnotationWin::ToggleInsMode()
1032 {
1033  if (!mrView.GetWrtShell().IsRedlineOn())
1034  {
1035  //change outliner
1036  mpOutlinerView->GetEditView().SetInsertMode(!mpOutlinerView->GetEditView().IsInsertMode());
1037  //change document
1038  mrView.GetWrtShell().ToggleInsMode();
1039  //update statusbar
1040  SfxBindings &rBnd = mrView.GetViewFrame()->GetBindings();
1041  rBnd.Invalidate(SID_ATTR_INSERT);
1042  rBnd.Update(SID_ATTR_INSERT);
1043  }
1044 }
1045 
1046 void SwAnnotationWin::ExecuteCommand(sal_uInt16 nSlot)
1047 {
1048  mrMgr.AssureStdModeAtShell();
1049 
1050  switch (nSlot)
1051  {
1052  case FN_POSTIT:
1053  case FN_REPLY:
1054  {
1055  // if this note is empty, it will be deleted once losing the focus, so no reply, but only a new note
1056  // will be created
1057  if (!mpOutliner->GetEditEngine().GetText().isEmpty())
1058  {
1059  OutlinerParaObject* pPara = new OutlinerParaObject(GetOutlinerView()->GetEditView().CreateTextObject());
1060  mrMgr.RegisterAnswer(pPara);
1061  }
1062  if (mrMgr.HasActiveSidebarWin())
1063  mrMgr.SetActiveSidebarWin(nullptr);
1064  SwitchToFieldPos();
1065  mrView.GetViewFrame()->GetDispatcher()->Execute(FN_POSTIT);
1066  break;
1067  }
1068  case FN_DELETE_COMMENT:
1069  //Delete(); // do not kill the parent of our open popup menu
1070  mnEventId = Application::PostUserEvent( LINK( this, SwAnnotationWin, DeleteHdl), nullptr, true );
1071  break;
1073  DeleteThread();
1074  break;
1075  case FN_RESOLVE_NOTE:
1076  ToggleResolved();
1077  DoResize();
1078  Invalidate();
1079  mrMgr.LayoutPostIts();
1080  break;
1082  GetTopReplyNote()->SetResolved(!IsThreadResolved());
1083  mrMgr.UpdateResolvedStatus(GetTopReplyNote());
1084  DoResize();
1085  Invalidate();
1086  mrMgr.LayoutPostIts();
1087  break;
1088  case FN_FORMAT_ALL_NOTES:
1089  case FN_DELETE_ALL_NOTES:
1090  case FN_HIDE_ALL_NOTES:
1091  // not possible as slot as this would require that "this" is the active postit
1092  mrView.GetViewFrame()->GetBindings().Execute( nSlot, nullptr, SfxCallMode::ASYNCHRON );
1093  break;
1094  case FN_DELETE_NOTE_AUTHOR:
1095  case FN_HIDE_NOTE_AUTHOR:
1096  {
1097  // not possible as slot as this would require that "this" is the active postit
1098  SfxStringItem aItem( nSlot, GetAuthor() );
1099  const SfxPoolItem* aItems[2];
1100  aItems[0] = &aItem;
1101  aItems[1] = nullptr;
1102  mrView.GetViewFrame()->GetBindings().Execute( nSlot, aItems, SfxCallMode::ASYNCHRON );
1103  }
1104  break;
1105  default:
1106  mrView.GetViewFrame()->GetBindings().Execute( nSlot );
1107  break;
1108  }
1109 }
1110 
1111 SwEditWin& SwAnnotationWin::EditWin()
1112 {
1113  return mrView.GetEditWin();
1114 }
1115 
1116 tools::Long SwAnnotationWin::GetPostItTextHeight()
1117 {
1118  return mpOutliner ? LogicToPixel(mpOutliner->CalcTextSize()).Height() : 0;
1119 }
1120 
1121 void SwAnnotationWin::SwitchToPostIt(sal_uInt16 aDirection)
1122 {
1123  SwAnnotationWin* pPostIt = mrMgr.GetNextPostIt(aDirection, this);
1124  if (pPostIt)
1125  pPostIt->GrabFocus();
1126 }
1127 
1128 IMPL_LINK(SwAnnotationWin, MouseMoveHdl, const MouseEvent&, rMEvt, bool)
1129 {
1130  if (rMEvt.IsEnterWindow())
1131  {
1132  mbMouseOver = true;
1133  if ( !HasFocus() )
1134  {
1135  SetViewState(ViewState::VIEW);
1136  Invalidate();
1137  }
1138  }
1139  else if (rMEvt.IsLeaveWindow())
1140  {
1141  mbMouseOver = false;
1142  if ( !HasFocus() )
1143  {
1144  SetViewState(ViewState::NORMAL);
1145  Invalidate();
1146  }
1147  }
1148  return false;
1149 }
1150 
1151 bool SwAnnotationWin::SetActiveSidebarWin()
1152 {
1153  if (mrMgr.GetActiveSidebarWin() == this)
1154  return false;
1155  const bool bLockView = mrView.GetWrtShell().IsViewLocked();
1156  mrView.GetWrtShell().LockView( true );
1157  mrMgr.SetActiveSidebarWin(this);
1158  mrView.GetWrtShell().LockView( bLockView );
1159  return true;
1160 }
1161 
1162 void SwAnnotationWin::UnsetActiveSidebarWin()
1163 {
1164  if (mrMgr.GetActiveSidebarWin() != this)
1165  return;
1166  const bool bLockView = mrView.GetWrtShell().IsViewLocked();
1167  mrView.GetWrtShell().LockView( true );
1168  mrMgr.SetActiveSidebarWin(nullptr);
1169  mrView.GetWrtShell().LockView( bLockView );
1170 }
1171 
1172 IMPL_LINK(SwAnnotationWin, ScrollHdl, weld::ScrolledWindow&, rScrolledWindow, void)
1173 {
1174  tools::Long nDiff = GetOutlinerView()->GetEditView().GetVisArea().Top() - rScrolledWindow.vadjustment_get_value();
1175  GetOutlinerView()->Scroll( 0, nDiff );
1176 }
1177 
1179 {
1180  mrView.GetDocShell()->SetModified();
1181 }
1182 
1183 IMPL_LINK_NOARG(SwAnnotationWin, DeleteHdl, void*, void)
1184 {
1185  mnEventId = nullptr;
1186  Delete();
1187 }
1188 
1189 void SwAnnotationWin::ResetAttributes()
1190 {
1191  mpOutlinerView->RemoveAttribsKeepLanguages(true);
1192  mpOutliner->RemoveFields();
1193  mpOutlinerView->SetAttribs(DefaultItem());
1194 }
1195 
1196 int SwAnnotationWin::GetPrefScrollbarWidth() const
1197 {
1198  const Fraction& f(mrView.GetWrtShellPtr()->GetOut()->GetMapMode().GetScaleY());
1199  return tools::Long(Application::GetSettings().GetStyleSettings().GetScrollBarSize() * f);
1200 }
1201 
1202 sal_Int32 SwAnnotationWin::GetMetaHeight() const
1203 {
1204  const Fraction& f(mrView.GetWrtShellPtr()->GetOut()->GetMapMode().GetScaleY());
1205  const int fields = GetNumFields();
1206  return tools::Long(fields*POSTIT_META_FIELD_HEIGHT * f);
1207 }
1208 
1209 sal_Int32 SwAnnotationWin::GetNumFields() const
1210 {
1211  return IsResolved() ? 3 : 2;
1212 }
1213 
1214 sal_Int32 SwAnnotationWin::GetMinimumSizeWithMeta() const
1215 {
1216  return mrMgr.GetMinimumSizeWithMeta();
1217 }
1218 
1219 sal_Int32 SwAnnotationWin::GetMinimumSizeWithoutMeta() const
1220 {
1221  const Fraction& f(mrView.GetWrtShellPtr()->GetOut()->GetMapMode().GetScaleY());
1223 }
1224 
1225 void SwAnnotationWin::SetSpellChecking()
1226 {
1227  const SwViewOption* pVOpt = mrView.GetWrtShellPtr()->GetViewOptions();
1228  EEControlBits nCntrl = mpOutliner->GetControlWord();
1229  if (pVOpt->IsOnlineSpell())
1230  nCntrl |= EEControlBits::ONLINESPELLING;
1231  else
1232  nCntrl &= ~EEControlBits::ONLINESPELLING;
1233  mpOutliner->SetControlWord(nCntrl);
1234 
1235  mpOutliner->CompleteOnlineSpelling();
1236  Invalidate();
1237 }
1238 
1239 void SwAnnotationWin::SetViewState(ViewState bViewState)
1240 {
1241  switch (bViewState)
1242  {
1243  case ViewState::EDIT:
1244  {
1245  if (mpAnchor)
1246  {
1247  mpAnchor->SetAnchorState(AnchorState::All);
1248  SwAnnotationWin* pWin = GetTopReplyNote();
1249  // #i111964#
1250  if ( pWin != this && pWin->Anchor() )
1251  {
1253  }
1254  mpAnchor->setLineSolid(true);
1255  if ( mpTextRangeOverlay != nullptr )
1256  {
1257  mpTextRangeOverlay->ShowSolidBorder();
1258  }
1259  }
1260  if (mpShadow)
1261  mpShadow->SetShadowState(SS_EDIT);
1262  break;
1263  }
1264  case ViewState::VIEW:
1265  {
1266  if (mpAnchor)
1267  {
1268  mpAnchor->setLineSolid(true);
1269  if ( mpTextRangeOverlay != nullptr )
1270  {
1271  mpTextRangeOverlay->ShowSolidBorder();
1272  }
1273  }
1274  if (mpShadow)
1275  mpShadow->SetShadowState(SS_VIEW);
1276  break;
1277  }
1278  case ViewState::NORMAL:
1279  {
1280  if (mpAnchor)
1281  {
1282  if (IsFollow())
1283  {
1284  // if there is no visible parent note, we want to see the complete anchor ??
1285  //if (IsAnyStackParentVisible())
1286  mpAnchor->SetAnchorState(AnchorState::End);
1287  SwAnnotationWin* pTopWinSelf = GetTopReplyNote();
1288  SwAnnotationWin* pTopWinActive = mrMgr.HasActiveSidebarWin()
1289  ? mrMgr.GetActiveSidebarWin()->GetTopReplyNote()
1290  : nullptr;
1291  // #i111964#
1292  if ( ( pTopWinSelf != this ) &&
1293  ( pTopWinSelf != pTopWinActive ) &&
1294  pTopWinSelf->Anchor() )
1295  {
1296  if ( pTopWinSelf != mrMgr.GetActiveSidebarWin() )
1297  {
1298  pTopWinSelf->Anchor()->setLineSolid(false);
1299  if ( pTopWinSelf->TextRange() != nullptr )
1300  {
1301  pTopWinSelf->TextRange()->HideSolidBorder();
1302  }
1303  }
1304  pTopWinSelf->Anchor()->SetAnchorState(AnchorState::All);
1305  }
1306  }
1307  mpAnchor->setLineSolid(false);
1308  if ( mpTextRangeOverlay != nullptr )
1309  {
1310  mpTextRangeOverlay->HideSolidBorder();
1311  }
1312  }
1313  if ( mpShadow )
1314  {
1315  mpShadow->SetShadowState(SS_NORMAL);
1316  }
1317  break;
1318  }
1319  }
1320 }
1321 
1322 SwAnnotationWin* SwAnnotationWin::GetTopReplyNote()
1323 {
1324  SwAnnotationWin* pTopNote = this;
1325  SwAnnotationWin* pSidebarWin = IsFollow() ? mrMgr.GetNextPostIt(KEY_PAGEUP, this) : nullptr;
1326  while (pSidebarWin)
1327  {
1328  pTopNote = pSidebarWin;
1329  pSidebarWin = pSidebarWin->IsFollow() ? mrMgr.GetNextPostIt(KEY_PAGEUP, pSidebarWin) : nullptr;
1330  }
1331  return pTopNote;
1332 }
1333 
1334 void SwAnnotationWin::SwitchToFieldPos()
1335 {
1336  if ( mrMgr.GetActiveSidebarWin() == this )
1337  mrMgr.SetActiveSidebarWin(nullptr);
1338  GotoPos();
1339  sal_uInt32 aCount = MoveCaret();
1340  if (aCount)
1341  mrView.GetDocShell()->GetWrtShell()->SwCursorShell::Right(aCount, 0);
1342  GrabFocusToDocument();
1343  collectUIInformation("LEAVE",get_id());
1344 }
1345 
1346 void SwAnnotationWin::SetChangeTracking( const SwPostItHelper::SwLayoutStatus aLayoutStatus,
1347  const Color& aChangeColor )
1348 {
1349  if ( (mLayoutStatus != aLayoutStatus) ||
1350  (mChangeColor != aChangeColor) )
1351  {
1352  mLayoutStatus = aLayoutStatus;
1353  mChangeColor = aChangeColor;
1354  Invalidate();
1355  }
1356 }
1357 
1358 bool SwAnnotationWin::HasScrollbar() const
1359 {
1360  return static_cast<bool>(mxVScrollbar);
1361 }
1362 
1363 bool SwAnnotationWin::IsScrollbarVisible() const
1364 {
1365  return HasScrollbar() && mxVScrollbar->get_vpolicy() == VclPolicyType::ALWAYS;
1366 }
1367 
1368 void SwAnnotationWin::ChangeSidebarItem( SwSidebarItem const & rSidebarItem )
1369 {
1370  const bool bAnchorChanged = mpAnchorFrame != rSidebarItem.maLayoutInfo.mpAnchorFrame;
1371  if ( bAnchorChanged )
1372  {
1373  mrMgr.DisconnectSidebarWinFromFrame( *mpAnchorFrame, *this );
1374  }
1375 
1376  mrSidebarItem = rSidebarItem;
1377  mpAnchorFrame = mrSidebarItem.maLayoutInfo.mpAnchorFrame;
1378 
1379  if (SidebarWinAccessible* pAcc = dynamic_cast<SidebarWinAccessible*>(GetWindowPeer()))
1380  pAcc->ChangeSidebarItem( mrSidebarItem );
1381 
1382  if ( bAnchorChanged )
1383  {
1384  mrMgr.ConnectSidebarWinToFrame( *(mrSidebarItem.maLayoutInfo.mpAnchorFrame),
1385  mrSidebarItem.GetFormatField(),
1386  *this );
1387  }
1388 }
1389 
1390 css::uno::Reference< css::accessibility::XAccessible > SwAnnotationWin::CreateAccessible()
1391 {
1393  mrView.GetWrtShell(),
1394  mrSidebarItem ) );
1395  SetWindowPeer( pAcc, pAcc.get() );
1396  return pAcc;
1397 }
1398 
1399 } // eof of namespace sw::sidebarwindows
1400 
1401 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define FN_HIDE_ALL_NOTES
Definition: cmdid.h:751
Point TopLeft() const
void DrawText(const Point &rStartPt, const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, MetricVector *pVector=nullptr, OUString *pDisplayText=nullptr, const SalLayoutGlyphs *pLayoutCache=nullptr)
sal_Int32 nStartPara
Marks a position in the document model.
Definition: pam.hxx:35
sal_uInt8 GetRed() const
const SwFrame * mpAnchorFrame
SwNodeIndex nNode
Definition: pam.hxx:37
::sw::overlay::OverlayRanges * TextRange()
long Long
constexpr::Color COL_TRANSPARENT(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
const SwPosition * GetMark() const
Definition: pam.hxx:209
LanguageType GetLanguage(SfxItemSet const &aSet, sal_uInt16 nLangWhichId)
Definition: langhelper.cxx:390
virtual void SetMark() override
Unless this is called, the getter method of Mark will return Point.
Definition: viscrs.cxx:652
Any GetTime(const OUString &val)
IMPL_LINK(SidebarTextControl, OnlineSpellCallback, SpellCallbackInfo &, rInfo, void)
virtual void SetSizePixel(const Size &rNewSize)
void SetCalcFieldValueHdl(Outliner *pOutliner)
In the Outliner, set a link to the method for field display in edit objects.
Definition: docdraw.cxx:477
static ImplSVEvent * PostUserEvent(const Link< void *, void > &rLink, void *pCaller=nullptr, bool bReferenceLink=false)
SwTextNode * GetpTextNode() const
Definition: txtfld.hxx:49
void IntersectClipRegion(const tools::Rectangle &rRect)
static Color GetColorAnchor(std::size_t aAuthorIndex)
Definition: PostItMgr.cxx:2165
Of course Writer needs its own rectangles.
Definition: swrect.hxx:35
void Invalidate(sal_uInt16 nId)
void setTiledPainting(bool bTiledPainting)
float x
EEControlBits
constexpr TypedWhichId< SvxFontHeightItem > EE_CHAR_FONTHEIGHT(EE_CHAR_START+2)
tools::Long GetFontHeight() const
#define POSTIT_MINIMUMSIZE_WITHOUT_META
static std::unique_ptr< AnchorOverlayObject > CreateAnchorOverlayObject(SwView const &rDocView, const SwRect &aAnchorRect, tools::Long aPageBorder, const Point &aLineStart, const Point &aLineEnd, const Color &aColorAnchor)
bool IsValidAndGregorian() const
constexpr tools::Long Width() const
static UITestLogger & getInstance()
void logEvent(const EventDescription &rDescription)
Reference< XNameAccess > m_xContainer
const LocaleDataWrapper & GetLocaleData() const
ESelection aNewSelection(GetSelection())
#define FN_FORMAT_ALL_NOTES
Definition: cmdid.h:755
const vcl::Font & GetLabelFont() const
SwIndex nContent
Definition: pam.hxx:38
unsigned long ULong
constexpr sal_uInt16 KEY_PAGEUP
static Color GetColorDark(std::size_t aAuthorIndex)
Definition: PostItMgr.cxx:2135
sal_Int32 GetStart() const
Definition: txatbase.hxx:86
bool GetHighContrastMode() const
#define FN_DELETE_COMMENT
Definition: cmdid.h:753
#define POSTIT_META_FIELD_HEIGHT
sal_Int32 nEndPos
virtual bool DoesUndo() const =0
Is Undo enabled?
sal_uInt8 GetBlue() const
void DrawRect(const tools::Rectangle &rRect)
SfxItemPool & GetPool() const
float y
#define FN_RESOLVE_NOTE
Definition: cmdid.h:756
SwDoc * GetDoc()
returns Doc. But be careful!
Definition: docsh.hxx:203
WinBits const WB_DIALOGCONTROL
#define FN_REPLY
Definition: cmdid.h:754
void SetLineColor()
sal_Int32 nEndPara
#define SW_MOD()
Definition: swmodule.hxx:255
SwAnnotationWin * GetTopReplyNote()
Find the first annotation for the thread which this annotation is in.
SwDoc & GetDoc()
Definition: node.hxx:212
static std::unique_ptr< OverlayRanges > CreateOverlayRange(SwView const &rDocView, const Color &rColor, const std::vector< basegfx::B2DRange > &rRanges, const bool bShowSolidBorder)
#define METABUTTON_WIDTH
Window class for the Writer edit area, this is the one handling mouse and keyboard events and doing t...
Definition: edtwin.hxx:58
SwIndex & Assign(SwIndexReg *, sal_Int32)
Definition: index.cxx:206
OUString Apply(const OUString &rStr) const
Definition: SwRewriter.cxx:41
#define FN_DELETE_NOTE_AUTHOR
Definition: cmdid.h:747
#define METABUTTON_HEIGHT
void SetOrigin(const Point &rOrigin)
#define FN_HIDE_NOTE_AUTHOR
Definition: cmdid.h:750
const SwFrame * mpAnchorFrame
IMPL_LINK_NOARG(DocumentTimerManager, DoIdleJobs, Timer *, void)
void SetFillColor()
void AddRule(SwUndoArg eWhat, const OUString &rWith)
Definition: SwRewriter.cxx:27
void SetTextColor(const Color &rColor)
static bool GetLayoutRTL()
virtual void SetMark() override
Unless this is called, the getter method of Mark will return Point.
Definition: viscrs.cxx:819
bool IsInside(const Point &rPOINT) const
#define FN_DELETE_COMMENT_THREAD
Definition: cmdid.h:758
const sal_Int16 mnEventId
OUString SwResId(const char *pId)
Definition: swmodule.cxx:166
bool IsOnlineSpell() const
Definition: viewopt.hxx:371
static bool IsFieldShadings()
Definition: viewopt.hxx:671
void GrabFocus()
#define Y
SwLayoutInfo maLayoutInfo
::sw::sidebarwindows::AnchorOverlayObject * Anchor()
void SetAnchorState(const AnchorState aState)
std::unique_ptr< drawinglayer::processor2d::BaseProcessor2D > createBaseProcessor2DFromOutputDevice(OutputDevice &rTargetOutDev, const drawinglayer::geometry::ViewInformation2D &rViewInformation2D)
sal_uInt8 GetGreen() const
void Update(sal_uInt16 nId)
OUString getDate(const Date &rDate) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:79
std::vector< SwRect > SwRects
Definition: swregion.hxx:26
std::deque< AttacherIndex_Impl > aIndex
static Color GetColorLight(std::size_t aAuthorIndex)
Definition: PostItMgr.cxx:2150
constexpr tools::Long Height() const
unsigned char sal_uInt8
void SetFont(const vcl::Font &rNewFont)
SlideSorterView & mrView
SwNodes & GetNodes()
Definition: doc.hxx:408
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_BLACK
const SwStartNode * FindTableBoxStartNode() const
Definition: node.hxx:197
void SetFontHeight(tools::Long nHeight)
tools::Long GetHeight() const
reference_type * get() const
void DrawSymbol(const tools::Rectangle &rRect, SymbolType eType, const Color &rColor, DrawSymbolFlags nStyle=DrawSymbolFlags::NONE)
void(* f)(TrueTypeTable *)
OUString getTime(const tools::Time &rTime, bool bSec=true, bool b100Sec=false) const
void SetLanguage(SwWrtShell &rWrtSh, std::u16string_view rLangText, bool bIsForSelection, SfxItemSet &rCoreSet)
Definition: langhelper.cxx:214
std::map< OUString, OUString > aParameters
void Push(PushFlags nFlags=PushFlags::ALL)
bool NewTableSelection()
Definition: swcrsr.cxx:2521
#define EE_TEXTPOS_ALL
#define FN_POSTIT
Definition: cmdid.h:215
#define FN_RESOLVE_NOTE_THREAD
Definition: cmdid.h:757
static Color ColorFromAlphaColor(const sal_uInt8 aTransparency, const Color &aFront, const Color &aBack)
#define FN_DELETE_ALL_NOTES
Definition: cmdid.h:748
sal_Int32 nStartPos