xref: /AOO41X/main/svx/source/svdraw/svdouno.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_svx.hxx"
30*cdf0e10cSrcweir #include <svx/sdr/contact/viewcontactofunocontrol.hxx>
31*cdf0e10cSrcweir #include <svx/sdr/contact/viewobjectcontactofunocontrol.hxx>
32*cdf0e10cSrcweir #include <com/sun/star/container/XChild.hpp>
33*cdf0e10cSrcweir #include <com/sun/star/awt/XWindow.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/awt/PosSize.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/io/XPersistObject.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/io/XOutputStream.hpp>
38*cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp>
39*cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSink.hpp>
40*cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSource.hpp>
41*cdf0e10cSrcweir #include <com/sun/star/io/XObjectOutputStream.hpp>
42*cdf0e10cSrcweir #include <com/sun/star/io/XObjectInputStream.hpp>
43*cdf0e10cSrcweir #include <com/sun/star/util/XCloneable.hpp>
44*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
45*cdf0e10cSrcweir #include <comphelper/types.hxx>
46*cdf0e10cSrcweir #include <vcl/pdfextoutdevdata.hxx>
47*cdf0e10cSrcweir #include <svx/svdouno.hxx>
48*cdf0e10cSrcweir #include <svx/svdpagv.hxx>
49*cdf0e10cSrcweir #include <svx/svdmodel.hxx>
50*cdf0e10cSrcweir #include "svx/svdglob.hxx"  // Stringcache
51*cdf0e10cSrcweir #include "svx/svdstr.hrc"   // Objektname
52*cdf0e10cSrcweir #include <svx/svdetc.hxx>
53*cdf0e10cSrcweir #include <svx/svdview.hxx>
54*cdf0e10cSrcweir #include <svx/svdorect.hxx>
55*cdf0e10cSrcweir #include "svx/svdviter.hxx"
56*cdf0e10cSrcweir #include <rtl/ref.hxx>
57*cdf0e10cSrcweir #include <set>
58*cdf0e10cSrcweir #include <memory>
59*cdf0e10cSrcweir #include <svx/sdrpagewindow.hxx>
60*cdf0e10cSrcweir #include <svx/sdrpaintwindow.hxx>
61*cdf0e10cSrcweir #include <tools/diagnose_ex.h>
62*cdf0e10cSrcweir #include <svx/svdograf.hxx>
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir using namespace ::com::sun::star;
65*cdf0e10cSrcweir using namespace ::sdr::contact;
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir //************************************************************
68*cdf0e10cSrcweir //   Defines
69*cdf0e10cSrcweir //************************************************************
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir //************************************************************
72*cdf0e10cSrcweir //   Hilfsklasse SdrControlEventListenerImpl
73*cdf0e10cSrcweir //************************************************************
74*cdf0e10cSrcweir #include <com/sun/star/lang/XEventListener.hpp>
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir // =============================================================================
79*cdf0e10cSrcweir class SdrControlEventListenerImpl : public ::cppu::WeakImplHelper1< ::com::sun::star::lang::XEventListener >
80*cdf0e10cSrcweir {
81*cdf0e10cSrcweir protected:
82*cdf0e10cSrcweir 	SdrUnoObj*					pObj;
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir public:
85*cdf0e10cSrcweir 	SdrControlEventListenerImpl(SdrUnoObj* _pObj)
86*cdf0e10cSrcweir 	:	pObj(_pObj)
87*cdf0e10cSrcweir 	{}
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir 	// XEventListener
90*cdf0e10cSrcweir     virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException);
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir 	void StopListening(const uno::Reference< lang::XComponent >& xComp);
93*cdf0e10cSrcweir 	void StartListening(const uno::Reference< lang::XComponent >& xComp);
94*cdf0e10cSrcweir };
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir // XEventListener
97*cdf0e10cSrcweir void SAL_CALL SdrControlEventListenerImpl::disposing( const ::com::sun::star::lang::EventObject& /*Source*/)
98*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
99*cdf0e10cSrcweir {
100*cdf0e10cSrcweir 	if (pObj)
101*cdf0e10cSrcweir 	{
102*cdf0e10cSrcweir 		pObj->xUnoControlModel = NULL;
103*cdf0e10cSrcweir 	}
104*cdf0e10cSrcweir }
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir void SdrControlEventListenerImpl::StopListening(const uno::Reference< lang::XComponent >& xComp)
107*cdf0e10cSrcweir {
108*cdf0e10cSrcweir 	if (xComp.is())
109*cdf0e10cSrcweir 		xComp->removeEventListener(this);
110*cdf0e10cSrcweir }
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir void SdrControlEventListenerImpl::StartListening(const uno::Reference< lang::XComponent >& xComp)
113*cdf0e10cSrcweir {
114*cdf0e10cSrcweir 	if (xComp.is())
115*cdf0e10cSrcweir 		xComp->addEventListener(this);
116*cdf0e10cSrcweir }
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir // =============================================================================
119*cdf0e10cSrcweir struct SAL_DLLPRIVATE SdrUnoObjDataHolder
120*cdf0e10cSrcweir {
121*cdf0e10cSrcweir     mutable ::rtl::Reference< SdrControlEventListenerImpl >
122*cdf0e10cSrcweir                                     pEventListener;
123*cdf0e10cSrcweir };
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir // =============================================================================
126*cdf0e10cSrcweir namespace
127*cdf0e10cSrcweir {
128*cdf0e10cSrcweir     void lcl_ensureControlVisibility( SdrView* _pView, const SdrUnoObj* _pObject, bool _bVisible )
129*cdf0e10cSrcweir     {
130*cdf0e10cSrcweir         OSL_PRECOND( _pObject, "lcl_ensureControlVisibility: no object -> no survival!" );
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir         SdrPageView* pPageView = _pView ? _pView->GetSdrPageView() : NULL;
133*cdf0e10cSrcweir         DBG_ASSERT( pPageView, "lcl_ensureControlVisibility: no view found!" );
134*cdf0e10cSrcweir         if ( !pPageView )
135*cdf0e10cSrcweir             return;
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir         ViewContact& rUnoControlContact( _pObject->GetViewContact() );
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir         for ( sal_uInt32 i = 0; i < pPageView->PageWindowCount(); ++i )
140*cdf0e10cSrcweir         {
141*cdf0e10cSrcweir             const SdrPageWindow* pPageWindow = pPageView->GetPageWindow( i );
142*cdf0e10cSrcweir             DBG_ASSERT( pPageWindow, "lcl_ensureControlVisibility: invalid PageViewWindow!" );
143*cdf0e10cSrcweir             if ( !pPageWindow )
144*cdf0e10cSrcweir                 continue;
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir             if ( !pPageWindow->HasObjectContact() )
147*cdf0e10cSrcweir                 continue;
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir             ObjectContact& rPageViewContact( pPageWindow->GetObjectContact() );
150*cdf0e10cSrcweir             const ViewObjectContact& rViewObjectContact( rUnoControlContact.GetViewObjectContact( rPageViewContact ) );
151*cdf0e10cSrcweir             const ViewObjectContactOfUnoControl* pUnoControlContact = dynamic_cast< const ViewObjectContactOfUnoControl* >( &rViewObjectContact );
152*cdf0e10cSrcweir             DBG_ASSERT( pUnoControlContact, "lcl_ensureControlVisibility: wrong ViewObjectContact type!" );
153*cdf0e10cSrcweir             if ( !pUnoControlContact )
154*cdf0e10cSrcweir                 continue;
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir             pUnoControlContact->ensureControlVisibility( _bVisible );
157*cdf0e10cSrcweir         }
158*cdf0e10cSrcweir     }
159*cdf0e10cSrcweir }
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir //************************************************************
162*cdf0e10cSrcweir //   SdrUnoObj
163*cdf0e10cSrcweir //************************************************************
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir TYPEINIT1(SdrUnoObj, SdrRectObj);
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir SdrUnoObj::SdrUnoObj(const String& rModelName, sal_Bool _bOwnUnoControlModel)
168*cdf0e10cSrcweir :	m_pImpl( new SdrUnoObjDataHolder ),
169*cdf0e10cSrcweir 	bOwnUnoControlModel( _bOwnUnoControlModel )
170*cdf0e10cSrcweir {
171*cdf0e10cSrcweir 	bIsUnoObj = sal_True;
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir 	m_pImpl->pEventListener = new SdrControlEventListenerImpl(this);
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir 	// nur ein owner darf eigenstaendig erzeugen
176*cdf0e10cSrcweir 	if (rModelName.Len())
177*cdf0e10cSrcweir 		CreateUnoControlModel(rModelName);
178*cdf0e10cSrcweir }
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir SdrUnoObj::SdrUnoObj(const String& rModelName,
181*cdf0e10cSrcweir 					 const uno::Reference< lang::XMultiServiceFactory >& rxSFac,
182*cdf0e10cSrcweir 					 sal_Bool _bOwnUnoControlModel)
183*cdf0e10cSrcweir :	m_pImpl( new SdrUnoObjDataHolder ),
184*cdf0e10cSrcweir 	bOwnUnoControlModel( _bOwnUnoControlModel )
185*cdf0e10cSrcweir {
186*cdf0e10cSrcweir 	bIsUnoObj = sal_True;
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir 	m_pImpl->pEventListener = new SdrControlEventListenerImpl(this);
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir 	// nur ein owner darf eigenstaendig erzeugen
191*cdf0e10cSrcweir 	if (rModelName.Len())
192*cdf0e10cSrcweir 		CreateUnoControlModel(rModelName,rxSFac);
193*cdf0e10cSrcweir }
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir SdrUnoObj::~SdrUnoObj()
196*cdf0e10cSrcweir {
197*cdf0e10cSrcweir     try
198*cdf0e10cSrcweir     {
199*cdf0e10cSrcweir         // clean up the control model
200*cdf0e10cSrcweir 	    uno::Reference< lang::XComponent > xComp(xUnoControlModel, uno::UNO_QUERY);
201*cdf0e10cSrcweir         if (xComp.is())
202*cdf0e10cSrcweir         {
203*cdf0e10cSrcweir             // is the control model owned by it's environment?
204*cdf0e10cSrcweir             uno::Reference< container::XChild > xContent(xUnoControlModel, uno::UNO_QUERY);
205*cdf0e10cSrcweir             if (xContent.is() && !xContent->getParent().is())
206*cdf0e10cSrcweir                 xComp->dispose();
207*cdf0e10cSrcweir             else
208*cdf0e10cSrcweir                 m_pImpl->pEventListener->StopListening(xComp);
209*cdf0e10cSrcweir         }
210*cdf0e10cSrcweir     }
211*cdf0e10cSrcweir     catch( const uno::Exception& )
212*cdf0e10cSrcweir     {
213*cdf0e10cSrcweir     	OSL_ENSURE( sal_False, "SdrUnoObj::~SdrUnoObj: caught an exception!" );
214*cdf0e10cSrcweir     }
215*cdf0e10cSrcweir     delete m_pImpl;
216*cdf0e10cSrcweir }
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir void SdrUnoObj::SetModel(SdrModel* pNewModel)
219*cdf0e10cSrcweir {
220*cdf0e10cSrcweir 	SdrRectObj::SetModel(pNewModel);
221*cdf0e10cSrcweir }
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir void SdrUnoObj::SetPage(SdrPage* pNewPage)
224*cdf0e10cSrcweir {
225*cdf0e10cSrcweir 	SdrRectObj::SetPage(pNewPage);
226*cdf0e10cSrcweir }
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir void SdrUnoObj::TakeObjInfo(SdrObjTransformInfoRec& rInfo) const
229*cdf0e10cSrcweir {
230*cdf0e10cSrcweir 	rInfo.bRotateFreeAllowed		=	sal_False;
231*cdf0e10cSrcweir 	rInfo.bRotate90Allowed			=	sal_False;
232*cdf0e10cSrcweir 	rInfo.bMirrorFreeAllowed		=	sal_False;
233*cdf0e10cSrcweir 	rInfo.bMirror45Allowed			=	sal_False;
234*cdf0e10cSrcweir 	rInfo.bMirror90Allowed			=	sal_False;
235*cdf0e10cSrcweir 	rInfo.bTransparenceAllowed = sal_False;
236*cdf0e10cSrcweir 	rInfo.bGradientAllowed = sal_False;
237*cdf0e10cSrcweir 	rInfo.bShearAllowed 			=	sal_False;
238*cdf0e10cSrcweir 	rInfo.bEdgeRadiusAllowed		=	sal_False;
239*cdf0e10cSrcweir 	rInfo.bNoOrthoDesired			=	sal_False;
240*cdf0e10cSrcweir 	rInfo.bCanConvToPath			=	sal_False;
241*cdf0e10cSrcweir 	rInfo.bCanConvToPoly			=	sal_False;
242*cdf0e10cSrcweir 	rInfo.bCanConvToPathLineToArea	=	sal_False;
243*cdf0e10cSrcweir 	rInfo.bCanConvToPolyLineToArea	=	sal_False;
244*cdf0e10cSrcweir 	rInfo.bCanConvToContour = sal_False;
245*cdf0e10cSrcweir }
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir sal_uInt16 SdrUnoObj::GetObjIdentifier() const
248*cdf0e10cSrcweir {
249*cdf0e10cSrcweir 	return sal_uInt16(OBJ_UNO);
250*cdf0e10cSrcweir }
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir void SdrUnoObj::SetContextWritingMode( const sal_Int16 _nContextWritingMode )
253*cdf0e10cSrcweir {
254*cdf0e10cSrcweir     try
255*cdf0e10cSrcweir     {
256*cdf0e10cSrcweir         uno::Reference< beans::XPropertySet > xModelProperties( GetUnoControlModel(), uno::UNO_QUERY_THROW );
257*cdf0e10cSrcweir         xModelProperties->setPropertyValue(
258*cdf0e10cSrcweir             ::rtl::OUString::intern( RTL_CONSTASCII_USTRINGPARAM( "ContextWritingMode" ) ),
259*cdf0e10cSrcweir             uno::makeAny( _nContextWritingMode )
260*cdf0e10cSrcweir         );
261*cdf0e10cSrcweir     }
262*cdf0e10cSrcweir     catch( const uno::Exception& )
263*cdf0e10cSrcweir     {
264*cdf0e10cSrcweir     	DBG_UNHANDLED_EXCEPTION();
265*cdf0e10cSrcweir     }
266*cdf0e10cSrcweir }
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir // ----------------------------------------------------------------------------
269*cdf0e10cSrcweir namespace
270*cdf0e10cSrcweir {
271*cdf0e10cSrcweir     /** helper class to restore graphics at <awt::XView> object after <SdrUnoObj::Paint>
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir         OD 08.05.2003 #109432#
274*cdf0e10cSrcweir         Restoration of graphics necessary to assure that paint on a window
275*cdf0e10cSrcweir 
276*cdf0e10cSrcweir         @author OD
277*cdf0e10cSrcweir     */
278*cdf0e10cSrcweir     class RestoreXViewGraphics
279*cdf0e10cSrcweir     {
280*cdf0e10cSrcweir         private:
281*cdf0e10cSrcweir             uno::Reference< awt::XView >        m_rXView;
282*cdf0e10cSrcweir             uno::Reference< awt::XGraphics >    m_rXGraphics;
283*cdf0e10cSrcweir 
284*cdf0e10cSrcweir         public:
285*cdf0e10cSrcweir             RestoreXViewGraphics( const uno::Reference< awt::XView >& _rXView )
286*cdf0e10cSrcweir             {
287*cdf0e10cSrcweir                 m_rXView = _rXView;
288*cdf0e10cSrcweir                 m_rXGraphics = m_rXView->getGraphics();
289*cdf0e10cSrcweir             }
290*cdf0e10cSrcweir             ~RestoreXViewGraphics()
291*cdf0e10cSrcweir             {
292*cdf0e10cSrcweir                 m_rXView->setGraphics( m_rXGraphics );
293*cdf0e10cSrcweir             }
294*cdf0e10cSrcweir     };
295*cdf0e10cSrcweir }
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir void SdrUnoObj::TakeObjNameSingul(XubString& rName) const
298*cdf0e10cSrcweir {
299*cdf0e10cSrcweir 	rName = ImpGetResStr(STR_ObjNameSingulUno);
300*cdf0e10cSrcweir 
301*cdf0e10cSrcweir 	String aName( GetName() );
302*cdf0e10cSrcweir 	if(aName.Len())
303*cdf0e10cSrcweir 	{
304*cdf0e10cSrcweir 		rName += sal_Unicode(' ');
305*cdf0e10cSrcweir 		rName += sal_Unicode('\'');
306*cdf0e10cSrcweir 		rName += aName;
307*cdf0e10cSrcweir 		rName += sal_Unicode('\'');
308*cdf0e10cSrcweir 	}
309*cdf0e10cSrcweir }
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir void SdrUnoObj::TakeObjNamePlural(XubString& rName) const
312*cdf0e10cSrcweir {
313*cdf0e10cSrcweir 	rName = ImpGetResStr(STR_ObjNamePluralUno);
314*cdf0e10cSrcweir }
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir void SdrUnoObj::operator = (const SdrObject& rObj)
317*cdf0e10cSrcweir {
318*cdf0e10cSrcweir 	SdrRectObj::operator = (rObj);
319*cdf0e10cSrcweir 
320*cdf0e10cSrcweir 	// release the reference to the current control model
321*cdf0e10cSrcweir 	SetUnoControlModel( NULL );
322*cdf0e10cSrcweir 
323*cdf0e10cSrcweir     const SdrUnoObj& rUnoObj = dynamic_cast< const SdrUnoObj& >( rObj );
324*cdf0e10cSrcweir 
325*cdf0e10cSrcweir 	aUnoControlModelTypeName = rUnoObj.aUnoControlModelTypeName;
326*cdf0e10cSrcweir 	aUnoControlTypeName = rUnoObj.aUnoControlTypeName;
327*cdf0e10cSrcweir 
328*cdf0e10cSrcweir 	// copy the uno control model
329*cdf0e10cSrcweir 	const uno::Reference< awt::XControlModel > xSourceControlModel( rUnoObj.GetUnoControlModel(), uno::UNO_QUERY );
330*cdf0e10cSrcweir     if ( xSourceControlModel.is() )
331*cdf0e10cSrcweir     {
332*cdf0e10cSrcweir         try
333*cdf0e10cSrcweir         {
334*cdf0e10cSrcweir 	        uno::Reference< util::XCloneable > xClone( xSourceControlModel, uno::UNO_QUERY_THROW );
335*cdf0e10cSrcweir             xUnoControlModel.set( xClone->createClone(), uno::UNO_QUERY_THROW );
336*cdf0e10cSrcweir         }
337*cdf0e10cSrcweir         catch( const uno::Exception& )
338*cdf0e10cSrcweir         {
339*cdf0e10cSrcweir         	DBG_UNHANDLED_EXCEPTION();
340*cdf0e10cSrcweir         }
341*cdf0e10cSrcweir     }
342*cdf0e10cSrcweir 
343*cdf0e10cSrcweir 	// get service name of the control from the control model
344*cdf0e10cSrcweir 	uno::Reference< beans::XPropertySet > xSet(xUnoControlModel, uno::UNO_QUERY);
345*cdf0e10cSrcweir 	if (xSet.is())
346*cdf0e10cSrcweir 	{
347*cdf0e10cSrcweir 		uno::Any aValue( xSet->getPropertyValue( rtl::OUString::createFromAscii("DefaultControl")) );
348*cdf0e10cSrcweir         ::rtl::OUString aStr;
349*cdf0e10cSrcweir 
350*cdf0e10cSrcweir 		if( aValue >>= aStr )
351*cdf0e10cSrcweir 			aUnoControlTypeName = String(aStr);
352*cdf0e10cSrcweir 	}
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir 	uno::Reference< lang::XComponent > xComp(xUnoControlModel, uno::UNO_QUERY);
355*cdf0e10cSrcweir 	if (xComp.is())
356*cdf0e10cSrcweir 		m_pImpl->pEventListener->StartListening(xComp);
357*cdf0e10cSrcweir }
358*cdf0e10cSrcweir 
359*cdf0e10cSrcweir void SdrUnoObj::NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact)
360*cdf0e10cSrcweir {
361*cdf0e10cSrcweir 	SdrRectObj::NbcResize(rRef,xFact,yFact);
362*cdf0e10cSrcweir 
363*cdf0e10cSrcweir 	if (aGeo.nShearWink!=0 || aGeo.nDrehWink!=0)
364*cdf0e10cSrcweir 	{
365*cdf0e10cSrcweir 		// kleine Korrekturen
366*cdf0e10cSrcweir 		if (aGeo.nDrehWink>=9000 && aGeo.nDrehWink<27000)
367*cdf0e10cSrcweir 		{
368*cdf0e10cSrcweir 			aRect.Move(aRect.Left()-aRect.Right(),aRect.Top()-aRect.Bottom());
369*cdf0e10cSrcweir 		}
370*cdf0e10cSrcweir 
371*cdf0e10cSrcweir 		aGeo.nDrehWink	= 0;
372*cdf0e10cSrcweir 		aGeo.nShearWink = 0;
373*cdf0e10cSrcweir 		aGeo.nSin		= 0.0;
374*cdf0e10cSrcweir 		aGeo.nCos		= 1.0;
375*cdf0e10cSrcweir 		aGeo.nTan		= 0.0;
376*cdf0e10cSrcweir 		SetRectsDirty();
377*cdf0e10cSrcweir 	}
378*cdf0e10cSrcweir }
379*cdf0e10cSrcweir 
380*cdf0e10cSrcweir // -----------------------------------------------------------------------------
381*cdf0e10cSrcweir 
382*cdf0e10cSrcweir bool SdrUnoObj::hasSpecialDrag() const
383*cdf0e10cSrcweir {
384*cdf0e10cSrcweir     // no special drag; we have no rounding rect and
385*cdf0e10cSrcweir     // do want frame handles
386*cdf0e10cSrcweir     return false;
387*cdf0e10cSrcweir }
388*cdf0e10cSrcweir 
389*cdf0e10cSrcweir bool SdrUnoObj::supportsFullDrag() const
390*cdf0e10cSrcweir {
391*cdf0e10cSrcweir     // overloaded to have the possibility to enable/disable in debug and
392*cdf0e10cSrcweir     // to ckeck some things out. Current solution is working, so default is
393*cdf0e10cSrcweir     // enabled
394*cdf0e10cSrcweir     static bool bDoSupportFullDrag(true);
395*cdf0e10cSrcweir 
396*cdf0e10cSrcweir     return bDoSupportFullDrag;
397*cdf0e10cSrcweir }
398*cdf0e10cSrcweir 
399*cdf0e10cSrcweir SdrObject* SdrUnoObj::getFullDragClone() const
400*cdf0e10cSrcweir {
401*cdf0e10cSrcweir     SdrObject* pRetval = 0;
402*cdf0e10cSrcweir     static bool bHandleSpecial(false);
403*cdf0e10cSrcweir 
404*cdf0e10cSrcweir     if(bHandleSpecial)
405*cdf0e10cSrcweir     {
406*cdf0e10cSrcweir 	    // special handling for SdrUnoObj (FormControl). Create a SdrGrafObj
407*cdf0e10cSrcweir 	    // for drag containing the graphical representation. This does not work too
408*cdf0e10cSrcweir         // well, so the default is to simply clone
409*cdf0e10cSrcweir 	    pRetval = new SdrGrafObj(SdrDragView::GetObjGraphic(GetModel(), this), GetLogicRect());
410*cdf0e10cSrcweir     }
411*cdf0e10cSrcweir     else
412*cdf0e10cSrcweir     {
413*cdf0e10cSrcweir         // call parent (simply clone)
414*cdf0e10cSrcweir         pRetval = SdrRectObj::getFullDragClone();
415*cdf0e10cSrcweir     }
416*cdf0e10cSrcweir 
417*cdf0e10cSrcweir 	return pRetval;
418*cdf0e10cSrcweir }
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir // -----------------------------------------------------------------------------
421*cdf0e10cSrcweir void SdrUnoObj::NbcSetLayer( SdrLayerID _nLayer )
422*cdf0e10cSrcweir {
423*cdf0e10cSrcweir     if ( GetLayer() == _nLayer )
424*cdf0e10cSrcweir     {   // redundant call -> not interested in doing anything here
425*cdf0e10cSrcweir         SdrRectObj::NbcSetLayer( _nLayer );
426*cdf0e10cSrcweir         return;
427*cdf0e10cSrcweir     }
428*cdf0e10cSrcweir 
429*cdf0e10cSrcweir     // we need some special handling here in case we're moved from an invisible layer
430*cdf0e10cSrcweir     // to a visible one, or vice versa
431*cdf0e10cSrcweir     // (relative to a layer. Remember that the visibility of a layer is a view attribute
432*cdf0e10cSrcweir     // - the same layer can be visible in one view, and invisible in another view, at the
433*cdf0e10cSrcweir     // same time)
434*cdf0e10cSrcweir     // 2003-06-03 - #110592# - fs@openoffice.org
435*cdf0e10cSrcweir 
436*cdf0e10cSrcweir     // collect all views in which our old layer is visible
437*cdf0e10cSrcweir     ::std::set< SdrView* > aPreviouslyVisible;
438*cdf0e10cSrcweir 
439*cdf0e10cSrcweir     {
440*cdf0e10cSrcweir         SdrViewIter aIter( this );
441*cdf0e10cSrcweir         for ( SdrView* pView = aIter.FirstView(); pView; pView = aIter.NextView() )
442*cdf0e10cSrcweir             aPreviouslyVisible.insert( pView );
443*cdf0e10cSrcweir     }
444*cdf0e10cSrcweir 
445*cdf0e10cSrcweir     SdrRectObj::NbcSetLayer( _nLayer );
446*cdf0e10cSrcweir 
447*cdf0e10cSrcweir     // collect all views in which our new layer is visible
448*cdf0e10cSrcweir     ::std::set< SdrView* > aNewlyVisible;
449*cdf0e10cSrcweir 
450*cdf0e10cSrcweir     {
451*cdf0e10cSrcweir         SdrViewIter aIter( this );
452*cdf0e10cSrcweir 	    for ( SdrView* pView = aIter.FirstView(); pView; pView = aIter.NextView() )
453*cdf0e10cSrcweir         {
454*cdf0e10cSrcweir             ::std::set< SdrView* >::const_iterator aPrevPos = aPreviouslyVisible.find( pView );
455*cdf0e10cSrcweir             if ( aPreviouslyVisible.end() != aPrevPos )
456*cdf0e10cSrcweir             {   // in pView, we were visible _before_ the layer change, and are
457*cdf0e10cSrcweir                 // visible _after_ the layer change, too
458*cdf0e10cSrcweir                 // -> we're not interested in this view at all
459*cdf0e10cSrcweir                 aPreviouslyVisible.erase( aPrevPos );
460*cdf0e10cSrcweir             }
461*cdf0e10cSrcweir             else
462*cdf0e10cSrcweir             {
463*cdf0e10cSrcweir                 // in pView, we were visible _before_ the layer change, and are
464*cdf0e10cSrcweir                 // _not_ visible after the layer change
465*cdf0e10cSrcweir                 // => remember this view, as our visibility there changed
466*cdf0e10cSrcweir                 aNewlyVisible.insert( pView );
467*cdf0e10cSrcweir             }
468*cdf0e10cSrcweir         }
469*cdf0e10cSrcweir     }
470*cdf0e10cSrcweir 
471*cdf0e10cSrcweir     // now aPreviouslyVisible contains all views where we became invisible
472*cdf0e10cSrcweir     ::std::set< SdrView* >::const_iterator aLoopViews;
473*cdf0e10cSrcweir     for (   aLoopViews = aPreviouslyVisible.begin();
474*cdf0e10cSrcweir             aLoopViews != aPreviouslyVisible.end();
475*cdf0e10cSrcweir             ++aLoopViews
476*cdf0e10cSrcweir         )
477*cdf0e10cSrcweir     {
478*cdf0e10cSrcweir         lcl_ensureControlVisibility( *aLoopViews, this, false );
479*cdf0e10cSrcweir     }
480*cdf0e10cSrcweir 
481*cdf0e10cSrcweir     // and aNewlyVisible all views where we became visible
482*cdf0e10cSrcweir     for (   aLoopViews = aNewlyVisible.begin();
483*cdf0e10cSrcweir             aLoopViews != aNewlyVisible.end();
484*cdf0e10cSrcweir             ++aLoopViews
485*cdf0e10cSrcweir         )
486*cdf0e10cSrcweir     {
487*cdf0e10cSrcweir         lcl_ensureControlVisibility( *aLoopViews, this, true );
488*cdf0e10cSrcweir     }
489*cdf0e10cSrcweir }
490*cdf0e10cSrcweir 
491*cdf0e10cSrcweir void SdrUnoObj::CreateUnoControlModel(const String& rModelName)
492*cdf0e10cSrcweir {
493*cdf0e10cSrcweir 	DBG_ASSERT(!xUnoControlModel.is(), "model already exists");
494*cdf0e10cSrcweir 
495*cdf0e10cSrcweir 	aUnoControlModelTypeName = rModelName;
496*cdf0e10cSrcweir 
497*cdf0e10cSrcweir 	uno::Reference< awt::XControlModel >   xModel;
498*cdf0e10cSrcweir 	uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
499*cdf0e10cSrcweir 	if (aUnoControlModelTypeName.Len() && xFactory.is() )
500*cdf0e10cSrcweir 	{
501*cdf0e10cSrcweir 		xModel = uno::Reference< awt::XControlModel >(xFactory->createInstance(
502*cdf0e10cSrcweir 			aUnoControlModelTypeName), uno::UNO_QUERY);
503*cdf0e10cSrcweir 
504*cdf0e10cSrcweir 		if (xModel.is())
505*cdf0e10cSrcweir 			SetChanged();
506*cdf0e10cSrcweir 	}
507*cdf0e10cSrcweir 
508*cdf0e10cSrcweir 	SetUnoControlModel(xModel);
509*cdf0e10cSrcweir }
510*cdf0e10cSrcweir 
511*cdf0e10cSrcweir void SdrUnoObj::CreateUnoControlModel(const String& rModelName,
512*cdf0e10cSrcweir 									  const uno::Reference< lang::XMultiServiceFactory >& rxSFac)
513*cdf0e10cSrcweir {
514*cdf0e10cSrcweir 	DBG_ASSERT(!xUnoControlModel.is(), "model already exists");
515*cdf0e10cSrcweir 
516*cdf0e10cSrcweir 	aUnoControlModelTypeName = rModelName;
517*cdf0e10cSrcweir 
518*cdf0e10cSrcweir 	uno::Reference< awt::XControlModel >   xModel;
519*cdf0e10cSrcweir 	if (aUnoControlModelTypeName.Len() && rxSFac.is() )
520*cdf0e10cSrcweir 	{
521*cdf0e10cSrcweir 		xModel = uno::Reference< awt::XControlModel >(rxSFac->createInstance(
522*cdf0e10cSrcweir 			aUnoControlModelTypeName), uno::UNO_QUERY);
523*cdf0e10cSrcweir 
524*cdf0e10cSrcweir 		if (xModel.is())
525*cdf0e10cSrcweir 			SetChanged();
526*cdf0e10cSrcweir 	}
527*cdf0e10cSrcweir 
528*cdf0e10cSrcweir 	SetUnoControlModel(xModel);
529*cdf0e10cSrcweir }
530*cdf0e10cSrcweir 
531*cdf0e10cSrcweir void SdrUnoObj::SetUnoControlModel( const uno::Reference< awt::XControlModel >& xModel)
532*cdf0e10cSrcweir {
533*cdf0e10cSrcweir 	if (xUnoControlModel.is())
534*cdf0e10cSrcweir 	{
535*cdf0e10cSrcweir 		uno::Reference< lang::XComponent > xComp(xUnoControlModel, uno::UNO_QUERY);
536*cdf0e10cSrcweir 		if (xComp.is())
537*cdf0e10cSrcweir 			m_pImpl->pEventListener->StopListening(xComp);
538*cdf0e10cSrcweir 	}
539*cdf0e10cSrcweir 
540*cdf0e10cSrcweir 	xUnoControlModel = xModel;
541*cdf0e10cSrcweir 
542*cdf0e10cSrcweir 	// control model muss servicename des controls enthalten
543*cdf0e10cSrcweir 	if (xUnoControlModel.is())
544*cdf0e10cSrcweir 	{
545*cdf0e10cSrcweir 		uno::Reference< beans::XPropertySet > xSet(xUnoControlModel, uno::UNO_QUERY);
546*cdf0e10cSrcweir 		if (xSet.is())
547*cdf0e10cSrcweir 		{
548*cdf0e10cSrcweir 			uno::Any aValue( xSet->getPropertyValue(String("DefaultControl", gsl_getSystemTextEncoding())) );
549*cdf0e10cSrcweir             ::rtl::OUString aStr;
550*cdf0e10cSrcweir 			if( aValue >>= aStr )
551*cdf0e10cSrcweir 				aUnoControlTypeName = String(aStr);
552*cdf0e10cSrcweir 		}
553*cdf0e10cSrcweir 
554*cdf0e10cSrcweir 		uno::Reference< lang::XComponent > xComp(xUnoControlModel, uno::UNO_QUERY);
555*cdf0e10cSrcweir 		if (xComp.is())
556*cdf0e10cSrcweir 			m_pImpl->pEventListener->StartListening(xComp);
557*cdf0e10cSrcweir 	}
558*cdf0e10cSrcweir 
559*cdf0e10cSrcweir     // invalidate all ViewObject contacts
560*cdf0e10cSrcweir     ViewContactOfUnoControl* pVC = NULL;
561*cdf0e10cSrcweir     if ( impl_getViewContact( pVC ) )
562*cdf0e10cSrcweir 	{
563*cdf0e10cSrcweir 		// flushViewObjectContacts() removes all existing VOCs for the local DrawHierarchy. This
564*cdf0e10cSrcweir         // is always allowed since they will be re-created on demand (and with the changed model)
565*cdf0e10cSrcweir         GetViewContact().flushViewObjectContacts(true);
566*cdf0e10cSrcweir 	}
567*cdf0e10cSrcweir }
568*cdf0e10cSrcweir 
569*cdf0e10cSrcweir //------------------------------------------------------------------------
570*cdf0e10cSrcweir uno::Reference< awt::XControl > SdrUnoObj::GetUnoControl(const SdrView& _rView, const OutputDevice& _rOut) const
571*cdf0e10cSrcweir {
572*cdf0e10cSrcweir     uno::Reference< awt::XControl > xControl;
573*cdf0e10cSrcweir 
574*cdf0e10cSrcweir     SdrPageView* pPageView = _rView.GetSdrPageView();
575*cdf0e10cSrcweir     OSL_ENSURE( GetPage() == pPageView->GetPage(), "SdrUnoObj::GetUnoControl: This object is not displayed in that particular view!" );
576*cdf0e10cSrcweir     if ( GetPage() != pPageView->GetPage() )
577*cdf0e10cSrcweir         return NULL;
578*cdf0e10cSrcweir 
579*cdf0e10cSrcweir     SdrPageWindow* pPageWindow = pPageView ? pPageView->FindPageWindow( _rOut ) : NULL;
580*cdf0e10cSrcweir     OSL_ENSURE( pPageWindow, "SdrUnoObj::GetUnoControl: did not find my SdrPageWindow!" );
581*cdf0e10cSrcweir     if ( !pPageWindow )
582*cdf0e10cSrcweir         return NULL;
583*cdf0e10cSrcweir 
584*cdf0e10cSrcweir     ViewObjectContact& rViewObjectContact( GetViewContact().GetViewObjectContact( pPageWindow->GetObjectContact() ) );
585*cdf0e10cSrcweir     ViewObjectContactOfUnoControl* pUnoContact = dynamic_cast< ViewObjectContactOfUnoControl* >( &rViewObjectContact );
586*cdf0e10cSrcweir     OSL_ENSURE( pUnoContact, "SdrUnoObj::GetUnoControl: wrong contact type!" );
587*cdf0e10cSrcweir     if ( pUnoContact )
588*cdf0e10cSrcweir         xControl = pUnoContact->getControl();
589*cdf0e10cSrcweir 
590*cdf0e10cSrcweir     return xControl;
591*cdf0e10cSrcweir }
592*cdf0e10cSrcweir 
593*cdf0e10cSrcweir //------------------------------------------------------------------------
594*cdf0e10cSrcweir uno::Reference< awt::XControl > SdrUnoObj::GetTemporaryControlForWindow(
595*cdf0e10cSrcweir     const Window& _rWindow, uno::Reference< awt::XControlContainer >& _inout_ControlContainer ) const
596*cdf0e10cSrcweir {
597*cdf0e10cSrcweir     uno::Reference< awt::XControl > xControl;
598*cdf0e10cSrcweir 
599*cdf0e10cSrcweir     ViewContactOfUnoControl* pVC = NULL;
600*cdf0e10cSrcweir     if ( impl_getViewContact( pVC ) )
601*cdf0e10cSrcweir         xControl = pVC->getTemporaryControlForWindow( _rWindow, _inout_ControlContainer );
602*cdf0e10cSrcweir 
603*cdf0e10cSrcweir     return xControl;
604*cdf0e10cSrcweir }
605*cdf0e10cSrcweir 
606*cdf0e10cSrcweir //------------------------------------------------------------------------
607*cdf0e10cSrcweir bool SdrUnoObj::impl_getViewContact( ViewContactOfUnoControl*& _out_rpContact ) const
608*cdf0e10cSrcweir {
609*cdf0e10cSrcweir     ViewContact& rViewContact( GetViewContact() );
610*cdf0e10cSrcweir     _out_rpContact = dynamic_cast< ViewContactOfUnoControl* >( &rViewContact );
611*cdf0e10cSrcweir     DBG_ASSERT( _out_rpContact, "SdrUnoObj::impl_getViewContact: could not find my ViewContact!" );
612*cdf0e10cSrcweir     return ( _out_rpContact != NULL );
613*cdf0e10cSrcweir }
614*cdf0e10cSrcweir 
615*cdf0e10cSrcweir //------------------------------------------------------------------------
616*cdf0e10cSrcweir ::sdr::contact::ViewContact* SdrUnoObj::CreateObjectSpecificViewContact()
617*cdf0e10cSrcweir {
618*cdf0e10cSrcweir   return new ::sdr::contact::ViewContactOfUnoControl( *this );
619*cdf0e10cSrcweir }
620*cdf0e10cSrcweir 
621*cdf0e10cSrcweir // -----------------------------------------------------------------------------
622*cdf0e10cSrcweir // eof
623