LibreOffice Module svx (master)  1
svdoole2.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <svx/svdoole2.hxx>
21 
22 #include <com/sun/star/util/XModifyBroadcaster.hpp>
23 #include <com/sun/star/util/XModifiable.hpp>
24 #include <com/sun/star/chart2/XChartDocument.hpp>
25 #include <com/sun/star/embed/EmbedStates.hpp>
26 #include <com/sun/star/embed/ElementModes.hpp>
27 #include <com/sun/star/embed/EmbedMisc.hpp>
28 #include <com/sun/star/embed/Aspects.hpp>
29 #include <com/sun/star/embed/ObjectSaveVetoException.hpp>
30 #include <com/sun/star/embed/XEmbeddedObject.hpp>
31 #include <com/sun/star/embed/XEmbedPersist2.hpp>
32 #include <com/sun/star/embed/XInplaceClient.hpp>
33 #include <com/sun/star/embed/XInplaceObject.hpp>
34 #include <com/sun/star/embed/XLinkageSupport.hpp>
35 #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
36 #include <com/sun/star/embed/XWindowSupplier.hpp>
37 #include <com/sun/star/document/XEventListener.hpp>
38 #include <com/sun/star/container/XChild.hpp>
39 #include <com/sun/star/document/XStorageBasedDocument.hpp>
40 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
41 
42 #include <cppuhelper/exc_hlp.hxx>
43 
47 
48 #include <vcl/graphicfilter.hxx>
49 #include <svtools/embedhlp.hxx>
50 
51 #include <sfx2/objsh.hxx>
52 #include <sfx2/ipclient.hxx>
53 #include <sfx2/lnkbase.hxx>
54 #include <tools/stream.hxx>
56 #include <svx/svdpagv.hxx>
57 #include <tools/debug.hxx>
58 #include <tools/globname.hxx>
59 #include <tools/diagnose_ex.h>
60 #include <vcl/jobset.hxx>
61 #include <comphelper/classids.hxx>
62 
63 #include <sot/formats.hxx>
64 #include <vcl/transfer.hxx>
65 #include <cppuhelper/implbase.hxx>
66 
67 #include <svl/solar.hrc>
68 #include <svl/urihelper.hxx>
69 #include <vcl/svapp.hxx>
70 
71 #include <svx/charthelper.hxx>
72 #include <svx/svdmodel.hxx>
73 #include <svx/dialmgr.hxx>
74 #include <svx/strings.hrc>
75 #include <svx/svdetc.hxx>
76 #include <svx/svdview.hxx>
77 #include <unomlstr.hxx>
79 #include <svx/svdograf.hxx>
81 #include <svx/xlineit0.hxx>
82 #include <svx/xlnclit.hxx>
83 #include <svx/xbtmpit.hxx>
84 #include <svx/xfillit0.hxx>
85 #include <svx/xflbmtit.hxx>
86 #include <svx/xflbstit.hxx>
89 #include <editeng/outlobj.hxx>
90 #include <svx/svdpage.hxx>
91 #include <rtl/ref.hxx>
92 #include <bitmaps.hlst>
93 #include <sal/log.hxx>
94 
95 using namespace ::com::sun::star;
96 
97 static uno::Reference < beans::XPropertySet > lcl_getFrame_throw(const SdrOle2Obj* _pObject)
98 {
99  uno::Reference < beans::XPropertySet > xFrame;
100  if ( _pObject )
101  {
102  uno::Reference< frame::XController> xController = _pObject->GetParentXModel()->getCurrentController();
103  if ( xController.is() )
104  {
105  xFrame.set( xController->getFrame(),uno::UNO_QUERY_THROW);
106  }
107  } // if ( _pObject )
108  return xFrame;
109 }
110 
111 namespace {
112 
113 class SdrLightEmbeddedClient_Impl : public ::cppu::WeakImplHelper
114  < embed::XStateChangeListener
115  , document::XEventListener
116  , embed::XInplaceClient
117  , embed::XEmbeddedClient
118  , embed::XWindowSupplier
119  >
120 {
121  uno::Reference< awt::XWindow > m_xWindow;
122  SdrOle2Obj* mpObj;
123 
124  Fraction m_aScaleWidth;
125  Fraction m_aScaleHeight;
126 
127 
128 public:
129  explicit SdrLightEmbeddedClient_Impl( SdrOle2Obj* pObj );
130  virtual ~SdrLightEmbeddedClient_Impl() override;
131 
132  void SetSizeScale( const Fraction& aScaleWidth, const Fraction& aScaleHeight )
133  {
134  m_aScaleWidth = aScaleWidth;
135  m_aScaleHeight = aScaleHeight;
136  }
137 
138  const Fraction& GetScaleWidth() const { return m_aScaleWidth; }
139  const Fraction& GetScaleHeight() const { return m_aScaleHeight; }
140 
141  void setWindow(const uno::Reference< awt::XWindow >& _xWindow);
142 
143  void disconnect();
144 private:
145 
146  tools::Rectangle impl_getScaledRect_nothrow() const;
147  // XStateChangeListener
148  virtual void SAL_CALL changingState( const css::lang::EventObject& aEvent, ::sal_Int32 nOldState, ::sal_Int32 nNewState ) override;
149  virtual void SAL_CALL stateChanged( const css::lang::EventObject& aEvent, ::sal_Int32 nOldState, ::sal_Int32 nNewState ) override;
150  virtual void SAL_CALL disposing( const css::lang::EventObject& aEvent ) override;
151 
152  // document::XEventListener
153  virtual void SAL_CALL notifyEvent( const document::EventObject& aEvent ) override;
154 
155  // XEmbeddedClient
156  virtual void SAL_CALL saveObject() override;
157  virtual void SAL_CALL visibilityChanged( sal_Bool bVisible ) override;
158 
159  // XComponentSupplier
160  virtual uno::Reference< util::XCloseable > SAL_CALL getComponent() override;
161 
162  // XInplaceClient
163  virtual sal_Bool SAL_CALL canInplaceActivate() override;
164  virtual void SAL_CALL activatingInplace() override;
165  virtual void SAL_CALL activatingUI() override;
166  virtual void SAL_CALL deactivatedInplace() override;
167  virtual void SAL_CALL deactivatedUI() override;
168  virtual uno::Reference< css::frame::XLayoutManager > SAL_CALL getLayoutManager() override;
169  virtual uno::Reference< frame::XDispatchProvider > SAL_CALL getInplaceDispatchProvider() override;
170  virtual awt::Rectangle SAL_CALL getPlacement() override;
171  virtual awt::Rectangle SAL_CALL getClipRectangle() override;
172  virtual void SAL_CALL translateAccelerators( const uno::Sequence< awt::KeyEvent >& aKeys ) override;
173  virtual void SAL_CALL scrollObject( const awt::Size& aOffset ) override;
174  virtual void SAL_CALL changedPlacement( const awt::Rectangle& aPosRect ) override;
175 
176  // XWindowSupplier
177  virtual uno::Reference< awt::XWindow > SAL_CALL getWindow() override;
178 };
179 
180 }
181 
182 SdrLightEmbeddedClient_Impl::SdrLightEmbeddedClient_Impl( SdrOle2Obj* pObj )
183 : mpObj( pObj )
184 {
185 }
186 SdrLightEmbeddedClient_Impl::~SdrLightEmbeddedClient_Impl()
187 {
188  assert(!mpObj);
189 }
190 tools::Rectangle SdrLightEmbeddedClient_Impl::impl_getScaledRect_nothrow() const
191 {
192  tools::Rectangle aLogicRect( mpObj->GetLogicRect() );
193  // apply scaling to object area and convert to pixels
194  aLogicRect.SetSize( Size( long( aLogicRect.GetWidth() * m_aScaleWidth),
195  long( aLogicRect.GetHeight() * m_aScaleHeight) ) );
196  return aLogicRect;
197 }
198 
199 void SAL_CALL SdrLightEmbeddedClient_Impl::changingState( const css::lang::EventObject& /*aEvent*/, ::sal_Int32 /*nOldState*/, ::sal_Int32 /*nNewState*/ )
200 {
201 }
202 
203 void SAL_CALL SdrLightEmbeddedClient_Impl::stateChanged( const css::lang::EventObject& /*aEvent*/, ::sal_Int32 nOldState, ::sal_Int32 nNewState )
204 {
205  SolarMutexGuard aGuard;
206 
207  if ( mpObj && nOldState == embed::EmbedStates::LOADED && nNewState == embed::EmbedStates::RUNNING )
208  {
209  mpObj->ObjectLoaded();
211  }
212  else if ( mpObj && nNewState == embed::EmbedStates::LOADED && nOldState == embed::EmbedStates::RUNNING )
213  {
215  }
216 }
217 
218 void SdrLightEmbeddedClient_Impl::disconnect()
219 {
220  SolarMutexGuard aGuard;
221  if (!mpObj)
222  return;
224  mpObj = nullptr;
225 }
226 
227 void SAL_CALL SdrLightEmbeddedClient_Impl::disposing( const css::lang::EventObject& /*aEvent*/ )
228 {
229  disconnect();
230 }
231 
232 void SAL_CALL SdrLightEmbeddedClient_Impl::notifyEvent( const document::EventObject& aEvent )
233 {
234  // TODO/LATER: when writer uses this implementation the code could be shared with SfxInPlaceClient_Impl
235 
236  SolarMutexGuard aGuard;
237 
238  // the code currently makes sense only in case there is no other client
239  if ( mpObj && mpObj->GetAspect() != embed::Aspects::MSOLE_ICON && aEvent.EventName == "OnVisAreaChanged"
240  && mpObj->GetObjRef().is() && mpObj->GetObjRef()->getClientSite() == uno::Reference< embed::XEmbeddedClient >( this ) )
241  {
242  try
243  {
244  MapUnit aContainerMapUnit( MapUnit::Map100thMM );
245  uno::Reference< embed::XVisualObject > xParentVis( mpObj->GetParentXModel(), uno::UNO_QUERY );
246  if ( xParentVis.is() )
247  aContainerMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xParentVis->getMapUnit( mpObj->GetAspect() ) );
248 
249  MapUnit aObjMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( mpObj->GetObjRef()->getMapUnit( mpObj->GetAspect() ) );
250 
251  tools::Rectangle aVisArea;
252  awt::Size aSz;
253  try
254  {
255  aSz = mpObj->GetObjRef()->getVisualAreaSize( mpObj->GetAspect() );
256  }
257  catch( embed::NoVisualAreaSizeException& )
258  {
259  OSL_FAIL( "No visual area size!" );
260  aSz.Width = 5000;
261  aSz.Height = 5000;
262  }
263  catch( uno::Exception& )
264  {
265  OSL_FAIL( "Unexpected exception!" );
266  aSz.Width = 5000;
267  aSz.Height = 5000;
268  }
269 
270  aVisArea.SetSize( Size( aSz.Width, aSz.Height ) );
271  aVisArea = OutputDevice::LogicToLogic(aVisArea, MapMode(aObjMapUnit), MapMode(aContainerMapUnit));
272  Size aScaledSize( static_cast< long >( m_aScaleWidth * Fraction( aVisArea.GetWidth() ) ),
273  static_cast< long >( m_aScaleHeight * Fraction( aVisArea.GetHeight() ) ) );
274  tools::Rectangle aLogicRect( mpObj->GetLogicRect() );
275 
276  // react to the change if the difference is bigger than one pixel
277  Size aPixelDiff =
279  Size( aLogicRect.GetWidth() - aScaledSize.Width(),
280  aLogicRect.GetHeight() - aScaledSize.Height() ),
281  MapMode(aContainerMapUnit));
282  if( aPixelDiff.Width() || aPixelDiff.Height() )
283  {
284  mpObj->SetLogicRect( tools::Rectangle( aLogicRect.TopLeft(), aScaledSize ) );
285  mpObj->BroadcastObjectChange();
286  }
287  else
288  mpObj->ActionChanged();
289  }
290  catch( uno::Exception& )
291  {
292  OSL_FAIL( "Unexpected exception!" );
293  }
294  }
295 }
296 
297 void SAL_CALL SdrLightEmbeddedClient_Impl::saveObject()
298 {
299  // TODO/LATER: when writer uses this implementation the code could be shared with SfxInPlaceClient_Impl
300  uno::Reference< embed::XCommonEmbedPersist > xPersist;
301  uno::Reference< util::XModifiable > xModifiable;
302 
303  {
304  SolarMutexGuard aGuard;
305 
306  if ( !mpObj )
307  throw embed::ObjectSaveVetoException();
308 
309  // the common persistence is supported by objects and links
310  xPersist.set( mpObj->GetObjRef(), uno::UNO_QUERY_THROW );
311  xModifiable.set( mpObj->GetParentXModel(), uno::UNO_QUERY );
312  }
313 
314  xPersist->storeOwn();
315 
316  if ( xModifiable.is() )
317  xModifiable->setModified( true );
318 }
319 
320 void SAL_CALL SdrLightEmbeddedClient_Impl::visibilityChanged( sal_Bool /*bVisible*/ )
321 {
322  // nothing to do currently
323  // TODO/LATER: when writer uses this implementation the code could be shared with SfxInPlaceClient_Impl
324  if ( mpObj )
325  {
326  tools::Rectangle aLogicRect( mpObj->GetLogicRect() );
327  Size aLogicSize( aLogicRect.GetWidth(), aLogicRect.GetHeight() );
328 
329  if( mpObj->IsChart() )
330  {
331  //charts never should be stretched see #i84323# for example
332  mpObj->SetLogicRect( tools::Rectangle( aLogicRect.TopLeft(), aLogicSize ) );
333  mpObj->BroadcastObjectChange();
334  } // if( mpObj->IsChart() )
335  }
336 }
337 
338 uno::Reference< util::XCloseable > SAL_CALL SdrLightEmbeddedClient_Impl::getComponent()
339 {
340  uno::Reference< util::XCloseable > xResult;
341 
342  SolarMutexGuard aGuard;
343  if ( mpObj )
344  xResult.set( mpObj->GetParentXModel(), uno::UNO_QUERY );
345 
346  return xResult;
347 }
348 // XInplaceClient
349 
350 sal_Bool SAL_CALL SdrLightEmbeddedClient_Impl::canInplaceActivate()
351 {
352  bool bRet = false;
353  SolarMutexGuard aGuard;
354  if ( mpObj )
355  {
356  uno::Reference< embed::XEmbeddedObject > xObject = mpObj->GetObjRef();
357  if ( !xObject.is() )
358  throw uno::RuntimeException();
359  // we don't want to switch directly from outplace to inplace mode
360  bRet = !( xObject->getCurrentState() == embed::EmbedStates::ACTIVE || mpObj->GetAspect() == embed::Aspects::MSOLE_ICON );
361  } // if ( mpObj )
362  return bRet;
363 }
364 
365 void SAL_CALL SdrLightEmbeddedClient_Impl::activatingInplace()
366 {
367 }
368 
369 void SAL_CALL SdrLightEmbeddedClient_Impl::activatingUI()
370 {
371  SolarMutexGuard aGuard;
372 
373  uno::Reference < beans::XPropertySet > xFrame( lcl_getFrame_throw(mpObj));
374  uno::Reference < frame::XFrame > xOwnFrame( xFrame,uno::UNO_QUERY);
375  uno::Reference < frame::XFramesSupplier > xParentFrame = xOwnFrame->getCreator();
376  if ( xParentFrame.is() )
377  xParentFrame->setActiveFrame( xOwnFrame );
378 
380  const sal_uIntPtr nCount = rObjCache.size();
381  for(sal_Int32 i = nCount-1 ; i >= 0;--i)
382  {
383  SdrOle2Obj* pObj = rObjCache[i];
384  if ( pObj != mpObj )
385  {
386  // only deactivate ole objects which belongs to the same frame
387  if ( xFrame == lcl_getFrame_throw(pObj) )
388  {
389  const uno::Reference< embed::XEmbeddedObject >& xObject = pObj->GetObjRef();
390  try
391  {
392  if ( xObject->getStatus( pObj->GetAspect() ) & embed::EmbedMisc::MS_EMBED_ACTIVATEWHENVISIBLE )
393  xObject->changeState( embed::EmbedStates::INPLACE_ACTIVE );
394  else
395  {
396  // the links should not stay in running state for long time because of locking
397  uno::Reference< embed::XLinkageSupport > xLink( xObject, uno::UNO_QUERY );
398  if ( xLink.is() && xLink->isLink() )
399  xObject->changeState( embed::EmbedStates::LOADED );
400  else
401  xObject->changeState( embed::EmbedStates::RUNNING );
402  }
403  }
404  catch (css::uno::Exception& )
405  {}
406  }
407  }
408  } // for(sal_Int32 i = nCount-1 ; i >= 0;--i)
409 }
410 
411 void SAL_CALL SdrLightEmbeddedClient_Impl::deactivatedInplace()
412 {
413 }
414 
415 void SAL_CALL SdrLightEmbeddedClient_Impl::deactivatedUI()
416 {
417  SolarMutexGuard aGuard;
418  css::uno::Reference< css::frame::XLayoutManager > xLayoutManager(getLayoutManager());
419  if ( xLayoutManager.is() )
420  {
421  static const char aMenuBarURL[] = "private:resource/menubar/menubar";
422  if ( !xLayoutManager->isElementVisible( aMenuBarURL ) )
423  xLayoutManager->createElement( aMenuBarURL );
424  }
425 }
426 
427 uno::Reference< css::frame::XLayoutManager > SAL_CALL SdrLightEmbeddedClient_Impl::getLayoutManager()
428 {
429  uno::Reference< css::frame::XLayoutManager > xMan;
430  SolarMutexGuard aGuard;
431  uno::Reference < beans::XPropertySet > xFrame( lcl_getFrame_throw(mpObj));
432  try
433  {
434  xMan.set(xFrame->getPropertyValue("LayoutManager"),uno::UNO_QUERY);
435  }
436  catch ( uno::Exception& ex )
437  {
438  css::uno::Any anyEx = cppu::getCaughtException();
439  throw css::lang::WrappedTargetRuntimeException( ex.Message,
440  nullptr, anyEx );
441  }
442 
443  return xMan;
444 }
445 
446 uno::Reference< frame::XDispatchProvider > SAL_CALL SdrLightEmbeddedClient_Impl::getInplaceDispatchProvider()
447 {
448  SolarMutexGuard aGuard;
449  return uno::Reference < frame::XDispatchProvider >( lcl_getFrame_throw(mpObj), uno::UNO_QUERY_THROW );
450 }
451 
452 awt::Rectangle SAL_CALL SdrLightEmbeddedClient_Impl::getPlacement()
453 {
454  SolarMutexGuard aGuard;
455  if ( !mpObj )
456  throw uno::RuntimeException();
457 
458  tools::Rectangle aLogicRect = impl_getScaledRect_nothrow();
459  MapUnit aContainerMapUnit( MapUnit::Map100thMM );
460  uno::Reference< embed::XVisualObject > xParentVis( mpObj->GetParentXModel(), uno::UNO_QUERY );
461  if ( xParentVis.is() )
462  aContainerMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xParentVis->getMapUnit( mpObj->GetAspect() ) );
463 
464  aLogicRect = Application::GetDefaultDevice()->LogicToPixel(aLogicRect, MapMode(aContainerMapUnit));
465  return AWTRectangle( aLogicRect );
466 }
467 
468 awt::Rectangle SAL_CALL SdrLightEmbeddedClient_Impl::getClipRectangle()
469 {
470  return getPlacement();
471 }
472 
473 void SAL_CALL SdrLightEmbeddedClient_Impl::translateAccelerators( const uno::Sequence< awt::KeyEvent >& /*aKeys*/ )
474 {
475 }
476 
477 void SAL_CALL SdrLightEmbeddedClient_Impl::scrollObject( const awt::Size& /*aOffset*/ )
478 {
479 }
480 
481 void SAL_CALL SdrLightEmbeddedClient_Impl::changedPlacement( const awt::Rectangle& aPosRect )
482 {
483  SolarMutexGuard aGuard;
484  if ( !mpObj )
485  throw uno::RuntimeException();
486 
487  uno::Reference< embed::XInplaceObject > xInplace( mpObj->GetObjRef(), uno::UNO_QUERY_THROW );
488 
489  // check if the change is at least one pixel in size
490  awt::Rectangle aOldRect = getPlacement();
491  tools::Rectangle aNewPixelRect = VCLRectangle( aPosRect );
492  tools::Rectangle aOldPixelRect = VCLRectangle( aOldRect );
493  if ( aOldPixelRect == aNewPixelRect )
494  // nothing has changed
495  return;
496 
497  // new scaled object area
498  MapUnit aContainerMapUnit( MapUnit::Map100thMM );
499  uno::Reference< embed::XVisualObject > xParentVis( mpObj->GetParentXModel(), uno::UNO_QUERY );
500  if ( xParentVis.is() )
501  aContainerMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xParentVis->getMapUnit( mpObj->GetAspect() ) );
502 
503  tools::Rectangle aNewLogicRect = Application::GetDefaultDevice()->PixelToLogic(aNewPixelRect, MapMode(aContainerMapUnit));
504  tools::Rectangle aLogicRect = impl_getScaledRect_nothrow();
505 
506  if ( aNewLogicRect != aLogicRect )
507  {
508  // the calculation of the object area has not changed the object size
509  // it should be done here then
510  //SfxBooleanFlagGuard aGuard( m_bResizeNoScale, true );
511 
512  // new size of the object area without scaling
513  Size aNewObjSize( long( aNewLogicRect.GetWidth() / m_aScaleWidth ),
514  long( aNewLogicRect.GetHeight() / m_aScaleHeight ) );
515 
516  // now remove scaling from new placement and keep this at the new object area
517  aNewLogicRect.SetSize( aNewObjSize );
518  // react to the change if the difference is bigger than one pixel
519  Size aPixelDiff =
521  Size( aLogicRect.GetWidth() - aNewObjSize.Width(),
522  aLogicRect.GetHeight() - aNewObjSize.Height() ),
523  MapMode(aContainerMapUnit));
524  if( aPixelDiff.Width() || aPixelDiff.Height() )
525  {
526  mpObj->SetLogicRect( tools::Rectangle( aLogicRect.TopLeft(), aNewObjSize ) );
527  mpObj->BroadcastObjectChange();
528  }
529  else
530  mpObj->ActionChanged();
531  }
532 }
533 // XWindowSupplier
534 
535 uno::Reference< awt::XWindow > SAL_CALL SdrLightEmbeddedClient_Impl::getWindow()
536 {
537  SolarMutexGuard aGuard;
538  uno::Reference< awt::XWindow > xCurrent = m_xWindow;
539  if ( !xCurrent.is() )
540  {
541  if ( !mpObj )
542  throw uno::RuntimeException();
543  uno::Reference< frame::XFrame> xFrame(lcl_getFrame_throw(mpObj),uno::UNO_QUERY_THROW);
544  xCurrent = xFrame->getComponentWindow();
545  } // if ( !xCurrent.is() )
546  return xCurrent;
547 }
548 void SdrLightEmbeddedClient_Impl::setWindow(const uno::Reference< awt::XWindow >& _xWindow)
549 {
550  m_xWindow = _xWindow;
551 }
552 
554  ::sfx2::SvBaseLink( ::SfxLinkUpdateMode::ONCALL, SotClipboardFormatId::SVXB ),
555  pObj(pObject)
556 {
557  SetSynchron( false );
558 }
559 
561 {
562 }
563 
565  const OUString& /*rMimeType*/, const css::uno::Any & /*rValue*/ )
566 {
567  if ( !pObj->UpdateLinkURL_Impl() )
568  {
569  // the link URL was not changed
570  uno::Reference< embed::XEmbeddedObject > xObject = pObj->GetObjRef();
571  OSL_ENSURE( xObject.is(), "The object must exist always!" );
572  if ( xObject.is() )
573  {
574  // let the object reload the link
575  // TODO/LATER: reload call could be used for this case
576 
577  try
578  {
579  sal_Int32 nState = xObject->getCurrentState();
580  if ( nState != embed::EmbedStates::LOADED )
581  {
582  // in some cases the linked file probably is not locked so it could be changed
583  xObject->changeState( embed::EmbedStates::LOADED );
584  xObject->changeState( nState );
585  }
586  }
587  catch ( uno::Exception& )
588  {
589  }
590  }
591  }
592 
593  pObj->GetNewReplacement();
594  pObj->SetChanged();
595 
596  return SUCCESS;
597 }
598 
600 {
601  pObj->BreakFileLink_Impl();
602  SvBaseLink::Closed();
603 }
604 
606 {
607 public:
609 
610  std::unique_ptr<Graphic> mxGraphic;
611  OUString maProgName;
612  OUString aPersistName; // name of object in persist
613  rtl::Reference<SdrLightEmbeddedClient_Impl> mxLightClient; // must be registered as client only using AddOwnLightClient() call
614 
615  bool mbFrame:1; // Due to compatibility at SdrTextObj for now
616  bool mbSuppressSetVisAreaSize:1; // #i118524#
617  mutable bool mbTypeAsked:1;
618  mutable bool mbIsChart:1;
619  bool mbLoadingOLEObjectFailed:1; // New local var to avoid repeated loading if load of OLE2 fails
620  bool mbConnected:1;
621 
623  OUString maLinkURL;
624 
626 
627  explicit SdrOle2ObjImpl( bool bFrame ) :
628  mbFrame(bFrame),
630  mbTypeAsked(false),
631  mbIsChart(false),
633  mbConnected(false),
634  mpObjectLink(nullptr)
635  {
636  mxObjRef.Lock();
637  }
638 
639  SdrOle2ObjImpl( bool bFrame, const svt::EmbeddedObjectRef& rObjRef ) :
640  mxObjRef(rObjRef),
641  mbFrame(bFrame),
643  mbTypeAsked(false),
644  mbIsChart(false),
646  mbConnected(false),
647  mpObjectLink(nullptr)
648  {
649  mxObjRef.Lock();
650  }
651 
653  {
654  mxGraphic.reset();
655 
656  if (mxModifyListener.is())
657  {
658  mxModifyListener->invalidate();
659  }
660  }
661 };
662 
663 // Predicate determining whether the given OLE is an internal math
664 // object
665 static bool ImplIsMathObj( const uno::Reference < embed::XEmbeddedObject >& rObjRef )
666 {
667  if ( !rObjRef.is() )
668  return false;
669 
670  SvGlobalName aClassName( rObjRef->getClassID() );
671  return aClassName == SvGlobalName(SO3_SM_CLASSID_30) ||
672  aClassName == SvGlobalName(SO3_SM_CLASSID_40) ||
673  aClassName == SvGlobalName(SO3_SM_CLASSID_50) ||
674  aClassName == SvGlobalName(SO3_SM_CLASSID_60) ||
675  aClassName == SvGlobalName(SO3_SM_CLASSID);
676 }
677 
678 // BaseProperties section
679 
680 std::unique_ptr<sdr::properties::BaseProperties> SdrOle2Obj::CreateObjectSpecificProperties()
681 {
682  return std::make_unique<sdr::properties::OleProperties>(*this);
683 }
684 
685 // DrawContact section
686 
687 std::unique_ptr<sdr::contact::ViewContact> SdrOle2Obj::CreateObjectSpecificViewContact()
688 {
689  return std::make_unique<sdr::contact::ViewContactOfSdrOle2Obj>(*this);
690 }
691 
693 {
694  // Stuff that was done from old SetModel:
695  // #i43086# #i85304 redo the change for charts for the above bugfix, as #i43086# does not occur anymore
696  // so maybe the ImpSetVisAreaSize call can be removed here completely
697  // Nevertheless I leave it in for other objects as I am not sure about the side effects when removing now
698  if(!getSdrModelFromSdrObject().isLocked() && !IsChart())
699  {
701  }
702 
703  ::comphelper::IEmbeddedHelper* pDestPers(getSdrModelFromSdrObject().GetPersist());
704  if(pDestPers && !IsEmptyPresObj())
705  {
706  // object wasn't connected, now it should be
707  Connect_Impl();
708  }
709 
711 }
712 
714  SdrModel& rSdrModel,
715  bool bFrame_)
716 : SdrRectObj(rSdrModel),
717  mpImpl(new SdrOle2ObjImpl(bFrame_))
718 {
719  Init();
720 }
721 
723  SdrModel& rSdrModel,
724  const svt::EmbeddedObjectRef& rNewObjRef,
725  const OUString& rNewObjName,
726  const tools::Rectangle& rNewRect)
727 : SdrRectObj(rSdrModel, rNewRect),
728  mpImpl(new SdrOle2ObjImpl(false/*bFrame_*/, rNewObjRef))
729 {
730  mpImpl->aPersistName = rNewObjName;
731 
732  if (mpImpl->mxObjRef.is() && (mpImpl->mxObjRef->getStatus( GetAspect() ) & embed::EmbedMisc::EMBED_NEVERRESIZE ) )
733  SetResizeProtect(true);
734 
735  // For math objects, set closed state to transparent
736  SetClosedObj(!ImplIsMathObj( mpImpl->mxObjRef.GetObject() ));
737 
738  Init();
739 }
740 
742 {
743  OUString strStyle;
744  if (mpImpl->mxObjRef.is() && mpImpl->mxObjRef.IsChart())
745  {
746  strStyle = mpImpl->mxObjRef.GetChartType();
747  }
748  return strStyle;
749 }
750 
752 {
753  if ( mpImpl->mbConnected )
754  Disconnect();
755 
757 
758  if (mpImpl->mxLightClient)
759  {
760  mpImpl->mxLightClient->disconnect();
761  mpImpl->mxLightClient.clear();
762  }
763 }
764 
765 void SdrOle2Obj::SetAspect( sal_Int64 nAspect )
766 {
767  mpImpl->mxObjRef.SetViewAspect( nAspect );
768 }
769 
771 {
772  return mpImpl->mxObjRef;
773 }
774 
775 sal_Int64 SdrOle2Obj::GetAspect() const
776 {
777  return mpImpl->mxObjRef.GetViewAspect();
778 }
779 
781 {
782  return mpImpl->mxObjRef.is() && embed::EmbedStates::INPLACE_ACTIVE == mpImpl->mxObjRef->getCurrentState();
783 }
784 
786 {
787  return mpImpl->mxObjRef.is() && embed::EmbedStates::UI_ACTIVE == mpImpl->mxObjRef->getCurrentState();
788 }
789 
791 {
792  // only for setting a preview graphic
793  mpImpl->mxGraphic.reset(new Graphic(rGrf));
794 
795  SetChanged();
797 }
798 
800 {
801  mpImpl->mxGraphic.reset();
802 
803  SetChanged();
805 }
806 
807 void SdrOle2Obj::SetProgName( const OUString& rName )
808 {
809  mpImpl->maProgName = rName;
810 }
811 
812 const OUString& SdrOle2Obj::GetProgName() const
813 {
814  return mpImpl->maProgName;
815 }
816 
818 {
819  return !mpImpl->mxObjRef.is();
820 }
821 
823 {
824  if( IsEmptyPresObj() )
825  return;
826 
827  if( mpImpl->mbConnected )
828  {
829  // currently there are situations where it seems to be unavoidable to have multiple connects
830  // changing this would need a larger code rewrite, so for now I remove the assertion
831  // OSL_FAIL("Connect() called on connected object!");
832  return;
833  }
834 
835  Connect_Impl();
837 }
838 
840 {
841  bool bResult = false;
842 
843  if ( mpImpl->mpObjectLink )
844  {
845  sfx2::LinkManager* pLinkManager(getSdrModelFromSdrObject().GetLinkManager());
846 
847  if ( pLinkManager )
848  {
849  OUString aNewLinkURL;
850  sfx2::LinkManager::GetDisplayNames( mpImpl->mpObjectLink, nullptr, &aNewLinkURL );
851  if ( !aNewLinkURL.equalsIgnoreAsciiCase( mpImpl->maLinkURL ) )
852  {
853  GetObjRef_Impl();
854  uno::Reference<embed::XCommonEmbedPersist> xPersObj( mpImpl->mxObjRef.GetObject(), uno::UNO_QUERY );
855  OSL_ENSURE( xPersObj.is(), "The object must exist!" );
856  if ( xPersObj.is() )
857  {
858  try
859  {
860  sal_Int32 nCurState = mpImpl->mxObjRef->getCurrentState();
861  if ( nCurState != embed::EmbedStates::LOADED )
862  mpImpl->mxObjRef->changeState(embed::EmbedStates::LOADED);
863 
864  // TODO/LATER: there should be possible to get current mediadescriptor settings from the object
865  uno::Sequence< beans::PropertyValue > aArgs( 1 );
866  aArgs[0].Name = "URL";
867  aArgs[0].Value <<= aNewLinkURL;
868  xPersObj->reload( aArgs, uno::Sequence< beans::PropertyValue >() );
869 
870  mpImpl->maLinkURL = aNewLinkURL;
871  bResult = true;
872 
873  if ( nCurState != embed::EmbedStates::LOADED )
874  mpImpl->mxObjRef->changeState(nCurState);
875  }
876  catch( css::uno::Exception const & )
877  {
878  TOOLS_WARN_EXCEPTION( "svx", "SdrOle2Obj::UpdateLinkURL_Impl()" );
879  }
880  }
881 
882  if ( !bResult )
883  {
884  // TODO/LATER: return the old name to the link manager, is it possible?
885  }
886  }
887  }
888  }
889 
890  return bResult;
891 }
892 
894 {
895  uno::Reference<document::XStorageBasedDocument> xDoc(getSdrModelFromSdrObject().getUnoModel(), uno::UNO_QUERY);
896 
897  if ( xDoc.is() )
898  {
899  uno::Reference< embed::XStorage > xStorage = xDoc->getDocumentStorage();
900  if ( xStorage.is() )
901  {
902  try
903  {
904  uno::Reference< embed::XLinkageSupport > xLinkSupport( mpImpl->mxObjRef.GetObject(), uno::UNO_QUERY_THROW );
905  xLinkSupport->breakLink( xStorage, mpImpl->aPersistName );
907  mpImpl->maLinkURL.clear();
908  }
909  catch( css::uno::Exception& )
910  {
911  TOOLS_WARN_EXCEPTION( "svx", "SdrOle2Obj::BreakFileLink_Impl()" );
912  }
913  }
914  }
915 }
916 
918 {
919  sfx2::LinkManager* pLinkManager(getSdrModelFromSdrObject().GetLinkManager());
920 
921  if ( pLinkManager && mpImpl->mpObjectLink )
922  {
923  pLinkManager->Remove( mpImpl->mpObjectLink );
924  mpImpl->mpObjectLink = nullptr;
925  }
926 }
927 
929 {
930  if (mpImpl->mxObjRef.GetObject().is() && !mpImpl->mpObjectLink)
931  {
932  try
933  {
934  uno::Reference< embed::XLinkageSupport > xLinkSupport( mpImpl->mxObjRef.GetObject(), uno::UNO_QUERY );
935 
936  if ( xLinkSupport.is() && xLinkSupport->isLink() )
937  {
938  OUString aLinkURL = xLinkSupport->getLinkURL();
939 
940  if ( !aLinkURL.isEmpty() )
941  {
942  // this is a file link so the model link manager should handle it
943  sfx2::LinkManager* pLinkManager(getSdrModelFromSdrObject().GetLinkManager());
944 
945  if ( pLinkManager )
946  {
947  mpImpl->mpObjectLink = new SdrEmbedObjectLink( this );
948  mpImpl->maLinkURL = aLinkURL;
949  pLinkManager->InsertFileLink( *mpImpl->mpObjectLink, OBJECT_CLIENT_OLE, aLinkURL );
950  mpImpl->mpObjectLink->Connect();
951  }
952  }
953  }
954  }
955  catch (const css::uno::Exception&)
956  {
957  TOOLS_WARN_EXCEPTION("svx", "SdrOle2Obj::CheckFileLink_Impl()");
958  }
959  }
960 }
961 
963 {
964  if(!mpImpl->aPersistName.isEmpty() )
965  {
966  try
967  {
969 
970  if ( pPers )
971  {
973 
974  if ( !rContainer.HasEmbeddedObject( mpImpl->aPersistName )
975  || ( mpImpl->mxObjRef.is() && !rContainer.HasEmbeddedObject( mpImpl->mxObjRef.GetObject() ) ) )
976  {
977  // object not known to container document
978  // No object -> disaster!
979  DBG_ASSERT( mpImpl->mxObjRef.is(), "No object in connect!");
980  if ( mpImpl->mxObjRef.is() )
981  {
982  // object came from the outside, now add it to the container
983  OUString aTmp;
984  rContainer.InsertEmbeddedObject( mpImpl->mxObjRef.GetObject(), aTmp );
985  mpImpl->aPersistName = aTmp;
986  }
987  }
988  else if ( !mpImpl->mxObjRef.is() )
989  {
990  mpImpl->mxObjRef.Assign( rContainer.GetEmbeddedObject( mpImpl->aPersistName ), mpImpl->mxObjRef.GetViewAspect() );
991  mpImpl->mbTypeAsked = false;
992  }
993 
994  if ( mpImpl->mxObjRef.GetObject().is() )
995  {
996  mpImpl->mxObjRef.AssignToContainer( &rContainer, mpImpl->aPersistName );
997  mpImpl->mbConnected = true;
998  mpImpl->mxObjRef.Lock();
999  }
1000  }
1001 
1002  if ( mpImpl->mxObjRef.is() )
1003  {
1004  if ( !mpImpl->mxLightClient.is() )
1005  mpImpl->mxLightClient = new SdrLightEmbeddedClient_Impl( this );
1006 
1007  mpImpl->mxObjRef->addStateChangeListener( mpImpl->mxLightClient.get() );
1008  mpImpl->mxObjRef->addEventListener( uno::Reference< document::XEventListener >( mpImpl->mxLightClient.get() ) );
1009 
1010  if ( mpImpl->mxObjRef->getCurrentState() != embed::EmbedStates::LOADED )
1012 
1014 
1015  uno::Reference< container::XChild > xChild( mpImpl->mxObjRef.GetObject(), uno::UNO_QUERY );
1016  if( xChild.is() )
1017  {
1018  uno::Reference< uno::XInterface > xParent( getSdrModelFromSdrObject().getUnoModel());
1019  if( xParent.is())
1020  xChild->setParent( getSdrModelFromSdrObject().getUnoModel() );
1021  }
1022 
1023  }
1024  }
1025  catch( css::uno::Exception& )
1026  {
1027  TOOLS_WARN_EXCEPTION( "svx", "SdrOle2Obj::Connect_Impl()" );
1028  }
1029  }
1030 }
1031 
1033 {
1035 }
1036 
1038 {
1039  if( mpImpl->mxObjRef.is() && mpImpl->mxObjRef->getCurrentState() != embed::EmbedStates::LOADED )
1040  {
1041  // register modify listener
1042  if (!mpImpl->mxModifyListener.is())
1043  {
1044  mpImpl->mxModifyListener = new SvxUnoShapeModifyListener(this);
1045  }
1046 
1047  uno::Reference< util::XModifyBroadcaster > xBC( getXModel(), uno::UNO_QUERY );
1048  if (xBC.is())
1049  {
1050  uno::Reference<util::XModifyListener> xListener(mpImpl->mxModifyListener.get());
1051  xBC->addModifyListener( xListener );
1052  }
1053  }
1054 }
1055 
1057 {
1058  if( IsEmptyPresObj() )
1059  return;
1060 
1061  if( !mpImpl->mbConnected )
1062  {
1063  OSL_FAIL("Disconnect() called on disconnected object!");
1064  return;
1065  }
1066 
1068  Disconnect_Impl();
1069 }
1070 
1072 {
1073  if ( mpImpl->mxObjRef.is() && !mpImpl->aPersistName.isEmpty() )
1074  {
1075  try
1076  {
1077  sal_Int32 nState = mpImpl->mxObjRef->getCurrentState();
1078  if ( nState != embed::EmbedStates::LOADED )
1079  {
1080  uno::Reference< util::XModifyBroadcaster > xBC( getXModel(), uno::UNO_QUERY );
1081  if (xBC.is() && mpImpl->mxModifyListener.is())
1082  {
1083  uno::Reference<util::XModifyListener> xListener(mpImpl->mxModifyListener.get());
1084  xBC->removeModifyListener( xListener );
1085  }
1086  }
1087  }
1088  catch( css::uno::Exception& )
1089  {
1090  TOOLS_WARN_EXCEPTION( "svx", "SdrOle2Obj::RemoveListeners_Impl()" );
1091  }
1092  }
1093 }
1094 
1096 {
1097  try
1098  {
1099  if ( !mpImpl->aPersistName.isEmpty() )
1100  {
1102  {
1103  // TODO/LATER: here we must assume that the destruction of the model is enough to make clear that we will not
1104  // remove the object from the container, even if the DrawingObject itself is not destroyed (unfortunately this
1105  // There is no real need to do the following removing of the object from the container
1106  // in case the model has correct persistence, but in case of problems such a removing
1107  // would make the behavior of the office more stable
1108 
1109  comphelper::EmbeddedObjectContainer* pContainer = mpImpl->mxObjRef.GetContainer();
1110  if ( pContainer )
1111  {
1112  pContainer->CloseEmbeddedObject( mpImpl->mxObjRef.GetObject() );
1113  mpImpl->mxObjRef.AssignToContainer( nullptr, mpImpl->aPersistName );
1114  }
1115 
1116  // happens later than the destruction of the model, so we can't assert that).
1117  //DBG_ASSERT( bInDestruction, "Model is destroyed, but not me?!" );
1118  //TODO/LATER: should be make sure that the ObjectShell also forgets the object, because we will close it soon?
1119  /*
1120  uno::Reference < util::XCloseable > xClose( xObjRef, uno::UNO_QUERY );
1121  if ( xClose.is() )
1122  {
1123  try
1124  {
1125  xClose->close( true );
1126  }
1127  catch ( util::CloseVetoException& )
1128  {
1129  // there's still someone who needs the object!
1130  }
1131  }
1132 
1133  xObjRef = NULL;*/
1134  }
1135  else if ( mpImpl->mxObjRef.is() )
1136  {
1137  if ( getSdrModelFromSdrObject().getUnoModel().is() )
1138  {
1139  // remove object, but don't close it (that's up to someone else)
1140  comphelper::EmbeddedObjectContainer* pContainer = mpImpl->mxObjRef.GetContainer();
1141  if ( pContainer )
1142  {
1143  pContainer->RemoveEmbeddedObject( mpImpl->mxObjRef.GetObject() );
1144 
1145  // TODO/LATER: mpImpl->aPersistName contains outdated information, to keep it updated
1146  // it should be returned from RemoveEmbeddedObject call. Currently it is no problem,
1147  // since no container is adjusted, actually the empty string could be provided as a name here
1148  mpImpl->mxObjRef.AssignToContainer( nullptr, mpImpl->aPersistName );
1149  }
1150 
1152  }
1153  }
1154  }
1155 
1156  if ( mpImpl->mxObjRef.is() && mpImpl->mxLightClient.is() )
1157  {
1158  mpImpl->mxObjRef->removeStateChangeListener ( mpImpl->mxLightClient.get() );
1159  mpImpl->mxObjRef->removeEventListener( uno::Reference< document::XEventListener >( mpImpl->mxLightClient.get() ) );
1160  mpImpl->mxObjRef->setClientSite( nullptr );
1161 
1163  }
1164  }
1165  catch( css::uno::Exception& )
1166  {
1167  TOOLS_WARN_EXCEPTION( "svx", "SdrOle2Obj::Disconnect_Impl()" );
1168  }
1169 
1170  mpImpl->mbConnected = false;
1171 }
1172 
1174 {
1175  const Graphic* pOLEGraphic = GetGraphic();
1176 
1177  if(pOLEGraphic)
1178  {
1179  // #i118485# allow creating a SdrGrafObj representation
1180  SdrGrafObj* pClone = new SdrGrafObj(
1182  *pOLEGraphic);
1183 
1184  // copy transformation
1185  basegfx::B2DHomMatrix aMatrix;
1186  basegfx::B2DPolyPolygon aPolyPolygon;
1187 
1188  TRGetBaseGeometry(aMatrix, aPolyPolygon);
1189  pClone->TRSetBaseGeometry(aMatrix, aPolyPolygon);
1190 
1191  // copy all attributes to support graphic styles for OLEs
1192  pClone->SetStyleSheet(GetStyleSheet(), false);
1194 
1195  if(bAddText)
1196  {
1197  // #i118485# copy text (Caution! Model needed, as guaranteed in aw080)
1199 
1200  if(pOPO)
1201  {
1202  pClone->NbcSetOutlinerParaObject(std::make_unique<OutlinerParaObject>(*pOPO));
1203  }
1204  }
1205 
1206  return SdrObjectUniquePtr(pClone);
1207  }
1208  else
1209  {
1210  // #i100710# pOLEGraphic may be zero (no visualisation available),
1211  // so we need to use the OLE replacement graphic
1212  SdrRectObj* pClone = new SdrRectObj(
1214  GetSnapRect());
1215 
1216  // gray outline
1217  pClone->SetMergedItem(XLineStyleItem(css::drawing::LineStyle_SOLID));
1218  const svtools::ColorConfig aColorConfig;
1220  pClone->SetMergedItem(XLineColorItem(OUString(), aColor.nColor));
1221 
1222  // bitmap fill
1223  pClone->SetMergedItem(XFillStyleItem(drawing::FillStyle_BITMAP));
1225  pClone->SetMergedItem(XFillBmpTileItem(false));
1226  pClone->SetMergedItem(XFillBmpStretchItem(false));
1227 
1228  return SdrObjectUniquePtr(pClone);
1229  }
1230 }
1231 
1232 SdrObjectUniquePtr SdrOle2Obj::DoConvertToPolyObj(bool bBezier, bool bAddText) const
1233 {
1234  // #i118485# missing converter added
1236 
1237  if(pRetval)
1238  {
1239  return pRetval->DoConvertToPolyObj(bBezier, bAddText);
1240  }
1241 
1242  return nullptr;
1243 }
1244 
1246 {
1247  const bool bRemove(pNewPage == nullptr && pOldPage != nullptr);
1248  const bool bInsert(pNewPage != nullptr && pOldPage == nullptr);
1249 
1250  if (bRemove && mpImpl->mbConnected )
1251  {
1252  Disconnect();
1253  }
1254 
1255  // call parent
1256  SdrRectObj::handlePageChange(pOldPage, pNewPage);
1257 
1258  if (bInsert && !mpImpl->mbConnected )
1259  {
1260  Connect();
1261  }
1262 }
1263 
1264 void SdrOle2Obj::SetObjRef( const css::uno::Reference < css::embed::XEmbeddedObject >& rNewObjRef )
1265 {
1266  DBG_ASSERT( !rNewObjRef.is() || !mpImpl->mxObjRef.GetObject().is(), "SetObjRef called on already initialized object!");
1267  if( rNewObjRef == mpImpl->mxObjRef.GetObject() )
1268  return;
1269 
1270  // the caller of the method is responsible to control the old object, it will not be closed here
1271  // Otherwise WW8 import crashes because it transfers control to OLENode by this method
1272  if ( mpImpl->mxObjRef.GetObject().is() )
1273  mpImpl->mxObjRef.Lock( false );
1274 
1275  // avoid removal of object in Disconnect! It is definitely a HACK to call SetObjRef(0)!
1276  // This call will try to close the objects; so if anybody else wants to keep it, it must be locked by a CloseListener
1277  mpImpl->mxObjRef.Clear();
1278 
1279  if ( mpImpl->mbConnected )
1280  Disconnect();
1281 
1282  mpImpl->mxObjRef.Assign( rNewObjRef, GetAspect() );
1283  mpImpl->mbTypeAsked = false;
1284 
1285  if ( mpImpl->mxObjRef.is() )
1286  {
1287  mpImpl->mxGraphic.reset();
1288 
1289  if ( mpImpl->mxObjRef->getStatus( GetAspect() ) & embed::EmbedMisc::EMBED_NEVERRESIZE )
1290  SetResizeProtect(true);
1291 
1292  // For math objects, set closed state to transparent
1293  SetClosedObj(!ImplIsMathObj( rNewObjRef ));
1294 
1295  Connect();
1296  }
1297 
1298  SetChanged();
1300 }
1301 
1302 void SdrOle2Obj::SetClosedObj( bool bIsClosed )
1303 {
1304  // TODO/LATER: do we still need this hack?
1305  // Allow changes to the closed state of OLE objects
1306  bClosedObj = bIsClosed;
1307 }
1308 
1310 {
1311  // #i118485# use central replacement generator
1312  return createSdrGrafObjReplacement(false);
1313 }
1314 
1315 void SdrOle2Obj::SetPersistName( const OUString& rPersistName )
1316 {
1317  DBG_ASSERT( mpImpl->aPersistName.isEmpty(), "Persist name changed!");
1318 
1319  mpImpl->aPersistName = rPersistName;
1320  mpImpl->mbLoadingOLEObjectFailed = false;
1321 
1322  Connect();
1323  SetChanged();
1324 }
1325 
1327 {
1328  mpImpl->aPersistName.clear();
1329  mpImpl->mbLoadingOLEObjectFailed = false;
1330  SetObjRef(nullptr);
1331 }
1332 
1333 const OUString& SdrOle2Obj::GetPersistName() const
1334 {
1335  return mpImpl->aPersistName;
1336 }
1337 
1339 {
1340  // #i118485# Allowing much more attributes for OLEs
1341  rInfo.bRotateFreeAllowed = true;
1342  rInfo.bRotate90Allowed = true;
1343  rInfo.bMirrorFreeAllowed = true;
1344  rInfo.bMirror45Allowed = true;
1345  rInfo.bMirror90Allowed = true;
1346  rInfo.bTransparenceAllowed = true;
1347  rInfo.bShearAllowed = true;
1348  rInfo.bEdgeRadiusAllowed = false;
1349  rInfo.bNoOrthoDesired = false;
1350  rInfo.bCanConvToPath = true;
1351  rInfo.bCanConvToPoly = true;
1352  rInfo.bCanConvToPathLineToArea = false;
1353  rInfo.bCanConvToPolyLineToArea = false;
1354  rInfo.bCanConvToContour = true;
1355 }
1356 
1358 {
1359  return mpImpl->mbFrame ? sal_uInt16(OBJ_FRAME) : sal_uInt16(OBJ_OLE2);
1360 }
1361 
1363 {
1364  OUStringBuffer sName(SvxResId(mpImpl->mbFrame ? STR_ObjNameSingulFrame : STR_ObjNameSingulOLE2));
1365 
1366  const OUString aName(GetName());
1367 
1368  if (!aName.isEmpty())
1369  {
1370  sName.append(" '");
1371  sName.append(aName);
1372  sName.append('\'');
1373  }
1374 
1375  return sName.makeStringAndClear();
1376 }
1377 
1379 {
1380  return SvxResId(mpImpl->mbFrame ? STR_ObjNamePluralFrame : STR_ObjNamePluralOLE2);
1381 }
1382 
1384 {
1385  return CloneHelper< SdrOle2Obj >(rTargetModel);
1386 }
1387 
1389 {
1390  return assignFrom(rObj);
1391 }
1392 
1394 {
1395  //TODO/LATER: who takes over control of my old object?!
1396  if( &rObj == this )
1397  {
1398  return *this;
1399  }
1400 
1401  // ImpAssign( rObj );
1402  const SdrOle2Obj& rOle2Obj = rObj;
1403 
1404  if( mpImpl->mbConnected )
1405  Disconnect();
1406 
1407  SdrRectObj::operator=( rObj );
1408 
1409  // Manually copying bClosedObj attribute
1410  SetClosedObj( rObj.IsClosedObj() );
1411 
1412  mpImpl->aPersistName = rOle2Obj.mpImpl->aPersistName;
1413  mpImpl->maProgName = rOle2Obj.mpImpl->maProgName;
1414  mpImpl->mbFrame = rOle2Obj.mpImpl->mbFrame;
1415 
1416  if (rOle2Obj.mpImpl->mxGraphic)
1417  {
1418  mpImpl->mxGraphic.reset(new Graphic(*rOle2Obj.mpImpl->mxGraphic));
1419  }
1420 
1421  if( !IsEmptyPresObj() )
1422  {
1423  ::comphelper::IEmbeddedHelper* pDestPers(getSdrModelFromSdrObject().GetPersist());
1425  if( pDestPers && pSrcPers )
1426  {
1427  DBG_ASSERT( !mpImpl->mxObjRef.is(), "Object already existing!" );
1428  comphelper::EmbeddedObjectContainer& rContainer = pSrcPers->getEmbeddedObjectContainer();
1429  uno::Reference < embed::XEmbeddedObject > xObj = rContainer.GetEmbeddedObject( mpImpl->aPersistName );
1430  if ( xObj.is() )
1431  {
1432  OUString aTmp;
1433  mpImpl->mxObjRef.Assign( pDestPers->getEmbeddedObjectContainer().CopyAndGetEmbeddedObject(
1434  rContainer, xObj, aTmp, pSrcPers->getDocumentBaseURL(), pDestPers->getDocumentBaseURL()), rOle2Obj.GetAspect());
1435  mpImpl->mbTypeAsked = false;
1436  mpImpl->aPersistName = aTmp;
1438  }
1439 
1440  Connect();
1441  }
1442  }
1443 
1444  return *this;
1445 }
1446 
1448 {
1449  // #i118524# do not again set VisAreaSize when the call comes from OLE client (e.g. ObjectAreaChanged)
1450  if (mpImpl->mbSuppressSetVisAreaSize)
1451  return;
1452 
1453  // currently there is no need to recalculate scaling for iconified objects
1454  // TODO/LATER: it might be needed in future when it is possible to change the icon
1455  if ( GetAspect() == embed::Aspects::MSOLE_ICON )
1456  return;
1457 
1458  // the object area of an embedded object was changed, e.g. by user interaction an a selected object
1459  GetObjRef();
1460  if (mpImpl->mxObjRef.is())
1461  {
1462  sal_Int64 nMiscStatus = mpImpl->mxObjRef->getStatus( GetAspect() );
1463 
1464  // the client is required to get access to scaling
1465  SfxInPlaceClient* pClient(
1467  dynamic_cast<SfxObjectShell*>(
1468  getSdrModelFromSdrObject().GetPersist()),
1469  mpImpl->mxObjRef.GetObject()));
1470  const bool bHasOwnClient(
1471  mpImpl->mxLightClient.is() &&
1472  mpImpl->mxObjRef->getClientSite() == uno::Reference< embed::XEmbeddedClient >( mpImpl->mxLightClient.get() ) );
1473 
1474  if ( pClient || bHasOwnClient )
1475  {
1476  // TODO: IMHO we need to do similar things when object is UIActive or OutplaceActive?!
1477  if ( ((nMiscStatus & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE) &&
1478  svt::EmbeddedObjectRef::TryRunningState( mpImpl->mxObjRef.GetObject() ))
1479  || mpImpl->mxObjRef->getCurrentState() == embed::EmbedStates::INPLACE_ACTIVE
1480  )
1481  {
1482  Fraction aScaleWidth;
1483  Fraction aScaleHeight;
1484  if ( pClient )
1485  {
1486  aScaleWidth = pClient->GetScaleWidth();
1487  aScaleHeight = pClient->GetScaleHeight();
1488  }
1489  else
1490  {
1491  aScaleWidth = mpImpl->mxLightClient->GetScaleWidth();
1492  aScaleHeight = mpImpl->mxLightClient->GetScaleHeight();
1493  }
1494 
1495  // The object wants to resize itself (f.e. Chart wants to recalculate the layout)
1496  // or object is inplace active and so has a window that must be resized also
1497  // In these cases the change in the object area size will be reflected in a change of the
1498  // objects' visual area. The scaling will not change, but it might exist already and must
1499  // be used in calculations
1500  MapUnit aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( mpImpl->mxObjRef->getMapUnit( GetAspect() ) );
1501  Size aVisSize( static_cast<long>( Fraction( maRect.GetWidth() ) / aScaleWidth ),
1502  static_cast<long>( Fraction( maRect.GetHeight() ) / aScaleHeight ) );
1503 
1504  aVisSize = OutputDevice::LogicToLogic(
1505  aVisSize,
1506  MapMode(getSdrModelFromSdrObject().GetScaleUnit()),
1507  MapMode(aMapUnit));
1508  awt::Size aSz;
1509  aSz.Width = aVisSize.Width();
1510  aSz.Height = aVisSize.Height();
1511  mpImpl->mxObjRef->setVisualAreaSize( GetAspect(), aSz );
1512 
1513  try
1514  {
1515  aSz = mpImpl->mxObjRef->getVisualAreaSize( GetAspect() );
1516  }
1517  catch( embed::NoVisualAreaSizeException& )
1518  {}
1519 
1520  tools::Rectangle aAcceptedVisArea;
1521  aAcceptedVisArea.SetSize( Size( static_cast<long>( Fraction( long( aSz.Width ) ) * aScaleWidth ),
1522  static_cast<long>( Fraction( long( aSz.Height ) ) * aScaleHeight ) ) );
1523  if (aVisSize != aAcceptedVisArea.GetSize())
1524  {
1525  // server changed VisArea to its liking and the VisArea is different than the suggested one
1526  // store the new value as given by the object
1527  MapUnit aNewMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( mpImpl->mxObjRef->getMapUnit( GetAspect() ) );
1528  maRect.SetSize(
1530  aAcceptedVisArea.GetSize(),
1531  MapMode(aNewMapUnit),
1532  MapMode(getSdrModelFromSdrObject().GetScaleUnit())));
1533  }
1534 
1535  // make the new object area known to the client
1536  // compared to the "else" branch aRect might have been changed by the object and no additional scaling was applied
1537  // WHY this -> OSL_ASSERT( pClient );
1538  if( pClient )
1539  pClient->SetObjArea(maRect);
1540 
1541  // we need a new replacement image as the object has resized itself
1542 
1543  //#i79578# don't request a new replacement image for charts to often
1544  //a chart sends a modified call to the framework if it was changed
1545  //thus the replacement update is already handled there
1546  if( !IsChart() )
1547  mpImpl->mxObjRef.UpdateReplacement();
1548  }
1549  else
1550  {
1551  // The object isn't active and does not want to resize itself so the changed object area size
1552  // will be reflected in a changed object scaling
1553  Fraction aScaleWidth;
1554  Fraction aScaleHeight;
1555  Size aObjAreaSize;
1556  if ( CalculateNewScaling( aScaleWidth, aScaleHeight, aObjAreaSize ) )
1557  {
1558  if ( pClient )
1559  {
1560  tools::Rectangle aScaleRect(maRect.TopLeft(), aObjAreaSize);
1561  pClient->SetObjAreaAndScale( aScaleRect, aScaleWidth, aScaleHeight);
1562  }
1563  else
1564  {
1565  mpImpl->mxLightClient->SetSizeScale( aScaleWidth, aScaleHeight );
1566  }
1567  }
1568  }
1569  }
1570  else if( (nMiscStatus & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE) &&
1571  svt::EmbeddedObjectRef::TryRunningState( mpImpl->mxObjRef.GetObject() ) )
1572  {
1573  //also handle not sfx based ole objects e.g. charts
1574  //#i83860# resizing charts in impress distorts fonts
1575  uno::Reference< embed::XVisualObject > xVisualObject( getXModel(), uno::UNO_QUERY );
1576  if( xVisualObject.is() )
1577  {
1578  const MapUnit aMapUnit(
1580  mpImpl->mxObjRef->getMapUnit(GetAspect())));
1581  const Point aTL( maRect.TopLeft() );
1582  const Point aBR( maRect.BottomRight() );
1583  const Point aTL2(
1585  aTL,
1586  MapMode(getSdrModelFromSdrObject().GetScaleUnit()),
1587  MapMode(aMapUnit)));
1588  const Point aBR2(
1590  aBR,
1591  MapMode(getSdrModelFromSdrObject().GetScaleUnit()),
1592  MapMode(aMapUnit)));
1593  const tools::Rectangle aNewRect(
1594  aTL2,
1595  aBR2);
1596 
1597  xVisualObject->setVisualAreaSize(
1598  GetAspect(),
1599  awt::Size(
1600  aNewRect.GetWidth(),
1601  aNewRect.GetHeight()));
1602  }
1603  }
1604  }
1605 }
1606 
1607 void SdrOle2Obj::NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact)
1608 {
1609  if(!getSdrModelFromSdrObject().isLocked())
1610  {
1611  GetObjRef();
1612 
1613  if ( mpImpl->mxObjRef.is() && ( mpImpl->mxObjRef->getStatus( GetAspect() ) & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE ) )
1614  {
1615  // if the object needs recompose on resize
1616  // the client site should be created before the resize will take place
1617  // check whether there is no client site and create it if necessary
1619  }
1620  }
1621 
1622  SdrRectObj::NbcResize(rRef,xFact,yFact);
1623 
1624  if( !getSdrModelFromSdrObject().isLocked() )
1626 }
1627 
1629 {
1630  SdrRectObj::SetGeoData(rGeo);
1631 
1632  if( !getSdrModelFromSdrObject().isLocked() )
1634 }
1635 
1637 {
1639 
1640  if( !getSdrModelFromSdrObject().isLocked() )
1642 
1643  if ( mpImpl->mxObjRef.is() && IsChart() )
1644  {
1645  //#i103460# charts do not necessarily have an own size within ODF files,
1646  //for this case they need to use the size settings from the surrounding frame,
1647  //which is made available with this method as there is no other way
1648  mpImpl->mxObjRef.SetDefaultSizeForChart( Size( rRect.GetWidth(), rRect.GetHeight() ) );
1649  }
1650 }
1651 
1653 {
1655 
1656  if( !getSdrModelFromSdrObject().isLocked() )
1658 }
1659 
1661 {
1662  if ( mpImpl->mxObjRef.is() )
1663  return mpImpl->mxObjRef.GetGraphic();
1664  return mpImpl->mxGraphic.get();
1665 }
1666 
1668 {
1669  if ( mpImpl->mxObjRef.is() )
1670  mpImpl->mxObjRef.UpdateReplacement();
1671 }
1672 
1673 Size SdrOle2Obj::GetOrigObjSize( MapMode const * pTargetMapMode ) const
1674 {
1675  return mpImpl->mxObjRef.GetSize( pTargetMapMode );
1676 }
1677 
1679 {
1680  mpImpl->mbSuppressSetVisAreaSize = bNew;
1681 }
1682 
1683 void SdrOle2Obj::NbcMove(const Size& rSize)
1684 {
1685  SdrRectObj::NbcMove(rSize);
1686 
1687  if( !getSdrModelFromSdrObject().isLocked() )
1689 }
1690 
1691 bool SdrOle2Obj::CanUnloadRunningObj( const uno::Reference< embed::XEmbeddedObject >& xObj, sal_Int64 nAspect )
1692 {
1693  uno::Reference<embed::XEmbedPersist2> xPersist(xObj, uno::UNO_QUERY);
1694  if (xPersist.is())
1695  {
1696  if (!xPersist->isStored())
1697  // It doesn't have persistent storage. We can't unload this.
1698  return false;
1699  }
1700 
1701  bool bResult = false;
1702 
1703  sal_Int32 nState = xObj->getCurrentState();
1704  if ( nState == embed::EmbedStates::LOADED )
1705  {
1706  // the object is already unloaded
1707  bResult = true;
1708  }
1709  else
1710  {
1711  uno::Reference < util::XModifiable > xModifiable( xObj->getComponent(), uno::UNO_QUERY );
1712  if ( !xModifiable.is() )
1713  bResult = true;
1714  else
1715  {
1716  sal_Int64 nMiscStatus = xObj->getStatus( nAspect );
1717 
1718  if ( embed::EmbedMisc::MS_EMBED_ALWAYSRUN != ( nMiscStatus & embed::EmbedMisc::MS_EMBED_ALWAYSRUN ) &&
1719  embed::EmbedMisc::EMBED_ACTIVATEIMMEDIATELY != ( nMiscStatus & embed::EmbedMisc::EMBED_ACTIVATEIMMEDIATELY ) &&
1720  !( xModifiable.is() && xModifiable->isModified() ) &&
1721  !( nState == embed::EmbedStates::INPLACE_ACTIVE || nState == embed::EmbedStates::UI_ACTIVE || nState == embed::EmbedStates::ACTIVE ) )
1722  {
1723  bResult = true;
1724  }
1725  }
1726  }
1727 
1728  return bResult;
1729 }
1730 
1731 bool SdrOle2Obj::Unload( const uno::Reference< embed::XEmbeddedObject >& xObj, sal_Int64 nAspect )
1732 {
1733  bool bResult = false;
1734 
1735  if ( CanUnloadRunningObj( xObj, nAspect ) )
1736  {
1737  try
1738  {
1739  xObj->changeState( embed::EmbedStates::LOADED );
1740  bResult = true;
1741  }
1742  catch( css::uno::Exception& )
1743  {
1744  TOOLS_WARN_EXCEPTION( "svx", "SdrOle2Obj::Unload()" );
1745  }
1746  }
1747 
1748  return bResult;
1749 }
1750 
1752 {
1753  if (!mpImpl->mxObjRef.is())
1754  // Already unloaded.
1755  return true;
1756 
1757  bool bUnloaded = false;
1758 
1759  if ( mpImpl->mxObjRef.is() )
1760  {
1761  bUnloaded = Unload( mpImpl->mxObjRef.GetObject(), GetAspect() );
1762  }
1763 
1764  return bUnloaded;
1765 }
1766 
1768 {
1769  if ( !mpImpl->mxObjRef.is() && !mpImpl->aPersistName.isEmpty() && getSdrModelFromSdrObject().GetPersist() )
1770  {
1771  // Only try loading if it did not went wrong up to now
1772  if(!mpImpl->mbLoadingOLEObjectFailed)
1773  {
1774  mpImpl->mxObjRef.Assign(
1775  getSdrModelFromSdrObject().GetPersist()->getEmbeddedObjectContainer().GetEmbeddedObject(mpImpl->aPersistName),
1776  GetAspect());
1777  mpImpl->mbTypeAsked = false;
1779 
1780  // If loading of OLE object failed, remember that to not invoke an endless
1781  // loop trying to load it again and again.
1782  if( mpImpl->mxObjRef.is() )
1783  {
1784  mpImpl->mbLoadingOLEObjectFailed = true;
1785  }
1786 
1787  // For math objects, set closed state to transparent
1788  SetClosedObj(!ImplIsMathObj( mpImpl->mxObjRef.GetObject() ));
1789  }
1790 
1791  if ( mpImpl->mxObjRef.is() )
1792  {
1793  if( !IsEmptyPresObj() )
1794  {
1795  // remember modified status of model
1796  const bool bWasChanged(getSdrModelFromSdrObject().IsChanged());
1797 
1798  // perhaps preview not valid anymore
1799  // This line changes the modified state of the model
1800  ClearGraphic();
1801 
1802  // if status was not set before, force it back
1803  // to not set, so that SetGraphic(0) above does not
1804  // set the modified state of the model.
1805  if(!bWasChanged && getSdrModelFromSdrObject().IsChanged())
1806  {
1808  }
1809  }
1810  }
1811 
1812  if ( mpImpl->mxObjRef.is() )
1813  Connect();
1814  }
1815 
1816  if ( mpImpl->mbConnected )
1817  {
1818  // move object to first position in cache
1820  }
1821 }
1822 
1823 uno::Reference < embed::XEmbeddedObject > const & SdrOle2Obj::GetObjRef() const
1824 {
1825  const_cast<SdrOle2Obj*>(this)->GetObjRef_Impl();
1826  return mpImpl->mxObjRef.GetObject();
1827 }
1828 
1829 uno::Reference < embed::XEmbeddedObject > const & SdrOle2Obj::GetObjRef_NoInit() const
1830 {
1831  return mpImpl->mxObjRef.GetObject();
1832 }
1833 
1834 uno::Reference< frame::XModel > SdrOle2Obj::getXModel() const
1835 {
1836  GetObjRef();
1837  if ( svt::EmbeddedObjectRef::TryRunningState(mpImpl->mxObjRef.GetObject()) )
1838  return uno::Reference< frame::XModel >( mpImpl->mxObjRef->getComponent(), uno::UNO_QUERY );
1839  else
1840  return uno::Reference< frame::XModel >();
1841 }
1842 
1844 {
1845  if (!mpImpl->mbTypeAsked)
1846  {
1847  mpImpl->mbIsChart = mpImpl->mxObjRef.IsChart();
1848  mpImpl->mbTypeAsked = true;
1849  }
1850  return mpImpl->mbIsChart;
1851 }
1852 
1853 void SdrOle2Obj::SetGraphicToObj( const Graphic& aGraphic )
1854 {
1855  mpImpl->mxObjRef.SetGraphic( aGraphic, OUString() );
1856  // if the object isn't valid, e.g. link to something that doesn't exist, set the fallback
1857  // graphic as mxGraphic so SdrOle2Obj::GetGraphic will show the fallback
1858  if (const Graphic* pObjGraphic = mpImpl->mxObjRef.is() ? nullptr : mpImpl->mxObjRef.GetGraphic())
1859  mpImpl->mxGraphic.reset(new Graphic(*pObjGraphic));
1860 }
1861 
1862 void SdrOle2Obj::SetGraphicToObj( const uno::Reference< io::XInputStream >& xGrStream, const OUString& aMediaType )
1863 {
1864  mpImpl->mxObjRef.SetGraphicStream( xGrStream, aMediaType );
1865  // if the object isn't valid, e.g. link to something that doesn't exist, set the fallback
1866  // graphic as mxGraphic so SdrOle2Obj::GetGraphic will show the fallback
1867  if (const Graphic* pObjGraphic = mpImpl->mxObjRef.is() ? nullptr : mpImpl->mxObjRef.GetGraphic())
1868  mpImpl->mxGraphic.reset(new Graphic(*pObjGraphic));
1869 }
1870 
1872 {
1873  if ( !mpImpl->mxObjRef.is() )
1874  return false;
1875 
1876  SvGlobalName aObjClsId( mpImpl->mxObjRef->getClassID() );
1877  return SvGlobalName(SO3_SC_CLASSID_30) == aObjClsId
1878  || SvGlobalName(SO3_SC_CLASSID_40) == aObjClsId
1879  || SvGlobalName(SO3_SC_CLASSID_50) == aObjClsId
1880  || SvGlobalName(SO3_SC_CLASSID_60) == aObjClsId
1881  || SvGlobalName(SO3_SC_OLE_EMBED_CLASSID_60) == aObjClsId
1882  || SvGlobalName(SO3_SC_OLE_EMBED_CLASSID_8) == aObjClsId
1883  || SvGlobalName(SO3_SC_CLASSID) == aObjClsId;
1884 }
1885 
1886 uno::Reference< frame::XModel > SdrOle2Obj::GetParentXModel() const
1887 {
1888  uno::Reference< frame::XModel > xDoc(getSdrModelFromSdrObject().getUnoModel(), uno::UNO_QUERY);
1889  return xDoc;
1890 }
1891 
1892 bool SdrOle2Obj::CalculateNewScaling( Fraction& aScaleWidth, Fraction& aScaleHeight, Size& aObjAreaSize )
1893 {
1894  // TODO/LEAN: to avoid rounding errors scaling always uses the VisArea.
1895  // If we don't cache it for own objects also we must load the object here
1896  if (!mpImpl->mxObjRef.is())
1897  return false;
1898 
1899  MapMode aMapMode(getSdrModelFromSdrObject().GetScaleUnit());
1900  aObjAreaSize = mpImpl->mxObjRef.GetSize( &aMapMode );
1901 
1902  Size aSize = maRect.GetSize();
1903  aScaleWidth = Fraction(aSize.Width(), aObjAreaSize.Width() );
1904  aScaleHeight = Fraction(aSize.Height(), aObjAreaSize.Height() );
1905 
1906  // reduce to 10 binary digits
1907  aScaleHeight.ReduceInaccurate(10);
1908  aScaleWidth.ReduceInaccurate(10);
1909 
1910  return true;
1911 }
1912 
1914 {
1915  // The Own Light Client must be registered in object only using this method!
1916  if ( !SfxInPlaceClient::GetClient( dynamic_cast<SfxObjectShell*>(getSdrModelFromSdrObject().GetPersist()), mpImpl->mxObjRef.GetObject() )
1917  && !( mpImpl->mxLightClient.is() && mpImpl->mxObjRef->getClientSite() == uno::Reference< embed::XEmbeddedClient >( mpImpl->mxLightClient.get() ) ) )
1918  {
1919  Connect();
1920 
1921  if ( mpImpl->mxObjRef.is() && mpImpl->mxLightClient.is() )
1922  {
1923  Fraction aScaleWidth;
1924  Fraction aScaleHeight;
1925  Size aObjAreaSize;
1926  if ( CalculateNewScaling( aScaleWidth, aScaleHeight, aObjAreaSize ) )
1927  {
1928  mpImpl->mxLightClient->SetSizeScale( aScaleWidth, aScaleHeight );
1929  try {
1930  mpImpl->mxObjRef->setClientSite( mpImpl->mxLightClient.get() );
1931  return true;
1932  } catch( uno::Exception& )
1933  {}
1934  }
1935 
1936  }
1937 
1938  return false;
1939  }
1940 
1941  return true;
1942 }
1943 
1945 {
1946  return Graphic(BitmapEx(BMP_SVXOLEOBJ));
1947 }
1948 
1949 void SdrOle2Obj::SetWindow(const css::uno::Reference < css::awt::XWindow >& _xWindow)
1950 {
1951  if ( mpImpl->mxObjRef.is() && mpImpl->mxLightClient.is() )
1952  {
1953  mpImpl->mxLightClient->setWindow(_xWindow);
1954  }
1955 }
1956 
1957 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Point TopLeft() const
const Fraction & GetScaleWidth() const
virtual void NbcMove(const Size &rSiz) override
The methods Move, Resize, Rotate, Mirror, Shear, SetSnapRect and SetLogicRect call the corresponding ...
Definition: svdorect.cxx:473
rtl::Reference< SvxUnoShapeModifyListener > mxModifyListener
Definition: svdoole2.cxx:625
long Width() const
#define SO3_SM_CLASSID_60
bool IsChart() const
Definition: svdoole2.cxx:1843
long GetWidth() const
void Disconnect()
Definition: svdoole2.cxx:1056
SdrRectObj(SdrModel &rSdrModel)
The corner radius parameter is dropped at some point.
Definition: svdorect.cxx:65
std::unique_ptr< SdrOle2ObjImpl > mpImpl
Definition: svdoole2.hxx:49
long GetHeight() const
bool IsClosedObj() const
Definition: svdobj.hxx:787
foreign graphic (StarView Graphic)
Definition: svdobj.hxx:137
css::uno::Reference< css::embed::XEmbeddedObject > const & GetObjRef() const
Definition: svdoole2.cxx:1823
void SetResizeProtect(bool bProt)
Definition: svdobj.cxx:2590
bool SetObjArea(const tools::Rectangle &)
virtual OUString TakeObjNameSingul() const override
Definition: svdoole2.cxx:1362
virtual void TakeObjInfo(SdrObjTransformInfoRec &rInfo) const override
Definition: svdoole2.cxx:1338
virtual void NbcSetLogicRect(const tools::Rectangle &rRect) override
Definition: svdoole2.cxx:1652
Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
long Height() const
void SetPersistName(const OUString &rPersistName)
Definition: svdoole2.cxx:1315
void SetProgName(const OUString &rName)
Definition: svdoole2.cxx:807
bool isInplaceActive() const
Definition: svdoole2.cxx:780
Reference< XFrame > xFrame
void SetStyleSheet(SfxStyleSheet *pNewStyleSheet, bool bDontRemoveHardAttr)
Definition: svdobj.cxx:2167
void Connect()
Definition: svdoole2.cxx:822
#define OBJECT_CLIENT_OLE
void CloseEmbeddedObject(const css::uno::Reference< css::embed::XEmbeddedObject > &)
bool isUiActive() const
Definition: svdoole2.cxx:785
virtual void handlePageChange(SdrPage *pOldPage, SdrPage *pNewPage) override
Definition: svdoole2.cxx:1245
virtual OUString getDocumentBaseURL() const =0
SVX_DLLPRIVATE void Connect_Impl()
Definition: svdoole2.cxx:962
bool HasEmbeddedObject(const OUString &)
measurement object
Definition: svdobj.hxx:144
css::uno::Reference< css::uno::XInterface > const & getUnoModel()
Definition: svdmodel.cxx:1696
Size GetOrigObjSize(MapMode const *pTargetMapMode=nullptr) const
Definition: svdoole2.cxx:1673
#define SO3_SC_CLASSID_40
virtual void NbcMove(const Size &rSize) override
The methods Move, Resize, Rotate, Mirror, Shear, SetSnapRect and SetLogicRect call the corresponding ...
Definition: svdoole2.cxx:1683
virtual void TRSetBaseGeometry(const basegfx::B2DHomMatrix &rMatrix, const basegfx::B2DPolyPolygon &rPolyPolygon) override
Definition: svdotext.cxx:1620
#define SO3_SM_CLASSID
virtual const tools::Rectangle & GetSnapRect() const override
Definition: svdoattr.cxx:91
All geometrical data of an arbitrary object for use in undo/redo.
Definition: svdobj.hxx:226
SdrOle2ObjImpl(bool bFrame, const svt::EmbeddedObjectRef &rObjRef)
Definition: svdoole2.cxx:639
virtual std::unique_ptr< sdr::contact::ViewContact > CreateObjectSpecificViewContact() override
Definition: svdoole2.cxx:687
css::uno::Reference< css::frame::XModel > getXModel() const
Definition: svdoole2.cxx:1834
Rectangle objects (rectangle, circle, ...)
Definition: svdorect.hxx:39
static OutputDevice * GetDefaultDevice()
void SetObjRef(const css::uno::Reference< css::embed::XEmbeddedObject > &rNewObjRef)
Definition: svdoole2.cxx:1264
SVX_DLLPRIVATE void GetObjRef_Impl()
Definition: svdoole2.cxx:1767
Provides information about various ZObject properties.
Definition: svdobj.hxx:248
Reference< XController > xController
OUString SvxResId(const char *pId)
Definition: dialmgr.cxx:28
Any SAL_CALL getCaughtException()
#define SO3_SC_CLASSID_30
void ObjectLoaded()
Definition: svdoole2.cxx:1032
int nCount
void RemoveObj(SdrOle2Obj *pObj)
Definition: svdetc.cxx:198
virtual EmbeddedObjectContainer & getEmbeddedObjectContainer() const =0
SfxStyleSheet * GetStyleSheet() const
Definition: svdobj.cxx:2162
tools::Rectangle maRect
Definition: svdotext.hxx:182
virtual std::unique_ptr< sdr::properties::BaseProperties > CreateObjectSpecificProperties() override
Definition: svdoole2.cxx:680
void SetMergedItemSet(const SfxItemSet &rSet, bool bClearAllItems=false)
Definition: svdobj.cxx:1936
SVX_DLLPRIVATE void Disconnect_Impl()
Definition: svdoole2.cxx:1095
bool bClosedObj
Definition: svdobj.hxx:941
OLEObjCache & GetOLEObjCache()
Definition: svdetc.hxx:197
SotClipboardFormatId
virtual SdrOle2Obj * CloneSdrObject(SdrModel &rTargetModel) const override
Definition: svdoole2.cxx:1383
#define SO3_SC_CLASSID_60
SVX_DLLPRIVATE css::uno::Reference< css::embed::XEmbeddedObject > const & GetObjRef_NoInit() const
Definition: svdoole2.cxx:1829
virtual void SetChanged(bool bFlg=true)
Definition: svdmodel.cxx:1274
virtual OUString TakeObjNamePlural() const override
Definition: svdoole2.cxx:1378
OUString maProgName
Definition: svdoole2.cxx:611
#define SO3_SC_CLASSID_50
virtual void NbcSetSnapRect(const tools::Rectangle &rRect) override
Definition: svdoole2.cxx:1636
void SetGraphicToObj(const Graphic &aGraphic)
Definition: svdoole2.cxx:1853
virtual SdrObjectUniquePtr DoConvertToPolyObj(bool bBezier, bool bAddText) const override
Definition: svdoole2.cxx:1232
Point BottomRight() const
void ReduceInaccurate(unsigned nSignificantBits)
#define SO3_SM_CLASSID_50
virtual void handlePageChange(SdrPage *pOldPage, SdrPage *pNewPage) override
Definition: svdotext.cxx:459
const svt::EmbeddedObjectRef & getEmbeddedObjectRef() const
Definition: svdoole2.cxx:770
#define TOOLS_WARN_EXCEPTION(area, stream)
bool mbSuppressSetVisAreaSize
Definition: svdoole2.cxx:616
void SetWindow(const css::uno::Reference< css::awt::XWindow > &_xWindow)
Definition: svdoole2.cxx:1949
static bool ImplIsMathObj(const uno::Reference< embed::XEmbeddedObject > &rObjRef)
Definition: svdoole2.cxx:665
rtl::Reference< SdrLightEmbeddedClient_Impl > mxLightClient
Definition: svdoole2.cxx:613
#define DBG_ASSERT(sCon, aError)
void SetClosedObj(bool bIsClosed)
Change the IsClosedObj attribute.
Definition: svdoole2.cxx:1302
virtual sal_uInt16 GetObjIdentifier() const override
Definition: svdoole2.cxx:1357
static Graphic GetEmptyOLEReplacementGraphic()
Definition: svdoole2.cxx:1944
void Remove(SvBaseLink const *pLink)
OUString sName
void InsertFileLink(sfx2::SvBaseLink &, sal_uInt16 nFileType, const OUString &rFileNm, const OUString *pFilterNm=nullptr, const OUString *pRange=nullptr)
inline::tools::Rectangle VCLRectangle(const css::awt::Rectangle &rAWTRect)
void SetSize(const Size &rSize)
int i
void BroadcastObjectChange() const
Definition: svdobj.cxx:932
virtual void SetGeoData(const SdrObjGeoData &rGeo)
Definition: svdobj.cxx:1894
SVX_DLLPRIVATE void ImpSetVisAreaSize()
Definition: svdoole2.cxx:1447
static bool CanUnloadRunningObj(const css::uno::Reference< css::embed::XEmbeddedObject > &xObj, sal_Int64 nAspect)
Definition: svdoole2.cxx:1691
unsigned char sal_Bool
void BreakFileLink_Impl()
Definition: svdoole2.cxx:893
SdrModel & getSdrModelFromSdrObject() const
Definition: svdobj.cxx:299
void DisconnectFileLink_Impl()
Definition: svdoole2.cxx:917
virtual void SetGeoData(const SdrObjGeoData &rGeo) override
Definition: svdoole2.cxx:1628
void SetMergedItem(const SfxPoolItem &rItem)
Definition: svdobj.cxx:1921
This class represents an embedded or linked bitmap graphic object.
Definition: svdograf.hxx:79
bool mbLoadingOLEObjectFailed
Definition: svdoole2.cxx:619
virtual void NbcResize(const Point &rRef, const Fraction &xFact, const Fraction &yFact) override
Definition: svdoole2.cxx:1607
SdrOle2Obj & operator=(const SdrOle2Obj &rObj)
Definition: svdoole2.cxx:1388
void CheckFileLink_Impl()
Definition: svdoole2.cxx:928
SdrOle2ObjImpl(bool bFrame)
Definition: svdoole2.cxx:627
SVX_DLLPRIVATE void Init()
Definition: svdoole2.cxx:692
OUString GetName() const
Definition: svdobj.cxx:725
Size GetSize() const
OUString GetStyleString()
Definition: svdoole2.cxx:741
SdrEmbedObjectLink * mpObjectLink
Definition: svdoole2.cxx:622
void SetGraphic(const Graphic &rGrf)
Definition: svdoole2.cxx:790
bool CalculateNewScaling(Fraction &aScaleWidth, Fraction &aScaleHeight, Size &aObjAreaSize)
Definition: svdoole2.cxx:1892
bool Unload()
Definition: svdoole2.cxx:1751
SdrOle2Obj & assignFrom(const SdrOle2Obj &rObj)
Definition: svdoole2.cxx:1393
#define SO3_SC_CLASSID
Point PixelToLogic(const Point &rDevicePt) const
Point LogicToPixel(const Point &rLogicPt) const
OUString maLinkURL
Definition: svdoole2.cxx:623
css::uno::Reference< css::embed::XEmbeddedObject > GetEmbeddedObject(const OUString &, OUString const *pBaseURL=nullptr)
std::unique_ptr< Graphic > mxGraphic
Definition: svdoole2.cxx:610
static bool GetDisplayNames(const SvBaseLink *, OUString *pType, OUString *pFile=nullptr, OUString *pLink=nullptr, OUString *pFilter=nullptr)
SdrGlobalData & GetSdrGlobalData()
Definition: svdetc.cxx:101
static SfxInPlaceClient * GetClient(SfxObjectShell const *pDoc, const css::uno::Reference< css::embed::XEmbeddedObject > &xObject)
virtual void NbcSetOutlinerParaObject(std::unique_ptr< OutlinerParaObject > pTextObject) override
Definition: svdotext.cxx:1371
void RemoveEmbeddedObject(const OUString &rName, bool bKeepToTempStorage=true)
virtual void NbcSetLogicRect(const tools::Rectangle &rRect) override
Definition: svdorect.cxx:301
SdrRectObj & operator=(const SdrRectObj &rCopy)
Definition: svdorect.cxx:263
bool IsCalc() const
Definition: svdoole2.cxx:1871
svt::EmbeddedObjectRef mxObjRef
Definition: svdoole2.cxx:608
sal_Int64 GetAspect() const
Definition: svdoole2.cxx:775
ColorConfigValue GetColorValue(ColorConfigEntry eEntry, bool bSmart=true) const
static MapUnit UnoEmbed2VCLMapUnit(sal_Int32 nUnoEmbedMapUnit)
void GetNewReplacement()
Definition: svdoole2.cxx:1667
virtual OutlinerParaObject * GetOutlinerParaObject() const override
Definition: svdotext.cxx:1362
SdrOle2Obj(SdrModel &rSdrModel, bool bFrame_=false)
Definition: svdoole2.cxx:713
virtual void NbcResize(const Point &rRef, const Fraction &xFact, const Fraction &yFact) override
Definition: svdorect.cxx:479
::comphelper::IEmbeddedHelper * GetPersist() const
Definition: svdmodel.hxx:351
#define SO3_SM_CLASSID_40
OUString aName
const SfxItemSet & GetMergedItemSet() const
Definition: svdobj.cxx:1911
void ClearGraphic()
Definition: svdoole2.cxx:799
void setSuppressSetVisAreaSize(bool bNew)
Definition: svdoole2.cxx:1678
const OUString & GetPersistName() const
Definition: svdoole2.cxx:1333
virtual ~SdrOle2Obj() override
Definition: svdoole2.cxx:751
void AbandonObject()
Definition: svdoole2.cxx:1326
bool IsEmpty() const
Definition: svdoole2.cxx:817
void SetObjAreaAndScale(const tools::Rectangle &, const Fraction &, const Fraction &)
std::unique_ptr< SdrObject, SdrObjectFreeOp > SdrObjectUniquePtr
Definition: svdobj.hxx:114
SVX_DLLPRIVATE void AddListeners_Impl()
Definition: svdoole2.cxx:1037
bool InsertEmbeddedObject(const css::uno::Reference< css::embed::XEmbeddedObject > &, OUString &)
bool AddOwnLightClient()
Definition: svdoole2.cxx:1913
css::uno::Reference< css::embed::XEmbeddedObject > CopyAndGetEmbeddedObject(EmbeddedObjectContainer &rSrc, const css::uno::Reference< css::embed::XEmbeddedObject > &xObj, OUString &rName, const OUString &rSrcShellID, const OUString &rDestShellID)
SVX_DLLPRIVATE void RemoveListeners_Impl()
Definition: svdoole2.cxx:1071
static uno::Reference< beans::XPropertySet > lcl_getFrame_throw(const SdrOle2Obj *_pObject)
Definition: svdoole2.cxx:97
MapUnit
virtual bool TRGetBaseGeometry(basegfx::B2DHomMatrix &rMatrix, basegfx::B2DPolyPolygon &rPolyPolygon) const override
Definition: svdotext.cxx:1585
static bool TryRunningState(const css::uno::Reference< css::embed::XEmbeddedObject > &)
virtual void NbcSetSnapRect(const tools::Rectangle &rRect) override
Definition: svdorect.cxx:295
A SdrPage contains exactly one SdrObjList and a description of the physical page dimensions (size / m...
Definition: svdpage.hxx:366
void InsertObj(SdrOle2Obj *pObj)
Definition: svdetc.cxx:171
void SetAspect(sal_Int64 nAspect)
Definition: svdoole2.cxx:765
bool IsInDestruction() const
Definition: svdmodel.hxx:589
virtual void SetChanged()
Definition: svdobj.cxx:956
virtual SdrObjectUniquePtr getFullDragClone() const override
Definition: svdoole2.cxx:1309
OUString aPersistName
Definition: svdoole2.cxx:612
#define SO3_SC_OLE_EMBED_CLASSID_60
const Fraction & GetScaleHeight() const
#define SO3_SM_CLASSID_30
void Lock(bool bLock=true)
sal_Int32 nState
SVX_DLLPUBLIC size_t size() const
Definition: svdetc.cxx:207
#define SO3_SC_OLE_EMBED_CLASSID_8
css::awt::Rectangle AWTRectangle(const ::tools::Rectangle &rVCLRect)
css::uno::Reference< css::frame::XModel > GetParentXModel() const
Definition: svdoole2.cxx:1886
const OUString & GetProgName() const
Definition: svdoole2.cxx:812
SfxLinkUpdateMode
const Graphic * GetGraphic() const
Definition: svdoole2.cxx:1660
bool UpdateLinkURL_Impl()
Definition: svdoole2.cxx:839
SVX_DLLPRIVATE SdrObjectUniquePtr createSdrGrafObjReplacement(bool bAddText) const
Definition: svdoole2.cxx:1173
bool IsEmptyPresObj() const
Definition: svdobj.hxx:880