1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <svtools/colorcfg.hxx>
23 #include <svx/sdr/contact/viewobjectcontactofpageobj.hxx>
24 #include <svx/sdr/contact/viewcontactofpageobj.hxx>
25 #include <svx/svdopage.hxx>
26 #include <svx/sdr/contact/displayinfo.hxx>
27 #include <basegfx/polygon/b2dpolygontools.hxx>
28 #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
29 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
30 #include <svx/sdr/contact/objectcontactofobjlistpainter.hxx>
31 #include <basegfx/matrix/b2dhommatrix.hxx>
32 #include <svx/svdpage.hxx>
33 #include <svx/unoapi.hxx>
34 #include <drawinglayer/primitive2d/pagepreviewprimitive2d.hxx>
35 #include <drawinglayer/primitive2d/sdrdecompositiontools2d.hxx>
37 //////////////////////////////////////////////////////////////////////////////
39 using namespace com::sun::star
;
41 //////////////////////////////////////////////////////////////////////////////
47 class PagePrimitiveExtractor
: public ObjectContactOfPagePainter
, public Timer
50 // the ViewObjectContactOfPageObj using this painter
51 ViewObjectContactOfPageObj
& mrViewObjectContactOfPageObj
;
54 // basic constructor/destructor
55 explicit PagePrimitiveExtractor(ViewObjectContactOfPageObj
& rVOC
);
56 virtual ~PagePrimitiveExtractor();
58 // LazyInvalidate request. Supported here to not automatically
59 // invalidate the second interaction state all the time at the
61 virtual void setLazyInvalidate(ViewObjectContact
& rVOC
);
63 // From baseclass Timer, the timeout call triggered by te LazyInvalidate mechanism
64 virtual void Timeout();
66 // get primitive visualization
67 drawinglayer::primitive2d::Primitive2DSequence
createPrimitive2DSequenceForPage(const DisplayInfo
& rDisplayInfo
);
69 // Own reaction on changes which will be forwarded to the OC of the owner-VOC
70 virtual void InvalidatePartOfView(const basegfx::B2DRange
& rRange
) const;
72 // forward access to SdrPageView of ViewObjectContactOfPageObj
73 virtual bool isOutputToPrinter() const;
74 virtual bool isOutputToWindow() const;
75 virtual bool isOutputToVirtualDevice() const;
76 virtual bool isOutputToRecordingMetaFile() const;
77 virtual bool isOutputToPDFFile() const;
78 virtual bool isDrawModeGray() const;
79 virtual bool isDrawModeBlackWhite() const;
80 virtual bool isDrawModeHighContrast() const;
81 virtual SdrPageView
* TryToGetSdrPageView() const;
82 virtual OutputDevice
* TryToGetOutputDevice() const;
85 PagePrimitiveExtractor::PagePrimitiveExtractor(
86 ViewObjectContactOfPageObj
& rVOC
)
87 : ObjectContactOfPagePainter(0, rVOC
.GetObjectContact()),
88 mrViewObjectContactOfPageObj(rVOC
)
90 // make this renderer a preview renderer
91 setPreviewRenderer(true);
98 PagePrimitiveExtractor::~PagePrimitiveExtractor()
100 // execute missing LazyInvalidates and stop timer
104 void PagePrimitiveExtractor::setLazyInvalidate(ViewObjectContact
& /*rVOC*/)
106 // do NOT call parent, but remember that something is to do by
107 // starting the LazyInvalidateTimer
111 // From baseclass Timer, the timeout call triggered by te LazyInvalidate mechanism
112 void PagePrimitiveExtractor::Timeout()
117 // invalidate all LazyInvalidate VOCs new situations
118 const sal_uInt32
nVOCCount(getViewObjectContactCount());
120 for(sal_uInt32
a(0); a
< nVOCCount
; a
++)
122 ViewObjectContact
* pCandidate
= getViewObjectContact(a
);
123 pCandidate
->triggerLazyInvalidate();
127 drawinglayer::primitive2d::Primitive2DSequence
PagePrimitiveExtractor::createPrimitive2DSequenceForPage(const DisplayInfo
& /*rDisplayInfo*/)
129 drawinglayer::primitive2d::Primitive2DSequence xRetval
;
130 const SdrPage
* pStartPage
= GetStartPage();
134 // update own ViewInformation2D for visualized page
135 const drawinglayer::geometry::ViewInformation2D
& rOriginalViewInformation
= mrViewObjectContactOfPageObj
.GetObjectContact().getViewInformation2D();
136 const drawinglayer::geometry::ViewInformation2D
aNewViewInformation2D(
137 rOriginalViewInformation
.getObjectTransformation(),
138 rOriginalViewInformation
.getViewTransformation(),
140 // #i101075# use empty range for page content here to force
141 // the content not to be physically clipped in any way. This
142 // would be possible, but would require the internal transformation
143 // which maps between the page visualisation object and the page
144 // content, including the aspect ratios (for details see in
145 // PagePreviewPrimitive2D::create2DDecomposition)
148 GetXDrawPageForSdrPage(const_cast< SdrPage
* >(pStartPage
)),
149 0.0, // no time; page previews are not animated
150 rOriginalViewInformation
.getExtendedInformationSequence());
151 updateViewInformation2D(aNewViewInformation2D
);
153 // create copy of DisplayInfo to set PagePainting
154 DisplayInfo aDisplayInfo
;
157 ViewObjectContact
& rDrawPageVOContact
= pStartPage
->GetViewContact().GetViewObjectContact(*this);
159 // get whole Primitive2DSequence
160 xRetval
= rDrawPageVOContact
.getPrimitive2DSequenceHierarchy(aDisplayInfo
);
166 void PagePrimitiveExtractor::InvalidatePartOfView(const basegfx::B2DRange
& rRange
) const
168 // an invalidate is called at this view, this needs to be translated to an invalidate
169 // for the using VOC. Coordinates are in page coordinate system.
170 const SdrPage
* pStartPage
= GetStartPage();
172 if(pStartPage
&& !rRange
.isEmpty())
174 const basegfx::B2DRange
aPageRange(0.0, 0.0, (double)pStartPage
->GetWdt(), (double)pStartPage
->GetHgt());
176 if(rRange
.overlaps(aPageRange
))
178 // if object on the page is inside or overlapping with page, create ActionChanged() for
180 mrViewObjectContactOfPageObj
.ActionChanged();
185 // forward access to SdrPageView to VOCOfPageObj
186 bool PagePrimitiveExtractor::isOutputToPrinter() const { return mrViewObjectContactOfPageObj
.GetObjectContact().isOutputToPrinter(); }
187 bool PagePrimitiveExtractor::isOutputToWindow() const { return mrViewObjectContactOfPageObj
.GetObjectContact().isOutputToWindow(); }
188 bool PagePrimitiveExtractor::isOutputToVirtualDevice() const { return mrViewObjectContactOfPageObj
.GetObjectContact().isOutputToVirtualDevice(); }
189 bool PagePrimitiveExtractor::isOutputToRecordingMetaFile() const { return mrViewObjectContactOfPageObj
.GetObjectContact().isOutputToRecordingMetaFile(); }
190 bool PagePrimitiveExtractor::isOutputToPDFFile() const { return mrViewObjectContactOfPageObj
.GetObjectContact().isOutputToPDFFile(); }
191 bool PagePrimitiveExtractor::isDrawModeGray() const { return mrViewObjectContactOfPageObj
.GetObjectContact().isDrawModeGray(); }
192 bool PagePrimitiveExtractor::isDrawModeBlackWhite() const { return mrViewObjectContactOfPageObj
.GetObjectContact().isDrawModeBlackWhite(); }
193 bool PagePrimitiveExtractor::isDrawModeHighContrast() const { return mrViewObjectContactOfPageObj
.GetObjectContact().isDrawModeHighContrast(); }
194 SdrPageView
* PagePrimitiveExtractor::TryToGetSdrPageView() const { return mrViewObjectContactOfPageObj
.GetObjectContact().TryToGetSdrPageView(); }
195 OutputDevice
* PagePrimitiveExtractor::TryToGetOutputDevice() const { return mrViewObjectContactOfPageObj
.GetObjectContact().TryToGetOutputDevice(); }
196 } // end of namespace contact
197 } // end of namespace sdr
199 //////////////////////////////////////////////////////////////////////////////
205 drawinglayer::primitive2d::Primitive2DSequence
ViewObjectContactOfPageObj::createPrimitive2DSequence(const DisplayInfo
& rDisplayInfo
) const
207 drawinglayer::primitive2d::Primitive2DSequence xRetval
;
208 const SdrPageObj
& rPageObject((static_cast< ViewContactOfPageObj
& >(GetViewContact())).GetPageObj());
209 const SdrPage
* pPage
= rPageObject
.GetReferencedPage();
210 const svtools::ColorConfig aColorConfig
;
212 // get PageObject's geometry
213 basegfx::B2DHomMatrix aPageObjectTransform
;
215 const Rectangle
aPageObjectModelData(rPageObject
.GetLastBoundRect());
216 const basegfx::B2DRange
aPageObjectBound(
217 aPageObjectModelData
.Left(), aPageObjectModelData
.Top(),
218 aPageObjectModelData
.Right(), aPageObjectModelData
.Bottom());
220 aPageObjectTransform
.set(0, 0, aPageObjectBound
.getWidth());
221 aPageObjectTransform
.set(1, 1, aPageObjectBound
.getHeight());
222 aPageObjectTransform
.set(0, 2, aPageObjectBound
.getMinX());
223 aPageObjectTransform
.set(1, 2, aPageObjectBound
.getMinY());
226 // #i102637# add gray frame also when printing and page exists (handout pages)
227 const bool bCreateGrayFrame(!GetObjectContact().isOutputToPrinter() || pPage
);
229 // get displayed page's content. This is the uscaled page content
230 if(mpExtractor
&& pPage
)
232 // get displayed page's geometry
233 drawinglayer::primitive2d::Primitive2DSequence xPageContent
;
234 const Size
aPageSize(pPage
->GetSize());
235 const double fPageWidth(aPageSize
.getWidth());
236 const double fPageHeight(aPageSize
.getHeight());
238 // The case that a PageObject contains another PageObject which visualizes the
239 // same page again would lead to a recursion. Limit that recursion depth to one
240 // by using a local static bool
241 static bool bInCreatePrimitive2D(false);
243 if(bInCreatePrimitive2D
)
245 // Recursion is possible. Create a replacement primitive
246 xPageContent
.realloc(2);
247 const Color
aDocColor(aColorConfig
.GetColorValue(svtools::DOCCOLOR
).nColor
);
248 const Color
aBorderColor(aColorConfig
.GetColorValue(svtools::DOCBOUNDARIES
).nColor
);
249 const basegfx::B2DRange
aPageBound(0.0, 0.0, fPageWidth
, fPageHeight
);
250 const basegfx::B2DPolygon
aOutline(basegfx::tools::createPolygonFromRect(aPageBound
));
252 // add replacement fill
253 xPageContent
[0L] = drawinglayer::primitive2d::Primitive2DReference(
254 new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(basegfx::B2DPolyPolygon(aOutline
), aDocColor
.getBColor()));
256 // add replacement border
257 xPageContent
[1L] = drawinglayer::primitive2d::Primitive2DReference(
258 new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(aOutline
, aBorderColor
.getBColor()));
262 // set recursion flag
263 bInCreatePrimitive2D
= true;
265 // init extractor, guarantee existance, set page there
266 mpExtractor
->SetStartPage(pPage
);
268 // #i105548# also need to copy the VOCRedirector for sub-content creation
269 mpExtractor
->SetViewObjectContactRedirector(GetObjectContact().GetViewObjectContactRedirector());
271 // create page content
272 xPageContent
= mpExtractor
->createPrimitive2DSequenceForPage(rDisplayInfo
);
274 // #i105548# reset VOCRedirector to not accidentially have a pointer to a
275 // temporary class, so calls to it are avoided safely
276 mpExtractor
->SetViewObjectContactRedirector(0);
278 // reset recursion flag
279 bInCreatePrimitive2D
= false;
283 if(xPageContent
.hasElements())
285 const uno::Reference
< drawing::XDrawPage
> xDrawPage(GetXDrawPageForSdrPage(const_cast< SdrPage
*>(pPage
)));
286 const drawinglayer::primitive2d::Primitive2DReference
xPagePreview(new drawinglayer::primitive2d::PagePreviewPrimitive2D(
287 xDrawPage
, aPageObjectTransform
, fPageWidth
, fPageHeight
, xPageContent
, true));
288 xRetval
= drawinglayer::primitive2d::Primitive2DSequence(&xPagePreview
, 1);
291 else if(bCreateGrayFrame
)
293 // #i105146# no content, but frame display. To make hitting the page preview objects
294 // on the handout page more simple, add hidden fill geometry
295 const drawinglayer::primitive2d::Primitive2DReference
xFrameHit(
296 drawinglayer::primitive2d::createHiddenGeometryPrimitives2D(
298 aPageObjectTransform
));
299 xRetval
= drawinglayer::primitive2d::Primitive2DSequence(&xFrameHit
, 1);
302 // add a gray outline frame, except not when printing
305 const Color
aFrameColor(aColorConfig
.GetColorValue(svtools::OBJECTBOUNDARIES
).nColor
);
306 basegfx::B2DPolygon
aOwnOutline(basegfx::tools::createUnitPolygon());
307 aOwnOutline
.transform(aPageObjectTransform
);
309 const drawinglayer::primitive2d::Primitive2DReference
xGrayFrame(
310 new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(aOwnOutline
, aFrameColor
.getBColor()));
312 drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(xRetval
, xGrayFrame
);
318 ViewObjectContactOfPageObj::ViewObjectContactOfPageObj(ObjectContact
& rObjectContact
, ViewContact
& rViewContact
)
319 : ViewObjectContactOfSdrObj(rObjectContact
, rViewContact
),
320 mpExtractor(new PagePrimitiveExtractor(*this))
324 ViewObjectContactOfPageObj::~ViewObjectContactOfPageObj()
326 // delete the helper OC
329 // remember candidate and reset own pointer to avoid action when createPrimitive2DSequence()
330 // would be called for any reason
331 PagePrimitiveExtractor
* pCandidate
= mpExtractor
;
334 // also reset the StartPage to avoid ActionChanged() forwardings in the
335 // PagePrimitiveExtractor::InvalidatePartOfView() implementation
336 pCandidate
->SetStartPage(0);
340 } // end of namespace contact
341 } // end of namespace sdr
343 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */