1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26 
27 #include <svx/sdr/contact/viewcontactofunocontrol.hxx>
28 #include <svx/sdr/contact/viewobjectcontactofunocontrol.hxx>
29 #include <svx/sdr/contact/objectcontactofpageview.hxx>
30 #include <svx/sdr/contact/displayinfo.hxx>
31 #include <svx/svdouno.hxx>
32 #include <svx/svdpagv.hxx>
33 #include <svx/svdview.hxx>
34 #include <svx/sdrpagewindow.hxx>
35 
36 /** === begin UNO includes === **/
37 #include <com/sun/star/awt/XWindow2.hpp>
38 /** === end UNO includes === **/
39 
40 #include "svx/sdrpaintwindow.hxx"
41 #include <tools/diagnose_ex.h>
42 #include <vcl/pdfextoutdevdata.hxx>
43 #include <basegfx/matrix/b2dhommatrix.hxx>
44 #include <drawinglayer/primitive2d/controlprimitive2d.hxx>
45 #include <svx/sdr/contact/displayinfo.hxx>
46 #include <drawinglayer/primitive2d/sdrdecompositiontools2d.hxx>
47 
48 //........................................................................
49 namespace sdr { namespace contact {
50 //........................................................................
51 
52     /** === begin UNO using === **/
53     using ::com::sun::star::awt::XControl;
54     using ::com::sun::star::uno::Reference;
55     using ::com::sun::star::awt::XControlContainer;
56 	using ::com::sun::star::awt::XControlModel;
57     using ::com::sun::star::awt::XWindow2;
58     using ::com::sun::star::uno::UNO_QUERY;
59     using ::com::sun::star::uno::Exception;
60     /** === end UNO using === **/
61 
62     //====================================================================
63 	//= ViewContactOfUnoControl
64 	//====================================================================
65     class ViewContactOfUnoControl_Impl
66     {
67     public:
68         ViewContactOfUnoControl_Impl();
69         ~ViewContactOfUnoControl_Impl();
70 
71     private:
72         ViewContactOfUnoControl_Impl( const ViewContactOfUnoControl_Impl& );            // never implemented
73         ViewContactOfUnoControl_Impl& operator=( const ViewContactOfUnoControl_Impl& ); // never implemented
74     };
75 
76 	//--------------------------------------------------------------------
ViewContactOfUnoControl_Impl()77     ViewContactOfUnoControl_Impl::ViewContactOfUnoControl_Impl()
78     {
79     }
80 
81     //--------------------------------------------------------------------
~ViewContactOfUnoControl_Impl()82     ViewContactOfUnoControl_Impl::~ViewContactOfUnoControl_Impl()
83     {
84     }
85 
86     //====================================================================
87 	//= ViewContactOfUnoControl
88 	//====================================================================
DBG_NAME(ViewContactOfUnoControl)89     DBG_NAME( ViewContactOfUnoControl )
90 	//--------------------------------------------------------------------
91 	ViewContactOfUnoControl::ViewContactOfUnoControl( SdrUnoObj& _rUnoObject )
92         :ViewContactOfSdrObj( _rUnoObject )
93         ,m_pImpl( new ViewContactOfUnoControl_Impl )
94     {
95         DBG_CTOR( ViewContactOfUnoControl, NULL );
96     }
97 
98 	//--------------------------------------------------------------------
~ViewContactOfUnoControl()99     ViewContactOfUnoControl::~ViewContactOfUnoControl()
100     {
101         DBG_DTOR( ViewContactOfUnoControl, NULL );
102     }
103 
104 	//--------------------------------------------------------------------
getTemporaryControlForWindow(const Window & _rWindow,Reference<XControlContainer> & _inout_ControlContainer) const105     Reference< XControl > ViewContactOfUnoControl::getTemporaryControlForWindow(
106         const Window& _rWindow, Reference< XControlContainer >& _inout_ControlContainer ) const
107     {
108         SdrUnoObj* pUnoObject = dynamic_cast< SdrUnoObj* >( TryToGetSdrObject() );
109         OSL_ENSURE( pUnoObject, "ViewContactOfUnoControl::getTemporaryControlForDevice: no SdrUnoObj!" );
110         if ( !pUnoObject )
111             return NULL;
112         return ViewObjectContactOfUnoControl::getTemporaryControlForWindow( _rWindow, _inout_ControlContainer, *pUnoObject );
113     }
114 
115 	//--------------------------------------------------------------------
CreateObjectSpecificViewObjectContact(ObjectContact & _rObjectContact)116     ViewObjectContact& ViewContactOfUnoControl::CreateObjectSpecificViewObjectContact( ObjectContact& _rObjectContact )
117     {
118         // print or print preview requires special handling
119         const OutputDevice* pDevice = _rObjectContact.TryToGetOutputDevice();
120         bool bPrintOrPreview = ( pDevice != NULL ) && ( pDevice->GetOutDevType() == OUTDEV_PRINTER );
121 
122         ObjectContactOfPageView* pPageViewContact = dynamic_cast< ObjectContactOfPageView* >( &_rObjectContact  );
123         bPrintOrPreview |= ( pPageViewContact != NULL ) && pPageViewContact->GetPageWindow().GetPageView().GetView().IsPrintPreview();
124 
125         if ( bPrintOrPreview )
126             return *new UnoControlPrintOrPreviewContact( *pPageViewContact, *this );
127 
128         // all others are nowadays served by the same implementation
129         return *new ViewObjectContactOfUnoControl( _rObjectContact, *this );
130     }
131 
132 	//--------------------------------------------------------------------
createViewIndependentPrimitive2DSequence() const133 	drawinglayer::primitive2d::Primitive2DSequence ViewContactOfUnoControl::createViewIndependentPrimitive2DSequence() const
134 	{
135 		// create range. Use model data directly, not getBoundRect()/getSnapRect; these will use
136         // the primitive data themselves in the long run. Use SdrUnoObj's (which is a SdrRectObj)
137         // call to GetGeoRect() to access SdrTextObj::aRect directly and without executing anything
138 		const Rectangle& rRectangle(GetSdrUnoObj().GetGeoRect());
139 		const basegfx::B2DRange aRange(
140 			rRectangle.Left(), rRectangle.Top(),
141 			rRectangle.Right(), rRectangle.Bottom());
142 
143 		// create object transform
144 		basegfx::B2DHomMatrix aTransform;
145 
146 		aTransform.set(0, 0, aRange.getWidth());
147 		aTransform.set(1, 1, aRange.getHeight());
148 		aTransform.set(0, 2, aRange.getMinX());
149 		aTransform.set(1, 2, aRange.getMinY());
150 
151 		Reference< XControlModel > xControlModel = GetSdrUnoObj().GetUnoControlModel();
152 
153 		if(xControlModel.is())
154 		{
155 			// create control primitive WITHOUT possibly existing XControl; this would be done in
156 			// the VOC in createPrimitive2DSequence()
157 			const drawinglayer::primitive2d::Primitive2DReference xRetval(
158 				new drawinglayer::primitive2d::ControlPrimitive2D(
159 					aTransform,
160 					xControlModel));
161 
162 			return drawinglayer::primitive2d::Primitive2DSequence(&xRetval, 1);
163 		}
164 		else
165 		{
166 			// always append an invisible outline for the cases where no visible content exists
167 			const drawinglayer::primitive2d::Primitive2DReference xRetval(
168 				drawinglayer::primitive2d::createHiddenGeometryPrimitives2D(
169 					false, aTransform));
170 
171 			return drawinglayer::primitive2d::Primitive2DSequence(&xRetval, 1);
172 		}
173 	}
174 
175 //........................................................................
176 } } // namespace sdr::contact
177 //........................................................................
178