fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / svx / source / svdraw / sdrpagewindow.cxx
blobf62a81ab95e5aa3cc2b2388eea9260454fe93dfc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <svx/sdrpagewindow.hxx>
21 #include <com/sun/star/awt/XWindow.hpp>
22 #include <com/sun/star/beans/XPropertySet.hpp>
23 #include <com/sun/star/awt/PosSize.hpp>
24 #include <com/sun/star/util/XModeChangeBroadcaster.hpp>
25 #include <comphelper/processfactory.hxx>
26 #include <comphelper/random.hxx>
27 #include <vcl/svapp.hxx>
28 #include <toolkit/helper/vclunohelper.hxx>
29 #include <svx/svdouno.hxx>
30 #include <svx/svdpage.hxx>
31 #include <svx/svdview.hxx>
32 #include <svx/svdpagv.hxx>
33 #include <svx/sdrpaintwindow.hxx>
34 #include <sdr/contact/objectcontactofpageview.hxx>
35 #include <svx/sdr/contact/displayinfo.hxx>
36 #include <osl/mutex.hxx>
37 #include <svx/fmview.hxx>
38 #include <basegfx/matrix/b2dhommatrix.hxx>
42 using namespace ::com::sun::star;
44 struct SdrPageWindow::Impl
46 // #110094# ObjectContact section
47 mutable sdr::contact::ObjectContactOfPageView* mpObjectContact;
49 // the SdrPageView this window belongs to
50 SdrPageView& mrPageView;
52 // the PaintWindow to paint on. Here is access to OutDev etc.
53 // #i72752# change to pointer to allow patcing it in DrawLayer() if necessary
54 SdrPaintWindow* mpPaintWindow;
55 SdrPaintWindow* mpOriginalPaintWindow;
57 // UNO stuff for xControls
58 uno::Reference<awt::XControlContainer> mxControlContainer;
60 Impl( SdrPageView& rPageView, SdrPaintWindow& rPaintWindow ) :
61 mpObjectContact(NULL),
62 mrPageView(rPageView),
63 mpPaintWindow(&rPaintWindow),
64 mpOriginalPaintWindow(NULL)
68 ~Impl()
74 uno::Reference<awt::XControlContainer> SdrPageWindow::GetControlContainer( bool _bCreateIfNecessary ) const
76 if (!mpImpl->mxControlContainer.is() && _bCreateIfNecessary)
78 SdrView& rView = GetPageView().GetView();
80 const SdrPaintWindow& rPaintWindow( GetOriginalPaintWindow() ? *GetOriginalPaintWindow() : GetPaintWindow() );
81 if ( rPaintWindow.OutputToWindow() && !rView.IsPrintPreview() )
83 vcl::Window& rWindow = dynamic_cast< vcl::Window& >( rPaintWindow.GetOutputDevice() );
84 const_cast< SdrPageWindow* >( this )->mpImpl->mxControlContainer = VCLUnoHelper::CreateControlContainer( &rWindow );
86 // #100394# xC->setVisible triggers window->Show() and this has
87 // problems when the view is not completely constructed which may
88 // happen when loading. This leads to accessibility broadcasts which
89 // throw asserts due to the not finished view. All this chain can be avoided
90 // since xC->setVisible is here called only for the side effect in
91 // UnoControlContainer::setVisible(...) which calls createPeer(...).
92 // This will now be called directly from here.
94 uno::Reference< awt::XControl > xControl(mpImpl->mxControlContainer, uno::UNO_QUERY);
95 if(xControl.is())
97 uno::Reference< uno::XInterface > xContext = xControl->getContext();
98 if(!xContext.is())
100 xControl->createPeer( uno::Reference<awt::XToolkit>(), uno::Reference<awt::XWindowPeer>() );
104 else
106 // Printer and VirtualDevice, or rather: no OutDev
107 uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
108 const_cast< SdrPageWindow* >( this )->mpImpl->mxControlContainer = uno::Reference< awt::XControlContainer >(xFactory->createInstance("com.sun.star.awt.UnoControlContainer"), uno::UNO_QUERY);
109 uno::Reference< awt::XControlModel > xModel(xFactory->createInstance("com.sun.star.awt.UnoControlContainerModel"), uno::UNO_QUERY);
110 uno::Reference< awt::XControl > xControl(mpImpl->mxControlContainer, uno::UNO_QUERY);
111 if (xControl.is())
112 xControl->setModel(xModel);
114 OutputDevice& rOutDev = rPaintWindow.GetOutputDevice();
115 Point aPosPix = rOutDev.GetMapMode().GetOrigin();
116 Size aSizePix = rOutDev.GetOutputSizePixel();
118 uno::Reference< awt::XWindow > xContComp(mpImpl->mxControlContainer, uno::UNO_QUERY);
119 if( xContComp.is() )
120 xContComp->setPosSize(aPosPix.X(), aPosPix.Y(), aSizePix.Width(), aSizePix.Height(), awt::PosSize::POSSIZE);
123 FmFormView* pViewAsFormView = dynamic_cast< FmFormView* >( &rView );
124 if ( pViewAsFormView )
125 pViewAsFormView->InsertControlContainer(mpImpl->mxControlContainer);
127 return mpImpl->mxControlContainer;
130 SdrPageWindow::SdrPageWindow(SdrPageView& rPageView, SdrPaintWindow& rPaintWindow) :
131 mpImpl(new Impl(rPageView, rPaintWindow))
135 SdrPageWindow::~SdrPageWindow()
137 // #i26631#
138 ResetObjectContact();
140 if (mpImpl->mxControlContainer.is())
142 SdrView& rView = GetPageView().GetView();
144 // notify derived views
145 FmFormView* pViewAsFormView = dynamic_cast< FmFormView* >( &rView );
146 if ( pViewAsFormView )
147 pViewAsFormView->RemoveControlContainer(mpImpl->mxControlContainer);
149 // dispose the control container
150 uno::Reference< lang::XComponent > xComponent(mpImpl->mxControlContainer, uno::UNO_QUERY);
151 xComponent->dispose();
154 delete mpImpl;
157 SdrPageView& SdrPageWindow::GetPageView() const
159 return mpImpl->mrPageView;
162 SdrPaintWindow& SdrPageWindow::GetPaintWindow() const
164 return *mpImpl->mpPaintWindow;
167 const SdrPaintWindow* SdrPageWindow::GetOriginalPaintWindow() const
169 return mpImpl->mpOriginalPaintWindow;
172 // OVERLAY MANAGER
173 rtl::Reference< sdr::overlay::OverlayManager > SdrPageWindow::GetOverlayManager() const
175 return GetPaintWindow().GetOverlayManager();
178 void SdrPageWindow::patchPaintWindow(SdrPaintWindow& rPaintWindow)
180 mpImpl->mpOriginalPaintWindow = mpImpl->mpPaintWindow;
181 mpImpl->mpPaintWindow = &rPaintWindow;
184 void SdrPageWindow::unpatchPaintWindow()
186 DBG_ASSERT(mpImpl->mpOriginalPaintWindow, "SdrPageWindow::unpatchPaintWindow: paint window not patched!" );
187 if (mpImpl->mpOriginalPaintWindow)
189 mpImpl->mpPaintWindow = mpImpl->mpOriginalPaintWindow;
190 mpImpl->mpOriginalPaintWindow = NULL;
194 void SdrPageWindow::PrePaint()
196 // give OC the chance to do ProcessDisplay preparations
197 if(HasObjectContact())
199 GetObjectContact().PrepareProcessDisplay();
203 void SdrPageWindow::PrepareRedraw(const vcl::Region& rReg)
205 // give OC the chance to do ProcessDisplay preparations
206 if(HasObjectContact())
208 GetObjectContact().PrepareProcessDisplay();
211 // if necessary, remember changed RedrawArea at PaintWindow for usage with
212 // overlay and PreRenderDevice stuff
213 GetPaintWindow().SetRedrawRegion(rReg);
217 // clip test
218 #ifdef CLIPPER_TEST
219 #include <svx/svdopath.hxx>
220 #include <basegfx/polygon/b2dpolygon.hxx>
221 #include <tools/helpers.hxx>
222 #include <basegfx/polygon/b2dpolygoncutandtouch.hxx>
223 #include <basegfx/polygon/b2dpolypolygontools.hxx>
224 #include <basegfx/polygon/b2dpolygontools.hxx>
225 #include <basegfx/polygon/b2dpolygonclipper.hxx>
227 // for ::std::sort
228 #include <algorithm>
230 namespace
232 void impPaintStrokePolygon(const basegfx::B2DPolygon& rCandidate, OutputDevice& rOutDev, Color aColor)
234 basegfx::B2DPolygon aCandidate(rCandidate);
236 if(aCandidate.areControlPointsUsed())
238 aCandidate = basegfx::tools::adaptiveSubdivideByAngle(rCandidate);
241 if(aCandidate.count())
243 const sal_uInt32 nLoopCount(aCandidate.isClosed() ? aCandidate.count() : aCandidate.count() - 1L);
244 rOutDev.SetFillColor();
245 rOutDev.SetLineColor(aColor);
247 for(sal_uInt32 a(0L); a < nLoopCount; a++)
249 const basegfx::B2DPoint aBStart(aCandidate.getB2DPoint(a));
250 const basegfx::B2DPoint aBEnd(aCandidate.getB2DPoint((a + 1) % aCandidate.count()));
251 const Point aStart(FRound(aBStart.getX()), FRound(aBStart.getY()));
252 const Point aEnd(FRound(aBEnd.getX()), FRound(aBEnd.getY()));
253 rOutDev.DrawLine(aStart, aEnd);
258 void impTryTest(const SdrPageView& rPageView, OutputDevice& rOutDev)
260 if(rPageView.GetPage() && rPageView.GetPage()->GetObjCount() >= 2L)
262 SdrPage* pPage = rPageView.GetPage();
263 SdrObject* pObjA = pPage->GetObj(0L);
265 if(pObjA && pObjA->ISA(SdrPathObj))
267 basegfx::B2DPolyPolygon aPolyA(((SdrPathObj*)pObjA)->GetPathPoly());
268 aPolyA = basegfx::tools::correctOrientations(aPolyA);
270 basegfx::B2DPolyPolygon aPolyB;
272 for(sal_uInt32 a(1L); a < rPageView.GetPage()->GetObjCount(); a++)
274 SdrObject* pObjB = pPage->GetObj(a);
276 if(pObjB && pObjB->ISA(SdrPathObj))
278 basegfx::B2DPolyPolygon aCandidate(((SdrPathObj*)pObjB)->GetPathPoly());
279 aCandidate = basegfx::tools::correctOrientations(aCandidate);
280 aPolyB.append(aCandidate);
284 if(aPolyA.count() && aPolyA.isClosed() && aPolyB.count())
286 // poly A is the clipregion, clip poly b against it. Algo depends on
287 // poly b being closed.
288 basegfx::B2DPolyPolygon aResult(basegfx::tools::clipPolyPolygonOnPolyPolygon(aPolyB, aPolyA));
290 for(sal_uInt32 a(0L); a < aResult.count(); a++)
292 int nR = comphelper::rng::uniform_int_distribution(0, 254);
293 int nG = comphelper::rng::uniform_int_distribution(0, 254);
294 int nB = comphelper::rng::uniform_int_distribution(0, 254);
295 Color aColor(nR, nG, nB);
296 impPaintStrokePolygon(aResult.getB2DPolygon(a), rOutDev, aColor);
302 } // end of anonymous namespace
303 #endif // CLIPPER_TEST
307 void SdrPageWindow::RedrawAll( sdr::contact::ViewObjectContactRedirector* pRedirector )
309 // set Redirector
310 GetObjectContact().SetViewObjectContactRedirector(pRedirector);
312 // set PaintingPageView
313 const SdrView& rView = mpImpl->mrPageView.GetView();
314 SdrModel& rModel = *(rView.GetModel());
316 // get to be processed layers
317 const bool bPrinter(GetPaintWindow().OutputToPrinter());
318 SetOfByte aProcessLayers = bPrinter ? mpImpl->mrPageView.GetPrintableLayers() : mpImpl->mrPageView.GetVisibleLayers();
320 // create PaintInfoRec; use Rectangle only temporarily
321 const vcl::Region& rRegion = GetPaintWindow().GetRedrawRegion();
323 // create processing data
324 sdr::contact::DisplayInfo aDisplayInfo;
326 // Draw all layers. do NOT draw form layer from CompleteRedraw, this is done separately
327 // as a single layer paint
328 const SdrLayerAdmin& rLayerAdmin = rModel.GetLayerAdmin();
329 const SdrLayerID nControlLayerId = rLayerAdmin.GetLayerID(rLayerAdmin.GetControlLayerName(), false);
330 aProcessLayers.Clear(nControlLayerId);
332 // still something to paint?
333 if(!aProcessLayers.IsEmpty())
335 aDisplayInfo.SetProcessLayers(aProcessLayers);
337 // Set region as redraw area
338 aDisplayInfo.SetRedrawArea(rRegion);
340 // Draw/Impress
341 aDisplayInfo.SetPageProcessingActive(rView.IsPagePaintingAllowed()); // #i72889#
343 // paint page
344 GetObjectContact().ProcessDisplay(aDisplayInfo);
347 // reset redirector
348 GetObjectContact().SetViewObjectContactRedirector(0L);
350 // LineClip test
351 #ifdef CLIPPER_TEST
352 if(true)
354 impTryTest(GetPageView(), GetPaintWindow().GetOutputDevice());
356 #endif // CLIPPER_TEST
359 void SdrPageWindow::RedrawLayer( const SdrLayerID* pId, sdr::contact::ViewObjectContactRedirector* pRedirector )
361 // set redirector
362 GetObjectContact().SetViewObjectContactRedirector(pRedirector);
364 // set PaintingPageView
365 const SdrView& rView = mpImpl->mrPageView.GetView();
366 SdrModel& rModel = *(rView.GetModel());
368 // get the layers to process
369 const bool bPrinter(GetPaintWindow().OutputToPrinter());
370 SetOfByte aProcessLayers = bPrinter ? mpImpl->mrPageView.GetPrintableLayers() : mpImpl->mrPageView.GetVisibleLayers();
372 // is the given layer visible at all?
373 if(aProcessLayers.IsSet(*pId))
375 // find out if we are painting the ControlLayer
376 const SdrLayerAdmin& rLayerAdmin = rModel.GetLayerAdmin();
377 const SdrLayerID nControlLayerId = rLayerAdmin.GetLayerID(rLayerAdmin.GetControlLayerName(), false);
378 const bool bControlLayerProcessingActive(nControlLayerId == *pId);
380 // create PaintInfoRec, use Rectangle only temporarily
381 const vcl::Region& rRegion = GetPaintWindow().GetRedrawRegion();
383 // create processing data
384 sdr::contact::DisplayInfo aDisplayInfo;
386 // is it the control layer? If Yes, set flag
387 aDisplayInfo.SetControlLayerProcessingActive(bControlLayerProcessingActive);
389 // Draw just the one given layer
390 aProcessLayers.ClearAll();
391 aProcessLayers.Set(*pId);
393 aDisplayInfo.SetProcessLayers(aProcessLayers);
395 // Set region as redraw area
396 aDisplayInfo.SetRedrawArea(rRegion);
398 // Writer or calc, coming from original RedrawOneLayer.
399 // #i72889# no page painting for layer painting
400 aDisplayInfo.SetPageProcessingActive(false);
402 // paint page
403 GetObjectContact().ProcessDisplay(aDisplayInfo);
406 // reset redirector
407 GetObjectContact().SetViewObjectContactRedirector(0L);
410 // Invalidate call, used from ObjectContact(OfPageView) in InvalidatePartOfView(...)
411 void SdrPageWindow::InvalidatePageWindow(const basegfx::B2DRange& rRange)
413 if(GetPageView().IsVisible() && GetPaintWindow().OutputToWindow())
415 const SvtOptionsDrawinglayer aDrawinglayerOpt;
416 vcl::Window& rWindow(static_cast< vcl::Window& >(GetPaintWindow().GetOutputDevice()));
417 basegfx::B2DRange aDiscreteRange(rRange);
418 aDiscreteRange.transform(rWindow.GetViewTransformation());
420 if(aDrawinglayerOpt.IsAntiAliasing())
422 // invalidate one discrete unit more under the assumption that AA
423 // needs one pixel more
424 aDiscreteRange.grow(1.0);
427 const Rectangle aVCLDiscreteRectangle(
428 static_cast<long>(floor(aDiscreteRange.getMinX())),
429 static_cast<long>(floor(aDiscreteRange.getMinY())),
430 static_cast<long>(ceil(aDiscreteRange.getMaxX())),
431 static_cast<long>(ceil(aDiscreteRange.getMaxY())));
432 const bool bWasMapModeEnabled(rWindow.IsMapModeEnabled());
434 rWindow.EnableMapMode(false);
435 rWindow.Invalidate(aVCLDiscreteRectangle, INVALIDATE_NOERASE);
436 rWindow.EnableMapMode(bWasMapModeEnabled);
440 // ObjectContact section
441 const sdr::contact::ObjectContact& SdrPageWindow::GetObjectContact() const
443 if (!mpImpl->mpObjectContact)
444 mpImpl->mpObjectContact = new sdr::contact::ObjectContactOfPageView(const_cast<SdrPageWindow&>(*this));
446 return *mpImpl->mpObjectContact;
449 sdr::contact::ObjectContact& SdrPageWindow::GetObjectContact()
451 if (!mpImpl->mpObjectContact)
452 mpImpl->mpObjectContact = new sdr::contact::ObjectContactOfPageView(*this);
454 return *mpImpl->mpObjectContact;
457 bool SdrPageWindow::HasObjectContact() const
459 return mpImpl->mpObjectContact != NULL;
462 // #i26631#
463 void SdrPageWindow::ResetObjectContact()
465 if (mpImpl->mpObjectContact)
467 delete mpImpl->mpObjectContact;
468 mpImpl->mpObjectContact = 0L;
472 void SdrPageWindow::SetDesignMode( bool _bDesignMode ) const
474 const sdr::contact::ObjectContactOfPageView* pOC = dynamic_cast< const sdr::contact::ObjectContactOfPageView* >( &GetObjectContact() );
475 DBG_ASSERT( pOC, "SdrPageWindow::SetDesignMode: invalid object contact!" );
476 if ( pOC )
477 pOC->SetUNOControlsDesignMode( _bDesignMode );
480 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */