Bug Summary

File:home/maarten/src/libreoffice/core/include/rtl/ref.hxx
Warning:line 192, column 9
Use of memory after it is freed

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name AnnotationWin2.cxx -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib64/clang/11.0.0 -isystem /usr/include/libxml2 -D BOOST_ERROR_CODE_HEADER_ONLY -D BOOST_SYSTEM_NO_DEPRECATED -D CPPU_ENV=gcc3 -D LINUX -D OSL_DEBUG_LEVEL=1 -D SAL_LOG_INFO -D SAL_LOG_WARN -D UNIX -D UNX -D X86_64 -D _PTHREADS -D _REENTRANT -D SW_DLLIMPLEMENTATION -D SWUI_DLL_NAME="libswuilo.so" -D SYSTEM_LIBXML -D EXCEPTIONS_ON -D LIBO_INTERNAL_ONLY -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source/i18n -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source/common -I /home/maarten/src/libreoffice/core/external/boost/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/boost -I /home/maarten/src/libreoffice/core/sw/source/core/inc -I /home/maarten/src/libreoffice/core/sw/source/filter/inc -I /home/maarten/src/libreoffice/core/sw/source/uibase/inc -I /home/maarten/src/libreoffice/core/sw/inc -I /home/maarten/src/libreoffice/core/workdir/SdiTarget/sw/sdi -I /home/maarten/src/libreoffice/core/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include/linux -I /home/maarten/src/libreoffice/core/config_host -I /home/maarten/src/libreoffice/core/workdir/CustomTarget/officecfg/registry -I /home/maarten/src/libreoffice/core/workdir/CustomTarget/sw/generated -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/udkapi/normal -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/offapi/normal -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/oovbaapi/normal -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10 -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/x86_64-redhat-linux -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/11.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O0 -Wno-missing-braces -std=c++17 -fdeprecated-macro -fdebug-compilation-dir /home/maarten/src/libreoffice/core -ferror-limit 19 -fvisibility hidden -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -debug-info-kind=constructor -analyzer-output=html -faddrsig -o /home/maarten/tmp/wis/scan-build-libreoffice/output/report/2020-10-07-141433-9725-1 -x c++ /home/maarten/src/libreoffice/core/sw/source/uibase/docvw/AnnotationWin2.cxx

/home/maarten/src/libreoffice/core/sw/source/uibase/docvw/AnnotationWin2.cxx

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>
28#include <basegfx/range/b2drange.hxx>
29#include "SidebarTxtControl.hxx"
30#include "SidebarScrollBar.hxx"
31#include "AnchorOverlayObject.hxx"
32#include "ShadowOverlayObject.hxx"
33#include "OverlayRanges.hxx"
34
35#include <strings.hrc>
36
37#include <viewopt.hxx>
38#include <cmdid.h>
39
40#include <editeng/fhgtitem.hxx>
41#include <editeng/langitem.hxx>
42#include <editeng/editview.hxx>
43#include <editeng/outliner.hxx>
44#include <editeng/editeng.hxx>
45#include <editeng/eeitem.hxx>
46#include <editeng/outlobj.hxx>
47
48#include <svl/undo.hxx>
49#include <svl/stritem.hxx>
50
51#include <sfx2/viewfrm.hxx>
52#include <sfx2/bindings.hxx>
53#include <sfx2/dispatch.hxx>
54
55#include <vcl/fixed.hxx>
56#include <vcl/event.hxx>
57#include <vcl/scrbar.hxx>
58#include <vcl/svapp.hxx>
59#include <vcl/menubtn.hxx>
60#include <vcl/settings.hxx>
61#include <vcl/ptrstyle.hxx>
62#include <vcl/uitest/logger.hxx>
63#include <vcl/uitest/eventdescription.hxx>
64
65#include <edtwin.hxx>
66#include <view.hxx>
67#include <docsh.hxx>
68#include <wrtsh.hxx>
69#include <doc.hxx>
70#include <swmodule.hxx>
71
72#include <txtannotationfld.hxx>
73#include <ndtxt.hxx>
74
75#include <drawinglayer/processor2d/baseprocessor2d.hxx>
76#include <drawinglayer/processor2d/processorfromoutputdevice.hxx>
77#include <unotools/localedatawrapper.hxx>
78#include <memory>
79#include <comphelper/lok.hxx>
80
81using namespace sw::sidebarwindows;
82
83namespace
84{
85
86void 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/// Translate absolute <-> relative twips: LOK wants absolute coordinates as output and gives absolute coordinates as input.
98void lcl_translateTwips(vcl::Window const & rParent, vcl::Window& rChild, MouseEvent* pMouseEvent)
99{
100 // Set map mode, so that callback payloads will contain absolute coordinates instead of relative ones.
101 Point aOffset(rChild.GetOutOffXPixel() - rParent.GetOutOffXPixel(), rChild.GetOutOffYPixel() - rParent.GetOutOffYPixel());
102 if (!rChild.IsMapModeEnabled())
103 {
104 MapMode aMapMode(rChild.GetMapMode());
105 aMapMode.SetMapUnit(MapUnit::MapTwip);
106 aMapMode.SetScaleX(rParent.GetMapMode().GetScaleX());
107 aMapMode.SetScaleY(rParent.GetMapMode().GetScaleY());
108 rChild.SetMapMode(aMapMode);
109 rChild.EnableMapMode();
110 }
111 aOffset = rChild.PixelToLogic(aOffset);
112 MapMode aMapMode(rChild.GetMapMode());
113 aMapMode.SetOrigin(aOffset);
114 aMapMode.SetMapUnit(rParent.GetMapMode().GetMapUnit());
115 rChild.SetMapMode(aMapMode);
116 rChild.EnableMapMode(false);
117
118 if (pMouseEvent)
119 {
120 // Set event coordinates, so they contain relative coordinates instead of absolute ones.
121 Point aPos = pMouseEvent->GetPosPixel();
122 aPos.Move(-aOffset.getX(), -aOffset.getY());
123 MouseEvent aMouseEvent(aPos, pMouseEvent->GetClicks(), pMouseEvent->GetMode(), pMouseEvent->GetButtons(), pMouseEvent->GetModifier());
124 *pMouseEvent = aMouseEvent;
125 }
126}
127
128/// Decide which one from the children of rParent should get rMouseEvent.
129vcl::Window* lcl_getHitWindow(sw::annotation::SwAnnotationWin& rParent, const MouseEvent& rMouseEvent)
130{
131 vcl::Window* pRet = nullptr;
132
133 rParent.EditWin().Push(PushFlags::MAPMODE);
134 rParent.EditWin().EnableMapMode();
135 for (sal_Int16 i = rParent.GetChildCount() - 1; i >= 0; --i)
136 {
137 vcl::Window* pChild = rParent.GetChild(i);
138
139 Point aPosition(rParent.GetPosPixel());
140 aPosition.Move(pChild->GetPosPixel().getX(), pChild->GetPosPixel().getY());
141 Size aSize(rParent.GetSizePixel());
142 tools::Rectangle aRectangleLogic(rParent.EditWin().PixelToLogic(aPosition), rParent.EditWin().PixelToLogic(aSize));
143 if (aRectangleLogic.IsInside(rMouseEvent.GetPosPixel()))
144 {
145 pRet = pChild;
146 break;
147 }
148 }
149 rParent.EditWin().Pop();
150 return pRet;
151}
152
153}
154
155namespace sw::annotation {
156
157#define METABUTTON_WIDTH16 16
158#define METABUTTON_HEIGHT18 18
159#define METABUTTON_AREA_WIDTH30 30
160#define POSTIT_META_FIELD_HEIGHTsal_Int32(15) sal_Int32(15)
161#define POSTIT_MINIMUMSIZE_WITHOUT_META50 50
162
163
164void SwAnnotationWin::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect)
165{
166 Window::Paint(rRenderContext, rRect);
167
168 if (!mpMetadataAuthor->IsVisible())
169 return;
170
171 //draw left over space
172 if (Application::GetSettings().GetStyleSettings().GetHighContrastMode())
173 {
174 rRenderContext.SetFillColor(COL_BLACK);
175 }
176 else
177 {
178 rRenderContext.SetFillColor(mColorDark);
179 }
180
181 sal_uInt32 boxHeight = mpMetadataAuthor->GetSizePixel().Height() + mpMetadataDate->GetSizePixel().Height();
182 boxHeight += IsResolved() ? mpMetadataResolved->GetSizePixel().Height() : 0;
183
184 rRenderContext.SetLineColor();
185 tools::Rectangle aRectangle(Point(mpMetadataAuthor->GetPosPixel().X() + mpMetadataAuthor->GetSizePixel().Width(),
186 mpMetadataAuthor->GetPosPixel().Y()),
187 Size(GetMetaButtonAreaWidth(), boxHeight));
188
189 if (comphelper::LibreOfficeKit::isActive())
190 aRectangle = rRect;
191 else
192 aRectangle = PixelToLogic(aRectangle);
193 rRenderContext.DrawRect(aRectangle);
194}
195
196void SwAnnotationWin::PaintTile(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect)
197{
198 Paint(rRenderContext, rRect);
199
200 for (sal_uInt16 i = 0; i < GetChildCount(); ++i)
201 {
202 vcl::Window* pChild = GetChild(i);
203
204 // No point in showing this button till click on it are not handled.
205 if (pChild == mpMenuButton.get())
206 continue;
207
208 if (!pChild->IsVisible())
209 continue;
210
211 rRenderContext.Push(PushFlags::MAPMODE);
212 Point aOffset(PixelToLogic(pChild->GetPosPixel()));
213 MapMode aMapMode(rRenderContext.GetMapMode());
214 aMapMode.SetOrigin(aMapMode.GetOrigin() + aOffset);
215 rRenderContext.SetMapMode(aMapMode);
216
217 bool bPopChild = false;
218 if (pChild->GetMapMode().GetMapUnit() != rRenderContext.GetMapMode().GetMapUnit())
219 {
220 // This is needed for the scrollbar that has its map unit in pixels.
221 pChild->Push(PushFlags::MAPMODE);
222 bPopChild = true;
223 pChild->EnableMapMode();
224 aMapMode = pChild->GetMapMode();
225 aMapMode.SetMapUnit(rRenderContext.GetMapMode().GetMapUnit());
226 aMapMode.SetScaleX(rRenderContext.GetMapMode().GetScaleX());
227 aMapMode.SetScaleY(rRenderContext.GetMapMode().GetScaleY());
228 pChild->SetMapMode(aMapMode);
229 }
230
231 pChild->Paint(rRenderContext, rRect);
232
233 if (bPopChild)
234 pChild->Pop();
235 rRenderContext.Pop();
236 }
237
238 const drawinglayer::geometry::ViewInformation2D aViewInformation;
239 std::unique_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor(drawinglayer::processor2d::createBaseProcessor2DFromOutputDevice(rRenderContext, aViewInformation));
240
241 // drawinglayer sets the map mode to pixels, not needed here.
242 rRenderContext.Pop();
243 // Work in document-global twips.
244 rRenderContext.Pop();
245 if (mpAnchor)
246 pProcessor->process(mpAnchor->getOverlayObjectPrimitive2DSequence());
247 if (mpTextRangeOverlay)
248 pProcessor->process(mpTextRangeOverlay->getOverlayObjectPrimitive2DSequence());
249
250 rRenderContext.Push(PushFlags::NONE);
251 pProcessor.reset();
252 rRenderContext.Push(PushFlags::NONE);
253}
254
255bool SwAnnotationWin::IsHitWindow(const Point& rPointLogic)
256{
257 tools::Rectangle aRectangleLogic(EditWin().PixelToLogic(GetPosPixel()), EditWin().PixelToLogic(GetSizePixel()));
258 return aRectangleLogic.IsInside(rPointLogic);
259}
260
261void SwAnnotationWin::SetCursorLogicPosition(const Point& rPosition, bool bPoint, bool bClearMark)
262{
263 mpSidebarTextControl->Push(PushFlags::MAPMODE);
264 MouseEvent aMouseEvent(rPosition);
265 lcl_translateTwips(EditWin(), *mpSidebarTextControl, &aMouseEvent);
266 Point aPosition(aMouseEvent.GetPosPixel());
267
268 EditView& rEditView = GetOutlinerView()->GetEditView();
269 rEditView.SetCursorLogicPosition(aPosition, bPoint, bClearMark);
270
271 mpSidebarTextControl->Pop();
272}
273
274void SwAnnotationWin::Draw(OutputDevice* pDev, const Point& rPt, DrawFlags nInFlags)
275{
276 Size aSz = pDev->PixelToLogic(GetSizePixel());
277
278 if (mpMetadataAuthor->IsVisible() )
279 {
280 pDev->SetFillColor(mColorDark);
281 pDev->SetLineColor();
282 pDev->DrawRect( tools::Rectangle( rPt, aSz ) );
283 }
284
285 if (mpMetadataAuthor->IsVisible())
286 {
287 vcl::Font aOrigFont(mpMetadataAuthor->GetControlFont());
288 Point aPos(PixelToLogic(mpMetadataAuthor->GetPosPixel()));
289 aPos += rPt;
290 vcl::Font aFont( mpMetadataAuthor->GetSettings().GetStyleSettings().GetLabelFont() );
291 mpMetadataAuthor->SetControlFont( aFont );
292 mpMetadataAuthor->Draw(pDev, aPos, nInFlags);
293 mpMetadataAuthor->SetControlFont( aOrigFont );
294 }
295
296 if (mpMetadataDate->IsVisible())
297 {
298 vcl::Font aOrigFont(mpMetadataDate->GetControlFont());
299 Point aPos(PixelToLogic(mpMetadataDate->GetPosPixel()));
300 aPos += rPt;
301 vcl::Font aFont( mpMetadataDate->GetSettings().GetStyleSettings().GetLabelFont() );
302 mpMetadataDate->SetControlFont( aFont );
303 mpMetadataDate->SetControlFont( aOrigFont );
304 }
305
306 if (mpMetadataResolved->IsVisible())
307 {
308 vcl::Font aOrigFont(mpMetadataResolved->GetControlFont());
309 Point aPos(PixelToLogic(mpMetadataResolved->GetPosPixel()));
310 aPos += rPt;
311 vcl::Font aFont( mpMetadataResolved->GetSettings().GetStyleSettings().GetLabelFont() );
312 mpMetadataResolved->SetControlFont( aFont );
313 mpMetadataResolved->SetControlFont( aOrigFont );
314 }
315
316 Size aOrigSize(mpSidebarTextControl->GetSizePixel());
317 mpSidebarTextControl->SetSizePixel(aSz);
318 mpSidebarTextControl->Draw(pDev, rPt, nInFlags);
319 mpSidebarTextControl->SetSizePixel(aOrigSize);
320
321 const drawinglayer::geometry::ViewInformation2D aNewViewInfos;
322 std::unique_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor(
323 drawinglayer::processor2d::createBaseProcessor2DFromOutputDevice(
324 *pDev, aNewViewInfos ));
325
326 if (mpAnchor)
327 pProcessor->process(mpAnchor->getOverlayObjectPrimitive2DSequence());
328 if (mpTextRangeOverlay)
329 pProcessor->process(mpTextRangeOverlay->getOverlayObjectPrimitive2DSequence());
330 pProcessor.reset();
331
332 if (!mpVScrollbar->IsVisible())
333 return;
334
335 vcl::Font aOrigFont(mpMetadataDate->GetControlFont());
336 Color aOrigBg( mpMetadataDate->GetControlBackground() );
337 OUString sOrigText(mpMetadataDate->GetText());
338
339 Point aPos(PixelToLogic(mpMenuButton->GetPosPixel()));
340 aPos += rPt;
341
342 vcl::Font aFont( mpMetadataDate->GetSettings().GetStyleSettings().GetLabelFont() );
343 mpMetadataDate->SetControlFont( aFont );
344 mpMetadataDate->SetControlBackground( Color(0xFFFFFF) );
345 mpMetadataDate->SetText("...");
346 aOrigSize = mpMetadataDate->GetSizePixel();
347 mpMetadataDate->SetSizePixel(mpMenuButton->GetSizePixel());
348 mpMetadataDate->Draw(pDev, aPos, nInFlags);
349 mpMetadataDate->SetSizePixel(aOrigSize);
350
351 mpMetadataDate->SetText(sOrigText);
352 mpMetadataDate->SetControlFont( aOrigFont );
353 mpMetadataDate->SetControlBackground( aOrigBg );
354}
355
356void SwAnnotationWin::KeyInput(const KeyEvent& rKeyEvent)
357{
358 if (mpSidebarTextControl)
359 {
360 mpSidebarTextControl->Push(PushFlags::MAPMODE);
361 lcl_translateTwips(EditWin(), *mpSidebarTextControl, nullptr);
362
363 mpSidebarTextControl->KeyInput(rKeyEvent);
364
365 mpSidebarTextControl->Pop();
366 }
367}
368
369void SwAnnotationWin::MouseMove(const MouseEvent& rMouseEvent)
370{
371 if (vcl::Window* pHit = lcl_getHitWindow(*this, rMouseEvent))
372 {
373 pHit->Push(PushFlags::MAPMODE);
374 MouseEvent aMouseEvent(rMouseEvent);
375 lcl_translateTwips(EditWin(), *pHit, &aMouseEvent);
376
377 pHit->MouseMove(aMouseEvent);
378
379 pHit->Pop();
380 }
381}
382
383void SwAnnotationWin::MouseButtonDown(const MouseEvent& rMouseEvent)
384{
385 if (vcl::Window* pHit = lcl_getHitWindow(*this, rMouseEvent))
386 {
387 pHit->Push(PushFlags::MAPMODE);
388 MouseEvent aMouseEvent(rMouseEvent);
389 lcl_translateTwips(EditWin(), *pHit, &aMouseEvent);
390
391 pHit->MouseButtonDown(aMouseEvent);
392
393 pHit->Pop();
394 }
395}
396
397void SwAnnotationWin::MouseButtonUp(const MouseEvent& rMouseEvent)
398{
399 if (vcl::Window* pHit = lcl_getHitWindow(*this, rMouseEvent))
400 {
401 pHit->Push(PushFlags::MAPMODE);
402 MouseEvent aMouseEvent(rMouseEvent);
403 lcl_translateTwips(EditWin(), *pHit, &aMouseEvent);
404
405 pHit->MouseButtonUp(aMouseEvent);
406
407 pHit->Pop();
408 }
409}
410
411void SwAnnotationWin::SetPosSizePixelRect(long nX, long nY, long nWidth, long nHeight,
412 const SwRect& aAnchorRect, const long aPageBorder)
413{
414 mPosSize = tools::Rectangle(Point(nX,nY),Size(nWidth,nHeight));
415 if (!mAnchorRect.IsEmpty() && mAnchorRect != aAnchorRect)
416 mbAnchorRectChanged = true;
417 mAnchorRect = aAnchorRect;
418 mPageBorder = aPageBorder;
419}
420
421void SwAnnotationWin::SetSize( const Size& rNewSize )
422{
423 mPosSize.SetSize(rNewSize);
424}
425
426void SwAnnotationWin::SetVirtualPosSize( const Point& aPoint, const Size& aSize)
427{
428 mPosSize = tools::Rectangle(aPoint,aSize);
429}
430
431void SwAnnotationWin::TranslateTopPosition(const long aAmount)
432{
433 mPosSize.Move(0,aAmount);
434}
435
436void SwAnnotationWin::ShowAnchorOnly(const Point &aPoint)
437{
438 HideNote();
439 SetPosAndSize();
440 if (mpAnchor)
441 {
442 mpAnchor->SetSixthPosition(basegfx::B2DPoint(aPoint.X(),aPoint.Y()));
443 mpAnchor->SetSeventhPosition(basegfx::B2DPoint(aPoint.X(),aPoint.Y()));
444 mpAnchor->SetAnchorState(AnchorState::All);
445 mpAnchor->setVisible(true);
446 }
447 if (mpShadow)
448 mpShadow->setVisible(false);
449}
450
451SfxItemSet SwAnnotationWin::DefaultItem()
452{
453 SfxItemSet aItem( mrView.GetDocShell()->GetPool() );
454 aItem.Put(SvxFontHeightItem(200,100,EE_CHAR_FONTHEIGHT));
455 return aItem;
456}
457
458void SwAnnotationWin::InitControls()
459{
460 AddEventListener( LINK( this, SwAnnotationWin, WindowEventListener )::tools::detail::makeLink( ::tools::detail::castTo<SwAnnotationWin
*>(this), &SwAnnotationWin::LinkStubWindowEventListener
)
);
461
462 // actual window which holds the user text
463 mpSidebarTextControl = VclPtr<SidebarTextControl>::Create( *this,
464 WB_NODIALOGCONTROL,
465 mrView, mrMgr );
466 mpSidebarTextControl->SetPointer(PointerStyle::Text);
467
468 // window controls for author and date
469 mpMetadataAuthor = VclPtr<FixedText>::Create(this);
470 mpMetadataAuthor->SetAccessibleName( SwResId( STR_ACCESS_ANNOTATION_AUTHOR_NAMEreinterpret_cast<char const *>("STR_ACCESS_ANNOTATION_AUTHOR_NAME"
"\004" u8"Author")
) );
471 mpMetadataAuthor->EnableRTL(AllSettings::GetLayoutRTL());
472 mpMetadataAuthor->AddEventListener( LINK( this, SwAnnotationWin, WindowEventListener )::tools::detail::makeLink( ::tools::detail::castTo<SwAnnotationWin
*>(this), &SwAnnotationWin::LinkStubWindowEventListener
)
);
473 // we should leave this setting alone, but for this we need a better layout algo
474 // with variable meta size height
475 {
476 AllSettings aSettings = mpMetadataAuthor->GetSettings();
477 StyleSettings aStyleSettings = aSettings.GetStyleSettings();
478 vcl::Font aFont = aStyleSettings.GetLabelFont();
479 aFont.SetFontHeight(8);
480 aStyleSettings.SetLabelFont(aFont);
481 aSettings.SetStyleSettings(aStyleSettings);
482 mpMetadataAuthor->SetSettings(aSettings);
483 }
484
485 mpMetadataDate = VclPtr<FixedText>::Create(this);
486 mpMetadataDate->SetAccessibleName( SwResId( STR_ACCESS_ANNOTATION_DATE_NAMEreinterpret_cast<char const *>("STR_ACCESS_ANNOTATION_DATE_NAME"
"\004" u8"Date")
) );
487 mpMetadataDate->EnableRTL(AllSettings::GetLayoutRTL());
488 mpMetadataDate->AddEventListener( LINK( this, SwAnnotationWin, WindowEventListener )::tools::detail::makeLink( ::tools::detail::castTo<SwAnnotationWin
*>(this), &SwAnnotationWin::LinkStubWindowEventListener
)
);
489 // we should leave this setting alone, but for this we need a better layout algo
490 // with variable meta size height
491 {
492 AllSettings aSettings = mpMetadataDate->GetSettings();
493 StyleSettings aStyleSettings = aSettings.GetStyleSettings();
494 vcl::Font aFont = aStyleSettings.GetLabelFont();
495 aFont.SetFontHeight(8);
496 aStyleSettings.SetLabelFont(aFont);
497 aSettings.SetStyleSettings(aStyleSettings);
498 mpMetadataDate->SetSettings(aSettings);
499 }
500
501 mpMetadataResolved = VclPtr<FixedText>::Create(this);
502 mpMetadataResolved->SetAccessibleName( SwResId( STR_ACCESS_ANNOTATION_RESOLVED_NAMEreinterpret_cast<char const *>("STR_ACCESS_ANNOTATION_RESOLVED_NAME"
"\004" u8"Resolved")
) );
503 mpMetadataResolved->EnableRTL(AllSettings::GetLayoutRTL());
504 mpMetadataResolved->AddEventListener( LINK( this, SwAnnotationWin, WindowEventListener )::tools::detail::makeLink( ::tools::detail::castTo<SwAnnotationWin
*>(this), &SwAnnotationWin::LinkStubWindowEventListener
)
);
505 // we should leave this setting alone, but for this we need a better layout algo
506 // with variable meta size height
507 {
508 AllSettings aSettings = mpMetadataResolved->GetSettings();
509 StyleSettings aStyleSettings = aSettings.GetStyleSettings();
510 vcl::Font aFont = aStyleSettings.GetLabelFont();
511 aFont.SetFontHeight(8);
512 aStyleSettings.SetLabelFont(aFont);
513 aSettings.SetStyleSettings(aStyleSettings);
514 mpMetadataResolved->SetSettings(aSettings);
515 mpMetadataResolved->SetText( SwResId( STR_ACCESS_ANNOTATION_RESOLVED_NAMEreinterpret_cast<char const *>("STR_ACCESS_ANNOTATION_RESOLVED_NAME"
"\004" u8"Resolved")
) );
516 }
517
518 SwDocShell* aShell = mrView.GetDocShell();
519 mpOutliner.reset(new Outliner(&aShell->GetPool(),OutlinerMode::TextObject));
520 aShell->GetDoc()->SetCalcFieldValueHdl( mpOutliner.get() );
521 mpOutliner->SetUpdateMode( true );
522 Rescale();
523
524 mpSidebarTextControl->EnableRTL( false );
525 mpOutlinerView.reset(new OutlinerView ( mpOutliner.get(), mpSidebarTextControl ));
526 mpOutlinerView->SetBackgroundColor(COL_TRANSPARENT);
527 mpOutliner->InsertView(mpOutlinerView.get() );
528 mpOutlinerView->SetOutputArea( PixelToLogic( tools::Rectangle(0,0,1,1) ) );
529
530 mpOutlinerView->SetAttribs(DefaultItem());
531
532 if (comphelper::LibreOfficeKit::isActive())
1
Assuming the condition is false
2
Taking false branch
533 {
534 // If there is a callback already registered, inform the new outliner view about it.
535 mpOutlinerView->RegisterViewShell(&mrView);
536 }
537
538 //create Scrollbars
539 mpVScrollbar = VclPtr<SidebarScrollBar>::Create(*this, WB_3DLOOK |WB_VSCROLL|WB_DRAG, mrView);
3
Calling 'VclPtr::Create'
5
Returned allocated memory
6
Calling implicit destructor for 'VclPtr<sw::sidebarwindows::SidebarScrollBar>'
7
Calling '~Reference'
14
Returning from '~Reference'
15
Returning from destructor for 'VclPtr<sw::sidebarwindows::SidebarScrollBar>'
540 mpVScrollbar->EnableNativeWidget(false);
16
Calling 'VclPtr::operator->'
541 mpVScrollbar->EnableRTL( false );
542 mpVScrollbar->SetScrollHdl(LINK(this, SwAnnotationWin, ScrollHdl)::tools::detail::makeLink( ::tools::detail::castTo<SwAnnotationWin
*>(this), &SwAnnotationWin::LinkStubScrollHdl)
);
543 mpVScrollbar->EnableDrag();
544 mpVScrollbar->AddEventListener( LINK( this, SwAnnotationWin, WindowEventListener )::tools::detail::makeLink( ::tools::detail::castTo<SwAnnotationWin
*>(this), &SwAnnotationWin::LinkStubWindowEventListener
)
);
545
546 const SwViewOption* pVOpt = mrView.GetWrtShellPtr()->GetViewOptions();
547 EEControlBits nCntrl = mpOutliner->GetControlWord();
548 // TODO: crash when AUTOCOMPLETE enabled
549 nCntrl |= EEControlBits::MARKFIELDS | EEControlBits::PASTESPECIAL | EEControlBits::AUTOCORRECT | EEControlBits::USECHARATTRIBS; // | EEControlBits::AUTOCOMPLETE;
550 if (SwViewOption::IsFieldShadings())
551 nCntrl |= EEControlBits::MARKFIELDS;
552 else
553 nCntrl &= ~EEControlBits::MARKFIELDS;
554 if (pVOpt->IsOnlineSpell())
555 nCntrl |= EEControlBits::ONLINESPELLING;
556 else
557 nCntrl &= ~EEControlBits::ONLINESPELLING;
558 mpOutliner->SetControlWord(nCntrl);
559
560 std::size_t aIndex = SW_MOD()( static_cast<SwModule*>(SfxApplication::GetModule(SfxToolsModule
::Writer)))
->InsertRedlineAuthor(GetAuthor());
561 SetColor( SwPostItMgr::GetColorDark(aIndex),
562 SwPostItMgr::GetColorLight(aIndex),
563 SwPostItMgr::GetColorAnchor(aIndex));
564
565 CheckMetaText();
566
567 mpMenuButton = CreateMenuButton();
568
569 SetLanguage(GetLanguage());
570 GetOutlinerView()->StartSpeller();
571 SetPostItText();
572 mpOutliner->CompleteOnlineSpelling();
573
574 mpSidebarTextControl->Show();
575 mpMetadataAuthor->Show();
576 mpMetadataDate->Show();
577 if(IsResolved()) { mpMetadataResolved->Show(); }
578 mpVScrollbar->Show();
579}
580
581void SwAnnotationWin::CheckMetaText()
582{
583 const SvtSysLocale aSysLocale;
584 const LocaleDataWrapper& rLocalData = aSysLocale.GetLocaleData();
585 OUString sMeta = GetAuthor();
586 if (sMeta.isEmpty())
587 {
588 sMeta = SwResId(STR_NOAUTHORreinterpret_cast<char const *>("STR_NOAUTHOR" "\004" u8"(no author)"
)
);
589 }
590 else if (sMeta.getLength() > 23)
591 {
592 sMeta = sMeta.copy(0, 20) + "...";
593 }
594 if ( mpMetadataAuthor->GetText() != sMeta )
595 {
596 mpMetadataAuthor->SetText(sMeta);
597 }
598
599 Date aDate = GetDate();
600 if (aDate.IsValidAndGregorian() )
601 {
602 sMeta = rLocalData.getDate(aDate);
603 }
604 else
605 {
606 sMeta = SwResId(STR_NODATEreinterpret_cast<char const *>("STR_NODATE" "\004" u8"(no date)"
)
);
607 }
608 if (GetTime().GetTime()!=0)
609 {
610 sMeta += " " + rLocalData.getTime( GetTime(),false );
611 }
612 if ( mpMetadataDate->GetText() != sMeta )
613 {
614 mpMetadataDate->SetText(sMeta);
615 }
616}
617
618void SwAnnotationWin::Rescale()
619{
620 // On Android, this method leads to invoke ImpEditEngine::UpdateViews
621 // which hides the text cursor. Moreover it causes sudden document scroll
622 // when modifying a commented text. Not clear the root cause,
623 // anyway skipping this method fixes the problem, and there should be
624 // no side effect, since the client has disabled annotations rendering.
625 if (comphelper::LibreOfficeKit::isActive() && !comphelper::LibreOfficeKit::isTiledAnnotations())
626 return;
627
628 MapMode aMode = GetParent()->GetMapMode();
629 aMode.SetOrigin( Point() );
630 mpOutliner->SetRefMapMode( aMode );
631 SetMapMode( aMode );
632 mpSidebarTextControl->SetMapMode( aMode );
633 const Fraction& rFraction = mrView.GetWrtShellPtr()->GetOut()->GetMapMode().GetScaleY();
634 if ( mpMetadataAuthor )
635 {
636 vcl::Font aFont( mpMetadataAuthor->GetSettings().GetStyleSettings().GetLabelFont() );
637 sal_Int32 nHeight = long(aFont.GetFontHeight() * rFraction);
638 aFont.SetFontHeight( nHeight );
639 mpMetadataAuthor->SetControlFont( aFont );
640 }
641 if ( mpMetadataDate )
642 {
643 vcl::Font aFont( mpMetadataDate->GetSettings().GetStyleSettings().GetLabelFont() );
644 sal_Int32 nHeight = long(aFont.GetFontHeight() * rFraction);
645 aFont.SetFontHeight( nHeight );
646 mpMetadataDate->SetControlFont( aFont );
647 }
648 if ( mpMetadataResolved )
649 {
650 vcl::Font aFont( mpMetadataResolved->GetSettings().GetStyleSettings().GetLabelFont() );
651 sal_Int32 nHeight = long(aFont.GetFontHeight() * rFraction);
652 aFont.SetFontHeight( nHeight );
653 mpMetadataResolved->SetControlFont( aFont );
654 }
655}
656
657void SwAnnotationWin::SetPosAndSize()
658{
659 bool bChange = false;
660
661 if (GetSizePixel() != mPosSize.GetSize())
662 {
663 bChange = true;
664 SetSizePixel(mPosSize.GetSize());
665
666 if (comphelper::LibreOfficeKit::isActive())
667 {
668 // Position is not yet set at VCL level, but the map mode should
669 // contain the right origin to emit the correct cursor position.
670 mpSidebarTextControl->Push(PushFlags::MAPMODE);
671 Point aOffset(mPosSize.Left(), mPosSize.Top());
672 aOffset = PixelToLogic(aOffset);
673 MapMode aMapMode(mpSidebarTextControl->GetMapMode());
674 aMapMode.SetOrigin(aOffset);
675 mpSidebarTextControl->SetMapMode(aMapMode);
676 mpSidebarTextControl->EnableMapMode(false);
677 }
678
679 DoResize();
680
681 if (comphelper::LibreOfficeKit::isActive())
682 mpSidebarTextControl->Pop();
683 }
684
685 if (GetPosPixel().X() != mPosSize.TopLeft().X() || (std::abs(GetPosPixel().Y() - mPosSize.TopLeft().Y()) > 5) )
686 {
687 bChange = true;
688 SetPosPixel(mPosSize.TopLeft());
689
690 Point aLineStart;
691 Point aLineEnd ;
692 switch ( meSidebarPosition )
693 {
694 case sw::sidebarwindows::SidebarPosition::LEFT:
695 {
696 aLineStart = EditWin().PixelToLogic( Point(GetPosPixel().X()+GetSizePixel().Width(),GetPosPixel().Y()-1) );
697 aLineEnd = EditWin().PixelToLogic( Point(GetPosPixel().X(),GetPosPixel().Y()-1) );
698 }
699 break;
700 case sw::sidebarwindows::SidebarPosition::RIGHT:
701 {
702 aLineStart = EditWin().PixelToLogic( Point(GetPosPixel().X(),GetPosPixel().Y()-1) );
703 aLineEnd = EditWin().PixelToLogic( Point(GetPosPixel().X()+GetSizePixel().Width(),GetPosPixel().Y()-1) );
704 }
705 break;
706 default:
707 OSL_FAIL( "<SwAnnotationWin::SetPosAndSize()> - unexpected position of sidebar" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/docvw/AnnotationWin2.cxx"
":" "707" ": "), "%s", "<SwAnnotationWin::SetPosAndSize()> - unexpected position of sidebar"
); } } while (false)
;
708 break;
709 }
710
711 // LOK has map mode disabled, and we still want to perform pixel ->
712 // twips conversion for the size of the line above the note.
713 if (comphelper::LibreOfficeKit::isActive() && !EditWin().IsMapModeEnabled())
714 {
715 EditWin().EnableMapMode();
716 Size aSize(aLineEnd.getX() - aLineStart.getX(), aLineEnd.getY() - aLineStart.getY());
717 aSize = EditWin().PixelToLogic(aSize);
718 aLineEnd = aLineStart;
719 aLineEnd.Move(aSize.getWidth(), aSize.getHeight());
720 EditWin().EnableMapMode(false);
721 }
722
723 if (mpAnchor)
724 {
725 mpAnchor->SetAllPosition( basegfx::B2DPoint( mAnchorRect.Left() , mAnchorRect.Bottom() - 5* 15),
726 basegfx::B2DPoint( mAnchorRect.Left()-5*15 , mAnchorRect.Bottom()+5*15),
727 basegfx::B2DPoint( mAnchorRect.Left()+5*15 , mAnchorRect.Bottom()+5*15),
728 basegfx::B2DPoint( mAnchorRect.Left(), mAnchorRect.Bottom()+2*15),
729 basegfx::B2DPoint( mPageBorder ,mAnchorRect.Bottom()+2*15),
730 basegfx::B2DPoint( aLineStart.X(),aLineStart.Y()),
731 basegfx::B2DPoint( aLineEnd.X(),aLineEnd.Y()));
732 }
733 else
734 {
735 mpAnchor = AnchorOverlayObject::CreateAnchorOverlayObject( mrView,
736 mAnchorRect,
737 mPageBorder,
738 aLineStart,
739 aLineEnd,
740 mColorAnchor );
741 if ( mpAnchor )
742 {
743 mpAnchor->setVisible(true);
744 mpAnchor->SetAnchorState(AnchorState::Tri);
745 if (HasChildPathFocus())
746 {
747 mpAnchor->setLineSolid(true);
748 }
749 }
750 }
751 }
752 else
753 {
754 if ( mpAnchor &&
755 ( mpAnchor->getBasePosition() != basegfx::B2DPoint( mAnchorRect.Left() , mAnchorRect.Bottom()-5*15) ) )
756 {
757 mpAnchor->SetTriPosition( basegfx::B2DPoint( mAnchorRect.Left() , mAnchorRect.Bottom() - 5* 15),
758 basegfx::B2DPoint( mAnchorRect.Left()-5*15 , mAnchorRect.Bottom()+5*15),
759 basegfx::B2DPoint( mAnchorRect.Left()+5*15 , mAnchorRect.Bottom()+5*15),
760 basegfx::B2DPoint( mAnchorRect.Left(), mAnchorRect.Bottom()+2*15),
761 basegfx::B2DPoint( mPageBorder , mAnchorRect.Bottom()+2*15));
762 }
763 }
764
765 if (mpShadow && bChange)
766 {
767 Point aStart = EditWin().PixelToLogic(GetPosPixel()+Point(0,GetSizePixel().Height()));
768 Point aEnd = EditWin().PixelToLogic(GetPosPixel()+Point(GetSizePixel().Width()-1,GetSizePixel().Height()));
769 mpShadow->SetPosition(basegfx::B2DPoint(aStart.X(),aStart.Y()), basegfx::B2DPoint(aEnd.X(),aEnd.Y()));
770 }
771
772 if (mrMgr.ShowNotes())
773 {
774 if (IsFollow() && !HasChildPathFocus())
775 {
776 // #i111964#
777 if ( mpAnchor )
778 {
779 mpAnchor->SetAnchorState(AnchorState::End);
780 }
781 }
782 else
783 {
784 // #i111964#
785 if ( mpAnchor )
786 {
787 mpAnchor->SetAnchorState(AnchorState::All);
788 }
789 SwAnnotationWin* pWin = GetTopReplyNote();
790 // #i111964#
791 if ( pWin != this && pWin->Anchor() )
792 {
793 pWin->Anchor()->SetAnchorState(AnchorState::End);
794 }
795 }
796 }
797
798
799 // text range overlay
800 maAnnotationTextRanges.clear();
801 if ( mrSidebarItem.maLayoutInfo.mnStartNodeIdx != 0
802 && mrSidebarItem.maLayoutInfo.mnStartContent != -1 )
803 {
804 const SwTextAnnotationField* pTextAnnotationField =
805 dynamic_cast< const SwTextAnnotationField* >( mrSidebarItem.GetFormatField().GetTextField() );
806 SwTextNode* pTextNode = pTextAnnotationField ? pTextAnnotationField->GetpTextNode() : nullptr;
807 SwContentNode* pContentNd = nullptr;
808 if (pTextNode)
809 {
810 SwNodes& rNds = pTextNode->GetDoc().GetNodes();
811 pContentNd = rNds[mrSidebarItem.maLayoutInfo.mnStartNodeIdx]->GetContentNode();
812 }
813 if (pContentNd)
814 {
815 SwPosition aStartPos( *pContentNd, mrSidebarItem.maLayoutInfo.mnStartContent );
816 SwShellCursor* pTmpCursor = nullptr;
817 const bool bTableCursorNeeded = pTextNode->FindTableBoxStartNode() != pContentNd->FindTableBoxStartNode();
818 if ( bTableCursorNeeded )
819 {
820 SwShellTableCursor* pTableCursor = new SwShellTableCursor( mrView.GetWrtShell(), aStartPos );
821 pTableCursor->SetMark();
822 pTableCursor->GetMark()->nNode = *pTextNode;
823 pTableCursor->GetMark()->nContent.Assign( pTextNode, pTextAnnotationField->GetStart()+1 );
824 pTableCursor->NewTableSelection();
825 pTmpCursor = pTableCursor;
826 }
827 else
828 {
829 SwShellCursor* pCursor = new SwShellCursor( mrView.GetWrtShell(), aStartPos );
830 pCursor->SetMark();
831 pCursor->GetMark()->nNode = *pTextNode;
832 pCursor->GetMark()->nContent.Assign( pTextNode, pTextAnnotationField->GetStart()+1 );
833 pTmpCursor = pCursor;
834 }
835 std::unique_ptr<SwShellCursor> pTmpCursorForAnnotationTextRange( pTmpCursor );
836
837 // For annotation text range rectangles to be calculated correctly,
838 // we need the map mode disabled
839 bool bDisableMapMode = comphelper::LibreOfficeKit::isActive() && EditWin().IsMapModeEnabled();
840 if (bDisableMapMode)
841 EditWin().EnableMapMode(false);
842
843 if (mrSidebarItem.maLayoutInfo.mPositionFromCommentAnchor)
844 pTmpCursorForAnnotationTextRange->FillRects();
845
846 if (bDisableMapMode)
847 EditWin().EnableMapMode();
848
849 SwRects* pRects(pTmpCursorForAnnotationTextRange.get());
850 for(const SwRect & rNextRect : *pRects)
851 {
852 const tools::Rectangle aPntRect(rNextRect.SVRect());
853 maAnnotationTextRanges.emplace_back(
854 aPntRect.Left(), aPntRect.Top(),
855 aPntRect.Right() + 1, aPntRect.Bottom() + 1);
856 }
857 }
858 }
859
860 if (mrMgr.ShowNotes() && !maAnnotationTextRanges.empty())
861 {
862 if ( mpTextRangeOverlay != nullptr )
863 {
864 mpTextRangeOverlay->setRanges( maAnnotationTextRanges );
865 if ( mpAnchor != nullptr && mpAnchor->getLineSolid() )
866 {
867 mpTextRangeOverlay->ShowSolidBorder();
868 }
869 else
870 {
871 mpTextRangeOverlay->HideSolidBorder();
872 }
873 }
874 else if (!IsFollow())
875 {
876 // This window is not a reply, then draw its range overlay.
877 mpTextRangeOverlay =
878 sw::overlay::OverlayRanges::CreateOverlayRange(
879 mrView,
880 mColorAnchor,
881 maAnnotationTextRanges,
882 mpAnchor && mpAnchor->getLineSolid() );
883 }
884 }
885 else
886 {
887 mpTextRangeOverlay.reset();
888 }
889}
890
891void SwAnnotationWin::DoResize()
892{
893 long aTextHeight = LogicToPixel( mpOutliner->CalcTextSize()).Height();
894 long aHeight = GetSizePixel().Height();
895 unsigned long aWidth = GetSizePixel().Width();
896
897 aHeight -= GetMetaHeight();
898 mpMetadataAuthor->Show();
899 if(IsResolved()) { mpMetadataResolved->Show(); }
900 mpMetadataDate->Show();
901 mpSidebarTextControl->SetQuickHelpText(OUString());
902 unsigned int numFields = GetNumFields();
903 if (aTextHeight > aHeight)
904 { // we need vertical scrollbars and have to reduce the width
905 aWidth -= GetScrollbarWidth();
906 mpVScrollbar->Show();
907 }
908 else
909 {
910 mpVScrollbar->Hide();
911 }
912
913 {
914 const Size aSizeOfMetadataControls( GetSizePixel().Width() - GetMetaButtonAreaWidth(),
915 GetMetaHeight()/numFields );
916 mpMetadataAuthor->setPosSizePixel( 0,
917 aHeight,
918 aSizeOfMetadataControls.Width(),
919 aSizeOfMetadataControls.Height() );
920 mpMetadataDate->setPosSizePixel( 0,
921 aHeight + aSizeOfMetadataControls.Height(),
922 aSizeOfMetadataControls.Width(),
923 aSizeOfMetadataControls.Height() );
924 if(IsResolved()) {
925 mpMetadataResolved->setPosSizePixel( 0,
926 aHeight + aSizeOfMetadataControls.Height()*2,
927 aSizeOfMetadataControls.Width(),
928 aSizeOfMetadataControls.Height() );
929 }
930 }
931
932 mpOutliner->SetPaperSize( PixelToLogic( Size(aWidth,aHeight) ) ) ;
933 if (!mpVScrollbar->IsVisible())
934 { // if we do not have a scrollbar anymore, we want to see the complete text
935 mpOutlinerView->SetVisArea( PixelToLogic( tools::Rectangle(0,0,aWidth,aHeight) ) );
936 }
937 mpOutlinerView->SetOutputArea( PixelToLogic( tools::Rectangle(0,0,aWidth,aHeight) ) );
938
939 if (!AllSettings::GetLayoutRTL())
940 {
941 mpSidebarTextControl->setPosSizePixel(0, 0, aWidth, aHeight);
942 mpVScrollbar->setPosSizePixel( aWidth, 0, GetScrollbarWidth(), aHeight);
943 }
944 else
945 {
946 mpSidebarTextControl->setPosSizePixel( ( aTextHeight > aHeight ? GetScrollbarWidth() : 0 ), 0,
947 aWidth, aHeight);
948 mpVScrollbar->setPosSizePixel( 0, 0, GetScrollbarWidth(), aHeight);
949 }
950
951 mpVScrollbar->SetVisibleSize( PixelToLogic(Size(0,aHeight)).Height() );
952 mpVScrollbar->SetPageSize( PixelToLogic(Size(0,aHeight)).Height() * 8 / 10 );
953 mpVScrollbar->SetLineSize( mpOutliner->GetTextHeight() / 10 );
954 SetScrollbar();
955 mpVScrollbar->SetRange( Range(0, mpOutliner->GetTextHeight()));
956
957 //calculate rects for meta- button
958 const Fraction& fx( GetMapMode().GetScaleX() );
959 const Fraction& fy( GetMapMode().GetScaleY() );
960
961 const Point aPos( mpMetadataAuthor->GetPosPixel());
962 mpMenuButton->setPosSizePixel( long(aPos.X()+GetSizePixel().Width()-(METABUTTON_WIDTH16+10)*fx),
963 long(aPos.Y()+5*fy),
964 long(METABUTTON_WIDTH16*fx),
965 long(METABUTTON_HEIGHT18*fy) );
966}
967
968void SwAnnotationWin::SetSizePixel( const Size& rNewSize )
969{
970 Window::SetSizePixel(rNewSize);
971
972 if (mpShadow)
973 {
974 Point aStart = EditWin().PixelToLogic(GetPosPixel()+Point(0,GetSizePixel().Height()));
975 Point aEnd = EditWin().PixelToLogic(GetPosPixel()+Point(GetSizePixel().Width()-1,GetSizePixel().Height()));
976 mpShadow->SetPosition(basegfx::B2DPoint(aStart.X(),aStart.Y()), basegfx::B2DPoint(aEnd.X(),aEnd.Y()));
977 }
978}
979
980void SwAnnotationWin::SetScrollbar()
981{
982 mpVScrollbar->SetThumbPos(mpOutlinerView->GetVisArea().Top());
983}
984
985void SwAnnotationWin::ResizeIfNecessary(long aOldHeight, long aNewHeight)
986{
987 if (aOldHeight != aNewHeight)
988 {
989 //check for lower border or next note
990 long aBorder = mrMgr.GetNextBorder();
991 if (aBorder != -1)
992 {
993 if (aNewHeight > GetMinimumSizeWithoutMeta())
994 {
995 long aNewLowerValue = GetPosPixel().Y() + aNewHeight + GetMetaHeight();
996 if (aNewLowerValue < aBorder)
997 SetSizePixel(Size(GetSizePixel().Width(),aNewHeight+GetMetaHeight()));
998 else
999 SetSizePixel(Size(GetSizePixel().Width(),aBorder - GetPosPixel().Y()));
1000 DoResize();
1001 Invalidate();
1002 }
1003 else
1004 {
1005 if (GetSizePixel().Height() != GetMinimumSizeWithoutMeta() + GetMetaHeight())
1006 SetSizePixel(Size(GetSizePixel().Width(),GetMinimumSizeWithoutMeta() + GetMetaHeight()));
1007 DoResize();
1008 Invalidate();
1009 }
1010 }
1011 else
1012 {
1013 DoResize();
1014 Invalidate();
1015 }
1016 }
1017 else
1018 {
1019 SetScrollbar();
1020 }
1021}
1022
1023void SwAnnotationWin::SetColor(Color aColorDark,Color aColorLight, Color aColorAnchor)
1024{
1025 mColorDark = aColorDark;
1026 mColorLight = aColorLight;
1027 mColorAnchor = aColorAnchor;
1028
1029 if ( Application::GetSettings().GetStyleSettings().GetHighContrastMode() )
1030 return;
1031
1032 {
1033 mpMetadataAuthor->SetControlBackground(mColorDark);
1034 AllSettings aSettings = mpMetadataAuthor->GetSettings();
1035 StyleSettings aStyleSettings = aSettings.GetStyleSettings();
1036 aStyleSettings.SetLabelTextColor(aColorAnchor);
1037 aSettings.SetStyleSettings(aStyleSettings);
1038 mpMetadataAuthor->SetSettings(aSettings);
1039 }
1040
1041 {
1042 mpMetadataDate->SetControlBackground(mColorDark);
1043 AllSettings aSettings = mpMetadataDate->GetSettings();
1044 StyleSettings aStyleSettings = aSettings.GetStyleSettings();
1045 aStyleSettings.SetLabelTextColor(aColorAnchor);
1046 aSettings.SetStyleSettings(aStyleSettings);
1047 mpMetadataDate->SetSettings(aSettings);
1048 }
1049
1050 {
1051 mpMetadataResolved->SetControlBackground(mColorDark);
1052 AllSettings aSettings = mpMetadataResolved->GetSettings();
1053 StyleSettings aStyleSettings = aSettings.GetStyleSettings();
1054 aStyleSettings.SetLabelTextColor(aColorAnchor);
1055 aSettings.SetStyleSettings(aStyleSettings);
1056 mpMetadataResolved->SetSettings(aSettings);
1057 }
1058
1059 AllSettings aSettings2 = mpVScrollbar->GetSettings();
1060 StyleSettings aStyleSettings2 = aSettings2.GetStyleSettings();
1061 aStyleSettings2.SetButtonTextColor(Color(0,0,0));
1062 aStyleSettings2.SetCheckedColor(mColorLight); // background
1063 aStyleSettings2.SetShadowColor(mColorAnchor);
1064 aStyleSettings2.SetFaceColor(mColorDark);
1065 aSettings2.SetStyleSettings(aStyleSettings2);
1066 mpVScrollbar->SetSettings(aSettings2);
1067}
1068
1069void SwAnnotationWin::SetSidebarPosition(sw::sidebarwindows::SidebarPosition eSidebarPosition)
1070{
1071 meSidebarPosition = eSidebarPosition;
1072}
1073
1074void SwAnnotationWin::SetReadonly(bool bSet)
1075{
1076 mbReadonly = bSet;
1077 GetOutlinerView()->SetReadOnly(bSet);
1078}
1079
1080void SwAnnotationWin::SetLanguage(const SvxLanguageItem& rNewItem)
1081{
1082 IDocumentUndoRedo& rUndoRedo(
1083 mrView.GetDocShell()->GetDoc()->GetIDocumentUndoRedo());
1084 const bool bDocUndoEnabled = rUndoRedo.DoesUndo();
1085 const bool bOutlinerUndoEnabled = mpOutliner->IsUndoEnabled();
1086 const bool bOutlinerModified = mpOutliner->IsModified();
1087 const bool bDisableAndRestoreUndoMode = !bDocUndoEnabled && bOutlinerUndoEnabled;
1088
1089 if (bDisableAndRestoreUndoMode)
1090 {
1091 // doc undo is disabled, but outliner was enabled, turn outliner undo off
1092 // for the duration of this function
1093 mpOutliner->EnableUndo(false);
1094 }
1095
1096 Link<LinkParamNone*,void> aLink = mpOutliner->GetModifyHdl();
1097 mpOutliner->SetModifyHdl( Link<LinkParamNone*,void>() );
1098 ESelection aOld = GetOutlinerView()->GetSelection();
1099
1100 ESelection aNewSelection( 0, 0, mpOutliner->GetParagraphCount()-1, EE_TEXTPOS_ALL((sal_Int32) 0x7FFFFFFF) );
1101 GetOutlinerView()->SetSelection( aNewSelection );
1102 SfxItemSet aEditAttr(GetOutlinerView()->GetAttribs());
1103 aEditAttr.Put(rNewItem);
1104 GetOutlinerView()->SetAttribs( aEditAttr );
1105
1106 if (!mpOutliner->IsUndoEnabled() && !bOutlinerModified)
1107 {
1108 // if undo was disabled (e.g. this is a redo action) and we were
1109 // originally 'unmodified' keep it that way
1110 mpOutliner->ClearModifyFlag();
1111 }
1112
1113 GetOutlinerView()->SetSelection(aOld);
1114 mpOutliner->SetModifyHdl( aLink );
1115
1116 const SwViewOption* pVOpt = mrView.GetWrtShellPtr()->GetViewOptions();
1117 EEControlBits nCntrl = mpOutliner->GetControlWord();
1118 // turn off
1119 nCntrl &= ~EEControlBits::ONLINESPELLING;
1120 mpOutliner->SetControlWord(nCntrl);
1121
1122 //turn back on
1123 if (pVOpt->IsOnlineSpell())
1124 nCntrl |= EEControlBits::ONLINESPELLING;
1125 else
1126 nCntrl &= ~EEControlBits::ONLINESPELLING;
1127 mpOutliner->SetControlWord(nCntrl);
1128
1129 mpOutliner->CompleteOnlineSpelling();
1130
1131 // restore original mode
1132 if (bDisableAndRestoreUndoMode)
1133 mpOutliner->EnableUndo(true);
1134
1135 Invalidate();
1136}
1137
1138void SwAnnotationWin::GetFocus()
1139{
1140 if (mpSidebarTextControl)
1141 mpSidebarTextControl->GrabFocus();
1142}
1143
1144void SwAnnotationWin::LoseFocus()
1145{
1146}
1147
1148void SwAnnotationWin::ShowNote()
1149{
1150 SetPosAndSize();
1151 if (!IsVisible())
1152 Window::Show();
1153 if (mpShadow && !mpShadow->isVisible())
1154 mpShadow->setVisible(true);
1155 if (mpAnchor && !mpAnchor->isVisible())
1156 mpAnchor->setVisible(true);
1157
1158 // Invalidate.
1159 InvalidateControl();
1160 collectUIInformation("SHOW",get_id());
1161}
1162
1163void SwAnnotationWin::HideNote()
1164{
1165 if (IsVisible())
1166 Window::Hide();
1167 if (mpAnchor)
1168 {
1169 if (mrMgr.IsShowAnchor())
1170 mpAnchor->SetAnchorState(AnchorState::Tri);
1171 else
1172 mpAnchor->setVisible(false);
1173 }
1174 if (mpShadow && mpShadow->isVisible())
1175 mpShadow->setVisible(false);
1176 collectUIInformation("HIDE",get_id());
1177}
1178
1179void SwAnnotationWin::InvalidateControl()
1180{
1181 // Invalidate.
1182 mpSidebarTextControl->Push(PushFlags::MAPMODE);
1183 lcl_translateTwips(EditWin(), *mpSidebarTextControl, nullptr);
1184 mpSidebarTextControl->Invalidate();
1185 mpSidebarTextControl->Pop();
1186}
1187
1188void SwAnnotationWin::ActivatePostIt()
1189{
1190 mrMgr.AssureStdModeAtShell();
1191
1192 mpOutliner->ClearModifyFlag();
1193 mpOutliner->GetUndoManager().Clear();
1194
1195 CheckMetaText();
1196 SetViewState(ViewState::EDIT);
1197 GetOutlinerView()->ShowCursor();
1198
1199 mpOutlinerView->GetEditView().SetInsertMode(mrView.GetWrtShellPtr()->IsInsMode());
1200
1201 if ( !Application::GetSettings().GetStyleSettings().GetHighContrastMode() )
1202 GetOutlinerView()->SetBackgroundColor(mColorDark);
1203
1204 //tdf#119130 only have the active postit as a dialog control in which pressing
1205 //ctrl+tab cycles between text and button so we don't waste time searching
1206 //thousands of SwAnnotationWins
1207 SetStyle(GetStyle() | WB_DIALOGCONTROL);
1208}
1209
1210void SwAnnotationWin::DeactivatePostIt()
1211{
1212 //tdf#119130 only have the active postit as a dialog control in which pressing
1213 //ctrl+tab cycles between text and button so we don't waste time searching
1214 //thousands of SwAnnotationWins
1215 SetStyle(GetStyle() & ~WB_DIALOGCONTROL);
1216
1217 // remove selection, #i87073#
1218 if (GetOutlinerView()->GetEditView().HasSelection())
1219 {
1220 ESelection aSelection = GetOutlinerView()->GetEditView().GetSelection();
1221 aSelection.nEndPara = aSelection.nStartPara;
1222 aSelection.nEndPos = aSelection.nStartPos;
1223 GetOutlinerView()->GetEditView().SetSelection(aSelection);
1224 }
1225
1226 mpOutliner->CompleteOnlineSpelling();
1227
1228 SetViewState(ViewState::NORMAL);
1229 // Make sure this view doesn't emit LOK callbacks during the update, as the
1230 // sidebar window's SidebarTextControl doesn't have a valid twip offset
1231 // (map mode origin) during that operation.
1232 bool bTiledPainting = comphelper::LibreOfficeKit::isTiledPainting();
1233 comphelper::LibreOfficeKit::setTiledPainting(true);
1234 // write the visible text back into the SwField
1235 UpdateData();
1236 comphelper::LibreOfficeKit::setTiledPainting(bTiledPainting);
1237
1238 if ( !Application::GetSettings().GetStyleSettings().GetHighContrastMode() )
1239 GetOutlinerView()->SetBackgroundColor(COL_TRANSPARENT);
1240
1241 if ( !IsProtected() && mpOutliner->GetEditEngine().GetText().isEmpty() )
1242 {
1243 mnEventId = Application::PostUserEvent( LINK( this, SwAnnotationWin, DeleteHdl)::tools::detail::makeLink( ::tools::detail::castTo<SwAnnotationWin
*>(this), &SwAnnotationWin::LinkStubDeleteHdl)
, nullptr, true );
1244 }
1245}
1246
1247void SwAnnotationWin::ToggleInsMode()
1248{
1249 if (!mrView.GetWrtShell().IsRedlineOn())
1250 {
1251 //change outliner
1252 mpOutlinerView->GetEditView().SetInsertMode(!mpOutlinerView->GetEditView().IsInsertMode());
1253 //change document
1254 mrView.GetWrtShell().ToggleInsMode();
1255 //update statusbar
1256 SfxBindings &rBnd = mrView.GetViewFrame()->GetBindings();
1257 rBnd.Invalidate(SID_ATTR_INSERTTypedWhichId<SfxBoolItem>( 10000 + 221 ));
1258 rBnd.Update(SID_ATTR_INSERTTypedWhichId<SfxBoolItem>( 10000 + 221 ));
1259 }
1260}
1261
1262void SwAnnotationWin::ExecuteCommand(sal_uInt16 nSlot)
1263{
1264 mrMgr.AssureStdModeAtShell();
1265
1266 switch (nSlot)
1267 {
1268 case FN_POSTIT((20000 + 300) + 29):
1269 case FN_REPLY((20000 + 2500)+7):
1270 {
1271 // if this note is empty, it will be deleted once losing the focus, so no reply, but only a new note
1272 // will be created
1273 if (!mpOutliner->GetEditEngine().GetText().isEmpty())
1274 {
1275 OutlinerParaObject* pPara = new OutlinerParaObject(*GetOutlinerView()->GetEditView().CreateTextObject());
1276 mrMgr.RegisterAnswer(pPara);
1277 }
1278 if (mrMgr.HasActiveSidebarWin())
1279 mrMgr.SetActiveSidebarWin(nullptr);
1280 SwitchToFieldPos();
1281 mrView.GetViewFrame()->GetDispatcher()->Execute(FN_POSTIT((20000 + 300) + 29));
1282 break;
1283 }
1284 case FN_DELETE_COMMENT((20000 + 2500)+6):
1285 //Delete(); // do not kill the parent of our open popup menu
1286 mnEventId = Application::PostUserEvent( LINK( this, SwAnnotationWin, DeleteHdl)::tools::detail::makeLink( ::tools::detail::castTo<SwAnnotationWin
*>(this), &SwAnnotationWin::LinkStubDeleteHdl)
, nullptr, true );
1287 break;
1288 case FN_DELETE_COMMENT_THREAD((20000 + 2500)+11):
1289 DeleteThread();
1290 break;
1291 case FN_RESOLVE_NOTE((20000 + 2500)+9):
1292 ToggleResolved();
1293 DoResize();
1294 Invalidate();
1295 mrMgr.LayoutPostIts();
1296 break;
1297 case FN_RESOLVE_NOTE_THREAD((20000 + 2500)+10):
1298 GetTopReplyNote()->SetResolved(!IsThreadResolved());
1299 mrMgr.UpdateResolvedStatus(GetTopReplyNote());
1300 DoResize();
1301 Invalidate();
1302 mrMgr.LayoutPostIts();
1303 break;
1304 case FN_FORMAT_ALL_NOTES((20000 + 2500)+8):
1305 case FN_DELETE_ALL_NOTES((20000 + 2500)+2):
1306 case FN_HIDE_ALL_NOTES((20000 + 2500)+5):
1307 // not possible as slot as this would require that "this" is the active postit
1308 mrView.GetViewFrame()->GetBindings().Execute( nSlot, nullptr, SfxCallMode::ASYNCHRON );
1309 break;
1310 case FN_DELETE_NOTE_AUTHOR((20000 + 2500)+1):
1311 case FN_HIDE_NOTE_AUTHOR((20000 + 2500)+4):
1312 {
1313 // not possible as slot as this would require that "this" is the active postit
1314 SfxStringItem aItem( nSlot, GetAuthor() );
1315 const SfxPoolItem* aItems[2];
1316 aItems[0] = &aItem;
1317 aItems[1] = nullptr;
1318 mrView.GetViewFrame()->GetBindings().Execute( nSlot, aItems, SfxCallMode::ASYNCHRON );
1319 }
1320 break;
1321 default:
1322 mrView.GetViewFrame()->GetBindings().Execute( nSlot );
1323 break;
1324 }
1325}
1326
1327SwEditWin& SwAnnotationWin::EditWin()
1328{
1329 return mrView.GetEditWin();
1330}
1331
1332long SwAnnotationWin::GetPostItTextHeight()
1333{
1334 return mpOutliner ? LogicToPixel(mpOutliner->CalcTextSize()).Height() : 0;
1335}
1336
1337void SwAnnotationWin::SwitchToPostIt(sal_uInt16 aDirection)
1338{
1339 SwAnnotationWin* pPostIt = mrMgr.GetNextPostIt(aDirection, this);
1340 if (pPostIt)
1341 pPostIt->GrabFocus();
1342}
1343
1344IMPL_LINK( SwAnnotationWin, WindowEventListener, VclWindowEvent&, rEvent, void )void SwAnnotationWin::LinkStubWindowEventListener(void * instance
, VclWindowEvent& data) { return static_cast<SwAnnotationWin
*>(instance)->WindowEventListener(data); } void SwAnnotationWin
::WindowEventListener(VclWindowEvent& rEvent)
1345{
1346 if ( rEvent.GetId() == VclEventId::WindowMouseMove )
1347 {
1348 MouseEvent* pMouseEvt = static_cast<MouseEvent*>(rEvent.GetData());
1349 if ( pMouseEvt->IsEnterWindow() )
1350 {
1351 mbMouseOver = true;
1352 if ( !HasFocus() )
1353 {
1354 SetViewState(ViewState::VIEW);
1355 Invalidate();
1356 }
1357 }
1358 else if ( pMouseEvt->IsLeaveWindow())
1359 {
1360 mbMouseOver = false;
1361 if ( !HasFocus() )
1362 {
1363 SetViewState(ViewState::NORMAL);
1364 Invalidate();
1365 }
1366 }
1367 }
1368 else if ( rEvent.GetId() == VclEventId::WindowActivate &&
1369 rEvent.GetWindow() == mpSidebarTextControl )
1370 {
1371 SetActiveSidebarWin();
1372 mrMgr.MakeVisible( this );
1373 }
1374}
1375
1376bool SwAnnotationWin::SetActiveSidebarWin()
1377{
1378 if (mrMgr.GetActiveSidebarWin() == this)
1379 return false;
1380 const bool bLockView = mrView.GetWrtShell().IsViewLocked();
1381 mrView.GetWrtShell().LockView( true );
1382 mrMgr.SetActiveSidebarWin(this);
1383 mrView.GetWrtShell().LockView( bLockView );
1384 return true;
1385}
1386
1387void SwAnnotationWin::UnsetActiveSidebarWin()
1388{
1389 if (mrMgr.GetActiveSidebarWin() != this)
1390 return;
1391 const bool bLockView = mrView.GetWrtShell().IsViewLocked();
1392 mrView.GetWrtShell().LockView( true );
1393 mrMgr.SetActiveSidebarWin(nullptr);
1394 mrView.GetWrtShell().LockView( bLockView );
1395}
1396
1397IMPL_LINK(SwAnnotationWin, ScrollHdl, ScrollBar*, pScroll, void)void SwAnnotationWin::LinkStubScrollHdl(void * instance, ScrollBar
* data) { return static_cast<SwAnnotationWin *>(instance
)->ScrollHdl(data); } void SwAnnotationWin::ScrollHdl(ScrollBar
* pScroll)
1398{
1399 long nDiff = GetOutlinerView()->GetEditView().GetVisArea().Top() - pScroll->GetThumbPos();
1400 GetOutlinerView()->Scroll( 0, nDiff );
1401}
1402
1403IMPL_LINK_NOARG(SwAnnotationWin, ModifyHdl, LinkParamNone*, void)void SwAnnotationWin::LinkStubModifyHdl(void * instance, LinkParamNone
* data) { return static_cast<SwAnnotationWin *>(instance
)->ModifyHdl(data); } void SwAnnotationWin::ModifyHdl(__attribute__
((unused)) LinkParamNone*)
1404{
1405 mrView.GetDocShell()->SetModified();
1406}
1407
1408IMPL_LINK_NOARG(SwAnnotationWin, DeleteHdl, void*, void)void SwAnnotationWin::LinkStubDeleteHdl(void * instance, void
* data) { return static_cast<SwAnnotationWin *>(instance
)->DeleteHdl(data); } void SwAnnotationWin::DeleteHdl(__attribute__
((unused)) void*)
1409{
1410 mnEventId = nullptr;
1411 Delete();
1412}
1413
1414void SwAnnotationWin::ResetAttributes()
1415{
1416 mpOutlinerView->RemoveAttribsKeepLanguages(true);
1417 mpOutliner->RemoveFields();
1418 mpOutlinerView->SetAttribs(DefaultItem());
1419}
1420
1421sal_Int32 SwAnnotationWin::GetScrollbarWidth() const
1422{
1423 return mrView.GetWrtShell().GetViewOptions()->GetZoom() / 10;
1424}
1425
1426sal_Int32 SwAnnotationWin::GetMetaButtonAreaWidth() const
1427{
1428 const Fraction& f( GetMapMode().GetScaleX() );
1429 return long(METABUTTON_AREA_WIDTH30 * f);
1430}
1431
1432sal_Int32 SwAnnotationWin::GetMetaHeight() const
1433{
1434 const Fraction& f(mrView.GetWrtShellPtr()->GetOut()->GetMapMode().GetScaleY());
1435 const int fields = GetNumFields();
1436 return long(fields*POSTIT_META_FIELD_HEIGHTsal_Int32(15)*f);
1437}
1438
1439sal_Int32 SwAnnotationWin::GetNumFields() const
1440{
1441 return IsResolved() ? 3 : 2;
1442}
1443
1444sal_Int32 SwAnnotationWin::GetMinimumSizeWithMeta() const
1445{
1446 return mrMgr.GetMinimumSizeWithMeta();
1447}
1448
1449sal_Int32 SwAnnotationWin::GetMinimumSizeWithoutMeta() const
1450{
1451 const Fraction& f(mrView.GetWrtShellPtr()->GetOut()->GetMapMode().GetScaleY());
1452 return long(POSTIT_MINIMUMSIZE_WITHOUT_META50 * f);
1453}
1454
1455void SwAnnotationWin::SetSpellChecking()
1456{
1457 const SwViewOption* pVOpt = mrView.GetWrtShellPtr()->GetViewOptions();
1458 EEControlBits nCntrl = mpOutliner->GetControlWord();
1459 if (pVOpt->IsOnlineSpell())
1460 nCntrl |= EEControlBits::ONLINESPELLING;
1461 else
1462 nCntrl &= ~EEControlBits::ONLINESPELLING;
1463 mpOutliner->SetControlWord(nCntrl);
1464
1465 mpOutliner->CompleteOnlineSpelling();
1466 Invalidate();
1467}
1468
1469void SwAnnotationWin::SetViewState(ViewState bViewState)
1470{
1471 switch (bViewState)
1472 {
1473 case ViewState::EDIT:
1474 {
1475 if (mpAnchor)
1476 {
1477 mpAnchor->SetAnchorState(AnchorState::All);
1478 SwAnnotationWin* pWin = GetTopReplyNote();
1479 // #i111964#
1480 if ( pWin != this && pWin->Anchor() )
1481 {
1482 pWin->Anchor()->SetAnchorState(AnchorState::End);
1483 }
1484 mpAnchor->setLineSolid(true);
1485 if ( mpTextRangeOverlay != nullptr )
1486 {
1487 mpTextRangeOverlay->ShowSolidBorder();
1488 }
1489 }
1490 if (mpShadow)
1491 mpShadow->SetShadowState(SS_EDIT);
1492 break;
1493 }
1494 case ViewState::VIEW:
1495 {
1496 if (mpAnchor)
1497 {
1498 mpAnchor->setLineSolid(true);
1499 if ( mpTextRangeOverlay != nullptr )
1500 {
1501 mpTextRangeOverlay->ShowSolidBorder();
1502 }
1503 }
1504 if (mpShadow)
1505 mpShadow->SetShadowState(SS_VIEW);
1506 break;
1507 }
1508 case ViewState::NORMAL:
1509 {
1510 if (mpAnchor)
1511 {
1512 if (IsFollow())
1513 {
1514 // if there is no visible parent note, we want to see the complete anchor ??
1515 //if (IsAnyStackParentVisible())
1516 mpAnchor->SetAnchorState(AnchorState::End);
1517 SwAnnotationWin* pTopWinSelf = GetTopReplyNote();
1518 SwAnnotationWin* pTopWinActive = mrMgr.HasActiveSidebarWin()
1519 ? mrMgr.GetActiveSidebarWin()->GetTopReplyNote()
1520 : nullptr;
1521 // #i111964#
1522 if ( ( pTopWinSelf != this ) &&
1523 ( pTopWinSelf != pTopWinActive ) &&
1524 pTopWinSelf->Anchor() )
1525 {
1526 if ( pTopWinSelf != mrMgr.GetActiveSidebarWin() )
1527 {
1528 pTopWinSelf->Anchor()->setLineSolid(false);
1529 if ( pTopWinSelf->TextRange() != nullptr )
1530 {
1531 pTopWinSelf->TextRange()->HideSolidBorder();
1532 }
1533 }
1534 pTopWinSelf->Anchor()->SetAnchorState(AnchorState::All);
1535 }
1536 }
1537 mpAnchor->setLineSolid(false);
1538 if ( mpTextRangeOverlay != nullptr )
1539 {
1540 mpTextRangeOverlay->HideSolidBorder();
1541 }
1542 }
1543 if ( mpShadow )
1544 {
1545 mpShadow->SetShadowState(SS_NORMAL);
1546 }
1547 break;
1548 }
1549 }
1550}
1551
1552SwAnnotationWin* SwAnnotationWin::GetTopReplyNote()
1553{
1554 SwAnnotationWin* pTopNote = this;
1555 SwAnnotationWin* pSidebarWin = IsFollow() ? mrMgr.GetNextPostIt(KEY_PAGEUP, this) : nullptr;
1556 while (pSidebarWin)
1557 {
1558 pTopNote = pSidebarWin;
1559 pSidebarWin = pSidebarWin->IsFollow() ? mrMgr.GetNextPostIt(KEY_PAGEUP, pSidebarWin) : nullptr;
1560 }
1561 return pTopNote;
1562}
1563
1564void SwAnnotationWin::SwitchToFieldPos()
1565{
1566 if ( mrMgr.GetActiveSidebarWin() == this )
1567 mrMgr.SetActiveSidebarWin(nullptr);
1568 GotoPos();
1569 sal_uInt32 aCount = MoveCaret();
1570 if (aCount)
1571 mrView.GetDocShell()->GetWrtShell()->SwCursorShell::Right(aCount, 0);
1572 GrabFocusToDocument();
1573 collectUIInformation("LEAVE",get_id());
1574}
1575
1576void SwAnnotationWin::SetChangeTracking( const SwPostItHelper::SwLayoutStatus aLayoutStatus,
1577 const Color& aChangeColor )
1578{
1579 if ( (mLayoutStatus != aLayoutStatus) ||
1580 (mChangeColor != aChangeColor) )
1581 {
1582 mLayoutStatus = aLayoutStatus;
1583 mChangeColor = aChangeColor;
1584 Invalidate();
1585 }
1586}
1587
1588bool SwAnnotationWin::HasScrollbar() const
1589{
1590 return mpVScrollbar != nullptr;
1591}
1592
1593bool SwAnnotationWin::IsScrollbarVisible() const
1594{
1595 return HasScrollbar() && mpVScrollbar->IsVisible();
1596}
1597
1598void SwAnnotationWin::ChangeSidebarItem( SwSidebarItem const & rSidebarItem )
1599{
1600 const bool bAnchorChanged = mpAnchorFrame != rSidebarItem.maLayoutInfo.mpAnchorFrame;
1601 if ( bAnchorChanged )
1602 {
1603 mrMgr.DisconnectSidebarWinFromFrame( *mpAnchorFrame, *this );
1604 }
1605
1606 mrSidebarItem = rSidebarItem;
1607 mpAnchorFrame = mrSidebarItem.maLayoutInfo.mpAnchorFrame;
1608
1609 if ( GetWindowPeer() )
1610 {
1611 SidebarWinAccessible* pAcc =
1612 static_cast<SidebarWinAccessible*>( GetWindowPeer() );
1613 OSL_ENSURE( dynamic_cast<SidebarWinAccessible*>( GetWindowPeer() ),do { if (true && (!(dynamic_cast<SidebarWinAccessible
*>( GetWindowPeer() )))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/docvw/AnnotationWin2.cxx"
":" "1614" ": "), "%s", "<SwAnnotationWin::ChangeSidebarItem(..)> - unexpected type of window peer -> crash possible!"
); } } while (false)
1614 "<SwAnnotationWin::ChangeSidebarItem(..)> - unexpected type of window peer -> crash possible!" )do { if (true && (!(dynamic_cast<SidebarWinAccessible
*>( GetWindowPeer() )))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/docvw/AnnotationWin2.cxx"
":" "1614" ": "), "%s", "<SwAnnotationWin::ChangeSidebarItem(..)> - unexpected type of window peer -> crash possible!"
); } } while (false)
;
1615 pAcc->ChangeSidebarItem( mrSidebarItem );
1616 }
1617
1618 if ( bAnchorChanged )
1619 {
1620 mrMgr.ConnectSidebarWinToFrame( *(mrSidebarItem.maLayoutInfo.mpAnchorFrame),
1621 mrSidebarItem.GetFormatField(),
1622 *this );
1623 }
1624}
1625
1626css::uno::Reference< css::accessibility::XAccessible > SwAnnotationWin::CreateAccessible()
1627{
1628 SidebarWinAccessible* pAcc( new SidebarWinAccessible( *this,
1629 mrView.GetWrtShell(),
1630 mrSidebarItem ) );
1631 css::uno::Reference< css::awt::XWindowPeer > xWinPeer( pAcc );
1632 SetWindowPeer( xWinPeer, pAcc );
1633
1634 css::uno::Reference< css::accessibility::XAccessible > xAcc( xWinPeer, css::uno::UNO_QUERY );
1635 return xAcc;
1636}
1637
1638} // eof of namespace sw::sidebarwindows
1639
1640/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx

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#ifndef INCLUDED_VCL_PTR_HXX
21#define INCLUDED_VCL_PTR_HXX
22
23#include <sal/config.h>
24
25#include <rtl/ref.hxx>
26
27#include <utility>
28#include <type_traits>
29
30#ifdef DBG_UTIL
31#ifndef _WIN32
32#include <vcl/vclmain.hxx>
33#endif
34#endif
35
36class VclReferenceBase;
37
38namespace vcl::detail {
39
40template<typename>
41constexpr bool isIncompleteOrDerivedFromVclReferenceBase(...) { return true; }
42
43template<typename T> constexpr bool isIncompleteOrDerivedFromVclReferenceBase(
44 int (*)[sizeof(T)])
45{ return std::is_base_of<VclReferenceBase, T>::value; }
46
47} // namespace vcl::detail
48
49/**
50 * A thin wrapper around rtl::Reference to implement the acquire and dispose semantics we want for references to vcl::Window subclasses.
51 *
52 * For more details on the design please see vcl/README.lifecycle
53 *
54 * @param reference_type must be a subclass of vcl::Window
55 */
56template <class reference_type>
57class VclPtr
58{
59 static_assert(
60 vcl::detail::isIncompleteOrDerivedFromVclReferenceBase<reference_type>(
61 nullptr),
62 "template argument type must be derived from VclReferenceBase");
63
64 ::rtl::Reference<reference_type> m_rInnerRef;
65
66public:
67 /** Constructor...
68 */
69 VclPtr()
70 : m_rInnerRef()
71 {}
72
73 /** Constructor...
74 */
75 VclPtr (reference_type * pBody)
76 : m_rInnerRef(pBody)
77 {}
78
79 /** Constructor... that doesn't take a ref.
80 */
81 VclPtr (reference_type * pBody, __sal_NoAcquire)
82 : m_rInnerRef(pBody, SAL_NO_ACQUIRE)
83 {}
84
85 /** Up-casting conversion constructor: Copies interface reference.
86
87 Does not work for up-casts to ambiguous bases. For the special case of
88 up-casting to Reference< XInterface >, see the corresponding conversion
89 operator.
90
91 @param rRef another reference
92 */
93 template< class derived_type >
94 VclPtr(
95 const VclPtr< derived_type > & rRef,
96 typename std::enable_if<
97 std::is_base_of<reference_type, derived_type>::value, int>::type
98 = 0 )
99 : m_rInnerRef( static_cast<reference_type*>(rRef) )
100 {
101 }
102
103#if defined(DBG_UTIL) && !defined(_WIN32)
104 virtual ~VclPtr()
105 {
106 assert(m_rInnerRef.get() == nullptr || vclmain::isAlive())(static_cast <bool> (m_rInnerRef.get() == nullptr || vclmain
::isAlive()) ? void (0) : __assert_fail ("m_rInnerRef.get() == nullptr || vclmain::isAlive()"
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 106, __extension__ __PRETTY_FUNCTION__))
;
107 // We can be one of the intermediate counts, but if we are the last
108 // VclPtr keeping this object alive, then something forgot to call dispose().
109 assert((!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1)(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef
->isDisposed() || m_rInnerRef->getRefCount() > 1) &&
"someone forgot to call dispose()") ? void (0) : __assert_fail
("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\""
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 110, __extension__ __PRETTY_FUNCTION__))
110 && "someone forgot to call dispose()")(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef
->isDisposed() || m_rInnerRef->getRefCount() > 1) &&
"someone forgot to call dispose()") ? void (0) : __assert_fail
("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\""
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 110, __extension__ __PRETTY_FUNCTION__))
;
111 }
112 VclPtr(VclPtr const &) = default;
113 VclPtr(VclPtr &&) = default;
114 VclPtr & operator =(VclPtr const &) = default;
115 VclPtr & operator =(VclPtr &&) = default;
116#endif
117
118 /**
119 * A construction helper for VclPtr. Since VclPtr types are created
120 * with a reference-count of one - to help fit into the existing
121 * code-flow; this helps us to construct them easily.
122 *
123 * For more details on the design please see vcl/README.lifecycle
124 *
125 * @tparam reference_type must be a subclass of vcl::Window
126 */
127 template<typename... Arg> [[nodiscard]] static VclPtr< reference_type > Create(Arg &&... arg)
128 {
129 return VclPtr< reference_type >( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE );
4
Memory is allocated
130 }
131
132 /** Probably most common used: handle->someBodyOp().
133 */
134 reference_type * operator->() const
135 {
136 return m_rInnerRef.get();
17
Calling 'Reference::get'
137 }
138
139 /** Get the body. Can be used instead of operator->().
140 I.e. handle->someBodyOp() and handle.get()->someBodyOp()
141 are the same.
142 */
143 reference_type * get() const
144 {
145 return m_rInnerRef.get();
146 }
147
148 void set(reference_type *pBody)
149 {
150 m_rInnerRef.set(pBody);
151 }
152
153 void reset(reference_type *pBody)
154 {
155 m_rInnerRef.set(pBody);
156 }
157
158 /** Up-casting copy assignment operator.
159
160 Does not work for up-casts to ambiguous bases.
161
162 @param rRef another reference
163 */
164 template<typename derived_type>
165 typename std::enable_if<
166 std::is_base_of<reference_type, derived_type>::value,
167 VclPtr &>::type
168 operator =(VclPtr<derived_type> const & rRef)
169 {
170 m_rInnerRef.set(rRef.get());
171 return *this;
172 }
173
174 VclPtr & operator =(reference_type * pBody)
175 {
176 m_rInnerRef.set(pBody);
177 return *this;
178 }
179
180 operator reference_type * () const
181 {
182 return m_rInnerRef.get();
183 }
184
185 explicit operator bool () const
186 {
187 return m_rInnerRef.get() != nullptr;
188 }
189
190 void clear()
191 {
192 m_rInnerRef.clear();
193 }
194
195 void reset()
196 {
197 m_rInnerRef.clear();
198 }
199
200 void disposeAndClear()
201 {
202 // hold it alive for the lifetime of this method
203 ::rtl::Reference<reference_type> aTmp(m_rInnerRef);
204 m_rInnerRef.clear(); // we should use some 'swap' method ideally ;-)
205 if (aTmp.get()) {
206 aTmp->disposeOnce();
207 }
208 }
209
210 /** Needed to place VclPtr's into STL collection.
211 */
212 bool operator< (const VclPtr<reference_type> & handle) const
213 {
214 return (m_rInnerRef < handle.m_rInnerRef);
215 }
216}; // class VclPtr
217
218template<typename T1, typename T2>
219inline bool operator ==(VclPtr<T1> const & p1, VclPtr<T2> const & p2) {
220 return p1.get() == p2.get();
221}
222
223template<typename T> inline bool operator ==(VclPtr<T> const & p1, T const * p2)
224{
225 return p1.get() == p2;
226}
227
228template<typename T> inline bool operator ==(VclPtr<T> const & p1, T * p2) {
229 return p1.get() == p2;
230}
231
232template<typename T> inline bool operator ==(T const * p1, VclPtr<T> const & p2)
233{
234 return p1 == p2.get();
235}
236
237template<typename T> inline bool operator ==(T * p1, VclPtr<T> const & p2) {
238 return p1 == p2.get();
239}
240
241template<typename T1, typename T2>
242inline bool operator !=(VclPtr<T1> const & p1, VclPtr<T2> const & p2) {
243 return !(p1 == p2);
244}
245
246template<typename T> inline bool operator !=(VclPtr<T> const & p1, T const * p2)
247{
248 return !(p1 == p2);
249}
250
251template<typename T> inline bool operator !=(VclPtr<T> const & p1, T * p2) {
252 return !(p1 == p2);
253}
254
255template<typename T> inline bool operator !=(T const * p1, VclPtr<T> const & p2)
256{
257 return !(p1 == p2);
258}
259
260template<typename T> inline bool operator !=(T * p1, VclPtr<T> const & p2) {
261 return !(p1 == p2);
262}
263
264/**
265 * A construction helper for a temporary VclPtr. Since VclPtr types
266 * are created with a reference-count of one - to help fit into
267 * the existing code-flow; this helps us to construct them easily.
268 * see also VclPtr::Create and ScopedVclPtr
269 *
270 * For more details on the design please see vcl/README.lifecycle
271 *
272 * @param reference_type must be a subclass of vcl::Window
273 */
274template <class reference_type>
275class SAL_WARN_UNUSED__attribute__((warn_unused)) VclPtrInstance final : public VclPtr<reference_type>
276{
277public:
278 template<typename... Arg> VclPtrInstance(Arg &&... arg)
279 : VclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE )
280 {
281 }
282
283 /**
284 * Override and disallow this, to prevent people accidentally calling it and actually
285 * getting VclPtr::Create and getting a naked VclPtr<> instance
286 */
287 template<typename... Arg> static VclPtrInstance< reference_type > Create(Arg &&... ) = delete;
288};
289
290template <class reference_type>
291class ScopedVclPtr : public VclPtr<reference_type>
292{
293public:
294 /** Constructor...
295 */
296 ScopedVclPtr()
297 : VclPtr<reference_type>()
298 {}
299
300 /** Constructor
301 */
302 ScopedVclPtr (reference_type * pBody)
303 : VclPtr<reference_type>(pBody)
304 {}
305
306 /** Copy constructor...
307 */
308 ScopedVclPtr (const VclPtr<reference_type> & handle)
309 : VclPtr<reference_type>(handle)
310 {}
311
312 /**
313 Assignment that releases the last reference.
314 */
315 void disposeAndReset(reference_type *pBody)
316 {
317 if (pBody != this->get()) {
318 VclPtr<reference_type>::disposeAndClear();
319 VclPtr<reference_type>::set(pBody);
320 }
321 }
322
323 /**
324 Assignment that releases the last reference.
325 */
326 ScopedVclPtr<reference_type>& operator = (reference_type * pBody)
327 {
328 disposeAndReset(pBody);
329 return *this;
330 }
331
332 /** Up-casting conversion constructor: Copies interface reference.
333
334 Does not work for up-casts to ambiguous bases. For the special case of
335 up-casting to Reference< XInterface >, see the corresponding conversion
336 operator.
337
338 @param rRef another reference
339 */
340 template< class derived_type >
341 ScopedVclPtr(
342 const VclPtr< derived_type > & rRef,
343 typename std::enable_if<
344 std::is_base_of<reference_type, derived_type>::value, int>::type
345 = 0 )
346 : VclPtr<reference_type>( rRef )
347 {
348 }
349
350 /** Up-casting assignment operator.
351
352 Does not work for up-casts to ambiguous bases.
353
354 @param rRef another VclPtr
355 */
356 template<typename derived_type>
357 typename std::enable_if<
358 std::is_base_of<reference_type, derived_type>::value,
359 ScopedVclPtr &>::type
360 operator =(VclPtr<derived_type> const & rRef)
361 {
362 disposeAndReset(rRef.get());
363 return *this;
364 }
365
366 /**
367 * Override and disallow this, to prevent people accidentally calling it and actually
368 * getting VclPtr::Create and getting a naked VclPtr<> instance
369 */
370 template<typename... Arg> static ScopedVclPtr< reference_type > Create(Arg &&... ) = delete;
371
372 ~ScopedVclPtr()
373 {
374 VclPtr<reference_type>::disposeAndClear();
375 assert(VclPtr<reference_type>::get() == nullptr)(static_cast <bool> (VclPtr<reference_type>::get(
) == nullptr) ? void (0) : __assert_fail ("VclPtr<reference_type>::get() == nullptr"
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 375, __extension__ __PRETTY_FUNCTION__))
; // make sure there are no lingering references
376 }
377
378private:
379 // Most likely we don't want this default copy-constructor.
380 ScopedVclPtr (const ScopedVclPtr<reference_type> &) = delete;
381 // And certainly we don't want a default assignment operator.
382 ScopedVclPtr<reference_type>& operator = (const ScopedVclPtr<reference_type> &) = delete;
383 // And disallow reset as that doesn't call disposeAndClear on the original reference
384 void reset() = delete;
385 void reset(reference_type *pBody) = delete;
386
387protected:
388 ScopedVclPtr (reference_type * pBody, __sal_NoAcquire)
389 : VclPtr<reference_type>(pBody, SAL_NO_ACQUIRE)
390 {}
391};
392
393/**
394 * A construction helper for ScopedVclPtr. Since VclPtr types are created
395 * with a reference-count of one - to help fit into the existing
396 * code-flow; this helps us to construct them easily.
397 *
398 * For more details on the design please see vcl/README.lifecycle
399 *
400 * @param reference_type must be a subclass of vcl::Window
401 */
402#if defined _MSC_VER
403#pragma warning(push)
404#pragma warning(disable: 4521) // " multiple copy constructors specified"
405#endif
406template <class reference_type>
407class SAL_WARN_UNUSED__attribute__((warn_unused)) ScopedVclPtrInstance final : public ScopedVclPtr<reference_type>
408{
409public:
410 template<typename... Arg> ScopedVclPtrInstance(Arg &&... arg)
411 : ScopedVclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE )
412 {
413 }
414
415 /**
416 * Override and disallow this, to prevent people accidentally calling it and actually
417 * getting VclPtr::Create and getting a naked VclPtr<> instance
418 */
419 template<typename... Arg> static ScopedVclPtrInstance< reference_type > Create(Arg &&...) = delete;
420
421private:
422 // Prevent the above perfect forwarding ctor from hijacking (accidental)
423 // attempts at ScopedVclPtrInstance copy construction (where the hijacking
424 // would typically lead to somewhat obscure error messages); both non-const
425 // and const variants are needed here, as the ScopedVclPtr base class has a
426 // const--variant copy ctor, so the implicitly declared copy ctor for
427 // ScopedVclPtrInstance would also be the const variant, so non-const copy
428 // construction attempts would be hijacked by the perfect forwarding ctor;
429 // but if we only declared a non-const variant here, the const variant would
430 // no longer be implicitly declared (as there would already be an explicitly
431 // declared copy ctor), so const copy construction attempts would then be
432 // hijacked by the perfect forwarding ctor:
433 ScopedVclPtrInstance(ScopedVclPtrInstance &) = delete;
434 ScopedVclPtrInstance(ScopedVclPtrInstance const &) = delete;
435};
436#if defined _MSC_VER
437#pragma warning(pop)
438#endif
439
440#endif // INCLUDED_VCL_PTR_HXX
441
442/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/home/maarten/src/libreoffice/core/include/rtl/ref.hxx

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#ifndef INCLUDED_RTL_REF_HXX
21#define INCLUDED_RTL_REF_HXX
22
23#include "sal/config.h"
24
25#include <cassert>
26#include <cstddef>
27#include <functional>
28#ifdef LIBO_INTERNAL_ONLY1
29#include <type_traits>
30#endif
31
32#include "sal/types.h"
33
34namespace rtl
35{
36
37/** Template reference class for reference type.
38*/
39template <class reference_type>
40class Reference
41{
42 /** The <b>reference_type</b> body pointer.
43 */
44 reference_type * m_pBody;
45
46
47public:
48 /** Constructor...
49 */
50 Reference()
51 : m_pBody (NULL__null)
52 {}
53
54
55 /** Constructor...
56 */
57 Reference (reference_type * pBody, __sal_NoAcquire)
58 : m_pBody (pBody)
59 {
60 }
61
62 /** Constructor...
63 */
64 Reference (reference_type * pBody)
65 : m_pBody (pBody)
66 {
67 if (m_pBody)
68 m_pBody->acquire();
69 }
70
71 /** Copy constructor...
72 */
73 Reference (const Reference<reference_type> & handle)
74 : m_pBody (handle.m_pBody)
75 {
76 if (m_pBody)
77 m_pBody->acquire();
78 }
79
80#ifdef LIBO_INTERNAL_ONLY1
81 /** Move constructor...
82 */
83 Reference (Reference<reference_type> && handle) noexcept
84 : m_pBody (handle.m_pBody)
85 {
86 handle.m_pBody = nullptr;
87 }
88#endif
89
90#if defined LIBO_INTERNAL_ONLY1
91 /** Up-casting conversion constructor: Copies interface reference.
92
93 Does not work for up-casts to ambiguous bases.
94
95 @param rRef another reference
96 */
97 template< class derived_type >
98 inline Reference(
99 const Reference< derived_type > & rRef,
100 std::enable_if_t<std::is_base_of_v<reference_type, derived_type>, int> = 0 )
101 : m_pBody (rRef.get())
102 {
103 if (m_pBody)
104 m_pBody->acquire();
105 }
106#endif
107
108 /** Destructor...
109 */
110 ~Reference() COVERITY_NOEXCEPT_FALSE
111 {
112 if (m_pBody
7.1
Field 'm_pBody' is non-null
7.1
Field 'm_pBody' is non-null
7.1
Field 'm_pBody' is non-null
7.1
Field 'm_pBody' is non-null
)
8
Taking true branch
113 m_pBody->release();
9
Calling 'VclReferenceBase::release'
13
Returning; memory was released
114 }
115
116 /** Set...
117 Similar to assignment.
118 */
119 Reference<reference_type> &
120 SAL_CALL set (reference_type * pBody)
121 {
122 if (pBody)
123 pBody->acquire();
124 reference_type * const pOld = m_pBody;
125 m_pBody = pBody;
126 if (pOld)
127 pOld->release();
128 return *this;
129 }
130
131 /** Assignment.
132 Unbinds this instance from its body (if bound) and
133 bind it to the body represented by the handle.
134 */
135 Reference<reference_type> &
136 SAL_CALL operator= (const Reference<reference_type> & handle)
137 {
138 return set( handle.m_pBody );
139 }
140
141#ifdef LIBO_INTERNAL_ONLY1
142 /** Assignment.
143 * Unbinds this instance from its body (if bound),
144 * bind it to the body represented by the handle, and
145 * set the body represented by the handle to nullptr.
146 */
147 Reference<reference_type> &
148 operator= (Reference<reference_type> && handle)
149 {
150 // self-movement guts ourself
151 if (m_pBody)
152 m_pBody->release();
153 m_pBody = handle.m_pBody;
154 handle.m_pBody = nullptr;
155 return *this;
156 }
157#endif
158
159 /** Assignment...
160 */
161 Reference<reference_type> &
162 SAL_CALL operator= (reference_type * pBody)
163 {
164 return set( pBody );
165 }
166
167 /** Unbind the body from this handle.
168 Note that for a handle representing a large body,
169 "handle.clear().set(new body());" _might_
170 perform a little bit better than "handle.set(new body());",
171 since in the second case two large objects exist in memory
172 (the old body and the new body).
173 */
174 Reference<reference_type> & SAL_CALL clear()
175 {
176 if (m_pBody)
177 {
178 reference_type * const pOld = m_pBody;
179 m_pBody = NULL__null;
180 pOld->release();
181 }
182 return *this;
183 }
184
185
186 /** Get the body. Can be used instead of operator->().
187 I.e. handle->someBodyOp() and handle.get()->someBodyOp()
188 are the same.
189 */
190 reference_type * SAL_CALL get() const
191 {
192 return m_pBody;
18
Use of memory after it is freed
193 }
194
195
196 /** Probably most common used: handle->someBodyOp().
197 */
198 reference_type * SAL_CALL operator->() const
199 {
200 assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail
("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx"
, 200, __extension__ __PRETTY_FUNCTION__))
;
201 return m_pBody;
202 }
203
204
205 /** Allows (*handle).someBodyOp().
206 */
207 reference_type & SAL_CALL operator*() const
208 {
209 assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail
("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx"
, 209, __extension__ __PRETTY_FUNCTION__))
;
210 return *m_pBody;
211 }
212
213
214 /** Returns True if the handle does point to a valid body.
215 */
216 bool SAL_CALL is() const
217 {
218 return (m_pBody != NULL__null);
219 }
220
221#if defined LIBO_INTERNAL_ONLY1
222 /** Returns True if the handle does point to a valid body.
223 */
224 explicit operator bool() const
225 {
226 return is();
227 }
228#endif
229
230 /** Returns True if this points to pBody.
231 */
232 bool SAL_CALL operator== (const reference_type * pBody) const
233 {
234 return (m_pBody == pBody);
235 }
236
237
238 /** Returns True if handle points to the same body.
239 */
240 bool
241 SAL_CALL operator== (const Reference<reference_type> & handle) const
242 {
243 return (m_pBody == handle.m_pBody);
244 }
245
246
247 /** Needed to place References into STL collection.
248 */
249 bool
250 SAL_CALL operator!= (const Reference<reference_type> & handle) const
251 {
252 return (m_pBody != handle.m_pBody);
253 }
254
255
256 /** Needed to place References into STL collection.
257 */
258 bool
259 SAL_CALL operator< (const Reference<reference_type> & handle) const
260 {
261 return (m_pBody < handle.m_pBody);
262 }
263
264
265 /** Needed to place References into STL collection.
266 */
267 bool
268 SAL_CALL operator> (const Reference<reference_type> & handle) const
269 {
270 return (m_pBody > handle.m_pBody);
271 }
272};
273
274} // namespace rtl
275
276#if defined LIBO_INTERNAL_ONLY1
277namespace std
278{
279
280/// @cond INTERNAL
281/**
282 Make rtl::Reference hashable by default for use in STL containers.
283
284 @since LibreOffice 6.3
285*/
286template<typename T>
287struct hash<::rtl::Reference<T>>
288{
289 std::size_t operator()(::rtl::Reference<T> const & s) const
290 { return std::size_t(s.get()); }
291};
292/// @endcond
293
294}
295
296#endif
297
298#endif /* ! INCLUDED_RTL_REF_HXX */
299
300/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/home/maarten/src/libreoffice/core/include/vcl/vclreferencebase.hxx

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#ifndef INCLUDED_VCL_Reference_HXX
20#define INCLUDED_VCL_Reference_HXX
21
22#include <vcl/dllapi.h>
23#include <osl/interlck.h>
24
25class VCL_DLLPUBLIC__attribute__ ((visibility("default"))) VclReferenceBase
26{
27 mutable oslInterlockedCount mnRefCnt;
28
29 template<typename T> friend class VclPtr;
30
31public:
32 void acquire() const
33 {
34 osl_atomic_increment(&mnRefCnt)__sync_add_and_fetch((&mnRefCnt), 1);
35 }
36
37 void release() const
38 {
39 if (osl_atomic_decrement(&mnRefCnt)__sync_sub_and_fetch((&mnRefCnt), 1) == 0)
10
Assuming the condition is true
11
Taking true branch
40 delete this;
12
Memory is released
41 }
42#ifdef DBG_UTIL
43#ifndef _WIN32
44 sal_Int32 getRefCount() const { return mnRefCnt; }
45#endif
46#endif
47
48
49private:
50 VclReferenceBase(const VclReferenceBase&) = delete;
51 VclReferenceBase& operator=(const VclReferenceBase&) = delete;
52
53 bool mbDisposed : 1;
54
55protected:
56 VclReferenceBase();
57protected:
58 virtual ~VclReferenceBase();
59
60protected:
61 virtual void dispose();
62
63public:
64 void disposeOnce();
65 bool isDisposed() const { return mbDisposed; }
66
67};
68#endif