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