LibreOffice Module svx (master) 1
viewobjectcontactofpageobj.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 <vcl/idle.hxx>
23#include <svx/svdopage.hxx>
25#include <svtools/colorcfg.hxx>
31#include <svx/svdpage.hxx>
32#include <svx/unoapi.hxx>
35#include <vcl/canvastools.hxx>
36
37using namespace com::sun::star;
38
39namespace sdr::contact {
40
42{
43private:
44 // the ViewObjectContactOfPageObj using this painter
46
47public:
48 // basic constructor/destructor
50 virtual ~PagePrimitiveExtractor() override;
51
52 // LazyInvalidate request. Supported here to not automatically
53 // invalidate the second interaction state all the time at the
54 // original OC
55 virtual void setLazyInvalidate(ViewObjectContact& rVOC) override;
56
57 // From baseclass Timer, the timeout call triggered by the LazyInvalidate mechanism
58 virtual void Invoke() final override;
59
60 // get primitive visualization
61 drawinglayer::primitive2d::Primitive2DContainer createPrimitive2DSequenceForPage();
62
63 // Own reaction on changes which will be forwarded to the OC of the owner-VOC
64 virtual void InvalidatePartOfView(const basegfx::B2DRange& rRange) const override;
65
66 // forward access to SdrPageView of ViewObjectContactOfPageObj
67 virtual bool isOutputToPrinter() const override;
68 virtual bool isPageDecorationActive() const override;
69 virtual bool isMasterPageActive() const override;
70 virtual bool isOutputToRecordingMetaFile() const override;
71 virtual bool isOutputToPDFFile() const override;
72 virtual bool isExportTaggedPDF() const override;
73 virtual ::vcl::PDFExtOutDevData const* GetPDFExtOutDevData() const override;
74 virtual bool isDrawModeGray() const override;
75 virtual bool isDrawModeHighContrast() const override;
76 virtual SdrPageView* TryToGetSdrPageView() const override;
77 virtual OutputDevice* TryToGetOutputDevice() const override;
78};
79
82: ObjectContactOfPagePainter(rVOC.GetObjectContact()), Idle("svx PagePrimitiveExtractor"),
84{
85 // make this renderer a preview renderer
86 setPreviewRenderer(true);
87
88 // init timer
89 SetPriority(TaskPriority::HIGH_IDLE);
90 Stop();
91}
92
94{
95 // execute missing LazyInvalidates and stop timer
96 Invoke();
97}
98
100{
101 // do NOT call parent, but remember that something is to do by
102 // starting the LazyInvalidateTimer
103 Start();
104}
105
106// From baseclass Timer, the timeout call triggered by the LazyInvalidate mechanism
108{
109 // stop the timer
110 Stop();
111
112 // invalidate all LazyInvalidate VOCs new situations
113 const sal_uInt32 nVOCCount(getViewObjectContactCount());
114
115 for(sal_uInt32 a(0); a < nVOCCount; a++)
116 {
117 ViewObjectContact* pCandidate = getViewObjectContact(a);
118 pCandidate->triggerLazyInvalidate();
119 }
120}
121
123{
125 SdrPage* pStartPage = GetStartPage();
126
127 if(pStartPage)
128 {
129 // update own ViewInformation2D for visualized page
131 drawinglayer::geometry::ViewInformation2D aNewViewInformation2D(rOriginalViewInformation);
132
133 // #i101075# use empty range for page content here to force
134 // the content not to be physically clipped in any way. This
135 // would be possible, but would require the internal transformation
136 // which maps between the page visualisation object and the page
137 // content, including the aspect ratios (for details see in
138 // PagePreviewPrimitive2D::create2DDecomposition)
139 aNewViewInformation2D.setViewport(basegfx::B2DRange());
140
141 aNewViewInformation2D.setVisualizedPage(GetXDrawPageForSdrPage(pStartPage));
142
143 // no time; page previews are not animated
144 aNewViewInformation2D.setViewTime(0.0);
145
146 updateViewInformation2D(aNewViewInformation2D);
147
148 // create copy of DisplayInfo to set PagePainting
149 DisplayInfo aDisplayInfo;
150
151 // get page's VOC
152 ViewObjectContact& rDrawPageVOContact = pStartPage->GetViewContact().GetViewObjectContact(*this);
153
154 // get whole Primitive2DContainer
155 rDrawPageVOContact.getPrimitive2DSequenceHierarchy(aDisplayInfo, xRetval);
156 }
157
158 return xRetval;
159}
160
162{
163 // an invalidate is called at this view, this needs to be translated to an invalidate
164 // for the using VOC. Coordinates are in page coordinate system.
165 const SdrPage* pStartPage = GetStartPage();
166
167 if(pStartPage && !rRange.isEmpty())
168 {
169 const basegfx::B2DRange aPageRange(0.0, 0.0, static_cast<double>(pStartPage->GetWidth()), static_cast<double>(pStartPage->GetHeight()));
170
171 if(rRange.overlaps(aPageRange))
172 {
173 // if object on the page is inside or overlapping with page, create ActionChanged() for
174 // involved VOC
176 }
177 }
178}
179
180// forward access to SdrPageView to VOCOfPageObj
192
194{
195 const SdrPageObj& rPageObject(static_cast< ViewContactOfPageObj& >(GetViewContact()).GetPageObj());
196 const SdrPage* pPage = rPageObject.GetReferencedPage();
197 const svtools::ColorConfig aColorConfig;
198
199 // get PageObject's geometry
200 basegfx::B2DHomMatrix aPageObjectTransform;
201 {
202 const tools::Rectangle aPageObjectModelData(rPageObject.GetLastBoundRect());
203 const basegfx::B2DRange aPageObjectBound = vcl::unotools::b2DRectangleFromRectangle(aPageObjectModelData);
204
205 aPageObjectTransform.set(0, 0, aPageObjectBound.getWidth());
206 aPageObjectTransform.set(1, 1, aPageObjectBound.getHeight());
207 aPageObjectTransform.set(0, 2, aPageObjectBound.getMinX());
208 aPageObjectTransform.set(1, 2, aPageObjectBound.getMinY());
209 }
210
211 // #i102637# add gray frame also when printing and page exists (handout pages)
212 const bool bCreateGrayFrame(!GetObjectContact().isOutputToPrinter() || pPage);
213
214 // get displayed page's content. This is the unscaled page content
215 if(mpExtractor && pPage)
216 {
217 // get displayed page's geometry
219 const Size aPageSize(pPage->GetSize());
220 const double fPageWidth(aPageSize.getWidth());
221 const double fPageHeight(aPageSize.getHeight());
222
223 // The case that a PageObject contains another PageObject which visualizes the
224 // same page again would lead to a recursion. Limit that recursion depth to one
225 // by using a local static bool
226 static bool bInCreatePrimitive2D(false);
227
228 if(bInCreatePrimitive2D)
229 {
230 // Recursion is possible. Create a replacement primitive
231 xPageContent.resize(2);
232 const Color aDocColor(aColorConfig.GetColorValue(svtools::DOCCOLOR).nColor);
234 const Color aBorderColor = aBorderConfig.bIsVisible ? aBorderConfig.nColor : aDocColor;
235 const basegfx::B2DRange aPageBound(0.0, 0.0, fPageWidth, fPageHeight);
237
238 // add replacement fill
241
242 // add replacement border
244 new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(std::move(aOutline), aBorderColor.getBColor()));
245 }
246 else
247 {
248 // set recursion flag
249 bInCreatePrimitive2D = true;
250
251 // init extractor, guarantee existence, set page there
252 mpExtractor->SetStartPage(pPage);
253
254 // #i105548# also need to copy the VOCRedirector for sub-content creation
255 mpExtractor->SetViewObjectContactRedirector(GetObjectContact().GetViewObjectContactRedirector());
256
257 // create page content
258 xPageContent = mpExtractor->createPrimitive2DSequenceForPage();
259
260 // #i105548# reset VOCRedirector to not accidentally have a pointer to a
261 // temporary class, so calls to it are avoided safely
262 mpExtractor->SetViewObjectContactRedirector(nullptr);
263
264 // reset recursion flag
265 bInCreatePrimitive2D = false;
266 }
267
268 // prepare retval
269 if(!xPageContent.empty())
270 {
271 const uno::Reference< drawing::XDrawPage > xDrawPage(GetXDrawPageForSdrPage(const_cast< SdrPage*>(pPage)));
273 xDrawPage, aPageObjectTransform, fPageWidth, fPageHeight, std::move(xPageContent)));
274 rVisitor.visit(xPagePreview);
275 }
276 }
277 else if(bCreateGrayFrame)
278 {
279 // #i105146# no content, but frame display. To make hitting the page preview objects
280 // on the handout page more simple, add hidden fill geometry
283 aPageObjectTransform));
284 rVisitor.visit(xFrameHit);
285 }
286
287 // add a gray outline frame, except not when printing
288 if(bCreateGrayFrame)
289 {
290 const Color aFrameColor(aColorConfig.GetColorValue(svtools::OBJECTBOUNDARIES).nColor);
292 aOwnOutline.transform(aPageObjectTransform);
293
295 new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(std::move(aOwnOutline), aFrameColor.getBColor()));
296
297 rVisitor.visit(xGrayFrame);
298 }
299}
300
302: ViewObjectContactOfSdrObj(rObjectContact, rViewContact),
303 mpExtractor(new PagePrimitiveExtractor(*this))
304{
305}
306
308{
309 // delete the helper OC
310 if(mpExtractor)
311 {
312 // remember candidate and reset own pointer to avoid action when createPrimitive2DSequence()
313 // would be called for any reason
314 std::unique_ptr<PagePrimitiveExtractor> pCandidate = std::move(mpExtractor);
315
316 // also reset the StartPage to avoid ActionChanged() forwardings in the
317 // PagePrimitiveExtractor::InvalidatePartOfView() implementation
318 pCandidate->SetStartPage(nullptr);
319 }
320}
321
322}
323
324/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
basegfx::BColor getBColor() const
virtual void Start(bool bStartTimer=true) override
virtual const tools::Rectangle & GetLastBoundRect() const
Definition: svdobj.cxx:977
SdrPage * GetReferencedPage() const
Definition: svdopage.hxx:55
A SdrPage contains exactly one SdrObjList and a description of the physical page dimensions (size / m...
Definition: svdpage.hxx:379
const sdr::contact::ViewContact & GetViewContact() const
Definition: svdpage.cxx:1139
Size GetSize() const
Definition: svdpage.cxx:1450
tools::Long GetHeight() const
Definition: svdpage.cxx:1481
tools::Long GetWidth() const
Definition: svdpage.cxx:1455
constexpr tools::Long getHeight() const
constexpr tools::Long getWidth() const
void SetPriority(TaskPriority ePriority)
void Stop()
void set(sal_uInt16 nRow, sal_uInt16 nColumn, double fValue)
void transform(const basegfx::B2DHomMatrix &rMatrix)
TYPE getWidth() const
TYPE getMinX() const
TYPE getMinY() const
bool isEmpty() const
TYPE getHeight() const
bool overlaps(const Range2D &rRange) const
void setViewport(const basegfx::B2DRange &rNew)
void setVisualizedPage(const css::uno::Reference< css::drawing::XDrawPage > &rNew)
virtual void visit(const Primitive2DReference &)=0
virtual bool isDrawModeGray() const
virtual bool isPageDecorationActive() const
virtual SdrPageView * TryToGetSdrPageView() const
access to SdrPageView. May return 0L like the default implementations do. Override as needed.
virtual bool isMasterPageActive() const
virtual ::vcl::PDFExtOutDevData const * GetPDFExtOutDevData() const
virtual bool isDrawModeHighContrast() const
virtual bool isExportTaggedPDF() const
virtual OutputDevice * TryToGetOutputDevice() const
access to OutputDevice. May return 0L like the default implementations do. Override as needed.
virtual bool isOutputToPDFFile() const
virtual bool isOutputToPrinter() const
const drawinglayer::geometry::ViewInformation2D & getViewInformation2D() const
virtual bool isOutputToRecordingMetaFile() const
virtual bool isDrawModeHighContrast() const override
virtual bool isPageDecorationActive() const override
virtual void setLazyInvalidate(ViewObjectContact &rVOC) override
drawinglayer::primitive2d::Primitive2DContainer createPrimitive2DSequenceForPage()
ViewObjectContactOfPageObj & mrViewObjectContactOfPageObj
virtual ::vcl::PDFExtOutDevData const * GetPDFExtOutDevData() const override
PagePrimitiveExtractor(ViewObjectContactOfPageObj &rVOC)
virtual SdrPageView * TryToGetSdrPageView() const override
virtual bool isMasterPageActive() const override
virtual void InvalidatePartOfView(const basegfx::B2DRange &rRange) const override
virtual bool isOutputToRecordingMetaFile() const override
virtual OutputDevice * TryToGetOutputDevice() const override
ViewObjectContact & GetViewObjectContact(ObjectContact &rObjectContact)
Definition: viewcontact.cxx:65
ViewObjectContactOfPageObj(ObjectContact &rObjectContact, ViewContact &rViewContact)
virtual void createPrimitive2DSequence(const DisplayInfo &rDisplayInfo, drawinglayer::primitive2d::Primitive2DDecompositionVisitor &rVisitor) const override
std::unique_ptr< PagePrimitiveExtractor > mpExtractor
ObjectContact & GetObjectContact() const
virtual void getPrimitive2DSequenceHierarchy(DisplayInfo &rDisplayInfo, drawinglayer::primitive2d::Primitive2DDecompositionVisitor &rVisitor) const
ColorConfigValue GetColorValue(ColorConfigEntry eEntry, bool bSmart=true) const
uno_Any a
B2DPolygon createPolygonFromRect(const B2DRectangle &rRect, double fRadiusX, double fRadiusY)
B2DPolygon const & createUnitPolygon()
rtl::Reference< BasePrimitive2D > Primitive2DReference
Primitive2DReference createHiddenGeometryPrimitives2D(const basegfx::B2DHomMatrix &rMatrix)
basegfx::B2DRange b2DRectangleFromRectangle(const ::tools::Rectangle &rRect)
uno::Reference< drawing::XDrawPage > GetXDrawPageForSdrPage(SdrPage *pPage) noexcept
returns a StarOffice API wrapper for the given SdrPage
Definition: unopage.cxx:873