1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26 
27 #include <svx/sdr/contact/viewobjectcontactofmasterpagedescriptor.hxx>
28 #include <svx/sdr/contact/viewcontactofmasterpagedescriptor.hxx>
29 #include <svx/sdr/contact/displayinfo.hxx>
30 #include <svx/sdr/contact/objectcontact.hxx>
31 #include <svx/svdpagv.hxx>
32 #include <svx/svdview.hxx>
33 #include <svx/svdpage.hxx>
34 #include <drawinglayer/primitive2d/maskprimitive2d.hxx>
35 #include <basegfx/polygon/b2dpolygontools.hxx>
36 #include <basegfx/polygon/b2dpolygon.hxx>
37 
38 //////////////////////////////////////////////////////////////////////////////
39 
40 namespace sdr
41 {
42 	namespace contact
43 	{
ViewObjectContactOfMasterPageDescriptor(ObjectContact & rObjectContact,ViewContact & rViewContact)44 		ViewObjectContactOfMasterPageDescriptor::ViewObjectContactOfMasterPageDescriptor(ObjectContact& rObjectContact, ViewContact& rViewContact)
45 		:	ViewObjectContact(rObjectContact, rViewContact)
46 		{
47 		}
48 
~ViewObjectContactOfMasterPageDescriptor()49 		ViewObjectContactOfMasterPageDescriptor::~ViewObjectContactOfMasterPageDescriptor()
50 		{
51 		}
52 
GetMasterPageDescriptor() const53 		sdr::MasterPageDescriptor& ViewObjectContactOfMasterPageDescriptor::GetMasterPageDescriptor() const
54 		{
55 			return static_cast< ViewContactOfMasterPageDescriptor& >(GetViewContact()).GetMasterPageDescriptor();
56 		}
57 
isPrimitiveVisible(const DisplayInfo & rDisplayInfo) const58 		bool ViewObjectContactOfMasterPageDescriptor::isPrimitiveVisible(const DisplayInfo& rDisplayInfo) const
59 		{
60 			if(rDisplayInfo.GetControlLayerProcessingActive())
61 			{
62 				return false;
63 			}
64 
65 			if(!rDisplayInfo.GetPageProcessingActive())
66 			{
67 				return false;
68 			}
69 
70 			return true;
71 		}
72 
getPrimitive2DSequenceHierarchy(DisplayInfo & rDisplayInfo) const73 		drawinglayer::primitive2d::Primitive2DSequence ViewObjectContactOfMasterPageDescriptor::getPrimitive2DSequenceHierarchy(DisplayInfo& rDisplayInfo) const
74 		{
75 			drawinglayer::primitive2d::Primitive2DSequence xRetval;
76 			drawinglayer::primitive2d::Primitive2DSequence xMasterPageSequence;
77 			const sdr::MasterPageDescriptor& rDescriptor = GetMasterPageDescriptor();
78 
79 			// used range (retval) is fixed here, it's the MasterPage fill range
80 			const SdrPage& rOwnerPage = rDescriptor.GetOwnerPage();
81 			const basegfx::B2DRange aPageFillRange(
82 				rOwnerPage.GetLftBorder(), rOwnerPage.GetUppBorder(),
83 				rOwnerPage.GetWdt() - rOwnerPage.GetRgtBorder(), rOwnerPage.GetHgt() - rOwnerPage.GetLwrBorder());
84 
85 			// Modify DisplayInfo for MasterPageContent collection; remember original layers and
86 			// set combined LayerSet; set MasterPagePaint flag
87 			const SetOfByte aRememberedLayers(rDisplayInfo.GetProcessLayers());
88 			SetOfByte aPreprocessedLayers(aRememberedLayers);
89 			aPreprocessedLayers &= rDescriptor.GetVisibleLayers();
90 			rDisplayInfo.SetProcessLayers(aPreprocessedLayers);
91 			rDisplayInfo.SetSubContentActive(true);
92 
93             // check layer visibility (traditionally was member of layer 1)
94 			if(aPreprocessedLayers.IsSet(1))
95             {
96 				// hide PageBackground for special DrawModes; historical reasons
97 				if(!GetObjectContact().isDrawModeGray() && !GetObjectContact().isDrawModeHighContrast())
98                 {
99 					// if visible, create the default background primitive sequence
100 					xRetval = static_cast< ViewContactOfMasterPageDescriptor& >(GetViewContact()).getViewIndependentPrimitive2DSequence();
101                 }
102             }
103 
104 			// hide MasterPage content? Test self here for hierarchy
105 			if(isPrimitiveVisible(rDisplayInfo))
106 			{
107 				// get the VOC of the Master-SdrPage and get it's object hierarchy
108 				ViewContact& rViewContactOfMasterPage(rDescriptor.GetUsedPage().GetViewContact());
109 				ViewObjectContact& rVOCOfMasterPage(rViewContactOfMasterPage.GetViewObjectContact(GetObjectContact()));
110 
111 				xMasterPageSequence = rVOCOfMasterPage.getPrimitive2DSequenceHierarchy(rDisplayInfo);
112 			}
113 
114 			// reset DisplayInfo changes for MasterPage paint
115 			rDisplayInfo.SetProcessLayers(aRememberedLayers);
116 			rDisplayInfo.SetSubContentActive(false);
117 
118 			if(xMasterPageSequence.hasElements())
119 			{
120 				// get range of MasterPage sub hierarchy
121 				const drawinglayer::geometry::ViewInformation2D& rViewInformation2D(GetObjectContact().getViewInformation2D());
122 				const basegfx::B2DRange aSubHierarchyRange(drawinglayer::primitive2d::getB2DRangeFromPrimitive2DSequence(xMasterPageSequence, rViewInformation2D));
123 
124 				if(aPageFillRange.isInside(aSubHierarchyRange))
125 				{
126 					// completely inside, just render MasterPage content. Add to target
127 					drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(xRetval, xMasterPageSequence);
128 				}
129 				else if(aPageFillRange.overlaps(aSubHierarchyRange))
130 				{
131 					// overlapping, compute common area
132 					basegfx::B2DRange aCommonArea(aPageFillRange);
133 					aCommonArea.intersect(aSubHierarchyRange);
134 
135 					// need to create a clip primitive, add clipped list to target
136 					const drawinglayer::primitive2d::Primitive2DReference xReference(new drawinglayer::primitive2d::MaskPrimitive2D(
137 						basegfx::B2DPolyPolygon(basegfx::tools::createPolygonFromRect(aCommonArea)), xMasterPageSequence));
138 					drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(xRetval, xReference);
139 				}
140 			}
141 
142 			// return grouped primitive
143 			return xRetval;
144 		}
145 	} // end of namespace contact
146 } // end of namespace sdr
147 
148 //////////////////////////////////////////////////////////////////////////////
149 // eof
150