xref: /AOO41X/main/svx/source/sdr/contact/viewobjectcontactofsdrole2obj.cxx (revision 0702bc67a2ac2836add565ba470821c1aa4db6ed)
1f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5f6e50924SAndrew Rist  * distributed with this work for additional information
6f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17f6e50924SAndrew Rist  * specific language governing permissions and limitations
18f6e50924SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20f6e50924SAndrew Rist  *************************************************************/
21f6e50924SAndrew Rist 
22f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <svx/sdr/contact/viewobjectcontactofsdrole2obj.hxx>
28cdf0e10cSrcweir #include <svx/sdr/contact/viewobjectcontactofsdrobj.hxx>
29cdf0e10cSrcweir #include <svx/sdr/contact/viewcontactofsdrole2obj.hxx>
30cdf0e10cSrcweir #include <svx/svdoole2.hxx>
31cdf0e10cSrcweir #include <svx/sdr/contact/objectcontact.hxx>
32cdf0e10cSrcweir #include <svx/svdview.hxx>
33cdf0e10cSrcweir #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
34cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx>
35cdf0e10cSrcweir #include <com/sun/star/embed/EmbedMisc.hpp>
36cdf0e10cSrcweir #include <com/sun/star/embed/EmbedStates.hpp>
37cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx>
3878d93489SArmin Le Grand #include <basegfx/matrix/b2dhommatrix.hxx>
39cdf0e10cSrcweir 
40cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
41cdf0e10cSrcweir 
42cdf0e10cSrcweir using namespace com::sun::star;
43cdf0e10cSrcweir 
44cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
45cdf0e10cSrcweir 
46cdf0e10cSrcweir namespace sdr
47cdf0e10cSrcweir {
48cdf0e10cSrcweir 	namespace contact
49cdf0e10cSrcweir 	{
getSdrOle2Object() const50cdf0e10cSrcweir 		const SdrOle2Obj& ViewObjectContactOfSdrOle2Obj::getSdrOle2Object() const
51cdf0e10cSrcweir 		{
52cdf0e10cSrcweir 			return static_cast< ViewContactOfSdrOle2Obj& >(GetViewContact()).GetOle2Obj();
53cdf0e10cSrcweir 		}
54cdf0e10cSrcweir 
createPrimitive2DSequence(const DisplayInfo &) const55cdf0e10cSrcweir 		drawinglayer::primitive2d::Primitive2DSequence ViewObjectContactOfSdrOle2Obj::createPrimitive2DSequence(
56cdf0e10cSrcweir             const DisplayInfo& /*rDisplayInfo*/) const
57cdf0e10cSrcweir 		{
58cdf0e10cSrcweir 			// this method is overloaded to do some things the old SdrOle2Obj::DoPaintObject did.
59cdf0e10cSrcweir 		    // In the future, some of these may be solved different, but ATM try to stay compatible
60cdf0e10cSrcweir 		    // with the old behaviour
61cdf0e10cSrcweir 		    drawinglayer::primitive2d::Primitive2DSequence xRetval;
62cdf0e10cSrcweir 		    const SdrOle2Obj& rSdrOle2 = getSdrOle2Object();
63cdf0e10cSrcweir             sal_Int32 nState(-1);
64cdf0e10cSrcweir 
65cdf0e10cSrcweir             {
66cdf0e10cSrcweir                 const svt::EmbeddedObjectRef& xObjRef  = rSdrOle2.getEmbeddedObjectRef();
67cdf0e10cSrcweir                 if ( xObjRef.is() )
68cdf0e10cSrcweir                     nState = xObjRef->getCurrentState();
69cdf0e10cSrcweir             }
70cdf0e10cSrcweir 
71cdf0e10cSrcweir             const bool bIsOutplaceActive(nState == embed::EmbedStates::ACTIVE);
72cdf0e10cSrcweir             const bool bIsInplaceActive((nState == embed::EmbedStates::INPLACE_ACTIVE) || (nState == embed::EmbedStates::UI_ACTIVE));
73cdf0e10cSrcweir             bool bDone(false);
74cdf0e10cSrcweir 
75cdf0e10cSrcweir             if(!bDone && bIsInplaceActive)
76cdf0e10cSrcweir             {
77cdf0e10cSrcweir                 if( !GetObjectContact().isOutputToPrinter() && !GetObjectContact().isOutputToRecordingMetaFile() )
78cdf0e10cSrcweir                 {
79cdf0e10cSrcweir                     //no need to create a primitive sequence here as the OLE object does render itself
80cdf0e10cSrcweir                     //in case of charts the superfluous creation of a metafile is strongly performance relevant!
81cdf0e10cSrcweir                     bDone = true;
82cdf0e10cSrcweir                 }
83cdf0e10cSrcweir             }
84cdf0e10cSrcweir 
85cdf0e10cSrcweir             if( !bDone )
86cdf0e10cSrcweir             {
87cdf0e10cSrcweir                 //old stuff that should be reworked
88cdf0e10cSrcweir                 {
89cdf0e10cSrcweir                     //if no replacement image is available load the OLE object
9078d93489SArmin Le Grand //                    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#
9178d93489SArmin Le Grand //                    {
9278d93489SArmin Le Grand //	                    // try to create embedded object
9378d93489SArmin Le Grand //                        rSdrOle2.GetObjRef(); //this loads the OLE object if it is not loaded already
9478d93489SArmin Le Grand //                    }
95cdf0e10cSrcweir                     const svt::EmbeddedObjectRef& xObjRef  = rSdrOle2.getEmbeddedObjectRef();
96cdf0e10cSrcweir                     if(xObjRef.is())
97cdf0e10cSrcweir                     {
98cdf0e10cSrcweir                         const sal_Int64 nMiscStatus(xObjRef->getStatus(rSdrOle2.GetAspect()));
99cdf0e10cSrcweir 
100cdf0e10cSrcweir                         // this hack (to change model data during PAINT argh(!)) should be reworked
101cdf0e10cSrcweir                         if(!rSdrOle2.IsResizeProtect() && (nMiscStatus & embed::EmbedMisc::EMBED_NEVERRESIZE))
102cdf0e10cSrcweir                         {
103cdf0e10cSrcweir 	                        const_cast< SdrOle2Obj* >(&rSdrOle2)->SetResizeProtect(true);
104cdf0e10cSrcweir                         }
105cdf0e10cSrcweir 
106cdf0e10cSrcweir                         SdrPageView* pPageView = GetObjectContact().TryToGetSdrPageView();
107cdf0e10cSrcweir 	                    if(pPageView && (nMiscStatus & embed::EmbedMisc::MS_EMBED_ACTIVATEWHENVISIBLE))
108cdf0e10cSrcweir 	                    {
109cdf0e10cSrcweir 		                    // connect plugin object
110cdf0e10cSrcweir 		                    pPageView->GetView().DoConnect(const_cast< SdrOle2Obj* >(&rSdrOle2));
111cdf0e10cSrcweir 	                    }
112cdf0e10cSrcweir                     }
113cdf0e10cSrcweir                 }//end old stuff to rework
114cdf0e10cSrcweir 
115cdf0e10cSrcweir                 // create OLE primitive stuff directly at VC with HC as parameter
116cdf0e10cSrcweir 		        const ViewContactOfSdrOle2Obj& rVC = static_cast< const ViewContactOfSdrOle2Obj& >(GetViewContact());
117cdf0e10cSrcweir                 xRetval = rVC.createPrimitive2DSequenceWithParameters(GetObjectContact().isDrawModeHighContrast());
118cdf0e10cSrcweir 
119cdf0e10cSrcweir                 if(bIsOutplaceActive)
120cdf0e10cSrcweir 		        {
121cdf0e10cSrcweir 			        // do not shade when printing or PDF exporting
122cdf0e10cSrcweir 			        if(!GetObjectContact().isOutputToPrinter() && !GetObjectContact().isOutputToRecordingMetaFile())
123cdf0e10cSrcweir 			        {
12478d93489SArmin Le Grand                         // get object transformation
12578d93489SArmin Le Grand                         const basegfx::B2DHomMatrix aObjectMatrix(static_cast< ViewContactOfSdrOle2Obj& >(GetViewContact()).createObjectTransform());
12678d93489SArmin Le Grand 
127cdf0e10cSrcweir                         // shade the representation if the object is activated outplace
128cdf0e10cSrcweir 				        basegfx::B2DPolygon aObjectOutline(basegfx::tools::createUnitPolygon());
12978d93489SArmin Le Grand 				        aObjectOutline.transform(aObjectMatrix);
130cdf0e10cSrcweir 
131cdf0e10cSrcweir 				        // Use a FillHatchPrimitive2D with necessary attributes
132cdf0e10cSrcweir 				        const drawinglayer::attribute::FillHatchAttribute aFillHatch(
133cdf0e10cSrcweir 					        drawinglayer::attribute::HATCHSTYLE_SINGLE, // single hatch
134cdf0e10cSrcweir 					        125.0, // 1.25 mm
135cdf0e10cSrcweir 					        45.0 * F_PI180, // 45 degree diagonal
136cdf0e10cSrcweir 					        Color(COL_BLACK).getBColor(), // black color
137*0702bc67SArmin Le Grand                             3, // same default as VCL, a minimum of three discrete units (pixels) offset
138cdf0e10cSrcweir 					        false); // no filling
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 				        const drawinglayer::primitive2d::Primitive2DReference xReference(new drawinglayer::primitive2d::PolyPolygonHatchPrimitive2D(
141cdf0e10cSrcweir 					        basegfx::B2DPolyPolygon(aObjectOutline),
142cdf0e10cSrcweir 					        Color(COL_BLACK).getBColor(),
143cdf0e10cSrcweir 					        aFillHatch));
144cdf0e10cSrcweir 
145cdf0e10cSrcweir 				        drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(xRetval, xReference);
146cdf0e10cSrcweir 			        }
147cdf0e10cSrcweir 		        }
148cdf0e10cSrcweir 
149cdf0e10cSrcweir             }
150cdf0e10cSrcweir 
151cdf0e10cSrcweir 		    return xRetval;
152cdf0e10cSrcweir 		}
153cdf0e10cSrcweir 
ViewObjectContactOfSdrOle2Obj(ObjectContact & rObjectContact,ViewContact & rViewContact)154cdf0e10cSrcweir 		ViewObjectContactOfSdrOle2Obj::ViewObjectContactOfSdrOle2Obj(ObjectContact& rObjectContact, ViewContact& rViewContact)
155cdf0e10cSrcweir 		:	ViewObjectContactOfSdrObj(rObjectContact, rViewContact)
156cdf0e10cSrcweir 		{
157cdf0e10cSrcweir 		}
158cdf0e10cSrcweir 
~ViewObjectContactOfSdrOle2Obj()159cdf0e10cSrcweir 		ViewObjectContactOfSdrOle2Obj::~ViewObjectContactOfSdrOle2Obj()
160cdf0e10cSrcweir 		{
161cdf0e10cSrcweir 		}
162cdf0e10cSrcweir 	} // end of namespace contact
163cdf0e10cSrcweir } // end of namespace sdr
164cdf0e10cSrcweir 
165cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
166cdf0e10cSrcweir // eof
167