Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/svx/source/sdr/contact/viewobjectcontactofsdrole2obj.cxx
Line
Count
Source (jump to first uncovered line)
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
20
#include <sdr/contact/viewobjectcontactofsdrole2obj.hxx>
21
#include <svx/sdr/contact/viewobjectcontactofsdrobj.hxx>
22
#include <sdr/contact/viewcontactofsdrole2obj.hxx>
23
#include <svx/svdoole2.hxx>
24
#include <svx/sdr/contact/objectcontact.hxx>
25
#include <svx/svdpagv.hxx>
26
#include <svx/svdview.hxx>
27
#include <drawinglayer/primitive2d/PolyPolygonHatchPrimitive2D.hxx>
28
#include <basegfx/polygon/b2dpolygontools.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>
32
#include <basegfx/polygon/b2dpolygon.hxx>
33
#include <basegfx/matrix/b2dhommatrix.hxx>
34
#include <svtools/embedhlp.hxx>
35
36
using namespace com::sun::star;
37
38
namespace sdr::contact {
39
40
void ViewObjectContactOfSdrOle2Obj::createPrimitive2DSequence(
41
    const DisplayInfo& /*rDisplayInfo*/, drawinglayer::primitive2d::Primitive2DDecompositionVisitor& rVisitor) const
42
0
{
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
46
0
    const SdrOle2Obj& rSdrOle2 = static_cast< ViewContactOfSdrOle2Obj& >(GetViewContact()).GetOle2Obj();
47
0
    sal_Int32 nState(-1);
48
49
0
    {
50
0
        const svt::EmbeddedObjectRef& xObjRef  = rSdrOle2.getEmbeddedObjectRef();
51
0
        if ( xObjRef.is() )
52
0
            nState = xObjRef->getCurrentState();
53
0
    }
54
55
0
    const bool bIsOutplaceActive(nState == embed::EmbedStates::ACTIVE);
56
0
    const bool bIsInplaceActive((nState == embed::EmbedStates::INPLACE_ACTIVE) || (nState == embed::EmbedStates::UI_ACTIVE));
57
0
    bool bDone(false);
58
59
0
    if (bIsInplaceActive)
60
0
    {
61
0
        if( !GetObjectContact().isOutputToPrinter() && !GetObjectContact().isOutputToRecordingMetaFile() )
62
0
        {
63
            //no need to create a primitive sequence here as the OLE object does render itself
64
            //in case of charts the superfluous creation of a metafile is strongly performance relevant!
65
0
            bDone = true;
66
0
        }
67
0
    }
68
69
0
    if( !bDone )
70
0
    {
71
        //old stuff that should be reworked
72
0
        {
73
            //if no replacement image is available load the OLE object
74
//          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#
75
//          {
76
//            // try to create embedded object
77
//              rSdrOle2.GetObjRef(); //this loads the OLE object if it is not loaded already
78
//          }
79
0
            const svt::EmbeddedObjectRef& xObjRef  = rSdrOle2.getEmbeddedObjectRef();
80
0
            if(xObjRef.is())
81
0
            {
82
0
                const sal_Int64 nMiscStatus(xObjRef->getStatus(rSdrOle2.GetAspect()));
83
84
                // this hack (to change model data during PAINT argh(!)) should be reworked
85
0
                if(!rSdrOle2.IsResizeProtect() && (nMiscStatus & embed::EmbedMisc::EMBED_NEVERRESIZE))
86
0
                {
87
0
                    const_cast< SdrOle2Obj* >(&rSdrOle2)->SetResizeProtect(true);
88
0
                }
89
90
0
                SdrPageView* pPageView = GetObjectContact().TryToGetSdrPageView();
91
0
                if(pPageView && (nMiscStatus & embed::EmbedMisc::MS_EMBED_ACTIVATEWHENVISIBLE))
92
0
                {
93
                    // connect plugin object
94
0
                    pPageView->GetView().DoConnect(const_cast< SdrOle2Obj* >(&rSdrOle2));
95
0
                }
96
0
            }
97
0
        }//end old stuff to rework
98
99
        // create OLE primitive stuff directly at VC with HC as parameter
100
0
        const ViewContactOfSdrOle2Obj& rVC = static_cast< const ViewContactOfSdrOle2Obj& >(GetViewContact());
101
0
        rVC.createPrimitive2DSequenceWithParameters(rVisitor);
102
103
0
        if(bIsOutplaceActive)
104
0
        {
105
            // do not shade when printing or PDF exporting
106
0
            if(!GetObjectContact().isOutputToPrinter() && !GetObjectContact().isOutputToRecordingMetaFile())
107
0
            {
108
                // get object transformation
109
0
                const basegfx::B2DHomMatrix aObjectMatrix(static_cast< ViewContactOfSdrOle2Obj& >(GetViewContact()).createObjectTransform());
110
111
                // shade the representation if the object is activated outplace
112
0
                basegfx::B2DPolygon aObjectOutline(basegfx::utils::createUnitPolygon());
113
0
                aObjectOutline.transform(aObjectMatrix);
114
115
                // Use a FillHatchPrimitive2D with necessary attributes
116
0
                drawinglayer::attribute::FillHatchAttribute aFillHatch(
117
0
                    drawinglayer::attribute::HatchStyle::Single, // single hatch
118
0
                    125.0, // 1.25 mm
119
0
                    basegfx::deg2rad(45.0), // 45 degree diagonal
120
0
                    COL_BLACK.getBColor(), // black color
121
0
                    3, // same default as VCL, a minimum of three discrete units (pixels) offset
122
0
                    false); // no filling
123
124
0
                const drawinglayer::primitive2d::Primitive2DReference xReference(new drawinglayer::primitive2d::PolyPolygonHatchPrimitive2D(
125
0
                    basegfx::B2DPolyPolygon(aObjectOutline),
126
0
                    COL_BLACK.getBColor(),
127
0
                    std::move(aFillHatch)));
128
129
0
                rVisitor.visit(xReference);
130
0
            }
131
0
        }
132
133
0
    }
134
0
}
135
136
ViewObjectContactOfSdrOle2Obj::ViewObjectContactOfSdrOle2Obj(ObjectContact& rObjectContact, ViewContact& rViewContact)
137
0
:   ViewObjectContactOfSdrObj(rObjectContact, rViewContact)
138
0
{
139
0
}
140
141
ViewObjectContactOfSdrOle2Obj::~ViewObjectContactOfSdrOle2Obj()
142
0
{
143
0
}
144
145
}
146
147
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */