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/viewobjectcontactofsdrole2obj.hxx>
28 #include <svx/sdr/contact/viewobjectcontactofsdrobj.hxx>
29 #include <svx/sdr/contact/viewcontactofsdrole2obj.hxx>
30 #include <svx/svdoole2.hxx>
31 #include <svx/sdr/contact/objectcontact.hxx>
32 #include <svx/svdview.hxx>
33 #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
34 #include <basegfx/polygon/b2dpolygontools.hxx>
35 #include <com/sun/star/embed/EmbedMisc.hpp>
36 #include <com/sun/star/embed/EmbedStates.hpp>
37 #include <basegfx/polygon/b2dpolygon.hxx>
38 #include <basegfx/matrix/b2dhommatrix.hxx>
39 
40 //////////////////////////////////////////////////////////////////////////////
41 
42 using namespace com::sun::star;
43 
44 //////////////////////////////////////////////////////////////////////////////
45 
46 namespace sdr
47 {
48 	namespace contact
49 	{
getSdrOle2Object() const50 		const SdrOle2Obj& ViewObjectContactOfSdrOle2Obj::getSdrOle2Object() const
51 		{
52 			return static_cast< ViewContactOfSdrOle2Obj& >(GetViewContact()).GetOle2Obj();
53 		}
54 
createPrimitive2DSequence(const DisplayInfo &) const55 		drawinglayer::primitive2d::Primitive2DSequence ViewObjectContactOfSdrOle2Obj::createPrimitive2DSequence(
56             const DisplayInfo& /*rDisplayInfo*/) const
57 		{
58 			// this method is overloaded to do some things the old SdrOle2Obj::DoPaintObject did.
59 		    // In the future, some of these may be solved different, but ATM try to stay compatible
60 		    // with the old behaviour
61 		    drawinglayer::primitive2d::Primitive2DSequence xRetval;
62 		    const SdrOle2Obj& rSdrOle2 = getSdrOle2Object();
63             sal_Int32 nState(-1);
64 
65             {
66                 const svt::EmbeddedObjectRef& xObjRef  = rSdrOle2.getEmbeddedObjectRef();
67                 if ( xObjRef.is() )
68                     nState = xObjRef->getCurrentState();
69             }
70 
71             const bool bIsOutplaceActive(nState == embed::EmbedStates::ACTIVE);
72             const bool bIsInplaceActive((nState == embed::EmbedStates::INPLACE_ACTIVE) || (nState == embed::EmbedStates::UI_ACTIVE));
73             bool bDone(false);
74 
75             if(!bDone && bIsInplaceActive)
76             {
77                 if( !GetObjectContact().isOutputToPrinter() && !GetObjectContact().isOutputToRecordingMetaFile() )
78                 {
79                     //no need to create a primitive sequence here as the OLE object does render itself
80                     //in case of charts the superfluous creation of a metafile is strongly performance relevant!
81                     bDone = true;
82                 }
83             }
84 
85             if( !bDone )
86             {
87                 //old stuff that should be reworked
88                 {
89                     //if no replacement image is available load the OLE object
90 //                    if(!rSdrOle2.GetGraphic()) //try to fetch the metafile - this can lead to the actual creation of the metafile what can be extremely expensive (e.g. for big charts)!!! #i101925#
91 //                    {
92 //	                    // try to create embedded object
93 //                        rSdrOle2.GetObjRef(); //this loads the OLE object if it is not loaded already
94 //                    }
95                     const svt::EmbeddedObjectRef& xObjRef  = rSdrOle2.getEmbeddedObjectRef();
96                     if(xObjRef.is())
97                     {
98                         const sal_Int64 nMiscStatus(xObjRef->getStatus(rSdrOle2.GetAspect()));
99 
100                         // this hack (to change model data during PAINT argh(!)) should be reworked
101                         if(!rSdrOle2.IsResizeProtect() && (nMiscStatus & embed::EmbedMisc::EMBED_NEVERRESIZE))
102                         {
103 	                        const_cast< SdrOle2Obj* >(&rSdrOle2)->SetResizeProtect(true);
104                         }
105 
106                         SdrPageView* pPageView = GetObjectContact().TryToGetSdrPageView();
107 	                    if(pPageView && (nMiscStatus & embed::EmbedMisc::MS_EMBED_ACTIVATEWHENVISIBLE))
108 	                    {
109 		                    // connect plugin object
110 		                    pPageView->GetView().DoConnect(const_cast< SdrOle2Obj* >(&rSdrOle2));
111 	                    }
112                     }
113                 }//end old stuff to rework
114 
115                 // create OLE primitive stuff directly at VC with HC as parameter
116 		        const ViewContactOfSdrOle2Obj& rVC = static_cast< const ViewContactOfSdrOle2Obj& >(GetViewContact());
117                 xRetval = rVC.createPrimitive2DSequenceWithParameters(GetObjectContact().isDrawModeHighContrast());
118 
119                 if(bIsOutplaceActive)
120 		        {
121 			        // do not shade when printing or PDF exporting
122 			        if(!GetObjectContact().isOutputToPrinter() && !GetObjectContact().isOutputToRecordingMetaFile())
123 			        {
124                         // get object transformation
125                         const basegfx::B2DHomMatrix aObjectMatrix(static_cast< ViewContactOfSdrOle2Obj& >(GetViewContact()).createObjectTransform());
126 
127                         // shade the representation if the object is activated outplace
128 				        basegfx::B2DPolygon aObjectOutline(basegfx::tools::createUnitPolygon());
129 				        aObjectOutline.transform(aObjectMatrix);
130 
131 				        // Use a FillHatchPrimitive2D with necessary attributes
132 				        const drawinglayer::attribute::FillHatchAttribute aFillHatch(
133 					        drawinglayer::attribute::HATCHSTYLE_SINGLE, // single hatch
134 					        125.0, // 1.25 mm
135 					        45.0 * F_PI180, // 45 degree diagonal
136 					        Color(COL_BLACK).getBColor(), // black color
137                             3, // same default as VCL, a minimum of three discrete units (pixels) offset
138 					        false); // no filling
139 
140 				        const drawinglayer::primitive2d::Primitive2DReference xReference(new drawinglayer::primitive2d::PolyPolygonHatchPrimitive2D(
141 					        basegfx::B2DPolyPolygon(aObjectOutline),
142 					        Color(COL_BLACK).getBColor(),
143 					        aFillHatch));
144 
145 				        drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(xRetval, xReference);
146 			        }
147 		        }
148 
149             }
150 
151 		    return xRetval;
152 		}
153 
ViewObjectContactOfSdrOle2Obj(ObjectContact & rObjectContact,ViewContact & rViewContact)154 		ViewObjectContactOfSdrOle2Obj::ViewObjectContactOfSdrOle2Obj(ObjectContact& rObjectContact, ViewContact& rViewContact)
155 		:	ViewObjectContactOfSdrObj(rObjectContact, rViewContact)
156 		{
157 		}
158 
~ViewObjectContactOfSdrOle2Obj()159 		ViewObjectContactOfSdrOle2Obj::~ViewObjectContactOfSdrOle2Obj()
160 		{
161 		}
162 	} // end of namespace contact
163 } // end of namespace sdr
164 
165 //////////////////////////////////////////////////////////////////////////////
166 // eof
167