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