Line data Source code
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/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>
39 :
40 :
41 :
42 : using namespace ::com::sun::star;
43 :
44 : struct SdrPageWindow::Impl
45 : {
46 : // #110094# ObjectContact section
47 : mutable sdr::contact::ObjectContactOfPageView* mpObjectContact;
48 :
49 : // the SdrPageView this window belongs to
50 : SdrPageView& mrPageView;
51 :
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;
56 :
57 : // UNO stuff for xControls
58 : uno::Reference<awt::XControlContainer> mxControlContainer;
59 :
60 5481 : Impl( SdrPageView& rPageView, SdrPaintWindow& rPaintWindow ) :
61 : mpObjectContact(NULL),
62 : mrPageView(rPageView),
63 : mpPaintWindow(&rPaintWindow),
64 5481 : mpOriginalPaintWindow(NULL)
65 : {
66 5481 : }
67 :
68 5459 : ~Impl()
69 5459 : {
70 5459 : }
71 : };
72 :
73 :
74 3637 : uno::Reference<awt::XControlContainer> SdrPageWindow::GetControlContainer( bool _bCreateIfNecessary ) const
75 : {
76 3637 : if (!mpImpl->mxControlContainer.is() && _bCreateIfNecessary)
77 : {
78 1100 : SdrView& rView = GetPageView().GetView();
79 :
80 1100 : const SdrPaintWindow& rPaintWindow( GetOriginalPaintWindow() ? *GetOriginalPaintWindow() : GetPaintWindow() );
81 1100 : if ( rPaintWindow.OutputToWindow() && !rView.IsPrintPreview() )
82 : {
83 1025 : vcl::Window& rWindow = dynamic_cast< vcl::Window& >( rPaintWindow.GetOutputDevice() );
84 1025 : const_cast< SdrPageWindow* >( this )->mpImpl->mxControlContainer = VCLUnoHelper::CreateControlContainer( &rWindow );
85 :
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.
93 :
94 1025 : uno::Reference< awt::XControl > xControl(mpImpl->mxControlContainer, uno::UNO_QUERY);
95 1025 : if(xControl.is())
96 : {
97 1025 : uno::Reference< uno::XInterface > xContext = xControl->getContext();
98 1025 : if(!xContext.is())
99 : {
100 1025 : xControl->createPeer( uno::Reference<awt::XToolkit>(), uno::Reference<awt::XWindowPeer>() );
101 1025 : }
102 1025 : }
103 : }
104 : else
105 : {
106 : // Printer and VirtualDevice, or rather: no OutDev
107 75 : uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
108 75 : const_cast< SdrPageWindow* >( this )->mpImpl->mxControlContainer = uno::Reference< awt::XControlContainer >(xFactory->createInstance("com.sun.star.awt.UnoControlContainer"), uno::UNO_QUERY);
109 150 : uno::Reference< awt::XControlModel > xModel(xFactory->createInstance("com.sun.star.awt.UnoControlContainerModel"), uno::UNO_QUERY);
110 150 : uno::Reference< awt::XControl > xControl(mpImpl->mxControlContainer, uno::UNO_QUERY);
111 75 : if (xControl.is())
112 75 : xControl->setModel(xModel);
113 :
114 75 : OutputDevice& rOutDev = rPaintWindow.GetOutputDevice();
115 75 : Point aPosPix = rOutDev.GetMapMode().GetOrigin();
116 75 : Size aSizePix = rOutDev.GetOutputSizePixel();
117 :
118 150 : uno::Reference< awt::XWindow > xContComp(mpImpl->mxControlContainer, uno::UNO_QUERY);
119 75 : if( xContComp.is() )
120 150 : xContComp->setPosSize(aPosPix.X(), aPosPix.Y(), aSizePix.Width(), aSizePix.Height(), awt::PosSize::POSSIZE);
121 : }
122 :
123 1100 : FmFormView* pViewAsFormView = dynamic_cast< FmFormView* >( &rView );
124 1100 : if ( pViewAsFormView )
125 1100 : pViewAsFormView->InsertControlContainer(mpImpl->mxControlContainer);
126 : }
127 3637 : return mpImpl->mxControlContainer;
128 : }
129 :
130 5481 : SdrPageWindow::SdrPageWindow(SdrPageView& rPageView, SdrPaintWindow& rPaintWindow) :
131 5481 : mpImpl(new Impl(rPageView, rPaintWindow))
132 : {
133 5481 : }
134 :
135 5459 : SdrPageWindow::~SdrPageWindow()
136 : {
137 : // #i26631#
138 5459 : ResetObjectContact();
139 :
140 5459 : if (mpImpl->mxControlContainer.is())
141 : {
142 1099 : SdrView& rView = GetPageView().GetView();
143 :
144 : // notify derived views
145 1099 : FmFormView* pViewAsFormView = dynamic_cast< FmFormView* >( &rView );
146 1099 : if ( pViewAsFormView )
147 1099 : pViewAsFormView->RemoveControlContainer(mpImpl->mxControlContainer);
148 :
149 : // dispose the control container
150 1099 : uno::Reference< lang::XComponent > xComponent(mpImpl->mxControlContainer, uno::UNO_QUERY);
151 1099 : xComponent->dispose();
152 : }
153 :
154 5459 : delete mpImpl;
155 5459 : }
156 :
157 581565 : SdrPageView& SdrPageWindow::GetPageView() const
158 : {
159 581565 : return mpImpl->mrPageView;
160 : }
161 :
162 795922 : SdrPaintWindow& SdrPageWindow::GetPaintWindow() const
163 : {
164 795922 : return *mpImpl->mpPaintWindow;
165 : }
166 :
167 10082 : const SdrPaintWindow* SdrPageWindow::GetOriginalPaintWindow() const
168 : {
169 10082 : return mpImpl->mpOriginalPaintWindow;
170 : }
171 :
172 : // OVERLAY MANAGER
173 5987 : rtl::Reference< sdr::overlay::OverlayManager > SdrPageWindow::GetOverlayManager() const
174 : {
175 5987 : return GetPaintWindow().GetOverlayManager();
176 : }
177 :
178 37547 : void SdrPageWindow::patchPaintWindow(SdrPaintWindow& rPaintWindow)
179 : {
180 37547 : mpImpl->mpOriginalPaintWindow = mpImpl->mpPaintWindow;
181 37547 : mpImpl->mpPaintWindow = &rPaintWindow;
182 37547 : }
183 :
184 37547 : void SdrPageWindow::unpatchPaintWindow()
185 : {
186 : DBG_ASSERT(mpImpl->mpOriginalPaintWindow, "SdrPageWindow::unpatchPaintWindow: paint window not patched!" );
187 37547 : if (mpImpl->mpOriginalPaintWindow)
188 : {
189 37547 : mpImpl->mpPaintWindow = mpImpl->mpOriginalPaintWindow;
190 37547 : mpImpl->mpOriginalPaintWindow = NULL;
191 : }
192 37547 : }
193 :
194 34757 : void SdrPageWindow::PrePaint()
195 : {
196 : // give OC the chance to do ProcessDisplay preparations
197 34757 : if(HasObjectContact())
198 : {
199 14043 : GetObjectContact().PrepareProcessDisplay();
200 : }
201 34757 : }
202 :
203 14341 : void SdrPageWindow::PrepareRedraw(const vcl::Region& rReg)
204 : {
205 : // give OC the chance to do ProcessDisplay preparations
206 14341 : if(HasObjectContact())
207 : {
208 11783 : GetObjectContact().PrepareProcessDisplay();
209 : }
210 :
211 : // if necessary, remember changed RedrawArea at PaintWindow for usage with
212 : // overlay and PreRenderDevice stuff
213 14341 : GetPaintWindow().SetRedrawRegion(rReg);
214 14341 : }
215 :
216 :
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>
226 :
227 : // for ::std::sort
228 : #include <algorithm>
229 :
230 : namespace
231 : {
232 : void impPaintStrokePolygon(const basegfx::B2DPolygon& rCandidate, OutputDevice& rOutDev, Color aColor)
233 : {
234 : basegfx::B2DPolygon aCandidate(rCandidate);
235 :
236 : if(aCandidate.areControlPointsUsed())
237 : {
238 : aCandidate = basegfx::tools::adaptiveSubdivideByAngle(rCandidate);
239 : }
240 :
241 : if(aCandidate.count())
242 : {
243 : const sal_uInt32 nLoopCount(aCandidate.isClosed() ? aCandidate.count() : aCandidate.count() - 1L);
244 : rOutDev.SetFillColor();
245 : rOutDev.SetLineColor(aColor);
246 :
247 : for(sal_uInt32 a(0L); a < nLoopCount; a++)
248 : {
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);
254 : }
255 : }
256 : }
257 :
258 : void impTryTest(const SdrPageView& rPageView, OutputDevice& rOutDev)
259 : {
260 : if(rPageView.GetPage() && rPageView.GetPage()->GetObjCount() >= 2L)
261 : {
262 : SdrPage* pPage = rPageView.GetPage();
263 : SdrObject* pObjA = pPage->GetObj(0L);
264 :
265 : if(pObjA && pObjA->ISA(SdrPathObj))
266 : {
267 : basegfx::B2DPolyPolygon aPolyA(pObjA->GetPathPoly());
268 : aPolyA = basegfx::tools::correctOrientations(aPolyA);
269 :
270 : basegfx::B2DPolyPolygon aPolyB;
271 :
272 : for(sal_uInt32 a(1L); a < rPageView.GetPage()->GetObjCount(); a++)
273 : {
274 : SdrObject* pObjB = pPage->GetObj(a);
275 :
276 : if(pObjB && pObjB->ISA(SdrPathObj))
277 : {
278 : basegfx::B2DPolyPolygon aCandidate(pObjB->GetPathPoly());
279 : aCandidate = basegfx::tools::correctOrientations(aCandidate);
280 : aPolyB.append(aCandidate);
281 : }
282 : }
283 :
284 : if(aPolyA.count() && aPolyA.isClosed() && aPolyB.count())
285 : {
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));
289 :
290 : for(sal_uInt32 a(0L); a < aResult.count(); a++)
291 : {
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);
297 : }
298 : }
299 : }
300 : }
301 : }
302 : } // end of anonymous namespace
303 : #endif // CLIPPER_TEST
304 :
305 :
306 :
307 1902 : void SdrPageWindow::RedrawAll( sdr::contact::ViewObjectContactRedirector* pRedirector )
308 : {
309 : // set Redirector
310 1902 : GetObjectContact().SetViewObjectContactRedirector(pRedirector);
311 :
312 : // set PaintingPageView
313 1902 : const SdrView& rView = mpImpl->mrPageView.GetView();
314 1902 : SdrModel& rModel = *(rView.GetModel());
315 :
316 : // get to be processed layers
317 1902 : const bool bPrinter(GetPaintWindow().OutputToPrinter());
318 1902 : SetOfByte aProcessLayers = bPrinter ? mpImpl->mrPageView.GetPrintableLayers() : mpImpl->mrPageView.GetVisibleLayers();
319 :
320 : // create PaintInfoRec; use Rectangle only temporarily
321 1902 : const vcl::Region& rRegion = GetPaintWindow().GetRedrawRegion();
322 :
323 : // create processing data
324 1902 : sdr::contact::DisplayInfo aDisplayInfo;
325 :
326 : // Draw all layers. do NOT draw form layer from CompleteRedraw, this is done separately
327 : // as a single layer paint
328 1902 : const SdrLayerAdmin& rLayerAdmin = rModel.GetLayerAdmin();
329 1902 : const SdrLayerID nControlLayerId = rLayerAdmin.GetLayerID(rLayerAdmin.GetControlLayerName(), false);
330 1902 : aProcessLayers.Clear(nControlLayerId);
331 :
332 : // still something to paint?
333 1902 : if(!aProcessLayers.IsEmpty())
334 : {
335 1902 : aDisplayInfo.SetProcessLayers(aProcessLayers);
336 :
337 : // Set region as redraw area
338 1902 : aDisplayInfo.SetRedrawArea(rRegion);
339 :
340 : // Draw/Impress
341 1902 : aDisplayInfo.SetPageProcessingActive(rView.IsPagePaintingAllowed()); // #i72889#
342 :
343 : // paint page
344 1902 : GetObjectContact().ProcessDisplay(aDisplayInfo);
345 : }
346 :
347 : // reset redirector
348 1902 : GetObjectContact().SetViewObjectContactRedirector(0L);
349 :
350 : // LineClip test
351 : #ifdef CLIPPER_TEST
352 : if(true)
353 : {
354 : impTryTest(GetPageView(), GetPaintWindow().GetOutputDevice());
355 : }
356 : #endif // CLIPPER_TEST
357 1902 : }
358 :
359 38922 : void SdrPageWindow::RedrawLayer( const SdrLayerID* pId, sdr::contact::ViewObjectContactRedirector* pRedirector )
360 : {
361 : // set redirector
362 38922 : GetObjectContact().SetViewObjectContactRedirector(pRedirector);
363 :
364 : // set PaintingPageView
365 38922 : const SdrView& rView = mpImpl->mrPageView.GetView();
366 38922 : SdrModel& rModel = *(rView.GetModel());
367 :
368 : // get the layers to process
369 38922 : const bool bPrinter(GetPaintWindow().OutputToPrinter());
370 38922 : SetOfByte aProcessLayers = bPrinter ? mpImpl->mrPageView.GetPrintableLayers() : mpImpl->mrPageView.GetVisibleLayers();
371 :
372 : // is the given layer visible at all?
373 38922 : if(aProcessLayers.IsSet(*pId))
374 : {
375 : // find out if we are painting the ControlLayer
376 38922 : const SdrLayerAdmin& rLayerAdmin = rModel.GetLayerAdmin();
377 38922 : const SdrLayerID nControlLayerId = rLayerAdmin.GetLayerID(rLayerAdmin.GetControlLayerName(), false);
378 38922 : const bool bControlLayerProcessingActive(nControlLayerId == *pId);
379 :
380 : // create PaintInfoRec, use Rectangle only temporarily
381 38922 : const vcl::Region& rRegion = GetPaintWindow().GetRedrawRegion();
382 :
383 : // create processing data
384 38922 : sdr::contact::DisplayInfo aDisplayInfo;
385 :
386 : // is it the control layer? If Yes, set flag
387 38922 : aDisplayInfo.SetControlLayerProcessingActive(bControlLayerProcessingActive);
388 :
389 : // Draw just the one given layer
390 38922 : aProcessLayers.ClearAll();
391 38922 : aProcessLayers.Set(*pId);
392 :
393 38922 : aDisplayInfo.SetProcessLayers(aProcessLayers);
394 :
395 : // Set region as redraw area
396 38922 : aDisplayInfo.SetRedrawArea(rRegion);
397 :
398 : // Writer or calc, coming from original RedrawOneLayer.
399 : // #i72889# no page painting for layer painting
400 38922 : aDisplayInfo.SetPageProcessingActive(false);
401 :
402 : // paint page
403 38922 : GetObjectContact().ProcessDisplay(aDisplayInfo);
404 : }
405 :
406 : // reset redirector
407 38922 : GetObjectContact().SetViewObjectContactRedirector(0L);
408 38922 : }
409 :
410 : // Invalidate call, used from ObjectContact(OfPageView) in InvalidatePartOfView(...)
411 15983 : void SdrPageWindow::InvalidatePageWindow(const basegfx::B2DRange& rRange)
412 : {
413 15983 : if(GetPageView().IsVisible() && GetPaintWindow().OutputToWindow())
414 : {
415 15528 : const SvtOptionsDrawinglayer aDrawinglayerOpt;
416 15528 : vcl::Window& rWindow(static_cast< vcl::Window& >(GetPaintWindow().GetOutputDevice()));
417 15528 : basegfx::B2DRange aDiscreteRange(rRange);
418 15528 : aDiscreteRange.transform(rWindow.GetViewTransformation());
419 :
420 15528 : if(aDrawinglayerOpt.IsAntiAliasing())
421 : {
422 : // invalidate one discrete unit more under the assumption that AA
423 : // needs one pixel more
424 0 : aDiscreteRange.grow(1.0);
425 : }
426 :
427 : const Rectangle aVCLDiscreteRectangle(
428 15528 : static_cast<long>(floor(aDiscreteRange.getMinX())),
429 15528 : static_cast<long>(floor(aDiscreteRange.getMinY())),
430 15528 : static_cast<long>(ceil(aDiscreteRange.getMaxX())),
431 62112 : static_cast<long>(ceil(aDiscreteRange.getMaxY())));
432 15528 : const bool bWasMapModeEnabled(rWindow.IsMapModeEnabled());
433 :
434 15528 : rWindow.EnableMapMode(false);
435 15528 : rWindow.Invalidate(aVCLDiscreteRectangle, InvalidateFlags::NoErase);
436 15528 : rWindow.EnableMapMode(bWasMapModeEnabled);
437 : }
438 15983 : }
439 :
440 : // ObjectContact section
441 23 : const sdr::contact::ObjectContact& SdrPageWindow::GetObjectContact() const
442 : {
443 23 : if (!mpImpl->mpObjectContact)
444 21 : mpImpl->mpObjectContact = new sdr::contact::ObjectContactOfPageView(const_cast<SdrPageWindow&>(*this));
445 :
446 23 : return *mpImpl->mpObjectContact;
447 : }
448 :
449 148952 : sdr::contact::ObjectContact& SdrPageWindow::GetObjectContact()
450 : {
451 148952 : if (!mpImpl->mpObjectContact)
452 2618 : mpImpl->mpObjectContact = new sdr::contact::ObjectContactOfPageView(*this);
453 :
454 148952 : return *mpImpl->mpObjectContact;
455 : }
456 :
457 49585 : bool SdrPageWindow::HasObjectContact() const
458 : {
459 49585 : return mpImpl->mpObjectContact != NULL;
460 : }
461 :
462 : // #i26631#
463 5459 : void SdrPageWindow::ResetObjectContact()
464 : {
465 5459 : if (mpImpl->mpObjectContact)
466 : {
467 2621 : delete mpImpl->mpObjectContact;
468 2621 : mpImpl->mpObjectContact = 0L;
469 : }
470 5459 : }
471 :
472 23 : void SdrPageWindow::SetDesignMode( bool _bDesignMode ) const
473 : {
474 23 : const sdr::contact::ObjectContactOfPageView* pOC = dynamic_cast< const sdr::contact::ObjectContactOfPageView* >( &GetObjectContact() );
475 : DBG_ASSERT( pOC, "SdrPageWindow::SetDesignMode: invalid object contact!" );
476 23 : if ( pOC )
477 23 : pOC->SetUNOControlsDesignMode( _bDesignMode );
478 458 : }
479 :
480 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|