summaryrefslogtreecommitdiff
path: root/svx/source/sdr/contact/viewobjectcontactofsdrole2obj.cxx
blob: 9c9aaa959c462ea3d836f6eaa4493b434be17618 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 * 
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: viewobjectcontactofsdrole2obj.cxx,v $
 *
 * $Revision: 1.2 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_svx.hxx"

#include <svx/sdr/contact/viewobjectcontactofsdrole2obj.hxx>
#include <svx/sdr/contact/viewobjectcontactofsdrobj.hxx>
#include <svx/sdr/contact/viewcontactofsdrole2obj.hxx>
#include <svx/svdoole2.hxx>
#include <svx/sdr/contact/objectcontact.hxx>
#include <svx/svdview.hxx>
#include <drawinglayer/primitive2d/chartprimitive2d.hxx>
#include <drawinglayer/attribute/fillattribute.hxx>
#include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
#include <basegfx/polygon/b2dpolygontools.hxx>
#include <com/sun/star/embed/EmbedMisc.hpp>
#include <com/sun/star/embed/EmbedStates.hpp>

//////////////////////////////////////////////////////////////////////////////

using namespace com::sun::star;

//////////////////////////////////////////////////////////////////////////////

namespace sdr
{
    namespace contact
    {
        const SdrOle2Obj& ViewObjectContactOfSdrOle2Obj::getSdrOle2Object() const
        {
            return static_cast< ViewContactOfSdrOle2Obj& >(GetViewContact()).GetOle2Obj();
        }

        drawinglayer::primitive2d::Primitive2DSequence ViewObjectContactOfSdrOle2Obj::createPrimitive2DSequence(
            const DisplayInfo& /*rDisplayInfo*/) const
        {
            // this method is overloaded to do some things the old SdrOle2Obj::DoPaintObject did.
            // In the future, some of these may be solved different, but ATM try to stay compatible
            // with the old behaviour
            drawinglayer::primitive2d::Primitive2DSequence xRetval;
            const SdrOle2Obj& rSdrOle2 = getSdrOle2Object();
            sal_Int32 nState(-1);

            {
                const svt::EmbeddedObjectRef& xObjRef  = rSdrOle2.getEmbeddedObjectRef();
                if ( xObjRef.is() )
                    nState = xObjRef->getCurrentState();
            }

            const bool bIsOutplaceActive(nState == embed::EmbedStates::ACTIVE);
            const bool bIsInplaceActive((nState == embed::EmbedStates::INPLACE_ACTIVE) || (nState == embed::EmbedStates::UI_ACTIVE));
            const bool bIsChart(rSdrOle2.IsChart());
            bool bDone(false);
 
            if(!bDone && bIsInplaceActive)
            {
                if( !GetObjectContact().isOutputToPrinter() && !GetObjectContact().isOutputToRecordingMetaFile() )
                {
                    //no need to create a primitive sequence here as the OLE object does render itself
                    //in case of charts the superfluous creation of a metafile is strongly performance relevant!
                    bDone = true;
                }
            }

            if( !bDone )
            {
                const Rectangle& rObjectRectangle(rSdrOle2.GetGeoRect());
                const basegfx::B2DRange aObjectRange(rObjectRectangle.Left(), rObjectRectangle.Top(), rObjectRectangle.Right(), rObjectRectangle.Bottom());

                // create object transform
                basegfx::B2DHomMatrix aObjectTransform;
                aObjectTransform.set(0, 0, aObjectRange.getWidth());
                aObjectTransform.set(1, 1, aObjectRange.getHeight());
                aObjectTransform.set(0, 2, aObjectRange.getMinX());
                aObjectTransform.set(1, 2, aObjectRange.getMinY());

                if(bIsChart)
                {
                    //charts must be painted resolution dependent!! #i82893#, #i75867#

                    // for chart, to not lose the current better quality visualisation which
                    // uses a direct paint, use a primtive wrapper for that exceptional case. The renderers
                    // will then ATM paint it to an OutputDevice directly.
                    // In later versions this should be replaced by getting the Primitive2DSequnce from
                    // the chart and using it.
                    // to be able to render something in non-VCL using renderers, the wrapper is a
                    // GroupPrimitive2D which automatically decomposes to the already created Metafile
                    // content.
                    // For being completely compatible, ATM Window and VDEV PrettyPrinting is suppressed.
                    // It works in the VCL renderers, though. So for activating again with VCL primitive
                    // renderers, change conditions here.

                    // determine if embedding and PrettyPrinting shall be done at all
                    uno::Reference< frame::XModel > xChartModel;
                    bool bDoChartPrettyPrinting(true);
                    
                    // the original ChartPrettyPainter does not do it for Window
                    if(bDoChartPrettyPrinting && GetObjectContact().isOutputToWindow())
                    {
                        bDoChartPrettyPrinting = false;
                    }

                    // the original ChartPrettyPainter does not do it for VDEV
                    if(bDoChartPrettyPrinting && GetObjectContact().isOutputToVirtualDevice())
                    {
                        if(GetObjectContact().isOutputToPDFFile())
                        {
                            // #i97982#
                            // For PDF files, allow PrettyPrinting
                        }
                        else
                        {
                            bDoChartPrettyPrinting = false;
                        }
                    }

                    // the chart model is needed. Check if it's available
                    if(bDoChartPrettyPrinting)
                    {
                        // get chart model
                        xChartModel = rSdrOle2.getXModel();

                        if(!xChartModel.is())
                        {
                            bDoChartPrettyPrinting = false;
                        }
                    }

                    if(bDoChartPrettyPrinting)
                    {
                        // embed MetaFile data in a specialized Wrapper Primitive which holds also the ChartModel needed
                        // for PrettyPrinting
                        const drawinglayer::primitive2d::Primitive2DReference xReference(new drawinglayer::primitive2d::ChartPrimitive2D(
                            xChartModel, aObjectTransform, xRetval));
                        xRetval = drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
                        bDone = true;
                    }
                }

                if( !bDone )
                {
                    //old stuff that should be reworked
                    {
                        //if no replacement image is available load the OLE object
                        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#
                        {
                            // try to create embedded object
                            rSdrOle2.GetObjRef(); //this loads the OLE object if it is not loaded already
                        }
                        const svt::EmbeddedObjectRef& xObjRef  = rSdrOle2.getEmbeddedObjectRef();
                        if(xObjRef.is())
                        {
                            const sal_Int64 nMiscStatus(xObjRef->getStatus(rSdrOle2.GetAspect()));

                            // this hack (to change model data during PAINT argh(!)) should be reworked
                            if(!rSdrOle2.IsResizeProtect() && (nMiscStatus & embed::EmbedMisc::EMBED_NEVERRESIZE))
                            {
                                const_cast< SdrOle2Obj* >(&rSdrOle2)->SetResizeProtect(true);
                            }

                            SdrPageView* pPageView = GetObjectContact().TryToGetSdrPageView();
                            if(pPageView && (nMiscStatus & embed::EmbedMisc::MS_EMBED_ACTIVATEWHENVISIBLE))
                            {
                                // connect plugin object
                                pPageView->GetView().DoConnect(const_cast< SdrOle2Obj* >(&rSdrOle2));
                            }
                        }
                    }//end old stuff to rework

                    // create OLE primitive stuff directly at VC with HC as parameter
                    const ViewContactOfSdrOle2Obj& rVC = static_cast< const ViewContactOfSdrOle2Obj& >(GetViewContact());
                    xRetval = rVC.createPrimitive2DSequenceWithParameters(GetObjectContact().isDrawModeHighContrast());
                }

                if(bIsOutplaceActive)
                {
                    // do not shade when printing or PDF exporting
                    if(!GetObjectContact().isOutputToPrinter() && !GetObjectContact().isOutputToRecordingMetaFile())
                    {
                        // shade the representation if the object is activated outplace
                        basegfx::B2DPolygon aObjectOutline(basegfx::tools::createPolygonFromRect(basegfx::B2DRange(0.0, 0.0, 1.0, 1.0)));
                        aObjectOutline.transform(aObjectTransform);

                        // Use a FillHatchPrimitive2D with necessary attributes
                        const drawinglayer::attribute::FillHatchAttribute aFillHatch(
                            drawinglayer::attribute::HATCHSTYLE_SINGLE, // single hatch
                            125.0, // 1.25 mm
                            45.0 * F_PI180, // 45 degree diagonal
                            Color(COL_BLACK).getBColor(), // black color
                            false); // no filling

                        const drawinglayer::primitive2d::Primitive2DReference xReference(new drawinglayer::primitive2d::PolyPolygonHatchPrimitive2D(
                            basegfx::B2DPolyPolygon(aObjectOutline), 
                            Color(COL_BLACK).getBColor(), 
                            aFillHatch));

                        drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(xRetval, xReference);
                    }
                }

            }
            
            return xRetval;
        }

        ViewObjectContactOfSdrOle2Obj::ViewObjectContactOfSdrOle2Obj(ObjectContact& rObjectContact, ViewContact& rViewContact)
        :	ViewObjectContactOfSdrObj(rObjectContact, rViewContact)
        {
        }

        ViewObjectContactOfSdrOle2Obj::~ViewObjectContactOfSdrOle2Obj()
        {
        }
    } // end of namespace contact
} // end of namespace sdr

//////////////////////////////////////////////////////////////////////////////
// eof