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