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 #include <svx/sdr/contact/viewcontactofvirtobj.hxx>
27 #include <svx/svdovirt.hxx>
28 #include <svx/sdr/contact/displayinfo.hxx>
29 #include <basegfx/matrix/b2dhommatrix.hxx>
30 #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
31 #include <vcl/outdev.hxx>
32 #include <drawinglayer/primitive2d/sdrdecompositiontools2d.hxx>
33 
34 //////////////////////////////////////////////////////////////////////////////
35 
36 namespace sdr
37 {
38 	namespace contact
39 	{
GetVirtObj() const40         SdrVirtObj& ViewContactOfVirtObj::GetVirtObj() const
41 		{
42 			return (SdrVirtObj&)mrObject;
43 		}
44 
ViewContactOfVirtObj(SdrVirtObj & rObj)45         ViewContactOfVirtObj::ViewContactOfVirtObj(SdrVirtObj& rObj)
46 		:	ViewContactOfSdrObj(rObj)
47 		{
48 		}
49 
~ViewContactOfVirtObj()50 		ViewContactOfVirtObj::~ViewContactOfVirtObj()
51 		{
52 		}
53 
54         // Access to possible sub-hierarchy
GetObjectCount() const55 		sal_uInt32 ViewContactOfVirtObj::GetObjectCount() const
56 		{
57             // Here, SdrVirtObj's need to return 0L to show that they have no
58             // sub-hierarchy, even when they are group objects. This is necessary
59             // to avoid that the same VOCs will be added to the draw hierarchy
60             // twice which leads to problems.
61 			//
62             // This solution is only a first solution to get things running. Later
63             // this needs to be replaced with creating real VOCs for the objects
64             // referenced by virtual objects to avoid the 'trick' of setting the
65             // offset for painting at the destination OutputDevive.
66 			//
67 			// As can be seen, with primitives, the problem will be solved using
68 			// a transformPrimitive, so this solution can stay with primitives.
69             return 0L;
70 		}
71 
createViewIndependentPrimitive2DSequence() const72 		drawinglayer::primitive2d::Primitive2DSequence ViewContactOfVirtObj::createViewIndependentPrimitive2DSequence() const
73 		{
74 			// create displacement transformation if we have content
75 			basegfx::B2DHomMatrix aObjectMatrix;
76 			Point aAnchor(GetVirtObj().GetAnchorPos());
77 
78 			if(aAnchor.X() || aAnchor.Y())
79 			{
80 				aObjectMatrix.set(0, 2, aAnchor.X());
81 				aObjectMatrix.set(1, 2, aAnchor.Y());
82 			}
83 
84 			// use method from referenced object to get the Primitive2DSequence
85 			const drawinglayer::primitive2d::Primitive2DSequence xSequenceVirtual(
86 				GetVirtObj().GetReferencedObj().GetViewContact().getViewIndependentPrimitive2DSequence());
87 
88 			if(xSequenceVirtual.hasElements())
89 			{
90 				// create transform primitive
91 				const drawinglayer::primitive2d::Primitive2DReference xReference(
92 					new drawinglayer::primitive2d::TransformPrimitive2D(
93 						aObjectMatrix,
94 						xSequenceVirtual));
95 
96 				return drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
97 			}
98 			else
99 			{
100 				// always append an invisible outline for the cases where no visible content exists
101 				const drawinglayer::primitive2d::Primitive2DReference xReference(
102 					drawinglayer::primitive2d::createHiddenGeometryPrimitives2D(
103 						false, aObjectMatrix));
104 
105 				return drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
106 			}
107 		}
108 	} // end of namespace contact
109 } // end of namespace sdr
110 
111 //////////////////////////////////////////////////////////////////////////////
112 // eof
113