LibreOffice Module svx (master)  1
viewobjectcontactofsdrole2obj.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
23 #include <svx/svdoole2.hxx>
25 #include <svx/svdpagv.hxx>
26 #include <svx/svdview.hxx>
29 #include <com/sun/star/embed/EmbedMisc.hpp>
30 #include <com/sun/star/embed/EmbedStates.hpp>
31 #include <com/sun/star/embed/XEmbeddedObject.hpp>
34 #include <svtools/embedhlp.hxx>
35 
36 using namespace com::sun::star;
37 
38 namespace sdr { namespace contact {
39 
40 drawinglayer::primitive2d::Primitive2DContainer ViewObjectContactOfSdrOle2Obj::createPrimitive2DSequence(
41  const DisplayInfo& /*rDisplayInfo*/) const
42 {
43  // override this method to do some things the old SdrOle2Obj::DoPaintObject did.
44  // In the future, some of these may be solved different, but ATM try to stay compatible
45  // with the old behaviour
47  const SdrOle2Obj& rSdrOle2 = static_cast< ViewContactOfSdrOle2Obj& >(GetViewContact()).GetOle2Obj();
48  sal_Int32 nState(-1);
49 
50  {
51  const svt::EmbeddedObjectRef& xObjRef = rSdrOle2.getEmbeddedObjectRef();
52  if ( xObjRef.is() )
53  nState = xObjRef->getCurrentState();
54  }
55 
56  const bool bIsOutplaceActive(nState == embed::EmbedStates::ACTIVE);
57  const bool bIsInplaceActive((nState == embed::EmbedStates::INPLACE_ACTIVE) || (nState == embed::EmbedStates::UI_ACTIVE));
58  bool bDone(false);
59 
60  if (bIsInplaceActive)
61  {
62  if( !GetObjectContact().isOutputToPrinter() && !GetObjectContact().isOutputToRecordingMetaFile() )
63  {
64  //no need to create a primitive sequence here as the OLE object does render itself
65  //in case of charts the superfluous creation of a metafile is strongly performance relevant!
66  bDone = true;
67  }
68  }
69 
70  if( !bDone )
71  {
72  //old stuff that should be reworked
73  {
74  //if no replacement image is available load the OLE object
75 // 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#
76 // {
77 // // try to create embedded object
78 // rSdrOle2.GetObjRef(); //this loads the OLE object if it is not loaded already
79 // }
80  const svt::EmbeddedObjectRef& xObjRef = rSdrOle2.getEmbeddedObjectRef();
81  if(xObjRef.is())
82  {
83  const sal_Int64 nMiscStatus(xObjRef->getStatus(rSdrOle2.GetAspect()));
84 
85  // this hack (to change model data during PAINT argh(!)) should be reworked
86  if(!rSdrOle2.IsResizeProtect() && (nMiscStatus & embed::EmbedMisc::EMBED_NEVERRESIZE))
87  {
88  const_cast< SdrOle2Obj* >(&rSdrOle2)->SetResizeProtect(true);
89  }
90 
91  SdrPageView* pPageView = GetObjectContact().TryToGetSdrPageView();
92  if(pPageView && (nMiscStatus & embed::EmbedMisc::MS_EMBED_ACTIVATEWHENVISIBLE))
93  {
94  // connect plugin object
95  pPageView->GetView().DoConnect(const_cast< SdrOle2Obj* >(&rSdrOle2));
96  }
97  }
98  }//end old stuff to rework
99 
100  // create OLE primitive stuff directly at VC with HC as parameter
101  const ViewContactOfSdrOle2Obj& rVC = static_cast< const ViewContactOfSdrOle2Obj& >(GetViewContact());
103 
104  if(bIsOutplaceActive)
105  {
106  // do not shade when printing or PDF exporting
107  if(!GetObjectContact().isOutputToPrinter() && !GetObjectContact().isOutputToRecordingMetaFile())
108  {
109  // get object transformation
110  const basegfx::B2DHomMatrix aObjectMatrix(static_cast< ViewContactOfSdrOle2Obj& >(GetViewContact()).createObjectTransform());
111 
112  // shade the representation if the object is activated outplace
114  aObjectOutline.transform(aObjectMatrix);
115 
116  // Use a FillHatchPrimitive2D with necessary attributes
119  125.0, // 1.25 mm
120  basegfx::deg2rad(45.0), // 45 degree diagonal
121  COL_BLACK.getBColor(), // black color
122  3, // same default as VCL, a minimum of three discrete units (pixels) offset
123  false); // no filling
124 
126  basegfx::B2DPolyPolygon(aObjectOutline),
127  COL_BLACK.getBColor(),
128  aFillHatch));
129 
130  xRetval.push_back(xReference);
131  }
132  }
133 
134  }
135 
136  return xRetval;
137 }
138 
139 ViewObjectContactOfSdrOle2Obj::ViewObjectContactOfSdrOle2Obj(ObjectContact& rObjectContact, ViewContact& rViewContact)
140 : ViewObjectContactOfSdrObj(rObjectContact, rViewContact)
141 {
142 }
143 
145 {
146 }
147 
148 }}
149 
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr::Color COL_BLACK(0x00, 0x00, 0x00)
B2DPolygon const & createUnitPolygon()
SdrView & GetView()
Definition: svdpagv.hxx:137
virtual void DoConnect(SdrOle2Obj *pOleObj)
For Plugins Is called by the Paint of the OLE object.
Definition: svdpntv.cxx:1075
drawinglayer::primitive2d::Primitive2DContainer createPrimitive2DSequenceWithParameters() const
const svt::EmbeddedObjectRef & getEmbeddedObjectRef() const
Definition: svdoole2.cxx:770
constexpr double deg2rad(double v)
bool IsResizeProtect() const
Definition: svdobj.hxx:800
void transform(const basegfx::B2DHomMatrix &rMatrix)
sal_Int64 GetAspect() const
Definition: svdoole2.cxx:775
css::uno::Reference< css::graphic::XPrimitive2D > Primitive2DReference
sal_Int32 nState