1*bfd08df8SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*bfd08df8SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*bfd08df8SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*bfd08df8SAndrew Rist * distributed with this work for additional information 6*bfd08df8SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*bfd08df8SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*bfd08df8SAndrew Rist * "License"); you may not use this file except in compliance 9*bfd08df8SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*bfd08df8SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*bfd08df8SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*bfd08df8SAndrew Rist * software distributed under the License is distributed on an 15*bfd08df8SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*bfd08df8SAndrew Rist * KIND, either express or implied. See the License for the 17*bfd08df8SAndrew Rist * specific language governing permissions and limitations 18*bfd08df8SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*bfd08df8SAndrew Rist *************************************************************/ 21*bfd08df8SAndrew Rist 22*bfd08df8SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_embeddedobj.hxx" 26cdf0e10cSrcweir #include <com/sun/star/embed/EmbedStates.hpp> 27cdf0e10cSrcweir #include <com/sun/star/embed/EmbedVerbs.hpp> 28cdf0e10cSrcweir #include <com/sun/star/embed/EmbedUpdateModes.hpp> 29cdf0e10cSrcweir #include <com/sun/star/embed/XEmbeddedClient.hpp> 30cdf0e10cSrcweir #include <com/sun/star/embed/XInplaceClient.hpp> 31cdf0e10cSrcweir #include <com/sun/star/embed/XWindowSupplier.hpp> 32cdf0e10cSrcweir #include <com/sun/star/embed/StateChangeInProgressException.hpp> 33cdf0e10cSrcweir #include <com/sun/star/embed/Aspects.hpp> 34cdf0e10cSrcweir 35cdf0e10cSrcweir #include <com/sun/star/awt/XWindowPeer.hpp> 36cdf0e10cSrcweir #include <com/sun/star/util/XCloseBroadcaster.hpp> 37cdf0e10cSrcweir #include <com/sun/star/util/XCloseable.hpp> 38cdf0e10cSrcweir #include <com/sun/star/util/XModifiable.hpp> 39cdf0e10cSrcweir #include <com/sun/star/frame/XFrame.hpp> 40cdf0e10cSrcweir #include <com/sun/star/frame/XComponentLoader.hpp> 41cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProviderInterception.hpp> 42cdf0e10cSrcweir #include <com/sun/star/frame/XModuleManager.hpp> 43cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp> 44cdf0e10cSrcweir 45cdf0e10cSrcweir #include <com/sun/star/embed/EmbedMisc.hpp> 46cdf0e10cSrcweir 47cdf0e10cSrcweir #include <rtl/logfile.hxx> 48cdf0e10cSrcweir 49cdf0e10cSrcweir #include <targetstatecontrol.hxx> 50cdf0e10cSrcweir 51cdf0e10cSrcweir #include "commonembobj.hxx" 52cdf0e10cSrcweir #include "intercept.hxx" 53cdf0e10cSrcweir 54cdf0e10cSrcweir 55cdf0e10cSrcweir using namespace ::com::sun::star; 56cdf0e10cSrcweir 57cdf0e10cSrcweir awt::Rectangle GetRectangleInterception( const awt::Rectangle& aRect1, const awt::Rectangle& aRect2 ) 58cdf0e10cSrcweir { 59cdf0e10cSrcweir awt::Rectangle aResult; 60cdf0e10cSrcweir 61cdf0e10cSrcweir OSL_ENSURE( aRect1.Width >= 0 && aRect2.Width >= 0 && aRect1.Height >= 0 && aRect2.Height >= 0, 62cdf0e10cSrcweir "Offset must not be less then zero!" ); 63cdf0e10cSrcweir 64cdf0e10cSrcweir aResult.X = aRect1.X > aRect2.X ? aRect1.X : aRect2.X; 65cdf0e10cSrcweir aResult.Y = aRect1.Y > aRect2.Y ? aRect1.Y : aRect2.Y; 66cdf0e10cSrcweir 67cdf0e10cSrcweir sal_Int32 nRight1 = aRect1.X + aRect1.Width; 68cdf0e10cSrcweir sal_Int32 nBottom1 = aRect1.Y + aRect1.Height; 69cdf0e10cSrcweir sal_Int32 nRight2 = aRect2.X + aRect2.Width; 70cdf0e10cSrcweir sal_Int32 nBottom2 = aRect2.Y + aRect2.Height; 71cdf0e10cSrcweir aResult.Width = ( nRight1 < nRight2 ? nRight1 : nRight2 ) - aResult.X; 72cdf0e10cSrcweir aResult.Height = ( nBottom1 < nBottom2 ? nBottom1 : nBottom2 ) - aResult.Y; 73cdf0e10cSrcweir 74cdf0e10cSrcweir return aResult; 75cdf0e10cSrcweir } 76cdf0e10cSrcweir 77cdf0e10cSrcweir //---------------------------------------------- 78cdf0e10cSrcweir sal_Int32 OCommonEmbeddedObject::ConvertVerbToState_Impl( sal_Int32 nVerb ) 79cdf0e10cSrcweir { 80cdf0e10cSrcweir for ( sal_Int32 nInd = 0; nInd < m_aVerbTable.getLength(); nInd++ ) 81cdf0e10cSrcweir if ( m_aVerbTable[nInd][0] == nVerb ) 82cdf0e10cSrcweir return m_aVerbTable[nInd][1]; 83cdf0e10cSrcweir 84cdf0e10cSrcweir throw lang::IllegalArgumentException(); // TODO: unexpected verb provided 85cdf0e10cSrcweir } 86cdf0e10cSrcweir 87cdf0e10cSrcweir //---------------------------------------------- 88cdf0e10cSrcweir void OCommonEmbeddedObject::Deactivate() 89cdf0e10cSrcweir { 90cdf0e10cSrcweir uno::Reference< util::XModifiable > xModif( m_pDocHolder->GetComponent(), uno::UNO_QUERY ); 91cdf0e10cSrcweir //MBA if ( !xModif.is() ) 92cdf0e10cSrcweir //MBA throw uno::RuntimeException(); 93cdf0e10cSrcweir 94cdf0e10cSrcweir // no need to lock for the initialization 95cdf0e10cSrcweir uno::Reference< embed::XEmbeddedClient > xClientSite = m_xClientSite; 96cdf0e10cSrcweir if ( !xClientSite.is() ) 97cdf0e10cSrcweir throw embed::WrongStateException(); //TODO: client site is not set! 98cdf0e10cSrcweir 99cdf0e10cSrcweir // store document if it is modified 100cdf0e10cSrcweir if ( xModif.is() && xModif->isModified() ) 101cdf0e10cSrcweir { 102cdf0e10cSrcweir try { 103cdf0e10cSrcweir xClientSite->saveObject(); 104cdf0e10cSrcweir } 105cdf0e10cSrcweir catch( embed::ObjectSaveVetoException& ) 106cdf0e10cSrcweir { 107cdf0e10cSrcweir } 108cdf0e10cSrcweir catch( uno::Exception& e ) 109cdf0e10cSrcweir { 110cdf0e10cSrcweir throw embed::StorageWrappedTargetException( 111cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "The client could not store the object!" ), 112cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >( this ) ), 113cdf0e10cSrcweir uno::makeAny( e ) ); 114cdf0e10cSrcweir } 115cdf0e10cSrcweir } 116cdf0e10cSrcweir 117cdf0e10cSrcweir m_pDocHolder->CloseFrame(); 118cdf0e10cSrcweir 119cdf0e10cSrcweir xClientSite->visibilityChanged( sal_False ); 120cdf0e10cSrcweir } 121cdf0e10cSrcweir 122cdf0e10cSrcweir //---------------------------------------------- 123cdf0e10cSrcweir void OCommonEmbeddedObject::StateChangeNotification_Impl( sal_Bool bBeforeChange, sal_Int32 nOldState, sal_Int32 nNewState ,::osl::ResettableMutexGuard& rGuard ) 124cdf0e10cSrcweir { 125cdf0e10cSrcweir if ( m_pInterfaceContainer ) 126cdf0e10cSrcweir { 127cdf0e10cSrcweir ::cppu::OInterfaceContainerHelper* pContainer = m_pInterfaceContainer->getContainer( 128cdf0e10cSrcweir ::getCppuType( ( const uno::Reference< embed::XStateChangeListener >*) NULL ) ); 129cdf0e10cSrcweir if ( pContainer != NULL ) 130cdf0e10cSrcweir { 131cdf0e10cSrcweir lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >( this ) ); 132cdf0e10cSrcweir ::cppu::OInterfaceIteratorHelper pIterator(*pContainer); 133cdf0e10cSrcweir 134cdf0e10cSrcweir // should be locked after the method is finished successfully 135cdf0e10cSrcweir rGuard.clear(); 136cdf0e10cSrcweir 137cdf0e10cSrcweir while (pIterator.hasMoreElements()) 138cdf0e10cSrcweir { 139cdf0e10cSrcweir try 140cdf0e10cSrcweir { 141cdf0e10cSrcweir if ( bBeforeChange ) 142cdf0e10cSrcweir ((embed::XStateChangeListener*)pIterator.next())->changingState( aSource, nOldState, nNewState ); 143cdf0e10cSrcweir else 144cdf0e10cSrcweir ((embed::XStateChangeListener*)pIterator.next())->stateChanged( aSource, nOldState, nNewState ); 145cdf0e10cSrcweir } 146cdf0e10cSrcweir catch( uno::Exception& ) 147cdf0e10cSrcweir { 148cdf0e10cSrcweir // even if the listener complains ignore it for now 149cdf0e10cSrcweir } 150cdf0e10cSrcweir 151cdf0e10cSrcweir if ( m_bDisposed ) 152cdf0e10cSrcweir return; 153cdf0e10cSrcweir } 154cdf0e10cSrcweir 155cdf0e10cSrcweir rGuard.reset(); 156cdf0e10cSrcweir } 157cdf0e10cSrcweir } 158cdf0e10cSrcweir } 159cdf0e10cSrcweir 160cdf0e10cSrcweir //---------------------------------------------- 161cdf0e10cSrcweir void OCommonEmbeddedObject::SwitchStateTo_Impl( sal_Int32 nNextState ) 162cdf0e10cSrcweir { 163cdf0e10cSrcweir // TODO: may be needs interaction handler to detect wherether the object state 164cdf0e10cSrcweir // can be changed even after errors 165cdf0e10cSrcweir 166cdf0e10cSrcweir if ( m_nObjectState == embed::EmbedStates::LOADED ) 167cdf0e10cSrcweir { 168cdf0e10cSrcweir if ( nNextState == embed::EmbedStates::RUNNING ) 169cdf0e10cSrcweir { 170cdf0e10cSrcweir // after the object reaches the running state the cloned size is not necessary any more 171cdf0e10cSrcweir m_bHasClonedSize = sal_False; 172cdf0e10cSrcweir 173cdf0e10cSrcweir if ( m_bIsLink ) 174cdf0e10cSrcweir { 175cdf0e10cSrcweir m_pDocHolder->SetComponent( LoadLink_Impl(), m_bReadOnly ); 176cdf0e10cSrcweir } 177cdf0e10cSrcweir else 178cdf0e10cSrcweir { 179cdf0e10cSrcweir uno::Reference < embed::XEmbedPersist > xPersist( static_cast < embed::XClassifiedObject* > (this), uno::UNO_QUERY ); 180cdf0e10cSrcweir if ( xPersist.is() ) 181cdf0e10cSrcweir { 182cdf0e10cSrcweir // in case embedded object is in loaded state the contents must 183cdf0e10cSrcweir // be stored in the related storage and the storage 184cdf0e10cSrcweir // must be created already 185cdf0e10cSrcweir if ( !m_xObjectStorage.is() ) 186cdf0e10cSrcweir throw io::IOException(); //TODO: access denied 187cdf0e10cSrcweir 188cdf0e10cSrcweir m_pDocHolder->SetComponent( LoadDocumentFromStorage_Impl(), m_bReadOnly ); 189cdf0e10cSrcweir } 190cdf0e10cSrcweir else 191cdf0e10cSrcweir { 192cdf0e10cSrcweir // objects without persistence will be initialized internally 193cdf0e10cSrcweir uno::Sequence < uno::Any > aArgs(1); 194cdf0e10cSrcweir aArgs[0] <<= uno::Reference < embed::XEmbeddedObject >( this ); 195cdf0e10cSrcweir uno::Reference< util::XCloseable > xDocument( 196cdf0e10cSrcweir m_xFactory->createInstanceWithArguments( GetDocumentServiceName(), aArgs ), uno::UNO_QUERY ); 197cdf0e10cSrcweir 198cdf0e10cSrcweir uno::Reference < container::XChild > xChild( xDocument, uno::UNO_QUERY ); 199cdf0e10cSrcweir if ( xChild.is() ) 200cdf0e10cSrcweir xChild->setParent( m_xParent ); 201cdf0e10cSrcweir 202cdf0e10cSrcweir m_pDocHolder->SetComponent( xDocument, m_bReadOnly ); 203cdf0e10cSrcweir } 204cdf0e10cSrcweir } 205cdf0e10cSrcweir 206cdf0e10cSrcweir if ( !m_pDocHolder->GetComponent().is() ) 207cdf0e10cSrcweir throw embed::UnreachableStateException(); //TODO: can't open document 208cdf0e10cSrcweir 209cdf0e10cSrcweir m_nObjectState = nNextState; 210cdf0e10cSrcweir } 211cdf0e10cSrcweir else 212cdf0e10cSrcweir { 213cdf0e10cSrcweir OSL_ENSURE( sal_False, "Unacceptable state switch!\n" ); 214cdf0e10cSrcweir throw uno::RuntimeException(); // TODO 215cdf0e10cSrcweir } 216cdf0e10cSrcweir } 217cdf0e10cSrcweir else if ( m_nObjectState == embed::EmbedStates::RUNNING ) 218cdf0e10cSrcweir { 219cdf0e10cSrcweir if ( nNextState == embed::EmbedStates::LOADED ) 220cdf0e10cSrcweir { 221cdf0e10cSrcweir m_nClonedMapUnit = m_pDocHolder->GetMapUnit( embed::Aspects::MSOLE_CONTENT ); 222cdf0e10cSrcweir m_bHasClonedSize = m_pDocHolder->GetExtent( embed::Aspects::MSOLE_CONTENT, &m_aClonedSize ); 223cdf0e10cSrcweir 224cdf0e10cSrcweir // actually frame should not exist at this point 225cdf0e10cSrcweir m_pDocHolder->CloseDocument( sal_False, sal_False ); 226cdf0e10cSrcweir 227cdf0e10cSrcweir m_nObjectState = nNextState; 228cdf0e10cSrcweir } 229cdf0e10cSrcweir else 230cdf0e10cSrcweir { 231cdf0e10cSrcweir if ( nNextState == embed::EmbedStates::INPLACE_ACTIVE ) 232cdf0e10cSrcweir { 233cdf0e10cSrcweir if ( !m_xClientSite.is() ) 234cdf0e10cSrcweir throw embed::WrongStateException( 235cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "client site not set, yet" ) ), 236cdf0e10cSrcweir *this 237cdf0e10cSrcweir ); 238cdf0e10cSrcweir 239cdf0e10cSrcweir uno::Reference< embed::XInplaceClient > xInplaceClient( m_xClientSite, uno::UNO_QUERY ); 240cdf0e10cSrcweir if ( xInplaceClient.is() && xInplaceClient->canInplaceActivate() ) 241cdf0e10cSrcweir { 242cdf0e10cSrcweir xInplaceClient->activatingInplace(); 243cdf0e10cSrcweir 244cdf0e10cSrcweir uno::Reference< embed::XWindowSupplier > xClientWindowSupplier( xInplaceClient, uno::UNO_QUERY ); 245cdf0e10cSrcweir if ( !xClientWindowSupplier.is() ) 246cdf0e10cSrcweir throw uno::RuntimeException(); // TODO: the inplace client implementation must support XWinSupp 247cdf0e10cSrcweir 248cdf0e10cSrcweir m_xClientWindow = xClientWindowSupplier->getWindow(); 249cdf0e10cSrcweir m_aOwnRectangle = xInplaceClient->getPlacement(); 250cdf0e10cSrcweir m_aClipRectangle = xInplaceClient->getClipRectangle(); 251cdf0e10cSrcweir awt::Rectangle aRectangleToShow = GetRectangleInterception( m_aOwnRectangle, m_aClipRectangle ); 252cdf0e10cSrcweir 253cdf0e10cSrcweir // create own window based on the client window 254cdf0e10cSrcweir // place and resize the window according to the rectangles 255cdf0e10cSrcweir uno::Reference< awt::XWindowPeer > xClientWindowPeer( m_xClientWindow, uno::UNO_QUERY ); 256cdf0e10cSrcweir if ( !xClientWindowPeer.is() ) 257cdf0e10cSrcweir throw uno::RuntimeException(); // TODO: the container window must support the interface 258cdf0e10cSrcweir 259cdf0e10cSrcweir // dispatch provider may not be provided 260cdf0e10cSrcweir uno::Reference< frame::XDispatchProvider > xContainerDP = xInplaceClient->getInplaceDispatchProvider(); 261cdf0e10cSrcweir sal_Bool bOk = m_pDocHolder->ShowInplace( xClientWindowPeer, aRectangleToShow, xContainerDP ); 262cdf0e10cSrcweir m_nObjectState = nNextState; 263cdf0e10cSrcweir if ( !bOk ) 264cdf0e10cSrcweir { 265cdf0e10cSrcweir SwitchStateTo_Impl( embed::EmbedStates::RUNNING ); 266cdf0e10cSrcweir throw embed::WrongStateException(); //TODO: can't activate inplace 267cdf0e10cSrcweir } 268cdf0e10cSrcweir } 269cdf0e10cSrcweir else 270cdf0e10cSrcweir throw embed::WrongStateException(); //TODO: can't activate inplace 271cdf0e10cSrcweir } 272cdf0e10cSrcweir else if ( nNextState == embed::EmbedStates::ACTIVE ) 273cdf0e10cSrcweir { 274cdf0e10cSrcweir if ( !m_xClientSite.is() ) 275cdf0e10cSrcweir throw embed::WrongStateException(); //TODO: client site is not set! 276cdf0e10cSrcweir 277cdf0e10cSrcweir // create frame and load document in the frame 278cdf0e10cSrcweir m_pDocHolder->Show(); 279cdf0e10cSrcweir 280cdf0e10cSrcweir m_xClientSite->visibilityChanged( sal_True ); 281cdf0e10cSrcweir m_nObjectState = nNextState; 282cdf0e10cSrcweir } 283cdf0e10cSrcweir else 284cdf0e10cSrcweir { 285cdf0e10cSrcweir OSL_ENSURE( sal_False, "Unacceptable state switch!\n" ); 286cdf0e10cSrcweir throw uno::RuntimeException(); // TODO 287cdf0e10cSrcweir } 288cdf0e10cSrcweir } 289cdf0e10cSrcweir } 290cdf0e10cSrcweir else if ( m_nObjectState == embed::EmbedStates::INPLACE_ACTIVE ) 291cdf0e10cSrcweir { 292cdf0e10cSrcweir if ( nNextState == embed::EmbedStates::RUNNING ) 293cdf0e10cSrcweir { 294cdf0e10cSrcweir uno::Reference< embed::XInplaceClient > xInplaceClient( m_xClientSite, uno::UNO_QUERY ); 295cdf0e10cSrcweir if ( !xInplaceClient.is() ) 296cdf0e10cSrcweir throw uno::RuntimeException(); 297cdf0e10cSrcweir 298cdf0e10cSrcweir m_xClientSite->visibilityChanged( sal_True ); 299cdf0e10cSrcweir 300cdf0e10cSrcweir xInplaceClient->deactivatedInplace(); 301cdf0e10cSrcweir Deactivate(); 302cdf0e10cSrcweir m_nObjectState = nNextState; 303cdf0e10cSrcweir } 304cdf0e10cSrcweir else if ( nNextState == embed::EmbedStates::UI_ACTIVE ) 305cdf0e10cSrcweir { 306cdf0e10cSrcweir if ( !(m_nMiscStatus & embed::EmbedMisc::MS_EMBED_NOUIACTIVATE) ) 307cdf0e10cSrcweir { 308cdf0e10cSrcweir uno::Reference< embed::XInplaceClient > xInplaceClient( m_xClientSite, uno::UNO_QUERY_THROW ); 309cdf0e10cSrcweir // TODO: 310cdf0e10cSrcweir uno::Reference< ::com::sun::star::frame::XLayoutManager > xContainerLM = 311cdf0e10cSrcweir xInplaceClient->getLayoutManager(); 312cdf0e10cSrcweir if ( xContainerLM.is() ) 313cdf0e10cSrcweir { 314cdf0e10cSrcweir // dispatch provider may not be provided 315cdf0e10cSrcweir uno::Reference< frame::XDispatchProvider > xContainerDP = xInplaceClient->getInplaceDispatchProvider(); 316cdf0e10cSrcweir 317cdf0e10cSrcweir // get the container module name 318cdf0e10cSrcweir ::rtl::OUString aModuleName; 319cdf0e10cSrcweir try 320cdf0e10cSrcweir { 321cdf0e10cSrcweir uno::Reference< embed::XComponentSupplier > xCompSupl( m_xClientSite, uno::UNO_QUERY_THROW ); 322cdf0e10cSrcweir uno::Reference< uno::XInterface > xContDoc( xCompSupl->getComponent(), uno::UNO_QUERY_THROW ); 323cdf0e10cSrcweir 324cdf0e10cSrcweir uno::Reference< frame::XModuleManager > xManager( 325cdf0e10cSrcweir m_xFactory->createInstance( 326cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.ModuleManager" ) ) ), 327cdf0e10cSrcweir uno::UNO_QUERY_THROW ); 328cdf0e10cSrcweir 329cdf0e10cSrcweir aModuleName = xManager->identify( xContDoc ); 330cdf0e10cSrcweir } 331cdf0e10cSrcweir catch( uno::Exception& ) 332cdf0e10cSrcweir {} 333cdf0e10cSrcweir 334cdf0e10cSrcweir // if currently another object is UIactive it will be deactivated; usually this will activate the LM of 335cdf0e10cSrcweir // the container. Locking the LM will prevent flicker. 336cdf0e10cSrcweir xContainerLM->lock(); 337cdf0e10cSrcweir xInplaceClient->activatingUI(); 338cdf0e10cSrcweir sal_Bool bOk = m_pDocHolder->ShowUI( xContainerLM, xContainerDP, aModuleName ); 339cdf0e10cSrcweir xContainerLM->unlock(); 340cdf0e10cSrcweir 341cdf0e10cSrcweir if ( bOk ) 342cdf0e10cSrcweir { 343cdf0e10cSrcweir m_nObjectState = nNextState; 344cdf0e10cSrcweir m_pDocHolder->ResizeHatchWindow(); 345cdf0e10cSrcweir } 346cdf0e10cSrcweir else 347cdf0e10cSrcweir { 348cdf0e10cSrcweir xInplaceClient->deactivatedUI(); 349cdf0e10cSrcweir throw embed::WrongStateException(); //TODO: can't activate UI 350cdf0e10cSrcweir } 351cdf0e10cSrcweir } 352cdf0e10cSrcweir else 353cdf0e10cSrcweir throw embed::WrongStateException(); //TODO: can't activate UI 354cdf0e10cSrcweir } 355cdf0e10cSrcweir } 356cdf0e10cSrcweir else 357cdf0e10cSrcweir { 358cdf0e10cSrcweir OSL_ENSURE( sal_False, "Unacceptable state switch!\n" ); 359cdf0e10cSrcweir throw uno::RuntimeException(); // TODO 360cdf0e10cSrcweir } 361cdf0e10cSrcweir } 362cdf0e10cSrcweir else if ( m_nObjectState == embed::EmbedStates::ACTIVE ) 363cdf0e10cSrcweir { 364cdf0e10cSrcweir if ( nNextState == embed::EmbedStates::RUNNING ) 365cdf0e10cSrcweir { 366cdf0e10cSrcweir Deactivate(); 367cdf0e10cSrcweir m_nObjectState = nNextState; 368cdf0e10cSrcweir } 369cdf0e10cSrcweir else 370cdf0e10cSrcweir { 371cdf0e10cSrcweir OSL_ENSURE( sal_False, "Unacceptable state switch!\n" ); 372cdf0e10cSrcweir throw uno::RuntimeException(); // TODO 373cdf0e10cSrcweir } 374cdf0e10cSrcweir } 375cdf0e10cSrcweir else if ( m_nObjectState == embed::EmbedStates::UI_ACTIVE ) 376cdf0e10cSrcweir { 377cdf0e10cSrcweir if ( nNextState == embed::EmbedStates::INPLACE_ACTIVE ) 378cdf0e10cSrcweir { 379cdf0e10cSrcweir uno::Reference< embed::XInplaceClient > xInplaceClient( m_xClientSite, uno::UNO_QUERY_THROW ); 380cdf0e10cSrcweir uno::Reference< ::com::sun::star::frame::XLayoutManager > xContainerLM = 381cdf0e10cSrcweir xInplaceClient->getLayoutManager(); 382cdf0e10cSrcweir 383cdf0e10cSrcweir sal_Bool bOk = sal_False; 384cdf0e10cSrcweir if ( xContainerLM.is() ) 385cdf0e10cSrcweir bOk = m_pDocHolder->HideUI( xContainerLM ); 386cdf0e10cSrcweir 387cdf0e10cSrcweir if ( bOk ) 388cdf0e10cSrcweir { 389cdf0e10cSrcweir m_nObjectState = nNextState; 390cdf0e10cSrcweir m_pDocHolder->ResizeHatchWindow(); 391cdf0e10cSrcweir xInplaceClient->deactivatedUI(); 392cdf0e10cSrcweir } 393cdf0e10cSrcweir else 394cdf0e10cSrcweir throw embed::WrongStateException(); //TODO: can't activate UI 395cdf0e10cSrcweir } 396cdf0e10cSrcweir } 397cdf0e10cSrcweir else 398cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object is in unacceptable state!\n" ), 399cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 400cdf0e10cSrcweir } 401cdf0e10cSrcweir 402cdf0e10cSrcweir //---------------------------------------------- 403cdf0e10cSrcweir uno::Sequence< sal_Int32 > OCommonEmbeddedObject::GetIntermediateStatesSequence_Impl( sal_Int32 nNewState ) 404cdf0e10cSrcweir { 405cdf0e10cSrcweir sal_Int32 nCurInd = 0; 406cdf0e10cSrcweir for ( nCurInd = 0; nCurInd < m_aAcceptedStates.getLength(); nCurInd++ ) 407cdf0e10cSrcweir if ( m_aAcceptedStates[nCurInd] == m_nObjectState ) 408cdf0e10cSrcweir break; 409cdf0e10cSrcweir 410cdf0e10cSrcweir if ( nCurInd == m_aAcceptedStates.getLength() ) 411cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object is in unacceptable state!\n" ), 412cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 413cdf0e10cSrcweir 414cdf0e10cSrcweir sal_Int32 nDestInd = 0; 415cdf0e10cSrcweir for ( nDestInd = 0; nDestInd < m_aAcceptedStates.getLength(); nDestInd++ ) 416cdf0e10cSrcweir if ( m_aAcceptedStates[nDestInd] == nNewState ) 417cdf0e10cSrcweir break; 418cdf0e10cSrcweir 419cdf0e10cSrcweir if ( nDestInd == m_aAcceptedStates.getLength() ) 420cdf0e10cSrcweir throw embed::UnreachableStateException( 421cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "The state either not reachable, or the object allows the state only as an intermediate one!\n" ), 422cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ), 423cdf0e10cSrcweir m_nObjectState, 424cdf0e10cSrcweir nNewState ); 425cdf0e10cSrcweir 426cdf0e10cSrcweir return m_pIntermediateStatesSeqs[nCurInd][nDestInd]; 427cdf0e10cSrcweir } 428cdf0e10cSrcweir 429cdf0e10cSrcweir //---------------------------------------------- 430cdf0e10cSrcweir void SAL_CALL OCommonEmbeddedObject::changeState( sal_Int32 nNewState ) 431cdf0e10cSrcweir throw ( embed::UnreachableStateException, 432cdf0e10cSrcweir embed::WrongStateException, 433cdf0e10cSrcweir uno::Exception, 434cdf0e10cSrcweir uno::RuntimeException ) 435cdf0e10cSrcweir { 436cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OCommonEmbeddedObject::changeState" ); 437cdf0e10cSrcweir 438cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >( this ), uno::UNO_QUERY); 439cdf0e10cSrcweir { 440cdf0e10cSrcweir ::osl::ResettableMutexGuard aGuard( m_aMutex ); 441cdf0e10cSrcweir if ( m_bDisposed ) 442cdf0e10cSrcweir throw lang::DisposedException(); // TODO 443cdf0e10cSrcweir 444cdf0e10cSrcweir if ( m_nObjectState == -1 ) 445cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ), 446cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 447cdf0e10cSrcweir 448cdf0e10cSrcweir sal_Int32 nOldState = m_nObjectState; 449cdf0e10cSrcweir 450cdf0e10cSrcweir if ( m_nTargetState != -1 ) 451cdf0e10cSrcweir { 452cdf0e10cSrcweir // means that the object is currently trying to reach the target state 453cdf0e10cSrcweir throw embed::StateChangeInProgressException( ::rtl::OUString(), 454cdf0e10cSrcweir uno::Reference< uno::XInterface >(), 455cdf0e10cSrcweir m_nTargetState ); 456cdf0e10cSrcweir } 457cdf0e10cSrcweir else 458cdf0e10cSrcweir { 459cdf0e10cSrcweir TargetStateControl_Impl aControl( m_nTargetState, nNewState ); 460cdf0e10cSrcweir 461cdf0e10cSrcweir // in case the object is already in requested state 462cdf0e10cSrcweir if ( m_nObjectState == nNewState ) 463cdf0e10cSrcweir { 464cdf0e10cSrcweir // if active object is activated again, bring it's window to top 465cdf0e10cSrcweir if ( m_nObjectState == embed::EmbedStates::ACTIVE ) 466cdf0e10cSrcweir m_pDocHolder->Show(); 467cdf0e10cSrcweir 468cdf0e10cSrcweir return; 469cdf0e10cSrcweir } 470cdf0e10cSrcweir 471cdf0e10cSrcweir // retrieve sequence of states that should be passed to reach desired state 472cdf0e10cSrcweir uno::Sequence< sal_Int32 > aIntermediateStates = GetIntermediateStatesSequence_Impl( nNewState ); 473cdf0e10cSrcweir 474cdf0e10cSrcweir // notify listeners that the object is going to change the state 475cdf0e10cSrcweir StateChangeNotification_Impl( sal_True, nOldState, nNewState,aGuard ); 476cdf0e10cSrcweir 477cdf0e10cSrcweir try { 478cdf0e10cSrcweir for ( sal_Int32 nInd = 0; nInd < aIntermediateStates.getLength(); nInd++ ) 479cdf0e10cSrcweir SwitchStateTo_Impl( aIntermediateStates[nInd] ); 480cdf0e10cSrcweir 481cdf0e10cSrcweir SwitchStateTo_Impl( nNewState ); 482cdf0e10cSrcweir } 483cdf0e10cSrcweir catch( uno::Exception& ) 484cdf0e10cSrcweir { 485cdf0e10cSrcweir if ( nOldState != m_nObjectState ) 486cdf0e10cSrcweir // notify listeners that the object has changed the state 487cdf0e10cSrcweir StateChangeNotification_Impl( sal_False, nOldState, m_nObjectState, aGuard ); 488cdf0e10cSrcweir 489cdf0e10cSrcweir throw; 490cdf0e10cSrcweir } 491cdf0e10cSrcweir } 492cdf0e10cSrcweir 493cdf0e10cSrcweir // notify listeners that the object has changed the state 494cdf0e10cSrcweir StateChangeNotification_Impl( sal_False, nOldState, nNewState, aGuard ); 495cdf0e10cSrcweir 496cdf0e10cSrcweir // let the object window be shown 497cdf0e10cSrcweir if ( nNewState == embed::EmbedStates::UI_ACTIVE || nNewState == embed::EmbedStates::INPLACE_ACTIVE ) 498cdf0e10cSrcweir PostEvent_Impl( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnVisAreaChanged" ) ), 499cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 500cdf0e10cSrcweir } 501cdf0e10cSrcweir } 502cdf0e10cSrcweir 503cdf0e10cSrcweir //---------------------------------------------- 504cdf0e10cSrcweir uno::Sequence< sal_Int32 > SAL_CALL OCommonEmbeddedObject::getReachableStates() 505cdf0e10cSrcweir throw ( embed::WrongStateException, 506cdf0e10cSrcweir uno::RuntimeException ) 507cdf0e10cSrcweir { 508cdf0e10cSrcweir if ( m_bDisposed ) 509cdf0e10cSrcweir throw lang::DisposedException(); // TODO 510cdf0e10cSrcweir 511cdf0e10cSrcweir if ( m_nObjectState == -1 ) 512cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ), 513cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 514cdf0e10cSrcweir 515cdf0e10cSrcweir return m_aAcceptedStates; 516cdf0e10cSrcweir } 517cdf0e10cSrcweir 518cdf0e10cSrcweir //---------------------------------------------- 519cdf0e10cSrcweir sal_Int32 SAL_CALL OCommonEmbeddedObject::getCurrentState() 520cdf0e10cSrcweir throw ( embed::WrongStateException, 521cdf0e10cSrcweir uno::RuntimeException ) 522cdf0e10cSrcweir { 523cdf0e10cSrcweir if ( m_bDisposed ) 524cdf0e10cSrcweir throw lang::DisposedException(); // TODO 525cdf0e10cSrcweir 526cdf0e10cSrcweir if ( m_nObjectState == -1 ) 527cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ), 528cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 529cdf0e10cSrcweir 530cdf0e10cSrcweir return m_nObjectState; 531cdf0e10cSrcweir } 532cdf0e10cSrcweir 533cdf0e10cSrcweir //---------------------------------------------- 534cdf0e10cSrcweir void SAL_CALL OCommonEmbeddedObject::doVerb( sal_Int32 nVerbID ) 535cdf0e10cSrcweir throw ( lang::IllegalArgumentException, 536cdf0e10cSrcweir embed::WrongStateException, 537cdf0e10cSrcweir embed::UnreachableStateException, 538cdf0e10cSrcweir uno::Exception, 539cdf0e10cSrcweir uno::RuntimeException ) 540cdf0e10cSrcweir { 541cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OCommonEmbeddedObject::doVerb" ); 542cdf0e10cSrcweir 543cdf0e10cSrcweir ::osl::ResettableMutexGuard aGuard( m_aMutex ); 544cdf0e10cSrcweir if ( m_bDisposed ) 545cdf0e10cSrcweir throw lang::DisposedException(); // TODO 546cdf0e10cSrcweir 547cdf0e10cSrcweir if ( m_nObjectState == -1 ) 548cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ), 549cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 550cdf0e10cSrcweir 551cdf0e10cSrcweir // for internal documents this call is just a duplicate of changeState 552cdf0e10cSrcweir sal_Int32 nNewState = -1; 553cdf0e10cSrcweir try 554cdf0e10cSrcweir { 555cdf0e10cSrcweir nNewState = ConvertVerbToState_Impl( nVerbID ); 556cdf0e10cSrcweir } 557cdf0e10cSrcweir catch( uno::Exception& ) 558cdf0e10cSrcweir {} 559cdf0e10cSrcweir 560cdf0e10cSrcweir if ( nNewState == -1 ) 561cdf0e10cSrcweir { 562cdf0e10cSrcweir // TODO/LATER: Save Copy as... verb ( -8 ) is implemented by container 563cdf0e10cSrcweir // TODO/LATER: check if the verb is a supported one and if it is produce related operation 564cdf0e10cSrcweir } 565cdf0e10cSrcweir else 566cdf0e10cSrcweir { 567cdf0e10cSrcweir aGuard.clear(); 568cdf0e10cSrcweir changeState( nNewState ); 569cdf0e10cSrcweir } 570cdf0e10cSrcweir } 571cdf0e10cSrcweir 572cdf0e10cSrcweir //---------------------------------------------- 573cdf0e10cSrcweir uno::Sequence< embed::VerbDescriptor > SAL_CALL OCommonEmbeddedObject::getSupportedVerbs() 574cdf0e10cSrcweir throw ( embed::WrongStateException, 575cdf0e10cSrcweir uno::RuntimeException ) 576cdf0e10cSrcweir { 577cdf0e10cSrcweir if ( m_bDisposed ) 578cdf0e10cSrcweir throw lang::DisposedException(); // TODO 579cdf0e10cSrcweir 580cdf0e10cSrcweir if ( m_nObjectState == -1 ) 581cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ), 582cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 583cdf0e10cSrcweir 584cdf0e10cSrcweir return m_aObjectVerbs; 585cdf0e10cSrcweir } 586cdf0e10cSrcweir 587cdf0e10cSrcweir //---------------------------------------------- 588cdf0e10cSrcweir void SAL_CALL OCommonEmbeddedObject::setClientSite( 589cdf0e10cSrcweir const uno::Reference< embed::XEmbeddedClient >& xClient ) 590cdf0e10cSrcweir throw ( embed::WrongStateException, 591cdf0e10cSrcweir uno::RuntimeException ) 592cdf0e10cSrcweir { 593cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 594cdf0e10cSrcweir if ( m_bDisposed ) 595cdf0e10cSrcweir throw lang::DisposedException(); // TODO 596cdf0e10cSrcweir 597cdf0e10cSrcweir if ( m_xClientSite != xClient) 598cdf0e10cSrcweir { 599cdf0e10cSrcweir if ( m_nObjectState != embed::EmbedStates::LOADED && m_nObjectState != embed::EmbedStates::RUNNING ) 600cdf0e10cSrcweir throw embed::WrongStateException( 601cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "The client site can not be set currently!\n" ), 602cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 603cdf0e10cSrcweir 604cdf0e10cSrcweir m_xClientSite = xClient; 605cdf0e10cSrcweir } 606cdf0e10cSrcweir } 607cdf0e10cSrcweir 608cdf0e10cSrcweir //---------------------------------------------- 609cdf0e10cSrcweir uno::Reference< embed::XEmbeddedClient > SAL_CALL OCommonEmbeddedObject::getClientSite() 610cdf0e10cSrcweir throw ( embed::WrongStateException, 611cdf0e10cSrcweir uno::RuntimeException ) 612cdf0e10cSrcweir { 613cdf0e10cSrcweir if ( m_bDisposed ) 614cdf0e10cSrcweir throw lang::DisposedException(); // TODO 615cdf0e10cSrcweir 616cdf0e10cSrcweir if ( m_nObjectState == -1 ) 617cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ), 618cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 619cdf0e10cSrcweir 620cdf0e10cSrcweir return m_xClientSite; 621cdf0e10cSrcweir } 622cdf0e10cSrcweir 623cdf0e10cSrcweir //---------------------------------------------- 624cdf0e10cSrcweir void SAL_CALL OCommonEmbeddedObject::update() 625cdf0e10cSrcweir throw ( embed::WrongStateException, 626cdf0e10cSrcweir uno::Exception, 627cdf0e10cSrcweir uno::RuntimeException ) 628cdf0e10cSrcweir { 629cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 630cdf0e10cSrcweir if ( m_bDisposed ) 631cdf0e10cSrcweir throw lang::DisposedException(); // TODO 632cdf0e10cSrcweir 633cdf0e10cSrcweir if ( m_nObjectState == -1 ) 634cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ), 635cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 636cdf0e10cSrcweir 637cdf0e10cSrcweir PostEvent_Impl( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnVisAreaChanged" ) ), 638cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 639cdf0e10cSrcweir } 640cdf0e10cSrcweir 641cdf0e10cSrcweir //---------------------------------------------- 642cdf0e10cSrcweir void SAL_CALL OCommonEmbeddedObject::setUpdateMode( sal_Int32 nMode ) 643cdf0e10cSrcweir throw ( embed::WrongStateException, 644cdf0e10cSrcweir uno::RuntimeException ) 645cdf0e10cSrcweir { 646cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 647cdf0e10cSrcweir if ( m_bDisposed ) 648cdf0e10cSrcweir throw lang::DisposedException(); // TODO 649cdf0e10cSrcweir 650cdf0e10cSrcweir if ( m_nObjectState == -1 ) 651cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ), 652cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 653cdf0e10cSrcweir 654cdf0e10cSrcweir OSL_ENSURE( nMode == embed::EmbedUpdateModes::ALWAYS_UPDATE 655cdf0e10cSrcweir || nMode == embed::EmbedUpdateModes::EXPLICIT_UPDATE, 656cdf0e10cSrcweir "Unknown update mode!\n" ); 657cdf0e10cSrcweir m_nUpdateMode = nMode; 658cdf0e10cSrcweir } 659cdf0e10cSrcweir 660cdf0e10cSrcweir //---------------------------------------------- 661cdf0e10cSrcweir sal_Int64 SAL_CALL OCommonEmbeddedObject::getStatus( sal_Int64 ) 662cdf0e10cSrcweir throw ( embed::WrongStateException, 663cdf0e10cSrcweir uno::RuntimeException ) 664cdf0e10cSrcweir { 665cdf0e10cSrcweir if ( m_bDisposed ) 666cdf0e10cSrcweir throw lang::DisposedException(); // TODO 667cdf0e10cSrcweir 668cdf0e10cSrcweir return m_nMiscStatus; 669cdf0e10cSrcweir } 670cdf0e10cSrcweir 671cdf0e10cSrcweir //---------------------------------------------- 672cdf0e10cSrcweir void SAL_CALL OCommonEmbeddedObject::setContainerName( const ::rtl::OUString& sName ) 673cdf0e10cSrcweir throw ( uno::RuntimeException ) 674cdf0e10cSrcweir { 675cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 676cdf0e10cSrcweir if ( m_bDisposed ) 677cdf0e10cSrcweir throw lang::DisposedException(); // TODO 678cdf0e10cSrcweir 679cdf0e10cSrcweir m_aContainerName = sName; 680cdf0e10cSrcweir } 681cdf0e10cSrcweir 682cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::uno::XInterface > SAL_CALL OCommonEmbeddedObject::getParent() throw (::com::sun::star::uno::RuntimeException) 683cdf0e10cSrcweir { 684cdf0e10cSrcweir return m_xParent; 685cdf0e10cSrcweir } 686cdf0e10cSrcweir 687cdf0e10cSrcweir void SAL_CALL OCommonEmbeddedObject::setParent( const com::sun::star::uno::Reference< com::sun::star::uno::XInterface >& xParent ) throw (::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException) 688cdf0e10cSrcweir { 689cdf0e10cSrcweir m_xParent = xParent; 690cdf0e10cSrcweir if ( m_nObjectState != -1 && m_nObjectState != embed::EmbedStates::LOADED ) 691cdf0e10cSrcweir { 692cdf0e10cSrcweir uno::Reference < container::XChild > xChild( m_pDocHolder->GetComponent(), uno::UNO_QUERY ); 693cdf0e10cSrcweir if ( xChild.is() ) 694cdf0e10cSrcweir xChild->setParent( xParent ); 695cdf0e10cSrcweir } 696cdf0e10cSrcweir } 697cdf0e10cSrcweir 698cdf0e10cSrcweir // XDefaultSizeTransmitter 699cdf0e10cSrcweir void SAL_CALL OCommonEmbeddedObject::setDefaultSize( const ::com::sun::star::awt::Size& rSize_100TH_MM ) throw (::com::sun::star::uno::RuntimeException) 700cdf0e10cSrcweir { 701cdf0e10cSrcweir //#i103460# charts do not necessaryly have an own size within ODF files, in this case they need to use the size settings from the surrounding frame, which is made available with this method 702cdf0e10cSrcweir m_aDefaultSizeForChart_In_100TH_MM = rSize_100TH_MM; 703cdf0e10cSrcweir } 704