xref: /AOO41X/main/svx/source/sdr/contact/viewobjectcontactofmasterpagedescriptor.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_svx.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <svx/sdr/contact/viewobjectcontactofmasterpagedescriptor.hxx>
32*cdf0e10cSrcweir #include <svx/sdr/contact/viewcontactofmasterpagedescriptor.hxx>
33*cdf0e10cSrcweir #include <svx/sdr/contact/displayinfo.hxx>
34*cdf0e10cSrcweir #include <svx/sdr/contact/objectcontact.hxx>
35*cdf0e10cSrcweir #include <svx/svdpagv.hxx>
36*cdf0e10cSrcweir #include <svx/svdview.hxx>
37*cdf0e10cSrcweir #include <svx/svdpage.hxx>
38*cdf0e10cSrcweir #include <drawinglayer/primitive2d/maskprimitive2d.hxx>
39*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx>
40*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx>
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir namespace sdr
45*cdf0e10cSrcweir {
46*cdf0e10cSrcweir 	namespace contact
47*cdf0e10cSrcweir 	{
48*cdf0e10cSrcweir 		ViewObjectContactOfMasterPageDescriptor::ViewObjectContactOfMasterPageDescriptor(ObjectContact& rObjectContact, ViewContact& rViewContact)
49*cdf0e10cSrcweir 		:	ViewObjectContact(rObjectContact, rViewContact)
50*cdf0e10cSrcweir 		{
51*cdf0e10cSrcweir 		}
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir 		ViewObjectContactOfMasterPageDescriptor::~ViewObjectContactOfMasterPageDescriptor()
54*cdf0e10cSrcweir 		{
55*cdf0e10cSrcweir 		}
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir 		sdr::MasterPageDescriptor& ViewObjectContactOfMasterPageDescriptor::GetMasterPageDescriptor() const
58*cdf0e10cSrcweir 		{
59*cdf0e10cSrcweir 			return static_cast< ViewContactOfMasterPageDescriptor& >(GetViewContact()).GetMasterPageDescriptor();
60*cdf0e10cSrcweir 		}
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir 		bool ViewObjectContactOfMasterPageDescriptor::isPrimitiveVisible(const DisplayInfo& rDisplayInfo) const
63*cdf0e10cSrcweir 		{
64*cdf0e10cSrcweir 			if(rDisplayInfo.GetControlLayerProcessingActive())
65*cdf0e10cSrcweir 			{
66*cdf0e10cSrcweir 				return false;
67*cdf0e10cSrcweir 			}
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir 			if(!rDisplayInfo.GetPageProcessingActive())
70*cdf0e10cSrcweir 			{
71*cdf0e10cSrcweir 				return false;
72*cdf0e10cSrcweir 			}
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir 			return true;
75*cdf0e10cSrcweir 		}
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir 		drawinglayer::primitive2d::Primitive2DSequence ViewObjectContactOfMasterPageDescriptor::getPrimitive2DSequenceHierarchy(DisplayInfo& rDisplayInfo) const
78*cdf0e10cSrcweir 		{
79*cdf0e10cSrcweir 			drawinglayer::primitive2d::Primitive2DSequence xRetval;
80*cdf0e10cSrcweir 			drawinglayer::primitive2d::Primitive2DSequence xMasterPageSequence;
81*cdf0e10cSrcweir 			const sdr::MasterPageDescriptor& rDescriptor = GetMasterPageDescriptor();
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir 			// used range (retval) is fixed here, it's the MasterPage fill range
84*cdf0e10cSrcweir 			const SdrPage& rOwnerPage = rDescriptor.GetOwnerPage();
85*cdf0e10cSrcweir 			const basegfx::B2DRange aPageFillRange(
86*cdf0e10cSrcweir 				rOwnerPage.GetLftBorder(), rOwnerPage.GetUppBorder(),
87*cdf0e10cSrcweir 				rOwnerPage.GetWdt() - rOwnerPage.GetRgtBorder(), rOwnerPage.GetHgt() - rOwnerPage.GetLwrBorder());
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir 			// Modify DisplayInfo for MasterPageContent collection; remember original layers and
90*cdf0e10cSrcweir 			// set combined LayerSet; set MasterPagePaint flag
91*cdf0e10cSrcweir 			const SetOfByte aRememberedLayers(rDisplayInfo.GetProcessLayers());
92*cdf0e10cSrcweir 			SetOfByte aPreprocessedLayers(aRememberedLayers);
93*cdf0e10cSrcweir 			aPreprocessedLayers &= rDescriptor.GetVisibleLayers();
94*cdf0e10cSrcweir 			rDisplayInfo.SetProcessLayers(aPreprocessedLayers);
95*cdf0e10cSrcweir 			rDisplayInfo.SetSubContentActive(true);
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir             // check layer visibility (traditionally was member of layer 1)
98*cdf0e10cSrcweir 			if(aPreprocessedLayers.IsSet(1))
99*cdf0e10cSrcweir             {
100*cdf0e10cSrcweir 				// hide PageBackground for special DrawModes; historical reasons
101*cdf0e10cSrcweir 				if(!GetObjectContact().isDrawModeGray() && !GetObjectContact().isDrawModeHighContrast())
102*cdf0e10cSrcweir                 {
103*cdf0e10cSrcweir 					// if visible, create the default background primitive sequence
104*cdf0e10cSrcweir 					xRetval = static_cast< ViewContactOfMasterPageDescriptor& >(GetViewContact()).getViewIndependentPrimitive2DSequence();
105*cdf0e10cSrcweir                 }
106*cdf0e10cSrcweir             }
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir 			// hide MasterPage content? Test self here for hierarchy
109*cdf0e10cSrcweir 			if(isPrimitiveVisible(rDisplayInfo))
110*cdf0e10cSrcweir 			{
111*cdf0e10cSrcweir 				// get the VOC of the Master-SdrPage and get it's object hierarchy
112*cdf0e10cSrcweir 				ViewContact& rViewContactOfMasterPage(rDescriptor.GetUsedPage().GetViewContact());
113*cdf0e10cSrcweir 				ViewObjectContact& rVOCOfMasterPage(rViewContactOfMasterPage.GetViewObjectContact(GetObjectContact()));
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir 				xMasterPageSequence = rVOCOfMasterPage.getPrimitive2DSequenceHierarchy(rDisplayInfo);
116*cdf0e10cSrcweir 			}
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir 			// reset DisplayInfo changes for MasterPage paint
119*cdf0e10cSrcweir 			rDisplayInfo.SetProcessLayers(aRememberedLayers);
120*cdf0e10cSrcweir 			rDisplayInfo.SetSubContentActive(false);
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir 			if(xMasterPageSequence.hasElements())
123*cdf0e10cSrcweir 			{
124*cdf0e10cSrcweir 				// get range of MasterPage sub hierarchy
125*cdf0e10cSrcweir 				const drawinglayer::geometry::ViewInformation2D& rViewInformation2D(GetObjectContact().getViewInformation2D());
126*cdf0e10cSrcweir 				const basegfx::B2DRange aSubHierarchyRange(drawinglayer::primitive2d::getB2DRangeFromPrimitive2DSequence(xMasterPageSequence, rViewInformation2D));
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir 				if(aPageFillRange.isInside(aSubHierarchyRange))
129*cdf0e10cSrcweir 				{
130*cdf0e10cSrcweir 					// completely inside, just render MasterPage content. Add to target
131*cdf0e10cSrcweir 					drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(xRetval, xMasterPageSequence);
132*cdf0e10cSrcweir 				}
133*cdf0e10cSrcweir 				else if(aPageFillRange.overlaps(aSubHierarchyRange))
134*cdf0e10cSrcweir 				{
135*cdf0e10cSrcweir 					// overlapping, compute common area
136*cdf0e10cSrcweir 					basegfx::B2DRange aCommonArea(aPageFillRange);
137*cdf0e10cSrcweir 					aCommonArea.intersect(aSubHierarchyRange);
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir 					// need to create a clip primitive, add clipped list to target
140*cdf0e10cSrcweir 					const drawinglayer::primitive2d::Primitive2DReference xReference(new drawinglayer::primitive2d::MaskPrimitive2D(
141*cdf0e10cSrcweir 						basegfx::B2DPolyPolygon(basegfx::tools::createPolygonFromRect(aCommonArea)), xMasterPageSequence));
142*cdf0e10cSrcweir 					drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(xRetval, xReference);
143*cdf0e10cSrcweir 				}
144*cdf0e10cSrcweir 			}
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir 			// return grouped primitive
147*cdf0e10cSrcweir 			return xRetval;
148*cdf0e10cSrcweir 		}
149*cdf0e10cSrcweir 	} // end of namespace contact
150*cdf0e10cSrcweir } // end of namespace sdr
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
153*cdf0e10cSrcweir // eof
154