1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 #include <svx/sdr/contact/viewcontactofunocontrol.hxx>
22 #include <svx/sdr/contact/viewobjectcontactofunocontrol.hxx>
23 #include <svx/sdr/contact/objectcontactofpageview.hxx>
24 #include <svx/sdr/contact/displayinfo.hxx>
25 #include <svx/svdouno.hxx>
26 #include <svx/svdpagv.hxx>
27 #include <svx/svdview.hxx>
28 #include <svx/sdrpagewindow.hxx>
30 #include <com/sun/star/awt/XWindow2.hpp>
32 #include "svx/sdrpaintwindow.hxx"
33 #include <tools/diagnose_ex.h>
34 #include <vcl/pdfextoutdevdata.hxx>
35 #include <basegfx/matrix/b2dhommatrix.hxx>
36 #include <drawinglayer/primitive2d/controlprimitive2d.hxx>
37 #include <drawinglayer/primitive2d/sdrdecompositiontools2d.hxx>
39 //........................................................................
40 namespace sdr
{ namespace contact
{
41 //........................................................................
43 using ::com::sun::star::awt::XControl
;
44 using ::com::sun::star::uno::Reference
;
45 using ::com::sun::star::awt::XControlContainer
;
46 using ::com::sun::star::awt::XControlModel
;
47 using ::com::sun::star::awt::XWindow2
;
48 using ::com::sun::star::uno::UNO_QUERY
;
49 using ::com::sun::star::uno::Exception
;
51 //====================================================================
52 //= ViewContactOfUnoControl
53 //====================================================================
54 class ViewContactOfUnoControl_Impl
57 ViewContactOfUnoControl_Impl();
58 ~ViewContactOfUnoControl_Impl();
61 ViewContactOfUnoControl_Impl( const ViewContactOfUnoControl_Impl
& ); // never implemented
62 ViewContactOfUnoControl_Impl
& operator=( const ViewContactOfUnoControl_Impl
& ); // never implemented
65 //--------------------------------------------------------------------
66 ViewContactOfUnoControl_Impl::ViewContactOfUnoControl_Impl()
70 //--------------------------------------------------------------------
71 ViewContactOfUnoControl_Impl::~ViewContactOfUnoControl_Impl()
75 //====================================================================
76 //= ViewContactOfUnoControl
77 //====================================================================
78 DBG_NAME( ViewContactOfUnoControl
)
79 //--------------------------------------------------------------------
80 ViewContactOfUnoControl::ViewContactOfUnoControl( SdrUnoObj
& _rUnoObject
)
81 :ViewContactOfSdrObj( _rUnoObject
)
82 ,m_pImpl( new ViewContactOfUnoControl_Impl
)
84 DBG_CTOR( ViewContactOfUnoControl
, NULL
);
87 //--------------------------------------------------------------------
88 ViewContactOfUnoControl::~ViewContactOfUnoControl()
90 DBG_DTOR( ViewContactOfUnoControl
, NULL
);
93 //--------------------------------------------------------------------
94 Reference
< XControl
> ViewContactOfUnoControl::getTemporaryControlForWindow(
95 const Window
& _rWindow
, Reference
< XControlContainer
>& _inout_ControlContainer
) const
97 SdrUnoObj
* pUnoObject
= dynamic_cast< SdrUnoObj
* >( TryToGetSdrObject() );
98 OSL_ENSURE( pUnoObject
, "ViewContactOfUnoControl::getTemporaryControlForDevice: no SdrUnoObj!" );
101 return ViewObjectContactOfUnoControl::getTemporaryControlForWindow( _rWindow
, _inout_ControlContainer
, *pUnoObject
);
104 //--------------------------------------------------------------------
105 ViewObjectContact
& ViewContactOfUnoControl::CreateObjectSpecificViewObjectContact( ObjectContact
& _rObjectContact
)
107 // print or print preview requires special handling
108 const OutputDevice
* pDevice
= _rObjectContact
.TryToGetOutputDevice();
109 bool bPrintOrPreview
= ( pDevice
!= NULL
) && ( pDevice
->GetOutDevType() == OUTDEV_PRINTER
);
111 ObjectContactOfPageView
* pPageViewContact
= dynamic_cast< ObjectContactOfPageView
* >( &_rObjectContact
);
112 bPrintOrPreview
|= ( pPageViewContact
!= NULL
) && pPageViewContact
->GetPageWindow().GetPageView().GetView().IsPrintPreview();
114 if ( bPrintOrPreview
)
115 return *new UnoControlPrintOrPreviewContact( *pPageViewContact
, *this );
117 // all others are nowadays served by the same implementation
118 return *new ViewObjectContactOfUnoControl( _rObjectContact
, *this );
121 //--------------------------------------------------------------------
122 drawinglayer::primitive2d::Primitive2DSequence
ViewContactOfUnoControl::createViewIndependentPrimitive2DSequence() const
124 // create range. Use model data directly, not getBoundRect()/getSnapRect; these will use
125 // the primitive data themselves in the long run. Use SdrUnoObj's (which is a SdrRectObj)
126 // call to GetGeoRect() to access SdrTextObj::aRect directly and without executing anything
127 Rectangle
aRectangle(GetSdrUnoObj().GetGeoRect());
128 // Hack for calc, transform position of object according
129 // to current zoom so as objects relative position to grid
131 Point aGridOffset
= GetSdrUnoObj().GetGridOffset();
132 aRectangle
+= aGridOffset
;
133 const basegfx::B2DRange
aRange(
134 aRectangle
.Left(), aRectangle
.Top(),
135 aRectangle
.Right(), aRectangle
.Bottom());
137 // create object transform
138 basegfx::B2DHomMatrix aTransform
;
140 aTransform
.set(0, 0, aRange
.getWidth());
141 aTransform
.set(1, 1, aRange
.getHeight());
142 aTransform
.set(0, 2, aRange
.getMinX());
143 aTransform
.set(1, 2, aRange
.getMinY());
145 Reference
< XControlModel
> xControlModel
= GetSdrUnoObj().GetUnoControlModel();
147 if(xControlModel
.is())
149 // create control primitive WITHOUT possibly existing XControl; this would be done in
150 // the VOC in createPrimitive2DSequence()
151 const drawinglayer::primitive2d::Primitive2DReference
xRetval(
152 new drawinglayer::primitive2d::ControlPrimitive2D(
156 return drawinglayer::primitive2d::Primitive2DSequence(&xRetval
, 1);
160 // always append an invisible outline for the cases where no visible content exists
161 const drawinglayer::primitive2d::Primitive2DReference
xRetval(
162 drawinglayer::primitive2d::createHiddenGeometryPrimitives2D(
165 return drawinglayer::primitive2d::Primitive2DSequence(&xRetval
, 1);
169 //........................................................................
170 } } // namespace sdr::contact
171 //........................................................................
173 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */