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