xref: /AOO41X/main/svx/source/svdraw/svdoole2.cxx (revision a5258243accf51c522d45cf65e4b16cb17a336f7)
1cdf0e10cSrcweir /*************************************************************************
2cdf0e10cSrcweir  *
3cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4cdf0e10cSrcweir  *
5cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6cdf0e10cSrcweir  *
7cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8cdf0e10cSrcweir  *
9cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10cdf0e10cSrcweir  *
11cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14cdf0e10cSrcweir  *
15cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20cdf0e10cSrcweir  *
21cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25cdf0e10cSrcweir  *
26cdf0e10cSrcweir  ************************************************************************/
27cdf0e10cSrcweir 
28cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29cdf0e10cSrcweir #include "precompiled_svx.hxx"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <svx/svdoole2.hxx>
32cdf0e10cSrcweir #include <com/sun/star/util/XModifyBroadcaster.hpp>
33cdf0e10cSrcweir #include <com/sun/star/util/XModifiable.hpp>
34cdf0e10cSrcweir #include <com/sun/star/embed/EmbedStates.hpp>
35cdf0e10cSrcweir #include <com/sun/star/embed/ElementModes.hpp>
36cdf0e10cSrcweir #include <com/sun/star/embed/EmbedMisc.hpp>
37cdf0e10cSrcweir #include <com/sun/star/embed/Aspects.hpp>
38cdf0e10cSrcweir #include <com/sun/star/embed/XInplaceClient.hpp>
39cdf0e10cSrcweir #include <com/sun/star/embed/XInplaceObject.hpp>
40cdf0e10cSrcweir #include <com/sun/star/embed/XLinkageSupport.hpp>
41cdf0e10cSrcweir #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
42cdf0e10cSrcweir #include <com/sun/star/embed/XWindowSupplier.hpp>
43cdf0e10cSrcweir #include <com/sun/star/document/XEventListener.hpp>
44cdf0e10cSrcweir #include <com/sun/star/container/XChild.hpp>
45cdf0e10cSrcweir #include "com/sun/star/document/XStorageBasedDocument.hpp"
46cdf0e10cSrcweir 
47cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
48cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx>
49cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx>
50cdf0e10cSrcweir 
51cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
52cdf0e10cSrcweir #include <toolkit/awt/vclxwindow.hxx>
53cdf0e10cSrcweir #include <toolkit/helper/convert.hxx>
54cdf0e10cSrcweir 
55cdf0e10cSrcweir #include <svtools/filter.hxx>
56cdf0e10cSrcweir #include <svtools/embedhlp.hxx>
57cdf0e10cSrcweir 
58cdf0e10cSrcweir #include <sfx2/objsh.hxx>
59cdf0e10cSrcweir #include <sfx2/ipclient.hxx>
60cdf0e10cSrcweir #include <sfx2/lnkbase.hxx>
61cdf0e10cSrcweir #include <tools/stream.hxx>
62cdf0e10cSrcweir #include <comphelper/anytostring.hxx>
63cdf0e10cSrcweir #include <svx/svdpagv.hxx>
64cdf0e10cSrcweir #include <tools/globname.hxx>
65cdf0e10cSrcweir #include <vcl/jobset.hxx>
66cdf0e10cSrcweir #include <sot/clsids.hxx>
67cdf0e10cSrcweir 
68cdf0e10cSrcweir #include <sot/formats.hxx>
69cdf0e10cSrcweir #include <sfx2/linkmgr.hxx>
70cdf0e10cSrcweir #include <svtools/transfer.hxx>
71cdf0e10cSrcweir #include <cppuhelper/implbase5.hxx>
72cdf0e10cSrcweir 
73cdf0e10cSrcweir #include <svl/solar.hrc>
74cdf0e10cSrcweir #include <svl/urihelper.hxx>
75cdf0e10cSrcweir #include <vos/mutex.hxx>
76cdf0e10cSrcweir #include <vcl/svapp.hxx>
77cdf0e10cSrcweir 
78cdf0e10cSrcweir #include <svx/svdpagv.hxx>
79cdf0e10cSrcweir #include <svx/svdmodel.hxx>
80cdf0e10cSrcweir #include "svx/svdglob.hxx"  // Stringcache
81cdf0e10cSrcweir #include "svx/svdstr.hrc"   // Objektname
82cdf0e10cSrcweir #include <svx/svdetc.hxx>
83cdf0e10cSrcweir #include <svx/svdview.hxx>
84cdf0e10cSrcweir #include "unomlstr.hxx"
85cdf0e10cSrcweir #include <svtools/chartprettypainter.hxx>
86cdf0e10cSrcweir #include <svx/sdr/contact/viewcontactofsdrole2obj.hxx>
87cdf0e10cSrcweir #include <svx/svdograf.hxx>
88cdf0e10cSrcweir #include <svx/sdr/properties/oleproperties.hxx>
89cdf0e10cSrcweir 
90cdf0e10cSrcweir // #i100710#
91cdf0e10cSrcweir #include <svx/xlnclit.hxx>
92cdf0e10cSrcweir #include <svx/xbtmpit.hxx>
93cdf0e10cSrcweir #include <svx/xflbmtit.hxx>
94cdf0e10cSrcweir #include <svx/xflbstit.hxx>
95cdf0e10cSrcweir 
96*a5258243SPedro Giffuni // #i118485#
97*a5258243SPedro Giffuni #include <basegfx/matrix/b2dhommatrix.hxx>
98*a5258243SPedro Giffuni #include <basegfx/polygon/b2dpolypolygon.hxx>
99*a5258243SPedro Giffuni #include <editeng/outlobj.hxx>
100*a5258243SPedro Giffuni 
101cdf0e10cSrcweir using namespace ::rtl;
102cdf0e10cSrcweir using namespace ::com::sun::star;
103cdf0e10cSrcweir 
104cdf0e10cSrcweir uno::Reference < beans::XPropertySet > lcl_getFrame_throw(const SdrOle2Obj* _pObject)
105cdf0e10cSrcweir {
106cdf0e10cSrcweir     uno::Reference < beans::XPropertySet > xFrame;
107cdf0e10cSrcweir     if ( _pObject )
108cdf0e10cSrcweir     {
109cdf0e10cSrcweir         uno::Reference< frame::XController> xController = _pObject->GetParentXModel()->getCurrentController();
110cdf0e10cSrcweir         if ( xController.is() )
111cdf0e10cSrcweir         {
112cdf0e10cSrcweir             xFrame.set( xController->getFrame(),uno::UNO_QUERY_THROW);
113cdf0e10cSrcweir         }
114cdf0e10cSrcweir     } // if ( _pObject )
115cdf0e10cSrcweir     return xFrame;
116cdf0e10cSrcweir }
117cdf0e10cSrcweir 
118cdf0e10cSrcweir class SdrLightEmbeddedClient_Impl : public ::cppu::WeakImplHelper5
119cdf0e10cSrcweir 															< embed::XStateChangeListener
120cdf0e10cSrcweir 															, document::XEventListener
121cdf0e10cSrcweir                                                             , embed::XInplaceClient
122cdf0e10cSrcweir 															, embed::XEmbeddedClient
123cdf0e10cSrcweir                                                             , embed::XWindowSupplier
124cdf0e10cSrcweir                                                             >
125cdf0e10cSrcweir {
126cdf0e10cSrcweir     uno::Reference< awt::XWindow > m_xWindow;
127cdf0e10cSrcweir 	SdrOle2Obj* mpObj;
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 	Fraction m_aScaleWidth;
130cdf0e10cSrcweir 	Fraction m_aScaleHeight;
131cdf0e10cSrcweir 
132cdf0e10cSrcweir 
133cdf0e10cSrcweir public:
134cdf0e10cSrcweir     SdrLightEmbeddedClient_Impl( SdrOle2Obj* pObj );
135cdf0e10cSrcweir     void Release();
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 	void SetSizeScale( const Fraction& aScaleWidth, const Fraction& aScaleHeight )
138cdf0e10cSrcweir 	{
139cdf0e10cSrcweir 		m_aScaleWidth = aScaleWidth;
140cdf0e10cSrcweir 		m_aScaleHeight = aScaleHeight;
141cdf0e10cSrcweir 	}
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 	Fraction GetScaleWidth() const { return m_aScaleWidth; }
144cdf0e10cSrcweir 	Fraction GetScaleHeight() const { return m_aScaleHeight; }
145cdf0e10cSrcweir 
146cdf0e10cSrcweir     void setWindow(const uno::Reference< awt::XWindow >& _xWindow);
147cdf0e10cSrcweir 
148cdf0e10cSrcweir private:
149cdf0e10cSrcweir     Rectangle impl_getScaledRect_nothrow() const;
150cdf0e10cSrcweir 	// XStateChangeListener
151cdf0e10cSrcweir     virtual void SAL_CALL changingState( const ::com::sun::star::lang::EventObject& aEvent, ::sal_Int32 nOldState, ::sal_Int32 nNewState ) throw (::com::sun::star::embed::WrongStateException, ::com::sun::star::uno::RuntimeException);
152cdf0e10cSrcweir     virtual void SAL_CALL stateChanged( const ::com::sun::star::lang::EventObject& aEvent, ::sal_Int32 nOldState, ::sal_Int32 nNewState ) throw (::com::sun::star::uno::RuntimeException);
153cdf0e10cSrcweir     virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException);
154cdf0e10cSrcweir 
155cdf0e10cSrcweir     // document::XEventListener
156cdf0e10cSrcweir     virtual void SAL_CALL       notifyEvent( const document::EventObject& aEvent ) throw( uno::RuntimeException );
157cdf0e10cSrcweir 
158cdf0e10cSrcweir 	// XEmbeddedClient
159cdf0e10cSrcweir     virtual void SAL_CALL saveObject() throw ( embed::ObjectSaveVetoException, uno::Exception, uno::RuntimeException );
160cdf0e10cSrcweir     virtual void SAL_CALL visibilityChanged( sal_Bool bVisible ) throw ( embed::WrongStateException, uno::RuntimeException );
161cdf0e10cSrcweir 
162cdf0e10cSrcweir 	// XComponentSupplier
163cdf0e10cSrcweir     virtual uno::Reference< util::XCloseable > SAL_CALL getComponent() throw ( uno::RuntimeException );
164cdf0e10cSrcweir 
165cdf0e10cSrcweir     // XInplaceClient
166cdf0e10cSrcweir     virtual sal_Bool SAL_CALL canInplaceActivate() throw ( uno::RuntimeException );
167cdf0e10cSrcweir     virtual void SAL_CALL activatingInplace() throw ( embed::WrongStateException, uno::RuntimeException );
168cdf0e10cSrcweir     virtual void SAL_CALL activatingUI() throw ( embed::WrongStateException, uno::RuntimeException );
169cdf0e10cSrcweir     virtual void SAL_CALL deactivatedInplace() throw ( embed::WrongStateException, uno::RuntimeException );
170cdf0e10cSrcweir     virtual void SAL_CALL deactivatedUI() throw ( embed::WrongStateException, uno::RuntimeException );
171cdf0e10cSrcweir     virtual uno::Reference< ::com::sun::star::frame::XLayoutManager > SAL_CALL getLayoutManager() throw ( embed::WrongStateException, uno::RuntimeException );
172cdf0e10cSrcweir     virtual uno::Reference< frame::XDispatchProvider > SAL_CALL getInplaceDispatchProvider() throw ( embed::WrongStateException, uno::RuntimeException );
173cdf0e10cSrcweir     virtual awt::Rectangle SAL_CALL getPlacement() throw ( embed::WrongStateException, uno::RuntimeException );
174cdf0e10cSrcweir     virtual awt::Rectangle SAL_CALL getClipRectangle() throw ( embed::WrongStateException, uno::RuntimeException );
175cdf0e10cSrcweir     virtual void SAL_CALL translateAccelerators( const uno::Sequence< awt::KeyEvent >& aKeys ) throw ( embed::WrongStateException, uno::RuntimeException );
176cdf0e10cSrcweir     virtual void SAL_CALL scrollObject( const awt::Size& aOffset ) throw ( embed::WrongStateException, uno::RuntimeException );
177cdf0e10cSrcweir     virtual void SAL_CALL changedPlacement( const awt::Rectangle& aPosRect ) throw ( embed::WrongStateException, uno::Exception, uno::RuntimeException );
178cdf0e10cSrcweir 
179cdf0e10cSrcweir     // XWindowSupplier
180cdf0e10cSrcweir     virtual uno::Reference< awt::XWindow > SAL_CALL getWindow() throw ( uno::RuntimeException );
181cdf0e10cSrcweir };
182cdf0e10cSrcweir 
183cdf0e10cSrcweir //--------------------------------------------------------------------
184cdf0e10cSrcweir SdrLightEmbeddedClient_Impl::SdrLightEmbeddedClient_Impl( SdrOle2Obj* pObj )
185cdf0e10cSrcweir : mpObj( pObj )
186cdf0e10cSrcweir {
187cdf0e10cSrcweir }
188cdf0e10cSrcweir Rectangle SdrLightEmbeddedClient_Impl::impl_getScaledRect_nothrow() const
189cdf0e10cSrcweir {
190cdf0e10cSrcweir     MapUnit aContainerMapUnit( MAP_100TH_MM );
191cdf0e10cSrcweir     uno::Reference< embed::XVisualObject > xParentVis( mpObj->GetParentXModel(), uno::UNO_QUERY );
192cdf0e10cSrcweir     if ( xParentVis.is() )
193cdf0e10cSrcweir 	    aContainerMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xParentVis->getMapUnit( mpObj->GetAspect() ) );
194cdf0e10cSrcweir     Rectangle aLogicRect( mpObj->GetLogicRect() );
195cdf0e10cSrcweir     // apply scaling to object area and convert to pixels
196cdf0e10cSrcweir     aLogicRect.SetSize( Size( Fraction( aLogicRect.GetWidth() ) * m_aScaleWidth,
197cdf0e10cSrcweir                     			Fraction( aLogicRect.GetHeight() ) * m_aScaleHeight ) );
198cdf0e10cSrcweir     return aLogicRect;
199cdf0e10cSrcweir }
200cdf0e10cSrcweir //--------------------------------------------------------------------
201cdf0e10cSrcweir void SAL_CALL SdrLightEmbeddedClient_Impl::changingState( const ::com::sun::star::lang::EventObject& /*aEvent*/, ::sal_Int32 /*nOldState*/, ::sal_Int32 /*nNewState*/ ) throw (::com::sun::star::embed::WrongStateException, ::com::sun::star::uno::RuntimeException)
202cdf0e10cSrcweir {
203cdf0e10cSrcweir }
204cdf0e10cSrcweir 
205cdf0e10cSrcweir //--------------------------------------------------------------------
206cdf0e10cSrcweir void SdrLightEmbeddedClient_Impl::Release()
207cdf0e10cSrcweir {
208cdf0e10cSrcweir 	{
209cdf0e10cSrcweir 		::vos::OGuard aGuard( Application::GetSolarMutex() );
210cdf0e10cSrcweir     	mpObj = NULL;
211cdf0e10cSrcweir 	}
212cdf0e10cSrcweir 
213cdf0e10cSrcweir     release();
214cdf0e10cSrcweir }
215cdf0e10cSrcweir 
216cdf0e10cSrcweir //--------------------------------------------------------------------
217cdf0e10cSrcweir void SAL_CALL SdrLightEmbeddedClient_Impl::stateChanged( const ::com::sun::star::lang::EventObject& /*aEvent*/, ::sal_Int32 nOldState, ::sal_Int32 nNewState ) throw (::com::sun::star::uno::RuntimeException)
218cdf0e10cSrcweir {
219cdf0e10cSrcweir 	::vos::OGuard aGuard( Application::GetSolarMutex() );
220cdf0e10cSrcweir 
221cdf0e10cSrcweir     if ( mpObj && nOldState == embed::EmbedStates::LOADED && nNewState == embed::EmbedStates::RUNNING )
222cdf0e10cSrcweir     {
223cdf0e10cSrcweir         mpObj->ObjectLoaded();
224cdf0e10cSrcweir         GetSdrGlobalData().GetOLEObjCache().InsertObj(mpObj);
225cdf0e10cSrcweir     }
226cdf0e10cSrcweir     else if ( mpObj && nNewState == embed::EmbedStates::LOADED && nOldState == embed::EmbedStates::RUNNING )
227cdf0e10cSrcweir     {
228cdf0e10cSrcweir         GetSdrGlobalData().GetOLEObjCache().RemoveObj(mpObj);
229cdf0e10cSrcweir     }
230cdf0e10cSrcweir }
231cdf0e10cSrcweir 
232cdf0e10cSrcweir //--------------------------------------------------------------------
233cdf0e10cSrcweir void SAL_CALL SdrLightEmbeddedClient_Impl::disposing( const ::com::sun::star::lang::EventObject& /*aEvent*/ ) throw (::com::sun::star::uno::RuntimeException)
234cdf0e10cSrcweir {
235cdf0e10cSrcweir 	::vos::OGuard aGuard( Application::GetSolarMutex() );
236cdf0e10cSrcweir 
237cdf0e10cSrcweir     GetSdrGlobalData().GetOLEObjCache().RemoveObj(mpObj);
238cdf0e10cSrcweir }
239cdf0e10cSrcweir 
240cdf0e10cSrcweir //--------------------------------------------------------------------
241cdf0e10cSrcweir void SAL_CALL SdrLightEmbeddedClient_Impl::notifyEvent( const document::EventObject& aEvent ) throw( uno::RuntimeException )
242cdf0e10cSrcweir {
243cdf0e10cSrcweir 	// TODO/LATER: when writer uses this implementation the code could be shared with SfxInPlaceClient_Impl
244cdf0e10cSrcweir 
245cdf0e10cSrcweir 	::vos::OGuard aGuard( Application::GetSolarMutex() );
246cdf0e10cSrcweir 
247cdf0e10cSrcweir 	// the code currently makes sence only in case there is no other client
248cdf0e10cSrcweir 	if ( mpObj && mpObj->GetAspect() != embed::Aspects::MSOLE_ICON && aEvent.EventName.equalsAscii("OnVisAreaChanged")
249cdf0e10cSrcweir 	  && mpObj->GetObjRef().is() && mpObj->GetObjRef()->getClientSite() == uno::Reference< embed::XEmbeddedClient >( this ) )
250cdf0e10cSrcweir 	{
251cdf0e10cSrcweir 		try
252cdf0e10cSrcweir 		{
253cdf0e10cSrcweir             MapUnit aContainerMapUnit( MAP_100TH_MM );
254cdf0e10cSrcweir 		    uno::Reference< embed::XVisualObject > xParentVis( mpObj->GetParentXModel(), uno::UNO_QUERY );
255cdf0e10cSrcweir 		    if ( xParentVis.is() )
256cdf0e10cSrcweir 			    aContainerMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xParentVis->getMapUnit( mpObj->GetAspect() ) );
257cdf0e10cSrcweir 
258cdf0e10cSrcweir 		    MapUnit aObjMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( mpObj->GetObjRef()->getMapUnit( mpObj->GetAspect() ) );
259cdf0e10cSrcweir 
260cdf0e10cSrcweir 		    Rectangle		   aVisArea;
261cdf0e10cSrcweir 		    awt::Size aSz;
262cdf0e10cSrcweir 		    try
263cdf0e10cSrcweir 		    {
264cdf0e10cSrcweir 			    aSz = mpObj->GetObjRef()->getVisualAreaSize( mpObj->GetAspect() );
265cdf0e10cSrcweir 		    }
266cdf0e10cSrcweir 		    catch( embed::NoVisualAreaSizeException& )
267cdf0e10cSrcweir 		    {
268cdf0e10cSrcweir 			    OSL_ENSURE( sal_False, "No visual area size!\n" );
269cdf0e10cSrcweir 			    aSz.Width = 5000;
270cdf0e10cSrcweir 			    aSz.Height = 5000;
271cdf0e10cSrcweir 		    }
272cdf0e10cSrcweir 		    catch( uno::Exception& )
273cdf0e10cSrcweir 		    {
274cdf0e10cSrcweir 			    OSL_ENSURE( sal_False, "Unexpected exception!\n" );
275cdf0e10cSrcweir 			    aSz.Width = 5000;
276cdf0e10cSrcweir 			    aSz.Height = 5000;
277cdf0e10cSrcweir 		    }
278cdf0e10cSrcweir 
279cdf0e10cSrcweir 		    aVisArea.SetSize( Size( aSz.Width, aSz.Height ) );
280cdf0e10cSrcweir 		    aVisArea = OutputDevice::LogicToLogic( aVisArea, aObjMapUnit, aContainerMapUnit );
281cdf0e10cSrcweir 		    Size aScaledSize( static_cast< long >( m_aScaleWidth * Fraction( aVisArea.GetWidth() ) ),
282cdf0e10cSrcweir 							    static_cast< long >( m_aScaleHeight * Fraction( aVisArea.GetHeight() ) ) );
283cdf0e10cSrcweir             Rectangle aLogicRect( mpObj->GetLogicRect() );
284cdf0e10cSrcweir 
285cdf0e10cSrcweir 			// react to the change if the difference is bigger than one pixel
286cdf0e10cSrcweir 			Size aPixelDiff =
287cdf0e10cSrcweir 				Application::GetDefaultDevice()->LogicToPixel(
288cdf0e10cSrcweir 					Size( aLogicRect.GetWidth() - aScaledSize.Width(),
289cdf0e10cSrcweir 						  aLogicRect.GetHeight() - aScaledSize.Height() ),
290cdf0e10cSrcweir 					aContainerMapUnit );
291cdf0e10cSrcweir 			if( aPixelDiff.Width() || aPixelDiff.Height() )
292cdf0e10cSrcweir 			{
293cdf0e10cSrcweir 				mpObj->SetLogicRect( Rectangle( aLogicRect.TopLeft(), aScaledSize ) );
294cdf0e10cSrcweir 				mpObj->BroadcastObjectChange();
295cdf0e10cSrcweir 			}
296cdf0e10cSrcweir 			else
297cdf0e10cSrcweir 				mpObj->ActionChanged();
298cdf0e10cSrcweir 		}
299cdf0e10cSrcweir 		catch( uno::Exception& )
300cdf0e10cSrcweir 		{
301cdf0e10cSrcweir 			OSL_ENSURE( sal_False, "Unexpected exception!\n" );
302cdf0e10cSrcweir 		}
303cdf0e10cSrcweir 	}
304cdf0e10cSrcweir }
305cdf0e10cSrcweir 
306cdf0e10cSrcweir //--------------------------------------------------------------------
307cdf0e10cSrcweir void SAL_CALL SdrLightEmbeddedClient_Impl::saveObject()
308cdf0e10cSrcweir 	throw ( embed::ObjectSaveVetoException,
309cdf0e10cSrcweir 			uno::Exception,
310cdf0e10cSrcweir 			uno::RuntimeException )
311cdf0e10cSrcweir {
312cdf0e10cSrcweir 	// TODO/LATER: when writer uses this implementation the code could be shared with SfxInPlaceClient_Impl
313cdf0e10cSrcweir 	uno::Reference< embed::XCommonEmbedPersist > xPersist;
314cdf0e10cSrcweir 	uno::Reference< util::XModifiable > xModifiable;
315cdf0e10cSrcweir 
316cdf0e10cSrcweir 	{
317cdf0e10cSrcweir 		::vos::OGuard aGuard( Application::GetSolarMutex() );
318cdf0e10cSrcweir 
319cdf0e10cSrcweir 		if ( !mpObj )
320cdf0e10cSrcweir 			throw embed::ObjectSaveVetoException();
321cdf0e10cSrcweir 
322cdf0e10cSrcweir 		// the common persistance is supported by objects and links
323cdf0e10cSrcweir 		xPersist = uno::Reference< embed::XCommonEmbedPersist >( mpObj->GetObjRef(), uno::UNO_QUERY_THROW );
324cdf0e10cSrcweir 		xModifiable = uno::Reference< util::XModifiable >( mpObj->GetParentXModel(), uno::UNO_QUERY );
325cdf0e10cSrcweir 	}
326cdf0e10cSrcweir 
327cdf0e10cSrcweir 	xPersist->storeOwn();
328cdf0e10cSrcweir 
329cdf0e10cSrcweir 	if ( xModifiable.is() )
330cdf0e10cSrcweir 		xModifiable->setModified( sal_True );
331cdf0e10cSrcweir }
332cdf0e10cSrcweir 
333cdf0e10cSrcweir //--------------------------------------------------------------------
334cdf0e10cSrcweir void SAL_CALL SdrLightEmbeddedClient_Impl::visibilityChanged( sal_Bool /*bVisible*/ )
335cdf0e10cSrcweir 	throw ( embed::WrongStateException,
336cdf0e10cSrcweir 			uno::RuntimeException )
337cdf0e10cSrcweir {
338cdf0e10cSrcweir 	// nothing to do currently
339cdf0e10cSrcweir 	// TODO/LATER: when writer uses this implementation the code could be shared with SfxInPlaceClient_Impl
340cdf0e10cSrcweir     if ( mpObj )
341cdf0e10cSrcweir     {
342cdf0e10cSrcweir         Rectangle aLogicRect( mpObj->GetLogicRect() );
343cdf0e10cSrcweir         Size aLogicSize( aLogicRect.GetWidth(), aLogicRect.GetHeight() );
344cdf0e10cSrcweir 
345cdf0e10cSrcweir         if( mpObj->IsChart() )
346cdf0e10cSrcweir         {
347cdf0e10cSrcweir             //charts never should be stretched see #i84323# for example
348cdf0e10cSrcweir             mpObj->SetLogicRect( Rectangle( aLogicRect.TopLeft(), aLogicSize ) );
349cdf0e10cSrcweir             mpObj->BroadcastObjectChange();
350cdf0e10cSrcweir         } // if( mpObj->IsChart() )
351cdf0e10cSrcweir     }
352cdf0e10cSrcweir }
353cdf0e10cSrcweir 
354cdf0e10cSrcweir //--------------------------------------------------------------------
355cdf0e10cSrcweir uno::Reference< util::XCloseable > SAL_CALL SdrLightEmbeddedClient_Impl::getComponent()
356cdf0e10cSrcweir 	throw ( uno::RuntimeException )
357cdf0e10cSrcweir {
358cdf0e10cSrcweir 	uno::Reference< util::XCloseable > xResult;
359cdf0e10cSrcweir 
360cdf0e10cSrcweir 	::vos::OGuard aGuard( Application::GetSolarMutex() );
361cdf0e10cSrcweir 	if ( mpObj )
362cdf0e10cSrcweir 		xResult = uno::Reference< util::XCloseable >( mpObj->GetParentXModel(), uno::UNO_QUERY );
363cdf0e10cSrcweir 
364cdf0e10cSrcweir 	return xResult;
365cdf0e10cSrcweir }
366cdf0e10cSrcweir // XInplaceClient
367cdf0e10cSrcweir //--------------------------------------------------------------------
368cdf0e10cSrcweir sal_Bool SAL_CALL SdrLightEmbeddedClient_Impl::canInplaceActivate()
369cdf0e10cSrcweir 	throw ( uno::RuntimeException )
370cdf0e10cSrcweir {
371cdf0e10cSrcweir     sal_Bool bRet = sal_False;
372cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
373cdf0e10cSrcweir     if ( mpObj )
374cdf0e10cSrcweir     {
375cdf0e10cSrcweir         uno::Reference< embed::XEmbeddedObject > xObject = mpObj->GetObjRef();
376cdf0e10cSrcweir         if ( !xObject.is() )
377cdf0e10cSrcweir 		    throw uno::RuntimeException();
378cdf0e10cSrcweir         // we don't want to switch directly from outplace to inplace mode
379cdf0e10cSrcweir         bRet = !( xObject->getCurrentState() == embed::EmbedStates::ACTIVE || mpObj->GetAspect() == embed::Aspects::MSOLE_ICON );
380cdf0e10cSrcweir     } // if ( mpObj )
381cdf0e10cSrcweir     return bRet;
382cdf0e10cSrcweir }
383cdf0e10cSrcweir 
384cdf0e10cSrcweir //--------------------------------------------------------------------
385cdf0e10cSrcweir void SAL_CALL SdrLightEmbeddedClient_Impl::activatingInplace()
386cdf0e10cSrcweir 	throw ( embed::WrongStateException,
387cdf0e10cSrcweir 			uno::RuntimeException )
388cdf0e10cSrcweir {
389cdf0e10cSrcweir }
390cdf0e10cSrcweir 
391cdf0e10cSrcweir //--------------------------------------------------------------------
392cdf0e10cSrcweir void SAL_CALL SdrLightEmbeddedClient_Impl::activatingUI()
393cdf0e10cSrcweir 	throw ( embed::WrongStateException,
394cdf0e10cSrcweir 			uno::RuntimeException )
395cdf0e10cSrcweir {
396cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
397cdf0e10cSrcweir 
398cdf0e10cSrcweir     uno::Reference < beans::XPropertySet > xFrame( lcl_getFrame_throw(mpObj));
399cdf0e10cSrcweir     uno::Reference < frame::XFrame > xOwnFrame( xFrame,uno::UNO_QUERY);
400cdf0e10cSrcweir     uno::Reference < frame::XFramesSupplier > xParentFrame( xOwnFrame->getCreator(), uno::UNO_QUERY );
401cdf0e10cSrcweir     if ( xParentFrame.is() )
402cdf0e10cSrcweir         xParentFrame->setActiveFrame( xOwnFrame );
403cdf0e10cSrcweir 
404cdf0e10cSrcweir     OLEObjCache& rObjCache = GetSdrGlobalData().GetOLEObjCache();
405cdf0e10cSrcweir     const sal_uIntPtr nCount = rObjCache.Count();
406cdf0e10cSrcweir     for(sal_Int32 i = nCount-1 ; i >= 0;--i)
407cdf0e10cSrcweir     {
408cdf0e10cSrcweir         SdrOle2Obj* pObj = reinterpret_cast<SdrOle2Obj*>(rObjCache.GetObject(i));
409cdf0e10cSrcweir         if ( pObj != mpObj )
410cdf0e10cSrcweir         {
411cdf0e10cSrcweir             // only deactivate ole objects which belongs to the same frame
412cdf0e10cSrcweir             if ( xFrame == lcl_getFrame_throw(pObj) )
413cdf0e10cSrcweir             {
414cdf0e10cSrcweir                 uno::Reference< embed::XEmbeddedObject > xObject = pObj->GetObjRef();
415cdf0e10cSrcweir                 try
416cdf0e10cSrcweir                 {
417cdf0e10cSrcweir                     if ( xObject->getStatus( pObj->GetAspect() ) & embed::EmbedMisc::MS_EMBED_ACTIVATEWHENVISIBLE )
418cdf0e10cSrcweir                         xObject->changeState( embed::EmbedStates::INPLACE_ACTIVE );
419cdf0e10cSrcweir                     else
420cdf0e10cSrcweir                     {
421cdf0e10cSrcweir                         // the links should not stay in running state for long time because of locking
422cdf0e10cSrcweir                         uno::Reference< embed::XLinkageSupport > xLink( xObject, uno::UNO_QUERY );
423cdf0e10cSrcweir                         if ( xLink.is() && xLink->isLink() )
424cdf0e10cSrcweir                             xObject->changeState( embed::EmbedStates::LOADED );
425cdf0e10cSrcweir                         else
426cdf0e10cSrcweir                             xObject->changeState( embed::EmbedStates::RUNNING );
427cdf0e10cSrcweir                     }
428cdf0e10cSrcweir                 }
429cdf0e10cSrcweir                 catch (com::sun::star::uno::Exception& )
430cdf0e10cSrcweir                 {}
431cdf0e10cSrcweir             }
432cdf0e10cSrcweir         }
433cdf0e10cSrcweir     } // for(sal_Int32 i = nCount-1 ; i >= 0;--i)
434cdf0e10cSrcweir 
435cdf0e10cSrcweir     //m_pClient->GetViewShell()->UIActivating( m_pClient );
436cdf0e10cSrcweir }
437cdf0e10cSrcweir 
438cdf0e10cSrcweir //--------------------------------------------------------------------
439cdf0e10cSrcweir void SAL_CALL SdrLightEmbeddedClient_Impl::deactivatedInplace()
440cdf0e10cSrcweir 	throw ( embed::WrongStateException,
441cdf0e10cSrcweir 			uno::RuntimeException )
442cdf0e10cSrcweir {
443cdf0e10cSrcweir }
444cdf0e10cSrcweir 
445cdf0e10cSrcweir //--------------------------------------------------------------------
446cdf0e10cSrcweir void SAL_CALL SdrLightEmbeddedClient_Impl::deactivatedUI()
447cdf0e10cSrcweir 	throw ( embed::WrongStateException,
448cdf0e10cSrcweir 			uno::RuntimeException )
449cdf0e10cSrcweir {
450cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
451cdf0e10cSrcweir     com::sun::star::uno::Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager(getLayoutManager());
452cdf0e10cSrcweir     if ( xLayoutManager.is() )
453cdf0e10cSrcweir     {
454cdf0e10cSrcweir         const static rtl::OUString aMenuBarURL( RTL_CONSTASCII_USTRINGPARAM( "private:resource/menubar/menubar" ));
455cdf0e10cSrcweir 		if ( !xLayoutManager->isElementVisible( aMenuBarURL ) )
456cdf0e10cSrcweir         	xLayoutManager->createElement( aMenuBarURL );
457cdf0e10cSrcweir     }
458cdf0e10cSrcweir }
459cdf0e10cSrcweir 
460cdf0e10cSrcweir //--------------------------------------------------------------------
461cdf0e10cSrcweir uno::Reference< ::com::sun::star::frame::XLayoutManager > SAL_CALL SdrLightEmbeddedClient_Impl::getLayoutManager()
462cdf0e10cSrcweir 	throw ( embed::WrongStateException,
463cdf0e10cSrcweir 			uno::RuntimeException )
464cdf0e10cSrcweir {
465cdf0e10cSrcweir     uno::Reference< ::com::sun::star::frame::XLayoutManager > xMan;
466cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
467cdf0e10cSrcweir     uno::Reference < beans::XPropertySet > xFrame( lcl_getFrame_throw(mpObj));
468cdf0e10cSrcweir     try
469cdf0e10cSrcweir     {
470cdf0e10cSrcweir         xMan.set(xFrame->getPropertyValue( ::rtl::OUString::createFromAscii("LayoutManager") ),uno::UNO_QUERY);
471cdf0e10cSrcweir     }
472cdf0e10cSrcweir     catch ( uno::Exception& )
473cdf0e10cSrcweir     {
474cdf0e10cSrcweir         throw uno::RuntimeException();
475cdf0e10cSrcweir     }
476cdf0e10cSrcweir 
477cdf0e10cSrcweir     return xMan;
478cdf0e10cSrcweir }
479cdf0e10cSrcweir 
480cdf0e10cSrcweir //--------------------------------------------------------------------
481cdf0e10cSrcweir uno::Reference< frame::XDispatchProvider > SAL_CALL SdrLightEmbeddedClient_Impl::getInplaceDispatchProvider()
482cdf0e10cSrcweir 	throw ( embed::WrongStateException,
483cdf0e10cSrcweir 			uno::RuntimeException )
484cdf0e10cSrcweir {
485cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
486cdf0e10cSrcweir 	return uno::Reference < frame::XDispatchProvider >( lcl_getFrame_throw(mpObj), uno::UNO_QUERY_THROW );
487cdf0e10cSrcweir }
488cdf0e10cSrcweir 
489cdf0e10cSrcweir //--------------------------------------------------------------------
490cdf0e10cSrcweir awt::Rectangle SAL_CALL SdrLightEmbeddedClient_Impl::getPlacement()
491cdf0e10cSrcweir 	throw ( embed::WrongStateException,
492cdf0e10cSrcweir 			uno::RuntimeException )
493cdf0e10cSrcweir {
494cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
495cdf0e10cSrcweir     if ( !mpObj )
496cdf0e10cSrcweir         throw uno::RuntimeException();
497cdf0e10cSrcweir 
498cdf0e10cSrcweir     Rectangle aLogicRect = impl_getScaledRect_nothrow();
499cdf0e10cSrcweir     MapUnit aContainerMapUnit( MAP_100TH_MM );
500cdf0e10cSrcweir     uno::Reference< embed::XVisualObject > xParentVis( mpObj->GetParentXModel(), uno::UNO_QUERY );
501cdf0e10cSrcweir     if ( xParentVis.is() )
502cdf0e10cSrcweir 	    aContainerMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xParentVis->getMapUnit( mpObj->GetAspect() ) );
503cdf0e10cSrcweir 
504cdf0e10cSrcweir     aLogicRect = Application::GetDefaultDevice()->LogicToPixel(aLogicRect,aContainerMapUnit);
505cdf0e10cSrcweir 	return AWTRectangle( aLogicRect );
506cdf0e10cSrcweir }
507cdf0e10cSrcweir 
508cdf0e10cSrcweir //--------------------------------------------------------------------
509cdf0e10cSrcweir awt::Rectangle SAL_CALL SdrLightEmbeddedClient_Impl::getClipRectangle()
510cdf0e10cSrcweir 	throw ( embed::WrongStateException,
511cdf0e10cSrcweir 			uno::RuntimeException )
512cdf0e10cSrcweir {
513cdf0e10cSrcweir 	return getPlacement();
514cdf0e10cSrcweir }
515cdf0e10cSrcweir 
516cdf0e10cSrcweir //--------------------------------------------------------------------
517cdf0e10cSrcweir void SAL_CALL SdrLightEmbeddedClient_Impl::translateAccelerators( const uno::Sequence< awt::KeyEvent >& /*aKeys*/ )
518cdf0e10cSrcweir 	throw ( embed::WrongStateException,
519cdf0e10cSrcweir 			uno::RuntimeException )
520cdf0e10cSrcweir {
521cdf0e10cSrcweir }
522cdf0e10cSrcweir 
523cdf0e10cSrcweir //--------------------------------------------------------------------
524cdf0e10cSrcweir void SAL_CALL SdrLightEmbeddedClient_Impl::scrollObject( const awt::Size& /*aOffset*/ )
525cdf0e10cSrcweir 	throw ( embed::WrongStateException,
526cdf0e10cSrcweir 			uno::RuntimeException )
527cdf0e10cSrcweir {
528cdf0e10cSrcweir }
529cdf0e10cSrcweir 
530cdf0e10cSrcweir //--------------------------------------------------------------------
531cdf0e10cSrcweir void SAL_CALL SdrLightEmbeddedClient_Impl::changedPlacement( const awt::Rectangle& aPosRect )
532cdf0e10cSrcweir 	throw ( embed::WrongStateException,
533cdf0e10cSrcweir 			uno::Exception,
534cdf0e10cSrcweir 			uno::RuntimeException )
535cdf0e10cSrcweir {
536cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
537cdf0e10cSrcweir     if ( !mpObj )
538cdf0e10cSrcweir         throw uno::RuntimeException();
539cdf0e10cSrcweir 
540cdf0e10cSrcweir 	uno::Reference< embed::XInplaceObject > xInplace( mpObj->GetObjRef(), uno::UNO_QUERY );
541cdf0e10cSrcweir     if ( !xInplace.is() )
542cdf0e10cSrcweir 		throw uno::RuntimeException();
543cdf0e10cSrcweir 
544cdf0e10cSrcweir     // check if the change is at least one pixel in size
545cdf0e10cSrcweir     awt::Rectangle aOldRect = getPlacement();
546cdf0e10cSrcweir     Rectangle aNewPixelRect = VCLRectangle( aPosRect );
547cdf0e10cSrcweir     Rectangle aOldPixelRect = VCLRectangle( aOldRect );
548cdf0e10cSrcweir     if ( aOldPixelRect == aNewPixelRect )
549cdf0e10cSrcweir         // nothing has changed
550cdf0e10cSrcweir         return;
551cdf0e10cSrcweir 
552cdf0e10cSrcweir     // new scaled object area
553cdf0e10cSrcweir     MapUnit aContainerMapUnit( MAP_100TH_MM );
554cdf0e10cSrcweir     uno::Reference< embed::XVisualObject > xParentVis( mpObj->GetParentXModel(), uno::UNO_QUERY );
555cdf0e10cSrcweir     if ( xParentVis.is() )
556cdf0e10cSrcweir 	    aContainerMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xParentVis->getMapUnit( mpObj->GetAspect() ) );
557cdf0e10cSrcweir 
558cdf0e10cSrcweir     Rectangle aNewLogicRect = Application::GetDefaultDevice()->PixelToLogic(aNewPixelRect,aContainerMapUnit);
559cdf0e10cSrcweir     Rectangle aLogicRect = impl_getScaledRect_nothrow();
560cdf0e10cSrcweir 
561cdf0e10cSrcweir     if ( aNewLogicRect != aLogicRect )
562cdf0e10cSrcweir 	{
563cdf0e10cSrcweir 		// the calculation of the object area has not changed the object size
564cdf0e10cSrcweir 		// it should be done here then
565cdf0e10cSrcweir 		//SfxBooleanFlagGuard aGuard( m_bResizeNoScale, sal_True );
566cdf0e10cSrcweir 
567cdf0e10cSrcweir     	// new size of the object area without scaling
568cdf0e10cSrcweir     	Size aNewObjSize( Fraction( aNewLogicRect.GetWidth() ) / m_aScaleWidth,
569cdf0e10cSrcweir                           Fraction( aNewLogicRect.GetHeight() ) / m_aScaleHeight );
570cdf0e10cSrcweir 
571cdf0e10cSrcweir     	// now remove scaling from new placement and keep this a the new object area
572cdf0e10cSrcweir     	aNewLogicRect.SetSize( aNewObjSize );
573cdf0e10cSrcweir         // react to the change if the difference is bigger than one pixel
574cdf0e10cSrcweir 		Size aPixelDiff =
575cdf0e10cSrcweir 			Application::GetDefaultDevice()->LogicToPixel(
576cdf0e10cSrcweir 				Size( aLogicRect.GetWidth() - aNewObjSize.Width(),
577cdf0e10cSrcweir 					  aLogicRect.GetHeight() - aNewObjSize.Height() ),
578cdf0e10cSrcweir 				aContainerMapUnit );
579cdf0e10cSrcweir 		if( aPixelDiff.Width() || aPixelDiff.Height() )
580cdf0e10cSrcweir 		{
581cdf0e10cSrcweir 			mpObj->SetLogicRect( Rectangle( aLogicRect.TopLeft(), aNewObjSize ) );
582cdf0e10cSrcweir 			mpObj->BroadcastObjectChange();
583cdf0e10cSrcweir 		}
584cdf0e10cSrcweir 		else
585cdf0e10cSrcweir 			mpObj->ActionChanged();
586cdf0e10cSrcweir 
587cdf0e10cSrcweir 		// let the window size be recalculated
588cdf0e10cSrcweir 		//SizeHasChanged(); // TODO: OJ
589cdf0e10cSrcweir 	}
590cdf0e10cSrcweir }
591cdf0e10cSrcweir // XWindowSupplier
592cdf0e10cSrcweir //--------------------------------------------------------------------
593cdf0e10cSrcweir uno::Reference< awt::XWindow > SAL_CALL SdrLightEmbeddedClient_Impl::getWindow()
594cdf0e10cSrcweir 	throw ( uno::RuntimeException )
595cdf0e10cSrcweir {
596cdf0e10cSrcweir 	::vos::OGuard aGuard( Application::GetSolarMutex() );
597cdf0e10cSrcweir     uno::Reference< awt::XWindow > xCurrent = m_xWindow;
598cdf0e10cSrcweir     if ( !xCurrent.is() )
599cdf0e10cSrcweir     {
600cdf0e10cSrcweir         if ( !mpObj )
601cdf0e10cSrcweir             throw uno::RuntimeException();
602cdf0e10cSrcweir         uno::Reference< frame::XFrame> xFrame(lcl_getFrame_throw(mpObj),uno::UNO_QUERY_THROW);
603cdf0e10cSrcweir         xCurrent = xFrame->getComponentWindow();
604cdf0e10cSrcweir     } // if ( !xCurrent.is() )
605cdf0e10cSrcweir     return xCurrent;
606cdf0e10cSrcweir }
607cdf0e10cSrcweir void SdrLightEmbeddedClient_Impl::setWindow(const uno::Reference< awt::XWindow >& _xWindow)
608cdf0e10cSrcweir {
609cdf0e10cSrcweir     m_xWindow = _xWindow;
610cdf0e10cSrcweir }
611cdf0e10cSrcweir 
612cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
613cdf0e10cSrcweir 
614cdf0e10cSrcweir class SdrEmbedObjectLink : public sfx2::SvBaseLink
615cdf0e10cSrcweir {
616cdf0e10cSrcweir 	SdrOle2Obj*			pObj;
617cdf0e10cSrcweir 
618cdf0e10cSrcweir public:
619cdf0e10cSrcweir 						SdrEmbedObjectLink(SdrOle2Obj* pObj);
620cdf0e10cSrcweir 	virtual				~SdrEmbedObjectLink();
621cdf0e10cSrcweir 
622cdf0e10cSrcweir 	virtual void		Closed();
623cdf0e10cSrcweir 	virtual void		DataChanged( const String& rMimeType,
624cdf0e10cSrcweir 								const ::com::sun::star::uno::Any & rValue );
625cdf0e10cSrcweir 
626cdf0e10cSrcweir 	sal_Bool			Connect() { return GetRealObject() != NULL; }
627cdf0e10cSrcweir };
628cdf0e10cSrcweir 
629cdf0e10cSrcweir // -----------------------------------------------------------------------------
630cdf0e10cSrcweir 
631cdf0e10cSrcweir SdrEmbedObjectLink::SdrEmbedObjectLink(SdrOle2Obj* pObject):
632cdf0e10cSrcweir 	::sfx2::SvBaseLink( ::sfx2::LINKUPDATE_ONCALL, SOT_FORMATSTR_ID_SVXB ),
633cdf0e10cSrcweir 	pObj(pObject)
634cdf0e10cSrcweir {
635cdf0e10cSrcweir 	SetSynchron( sal_False );
636cdf0e10cSrcweir }
637cdf0e10cSrcweir 
638cdf0e10cSrcweir // -----------------------------------------------------------------------------
639cdf0e10cSrcweir 
640cdf0e10cSrcweir SdrEmbedObjectLink::~SdrEmbedObjectLink()
641cdf0e10cSrcweir {
642cdf0e10cSrcweir }
643cdf0e10cSrcweir 
644cdf0e10cSrcweir // -----------------------------------------------------------------------------
645cdf0e10cSrcweir 
646cdf0e10cSrcweir void SdrEmbedObjectLink::DataChanged( const String& /*rMimeType*/,
647cdf0e10cSrcweir 								const ::com::sun::star::uno::Any & /*rValue*/ )
648cdf0e10cSrcweir {
649cdf0e10cSrcweir 	if ( !pObj->UpdateLinkURL_Impl() )
650cdf0e10cSrcweir 	{
651cdf0e10cSrcweir 		// the link URL was not changed
652cdf0e10cSrcweir 		uno::Reference< embed::XEmbeddedObject > xObject = pObj->GetObjRef();
653cdf0e10cSrcweir 		OSL_ENSURE( xObject.is(), "The object must exist always!\n" );
654cdf0e10cSrcweir 		if ( xObject.is() )
655cdf0e10cSrcweir 		{
656cdf0e10cSrcweir 			// let the object reload the link
657cdf0e10cSrcweir 			// TODO/LATER: reload call could be used for this case
658cdf0e10cSrcweir 
659cdf0e10cSrcweir 			try
660cdf0e10cSrcweir 			{
661cdf0e10cSrcweir 				sal_Int32 nState = xObject->getCurrentState();
662cdf0e10cSrcweir 				if ( nState != embed::EmbedStates::LOADED )
663cdf0e10cSrcweir 				{
664cdf0e10cSrcweir 					// in some cases the linked file probably is not locked so it could be changed
665cdf0e10cSrcweir 					xObject->changeState( embed::EmbedStates::LOADED );
666cdf0e10cSrcweir 					xObject->changeState( nState );
667cdf0e10cSrcweir 				}
668cdf0e10cSrcweir 			}
669cdf0e10cSrcweir 			catch ( uno::Exception& )
670cdf0e10cSrcweir 			{
671cdf0e10cSrcweir 			}
672cdf0e10cSrcweir 		}
673cdf0e10cSrcweir 	}
674cdf0e10cSrcweir 
675cdf0e10cSrcweir 	pObj->GetNewReplacement();
676cdf0e10cSrcweir 	pObj->SetChanged();
677cdf0e10cSrcweir }
678cdf0e10cSrcweir 
679cdf0e10cSrcweir // -----------------------------------------------------------------------------
680cdf0e10cSrcweir 
681cdf0e10cSrcweir void SdrEmbedObjectLink::Closed()
682cdf0e10cSrcweir {
683cdf0e10cSrcweir 	pObj->BreakFileLink_Impl();
684cdf0e10cSrcweir 	SvBaseLink::Closed();
685cdf0e10cSrcweir }
686cdf0e10cSrcweir 
687cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
688cdf0e10cSrcweir 
689cdf0e10cSrcweir class SdrOle2ObjImpl
690cdf0e10cSrcweir {
691cdf0e10cSrcweir public:
692cdf0e10cSrcweir     // TODO/LATER: do we really need this pointer?
693cdf0e10cSrcweir 	GraphicObject*	pGraphicObject;
694cdf0e10cSrcweir 	String          aPersistName;       // name of object in persist
695cdf0e10cSrcweir     SdrLightEmbeddedClient_Impl* pLightClient; // must be registered as client only using AddOwnLightClient() call
696cdf0e10cSrcweir 
697cdf0e10cSrcweir 	// #107645#
698cdf0e10cSrcweir 	// New local var to avoid repeated loading if load of OLE2 fails
699cdf0e10cSrcweir 	sal_Bool		mbLoadingOLEObjectFailed;
700cdf0e10cSrcweir     sal_Bool        mbConnected;
701cdf0e10cSrcweir 
702cdf0e10cSrcweir 	SdrEmbedObjectLink*	mpObjectLink;
703cdf0e10cSrcweir 	String maLinkURL;
704cdf0e10cSrcweir 
705cdf0e10cSrcweir 	SdrOle2ObjImpl()
706cdf0e10cSrcweir 	: pGraphicObject( NULL )
707cdf0e10cSrcweir 	// #107645#
708cdf0e10cSrcweir 	// init to start situation, loading did not fail
709cdf0e10cSrcweir 	, mbLoadingOLEObjectFailed( sal_False )
710cdf0e10cSrcweir 	, mbConnected( sal_False )
711cdf0e10cSrcweir 	, mpObjectLink( NULL )
712cdf0e10cSrcweir 	{
713cdf0e10cSrcweir 	}
714cdf0e10cSrcweir };
715cdf0e10cSrcweir 
716cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
717cdf0e10cSrcweir 
718cdf0e10cSrcweir // Predicate determining whether the given OLE is an internal math
719cdf0e10cSrcweir // object
720cdf0e10cSrcweir static bool ImplIsMathObj( const uno::Reference < embed::XEmbeddedObject >& rObjRef )
721cdf0e10cSrcweir {
722cdf0e10cSrcweir     if ( !rObjRef.is() )
723cdf0e10cSrcweir         return false;
724cdf0e10cSrcweir 
725cdf0e10cSrcweir     SvGlobalName aClassName( rObjRef->getClassID() );
726cdf0e10cSrcweir     if( aClassName == SvGlobalName(SO3_SM_CLASSID_30) ||
727cdf0e10cSrcweir         aClassName == SvGlobalName(SO3_SM_CLASSID_40) ||
728cdf0e10cSrcweir         aClassName == SvGlobalName(SO3_SM_CLASSID_50) ||
729cdf0e10cSrcweir         aClassName == SvGlobalName(SO3_SM_CLASSID_60) ||
730cdf0e10cSrcweir         aClassName == SvGlobalName(SO3_SM_CLASSID) 		)
731cdf0e10cSrcweir     {
732cdf0e10cSrcweir         return true;
733cdf0e10cSrcweir     }
734cdf0e10cSrcweir     else
735cdf0e10cSrcweir     {
736cdf0e10cSrcweir         return false;
737cdf0e10cSrcweir     }
738cdf0e10cSrcweir }
739cdf0e10cSrcweir 
740cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
741cdf0e10cSrcweir // BaseProperties section
742cdf0e10cSrcweir 
743cdf0e10cSrcweir sdr::properties::BaseProperties* SdrOle2Obj::CreateObjectSpecificProperties()
744cdf0e10cSrcweir {
745cdf0e10cSrcweir 	return new sdr::properties::OleProperties(*this);
746cdf0e10cSrcweir }
747cdf0e10cSrcweir 
748cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
749cdf0e10cSrcweir // DrawContact section
750cdf0e10cSrcweir 
751cdf0e10cSrcweir sdr::contact::ViewContact* SdrOle2Obj::CreateObjectSpecificViewContact()
752cdf0e10cSrcweir {
753cdf0e10cSrcweir 	return new sdr::contact::ViewContactOfSdrOle2Obj(*this);
754cdf0e10cSrcweir }
755cdf0e10cSrcweir 
756cdf0e10cSrcweir // -----------------------------------------------------------------------------
757cdf0e10cSrcweir 
758cdf0e10cSrcweir TYPEINIT1(SdrOle2Obj,SdrRectObj);
759cdf0e10cSrcweir DBG_NAME(SdrOle2Obj)
760cdf0e10cSrcweir SdrOle2Obj::SdrOle2Obj(FASTBOOL bFrame_) : m_bTypeAsked(false)
761cdf0e10cSrcweir ,m_bChart(false)
762cdf0e10cSrcweir {
763cdf0e10cSrcweir     DBG_CTOR( SdrOle2Obj,NULL);
764cdf0e10cSrcweir 	bInDestruction = sal_False;
765cdf0e10cSrcweir 	Init();
766cdf0e10cSrcweir 	bFrame=bFrame_;
767cdf0e10cSrcweir }
768cdf0e10cSrcweir 
769cdf0e10cSrcweir // -----------------------------------------------------------------------------
770cdf0e10cSrcweir SdrOle2Obj::SdrOle2Obj( const svt::EmbeddedObjectRef& rNewObjRef, FASTBOOL bFrame_)
771cdf0e10cSrcweir     : xObjRef( rNewObjRef )
772cdf0e10cSrcweir     , m_bTypeAsked(false)
773cdf0e10cSrcweir     , m_bChart(false)
774cdf0e10cSrcweir {
775cdf0e10cSrcweir     DBG_CTOR( SdrOle2Obj,NULL);
776cdf0e10cSrcweir 	bInDestruction = sal_False;
777cdf0e10cSrcweir 	Init();
778cdf0e10cSrcweir 
779cdf0e10cSrcweir 	bFrame=bFrame_;
780cdf0e10cSrcweir 
781cdf0e10cSrcweir     if ( xObjRef.is() && (xObjRef->getStatus( GetAspect() ) & embed::EmbedMisc::EMBED_NEVERRESIZE ) )
782cdf0e10cSrcweir         SetResizeProtect(sal_True);
783cdf0e10cSrcweir 
784cdf0e10cSrcweir     // #108759# For math objects, set closed state to transparent
785cdf0e10cSrcweir     if( ImplIsMathObj( xObjRef.GetObject() ) )
786cdf0e10cSrcweir         SetClosedObj( false );
787cdf0e10cSrcweir }
788cdf0e10cSrcweir 
789cdf0e10cSrcweir // -----------------------------------------------------------------------------
790cdf0e10cSrcweir 
791cdf0e10cSrcweir SdrOle2Obj::SdrOle2Obj( const svt::EmbeddedObjectRef& rNewObjRef, const XubString& rNewObjName, FASTBOOL bFrame_)
792cdf0e10cSrcweir     : xObjRef( rNewObjRef )
793cdf0e10cSrcweir     , m_bTypeAsked(false)
794cdf0e10cSrcweir     , m_bChart(false)
795cdf0e10cSrcweir {
796cdf0e10cSrcweir     DBG_CTOR( SdrOle2Obj,NULL);
797cdf0e10cSrcweir 	bInDestruction = sal_False;
798cdf0e10cSrcweir 	Init();
799cdf0e10cSrcweir 
800cdf0e10cSrcweir 	mpImpl->aPersistName = rNewObjName;
801cdf0e10cSrcweir 	bFrame=bFrame_;
802cdf0e10cSrcweir 
803cdf0e10cSrcweir     if ( xObjRef.is() && (xObjRef->getStatus( GetAspect() ) & embed::EmbedMisc::EMBED_NEVERRESIZE ) )
804cdf0e10cSrcweir         SetResizeProtect(sal_True);
805cdf0e10cSrcweir 
806cdf0e10cSrcweir     // #108759# For math objects, set closed state to transparent
807cdf0e10cSrcweir     if( ImplIsMathObj( xObjRef.GetObject() ) )
808cdf0e10cSrcweir         SetClosedObj( false );
809cdf0e10cSrcweir }
810cdf0e10cSrcweir 
811cdf0e10cSrcweir // -----------------------------------------------------------------------------
812cdf0e10cSrcweir 
813cdf0e10cSrcweir SdrOle2Obj::SdrOle2Obj( const svt::EmbeddedObjectRef&  rNewObjRef, const XubString& rNewObjName, const Rectangle& rNewRect, FASTBOOL bFrame_)
814cdf0e10cSrcweir     : SdrRectObj(rNewRect)
815cdf0e10cSrcweir     , xObjRef( rNewObjRef )
816cdf0e10cSrcweir     , m_bTypeAsked(false)
817cdf0e10cSrcweir     , m_bChart(false)
818cdf0e10cSrcweir {
819cdf0e10cSrcweir     DBG_CTOR( SdrOle2Obj,NULL);
820cdf0e10cSrcweir 	bInDestruction = sal_False;
821cdf0e10cSrcweir 	Init();
822cdf0e10cSrcweir 
823cdf0e10cSrcweir 	mpImpl->aPersistName = rNewObjName;
824cdf0e10cSrcweir 	bFrame=bFrame_;
825cdf0e10cSrcweir 
826cdf0e10cSrcweir     if ( xObjRef.is() && (xObjRef->getStatus( GetAspect() ) & embed::EmbedMisc::EMBED_NEVERRESIZE ) )
827cdf0e10cSrcweir         SetResizeProtect(sal_True);
828cdf0e10cSrcweir 
829cdf0e10cSrcweir     // #108759# For math objects, set closed state to transparent
830cdf0e10cSrcweir     if( ImplIsMathObj( xObjRef.GetObject() ) )
831cdf0e10cSrcweir         SetClosedObj( false );
832cdf0e10cSrcweir }
833cdf0e10cSrcweir 
834cdf0e10cSrcweir // -----------------------------------------------------------------------------
835cdf0e10cSrcweir 
836cdf0e10cSrcweir void SdrOle2Obj::Init()
837cdf0e10cSrcweir {
838cdf0e10cSrcweir 	mpImpl = new SdrOle2ObjImpl;
839cdf0e10cSrcweir 	pModifyListener = NULL;
840cdf0e10cSrcweir 	pGraphic=NULL;
841cdf0e10cSrcweir 	mpImpl->pGraphicObject=NULL;
842cdf0e10cSrcweir     mpImpl->pLightClient = 0;
843cdf0e10cSrcweir 
844cdf0e10cSrcweir     xObjRef.Lock( sal_True );
845cdf0e10cSrcweir }
846cdf0e10cSrcweir 
847cdf0e10cSrcweir // -----------------------------------------------------------------------------
848cdf0e10cSrcweir 
849cdf0e10cSrcweir SdrOle2Obj::~SdrOle2Obj()
850cdf0e10cSrcweir {
851cdf0e10cSrcweir     DBG_DTOR( SdrOle2Obj,NULL);
852cdf0e10cSrcweir 	bInDestruction = sal_True;
853cdf0e10cSrcweir 
854cdf0e10cSrcweir     if ( mpImpl->mbConnected )
855cdf0e10cSrcweir         Disconnect();
856cdf0e10cSrcweir 
857cdf0e10cSrcweir     if( pGraphic!=NULL )
858cdf0e10cSrcweir 		delete pGraphic;
859cdf0e10cSrcweir 
860cdf0e10cSrcweir 	if(mpImpl->pGraphicObject!=NULL)
861cdf0e10cSrcweir 		delete mpImpl->pGraphicObject;
862cdf0e10cSrcweir 
863cdf0e10cSrcweir 	if(pModifyListener)
864cdf0e10cSrcweir 	{
865cdf0e10cSrcweir 		pModifyListener->invalidate();
866cdf0e10cSrcweir 		pModifyListener->release();
867cdf0e10cSrcweir 	}
868cdf0e10cSrcweir 
869cdf0e10cSrcweir 	DisconnectFileLink_Impl();
870cdf0e10cSrcweir 
871cdf0e10cSrcweir     if ( mpImpl->pLightClient )
872cdf0e10cSrcweir 	{
873cdf0e10cSrcweir         mpImpl->pLightClient->Release();
874cdf0e10cSrcweir 		mpImpl->pLightClient = NULL;
875cdf0e10cSrcweir 	}
876cdf0e10cSrcweir 
877cdf0e10cSrcweir 	delete mpImpl;
878cdf0e10cSrcweir }
879cdf0e10cSrcweir 
880cdf0e10cSrcweir // -----------------------------------------------------------------------------
881cdf0e10cSrcweir void SdrOle2Obj::SetAspect( sal_Int64 nAspect )
882cdf0e10cSrcweir {
883cdf0e10cSrcweir 	xObjRef.SetViewAspect( nAspect );
884cdf0e10cSrcweir }
885cdf0e10cSrcweir 
886cdf0e10cSrcweir // -----------------------------------------------------------------------------
887cdf0e10cSrcweir 
888cdf0e10cSrcweir void SdrOle2Obj::SetGraphic_Impl(const Graphic* pGrf)
889cdf0e10cSrcweir {
890cdf0e10cSrcweir 	if ( pGraphic )
891cdf0e10cSrcweir 	{
892cdf0e10cSrcweir 		delete pGraphic;
893cdf0e10cSrcweir 		pGraphic = NULL;
894cdf0e10cSrcweir 		delete mpImpl->pGraphicObject;
895cdf0e10cSrcweir 		mpImpl->pGraphicObject = NULL;
896cdf0e10cSrcweir 	}
897cdf0e10cSrcweir 
898cdf0e10cSrcweir 	if (pGrf!=NULL)
899cdf0e10cSrcweir 	{
900cdf0e10cSrcweir 		pGraphic = new Graphic(*pGrf);
901cdf0e10cSrcweir 		mpImpl->pGraphicObject = new GraphicObject( *pGraphic );
902cdf0e10cSrcweir 	}
903cdf0e10cSrcweir 
904cdf0e10cSrcweir 	SetChanged();
905cdf0e10cSrcweir 	BroadcastObjectChange();
906cdf0e10cSrcweir 
907cdf0e10cSrcweir 	//if ( ppObjRef->Is() && pGrf )
908cdf0e10cSrcweir 	//	BroadcastObjectChange();
909cdf0e10cSrcweir }
910cdf0e10cSrcweir 
911cdf0e10cSrcweir void SdrOle2Obj::SetGraphic(const Graphic* pGrf)
912cdf0e10cSrcweir {
913cdf0e10cSrcweir     // only for setting a preview graphic
914cdf0e10cSrcweir     SetGraphic_Impl( pGrf );
915cdf0e10cSrcweir }
916cdf0e10cSrcweir 
917cdf0e10cSrcweir // -----------------------------------------------------------------------------
918cdf0e10cSrcweir 
919cdf0e10cSrcweir FASTBOOL SdrOle2Obj::IsEmpty() const
920cdf0e10cSrcweir {
921cdf0e10cSrcweir     return !(xObjRef.is());
922cdf0e10cSrcweir }
923cdf0e10cSrcweir 
924cdf0e10cSrcweir // -----------------------------------------------------------------------------
925cdf0e10cSrcweir 
926cdf0e10cSrcweir void SdrOle2Obj::Connect()
927cdf0e10cSrcweir {
928cdf0e10cSrcweir 	if( IsEmptyPresObj() )
929cdf0e10cSrcweir 		return;
930cdf0e10cSrcweir 
931cdf0e10cSrcweir     if( mpImpl->mbConnected )
932cdf0e10cSrcweir     {
933cdf0e10cSrcweir         // mba: currently there are situations where it seems to be unavoidable to have multiple connects
934cdf0e10cSrcweir         // changing this would need a larger code rewrite, so for now I remove the assertion
935cdf0e10cSrcweir         // DBG_ERROR("Connect() called on connected object!");
936cdf0e10cSrcweir 		return;
937cdf0e10cSrcweir     }
938cdf0e10cSrcweir 
939cdf0e10cSrcweir     Connect_Impl();
940cdf0e10cSrcweir     AddListeners_Impl();
941cdf0e10cSrcweir }
942cdf0e10cSrcweir 
943cdf0e10cSrcweir // -----------------------------------------------------------------------------
944cdf0e10cSrcweir 
945cdf0e10cSrcweir sal_Bool SdrOle2Obj::UpdateLinkURL_Impl()
946cdf0e10cSrcweir {
947cdf0e10cSrcweir 	sal_Bool bResult = sal_False;
948cdf0e10cSrcweir 
949cdf0e10cSrcweir 	if ( mpImpl->mpObjectLink )
950cdf0e10cSrcweir 	{
951cdf0e10cSrcweir 		sfx2::LinkManager* pLinkManager = pModel ? pModel->GetLinkManager() : NULL;
952cdf0e10cSrcweir 		if ( pLinkManager )
953cdf0e10cSrcweir 		{
954cdf0e10cSrcweir 			String aNewLinkURL;
955cdf0e10cSrcweir 			pLinkManager->GetDisplayNames( mpImpl->mpObjectLink, 0, &aNewLinkURL, 0, 0 );
956cdf0e10cSrcweir 			if ( !aNewLinkURL.EqualsIgnoreCaseAscii( mpImpl->maLinkURL ) )
957cdf0e10cSrcweir 			{
958cdf0e10cSrcweir     			const_cast<SdrOle2Obj*>(this)->GetObjRef_Impl();
959cdf0e10cSrcweir 				uno::Reference< embed::XCommonEmbedPersist > xPersObj( xObjRef.GetObject(), uno::UNO_QUERY );
960cdf0e10cSrcweir 				OSL_ENSURE( xPersObj.is(), "The object must exist!\n" );
961cdf0e10cSrcweir     			if ( xPersObj.is() )
962cdf0e10cSrcweir 				{
963cdf0e10cSrcweir 					try
964cdf0e10cSrcweir 					{
965cdf0e10cSrcweir 						sal_Int32 nCurState = xObjRef->getCurrentState();
966cdf0e10cSrcweir 						if ( nCurState != embed::EmbedStates::LOADED )
967cdf0e10cSrcweir 							xObjRef->changeState( embed::EmbedStates::LOADED );
968cdf0e10cSrcweir 
969cdf0e10cSrcweir 						// TODO/LATER: there should be possible to get current mediadescriptor settings from the object
970cdf0e10cSrcweir 						uno::Sequence< beans::PropertyValue > aArgs( 1 );
971cdf0e10cSrcweir 						aArgs[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) );
972cdf0e10cSrcweir 						aArgs[0].Value <<= ::rtl::OUString( aNewLinkURL );
973cdf0e10cSrcweir 						xPersObj->reload( aArgs, uno::Sequence< beans::PropertyValue >() );
974cdf0e10cSrcweir 
975cdf0e10cSrcweir 						mpImpl->maLinkURL = aNewLinkURL;
976cdf0e10cSrcweir 						bResult = sal_True;
977cdf0e10cSrcweir 
978cdf0e10cSrcweir 						if ( nCurState != embed::EmbedStates::LOADED )
979cdf0e10cSrcweir 							xObjRef->changeState( nCurState );
980cdf0e10cSrcweir 					}
981cdf0e10cSrcweir 					catch( ::com::sun::star::uno::Exception& e )
982cdf0e10cSrcweir 					{
983cdf0e10cSrcweir 						(void)e;
984cdf0e10cSrcweir 						DBG_ERROR(
985cdf0e10cSrcweir 							(OString("SdrOle2Obj::UpdateLinkURL_Impl(), "
986cdf0e10cSrcweir 									"exception caught: ") +
987cdf0e10cSrcweir 							rtl::OUStringToOString(
988cdf0e10cSrcweir 								comphelper::anyToString( cppu::getCaughtException() ),
989cdf0e10cSrcweir 								RTL_TEXTENCODING_UTF8 )).getStr() );
990cdf0e10cSrcweir 					}
991cdf0e10cSrcweir 				}
992cdf0e10cSrcweir 
993cdf0e10cSrcweir 				if ( !bResult )
994cdf0e10cSrcweir 				{
995cdf0e10cSrcweir 					// TODO/LATER: return the old name to the link manager, is it possible?
996cdf0e10cSrcweir 				}
997cdf0e10cSrcweir 			}
998cdf0e10cSrcweir 		}
999cdf0e10cSrcweir 	}
1000cdf0e10cSrcweir 
1001cdf0e10cSrcweir 	return bResult;
1002cdf0e10cSrcweir }
1003cdf0e10cSrcweir 
1004cdf0e10cSrcweir // -----------------------------------------------------------------------------
1005cdf0e10cSrcweir 
1006cdf0e10cSrcweir void SdrOle2Obj::BreakFileLink_Impl()
1007cdf0e10cSrcweir {
1008cdf0e10cSrcweir     uno::Reference<document::XStorageBasedDocument> xDoc;
1009cdf0e10cSrcweir 	if ( pModel )
1010cdf0e10cSrcweir 		xDoc.set( pModel->getUnoModel(),uno::UNO_QUERY);
1011cdf0e10cSrcweir 
1012cdf0e10cSrcweir 	if ( xDoc.is() )
1013cdf0e10cSrcweir 	{
1014cdf0e10cSrcweir 		uno::Reference< embed::XStorage > xStorage = xDoc->getDocumentStorage();
1015cdf0e10cSrcweir 		if ( xStorage.is() )
1016cdf0e10cSrcweir 		{
1017cdf0e10cSrcweir 			try
1018cdf0e10cSrcweir 			{
1019cdf0e10cSrcweir 				uno::Reference< embed::XLinkageSupport > xLinkSupport( xObjRef.GetObject(), uno::UNO_QUERY_THROW );
1020cdf0e10cSrcweir 				xLinkSupport->breakLink( xStorage, mpImpl->aPersistName );
1021cdf0e10cSrcweir 				DisconnectFileLink_Impl();
1022cdf0e10cSrcweir 				mpImpl->maLinkURL = String();
1023cdf0e10cSrcweir 			}
1024cdf0e10cSrcweir 			catch( ::com::sun::star::uno::Exception& e )
1025cdf0e10cSrcweir 			{
1026cdf0e10cSrcweir 				(void)e;
1027cdf0e10cSrcweir 				DBG_ERROR(
1028cdf0e10cSrcweir 					(OString("SdrOle2Obj::BreakFileLink_Impl(), "
1029cdf0e10cSrcweir 							"exception caught: ") +
1030cdf0e10cSrcweir 					rtl::OUStringToOString(
1031cdf0e10cSrcweir 						comphelper::anyToString( cppu::getCaughtException() ),
1032cdf0e10cSrcweir 						RTL_TEXTENCODING_UTF8 )).getStr() );
1033cdf0e10cSrcweir 			}
1034cdf0e10cSrcweir 		}
1035cdf0e10cSrcweir 	}
1036cdf0e10cSrcweir }
1037cdf0e10cSrcweir 
1038cdf0e10cSrcweir // -----------------------------------------------------------------------------
1039cdf0e10cSrcweir 
1040cdf0e10cSrcweir void SdrOle2Obj::DisconnectFileLink_Impl()
1041cdf0e10cSrcweir {
1042cdf0e10cSrcweir 	sfx2::LinkManager* pLinkManager = pModel ? pModel->GetLinkManager() : NULL;
1043cdf0e10cSrcweir 	if ( pLinkManager && mpImpl->mpObjectLink )
1044cdf0e10cSrcweir 	{
1045cdf0e10cSrcweir 		pLinkManager->Remove( mpImpl->mpObjectLink );
1046cdf0e10cSrcweir 		mpImpl->mpObjectLink = NULL;
1047cdf0e10cSrcweir 	}
1048cdf0e10cSrcweir }
1049cdf0e10cSrcweir 
1050cdf0e10cSrcweir // -----------------------------------------------------------------------------
1051cdf0e10cSrcweir 
1052cdf0e10cSrcweir void SdrOle2Obj::CheckFileLink_Impl()
1053cdf0e10cSrcweir {
1054cdf0e10cSrcweir 	if ( pModel && xObjRef.GetObject().is() && !mpImpl->mpObjectLink )
1055cdf0e10cSrcweir 	{
1056cdf0e10cSrcweir 		try
1057cdf0e10cSrcweir 		{
1058cdf0e10cSrcweir 			uno::Reference< embed::XLinkageSupport > xLinkSupport( xObjRef.GetObject(), uno::UNO_QUERY );
1059cdf0e10cSrcweir 			if ( xLinkSupport.is() && xLinkSupport->isLink() )
1060cdf0e10cSrcweir 			{
1061cdf0e10cSrcweir 				String aLinkURL = xLinkSupport->getLinkURL();
1062cdf0e10cSrcweir 				if ( aLinkURL.Len() )
1063cdf0e10cSrcweir 				{
1064cdf0e10cSrcweir 					// this is a file link so the model link manager should handle it
1065cdf0e10cSrcweir 					sfx2::LinkManager* pLinkManager = pModel->GetLinkManager();
1066cdf0e10cSrcweir 					if ( pLinkManager )
1067cdf0e10cSrcweir 					{
1068cdf0e10cSrcweir 						mpImpl->mpObjectLink = new SdrEmbedObjectLink( this );
1069cdf0e10cSrcweir 						mpImpl->maLinkURL = aLinkURL;
1070cdf0e10cSrcweir 						pLinkManager->InsertFileLink( *mpImpl->mpObjectLink, OBJECT_CLIENT_OLE, aLinkURL, NULL, NULL );
1071cdf0e10cSrcweir 						mpImpl->mpObjectLink->Connect();
1072cdf0e10cSrcweir 					}
1073cdf0e10cSrcweir 				}
1074cdf0e10cSrcweir 			}
1075cdf0e10cSrcweir 		}
1076cdf0e10cSrcweir 		catch( ::com::sun::star::uno::Exception& e )
1077cdf0e10cSrcweir 		{
1078cdf0e10cSrcweir 			(void)e;
1079cdf0e10cSrcweir 			DBG_ERROR(
1080cdf0e10cSrcweir 				(OString("SdrOle2Obj::CheckFileLink_Impl(), "
1081cdf0e10cSrcweir 						"exception caught: ") +
1082cdf0e10cSrcweir 				rtl::OUStringToOString(
1083cdf0e10cSrcweir 					comphelper::anyToString( cppu::getCaughtException() ),
1084cdf0e10cSrcweir 					RTL_TEXTENCODING_UTF8 )).getStr() );
1085cdf0e10cSrcweir 		}
1086cdf0e10cSrcweir 	}
1087cdf0e10cSrcweir }
1088cdf0e10cSrcweir 
1089cdf0e10cSrcweir // -----------------------------------------------------------------------------
1090cdf0e10cSrcweir 
1091cdf0e10cSrcweir void SdrOle2Obj::Reconnect_Impl()
1092cdf0e10cSrcweir {
1093cdf0e10cSrcweir     DBG_ASSERT( mpImpl->mbConnected, "Assigned unconnected object?!" );
1094cdf0e10cSrcweir     Connect_Impl();
1095cdf0e10cSrcweir }
1096cdf0e10cSrcweir 
1097cdf0e10cSrcweir void SdrOle2Obj::Connect_Impl()
1098cdf0e10cSrcweir {
1099cdf0e10cSrcweir     if( pModel && mpImpl->aPersistName.Len() )
1100cdf0e10cSrcweir 	{
1101cdf0e10cSrcweir 		try
1102cdf0e10cSrcweir 		{
1103cdf0e10cSrcweir 			::comphelper::IEmbeddedHelper* pPers = pModel->GetPersist();
1104cdf0e10cSrcweir 			if ( pPers )
1105cdf0e10cSrcweir 			{
1106cdf0e10cSrcweir 				comphelper::EmbeddedObjectContainer& rContainer = pPers->getEmbeddedObjectContainer();
1107cdf0e10cSrcweir 				if ( !rContainer.HasEmbeddedObject( mpImpl->aPersistName )
1108cdf0e10cSrcweir 				  || ( xObjRef.is() && !rContainer.HasEmbeddedObject( xObjRef.GetObject() ) ) )
1109cdf0e10cSrcweir 				{
1110cdf0e10cSrcweir 					// object not known to container document
1111cdf0e10cSrcweir 					// No object -> disaster!
1112cdf0e10cSrcweir 					DBG_ASSERT( xObjRef.is(), "No object in connect!");
1113cdf0e10cSrcweir 					if ( xObjRef.is() )
1114cdf0e10cSrcweir 					{
1115cdf0e10cSrcweir 						// object came from the outside, now add it to the container
1116cdf0e10cSrcweir 						::rtl::OUString aTmp;
1117cdf0e10cSrcweir 						rContainer.InsertEmbeddedObject( xObjRef.GetObject(), aTmp );
1118cdf0e10cSrcweir                         mpImpl->aPersistName = aTmp;
1119cdf0e10cSrcweir 					}
1120cdf0e10cSrcweir 				}
1121cdf0e10cSrcweir 				else if ( !xObjRef.is() )
1122cdf0e10cSrcweir                 {
1123cdf0e10cSrcweir 					xObjRef.Assign( rContainer.GetEmbeddedObject( mpImpl->aPersistName ), xObjRef.GetViewAspect() );
1124cdf0e10cSrcweir                     m_bTypeAsked = false;
1125cdf0e10cSrcweir                 }
1126cdf0e10cSrcweir 
1127cdf0e10cSrcweir 				if ( xObjRef.GetObject().is() )
1128cdf0e10cSrcweir 				{
1129cdf0e10cSrcweir 					xObjRef.AssignToContainer( &rContainer, mpImpl->aPersistName );
1130cdf0e10cSrcweir 					mpImpl->mbConnected = true;
1131cdf0e10cSrcweir 					xObjRef.Lock( sal_True );
1132cdf0e10cSrcweir 				}
1133cdf0e10cSrcweir 			}
1134cdf0e10cSrcweir 
1135cdf0e10cSrcweir 			if ( xObjRef.is() )
1136cdf0e10cSrcweir 			{
1137cdf0e10cSrcweir 				if ( !mpImpl->pLightClient )
1138cdf0e10cSrcweir 				{
1139cdf0e10cSrcweir 					mpImpl->pLightClient = new SdrLightEmbeddedClient_Impl( this );
1140cdf0e10cSrcweir 					mpImpl->pLightClient->acquire();
1141cdf0e10cSrcweir 				}
1142cdf0e10cSrcweir 
1143cdf0e10cSrcweir 				xObjRef->addStateChangeListener( mpImpl->pLightClient );
1144cdf0e10cSrcweir 				xObjRef->addEventListener( uno::Reference< document::XEventListener >( mpImpl->pLightClient ) );
1145cdf0e10cSrcweir 
1146cdf0e10cSrcweir 				if ( xObjRef->getCurrentState() != embed::EmbedStates::LOADED )
1147cdf0e10cSrcweir 					GetSdrGlobalData().GetOLEObjCache().InsertObj(this);
1148cdf0e10cSrcweir 
1149cdf0e10cSrcweir 				CheckFileLink_Impl();
1150cdf0e10cSrcweir 
1151cdf0e10cSrcweir 				uno::Reference< container::XChild > xChild( xObjRef.GetObject(), uno::UNO_QUERY );
1152cdf0e10cSrcweir 				if( xChild.is() )
1153cdf0e10cSrcweir                 {
1154cdf0e10cSrcweir                     uno::Reference< uno::XInterface > xParent( pModel->getUnoModel());
1155cdf0e10cSrcweir                     if( xParent.is())
1156cdf0e10cSrcweir                         xChild->setParent( pModel->getUnoModel() );
1157cdf0e10cSrcweir                 }
1158cdf0e10cSrcweir 
1159cdf0e10cSrcweir 			}
1160cdf0e10cSrcweir 		}
1161cdf0e10cSrcweir 		catch( ::com::sun::star::uno::Exception& e )
1162cdf0e10cSrcweir 		{
1163cdf0e10cSrcweir 			(void)e;
1164cdf0e10cSrcweir 			DBG_ERROR(
1165cdf0e10cSrcweir 				(OString("SdrOle2Obj::Connect_Impl(), "
1166cdf0e10cSrcweir 						"exception caught: ") +
1167cdf0e10cSrcweir 				rtl::OUStringToOString(
1168cdf0e10cSrcweir 					comphelper::anyToString( cppu::getCaughtException() ),
1169cdf0e10cSrcweir 					RTL_TEXTENCODING_UTF8 )).getStr() );
1170cdf0e10cSrcweir 		}
1171cdf0e10cSrcweir 	}
1172cdf0e10cSrcweir 
1173cdf0e10cSrcweir     //TODO/LATER: wait for definition of MiscStatus RESIZEONPRINTERCHANGE
1174cdf0e10cSrcweir     //if ( xObjRef.is() && (*ppObjRef)->GetMiscStatus() & SVOBJ_MISCSTATUS_RESIZEONPRINTERCHANGE )
1175cdf0e10cSrcweir 	{
1176cdf0e10cSrcweir         //TODO/LATER: needs a new handling for OnPrinterChanged
1177cdf0e10cSrcweir         /*
1178cdf0e10cSrcweir 		if (pModel && pModel->GetRefDevice() &&
1179cdf0e10cSrcweir 			pModel->GetRefDevice()->GetOutDevType() == OUTDEV_PRINTER)
1180cdf0e10cSrcweir 		{
1181cdf0e10cSrcweir 			// Kein RefDevice oder RefDevice kein Printer
1182cdf0e10cSrcweir 			sal_Bool bModified = (*ppObjRef)->IsModified();
1183cdf0e10cSrcweir 			Printer* pPrinter = (Printer*) pModel->GetRefDevice();
1184cdf0e10cSrcweir 			(*ppObjRef)->OnDocumentPrinterChanged( pPrinter );
1185cdf0e10cSrcweir 			(*ppObjRef)->SetModified( bModified );
1186cdf0e10cSrcweir         }*/
1187cdf0e10cSrcweir 	}
1188cdf0e10cSrcweir }
1189cdf0e10cSrcweir 
1190cdf0e10cSrcweir void SdrOle2Obj::ObjectLoaded()
1191cdf0e10cSrcweir {
1192cdf0e10cSrcweir     AddListeners_Impl();
1193cdf0e10cSrcweir }
1194cdf0e10cSrcweir 
1195cdf0e10cSrcweir void SdrOle2Obj::AddListeners_Impl()
1196cdf0e10cSrcweir {
1197cdf0e10cSrcweir     if( xObjRef.is() && xObjRef->getCurrentState() != embed::EmbedStates::LOADED )
1198cdf0e10cSrcweir 	{
1199cdf0e10cSrcweir 		// register modify listener
1200cdf0e10cSrcweir         if( !pModifyListener )
1201cdf0e10cSrcweir 		{
1202cdf0e10cSrcweir 			((SdrOle2Obj*)this)->pModifyListener = new SvxUnoShapeModifyListener( (SdrOle2Obj*)this );
1203cdf0e10cSrcweir 			pModifyListener->acquire();
1204cdf0e10cSrcweir 		}
1205cdf0e10cSrcweir 
1206cdf0e10cSrcweir 		uno::Reference< util::XModifyBroadcaster > xBC( getXModel(), uno::UNO_QUERY );
1207cdf0e10cSrcweir 		if( xBC.is() && pModifyListener )
1208cdf0e10cSrcweir 		{
1209cdf0e10cSrcweir 			uno::Reference< util::XModifyListener > xListener( pModifyListener );
1210cdf0e10cSrcweir 			xBC->addModifyListener( xListener );
1211cdf0e10cSrcweir 		}
1212cdf0e10cSrcweir 	}
1213cdf0e10cSrcweir }
1214cdf0e10cSrcweir 
1215cdf0e10cSrcweir // -----------------------------------------------------------------------------
1216cdf0e10cSrcweir 
1217cdf0e10cSrcweir void SdrOle2Obj::Disconnect()
1218cdf0e10cSrcweir {
1219cdf0e10cSrcweir 	if( IsEmptyPresObj() )
1220cdf0e10cSrcweir 		return;
1221cdf0e10cSrcweir 
1222cdf0e10cSrcweir 	if( !mpImpl->mbConnected )
1223cdf0e10cSrcweir     {
1224cdf0e10cSrcweir         DBG_ERROR("Disconnect() called on disconnected object!");
1225cdf0e10cSrcweir 		return;
1226cdf0e10cSrcweir     }
1227cdf0e10cSrcweir 
1228cdf0e10cSrcweir     RemoveListeners_Impl();
1229cdf0e10cSrcweir     Disconnect_Impl();
1230cdf0e10cSrcweir }
1231cdf0e10cSrcweir 
1232cdf0e10cSrcweir void SdrOle2Obj::RemoveListeners_Impl()
1233cdf0e10cSrcweir {
1234cdf0e10cSrcweir     if( xObjRef.is() && mpImpl->aPersistName.Len() )
1235cdf0e10cSrcweir 	{
1236cdf0e10cSrcweir 		try
1237cdf0e10cSrcweir 		{
1238cdf0e10cSrcweir 			sal_Int32 nState = xObjRef->getCurrentState();
1239cdf0e10cSrcweir 			if ( nState != embed::EmbedStates::LOADED )
1240cdf0e10cSrcweir 			{
1241cdf0e10cSrcweir 				uno::Reference< util::XModifyBroadcaster > xBC( getXModel(), uno::UNO_QUERY );
1242cdf0e10cSrcweir 				if( xBC.is() && pModifyListener )
1243cdf0e10cSrcweir 				{
1244cdf0e10cSrcweir 					uno::Reference< util::XModifyListener > xListener( pModifyListener );
1245cdf0e10cSrcweir 					xBC->removeModifyListener( xListener );
1246cdf0e10cSrcweir 				}
1247cdf0e10cSrcweir 			}
1248cdf0e10cSrcweir 		}
1249cdf0e10cSrcweir 		catch( ::com::sun::star::uno::Exception& e )
1250cdf0e10cSrcweir 		{
1251cdf0e10cSrcweir 			(void)e;
1252cdf0e10cSrcweir 			DBG_ERROR(
1253cdf0e10cSrcweir 				(OString("SdrOle2Obj::RemoveListeners_Impl(), "
1254cdf0e10cSrcweir 						"exception caught: ") +
1255cdf0e10cSrcweir 				rtl::OUStringToOString(
1256cdf0e10cSrcweir 					comphelper::anyToString( cppu::getCaughtException() ),
1257cdf0e10cSrcweir 					RTL_TEXTENCODING_UTF8 )).getStr() );
1258cdf0e10cSrcweir 		}
1259cdf0e10cSrcweir 	}
1260cdf0e10cSrcweir }
1261cdf0e10cSrcweir 
1262cdf0e10cSrcweir void SdrOle2Obj::Disconnect_Impl()
1263cdf0e10cSrcweir {
1264cdf0e10cSrcweir 	try
1265cdf0e10cSrcweir 	{
1266cdf0e10cSrcweir 		if ( pModel && mpImpl->aPersistName.Len() )
1267cdf0e10cSrcweir 		{
1268cdf0e10cSrcweir 			if( pModel->IsInDestruction() )
1269cdf0e10cSrcweir 			{
1270cdf0e10cSrcweir 				// TODO/LATER: here we must assume that the destruction of the model is enough to make clear that we will not
1271cdf0e10cSrcweir 				// remove the object from the container, even if the DrawingObject itself is not destroyed (unfortunately this
1272cdf0e10cSrcweir 				// There is no real need to do the following removing of the object from the container
1273cdf0e10cSrcweir 				// in case the model has correct persistance, but in case of problems such a removing
1274cdf0e10cSrcweir 				// would make the behaviour of the office more stable
1275cdf0e10cSrcweir 
1276cdf0e10cSrcweir 				comphelper::EmbeddedObjectContainer* pContainer = xObjRef.GetContainer();
1277cdf0e10cSrcweir 				if ( pContainer )
1278cdf0e10cSrcweir 				{
1279cdf0e10cSrcweir 					pContainer->CloseEmbeddedObject( xObjRef.GetObject() );
1280cdf0e10cSrcweir 					xObjRef.AssignToContainer( NULL, mpImpl->aPersistName );
1281cdf0e10cSrcweir 				}
1282cdf0e10cSrcweir 
1283cdf0e10cSrcweir 				// happens later than the destruction of the model, so we can't assert that).
1284cdf0e10cSrcweir 				//DBG_ASSERT( bInDestruction, "Model is destroyed, but not me?!" );
1285cdf0e10cSrcweir 				//TODO/LATER: should be make sure that the ObjectShell also forgets the object, because we will close it soon?
1286cdf0e10cSrcweir 				/*
1287cdf0e10cSrcweir 				uno::Reference < util::XCloseable > xClose( xObjRef, uno::UNO_QUERY );
1288cdf0e10cSrcweir 				if ( xClose.is() )
1289cdf0e10cSrcweir 				{
1290cdf0e10cSrcweir 					try
1291cdf0e10cSrcweir 					{
1292cdf0e10cSrcweir 						xClose->close( sal_True );
1293cdf0e10cSrcweir 					}
1294cdf0e10cSrcweir 					catch ( util::CloseVetoException& )
1295cdf0e10cSrcweir 					{
1296cdf0e10cSrcweir 						// there's still someone who needs the object!
1297cdf0e10cSrcweir 					}
1298cdf0e10cSrcweir 				}
1299cdf0e10cSrcweir 
1300cdf0e10cSrcweir 				xObjRef = NULL;*/
1301cdf0e10cSrcweir 			}
1302cdf0e10cSrcweir 			else if ( xObjRef.is() )
1303cdf0e10cSrcweir 			{
1304cdf0e10cSrcweir 				if ( pModel->getUnoModel().is() )
1305cdf0e10cSrcweir 				{
1306cdf0e10cSrcweir 					// remove object, but don't close it (that's up to someone else)
1307cdf0e10cSrcweir 					comphelper::EmbeddedObjectContainer* pContainer = xObjRef.GetContainer();
1308cdf0e10cSrcweir 					if ( pContainer )
1309cdf0e10cSrcweir 					{
1310cdf0e10cSrcweir 						pContainer->RemoveEmbeddedObject( xObjRef.GetObject(), sal_False);
1311cdf0e10cSrcweir 
1312cdf0e10cSrcweir 						// TODO/LATER: mpImpl->aPersistName contains outdated information, to have it uptodate
1313cdf0e10cSrcweir 						// it should be returned from RemoveEmbeddedObject call. Currently it is no problem,
1314cdf0e10cSrcweir 						// since no container is adjusted, actually the empty string could be provided as a name here
1315cdf0e10cSrcweir 						xObjRef.AssignToContainer( NULL, mpImpl->aPersistName );
1316cdf0e10cSrcweir 					}
1317cdf0e10cSrcweir 
1318cdf0e10cSrcweir 					DisconnectFileLink_Impl();
1319cdf0e10cSrcweir 				}
1320cdf0e10cSrcweir 			}
1321cdf0e10cSrcweir 		}
1322cdf0e10cSrcweir 
1323cdf0e10cSrcweir 		if ( xObjRef.is() && mpImpl->pLightClient )
1324cdf0e10cSrcweir 		{
1325cdf0e10cSrcweir 			xObjRef->removeStateChangeListener ( mpImpl->pLightClient );
1326cdf0e10cSrcweir 			xObjRef->removeEventListener( uno::Reference< document::XEventListener >( mpImpl->pLightClient ) );
1327cdf0e10cSrcweir 			xObjRef->setClientSite( NULL );
1328cdf0e10cSrcweir 
1329cdf0e10cSrcweir 			GetSdrGlobalData().GetOLEObjCache().RemoveObj(this);
1330cdf0e10cSrcweir 		}
1331cdf0e10cSrcweir 	}
1332cdf0e10cSrcweir 	catch( ::com::sun::star::uno::Exception& e )
1333cdf0e10cSrcweir 	{
1334cdf0e10cSrcweir 		(void)e;
1335cdf0e10cSrcweir 		DBG_ERROR(
1336cdf0e10cSrcweir 			(OString("SdrOle2Obj::Disconnect_Impl(), "
1337cdf0e10cSrcweir 					"exception caught: ") +
1338cdf0e10cSrcweir 			rtl::OUStringToOString(
1339cdf0e10cSrcweir 				comphelper::anyToString( cppu::getCaughtException() ),
1340cdf0e10cSrcweir 				RTL_TEXTENCODING_UTF8 )).getStr() );
1341cdf0e10cSrcweir 	}
1342cdf0e10cSrcweir 
1343cdf0e10cSrcweir 	mpImpl->mbConnected = false;
1344cdf0e10cSrcweir }
1345cdf0e10cSrcweir 
1346cdf0e10cSrcweir // -----------------------------------------------------------------------------
1347cdf0e10cSrcweir 
1348*a5258243SPedro Giffuni SdrObject* SdrOle2Obj::createSdrGrafObjReplacement(bool bAddText, bool bUseHCGraphic) const
1349*a5258243SPedro Giffuni {
1350*a5258243SPedro Giffuni     Graphic* pOLEGraphic = GetGraphic();
1351*a5258243SPedro Giffuni 
1352*a5258243SPedro Giffuni     if(bUseHCGraphic && Application::GetSettings().GetStyleSettings().GetHighContrastMode())
1353*a5258243SPedro Giffuni     {
1354*a5258243SPedro Giffuni         pOLEGraphic = getEmbeddedObjectRef().GetHCGraphic();
1355*a5258243SPedro Giffuni     }
1356*a5258243SPedro Giffuni 
1357*a5258243SPedro Giffuni     if(pOLEGraphic)
1358*a5258243SPedro Giffuni     {
1359*a5258243SPedro Giffuni         // #i118485# allow creating a SdrGrafObj representation
1360*a5258243SPedro Giffuni         SdrGrafObj* pClone = new SdrGrafObj(*pOLEGraphic);
1361*a5258243SPedro Giffuni         pClone->SetModel(GetModel());
1362*a5258243SPedro Giffuni 
1363*a5258243SPedro Giffuni         // copy transformation
1364*a5258243SPedro Giffuni         basegfx::B2DHomMatrix aMatrix;
1365*a5258243SPedro Giffuni         basegfx::B2DPolyPolygon aPolyPolygon;
1366*a5258243SPedro Giffuni 
1367*a5258243SPedro Giffuni         TRGetBaseGeometry(aMatrix, aPolyPolygon);
1368*a5258243SPedro Giffuni         pClone->TRSetBaseGeometry(aMatrix, aPolyPolygon);
1369*a5258243SPedro Giffuni 
1370*a5258243SPedro Giffuni         // copy all attributes to support graphic styles for OLEs
1371*a5258243SPedro Giffuni         pClone->SetStyleSheet(GetStyleSheet(), false);
1372*a5258243SPedro Giffuni         pClone->SetMergedItemSet(GetMergedItemSet());
1373*a5258243SPedro Giffuni 
1374*a5258243SPedro Giffuni         if(bAddText)
1375*a5258243SPedro Giffuni         {
1376*a5258243SPedro Giffuni             // #i118485# copy text (Caution! Model needed, as guaranteed in aw080)
1377*a5258243SPedro Giffuni             OutlinerParaObject* pOPO = GetOutlinerParaObject();
1378*a5258243SPedro Giffuni 
1379*a5258243SPedro Giffuni             if(pOPO && GetModel())
1380*a5258243SPedro Giffuni             {
1381*a5258243SPedro Giffuni                 pClone->NbcSetOutlinerParaObject(new OutlinerParaObject(*pOPO));
1382*a5258243SPedro Giffuni             }
1383*a5258243SPedro Giffuni         }
1384*a5258243SPedro Giffuni 
1385*a5258243SPedro Giffuni         return pClone;
1386*a5258243SPedro Giffuni     }
1387*a5258243SPedro Giffuni     else
1388*a5258243SPedro Giffuni     {
1389*a5258243SPedro Giffuni         // #i100710# pOLEGraphic may be zero (no visualisation available),
1390*a5258243SPedro Giffuni         // so we need to use the OLE replacement graphic
1391*a5258243SPedro Giffuni         SdrRectObj* pClone = new SdrRectObj(GetSnapRect());
1392*a5258243SPedro Giffuni         pClone->SetModel(GetModel());
1393*a5258243SPedro Giffuni 
1394*a5258243SPedro Giffuni         // gray outline
1395*a5258243SPedro Giffuni         pClone->SetMergedItem(XLineStyleItem(XLINE_SOLID));
1396*a5258243SPedro Giffuni         const svtools::ColorConfig aColorConfig;
1397*a5258243SPedro Giffuni         const svtools::ColorConfigValue aColor(aColorConfig.GetColorValue(svtools::OBJECTBOUNDARIES));
1398*a5258243SPedro Giffuni         pClone->SetMergedItem(XLineColorItem(String(), aColor.nColor));
1399*a5258243SPedro Giffuni 
1400*a5258243SPedro Giffuni         // bitmap fill
1401*a5258243SPedro Giffuni         pClone->SetMergedItem(XFillStyleItem(XFILL_BITMAP));
1402*a5258243SPedro Giffuni         pClone->SetMergedItem(XFillBitmapItem(String(), GetEmtyOLEReplacementBitmap()));
1403*a5258243SPedro Giffuni         pClone->SetMergedItem(XFillBmpTileItem(false));
1404*a5258243SPedro Giffuni         pClone->SetMergedItem(XFillBmpStretchItem(false));
1405*a5258243SPedro Giffuni 
1406*a5258243SPedro Giffuni         return pClone;
1407*a5258243SPedro Giffuni     }
1408*a5258243SPedro Giffuni }
1409*a5258243SPedro Giffuni 
1410*a5258243SPedro Giffuni SdrObject* SdrOle2Obj::DoConvertToPolyObj(sal_Bool bBezier, bool bAddText) const
1411*a5258243SPedro Giffuni {
1412*a5258243SPedro Giffuni     // #i118485# missing converter added
1413*a5258243SPedro Giffuni     if(GetModel())
1414*a5258243SPedro Giffuni     {
1415*a5258243SPedro Giffuni         SdrObject* pRetval = createSdrGrafObjReplacement(true, false);
1416*a5258243SPedro Giffuni 
1417*a5258243SPedro Giffuni         if(pRetval)
1418*a5258243SPedro Giffuni         {
1419*a5258243SPedro Giffuni             SdrObject* pRetval2 = pRetval->DoConvertToPolyObj(bBezier, bAddText);
1420*a5258243SPedro Giffuni             SdrObject::Free(pRetval);
1421*a5258243SPedro Giffuni 
1422*a5258243SPedro Giffuni             return pRetval2;
1423*a5258243SPedro Giffuni         }
1424*a5258243SPedro Giffuni     }
1425*a5258243SPedro Giffuni 
1426*a5258243SPedro Giffuni     return 0;
1427*a5258243SPedro Giffuni }
1428*a5258243SPedro Giffuni 
1429*a5258243SPedro Giffuni // -----------------------------------------------------------------------------
1430*a5258243SPedro Giffuni 
1431cdf0e10cSrcweir void SdrOle2Obj::SetModel(SdrModel* pNewModel)
1432cdf0e10cSrcweir {
1433cdf0e10cSrcweir     ::comphelper::IEmbeddedHelper* pDestPers = pNewModel ? pNewModel->GetPersist() : 0;
1434cdf0e10cSrcweir     ::comphelper::IEmbeddedHelper* pSrcPers  = pModel ? pModel->GetPersist() : 0;
1435cdf0e10cSrcweir 
1436cdf0e10cSrcweir     if ( pNewModel == pModel )
1437cdf0e10cSrcweir     {
1438cdf0e10cSrcweir         // don't know if this is necessary or if it will ever happen, but who know?!
1439cdf0e10cSrcweir         SdrRectObj::SetModel( pNewModel );
1440cdf0e10cSrcweir         return;
1441cdf0e10cSrcweir     }
1442cdf0e10cSrcweir 
1443cdf0e10cSrcweir     // assignment to model has changed
1444cdf0e10cSrcweir     DBG_ASSERT( pSrcPers || !mpImpl->mbConnected, "Connected object without a model?!" );
1445cdf0e10cSrcweir 
1446cdf0e10cSrcweir 	DBG_ASSERT( pDestPers, "The destination model must have a persistence! Please submit an issue!" );
1447cdf0e10cSrcweir 	DBG_ASSERT( pDestPers != pSrcPers, "The source and the destination models should have different persistences! Problems are possible!" );
1448cdf0e10cSrcweir 
1449cdf0e10cSrcweir 	// this is a bug if the target model has no persistence
1450cdf0e10cSrcweir 	// no error handling is possible so just do nothing in this method
1451cdf0e10cSrcweir 	if ( !pDestPers )
1452cdf0e10cSrcweir 		return;
1453cdf0e10cSrcweir 
1454cdf0e10cSrcweir     RemoveListeners_Impl();
1455cdf0e10cSrcweir 
1456cdf0e10cSrcweir     if( pDestPers && pSrcPers && !IsEmptyPresObj() )
1457cdf0e10cSrcweir     {
1458cdf0e10cSrcweir 		try
1459cdf0e10cSrcweir 		{
1460cdf0e10cSrcweir 			// move the objects' storage; ObjectRef remains the same, but PersistName may change
1461cdf0e10cSrcweir 			::rtl::OUString aTmp;
1462cdf0e10cSrcweir 			comphelper::EmbeddedObjectContainer& rContainer = pSrcPers->getEmbeddedObjectContainer();
1463cdf0e10cSrcweir 			uno::Reference < embed::XEmbeddedObject > xObj = rContainer.GetEmbeddedObject( mpImpl->aPersistName );
1464cdf0e10cSrcweir 			DBG_ASSERT( !xObjRef.is() || xObjRef.GetObject() == xObj, "Wrong object identity!" );
1465cdf0e10cSrcweir 			if ( xObj.is() )
1466cdf0e10cSrcweir 			{
1467cdf0e10cSrcweir 				pDestPers->getEmbeddedObjectContainer().MoveEmbeddedObject( rContainer, xObj, aTmp );
1468cdf0e10cSrcweir 				mpImpl->aPersistName = aTmp;
1469cdf0e10cSrcweir 				xObjRef.AssignToContainer( &pDestPers->getEmbeddedObjectContainer(), aTmp );
1470cdf0e10cSrcweir 			}
1471cdf0e10cSrcweir 	        DBG_ASSERT( aTmp.getLength(), "Copying embedded object failed!" );
1472cdf0e10cSrcweir 		}
1473cdf0e10cSrcweir 		catch( ::com::sun::star::uno::Exception& e )
1474cdf0e10cSrcweir 		{
1475cdf0e10cSrcweir 			(void)e;
1476cdf0e10cSrcweir 			DBG_ERROR(
1477cdf0e10cSrcweir 				(OString("SdrOle2Obj::SetModel(), "
1478cdf0e10cSrcweir 						"exception caught: ") +
1479cdf0e10cSrcweir 				rtl::OUStringToOString(
1480cdf0e10cSrcweir 					comphelper::anyToString( cppu::getCaughtException() ),
1481cdf0e10cSrcweir 					RTL_TEXTENCODING_UTF8 )).getStr() );
1482cdf0e10cSrcweir 		}
1483cdf0e10cSrcweir     }
1484cdf0e10cSrcweir 
1485cdf0e10cSrcweir 	SdrRectObj::SetModel( pNewModel );
1486cdf0e10cSrcweir 
1487cdf0e10cSrcweir     // #i43086#
1488cdf0e10cSrcweir     // #i85304 redo the change for charts for the above bugfix, as #i43086# does not ocur anymore
1489cdf0e10cSrcweir     //so maybe the ImpSetVisAreaSize call can be removed here completely
1490cdf0e10cSrcweir     //Nevertheless I leave it in for other objects as I am not sure about the side effects when removing now
1491cdf0e10cSrcweir     if( pModel && !pModel->isLocked() && !IsChart() )
1492cdf0e10cSrcweir         ImpSetVisAreaSize();
1493cdf0e10cSrcweir 
1494cdf0e10cSrcweir     if( pDestPers && !IsEmptyPresObj() )
1495cdf0e10cSrcweir     {
1496cdf0e10cSrcweir         if ( !pSrcPers || IsEmptyPresObj() )
1497cdf0e10cSrcweir             // object wasn't connected, now it should
1498cdf0e10cSrcweir             Connect_Impl();
1499cdf0e10cSrcweir         else
1500cdf0e10cSrcweir             Reconnect_Impl();
1501cdf0e10cSrcweir     }
1502cdf0e10cSrcweir 
1503cdf0e10cSrcweir     AddListeners_Impl();
1504cdf0e10cSrcweir }
1505cdf0e10cSrcweir 
1506cdf0e10cSrcweir // -----------------------------------------------------------------------------
1507cdf0e10cSrcweir 
1508cdf0e10cSrcweir void SdrOle2Obj::SetPage(SdrPage* pNewPage)
1509cdf0e10cSrcweir {
1510cdf0e10cSrcweir 	FASTBOOL bRemove=pNewPage==NULL && pPage!=NULL;
1511cdf0e10cSrcweir 	FASTBOOL bInsert=pNewPage!=NULL && pPage==NULL;
1512cdf0e10cSrcweir 
1513cdf0e10cSrcweir     if (bRemove && mpImpl->mbConnected )
1514cdf0e10cSrcweir         Disconnect();
1515cdf0e10cSrcweir 
1516cdf0e10cSrcweir 	SdrRectObj::SetPage(pNewPage);
1517cdf0e10cSrcweir 
1518cdf0e10cSrcweir     if (bInsert && !mpImpl->mbConnected )
1519cdf0e10cSrcweir         Connect();
1520cdf0e10cSrcweir }
1521cdf0e10cSrcweir 
1522cdf0e10cSrcweir // -----------------------------------------------------------------------------
1523cdf0e10cSrcweir 
1524cdf0e10cSrcweir void SdrOle2Obj::SetObjRef( const com::sun::star::uno::Reference < com::sun::star::embed::XEmbeddedObject >& rNewObjRef )
1525cdf0e10cSrcweir {
1526cdf0e10cSrcweir     DBG_ASSERT( !rNewObjRef.is() || !xObjRef.GetObject().is(), "SetObjRef called on already initialized object!");
1527cdf0e10cSrcweir     if( rNewObjRef == xObjRef.GetObject() )
1528cdf0e10cSrcweir 		return;
1529cdf0e10cSrcweir 
1530cdf0e10cSrcweir     // MBA: the caller of the method is responsible to control the old object, it will not be closed here
1531cdf0e10cSrcweir     // Otherwise WW8 import crashes because it tranfers control to OLENode by this method
1532cdf0e10cSrcweir     if ( xObjRef.GetObject().is() )
1533cdf0e10cSrcweir         xObjRef.Lock( sal_False );
1534cdf0e10cSrcweir 
1535cdf0e10cSrcweir     // MBA: avoid removal of object in Disconnect! It is definitely a HACK to call SetObjRef(0)!
1536cdf0e10cSrcweir     // This call will try to close the objects; so if anybody else wants to keep it, it must be locked by a CloseListener
1537cdf0e10cSrcweir     xObjRef.Clear();
1538cdf0e10cSrcweir 
1539cdf0e10cSrcweir     if ( mpImpl->mbConnected )
1540cdf0e10cSrcweir         Disconnect();
1541cdf0e10cSrcweir 
1542cdf0e10cSrcweir     xObjRef.Assign( rNewObjRef, GetAspect() );
1543cdf0e10cSrcweir     m_bTypeAsked = false;
1544cdf0e10cSrcweir 
1545cdf0e10cSrcweir     if ( xObjRef.is() )
1546cdf0e10cSrcweir     {
1547cdf0e10cSrcweir         DELETEZ( pGraphic );
1548cdf0e10cSrcweir 
1549cdf0e10cSrcweir         if ( (xObjRef->getStatus( GetAspect() ) & embed::EmbedMisc::EMBED_NEVERRESIZE ) )
1550cdf0e10cSrcweir             SetResizeProtect(sal_True);
1551cdf0e10cSrcweir 
1552cdf0e10cSrcweir         // #108759# For math objects, set closed state to transparent
1553cdf0e10cSrcweir         if( ImplIsMathObj( rNewObjRef ) )
1554cdf0e10cSrcweir             SetClosedObj( false );
1555cdf0e10cSrcweir 
1556cdf0e10cSrcweir         Connect();
1557cdf0e10cSrcweir     }
1558cdf0e10cSrcweir 
1559cdf0e10cSrcweir 	SetChanged();
1560cdf0e10cSrcweir 	BroadcastObjectChange();
1561cdf0e10cSrcweir }
1562cdf0e10cSrcweir 
1563cdf0e10cSrcweir // -----------------------------------------------------------------------------
1564cdf0e10cSrcweir 
1565cdf0e10cSrcweir void SdrOle2Obj::SetClosedObj( bool bIsClosed )
1566cdf0e10cSrcweir {
1567cdf0e10cSrcweir     // TODO/LATER: do we still need this hack?
1568cdf0e10cSrcweir     // #108759# Allow changes to the closed state of OLE objects
1569cdf0e10cSrcweir     bClosedObj = bIsClosed;
1570cdf0e10cSrcweir }
1571cdf0e10cSrcweir 
1572cdf0e10cSrcweir // -----------------------------------------------------------------------------
1573cdf0e10cSrcweir 
1574cdf0e10cSrcweir SdrObject* SdrOle2Obj::getFullDragClone() const
1575cdf0e10cSrcweir {
1576cdf0e10cSrcweir     // special handling for OLE. The default handling works, but is too
1577cdf0e10cSrcweir     // slow when the whole OLE needs to be cloned. Get the Metafile and
1578cdf0e10cSrcweir     // create a graphic object with it
1579cdf0e10cSrcweir 
1580*a5258243SPedro Giffuni     // #i118485# use central replacement generator
1581*a5258243SPedro Giffuni     return createSdrGrafObjReplacement(false, true);
1582cdf0e10cSrcweir }
1583cdf0e10cSrcweir 
1584cdf0e10cSrcweir // -----------------------------------------------------------------------------
1585cdf0e10cSrcweir 
1586cdf0e10cSrcweir void SdrOle2Obj::SetPersistName( const String& rPersistName )
1587cdf0e10cSrcweir {
1588cdf0e10cSrcweir     DBG_ASSERT( !mpImpl->aPersistName.Len(), "Persist name changed!");
1589cdf0e10cSrcweir 
1590cdf0e10cSrcweir     mpImpl->aPersistName = rPersistName;
1591cdf0e10cSrcweir 	mpImpl->mbLoadingOLEObjectFailed = false;
1592cdf0e10cSrcweir 
1593cdf0e10cSrcweir 	Connect();
1594cdf0e10cSrcweir     SetChanged();
1595cdf0e10cSrcweir }
1596cdf0e10cSrcweir 
1597cdf0e10cSrcweir void SdrOle2Obj::AbandonObject()
1598cdf0e10cSrcweir {
1599cdf0e10cSrcweir     mpImpl->aPersistName.Erase();
1600cdf0e10cSrcweir 	mpImpl->mbLoadingOLEObjectFailed = false;
1601cdf0e10cSrcweir     SetObjRef(0);
1602cdf0e10cSrcweir }
1603cdf0e10cSrcweir 
1604cdf0e10cSrcweir // -----------------------------------------------------------------------------
1605cdf0e10cSrcweir 
1606cdf0e10cSrcweir String SdrOle2Obj::GetPersistName() const
1607cdf0e10cSrcweir {
1608cdf0e10cSrcweir     return mpImpl->aPersistName;
1609cdf0e10cSrcweir }
1610cdf0e10cSrcweir 
1611cdf0e10cSrcweir // -----------------------------------------------------------------------------
1612cdf0e10cSrcweir 
1613cdf0e10cSrcweir void SdrOle2Obj::TakeObjInfo(SdrObjTransformInfoRec& rInfo) const
1614cdf0e10cSrcweir {
1615*a5258243SPedro Giffuni     // #i118485# Allowing much more attributes for OLEs
1616*a5258243SPedro Giffuni 	rInfo.bRotateFreeAllowed = true;
1617*a5258243SPedro Giffuni 	rInfo.bRotate90Allowed = true;
1618*a5258243SPedro Giffuni 	rInfo.bMirrorFreeAllowed = true;
1619*a5258243SPedro Giffuni 	rInfo.bMirror45Allowed = true;
1620*a5258243SPedro Giffuni 	rInfo.bMirror90Allowed = true;
1621*a5258243SPedro Giffuni 	rInfo.bTransparenceAllowed = true;
1622*a5258243SPedro Giffuni 	rInfo.bGradientAllowed = true;
1623*a5258243SPedro Giffuni 	rInfo.bShearAllowed = true;
1624*a5258243SPedro Giffuni 	rInfo.bEdgeRadiusAllowed = false;
1625*a5258243SPedro Giffuni 	rInfo.bNoOrthoDesired = false;
1626*a5258243SPedro Giffuni 	rInfo.bCanConvToPath = true;
1627*a5258243SPedro Giffuni 	rInfo.bCanConvToPoly = true;
1628*a5258243SPedro Giffuni 	rInfo.bCanConvToPathLineToArea = false;
1629*a5258243SPedro Giffuni 	rInfo.bCanConvToPolyLineToArea = false;
1630*a5258243SPedro Giffuni 	rInfo.bCanConvToContour = true;
1631cdf0e10cSrcweir }
1632cdf0e10cSrcweir 
1633cdf0e10cSrcweir // -----------------------------------------------------------------------------
1634cdf0e10cSrcweir 
1635cdf0e10cSrcweir sal_uInt16 SdrOle2Obj::GetObjIdentifier() const
1636cdf0e10cSrcweir {
1637cdf0e10cSrcweir 	return bFrame ? sal_uInt16(OBJ_FRAME) : sal_uInt16(OBJ_OLE2);
1638cdf0e10cSrcweir }
1639cdf0e10cSrcweir 
1640cdf0e10cSrcweir // -----------------------------------------------------------------------------
1641cdf0e10cSrcweir 
1642cdf0e10cSrcweir void SdrOle2Obj::TakeObjNameSingul(XubString& rName) const
1643cdf0e10cSrcweir {
1644cdf0e10cSrcweir 	rName = ImpGetResStr(bFrame ? STR_ObjNameSingulFrame : STR_ObjNameSingulOLE2);
1645cdf0e10cSrcweir 
1646cdf0e10cSrcweir 	const String aName(GetName());
1647cdf0e10cSrcweir 
1648cdf0e10cSrcweir 	if( aName.Len() )
1649cdf0e10cSrcweir 	{
1650cdf0e10cSrcweir 		rName.AppendAscii(" '");
1651cdf0e10cSrcweir 		rName += aName;
1652cdf0e10cSrcweir 		rName += sal_Unicode('\'');
1653cdf0e10cSrcweir 	}
1654cdf0e10cSrcweir }
1655cdf0e10cSrcweir 
1656cdf0e10cSrcweir // -----------------------------------------------------------------------------
1657cdf0e10cSrcweir 
1658cdf0e10cSrcweir void SdrOle2Obj::TakeObjNamePlural(XubString& rName) const
1659cdf0e10cSrcweir {
1660cdf0e10cSrcweir 	rName=ImpGetResStr(bFrame ? STR_ObjNamePluralFrame : STR_ObjNamePluralOLE2);
1661cdf0e10cSrcweir }
1662cdf0e10cSrcweir 
1663cdf0e10cSrcweir // -----------------------------------------------------------------------------
1664cdf0e10cSrcweir 
1665cdf0e10cSrcweir void SdrOle2Obj::operator=(const SdrObject& rObj)
1666cdf0e10cSrcweir {
1667cdf0e10cSrcweir     //TODO/LATER: who takes over control of my old object?!
1668cdf0e10cSrcweir     if( &rObj != this )
1669cdf0e10cSrcweir 	{
1670cdf0e10cSrcweir 		// #116235#
1671cdf0e10cSrcweir 		// ImpAssign( rObj );
1672cdf0e10cSrcweir         const SdrOle2Obj& rOle2Obj = static_cast< const SdrOle2Obj& >( rObj );
1673cdf0e10cSrcweir 
1674cdf0e10cSrcweir         uno::Reference < util::XCloseable > xClose( xObjRef.GetObject(), uno::UNO_QUERY );
1675cdf0e10cSrcweir 
1676cdf0e10cSrcweir         if( pModel && mpImpl->mbConnected )
1677cdf0e10cSrcweir             Disconnect();
1678cdf0e10cSrcweir 
1679cdf0e10cSrcweir         SdrRectObj::operator=( rObj );
1680cdf0e10cSrcweir 
1681cdf0e10cSrcweir         // #108867# Manually copying bClosedObj attribute
1682cdf0e10cSrcweir         SetClosedObj( rObj.IsClosedObj() );
1683cdf0e10cSrcweir 
1684cdf0e10cSrcweir         mpImpl->aPersistName = rOle2Obj.mpImpl->aPersistName;
1685cdf0e10cSrcweir         aProgName = rOle2Obj.aProgName;
1686cdf0e10cSrcweir         bFrame = rOle2Obj.bFrame;
1687cdf0e10cSrcweir 
1688cdf0e10cSrcweir         if( rOle2Obj.pGraphic )
1689cdf0e10cSrcweir         {
1690cdf0e10cSrcweir             if( pGraphic )
1691cdf0e10cSrcweir             {
1692cdf0e10cSrcweir                 delete pGraphic;
1693cdf0e10cSrcweir                 delete mpImpl->pGraphicObject;
1694cdf0e10cSrcweir             }
1695cdf0e10cSrcweir 
1696cdf0e10cSrcweir             pGraphic = new Graphic( *rOle2Obj.pGraphic );
1697cdf0e10cSrcweir             mpImpl->pGraphicObject = new GraphicObject( *pGraphic );
1698cdf0e10cSrcweir         }
1699cdf0e10cSrcweir 
1700cdf0e10cSrcweir         if( pModel && rObj.GetModel() && !IsEmptyPresObj() )
1701cdf0e10cSrcweir         {
1702cdf0e10cSrcweir             ::comphelper::IEmbeddedHelper* pDestPers = pModel->GetPersist();
1703cdf0e10cSrcweir             ::comphelper::IEmbeddedHelper* pSrcPers = rObj.GetModel()->GetPersist();
1704cdf0e10cSrcweir             if( pDestPers && pSrcPers )
1705cdf0e10cSrcweir             {
1706cdf0e10cSrcweir     			DBG_ASSERT( !xObjRef.is(), "Object already existing!" );
1707cdf0e10cSrcweir     			comphelper::EmbeddedObjectContainer& rContainer = pSrcPers->getEmbeddedObjectContainer();
1708cdf0e10cSrcweir     			uno::Reference < embed::XEmbeddedObject > xObj = rContainer.GetEmbeddedObject( mpImpl->aPersistName );
1709cdf0e10cSrcweir     			if ( xObj.is() )
1710cdf0e10cSrcweir     			{
1711cdf0e10cSrcweir         			::rtl::OUString aTmp;
1712cdf0e10cSrcweir         			xObjRef.Assign( pDestPers->getEmbeddedObjectContainer().CopyAndGetEmbeddedObject( rContainer, xObj, aTmp ), rOle2Obj.GetAspect() );
1713cdf0e10cSrcweir                     m_bTypeAsked = false;
1714cdf0e10cSrcweir         			mpImpl->aPersistName = aTmp;
1715cdf0e10cSrcweir 					CheckFileLink_Impl();
1716cdf0e10cSrcweir     			}
1717cdf0e10cSrcweir 
1718cdf0e10cSrcweir                 Connect();
1719cdf0e10cSrcweir 
1720cdf0e10cSrcweir                 /* only needed for MSOLE-Objects, now handled inside implementation of Object
1721cdf0e10cSrcweir 				if ( xObjRef.is() && rOle2Obj.xObjRef.is() && rOle2Obj.GetAspect() != embed::Aspects::MSOLE_ICON )
1722cdf0e10cSrcweir 				{
1723cdf0e10cSrcweir 					try
1724cdf0e10cSrcweir 					{
1725cdf0e10cSrcweir 						awt::Size aVisSize = rOle2Obj.xObjRef->getVisualAreaSize( rOle2Obj.GetAspect() );
1726cdf0e10cSrcweir 						if( rOle2Obj.xObjRef->getMapUnit( rOle2Obj.GetAspect() ) == xObjRef->getMapUnit( GetAspect() ) )
1727cdf0e10cSrcweir 						xObjRef->setVisualAreaSize( GetAspect(), aVisSize );
1728cdf0e10cSrcweir 					}
1729cdf0e10cSrcweir 					catch ( embed::WrongStateException& )
1730cdf0e10cSrcweir 					{
1731cdf0e10cSrcweir 						// setting of VisArea not necessary for objects that don't cache it in loaded state
1732cdf0e10cSrcweir 					}
1733cdf0e10cSrcweir 					catch( embed::NoVisualAreaSizeException& )
1734cdf0e10cSrcweir 					{
1735cdf0e10cSrcweir 						// objects my not have visual areas
1736cdf0e10cSrcweir 					}
1737cdf0e10cSrcweir 					catch( uno::Exception& e )
1738cdf0e10cSrcweir 					{
1739cdf0e10cSrcweir 						(void)e;
1740cdf0e10cSrcweir 						DBG_ERROR( "SdrOle2Obj::operator=(), unexcpected exception caught!" );
1741cdf0e10cSrcweir 					}
1742cdf0e10cSrcweir                 }                                                                            */
1743cdf0e10cSrcweir             }
1744cdf0e10cSrcweir         }
1745cdf0e10cSrcweir     }
1746cdf0e10cSrcweir }
1747cdf0e10cSrcweir 
1748cdf0e10cSrcweir // -----------------------------------------------------------------------------
1749cdf0e10cSrcweir 
1750cdf0e10cSrcweir void SdrOle2Obj::ImpSetVisAreaSize()
1751cdf0e10cSrcweir {
1752cdf0e10cSrcweir 	// currently there is no need to recalculate scaling for iconified objects
1753cdf0e10cSrcweir 	// TODO/LATER: it might be needed in future when it is possible to change the icon
1754cdf0e10cSrcweir 	if ( GetAspect() == embed::Aspects::MSOLE_ICON )
1755cdf0e10cSrcweir 		return;
1756cdf0e10cSrcweir 
1757cdf0e10cSrcweir     // the object area of an embedded object was changed, e.g. by user interaction an a selected object
1758cdf0e10cSrcweir     GetObjRef();
1759cdf0e10cSrcweir     if ( xObjRef.is() )
1760cdf0e10cSrcweir 	{
1761cdf0e10cSrcweir         OSL_ASSERT( pModel );
1762cdf0e10cSrcweir         sal_Int64 nMiscStatus = xObjRef->getStatus( GetAspect() );
1763cdf0e10cSrcweir 
1764cdf0e10cSrcweir 		// the client is required to get access to scaling
1765cdf0e10cSrcweir 		SfxInPlaceClient* pClient = SfxInPlaceClient::GetClient( dynamic_cast<SfxObjectShell*>(pModel->GetPersist()), xObjRef.GetObject() );
1766cdf0e10cSrcweir 		sal_Bool bHasOwnClient =
1767cdf0e10cSrcweir 						( mpImpl->pLightClient
1768cdf0e10cSrcweir 						&& xObjRef->getClientSite() == uno::Reference< embed::XEmbeddedClient >( mpImpl->pLightClient ) );
1769cdf0e10cSrcweir 
1770cdf0e10cSrcweir 		if ( pClient || bHasOwnClient )
1771cdf0e10cSrcweir 		{
1772cdf0e10cSrcweir             // TODO/LATER: IMHO we need to do similar things when object is UIActive or OutplaceActive?! (MBA)
1773cdf0e10cSrcweir             if ( ((nMiscStatus & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE) &&
1774cdf0e10cSrcweir                     svt::EmbeddedObjectRef::TryRunningState( xObjRef.GetObject() ))
1775cdf0e10cSrcweir                     || xObjRef->getCurrentState() == embed::EmbedStates::INPLACE_ACTIVE
1776cdf0e10cSrcweir                     )
1777cdf0e10cSrcweir 			{
1778cdf0e10cSrcweir 				Fraction aScaleWidth;
1779cdf0e10cSrcweir 				Fraction aScaleHeight;
1780cdf0e10cSrcweir 				if ( pClient )
1781cdf0e10cSrcweir 				{
1782cdf0e10cSrcweir 					aScaleWidth = pClient->GetScaleWidth();
1783cdf0e10cSrcweir 					aScaleHeight = pClient->GetScaleHeight();
1784cdf0e10cSrcweir 				}
1785cdf0e10cSrcweir 				else
1786cdf0e10cSrcweir 				{
1787cdf0e10cSrcweir 					aScaleWidth = mpImpl->pLightClient->GetScaleWidth();
1788cdf0e10cSrcweir 					aScaleHeight = mpImpl->pLightClient->GetScaleHeight();
1789cdf0e10cSrcweir 				}
1790cdf0e10cSrcweir 
1791cdf0e10cSrcweir                 // The object wants to resize itself (f.e. Chart wants to recalculate the layout)
1792cdf0e10cSrcweir                 // or object is inplace active and so has a window that must be resized also
1793cdf0e10cSrcweir                 // In these cases the change in the object area size will be reflected in a change of the
1794cdf0e10cSrcweir                 // objects' visual area. The scaling will not change, but it might exist already and must
1795cdf0e10cSrcweir                 // be used in calculations
1796cdf0e10cSrcweir 				MapUnit aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObjRef->getMapUnit( GetAspect() ) );
1797cdf0e10cSrcweir 				Size aVisSize( (long)( Fraction( aRect.GetWidth() ) / aScaleWidth ),
1798cdf0e10cSrcweir 								(long)( Fraction( aRect.GetHeight() ) / aScaleHeight ) );
1799cdf0e10cSrcweir 
1800cdf0e10cSrcweir 				aVisSize = OutputDevice::LogicToLogic( aVisSize, pModel->GetScaleUnit(), aMapUnit);
1801cdf0e10cSrcweir 				awt::Size aSz;
1802cdf0e10cSrcweir 				aSz.Width = aVisSize.Width();
1803cdf0e10cSrcweir 				aSz.Height = aVisSize.Height();
1804cdf0e10cSrcweir 				xObjRef->setVisualAreaSize( GetAspect(), aSz );
1805cdf0e10cSrcweir 
1806cdf0e10cSrcweir 				try
1807cdf0e10cSrcweir 				{
1808cdf0e10cSrcweir 					aSz = xObjRef->getVisualAreaSize( GetAspect() );
1809cdf0e10cSrcweir 				}
1810cdf0e10cSrcweir 				catch( embed::NoVisualAreaSizeException& )
1811cdf0e10cSrcweir 				{}
1812cdf0e10cSrcweir 
1813cdf0e10cSrcweir 				Rectangle aAcceptedVisArea;
1814cdf0e10cSrcweir 				aAcceptedVisArea.SetSize( Size( (long)( Fraction( long( aSz.Width ) ) * aScaleWidth ),
1815cdf0e10cSrcweir 												(long)( Fraction( long( aSz.Height ) ) * aScaleHeight ) ) );
1816cdf0e10cSrcweir 				if (aVisSize != aAcceptedVisArea.GetSize())
1817cdf0e10cSrcweir 				{
1818cdf0e10cSrcweir                     // server changed VisArea to its liking and the VisArea is different than the suggested one
1819cdf0e10cSrcweir                     // store the new value as given by the object
1820cdf0e10cSrcweir 					MapUnit aNewMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObjRef->getMapUnit( GetAspect() ) );
1821cdf0e10cSrcweir 					aRect.SetSize(OutputDevice::LogicToLogic( aAcceptedVisArea.GetSize(), aNewMapUnit, pModel->GetScaleUnit()));
1822cdf0e10cSrcweir                 }
1823cdf0e10cSrcweir 
1824cdf0e10cSrcweir                 // make the new object area known to the client
1825cdf0e10cSrcweir                 // compared to the "else" branch aRect might have been changed by the object and no additional scaling was applied
1826cdf0e10cSrcweir                 // OJ: WHY this -> OSL_ASSERT( pClient );
1827cdf0e10cSrcweir                 if( pClient )
1828cdf0e10cSrcweir                     pClient->SetObjArea(aRect);
1829cdf0e10cSrcweir 
1830cdf0e10cSrcweir                 // we need a new replacement image as the object has resized itself
1831cdf0e10cSrcweir 
1832cdf0e10cSrcweir                 //#i79578# don't request a new replacement image for charts to often
1833cdf0e10cSrcweir                 //a chart sends a modified call to the framework if it was changed
1834cdf0e10cSrcweir                 //thus the replacement update is already handled there
1835cdf0e10cSrcweir                 if( !IsChart() )
1836cdf0e10cSrcweir                     xObjRef.UpdateReplacement();
1837cdf0e10cSrcweir 			}
1838cdf0e10cSrcweir 			else
1839cdf0e10cSrcweir 			{
1840cdf0e10cSrcweir                 // The object isn't active and does not want to resize itself so the changed object area size
1841cdf0e10cSrcweir                 // will be reflected in a changed object scaling
1842cdf0e10cSrcweir 				Fraction aScaleWidth;
1843cdf0e10cSrcweir 				Fraction aScaleHeight;
1844cdf0e10cSrcweir 				Size aObjAreaSize;
1845cdf0e10cSrcweir 				if ( CalculateNewScaling( aScaleWidth, aScaleHeight, aObjAreaSize ) )
1846cdf0e10cSrcweir 				{
1847cdf0e10cSrcweir 					if ( pClient )
1848cdf0e10cSrcweir 					{
1849cdf0e10cSrcweir 						Rectangle aScaleRect(aRect.TopLeft(), aObjAreaSize);
1850cdf0e10cSrcweir 						pClient->SetObjAreaAndScale( aScaleRect, aScaleWidth, aScaleHeight);
1851cdf0e10cSrcweir 					}
1852cdf0e10cSrcweir 					else
1853cdf0e10cSrcweir 					{
1854cdf0e10cSrcweir 						mpImpl->pLightClient->SetSizeScale( aScaleWidth, aScaleHeight );
1855cdf0e10cSrcweir 					}
1856cdf0e10cSrcweir 				}
1857cdf0e10cSrcweir 			}
1858cdf0e10cSrcweir 		}
1859cdf0e10cSrcweir         else if( (nMiscStatus & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE) &&
1860cdf0e10cSrcweir             svt::EmbeddedObjectRef::TryRunningState( xObjRef.GetObject() ) )
1861cdf0e10cSrcweir         {
1862cdf0e10cSrcweir             //also handle not sfx based ole objects e.g. charts
1863cdf0e10cSrcweir             //#i83860# resizing charts in impress distorts fonts
1864cdf0e10cSrcweir             uno::Reference< embed::XVisualObject > xVisualObject( this->getXModel(), uno::UNO_QUERY );
1865cdf0e10cSrcweir             if( xVisualObject.is() )
1866cdf0e10cSrcweir             {
1867cdf0e10cSrcweir                 MapUnit aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObjRef->getMapUnit( GetAspect() ) );
1868cdf0e10cSrcweir                 Point aTL( aRect.TopLeft() );
1869cdf0e10cSrcweir                 Point aBR( aRect.BottomRight() );
1870cdf0e10cSrcweir                 Point aTL2( OutputDevice::LogicToLogic( aTL, pModel->GetScaleUnit(), aMapUnit) );
1871cdf0e10cSrcweir                 Point aBR2( OutputDevice::LogicToLogic( aBR, pModel->GetScaleUnit(), aMapUnit) );
1872cdf0e10cSrcweir                 Rectangle aNewRect( aTL2, aBR2 );
1873cdf0e10cSrcweir                 xVisualObject->setVisualAreaSize( GetAspect(), awt::Size( aNewRect.GetWidth(), aNewRect.GetHeight() ) );
1874cdf0e10cSrcweir             }
1875cdf0e10cSrcweir         }
1876cdf0e10cSrcweir 	}
1877cdf0e10cSrcweir }
1878cdf0e10cSrcweir 
1879cdf0e10cSrcweir // -----------------------------------------------------------------------------
1880cdf0e10cSrcweir 
1881cdf0e10cSrcweir void SdrOle2Obj::NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact)
1882cdf0e10cSrcweir {
1883cdf0e10cSrcweir 	if( pModel && !pModel->isLocked() )
1884cdf0e10cSrcweir     {
1885cdf0e10cSrcweir         GetObjRef();
1886cdf0e10cSrcweir         if ( xObjRef.is() && ( xObjRef->getStatus( GetAspect() ) & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE ) )
1887cdf0e10cSrcweir         {
1888cdf0e10cSrcweir             // if the object needs recompose on resize
1889cdf0e10cSrcweir             // the client site should be created before the resize will take place
1890cdf0e10cSrcweir             // check whether there is no client site and create it if necessary
1891cdf0e10cSrcweir             AddOwnLightClient();
1892cdf0e10cSrcweir         }
1893cdf0e10cSrcweir     }
1894cdf0e10cSrcweir 
1895cdf0e10cSrcweir 	SdrRectObj::NbcResize(rRef,xFact,yFact);
1896cdf0e10cSrcweir 	if (aGeo.nShearWink!=0 || aGeo.nDrehWink!=0) { // kleine Korrekturen
1897cdf0e10cSrcweir 		if (aGeo.nDrehWink>=9000 && aGeo.nDrehWink<27000) {
1898cdf0e10cSrcweir 			aRect.Move(aRect.Left()-aRect.Right(),aRect.Top()-aRect.Bottom());
1899cdf0e10cSrcweir 		}
1900cdf0e10cSrcweir 		aGeo.nDrehWink=0;
1901cdf0e10cSrcweir 		aGeo.nShearWink=0;
1902cdf0e10cSrcweir 		aGeo.nSin=0.0;
1903cdf0e10cSrcweir 		aGeo.nCos=1.0;
1904cdf0e10cSrcweir 		aGeo.nTan=0.0;
1905cdf0e10cSrcweir 		SetRectsDirty();
1906cdf0e10cSrcweir 	}
1907cdf0e10cSrcweir 	if( pModel && !pModel->isLocked() )
1908cdf0e10cSrcweir 		ImpSetVisAreaSize();
1909cdf0e10cSrcweir }
1910cdf0e10cSrcweir 
1911cdf0e10cSrcweir // -----------------------------------------------------------------------------
1912cdf0e10cSrcweir 
1913cdf0e10cSrcweir void SdrOle2Obj::SetGeoData(const SdrObjGeoData& rGeo)
1914cdf0e10cSrcweir {
1915cdf0e10cSrcweir 	SdrRectObj::SetGeoData(rGeo);
1916cdf0e10cSrcweir 	if( pModel && !pModel->isLocked() )
1917cdf0e10cSrcweir 		ImpSetVisAreaSize();
1918cdf0e10cSrcweir }
1919cdf0e10cSrcweir 
1920cdf0e10cSrcweir // -----------------------------------------------------------------------------
1921cdf0e10cSrcweir 
1922cdf0e10cSrcweir void SdrOle2Obj::NbcSetSnapRect(const Rectangle& rRect)
1923cdf0e10cSrcweir {
1924cdf0e10cSrcweir 	SdrRectObj::NbcSetSnapRect(rRect);
1925cdf0e10cSrcweir 	if( pModel && !pModel->isLocked() )
1926cdf0e10cSrcweir 		ImpSetVisAreaSize();
1927cdf0e10cSrcweir 
1928cdf0e10cSrcweir     if ( xObjRef.is() && IsChart() )
1929cdf0e10cSrcweir     {
1930cdf0e10cSrcweir         //#i103460# charts do not necessaryly have an own size within ODF files,
1931cdf0e10cSrcweir         //for this case they need to use the size settings from the surrounding frame,
1932cdf0e10cSrcweir         //which is made available with this method as there is no other way
1933cdf0e10cSrcweir         xObjRef.SetDefaultSizeForChart( Size( rRect.GetWidth(), rRect.GetHeight() ) );
1934cdf0e10cSrcweir     }
1935cdf0e10cSrcweir }
1936cdf0e10cSrcweir 
1937cdf0e10cSrcweir // -----------------------------------------------------------------------------
1938cdf0e10cSrcweir 
1939cdf0e10cSrcweir void SdrOle2Obj::NbcSetLogicRect(const Rectangle& rRect)
1940cdf0e10cSrcweir {
1941cdf0e10cSrcweir 	SdrRectObj::NbcSetLogicRect(rRect);
1942cdf0e10cSrcweir 	if( pModel && !pModel->isLocked() )
1943cdf0e10cSrcweir 		ImpSetVisAreaSize();
1944cdf0e10cSrcweir }
1945cdf0e10cSrcweir 
1946cdf0e10cSrcweir Graphic* SdrOle2Obj::GetGraphic() const
1947cdf0e10cSrcweir {
1948cdf0e10cSrcweir     if ( xObjRef.is() )
1949cdf0e10cSrcweir         return xObjRef.GetGraphic();
1950cdf0e10cSrcweir     return pGraphic;
1951cdf0e10cSrcweir }
1952cdf0e10cSrcweir 
1953cdf0e10cSrcweir void SdrOle2Obj::GetNewReplacement()
1954cdf0e10cSrcweir {
1955cdf0e10cSrcweir 	if ( xObjRef.is() )
1956cdf0e10cSrcweir 		xObjRef.UpdateReplacement();
1957cdf0e10cSrcweir }
1958cdf0e10cSrcweir 
1959cdf0e10cSrcweir // -----------------------------------------------------------------------------
1960cdf0e10cSrcweir 
1961cdf0e10cSrcweir Size SdrOle2Obj::GetOrigObjSize( MapMode* pTargetMapMode ) const
1962cdf0e10cSrcweir {
1963cdf0e10cSrcweir 	return xObjRef.GetSize( pTargetMapMode );
1964cdf0e10cSrcweir }
1965cdf0e10cSrcweir 
1966cdf0e10cSrcweir // -----------------------------------------------------------------------------
1967cdf0e10cSrcweir 
1968cdf0e10cSrcweir void SdrOle2Obj::NbcMove(const Size& rSize)
1969cdf0e10cSrcweir {
1970cdf0e10cSrcweir 	SdrRectObj::NbcMove(rSize);
1971cdf0e10cSrcweir 	if( pModel && !pModel->isLocked() )
1972cdf0e10cSrcweir 		ImpSetVisAreaSize();
1973cdf0e10cSrcweir }
1974cdf0e10cSrcweir 
1975cdf0e10cSrcweir // -----------------------------------------------------------------------------
1976cdf0e10cSrcweir 
1977cdf0e10cSrcweir sal_Bool SdrOle2Obj::CanUnloadRunningObj( const uno::Reference< embed::XEmbeddedObject >& xObj, sal_Int64 nAspect )
1978cdf0e10cSrcweir {
1979cdf0e10cSrcweir 	sal_Bool bResult = sal_False;
1980cdf0e10cSrcweir 
1981cdf0e10cSrcweir 	sal_Int32 nState = xObj->getCurrentState();
1982cdf0e10cSrcweir 	if ( nState == embed::EmbedStates::LOADED )
1983cdf0e10cSrcweir 	{
1984cdf0e10cSrcweir         // the object is already unloaded
1985cdf0e10cSrcweir 		bResult = sal_True;
1986cdf0e10cSrcweir 	}
1987cdf0e10cSrcweir 	else
1988cdf0e10cSrcweir 	{
1989cdf0e10cSrcweir         uno::Reference < util::XModifiable > xModifiable( xObj->getComponent(), uno::UNO_QUERY );
1990cdf0e10cSrcweir         if ( !xModifiable.is() )
1991cdf0e10cSrcweir             bResult = sal_True;
1992cdf0e10cSrcweir         else
1993cdf0e10cSrcweir         {
1994cdf0e10cSrcweir             sal_Int64 nMiscStatus = xObj->getStatus( nAspect );
1995cdf0e10cSrcweir 
1996cdf0e10cSrcweir             if ( embed::EmbedMisc::MS_EMBED_ALWAYSRUN != ( nMiscStatus & embed::EmbedMisc::MS_EMBED_ALWAYSRUN ) &&
1997cdf0e10cSrcweir             embed::EmbedMisc::EMBED_ACTIVATEIMMEDIATELY != ( nMiscStatus & embed::EmbedMisc::EMBED_ACTIVATEIMMEDIATELY ) &&
1998cdf0e10cSrcweir             !( xModifiable.is() && xModifiable->isModified() ) &&
1999cdf0e10cSrcweir             !( nState == embed::EmbedStates::INPLACE_ACTIVE || nState == embed::EmbedStates::UI_ACTIVE || nState == embed::EmbedStates::ACTIVE ) )
2000cdf0e10cSrcweir             {
2001cdf0e10cSrcweir                 bResult = sal_True;
2002cdf0e10cSrcweir             }
2003cdf0e10cSrcweir         }
2004cdf0e10cSrcweir     }
2005cdf0e10cSrcweir 
2006cdf0e10cSrcweir 	return bResult;
2007cdf0e10cSrcweir }
2008cdf0e10cSrcweir 
2009cdf0e10cSrcweir // -----------------------------------------------------------------------------
2010cdf0e10cSrcweir 
2011cdf0e10cSrcweir sal_Bool SdrOle2Obj::Unload( const uno::Reference< embed::XEmbeddedObject >& xObj, sal_Int64 nAspect )
2012cdf0e10cSrcweir {
2013cdf0e10cSrcweir 	sal_Bool bResult = sal_False;
2014cdf0e10cSrcweir 
2015cdf0e10cSrcweir     if ( CanUnloadRunningObj( xObj, nAspect ) )
2016cdf0e10cSrcweir     {
2017cdf0e10cSrcweir         try
2018cdf0e10cSrcweir         {
2019cdf0e10cSrcweir             xObj->changeState( embed::EmbedStates::LOADED );
2020cdf0e10cSrcweir             bResult = sal_True;
2021cdf0e10cSrcweir         }
2022cdf0e10cSrcweir         catch( ::com::sun::star::uno::Exception& e )
2023cdf0e10cSrcweir         {
2024cdf0e10cSrcweir             (void)e;
2025cdf0e10cSrcweir             DBG_ERROR(
2026cdf0e10cSrcweir                 (OString("SdrOle2Obj::Unload=(), "
2027cdf0e10cSrcweir                         "exception caught: ") +
2028cdf0e10cSrcweir                 rtl::OUStringToOString(
2029cdf0e10cSrcweir                     comphelper::anyToString( cppu::getCaughtException() ),
2030cdf0e10cSrcweir                     RTL_TEXTENCODING_UTF8 )).getStr() );
2031cdf0e10cSrcweir         }
2032cdf0e10cSrcweir     }
2033cdf0e10cSrcweir 
2034cdf0e10cSrcweir 	return bResult;
2035cdf0e10cSrcweir }
2036cdf0e10cSrcweir 
2037cdf0e10cSrcweir // -----------------------------------------------------------------------------
2038cdf0e10cSrcweir 
2039cdf0e10cSrcweir sal_Bool SdrOle2Obj::Unload()
2040cdf0e10cSrcweir {
2041cdf0e10cSrcweir 	sal_Bool bUnloaded = sal_False;
2042cdf0e10cSrcweir 
2043cdf0e10cSrcweir     if( xObjRef.is() )
2044cdf0e10cSrcweir 	{
2045cdf0e10cSrcweir         //TODO/LATER: no refcounting tricks anymore!
2046cdf0e10cSrcweir         //"customers" must register as state change listeners
2047cdf0e10cSrcweir 		//Nicht notwendig im Doc DTor (MM)
2048cdf0e10cSrcweir         //sal_uIntPtr nRefCount = (*ppObjRef)->GetRefCount();
2049cdf0e10cSrcweir 		// prevent Unload if there are external references
2050cdf0e10cSrcweir         //if( nRefCount > 2 )
2051cdf0e10cSrcweir         //    return sal_False;
2052cdf0e10cSrcweir         //DBG_ASSERT( nRefCount == 2, "Wrong RefCount for unload" );
2053cdf0e10cSrcweir 	}
2054cdf0e10cSrcweir 	else
2055cdf0e10cSrcweir 		bUnloaded = sal_True;
2056cdf0e10cSrcweir 
2057cdf0e10cSrcweir     if ( pModel && xObjRef.is() )
2058cdf0e10cSrcweir     {
2059cdf0e10cSrcweir 		bUnloaded = Unload( xObjRef.GetObject(), GetAspect() );
2060cdf0e10cSrcweir 	}
2061cdf0e10cSrcweir 
2062cdf0e10cSrcweir 	return bUnloaded;
2063cdf0e10cSrcweir }
2064cdf0e10cSrcweir 
2065cdf0e10cSrcweir // -----------------------------------------------------------------------------
2066cdf0e10cSrcweir 
2067cdf0e10cSrcweir void SdrOle2Obj::GetObjRef_Impl()
2068cdf0e10cSrcweir {
2069cdf0e10cSrcweir     if ( !xObjRef.is() && mpImpl->aPersistName.Len() && pModel && pModel->GetPersist() )
2070cdf0e10cSrcweir     {
2071cdf0e10cSrcweir 		// #107645#
2072cdf0e10cSrcweir         // Only try loading if it did not went wrong up to now
2073cdf0e10cSrcweir 		if(!mpImpl->mbLoadingOLEObjectFailed)
2074cdf0e10cSrcweir 		{
2075cdf0e10cSrcweir             xObjRef.Assign( pModel->GetPersist()->getEmbeddedObjectContainer().GetEmbeddedObject( mpImpl->aPersistName ), GetAspect() );
2076cdf0e10cSrcweir             m_bTypeAsked = false;
2077cdf0e10cSrcweir 			CheckFileLink_Impl();
2078cdf0e10cSrcweir 
2079cdf0e10cSrcweir 			// #107645#
2080cdf0e10cSrcweir 			// If loading of OLE object failed, remember that to not invoke a endless
2081cdf0e10cSrcweir 			// loop trying to load it again and again.
2082cdf0e10cSrcweir             if( xObjRef.is() )
2083cdf0e10cSrcweir 			{
2084cdf0e10cSrcweir 				mpImpl->mbLoadingOLEObjectFailed = sal_True;
2085cdf0e10cSrcweir 			}
2086cdf0e10cSrcweir 
2087cdf0e10cSrcweir             // #108759# For math objects, set closed state to transparent
2088cdf0e10cSrcweir             if( ImplIsMathObj( xObjRef.GetObject() ) )
2089cdf0e10cSrcweir                 SetClosedObj( false );
2090cdf0e10cSrcweir 		}
2091cdf0e10cSrcweir 
2092cdf0e10cSrcweir         if ( xObjRef.is() )
2093cdf0e10cSrcweir 		{
2094cdf0e10cSrcweir 			if( !IsEmptyPresObj() )
2095cdf0e10cSrcweir 			{
2096cdf0e10cSrcweir 				// #75637# remember modified status of model
2097cdf0e10cSrcweir 				const sal_Bool bWasChanged(pModel ? pModel->IsChanged() : sal_False);
2098cdf0e10cSrcweir 
2099cdf0e10cSrcweir 				// perhaps preview not valid anymore
2100cdf0e10cSrcweir 				// #75637# This line changes the modified state of the model
2101cdf0e10cSrcweir                 SetGraphic_Impl( NULL );
2102cdf0e10cSrcweir 
2103cdf0e10cSrcweir 				// #75637# if status was not set before, force it back
2104cdf0e10cSrcweir 				// to not set, so that SetGraphic(0L) above does not
2105cdf0e10cSrcweir 				// set the modified state of the model.
2106cdf0e10cSrcweir 				if(!bWasChanged && pModel && pModel->IsChanged())
2107cdf0e10cSrcweir 				{
2108cdf0e10cSrcweir 					pModel->SetChanged( sal_False );
2109cdf0e10cSrcweir 				}
2110cdf0e10cSrcweir 			}
2111cdf0e10cSrcweir 
2112cdf0e10cSrcweir             sal_Int64 nMiscStatus = xObjRef->getStatus( GetAspect() );
2113cdf0e10cSrcweir             (void)nMiscStatus;
2114cdf0e10cSrcweir             //TODO/LATER: wait until ResizeOnPrinterChange is defined
2115cdf0e10cSrcweir             //if ( nMiscStatus & SVOBJ_MISCSTATUS_RESIZEONPRINTERCHANGE )
2116cdf0e10cSrcweir 			{
2117cdf0e10cSrcweir 				if (pModel && pModel->GetRefDevice() &&
2118cdf0e10cSrcweir 					pModel->GetRefDevice()->GetOutDevType() == OUTDEV_PRINTER)
2119cdf0e10cSrcweir 				{
2120cdf0e10cSrcweir 					if(!bInDestruction)
2121cdf0e10cSrcweir 					{
2122cdf0e10cSrcweir                         //TODO/LATER: printerchange notification
2123cdf0e10cSrcweir                         /*
2124cdf0e10cSrcweir 						// prevent SetModified (don't want no update here)
2125cdf0e10cSrcweir 						sal_Bool bWasEnabled = (*ppObjRef)->IsEnableSetModified();
2126cdf0e10cSrcweir 						if ( bWasEnabled )
2127cdf0e10cSrcweir 							(*ppObjRef)->EnableSetModified( sal_False );
2128cdf0e10cSrcweir 
2129cdf0e10cSrcweir 						// Kein RefDevice oder RefDevice kein Printer
2130cdf0e10cSrcweir 						Printer* pPrinter = (Printer*) pModel->GetRefDevice();
2131cdf0e10cSrcweir 						(*ppObjRef)->OnDocumentPrinterChanged( pPrinter );
2132cdf0e10cSrcweir 
2133cdf0e10cSrcweir 						// reset state
2134cdf0e10cSrcweir                         (*ppObjRef)->EnableSetModified( bWasEnabled );*/
2135cdf0e10cSrcweir 					}
2136cdf0e10cSrcweir 				}
2137cdf0e10cSrcweir 			}
2138cdf0e10cSrcweir         }
2139cdf0e10cSrcweir 
2140cdf0e10cSrcweir         if ( xObjRef.is() )
2141cdf0e10cSrcweir             Connect();
2142cdf0e10cSrcweir     }
2143cdf0e10cSrcweir 
2144cdf0e10cSrcweir     if ( mpImpl->mbConnected )
2145cdf0e10cSrcweir         // move object to first position in cache
2146cdf0e10cSrcweir         GetSdrGlobalData().GetOLEObjCache().InsertObj(this);
2147cdf0e10cSrcweir }
2148cdf0e10cSrcweir 
2149cdf0e10cSrcweir uno::Reference < embed::XEmbeddedObject > SdrOle2Obj::GetObjRef() const
2150cdf0e10cSrcweir {
2151cdf0e10cSrcweir     const_cast<SdrOle2Obj*>(this)->GetObjRef_Impl();
2152cdf0e10cSrcweir     return xObjRef.GetObject();
2153cdf0e10cSrcweir }
2154cdf0e10cSrcweir 
2155cdf0e10cSrcweir uno::Reference < embed::XEmbeddedObject > SdrOle2Obj::GetObjRef_NoInit() const
2156cdf0e10cSrcweir {
2157cdf0e10cSrcweir     return xObjRef.GetObject();
2158cdf0e10cSrcweir }
2159cdf0e10cSrcweir 
2160cdf0e10cSrcweir // -----------------------------------------------------------------------------
2161cdf0e10cSrcweir 
2162cdf0e10cSrcweir uno::Reference< frame::XModel > SdrOle2Obj::getXModel() const
2163cdf0e10cSrcweir {
2164cdf0e10cSrcweir     GetObjRef();
2165cdf0e10cSrcweir     if ( svt::EmbeddedObjectRef::TryRunningState(xObjRef.GetObject()) )
2166cdf0e10cSrcweir         return uno::Reference< frame::XModel >( xObjRef->getComponent(), uno::UNO_QUERY );
2167cdf0e10cSrcweir     else
2168cdf0e10cSrcweir         return uno::Reference< frame::XModel >();
2169cdf0e10cSrcweir }
2170cdf0e10cSrcweir 
2171cdf0e10cSrcweir // -----------------------------------------------------------------------------
2172cdf0e10cSrcweir 
2173cdf0e10cSrcweir // #109985#
2174cdf0e10cSrcweir sal_Bool SdrOle2Obj::IsChart() const
2175cdf0e10cSrcweir {
2176cdf0e10cSrcweir     if ( !m_bTypeAsked )
2177cdf0e10cSrcweir     {
2178cdf0e10cSrcweir         m_bChart = ChartPrettyPainter::IsChart(xObjRef);
2179cdf0e10cSrcweir         m_bTypeAsked = true;
2180cdf0e10cSrcweir     }
2181cdf0e10cSrcweir     return m_bChart;
2182cdf0e10cSrcweir }
2183cdf0e10cSrcweir 
2184cdf0e10cSrcweir // -----------------------------------------------------------------------------
2185cdf0e10cSrcweir void SdrOle2Obj::SetGraphicToObj( const Graphic& aGraphic, const ::rtl::OUString& aMediaType )
2186cdf0e10cSrcweir {
2187cdf0e10cSrcweir 	xObjRef.SetGraphic( aGraphic, aMediaType );
2188cdf0e10cSrcweir }
2189cdf0e10cSrcweir 
2190cdf0e10cSrcweir // -----------------------------------------------------------------------------
2191cdf0e10cSrcweir void SdrOle2Obj::SetGraphicToObj( const uno::Reference< io::XInputStream >& xGrStream, const ::rtl::OUString& aMediaType )
2192cdf0e10cSrcweir {
2193cdf0e10cSrcweir 	xObjRef.SetGraphicStream( xGrStream, aMediaType );
2194cdf0e10cSrcweir }
2195cdf0e10cSrcweir 
2196cdf0e10cSrcweir // -----------------------------------------------------------------------------
2197cdf0e10cSrcweir sal_Bool SdrOle2Obj::IsCalc() const
2198cdf0e10cSrcweir {
2199cdf0e10cSrcweir     if ( !xObjRef.is() )
2200cdf0e10cSrcweir         return false;
2201cdf0e10cSrcweir 
2202cdf0e10cSrcweir     SvGlobalName aObjClsId( xObjRef->getClassID() );
2203cdf0e10cSrcweir     if(    SvGlobalName(SO3_SC_CLASSID_30) == aObjClsId
2204cdf0e10cSrcweir         || SvGlobalName(SO3_SC_CLASSID_40) == aObjClsId
2205cdf0e10cSrcweir         || SvGlobalName(SO3_SC_CLASSID_50) == aObjClsId
2206cdf0e10cSrcweir         || SvGlobalName(SO3_SC_CLASSID_60) == aObjClsId
2207cdf0e10cSrcweir 		|| SvGlobalName(SO3_SC_OLE_EMBED_CLASSID_60) == aObjClsId
2208cdf0e10cSrcweir 		|| SvGlobalName(SO3_SC_OLE_EMBED_CLASSID_8) == aObjClsId
2209cdf0e10cSrcweir 		|| SvGlobalName(SO3_SC_CLASSID) == aObjClsId )
2210cdf0e10cSrcweir     {
2211cdf0e10cSrcweir         return sal_True;
2212cdf0e10cSrcweir     }
2213cdf0e10cSrcweir 
2214cdf0e10cSrcweir 	return sal_False;
2215cdf0e10cSrcweir }
2216cdf0e10cSrcweir 
2217cdf0e10cSrcweir // -----------------------------------------------------------------------------
2218cdf0e10cSrcweir uno::Reference< frame::XModel > SdrOle2Obj::GetParentXModel() const
2219cdf0e10cSrcweir {
2220cdf0e10cSrcweir     uno::Reference< frame::XModel > xDoc;
2221cdf0e10cSrcweir 	if ( pModel )
2222cdf0e10cSrcweir 		xDoc.set( pModel->getUnoModel(),uno::UNO_QUERY);
2223cdf0e10cSrcweir     return xDoc;
2224cdf0e10cSrcweir }
2225cdf0e10cSrcweir 
2226cdf0e10cSrcweir // -----------------------------------------------------------------------------
2227cdf0e10cSrcweir sal_Bool SdrOle2Obj::CalculateNewScaling( Fraction& aScaleWidth, Fraction& aScaleHeight, Size& aObjAreaSize )
2228cdf0e10cSrcweir {
2229cdf0e10cSrcweir 	// TODO/LEAN: to avoid rounding errors scaling always uses the VisArea.
2230cdf0e10cSrcweir 	// If we don't cache it for own objects also we must load the object here
2231cdf0e10cSrcweir 	if ( !xObjRef.is() || !pModel )
2232cdf0e10cSrcweir 		return sal_False;
2233cdf0e10cSrcweir 
2234cdf0e10cSrcweir 	MapMode aMapMode( pModel->GetScaleUnit() );
2235cdf0e10cSrcweir 	aObjAreaSize = xObjRef.GetSize( &aMapMode );
2236cdf0e10cSrcweir 
2237cdf0e10cSrcweir 	Size aSize = aRect.GetSize();
2238cdf0e10cSrcweir 	aScaleWidth = Fraction(aSize.Width(),  aObjAreaSize.Width() );
2239cdf0e10cSrcweir 	aScaleHeight = Fraction(aSize.Height(), aObjAreaSize.Height() );
2240cdf0e10cSrcweir 
2241cdf0e10cSrcweir 	// reduce to 10 binary digits
2242cdf0e10cSrcweir 	Kuerzen(aScaleHeight, 10);
2243cdf0e10cSrcweir 	Kuerzen(aScaleWidth,  10);
2244cdf0e10cSrcweir 
2245cdf0e10cSrcweir 	return sal_True;
2246cdf0e10cSrcweir }
2247cdf0e10cSrcweir 
2248cdf0e10cSrcweir // -----------------------------------------------------------------------------
2249cdf0e10cSrcweir sal_Bool SdrOle2Obj::AddOwnLightClient()
2250cdf0e10cSrcweir {
2251cdf0e10cSrcweir 	// The Own Light Client must be registered in object only using this method!
2252cdf0e10cSrcweir     if ( !SfxInPlaceClient::GetClient( dynamic_cast<SfxObjectShell*>(pModel->GetPersist()), xObjRef.GetObject() )
2253cdf0e10cSrcweir       && !( mpImpl->pLightClient && xObjRef->getClientSite() == uno::Reference< embed::XEmbeddedClient >( mpImpl->pLightClient ) ) )
2254cdf0e10cSrcweir     {
2255cdf0e10cSrcweir 	    Connect();
2256cdf0e10cSrcweir 
2257cdf0e10cSrcweir 	    if ( xObjRef.is() && mpImpl->pLightClient )
2258cdf0e10cSrcweir 	    {
2259cdf0e10cSrcweir 		    Fraction aScaleWidth;
2260cdf0e10cSrcweir 		    Fraction aScaleHeight;
2261cdf0e10cSrcweir 		    Size aObjAreaSize;
2262cdf0e10cSrcweir 		    if ( CalculateNewScaling( aScaleWidth, aScaleHeight, aObjAreaSize ) )
2263cdf0e10cSrcweir 		    {
2264cdf0e10cSrcweir 			    mpImpl->pLightClient->SetSizeScale( aScaleWidth, aScaleHeight );
2265cdf0e10cSrcweir 			    try {
2266cdf0e10cSrcweir 				    xObjRef->setClientSite( mpImpl->pLightClient );
2267cdf0e10cSrcweir 				    return sal_True;
2268cdf0e10cSrcweir 			    } catch( uno::Exception& )
2269cdf0e10cSrcweir 			    {}
2270cdf0e10cSrcweir 		    }
2271cdf0e10cSrcweir 
2272cdf0e10cSrcweir 	    }
2273cdf0e10cSrcweir 
2274cdf0e10cSrcweir     	return sal_False;
2275cdf0e10cSrcweir     }
2276cdf0e10cSrcweir 
2277cdf0e10cSrcweir    	return sal_True;
2278cdf0e10cSrcweir }
2279cdf0e10cSrcweir 
2280cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
2281cdf0e10cSrcweir 
2282cdf0e10cSrcweir Bitmap SdrOle2Obj::GetEmtyOLEReplacementBitmap()
2283cdf0e10cSrcweir {
2284cdf0e10cSrcweir 	return Bitmap(ResId(BMP_SVXOLEOBJ, *ImpGetResMgr()));
2285cdf0e10cSrcweir }
2286cdf0e10cSrcweir 
2287cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
2288cdf0e10cSrcweir 
2289cdf0e10cSrcweir void SdrOle2Obj::SetWindow(const com::sun::star::uno::Reference < com::sun::star::awt::XWindow >& _xWindow)
2290cdf0e10cSrcweir {
2291cdf0e10cSrcweir     if ( xObjRef.is() && mpImpl->pLightClient )
2292cdf0e10cSrcweir     {
2293cdf0e10cSrcweir         mpImpl->pLightClient->setWindow(_xWindow);
2294cdf0e10cSrcweir     }
2295cdf0e10cSrcweir }
2296cdf0e10cSrcweir 
2297cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
2298cdf0e10cSrcweir // eof
2299