LibreOffice Module svx (master)  1
sdrpagewindow.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 <svx/sdrpagewindow.hxx>
21 #include <com/sun/star/awt/XWindow.hpp>
22 #include <com/sun/star/awt/PosSize.hpp>
23 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
24 #include <comphelper/lok.hxx>
27 #include <svx/svdview.hxx>
28 #include <svx/svdpagv.hxx>
29 #include <svx/sdrpaintwindow.hxx>
32 #include <svx/fmview.hxx>
33 #include <sfx2/lokhelper.hxx>
34 #include <tools/debug.hxx>
35 
36 using namespace ::com::sun::star;
37 
39 {
40  // #110094# ObjectContact section
42 
43  // the SdrPageView this window belongs to
45 
46  // the PaintWindow to paint on. Here is access to OutDev etc.
47  // #i72752# change to pointer to allow patcing it in DrawLayer() if necessary
50 
51  // UNO stuff for xControls
52  uno::Reference<awt::XControlContainer> mxControlContainer;
53 
54  Impl( SdrPageView& rPageView, SdrPaintWindow& rPaintWindow ) :
55  mpObjectContact(nullptr),
56  mrPageView(rPageView),
57  mpPaintWindow(&rPaintWindow),
58  mpOriginalPaintWindow(nullptr)
59  {
60  }
61 };
62 
63 
64 uno::Reference<awt::XControlContainer> const & SdrPageWindow::GetControlContainer( bool _bCreateIfNecessary ) const
65 {
66  if (!mpImpl->mxControlContainer.is() && _bCreateIfNecessary)
67  {
68  SdrView& rView = GetPageView().GetView();
69 
71  if ( rPaintWindow.OutputToWindow() && !rView.IsPrintPreview() )
72  {
73  vcl::Window& rWindow = dynamic_cast< vcl::Window& >( rPaintWindow.GetOutputDevice() );
74  const_cast< SdrPageWindow* >( this )->mpImpl->mxControlContainer = VCLUnoHelper::CreateControlContainer( &rWindow );
75 
76  // #100394# xC->setVisible triggers window->Show() and this has
77  // problems when the view is not completely constructed which may
78  // happen when loading. This leads to accessibility broadcasts which
79  // throw asserts due to the not finished view. All this chain can be avoided
80  // since xC->setVisible is here called only for the side effect in
81  // UnoControlContainer::setVisible(...) which calls createPeer(...).
82  // This will now be called directly from here.
83 
84  uno::Reference< awt::XControl > xControl(mpImpl->mxControlContainer, uno::UNO_QUERY);
85  if(xControl.is())
86  {
87  uno::Reference< uno::XInterface > xContext = xControl->getContext();
88  if(!xContext.is())
89  {
90  xControl->createPeer( uno::Reference<awt::XToolkit>(), uno::Reference<awt::XWindowPeer>() );
91  }
92  }
93  }
94  else
95  {
96  // Printer and VirtualDevice, or rather: no OutDev
97  uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
98  const_cast< SdrPageWindow* >( this )->mpImpl->mxControlContainer.set(xFactory->createInstance("com.sun.star.awt.UnoControlContainer"), uno::UNO_QUERY);
99  uno::Reference< awt::XControlModel > xModel(xFactory->createInstance("com.sun.star.awt.UnoControlContainerModel"), uno::UNO_QUERY);
100  uno::Reference< awt::XControl > xControl(mpImpl->mxControlContainer, uno::UNO_QUERY);
101  if (xControl.is())
102  xControl->setModel(xModel);
103 
104  OutputDevice& rOutDev = rPaintWindow.GetOutputDevice();
105  Point aPosPix = rOutDev.GetMapMode().GetOrigin();
106  Size aSizePix = rOutDev.GetOutputSizePixel();
107 
108  uno::Reference< awt::XWindow > xContComp(mpImpl->mxControlContainer, uno::UNO_QUERY);
109  if( xContComp.is() )
110  xContComp->setPosSize(aPosPix.X(), aPosPix.Y(), aSizePix.Width(), aSizePix.Height(), awt::PosSize::POSSIZE);
111  }
112 
113  FmFormView* pViewAsFormView = dynamic_cast< FmFormView* >( &rView );
114  if ( pViewAsFormView )
115  pViewAsFormView->InsertControlContainer(mpImpl->mxControlContainer);
116  }
117  return mpImpl->mxControlContainer;
118 }
119 
121  mpImpl(new Impl(rPageView, rPaintWindow))
122 {
123 }
124 
126 {
127  // #i26631#
129 
130  if (mpImpl->mxControlContainer.is())
131  {
132  auto & rView = static_cast<SdrPaintView &>(GetPageView().GetView());
133 
134  // notify derived views
135  FmFormView* pViewAsFormView = dynamic_cast< FmFormView* >( &rView );
136  if ( pViewAsFormView )
137  pViewAsFormView->RemoveControlContainer(mpImpl->mxControlContainer);
138 
139  // dispose the control container
140  uno::Reference< lang::XComponent > xComponent(mpImpl->mxControlContainer, uno::UNO_QUERY);
141  xComponent->dispose();
142  }
143 }
144 
146 {
147  return mpImpl->mrPageView;
148 }
149 
151 {
152  return *mpImpl->mpPaintWindow;
153 }
154 
156 {
157  return mpImpl->mpOriginalPaintWindow;
158 }
159 
160 // OVERLAY MANAGER
162 {
164 }
165 
167 {
168  mpImpl->mpOriginalPaintWindow = mpImpl->mpPaintWindow;
169  mpImpl->mpPaintWindow = &rPaintWindow;
170  mpImpl->mpOriginalPaintWindow->setPatched(&rPaintWindow);
171 }
172 
174 {
175  DBG_ASSERT(mpImpl->mpOriginalPaintWindow, "SdrPageWindow::unpatchPaintWindow: paint window not patched!" );
176  if (mpImpl->mpOriginalPaintWindow)
177  {
178  mpImpl->mpPaintWindow = mpImpl->mpOriginalPaintWindow;
179  mpImpl->mpOriginalPaintWindow->setPatched(nullptr);
180  mpImpl->mpOriginalPaintWindow = nullptr;
181  }
182 }
183 
185 {
186  // give OC the chance to do ProcessDisplay preparations
187  if(HasObjectContact())
188  {
190  }
191 }
192 
194 {
195  // give OC the chance to do ProcessDisplay preparations
196  if(HasObjectContact())
197  {
199  }
200 
201  // if necessary, remember changed RedrawArea at PaintWindow for usage with
202  // overlay and PreRenderDevice stuff
204 }
205 
206 
207 // clip test
208 #ifdef CLIPPER_TEST
209 #include <svx/svdopath.hxx>
211 #include <tools/helpers.hxx>
216 
217 // for ::std::sort
218 #include <algorithm>
219 
220 namespace
221 {
222  void impPaintStrokePolygon(const basegfx::B2DPolygon& rCandidate, OutputDevice& rOutDev, Color aColor)
223  {
224  basegfx::B2DPolygon aCandidate(rCandidate);
225 
226  if(aCandidate.areControlPointsUsed())
227  {
228  aCandidate = basegfx::utils::adaptiveSubdivideByAngle(rCandidate);
229  }
230 
231  if(aCandidate.count())
232  {
233  const sal_uInt32 nLoopCount(aCandidate.isClosed() ? aCandidate.count() : aCandidate.count() - 1);
234  rOutDev.SetFillColor();
235  rOutDev.SetLineColor(aColor);
236 
237  for(sal_uInt32 a(0); a < nLoopCount; a++)
238  {
239  const basegfx::B2DPoint aBStart(aCandidate.getB2DPoint(a));
240  const basegfx::B2DPoint aBEnd(aCandidate.getB2DPoint((a + 1) % aCandidate.count()));
241  const Point aStart(FRound(aBStart.getX()), FRound(aBStart.getY()));
242  const Point aEnd(FRound(aBEnd.getX()), FRound(aBEnd.getY()));
243  rOutDev.DrawLine(aStart, aEnd);
244  }
245  }
246  }
247 
248  void impTryTest(const SdrPageView& rPageView, OutputDevice& rOutDev)
249  {
250  if(rPageView.GetPage() && rPageView.GetPage()->GetObjCount() >= 2)
251  {
252  SdrPage* pPage = rPageView.GetPage();
253  SdrObject* pObjA = pPage->GetObj(0);
254 
255  if(dynamic_cast<const SdrPathObj*>( pObjA))
256  {
257  basegfx::B2DPolyPolygon aPolyA(pObjA->GetPathPoly());
258  aPolyA = basegfx::utils::correctOrientations(aPolyA);
259 
261 
262  for(sal_uInt32 a(1); a < rPageView.GetPage()->GetObjCount(); a++)
263  {
264  SdrObject* pObjB = pPage->GetObj(a);
265 
266  if(dynamic_cast<const SdrPathObj*>( pObjB))
267  {
268  basegfx::B2DPolyPolygon aCandidate(pObjB->GetPathPoly());
269  aCandidate = basegfx::utils::correctOrientations(aCandidate);
270  aPolyB.append(aCandidate);
271  }
272  }
273 
274  if(aPolyA.count() && aPolyA.isClosed() && aPolyB.count())
275  {
276  // poly A is the clipregion, clip poly b against it. Algo depends on
277  // poly b being closed.
279 
280  for(auto const& rPolygon : aResult)
281  {
285  Color aColor(nR, nG, nB);
286  impPaintStrokePolygon(rPolygon, rOutDev, aColor);
287  }
288  }
289  }
290  }
291  }
292 } // end of anonymous namespace
293 #endif // CLIPPER_TEST
294 
295 
297 {
298  // set Redirector
300 
301  // set PaintingPageView
302  const SdrView& rView = mpImpl->mrPageView.GetView();
303  SdrModel& rModel = *(rView.GetModel());
304 
305  // get to be processed layers
306  const bool bPrinter(GetPaintWindow().OutputToPrinter());
307  SdrLayerIDSet aProcessLayers = bPrinter ? mpImpl->mrPageView.GetPrintableLayers() : mpImpl->mrPageView.GetVisibleLayers();
308 
309  // create PaintInfoRec; use Rectangle only temporarily
310  const vcl::Region& rRegion = GetPaintWindow().GetRedrawRegion();
311 
312  // create processing data
313  sdr::contact::DisplayInfo aDisplayInfo;
314 
315  // Draw all layers. do NOT draw form layer from CompleteRedraw, this is done separately
316  // as a single layer paint
317  const SdrLayerAdmin& rLayerAdmin = rModel.GetLayerAdmin();
318  const SdrLayerID nControlLayerId = rLayerAdmin.GetLayerID(rLayerAdmin.GetControlLayerName());
319  aProcessLayers.Clear(nControlLayerId);
320 
321  // still something to paint?
322  if(!aProcessLayers.IsEmpty())
323  {
324  aDisplayInfo.SetProcessLayers(aProcessLayers);
325 
326  // Set region as redraw area
327  aDisplayInfo.SetRedrawArea(rRegion);
328 
329  // Draw/Impress
330  aDisplayInfo.SetPageProcessingActive(rView.IsPagePaintingAllowed()); // #i72889#
331 
332  // paint page
333  GetObjectContact().ProcessDisplay(aDisplayInfo);
334  }
335 
336  // reset redirector
338 
339  // LineClip test
340 #ifdef CLIPPER_TEST
341  if(true)
342  {
343  impTryTest(GetPageView(), GetPaintWindow().GetOutputDevice());
344  }
345 #endif // CLIPPER_TEST
346 }
347 
350  basegfx::B2IRectangle const*const pPageFrame)
351 {
352  // set redirector
354 
355  // set PaintingPageView
356  const SdrView& rView = mpImpl->mrPageView.GetView();
357  SdrModel& rModel = *(rView.GetModel());
358 
359  // get the layers to process
360  const bool bPrinter(GetPaintWindow().OutputToPrinter());
361  SdrLayerIDSet aProcessLayers = bPrinter ? mpImpl->mrPageView.GetPrintableLayers() : mpImpl->mrPageView.GetVisibleLayers();
362 
363  // is the given layer visible at all?
364  if(aProcessLayers.IsSet(*pId))
365  {
366  // find out if we are painting the ControlLayer
367  const SdrLayerAdmin& rLayerAdmin = rModel.GetLayerAdmin();
368  const SdrLayerID nControlLayerId = rLayerAdmin.GetLayerID(rLayerAdmin.GetControlLayerName());
369  const bool bControlLayerProcessingActive(nControlLayerId == *pId);
370 
371  // create PaintInfoRec, use Rectangle only temporarily
372  const vcl::Region& rRegion = GetPaintWindow().GetRedrawRegion();
373 
374  // create processing data
375  sdr::contact::DisplayInfo aDisplayInfo;
376 
377  // is it the control layer? If Yes, set flag
378  aDisplayInfo.SetControlLayerProcessingActive(bControlLayerProcessingActive);
379 
380  // Draw just the one given layer
381  aProcessLayers.ClearAll();
382  aProcessLayers.Set(*pId);
383 
384  aDisplayInfo.SetProcessLayers(aProcessLayers);
385 
386  // Set region as redraw area
387  aDisplayInfo.SetRedrawArea(rRegion);
388 
389  // Writer or calc, coming from original RedrawOneLayer.
390  // #i72889# no page painting for layer painting
391  aDisplayInfo.SetPageProcessingActive(false);
392 
393  if (pPageFrame) // Writer page frame for anchor based clipping
394  {
395  aDisplayInfo.SetWriterPageFrame(*pPageFrame);
396  }
397 
398  // paint page
399  GetObjectContact().ProcessDisplay(aDisplayInfo);
400  }
401 
402  // reset redirector
404 }
405 
406 // Invalidate call, used from ObjectContact(OfPageView) in InvalidatePartOfView(...)
408 {
409  if (GetPageView().IsVisible() && GetPaintWindow().OutputToWindow())
410  {
411  const SvtOptionsDrawinglayer aDrawinglayerOpt;
412  OutputDevice& rWindow(GetPaintWindow().GetOutputDevice());
413  basegfx::B2DRange aDiscreteRange(rRange);
414  aDiscreteRange.transform(rWindow.GetViewTransformation());
415 
416  if (aDrawinglayerOpt.IsAntiAliasing())
417  {
418  // invalidate one discrete unit more under the assumption that AA
419  // needs one pixel more
420  aDiscreteRange.grow(1.0);
421  }
422 
423  const tools::Rectangle aVCLDiscreteRectangle(
424  static_cast<long>(floor(aDiscreteRange.getMinX())),
425  static_cast<long>(floor(aDiscreteRange.getMinY())),
426  static_cast<long>(ceil(aDiscreteRange.getMaxX())),
427  static_cast<long>(ceil(aDiscreteRange.getMaxY())));
428 
429  const bool bWasMapModeEnabled(rWindow.IsMapModeEnabled());
430  rWindow.EnableMapMode(false);
431  GetPageView().GetView().InvalidateOneWin(rWindow, aVCLDiscreteRectangle);
432  rWindow.EnableMapMode(bWasMapModeEnabled);
433  }
435  {
436  // we don't really have to have a paint window with LOK; OTOH we know
437  // that the drawinglayer units are 100ths of mm, so they are easy to
438  // convert to twips
439  const tools::Rectangle aRect100thMM(
440  static_cast<long>(floor(rRange.getMinX())),
441  static_cast<long>(floor(rRange.getMinY())),
442  static_cast<long>(ceil(rRange.getMaxX())),
443  static_cast<long>(ceil(rRange.getMaxY())));
444 
445  const tools::Rectangle aRectTwips = OutputDevice::LogicToLogic(aRect100thMM, MapMode(MapUnit::Map100thMM), MapMode(MapUnit::MapTwip));
446 
447  if (SfxViewShell* pViewShell = SfxViewShell::Current())
448  SfxLokHelper::notifyInvalidation(pViewShell, aRectTwips.toString());
449  }
450 }
451 
452 // ObjectContact section
454 {
455  if (!mpImpl->mpObjectContact)
456  {
458  const_cast<SdrPageWindow&>(*this),
459  "svx::svdraw::SdrPageWindow mpObjectContact");
460  }
461 
462  return *mpImpl->mpObjectContact;
463 }
464 
466 {
467  if (!mpImpl->mpObjectContact)
468  {
470  *this,
471  "svx::svdraw::SdrPageWindow mpObjectContact" );
472  }
473 
474  return *mpImpl->mpObjectContact;
475 }
476 
478 {
479  return mpImpl->mpObjectContact != nullptr;
480 }
481 
482 // #i26631#
484 {
485  if (mpImpl->mpObjectContact)
486  {
487  delete mpImpl->mpObjectContact;
488  mpImpl->mpObjectContact = nullptr;
489  }
490 }
491 
492 void SdrPageWindow::SetDesignMode( bool _bDesignMode ) const
493 {
495  DBG_ASSERT( pOC, "SdrPageWindow::SetDesignMode: invalid object contact!" );
496  if ( pOC )
497  pOC->SetUNOControlsDesignMode( _bDesignMode );
498 }
499 
500 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
long Width() const
rtl::Reference< sdr::overlay::OverlayManager > const & GetOverlayManager() const
SdrPaintWindow * mpOriginalPaintWindow
void SetWriterPageFrame(basegfx::B2IRectangle const &rPageFrame)
Definition: displayinfo.cxx:47
void Set(SdrLayerID a)
Definition: svdsob.hxx:48
const SdrPaintWindow * GetOriginalPaintWindow() const
virtual void PrepareProcessDisplay()
uno::Reference< awt::XControlContainer > mxControlContainer
long FRound(double fVal)
rtl::Reference< sdr::overlay::OverlayManager > const & GetOverlayManager() const
Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
long Height() const
SdrView & GetView()
Definition: svdpagv.hxx:135
void unpatchPaintWindow()
bool IsMapModeEnabled() const
SdrObject * GetObj(size_t nNum) const
Definition: svdpage.cxx:758
css::uno::Reference< css::awt::XControlContainer > const & GetControlContainer(bool _bCreateIfNecessary=true) const
size_t GetObjCount() const
Definition: svdpage.cxx:752
sdr::contact::ObjectContact * mpObjectContact
bool IsEmpty() const
Definition: svdlayer.cxx:25
const MapMode & GetMapMode() const
void SetControlLayerProcessingActive(bool bDoPaint)
Definition: displayinfo.cxx:52
static css::uno::Reference< css::awt::XControlContainer > CreateControlContainer(vcl::Window *pWindow)
void EnableMapMode(bool bEnable=true)
double getMaxX() const
B2DPolyPolygon clipPolyPolygonOnPolyPolygon(const B2DPolyPolygon &rCandidate, const B2DPolyPolygon &rClip, bool bInside, bool bStroke)
void SetRedrawRegion(const vcl::Region &rNew)
void RedrawLayer(const SdrLayerID *pId, sdr::contact::ViewObjectContactRedirector *pRedirector, basegfx::B2IRectangle const *)
void SetProcessLayers(const SdrLayerIDSet &rSet)
Definition: displayinfo.cxx:36
static void notifyInvalidation(SfxViewShell const *pThisView, const OString &rPayload)
void RemoveControlContainer(const css::uno::Reference< css::awt::XControlContainer > &xCC)
Definition: fmview.cxx:427
void SetPageProcessingActive(bool bDoPaint)
Definition: displayinfo.cxx:60
BASEGFX_DLLPUBLIC void transform(const B2DHomMatrix &rMatrix)
bool OutputToWindow() const
bool IsPagePaintingAllowed() const
Definition: svdpntv.hxx:213
static SfxViewShell * Current()
void InsertControlContainer(const css::uno::Reference< css::awt::XControlContainer > &xCC)
Definition: fmview.cxx:405
double getMaxY() const
void SetUNOControlsDesignMode(bool _bDesignMode) const
sets all UNO controls which are associated with this ObjectContact to design or alive mode...
void DrawLine(const Point &rStartPt, const Point &rEndPt)
css::uno::Reference< css::lang::XComponent > xComponent
void ResetObjectContact()
void grow(double fValue)
void SetLineColor()
SdrPageView & mrPageView
const OUString & GetControlLayerName() const
Definition: svdlayer.hxx:151
#define DBG_ASSERT(sCon, aError)
uno_Any a
Impl(SdrPageView &rPageView, SdrPaintWindow &rPaintWindow)
void SetFillColor()
void SetRedrawArea(const vcl::Region &rRegion)
Definition: displayinfo.cxx:42
const vcl::Region & GetRedrawRegion() const
void SetViewObjectContactRedirector(ViewObjectContactRedirector *pNew)
Size GetOutputSizePixel() const
const sdr::contact::ObjectContact & GetObjectContact() const
Abstract DrawObject.
Definition: svdobj.hxx:312
void RedrawAll(sdr::contact::ViewObjectContactRedirector *pRedirector)
void PrepareRedraw(const vcl::Region &rReg)
void patchPaintWindow(SdrPaintWindow &rPaintWindow)
virtual sdr::contact::ObjectContact * createViewSpecificObjectContact(SdrPageWindow &rPageWindow, const char *pDebugName) const
Definition: svdview.cxx:1453
void append(const B2DPolygon &rPolygon, sal_uInt32 nCount=1)
bool IsSet(SdrLayerID a) const
Definition: svdsob.hxx:66
Reference< XMultiServiceFactory > getProcessServiceFactory()
double getMinY() const
sal_uInt32 count() const
SdrPageWindow(const SdrPageWindow &)=delete
B2DPolygon adaptiveSubdivideByAngle(const B2DPolygon &rCandidate, double fAngleBound)
SdrPage * GetPage() const
Definition: svdpagv.hxx:171
bool HasObjectContact() const
determines whether there already exists an ObjectContact
int uniform_int_distribution(int a, int b)
SdrPaintWindow * mpPaintWindow
SdrPaintWindow & GetPaintWindow() const
void InvalidatePageWindow(const basegfx::B2DRange &rRange)
std::unique_ptr< Impl > mpImpl
virtual void ProcessDisplay(DisplayInfo &rDisplayInfo)
bool IsPrintPreview() const
Definition: svdpntv.hxx:497
const Point & GetOrigin() const
bool IsAntiAliasing() const
Reference< XSingleServiceFactory > xFactory
Reference< XModel > xModel
double getMinX() const
void ClearAll()
Definition: svdsob.hxx:76
A SdrPage contains exactly one SdrObjList and a description of the physical page dimensions (size / m...
Definition: svdpage.hxx:365
B2DPolyPolygon correctOrientations(const B2DPolyPolygon &rCandidate)
const SdrLayerAdmin & GetLayerAdmin() const
Definition: svdmodel.hxx:311
virtual void InvalidateOneWin(OutputDevice &rWin)
If the View should not call Invalidate() on the windows, override the following 2 methods and do some...
Definition: svdpntv.cxx:862
void Clear(SdrLayerID a)
Definition: svdsob.hxx:53
SdrLayerID GetLayerID(const OUString &rName) const
Definition: svdlayer.cxx:228
basegfx::B2DHomMatrix GetViewTransformation() const
SdrModel * GetModel() const
Definition: svdpntv.hxx:271
OutputDevice & GetOutputDevice() const
void SetDesignMode(bool _bDesignMode) const
sets all elements in the view which support a design and an alive mode into the given mode ...
SdrPageView & GetPageView() const