1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: viewcontactofunocontrol.cxx,v $
10 * $Revision: 1.12.18.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #include <svx/sdr/contact/viewcontactofunocontrol.hxx>
35 #include <svx/sdr/contact/viewobjectcontactofunocontrol.hxx>
36 #include <svx/sdr/contact/objectcontactofpageview.hxx>
37 #include <svx/sdr/contact/displayinfo.hxx>
38 #include <svx/svdouno.hxx>
39 #include <svx/svdpagv.hxx>
40 #include <svx/svdview.hxx>
41 #include <svx/sdrpagewindow.hxx>
43 /** === begin UNO includes === **/
44 #include <com/sun/star/awt/XWindow2.hpp>
45 /** === end UNO includes === **/
47 #include "sdrpaintwindow.hxx"
48 #include <tools/diagnose_ex.h>
49 #include <vcl/pdfextoutdevdata.hxx>
50 #include <basegfx/matrix/b2dhommatrix.hxx>
51 #include <drawinglayer/primitive2d/controlprimitive2d.hxx>
52 #include <svx/sdr/contact/displayinfo.hxx>
54 //........................................................................
55 namespace sdr
{ namespace contact
{
56 //........................................................................
58 /** === begin UNO using === **/
59 using ::com::sun::star::awt::XControl
;
60 using ::com::sun::star::uno::Reference
;
61 using ::com::sun::star::awt::XControlContainer
;
62 using ::com::sun::star::awt::XControlModel
;
63 using ::com::sun::star::awt::XWindow2
;
64 using ::com::sun::star::uno::UNO_QUERY
;
65 using ::com::sun::star::uno::Exception
;
66 /** === end UNO using === **/
68 //====================================================================
69 //= ViewContactOfUnoControl
70 //====================================================================
71 class ViewContactOfUnoControl_Impl
74 ViewContactOfUnoControl_Impl();
75 ~ViewContactOfUnoControl_Impl();
78 ViewContactOfUnoControl_Impl( const ViewContactOfUnoControl_Impl
& ); // never implemented
79 ViewContactOfUnoControl_Impl
& operator=( const ViewContactOfUnoControl_Impl
& ); // never implemented
82 //--------------------------------------------------------------------
83 ViewContactOfUnoControl_Impl::ViewContactOfUnoControl_Impl()
87 //--------------------------------------------------------------------
88 ViewContactOfUnoControl_Impl::~ViewContactOfUnoControl_Impl()
92 //====================================================================
93 //= ViewContactOfUnoControl
94 //====================================================================
95 DBG_NAME( ViewContactOfUnoControl
)
96 //--------------------------------------------------------------------
97 ViewContactOfUnoControl::ViewContactOfUnoControl( SdrUnoObj
& _rUnoObject
)
98 :ViewContactOfSdrObj( _rUnoObject
)
99 ,m_pImpl( new ViewContactOfUnoControl_Impl
)
101 DBG_CTOR( ViewContactOfUnoControl
, NULL
);
104 //--------------------------------------------------------------------
105 ViewContactOfUnoControl::~ViewContactOfUnoControl()
107 DBG_DTOR( ViewContactOfUnoControl
, NULL
);
110 //--------------------------------------------------------------------
111 Reference
< XControl
> ViewContactOfUnoControl::getTemporaryControlForWindow(
112 const Window
& _rWindow
, Reference
< XControlContainer
>& _inout_ControlContainer
) const
114 SdrUnoObj
* pUnoObject
= dynamic_cast< SdrUnoObj
* >( TryToGetSdrObject() );
115 OSL_ENSURE( pUnoObject
, "ViewContactOfUnoControl::getTemporaryControlForDevice: no SdrUnoObj!" );
118 return ViewObjectContactOfUnoControl::getTemporaryControlForWindow( _rWindow
, _inout_ControlContainer
, *pUnoObject
);
121 //--------------------------------------------------------------------
122 ViewObjectContact
& ViewContactOfUnoControl::CreateObjectSpecificViewObjectContact( ObjectContact
& _rObjectContact
)
124 ObjectContactOfPageView
* pPageViewContact
= dynamic_cast< ObjectContactOfPageView
* >( &_rObjectContact
);
125 if ( pPageViewContact
)
127 // special classes for special devices:
129 ::vcl::PDFExtOutDevData
* pPDFExport
= PTR_CAST( ::vcl::PDFExtOutDevData
, pPageViewContact
->GetPageWindow().GetPaintWindow().GetOutputDevice().GetExtOutDevData() );
130 if ( pPDFExport
!= NULL
)
131 return *new UnoControlPDFExportContact( *pPageViewContact
, *this );
134 if ( pPageViewContact
->GetPageWindow().GetPageView().GetView().IsPrintPreview() )
135 return *new UnoControlPrintOrPreviewContact( *pPageViewContact
, *this );
137 OutDevType eDeviceType
= pPageViewContact
->GetPageWindow().GetPaintWindow().GetOutputDevice().GetOutDevType();
139 if ( eDeviceType
== OUTDEV_PRINTER
)
140 return *new UnoControlPrintOrPreviewContact( *pPageViewContact
, *this );
142 // - any other virtual device
143 if ( eDeviceType
== OUTDEV_VIRDEV
)
144 return *new UnoControlDefaultContact( *pPageViewContact
, *this );
146 // - normal windows have special, design-mode dependent handling
147 if ( eDeviceType
== OUTDEV_WINDOW
)
148 return *new UnoControlWindowContact( *pPageViewContact
, *this );
151 // if we're not working for a ObjectContactOfPageView, then we can't use a ViewObjectContactOfUnoControl, or any
152 // of its derivees. Fall back to a "normal" SdrObj's contact object.
153 return *new ViewObjectContactOfSdrObj( _rObjectContact
, *this );
156 //--------------------------------------------------------------------
157 drawinglayer::primitive2d::Primitive2DSequence
ViewContactOfUnoControl::createViewIndependentPrimitive2DSequence() const
159 Reference
< XControlModel
> xControlModel
= GetSdrUnoObj().GetUnoControlModel();
161 if(xControlModel
.is())
163 // create range. Use model data directly, not getBoundRect()/getSnapRect; these will use
164 // the primitive data themselves in the long run. Use SdrUnoObj's (which is a SdrRectObj)
165 // call to GetGeoRect() to access SdrTextObj::aRect directly and without executing anything
166 const Rectangle
& rRectangle(GetSdrUnoObj().GetGeoRect());
167 const basegfx::B2DRange
aRange(rRectangle
.Left(), rRectangle
.Top(), rRectangle
.Right(), rRectangle
.Bottom());
169 // create object transform
170 basegfx::B2DHomMatrix aTransform
;
171 aTransform
.set(0, 0, aRange
.getWidth());
172 aTransform
.set(1, 1, aRange
.getHeight());
173 aTransform
.set(0, 2, aRange
.getMinX());
174 aTransform
.set(1, 2, aRange
.getMinY());
176 // create control primitive WITHOUT evtl. existing XControl; this would be done in
177 // the VOC in createPrimitive2DSequence()
178 const drawinglayer::primitive2d::Primitive2DReference
xRetval(new drawinglayer::primitive2d::ControlPrimitive2D(
179 aTransform
, xControlModel
));
181 return drawinglayer::primitive2d::Primitive2DSequence(&xRetval
, 1);
185 // #i93161# This UnoControl does not yet have a xControlModel (can happen
186 // during diverse creations). Without a model, create no visualisation.
187 return drawinglayer::primitive2d::Primitive2DSequence();
191 //........................................................................
192 } } // namespace sdr::contact
193 //........................................................................