cid#1606940 Check of thread-shared field evades lock acquisition
[LibreOffice.git] / svx / source / sdr / contact / viewcontactofunocontrol.cxx
blob3018551d817558f3828bc0b6e35dfcf787ce7071
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
22 #include <sdr/contact/viewcontactofunocontrol.hxx>
23 #include <sdr/contact/viewobjectcontactofunocontrol.hxx>
24 #include <svx/sdr/contact/objectcontactofpageview.hxx>
25 #include <svx/svdouno.hxx>
26 #include <svx/svdpagv.hxx>
27 #include <svx/svdview.hxx>
28 #include <svx/sdrpagewindow.hxx>
30 #include <vcl/canvastools.hxx>
31 #include <basegfx/matrix/b2dhommatrix.hxx>
32 #include <drawinglayer/primitive2d/controlprimitive2d.hxx>
33 #include <drawinglayer/primitive2d/sdrdecompositiontools2d.hxx>
34 #include <osl/diagnose.h>
37 namespace sdr::contact {
40 using ::com::sun::star::awt::XControl;
41 using ::com::sun::star::uno::Reference;
42 using ::com::sun::star::awt::XControlContainer;
43 using ::com::sun::star::awt::XControlModel;
46 //= ViewContactOfUnoControl
48 ViewContactOfUnoControl::ViewContactOfUnoControl( SdrUnoObj& _rUnoObject )
49 :ViewContactOfSdrObj( _rUnoObject )
54 ViewContactOfUnoControl::~ViewContactOfUnoControl()
59 Reference< XControl > ViewContactOfUnoControl::getTemporaryControlForWindow(
60 const vcl::Window& _rWindow, Reference< XControlContainer >& _inout_ControlContainer ) const
62 SdrUnoObj* pUnoObject = dynamic_cast< SdrUnoObj* >( TryToGetSdrObject() );
63 OSL_ENSURE( pUnoObject, "ViewContactOfUnoControl::getTemporaryControlForDevice: no SdrUnoObj!" );
64 if ( !pUnoObject )
65 return nullptr;
66 return ViewObjectContactOfUnoControl::getTemporaryControlForWindow( _rWindow, _inout_ControlContainer, *pUnoObject );
70 ViewObjectContact& ViewContactOfUnoControl::CreateObjectSpecificViewObjectContact( ObjectContact& _rObjectContact )
72 // print or print preview requires special handling
73 const OutputDevice* pDevice = _rObjectContact.TryToGetOutputDevice();
74 ObjectContactOfPageView* const pPageViewContact = dynamic_cast< ObjectContactOfPageView* >( &_rObjectContact );
76 const bool bPrintOrPreview = pPageViewContact
77 && ( ( ( pDevice != nullptr ) && ( pDevice->GetOutDevType() == OUTDEV_PRINTER ) )
78 || pPageViewContact->GetPageWindow().GetPageView().GetView().IsPrintPreview()
82 if ( bPrintOrPreview )
83 return *new UnoControlPrintOrPreviewContact( *pPageViewContact, *this );
85 // all others are nowadays served by the same implementation
86 return *new ViewObjectContactOfUnoControl( _rObjectContact, *this );
90 void ViewContactOfUnoControl::createViewIndependentPrimitive2DSequence(drawinglayer::primitive2d::Primitive2DDecompositionVisitor& rVisitor) const
92 // create range. Use model data directly, not getBoundRect()/getSnapRect; these will use
93 // the primitive data themselves in the long run. Use SdrUnoObj's (which is a SdrRectObj)
94 // call to GetGeoRect() to access SdrTextObj::aRect directly and without executing anything
95 const basegfx::B2DRange aRange = vcl::unotools::b2DRectangleFromRectangle(GetSdrUnoObj().GetGeoRect());
97 // create object transform
98 basegfx::B2DHomMatrix aTransform;
100 aTransform.set(0, 0, aRange.getWidth());
101 aTransform.set(1, 1, aRange.getHeight());
102 aTransform.set(0, 2, aRange.getMinX());
103 aTransform.set(1, 2, aRange.getMinY());
105 Reference< XControlModel > xControlModel = GetSdrUnoObj().GetUnoControlModel();
107 if(xControlModel.is())
109 void const* pAnchorKey(nullptr);
110 if (auto const pUserCall = GetSdrObject().GetUserCall())
112 pAnchorKey = pUserCall->GetPDFAnchorStructureElementKey(GetSdrObject());
115 // create control primitive WITHOUT possibly existing XControl; this would be done in
116 // the VOC in createPrimitive2DSequence()
117 const drawinglayer::primitive2d::Primitive2DReference xRetval(
118 new drawinglayer::primitive2d::ControlPrimitive2D(
119 aTransform,
120 xControlModel,
121 nullptr,
122 GetSdrObject().GetTitle(),
123 GetSdrObject().GetDescription(),
124 pAnchorKey));
126 rVisitor.visit(xRetval);
128 else
130 // always append an invisible outline for the cases where no visible content exists
131 const drawinglayer::primitive2d::Primitive2DReference xRetval(
132 drawinglayer::primitive2d::createHiddenGeometryPrimitives2D(
133 aTransform));
135 rVisitor.visit(xRetval);
140 } // namespace sdr::contact
143 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */