Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / svx / source / sdr / contact / viewcontactofunocontrol.cxx
blob7df1f041631d3ca6f96f52366d82cc69ef6fbe2e
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 <sdr/contact/objectcontactofpageview.hxx>
25 #include <svx/sdr/contact/displayinfo.hxx>
26 #include <svx/svdouno.hxx>
27 #include <svx/svdpagv.hxx>
28 #include <svx/svdview.hxx>
29 #include <svx/sdrpagewindow.hxx>
31 #include "svx/sdrpaintwindow.hxx"
32 #include <tools/diagnose_ex.h>
33 #include <vcl/pdfextoutdevdata.hxx>
34 #include <basegfx/matrix/b2dhommatrix.hxx>
35 #include <drawinglayer/primitive2d/controlprimitive2d.hxx>
36 #include <drawinglayer/primitive2d/sdrdecompositiontools2d.hxx>
39 namespace sdr { namespace contact {
42 using ::com::sun::star::awt::XControl;
43 using ::com::sun::star::uno::Reference;
44 using ::com::sun::star::awt::XControlContainer;
45 using ::com::sun::star::awt::XControlModel;
48 //= ViewContactOfUnoControl
50 ViewContactOfUnoControl::ViewContactOfUnoControl( SdrUnoObj& _rUnoObject )
51 :ViewContactOfSdrObj( _rUnoObject )
56 ViewContactOfUnoControl::~ViewContactOfUnoControl()
61 Reference< XControl > ViewContactOfUnoControl::getTemporaryControlForWindow(
62 const vcl::Window& _rWindow, Reference< XControlContainer >& _inout_ControlContainer ) const
64 SdrUnoObj* pUnoObject = dynamic_cast< SdrUnoObj* >( TryToGetSdrObject() );
65 OSL_ENSURE( pUnoObject, "ViewContactOfUnoControl::getTemporaryControlForDevice: no SdrUnoObj!" );
66 if ( !pUnoObject )
67 return nullptr;
68 return ViewObjectContactOfUnoControl::getTemporaryControlForWindow( _rWindow, _inout_ControlContainer, *pUnoObject );
72 ViewObjectContact& ViewContactOfUnoControl::CreateObjectSpecificViewObjectContact( ObjectContact& _rObjectContact )
74 // print or print preview requires special handling
75 const OutputDevice* pDevice = _rObjectContact.TryToGetOutputDevice();
76 ObjectContactOfPageView* const pPageViewContact = dynamic_cast< ObjectContactOfPageView* >( &_rObjectContact );
78 const bool bPrintOrPreview = pPageViewContact
79 && ( ( ( pDevice != nullptr ) && ( pDevice->GetOutDevType() == OUTDEV_PRINTER ) )
80 || pPageViewContact->GetPageWindow().GetPageView().GetView().IsPrintPreview()
84 if ( bPrintOrPreview )
85 return *new UnoControlPrintOrPreviewContact( *pPageViewContact, *this );
87 // all others are nowadays served by the same implementation
88 return *new ViewObjectContactOfUnoControl( _rObjectContact, *this );
92 drawinglayer::primitive2d::Primitive2DContainer ViewContactOfUnoControl::createViewIndependentPrimitive2DSequence() const
94 // create range. Use model data directly, not getBoundRect()/getSnapRect; these will use
95 // the primitive data themselves in the long run. Use SdrUnoObj's (which is a SdrRectObj)
96 // call to GetGeoRect() to access SdrTextObj::aRect directly and without executing anything
97 tools::Rectangle aRectangle(GetSdrUnoObj().GetGeoRect());
98 // Hack for calc, transform position of object according
99 // to current zoom so as objects relative position to grid
100 // appears stable
101 Point aGridOffset = GetSdrUnoObj().GetGridOffset();
102 aRectangle += aGridOffset;
103 const basegfx::B2DRange aRange(
104 aRectangle.Left(), aRectangle.Top(),
105 aRectangle.Right(), aRectangle.Bottom());
107 // create object transform
108 basegfx::B2DHomMatrix aTransform;
110 aTransform.set(0, 0, aRange.getWidth());
111 aTransform.set(1, 1, aRange.getHeight());
112 aTransform.set(0, 2, aRange.getMinX());
113 aTransform.set(1, 2, aRange.getMinY());
115 Reference< XControlModel > xControlModel = GetSdrUnoObj().GetUnoControlModel();
117 if(xControlModel.is())
119 // create control primitive WITHOUT possibly existing XControl; this would be done in
120 // the VOC in createPrimitive2DSequence()
121 const drawinglayer::primitive2d::Primitive2DReference xRetval(
122 new drawinglayer::primitive2d::ControlPrimitive2D(
123 aTransform,
124 xControlModel));
126 return drawinglayer::primitive2d::Primitive2DContainer { 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 return drawinglayer::primitive2d::Primitive2DContainer { xRetval };
140 } } // namespace sdr::contact
143 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */