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