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