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 isOutputToRecordingMetaFile() const override;
69 virtual bool isOutputToPDFFile() const override;
70 virtual bool isExportTaggedPDF() const override;
71 virtual ::vcl::PDFExtOutDevData const* GetPDFExtOutDevData() const override;
72 virtual bool isDrawModeGray() const override;
73 virtual bool isDrawModeHighContrast() const override;
74 virtual SdrPageView* TryToGetSdrPageView() const override;
75 virtual OutputDevice* TryToGetOutputDevice() const override;
76};
77
80: ObjectContactOfPagePainter(rVOC.GetObjectContact()), Idle("svx PagePrimitiveExtractor"),
82{
83 // make this renderer a preview renderer
84 setPreviewRenderer(true);
85
86 // init timer
87 SetPriority(TaskPriority::HIGH_IDLE);
88 Stop();
89}
90
92{
93 // execute missing LazyInvalidates and stop timer
94 Invoke();
95}
96
98{
99 // do NOT call parent, but remember that something is to do by
100 // starting the LazyInvalidateTimer
101 Start();
102}
103
104// From baseclass Timer, the timeout call triggered by the LazyInvalidate mechanism
106{
107 // stop the timer
108 Stop();
109
110 // invalidate all LazyInvalidate VOCs new situations
111 const sal_uInt32 nVOCCount(getViewObjectContactCount());
112
113 for(sal_uInt32 a(0); a < nVOCCount; a++)
114 {
115 ViewObjectContact* pCandidate = getViewObjectContact(a);
116 pCandidate->triggerLazyInvalidate();
117 }
118}
119
121{
123 SdrPage* pStartPage = GetStartPage();
124
125 if(pStartPage)
126 {
127 // update own ViewInformation2D for visualized page
129 drawinglayer::geometry::ViewInformation2D aNewViewInformation2D(rOriginalViewInformation);
130
131 // #i101075# use empty range for page content here to force
132 // the content not to be physically clipped in any way. This
133 // would be possible, but would require the internal transformation
134 // which maps between the page visualisation object and the page
135 // content, including the aspect ratios (for details see in
136 // PagePreviewPrimitive2D::create2DDecomposition)
137 aNewViewInformation2D.setViewport(basegfx::B2DRange());
138
139 aNewViewInformation2D.setVisualizedPage(GetXDrawPageForSdrPage(pStartPage));
140
141 // no time; page previews are not animated
142 aNewViewInformation2D.setViewTime(0.0);
143
144 updateViewInformation2D(aNewViewInformation2D);
145
146 // create copy of DisplayInfo to set PagePainting
147 DisplayInfo aDisplayInfo;
148
149 // get page's VOC
150 ViewObjectContact& rDrawPageVOContact = pStartPage->GetViewContact().GetViewObjectContact(*this);
151
152 // get whole Primitive2DContainer
153 rDrawPageVOContact.getPrimitive2DSequenceHierarchy(aDisplayInfo, xRetval);
154 }
155
156 return xRetval;
157}
158
160{
161 // an invalidate is called at this view, this needs to be translated to an invalidate
162 // for the using VOC. Coordinates are in page coordinate system.
163 const SdrPage* pStartPage = GetStartPage();
164
165 if(pStartPage && !rRange.isEmpty())
166 {
167 const basegfx::B2DRange aPageRange(0.0, 0.0, static_cast<double>(pStartPage->GetWidth()), static_cast<double>(pStartPage->GetHeight()));
168
169 if(rRange.overlaps(aPageRange))
170 {
171 // if object on the page is inside or overlapping with page, create ActionChanged() for
172 // involved VOC
174 }
175 }
176}
177
178// forward access to SdrPageView to VOCOfPageObj
188
190{
191 const SdrPageObj& rPageObject(static_cast< ViewContactOfPageObj& >(GetViewContact()).GetPageObj());
192 const SdrPage* pPage = rPageObject.GetReferencedPage();
193 const svtools::ColorConfig aColorConfig;
194
195 // get PageObject's geometry
196 basegfx::B2DHomMatrix aPageObjectTransform;
197 {
198 const tools::Rectangle aPageObjectModelData(rPageObject.GetLastBoundRect());
199 const basegfx::B2DRange aPageObjectBound = vcl::unotools::b2DRectangleFromRectangle(aPageObjectModelData);
200
201 aPageObjectTransform.set(0, 0, aPageObjectBound.getWidth());
202 aPageObjectTransform.set(1, 1, aPageObjectBound.getHeight());
203 aPageObjectTransform.set(0, 2, aPageObjectBound.getMinX());
204 aPageObjectTransform.set(1, 2, aPageObjectBound.getMinY());
205 }
206
207 // #i102637# add gray frame also when printing and page exists (handout pages)
208 const bool bCreateGrayFrame(!GetObjectContact().isOutputToPrinter() || pPage);
209
210 // get displayed page's content. This is the unscaled page content
211 if(mpExtractor && pPage)
212 {
213 // get displayed page's geometry
215 const Size aPageSize(pPage->GetSize());
216 const double fPageWidth(aPageSize.getWidth());
217 const double fPageHeight(aPageSize.getHeight());
218
219 // The case that a PageObject contains another PageObject which visualizes the
220 // same page again would lead to a recursion. Limit that recursion depth to one
221 // by using a local static bool
222 static bool bInCreatePrimitive2D(false);
223
224 if(bInCreatePrimitive2D)
225 {
226 // Recursion is possible. Create a replacement primitive
227 xPageContent.resize(2);
228 const Color aDocColor(aColorConfig.GetColorValue(svtools::DOCCOLOR).nColor);
230 const Color aBorderColor = aBorderConfig.bIsVisible ? aBorderConfig.nColor : aDocColor;
231 const basegfx::B2DRange aPageBound(0.0, 0.0, fPageWidth, fPageHeight);
233
234 // add replacement fill
237
238 // add replacement border
240 new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(std::move(aOutline), aBorderColor.getBColor()));
241 }
242 else
243 {
244 // set recursion flag
245 bInCreatePrimitive2D = true;
246
247 // init extractor, guarantee existence, set page there
248 mpExtractor->SetStartPage(pPage);
249
250 // #i105548# also need to copy the VOCRedirector for sub-content creation
251 mpExtractor->SetViewObjectContactRedirector(GetObjectContact().GetViewObjectContactRedirector());
252
253 // create page content
254 xPageContent = mpExtractor->createPrimitive2DSequenceForPage();
255
256 // #i105548# reset VOCRedirector to not accidentally have a pointer to a
257 // temporary class, so calls to it are avoided safely
258 mpExtractor->SetViewObjectContactRedirector(nullptr);
259
260 // reset recursion flag
261 bInCreatePrimitive2D = false;
262 }
263
264 // prepare retval
265 if(!xPageContent.empty())
266 {
267 const uno::Reference< drawing::XDrawPage > xDrawPage(GetXDrawPageForSdrPage(const_cast< SdrPage*>(pPage)));
269 xDrawPage, aPageObjectTransform, fPageWidth, fPageHeight, std::move(xPageContent)));
270 rVisitor.visit(xPagePreview);
271 }
272 }
273 else if(bCreateGrayFrame)
274 {
275 // #i105146# no content, but frame display. To make hitting the page preview objects
276 // on the handout page more simple, add hidden fill geometry
279 aPageObjectTransform));
280 rVisitor.visit(xFrameHit);
281 }
282
283 // add a gray outline frame, except not when printing
284 if(bCreateGrayFrame)
285 {
286 const Color aFrameColor(aColorConfig.GetColorValue(svtools::OBJECTBOUNDARIES).nColor);
288 aOwnOutline.transform(aPageObjectTransform);
289
291 new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(std::move(aOwnOutline), aFrameColor.getBColor()));
292
293 rVisitor.visit(xGrayFrame);
294 }
295}
296
298: ViewObjectContactOfSdrObj(rObjectContact, rViewContact),
299 mpExtractor(new PagePrimitiveExtractor(*this))
300{
301}
302
304{
305 // delete the helper OC
306 if(mpExtractor)
307 {
308 // remember candidate and reset own pointer to avoid action when createPrimitive2DSequence()
309 // would be called for any reason
310 std::unique_ptr<PagePrimitiveExtractor> pCandidate = std::move(mpExtractor);
311
312 // also reset the StartPage to avoid ActionChanged() forwardings in the
313 // PagePrimitiveExtractor::InvalidatePartOfView() implementation
314 pCandidate->SetStartPage(nullptr);
315 }
316}
317
318}
319
320/* 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:941
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:377
const sdr::contact::ViewContact & GetViewContact() const
Definition: svdpage.cxx:1167
Size GetSize() const
Definition: svdpage.cxx:1475
tools::Long GetHeight() const
Definition: svdpage.cxx:1506
tools::Long GetWidth() const
Definition: svdpage.cxx:1480
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 SdrPageView * TryToGetSdrPageView() const
access to SdrPageView. May return 0L like the default implementations do. Override as needed.
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 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 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