cid#1606940 Check of thread-shared field evades lock acquisition
[LibreOffice.git] / svx / source / sdr / contact / viewobjectcontactofsdrpage.cxx
blob3cc27104c3c290cae6d26ee2d1452f393c19aca1
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 .
21 #include <sdr/contact/viewobjectcontactofsdrpage.hxx>
22 #include <svx/sdr/contact/displayinfo.hxx>
23 #include <sdr/contact/viewcontactofsdrpage.hxx>
24 #include <svx/svdview.hxx>
25 #include <svx/svdpage.hxx>
26 #include <svx/svdpagv.hxx>
27 #include <svx/sdr/contact/objectcontact.hxx>
28 #include <drawinglayer/primitive2d/backgroundcolorprimitive2d.hxx>
29 #include <basegfx/polygon/b2dpolygontools.hxx>
30 #include <drawinglayer/primitive2d/PolyPolygonColorPrimitive2D.hxx>
31 #include <drawinglayer/primitive2d/gridprimitive2d.hxx>
32 #include <drawinglayer/primitive2d/helplineprimitive2d.hxx>
33 #include <basegfx/polygon/b2dpolygon.hxx>
34 #include <sdr/primitive2d/sdrprimitivetools.hxx>
36 using namespace com::sun::star;
38 namespace sdr::contact {
40 const SdrPage& ViewObjectContactOfPageSubObject::getPage() const
42 return static_cast< ViewContactOfPageSubObject& >(GetViewContact()).getPage();
45 ViewObjectContactOfPageSubObject::ViewObjectContactOfPageSubObject(ObjectContact& rObjectContact, ViewContact& rViewContact)
46 : ViewObjectContact(rObjectContact, rViewContact)
50 ViewObjectContactOfPageSubObject::~ViewObjectContactOfPageSubObject()
54 bool ViewObjectContactOfPageSubObject::isPrimitiveVisible(const DisplayInfo& rDisplayInfo) const
56 if(rDisplayInfo.GetSubContentActive())
58 return false;
61 if(rDisplayInfo.GetControlLayerProcessingActive())
63 return false;
66 if(!GetObjectContact().isPageDecorationActive())
68 return false;
71 if(GetObjectContact().isOutputToPrinter())
73 return false;
76 if(!GetObjectContact().TryToGetSdrPageView())
78 return false;
81 return true;
84 bool ViewObjectContactOfPageSubObject::isPrimitiveGhosted(const DisplayInfo& /*rDisplayInfo*/) const
86 // suppress ghosted for page parts
87 return false;
90 ViewObjectContactOfPageBackground::ViewObjectContactOfPageBackground(ObjectContact& rObjectContact, ViewContact& rViewContact)
91 : ViewObjectContactOfPageSubObject(rObjectContact, rViewContact)
95 ViewObjectContactOfPageBackground::~ViewObjectContactOfPageBackground()
99 bool ViewObjectContactOfPageBackground::isPrimitiveVisible(const DisplayInfo& rDisplayInfo) const
101 if(!ViewObjectContactOfPageSubObject::isPrimitiveVisible(rDisplayInfo))
103 return false;
106 // no page background for preview renderers
107 if(GetObjectContact().IsPreviewRenderer())
109 return false;
112 return true;
115 void ViewObjectContactOfPageBackground::createPrimitive2DSequence(const DisplayInfo& /*rDisplayInfo*/, drawinglayer::primitive2d::Primitive2DDecompositionVisitor& rVisitor) const
117 // Initialize background. Dependent of IsPageVisible, use ApplicationBackgroundColor or ApplicationDocumentColor. Most
118 // old renderers for export (html, pdf, gallery, ...) set the page to not visible (SetPageVisible(false)). They expect the
119 // given OutputDevice to be initialized with the ApplicationDocumentColor then.
120 const SdrPageView* pPageView = GetObjectContact().TryToGetSdrPageView();
122 if(pPageView)
124 const SdrView& rView = pPageView->GetView();
125 Color aInitColor;
127 if(rView.IsPageVisible())
129 aInitColor = pPageView->GetApplicationBackgroundColor();
131 else
133 aInitColor = pPageView->GetApplicationDocumentColor();
135 if(COL_AUTO == aInitColor)
137 const svtools::ColorConfig aColorConfig;
138 aInitColor = aColorConfig.GetColorValue(svtools::DOCCOLOR).nColor;
142 // init background with InitColor
143 const basegfx::BColor aRGBColor(aInitColor.getBColor());
144 rVisitor.visit(new drawinglayer::primitive2d::BackgroundColorPrimitive2D(aRGBColor, (255 - aInitColor.GetAlpha()) / 255.0));
148 ViewObjectContactOfMasterPage::ViewObjectContactOfMasterPage(ObjectContact& rObjectContact, ViewContact& rViewContact)
149 : ViewObjectContactOfPageSubObject(rObjectContact, rViewContact)
153 ViewObjectContactOfMasterPage::~ViewObjectContactOfMasterPage()
157 bool ViewObjectContactOfMasterPage::isPrimitiveVisible(const DisplayInfo& rDisplayInfo) const
159 if(!ViewObjectContactOfPageSubObject::isPrimitiveVisible(rDisplayInfo))
161 return false;
164 // this object is only used for MasterPages. When not the MasterPage is
165 // displayed as a page, but another page is using it as sub-object, the
166 // geometry needs to be hidden
167 if(rDisplayInfo.GetSubContentActive())
169 return false;
172 return true;
175 ViewObjectContactOfPageFill::ViewObjectContactOfPageFill(ObjectContact& rObjectContact, ViewContact& rViewContact)
176 : ViewObjectContactOfPageSubObject(rObjectContact, rViewContact)
180 ViewObjectContactOfPageFill::~ViewObjectContactOfPageFill()
184 bool ViewObjectContactOfPageFill::isPrimitiveVisible(const DisplayInfo& rDisplayInfo) const
186 if(!ViewObjectContactOfPageSubObject::isPrimitiveVisible(rDisplayInfo))
188 return false;
191 SdrPageView* pSdrPageView = GetObjectContact().TryToGetSdrPageView();
193 if(!pSdrPageView)
195 return false;
198 if(!pSdrPageView->GetView().IsPageVisible())
200 return false;
203 return true;
206 void ViewObjectContactOfPageFill::createPrimitive2DSequence(const DisplayInfo& /*rDisplayInfo*/, drawinglayer::primitive2d::Primitive2DDecompositionVisitor& rVisitor) const
208 const SdrPageView* pPageView = GetObjectContact().TryToGetSdrPageView();
210 if(pPageView)
212 const SdrPage& rPage = getPage();
214 const basegfx::B2DRange aPageFillRange(0.0, 0.0, static_cast<double>(rPage.GetWidth()), static_cast<double>(rPage.GetHeight()));
215 const basegfx::B2DPolygon aPageFillPolygon(basegfx::utils::createPolygonFromRect(aPageFillRange));
216 Color aPageFillColor;
218 if(pPageView->GetApplicationDocumentColor() != COL_AUTO)
220 aPageFillColor = pPageView->GetApplicationDocumentColor();
222 else
224 const svtools::ColorConfig aColorConfig;
225 aPageFillColor = aColorConfig.GetColorValue(svtools::DOCCOLOR).nColor;
228 // create and add primitive
229 const basegfx::BColor aRGBColor(aPageFillColor.getBColor());
230 rVisitor.visit(new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(basegfx::B2DPolyPolygon(aPageFillPolygon), aRGBColor));
234 ViewObjectContactOfPageShadow::ViewObjectContactOfPageShadow(ObjectContact& rObjectContact, ViewContact& rViewContact)
235 : ViewObjectContactOfPageSubObject(rObjectContact, rViewContact)
239 ViewObjectContactOfPageShadow::~ViewObjectContactOfPageShadow()
243 bool ViewObjectContactOfPageShadow::isPrimitiveVisible(const DisplayInfo& rDisplayInfo) const
245 if(!ViewObjectContactOfPageSubObject::isPrimitiveVisible(rDisplayInfo))
247 return false;
250 SdrPageView* pSdrPageView = GetObjectContact().TryToGetSdrPageView();
252 if(!pSdrPageView)
254 return false;
257 if(!pSdrPageView->GetView().IsPageVisible())
259 return false;
262 if(!pSdrPageView->GetView().IsPageShadowVisible())
264 return false;
267 // no page shadow for preview renderers
268 if(GetObjectContact().IsPreviewRenderer())
270 return false;
273 // no page shadow for high contrast mode
274 if(GetObjectContact().isDrawModeHighContrast())
276 return false;
279 return true;
282 ViewObjectContactOfOuterPageBorder::ViewObjectContactOfOuterPageBorder(ObjectContact& rObjectContact, ViewContact& rViewContact)
283 : ViewObjectContactOfPageSubObject(rObjectContact, rViewContact)
287 ViewObjectContactOfOuterPageBorder::~ViewObjectContactOfOuterPageBorder()
291 bool ViewObjectContactOfOuterPageBorder::isPrimitiveVisible(const DisplayInfo& rDisplayInfo) const
293 if(!ViewObjectContactOfPageSubObject::isPrimitiveVisible(rDisplayInfo))
295 return false;
298 SdrPageView* pSdrPageView = GetObjectContact().TryToGetSdrPageView();
300 if(!pSdrPageView)
302 return false;
305 const SdrView& rView = pSdrPageView->GetView();
307 return rView.IsPageVisible() || !rView.IsPageBorderVisible();
310 ViewObjectContactOfInnerPageBorder::ViewObjectContactOfInnerPageBorder(ObjectContact& rObjectContact, ViewContact& rViewContact)
311 : ViewObjectContactOfPageSubObject(rObjectContact, rViewContact)
315 ViewObjectContactOfInnerPageBorder::~ViewObjectContactOfInnerPageBorder()
319 bool ViewObjectContactOfInnerPageBorder::isPrimitiveVisible(const DisplayInfo& rDisplayInfo) const
321 if(!ViewObjectContactOfPageSubObject::isPrimitiveVisible(rDisplayInfo))
323 return false;
326 SdrPageView* pSdrPageView = GetObjectContact().TryToGetSdrPageView();
328 if(!pSdrPageView)
330 return false;
333 if(!pSdrPageView->GetView().IsBordVisible())
335 return false;
338 const SdrPage& rPage = getPage();
340 if(!rPage.GetLeftBorder() && !rPage.GetUpperBorder() && !rPage.GetRightBorder() && !rPage.GetLowerBorder())
342 return false;
345 // no inner page border for preview renderers
346 if(GetObjectContact().IsPreviewRenderer())
348 return false;
351 return true;
354 ViewObjectContactOfPageHierarchy::ViewObjectContactOfPageHierarchy(ObjectContact& rObjectContact, ViewContact& rViewContact)
355 : ViewObjectContactOfPageSubObject(rObjectContact, rViewContact)
359 ViewObjectContactOfPageHierarchy::~ViewObjectContactOfPageHierarchy()
363 void ViewObjectContactOfPageHierarchy::getPrimitive2DSequenceHierarchy(DisplayInfo& rDisplayInfo, drawinglayer::primitive2d::Primitive2DDecompositionVisitor& rVisitor) const
365 // process local sub-hierarchy
366 const sal_uInt32 nSubHierarchyCount(GetViewContact().GetObjectCount());
368 if(!nSubHierarchyCount)
369 return;
371 getPrimitive2DSequenceSubHierarchy(rDisplayInfo, rVisitor);
374 ViewObjectContactOfPageGrid::ViewObjectContactOfPageGrid(ObjectContact& rObjectContact, ViewContact& rViewContact)
375 : ViewObjectContactOfPageSubObject(rObjectContact, rViewContact)
379 ViewObjectContactOfPageGrid::~ViewObjectContactOfPageGrid()
383 bool ViewObjectContactOfPageGrid::isPrimitiveVisible(const DisplayInfo& rDisplayInfo) const
385 if(!ViewObjectContactOfPageSubObject::isPrimitiveVisible(rDisplayInfo))
387 return false;
390 SdrPageView* pSdrPageView = GetObjectContact().TryToGetSdrPageView();
392 if(!pSdrPageView)
394 return false;
397 const SdrView& rView = pSdrPageView->GetView();
399 if(!rView.IsGridVisible())
401 return false;
404 // no page grid for preview renderers
405 if(GetObjectContact().IsPreviewRenderer())
407 return false;
410 if(static_cast< ViewContactOfGrid& >(GetViewContact()).getFront() != rView.IsGridFront())
412 return false;
415 return true;
418 void ViewObjectContactOfPageGrid::createPrimitive2DSequence(const DisplayInfo& /*rDisplayInfo*/, drawinglayer::primitive2d::Primitive2DDecompositionVisitor& rVisitor) const
420 const SdrPageView* pPageView = GetObjectContact().TryToGetSdrPageView();
422 if(pPageView)
424 const SdrView& rView = pPageView->GetView();
425 const SdrPage& rPage = getPage();
426 const Color aGridColor(rView.GetGridColor());
427 const basegfx::BColor aRGBGridColor(aGridColor.getBColor());
429 basegfx::B2DHomMatrix aGridMatrix;
430 aGridMatrix.set(0, 0, static_cast<double>(rPage.GetWidth() - (rPage.GetRightBorder() + rPage.GetLeftBorder())));
431 aGridMatrix.set(1, 1, static_cast<double>(rPage.GetHeight() - (rPage.GetLowerBorder() + rPage.GetUpperBorder())));
432 aGridMatrix.set(0, 2, static_cast<double>(rPage.GetLeftBorder()));
433 aGridMatrix.set(1, 2, static_cast<double>(rPage.GetUpperBorder()));
435 const Size aRaw(rView.GetGridCoarse());
436 const Size aFine(rView.GetGridFine());
437 const double fWidthX(aRaw.getWidth());
438 const double fWidthY(aRaw.getHeight());
439 const sal_uInt32 nSubdivisionsX(aFine.getWidth() ? aRaw.getWidth() / aFine.getWidth() : 0);
440 const sal_uInt32 nSubdivisionsY(aFine.getHeight() ? aRaw.getHeight() / aFine.getHeight() : 0);
442 rVisitor.visit(new drawinglayer::primitive2d::GridPrimitive2D(
443 aGridMatrix, fWidthX, fWidthY, 10.0, 3.0, nSubdivisionsX, nSubdivisionsY, aRGBGridColor,
444 drawinglayer::primitive2d::createDefaultCross_3x3(aRGBGridColor)));
448 ViewObjectContactOfPageHelplines::ViewObjectContactOfPageHelplines(ObjectContact& rObjectContact, ViewContact& rViewContact)
449 : ViewObjectContactOfPageSubObject(rObjectContact, rViewContact)
453 ViewObjectContactOfPageHelplines::~ViewObjectContactOfPageHelplines()
457 bool ViewObjectContactOfPageHelplines::isPrimitiveVisible(const DisplayInfo& rDisplayInfo) const
459 if(!ViewObjectContactOfPageSubObject::isPrimitiveVisible(rDisplayInfo))
461 return false;
464 SdrPageView* pSdrPageView = GetObjectContact().TryToGetSdrPageView();
466 if(!pSdrPageView)
468 return false;
471 const SdrView& rView = pSdrPageView->GetView();
473 if(!rView.IsHlplVisible())
475 return false;
478 // no helplines for preview renderers
479 if(GetObjectContact().IsPreviewRenderer())
481 return false;
484 if(static_cast< ViewContactOfHelplines& >(GetViewContact()).getFront() != rView.IsHlplFront())
486 return false;
489 return true;
492 void ViewObjectContactOfPageHelplines::createPrimitive2DSequence(const DisplayInfo& /*rDisplayInfo*/, drawinglayer::primitive2d::Primitive2DDecompositionVisitor& rVisitor) const
494 const SdrPageView* pPageView = GetObjectContact().TryToGetSdrPageView();
496 if(pPageView)
498 const SdrHelpLineList& rHelpLineList = pPageView->GetHelpLines();
499 const sal_uInt32 nCount(rHelpLineList.GetCount());
501 if(nCount)
503 const basegfx::BColor aRGBColorA(1.0, 1.0, 1.0);
504 const basegfx::BColor aRGBColorB(0.0, 0.0, 0.0);
506 for(sal_uInt32 a(0); a < nCount; a++)
508 const SdrHelpLine& rHelpLine = rHelpLineList[static_cast<sal_uInt16>(a)];
509 const basegfx::B2DPoint aPosition(static_cast<double>(rHelpLine.GetPos().X()), static_cast<double>(rHelpLine.GetPos().Y()));
510 const double fDiscreteDashLength(4.0);
512 switch(rHelpLine.GetKind())
514 default : // SdrHelpLineKind::Point
516 rVisitor.visit(new drawinglayer::primitive2d::HelplinePrimitive2D(
517 aPosition, basegfx::B2DVector(1.0, 0.0), drawinglayer::primitive2d::HelplineStyle2D::Point,
518 aRGBColorA, aRGBColorB, fDiscreteDashLength));
519 break;
521 case SdrHelpLineKind::Vertical :
523 rVisitor.visit(new drawinglayer::primitive2d::HelplinePrimitive2D(
524 aPosition, basegfx::B2DVector(0.0, 1.0), drawinglayer::primitive2d::HelplineStyle2D::Line,
525 aRGBColorA, aRGBColorB, fDiscreteDashLength));
526 break;
528 case SdrHelpLineKind::Horizontal :
530 rVisitor.visit(new drawinglayer::primitive2d::HelplinePrimitive2D(
531 aPosition, basegfx::B2DVector(1.0, 0.0), drawinglayer::primitive2d::HelplineStyle2D::Line,
532 aRGBColorA, aRGBColorB, fDiscreteDashLength));
533 break;
541 ViewObjectContactOfSdrPage::ViewObjectContactOfSdrPage(ObjectContact& rObjectContact, ViewContact& rViewContact)
542 : ViewObjectContact(rObjectContact, rViewContact)
546 ViewObjectContactOfSdrPage::~ViewObjectContactOfSdrPage()
550 void ViewObjectContactOfSdrPage::getPrimitive2DSequenceHierarchy(DisplayInfo& rDisplayInfo, drawinglayer::primitive2d::Primitive2DDecompositionVisitor& rVisitor) const
552 // process local sub-hierarchy
553 const sal_uInt32 nSubHierarchyCount(GetViewContact().GetObjectCount());
555 if(!nSubHierarchyCount)
556 return;
558 const bool bDoGhostedDisplaying(
559 GetObjectContact().DoVisualizeEnteredGroup()
560 && !GetObjectContact().isOutputToPrinter()
561 && GetObjectContact().getActiveViewContact() == &GetViewContact());
563 if(bDoGhostedDisplaying)
565 rDisplayInfo.ClearGhostedDrawMode();
568 // visit object hierarchy
569 getPrimitive2DSequenceSubHierarchy(rDisplayInfo, rVisitor);
571 if(bDoGhostedDisplaying)
573 rDisplayInfo.SetGhostedDrawMode();
579 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */