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_sfx2.hxx" 26 27 //________________________________________________________________________________________________________ 28 // my own includes 29 //________________________________________________________________________________________________________ 30 31 #include <sfx2/sfxbasemodel.hxx> 32 33 //________________________________________________________________________________________________________ 34 // include of other projects 35 //________________________________________________________________________________________________________ 36 37 #include <com/sun/star/task/XInteractionHandler.hpp> 38 #include <com/sun/star/task/ErrorCodeRequest.hpp> 39 #include <com/sun/star/view/XSelectionSupplier.hpp> 40 #include <com/sun/star/view/XPrintJobListener.hpp> 41 #include <com/sun/star/lang/DisposedException.hpp> 42 #include <com/sun/star/lang/IllegalArgumentException.hpp> 43 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> 44 #include <com/sun/star/frame/IllegalArgumentIOException.hpp> 45 #include <com/sun/star/frame/XUntitledNumbers.hpp> 46 #include <com/sun/star/frame/UntitledNumbersConst.hpp> 47 #include <com/sun/star/embed/XTransactionBroadcaster.hpp> 48 #include <com/sun/star/embed/XStorage.hpp> 49 #include <com/sun/star/embed/EmbedMapUnits.hpp> 50 #include <com/sun/star/document/XStorageChangeListener.hpp> 51 #include <com/sun/star/document/XActionLockable.hpp> 52 #include <com/sun/star/beans/XPropertySet.hpp> 53 #include <com/sun/star/container/XIndexContainer.hpp> 54 #include <com/sun/star/script/provider/XScriptProviderFactory.hpp> 55 #include <com/sun/star/script/provider/XScriptProvider.hpp> 56 #include <com/sun/star/ui/XUIConfigurationStorage.hpp> 57 #include <com/sun/star/ui/XUIConfigurationPersistence.hpp> 58 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> 59 #include <com/sun/star/embed/ElementModes.hpp> 60 #include <com/sun/star/embed/Aspects.hpp> 61 #include <com/sun/star/document/XDocumentProperties.hpp> 62 #include <com/sun/star/frame/XTransientDocumentsDocumentContentFactory.hpp> 63 #include <comphelper/enumhelper.hxx> // can be removed when this is a "real" service 64 65 #include <cppuhelper/interfacecontainer.hxx> 66 #include <cppuhelper/exc_hlp.hxx> 67 #include <comphelper/processfactory.hxx> // can be removed when this is a "real" service 68 #include <comphelper/componentcontext.hxx> 69 #include <comphelper/namedvaluecollection.hxx> 70 #include <svl/itemset.hxx> 71 #include <svl/stritem.hxx> 72 #include <svl/eitem.hxx> 73 #include <svl/intitem.hxx> 74 #include <basic/sbx.hxx> 75 #include <basic/sbuno.hxx> 76 #include <tools/urlobj.hxx> 77 #include <tools/diagnose_ex.h> 78 #include <unotools/tempfile.hxx> 79 #include <vos/mutex.hxx> 80 #include <vcl/salctype.hxx> 81 #include <sot/clsids.hxx> 82 #include <sot/storinfo.hxx> 83 #include <comphelper/storagehelper.hxx> 84 #include <toolkit/helper/vclunohelper.hxx> 85 #include <svtools/transfer.hxx> 86 #include <svtools/ehdl.hxx> 87 #include <svtools/sfxecode.hxx> 88 #include <rtl/logfile.hxx> 89 #include <framework/configimporter.hxx> 90 #include <framework/interaction.hxx> 91 #include <framework/titlehelper.hxx> 92 #include <comphelper/numberedcollection.hxx> 93 #include <unotools/ucbstreamhelper.hxx> 94 #include <unotools/ucbhelper.hxx> 95 96 //________________________________________________________________________________________________________ 97 // includes of my own project 98 //________________________________________________________________________________________________________ 99 100 #include <sfx2/sfxbasecontroller.hxx> 101 #include "sfx2/viewfac.hxx" 102 #include "workwin.hxx" 103 #include <sfx2/signaturestate.hxx> 104 #include <sfx2/sfxuno.hxx> 105 #include <objshimp.hxx> 106 #include <sfx2/viewfrm.hxx> 107 #include <sfx2/viewsh.hxx> 108 #include <sfx2/docfile.hxx> 109 #include <sfx2/dispatch.hxx> 110 #include <sfx2/request.hxx> 111 #include <sfx2/objuno.hxx> 112 #include <sfx2/printer.hxx> 113 #include <sfx2/basmgr.hxx> 114 #include <sfx2/event.hxx> 115 #include <eventsupplier.hxx> 116 #include <sfx2/evntconf.hxx> 117 #include <sfx2/sfx.hrc> 118 #include <sfx2/app.hxx> 119 #include <sfx2/viewfrm.hxx> 120 #include "appdata.hxx" 121 #include <sfx2/docfac.hxx> 122 #include <sfx2/fcontnr.hxx> 123 #include "sfx2/docstoragemodifylistener.hxx" 124 #include "sfx2/brokenpackageint.hxx" 125 #include "graphhelp.hxx" 126 #include "docundomanager.hxx" 127 #include <sfx2/msgpool.hxx> 128 #include <sfx2/DocumentMetadataAccess.hxx> 129 130 #include <sfx2/sfxresid.hxx> 131 132 //________________________________________________________________________________________________________ 133 // const 134 static const ::rtl::OUString SERVICENAME_DESKTOP = ::rtl::OUString::createFromAscii ("com.sun.star.frame.Desktop"); 135 136 //________________________________________________________________________________________________________ 137 // namespaces 138 //________________________________________________________________________________________________________ 139 140 namespace css = ::com::sun::star; 141 using namespace ::com::sun::star; 142 using namespace ::com::sun::star::uno; 143 using ::com::sun::star::beans::PropertyValue; 144 using ::com::sun::star::frame::XFrame; 145 using ::com::sun::star::frame::XController; 146 using ::com::sun::star::frame::XController2; 147 using ::com::sun::star::lang::IllegalArgumentException; 148 using ::com::sun::star::io::IOException; 149 using ::com::sun::star::lang::WrappedTargetException; 150 using ::com::sun::star::uno::Type; 151 using ::com::sun::star::uno::Sequence; 152 using ::com::sun::star::document::XDocumentRecovery; 153 using ::com::sun::star::document::XUndoManager; 154 using ::com::sun::star::document::XUndoAction; 155 using ::com::sun::star::document::UndoFailedException; 156 using ::com::sun::star::frame::XModel; 157 158 /** This Listener is used to get notified when the XDocumentProperties of the 159 XModel change. 160 */ 161 class SfxDocInfoListener_Impl : public ::cppu::WeakImplHelper1< 162 ::com::sun::star::util::XModifyListener > 163 { 164 165 public: 166 SfxObjectShell& m_rShell; 167 168 SfxDocInfoListener_Impl( SfxObjectShell& i_rDoc ) 169 : m_rShell(i_rDoc) 170 { }; 171 172 ~SfxDocInfoListener_Impl(); 173 174 virtual void SAL_CALL disposing( const lang::EventObject& ) 175 throw ( uno::RuntimeException ); 176 virtual void SAL_CALL modified( const lang::EventObject& ) 177 throw ( uno::RuntimeException ); 178 }; 179 SfxDocInfoListener_Impl::~SfxDocInfoListener_Impl() 180 { 181 } 182 void SAL_CALL SfxDocInfoListener_Impl::modified( const lang::EventObject& ) 183 throw ( uno::RuntimeException ) 184 { 185 ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 186 187 // notify changes to the SfxObjectShell 188 m_rShell.FlushDocInfo(); 189 } 190 191 void SAL_CALL SfxDocInfoListener_Impl::disposing( const lang::EventObject& ) 192 throw ( uno::RuntimeException ) 193 { 194 } 195 196 //________________________________________________________________________________________________________ 197 // impl. declarations 198 //________________________________________________________________________________________________________ 199 200 201 struct IMPL_SfxBaseModel_DataContainer : public ::sfx2::IModifiableDocument 202 { 203 // counter for SfxBaseModel instances created. 204 static sal_Int64 g_nInstanceCounter ; 205 SfxObjectShellRef m_pObjectShell ; 206 ::rtl::OUString m_sURL ; 207 ::rtl::OUString m_sRuntimeUID ; 208 ::rtl::OUString m_aPreusedFilterName; 209 ::cppu::OMultiTypeInterfaceContainerHelper m_aInterfaceContainer ; 210 uno::Reference< uno::XInterface > m_xParent ; 211 uno::Reference< frame::XController > m_xCurrent ; 212 uno::Reference< document::XDocumentInfo > m_xDocumentInfo ; 213 uno::Reference< document::XDocumentProperties > m_xDocumentProperties; 214 uno::Reference< script::XStarBasicAccess > m_xStarBasicAccess ; 215 uno::Reference< container::XNameReplace > m_xEvents ; 216 uno::Sequence< beans::PropertyValue> m_seqArguments ; 217 uno::Sequence< uno::Reference< frame::XController > > m_seqControllers ; 218 uno::Reference< container::XIndexAccess > m_contViewData ; 219 sal_uInt16 m_nControllerLockCount ; 220 sal_Bool m_bClosed ; 221 sal_Bool m_bClosing ; 222 sal_Bool m_bSaving ; 223 sal_Bool m_bSuicide ; 224 sal_Bool m_bInitialized ; 225 sal_Bool m_bExternalTitle ; 226 sal_Bool m_bModifiedSinceLastSave; 227 uno::Reference< com::sun::star::view::XPrintable> m_xPrintable ; 228 uno::Reference< script::provider::XScriptProvider > m_xScriptProvider; 229 uno::Reference< ui::XUIConfigurationManager > m_xUIConfigurationManager; 230 ::rtl::Reference< ::sfx2::DocumentStorageModifyListener > m_pStorageModifyListen; 231 ::rtl::OUString m_sModuleIdentifier; 232 css::uno::Reference< css::frame::XTitle > m_xTitleHelper; 233 css::uno::Reference< css::frame::XUntitledNumbers > m_xNumberedControllers; 234 uno::Reference< rdf::XDocumentMetadataAccess> m_xDocumentMetadata; 235 ::rtl::Reference< ::sfx2::DocumentUndoManager > m_pDocumentUndoManager; 236 237 238 IMPL_SfxBaseModel_DataContainer( ::osl::Mutex& rMutex, SfxObjectShell* pObjectShell ) 239 : m_pObjectShell ( pObjectShell ) 240 , m_aInterfaceContainer ( rMutex ) 241 , m_nControllerLockCount ( 0 ) 242 , m_bClosed ( sal_False ) 243 , m_bClosing ( sal_False ) 244 , m_bSaving ( sal_False ) 245 , m_bSuicide ( sal_False ) 246 , m_bInitialized ( sal_False ) 247 , m_bExternalTitle ( sal_False ) 248 , m_bModifiedSinceLastSave( sal_False ) 249 , m_pStorageModifyListen ( NULL ) 250 , m_xTitleHelper () 251 , m_xNumberedControllers () 252 , m_xDocumentMetadata () // lazy 253 , m_pDocumentUndoManager () 254 { 255 // increase global instance counter. 256 ++g_nInstanceCounter; 257 // set own Runtime UID 258 m_sRuntimeUID = rtl::OUString::valueOf( g_nInstanceCounter ); 259 } 260 261 virtual ~IMPL_SfxBaseModel_DataContainer() 262 { 263 } 264 265 // ::sfx2::IModifiableDocument 266 virtual void storageIsModified() 267 { 268 if ( m_pObjectShell.Is() && !m_pObjectShell->IsModified() ) 269 m_pObjectShell->SetModified( sal_True ); 270 } 271 272 uno::Reference<rdf::XDocumentMetadataAccess> GetDMA() 273 { 274 if (!m_xDocumentMetadata.is()) 275 { 276 OSL_ENSURE(m_pObjectShell, "GetDMA: no object shell?"); 277 if (!m_pObjectShell) 278 { 279 return 0; 280 } 281 282 const uno::Reference<uno::XComponentContext> xContext( 283 ::comphelper::getProcessComponentContext()); 284 ::rtl::OUString uri; 285 const uno::Reference<frame::XModel> xModel( 286 m_pObjectShell->GetModel()); 287 const uno::Reference<lang::XMultiComponentFactory> xMsf( 288 xContext->getServiceManager()); 289 const uno::Reference<frame:: 290 XTransientDocumentsDocumentContentFactory> xTDDCF( 291 xMsf->createInstanceWithContext( 292 ::rtl::OUString::createFromAscii( "com.sun.star.frame." 293 "TransientDocumentsDocumentContentFactory"), 294 xContext), 295 uno::UNO_QUERY_THROW); 296 const uno::Reference<ucb::XContent> xContent( 297 xTDDCF->createDocumentContent(xModel) ); 298 OSL_ENSURE(xContent.is(), "GetDMA: cannot create DocumentContent"); 299 if (!xContent.is()) 300 { 301 return 0; 302 } 303 uri = xContent->getIdentifier()->getContentIdentifier(); 304 OSL_ENSURE(uri.getLength(), "GetDMA: empty uri?"); 305 if (uri.getLength() && !uri.endsWithAsciiL("/", 1)) 306 { 307 uri = uri + ::rtl::OUString::createFromAscii("/"); 308 } 309 310 m_xDocumentMetadata = new ::sfx2::DocumentMetadataAccess( 311 xContext, *m_pObjectShell, uri); 312 } 313 return m_xDocumentMetadata; 314 } 315 316 uno::Reference<rdf::XDocumentMetadataAccess> CreateDMAUninitialized() 317 { 318 return (m_pObjectShell) 319 ? new ::sfx2::DocumentMetadataAccess( 320 ::comphelper::getProcessComponentContext(), *m_pObjectShell) 321 : 0; 322 } 323 }; 324 325 // static member initialization. 326 sal_Int64 IMPL_SfxBaseModel_DataContainer::g_nInstanceCounter = 0; 327 328 // ======================================================================================================= 329 330 // Listener that forwards notifications from the PrintHelper to the "real" listeners 331 class SfxPrintHelperListener_Impl : public ::cppu::WeakImplHelper1< ::com::sun::star::view::XPrintJobListener > 332 { 333 public: 334 IMPL_SfxBaseModel_DataContainer* m_pData; 335 SfxPrintHelperListener_Impl( IMPL_SfxBaseModel_DataContainer* pData ) 336 : m_pData( pData ) 337 {} 338 339 virtual void SAL_CALL disposing( const lang::EventObject& aEvent ) throw ( uno::RuntimeException ) ; 340 virtual void SAL_CALL printJobEvent( const view::PrintJobEvent& rEvent ) throw ( uno::RuntimeException); 341 }; 342 343 void SAL_CALL SfxPrintHelperListener_Impl::disposing( const lang::EventObject& ) throw ( uno::RuntimeException ) 344 { 345 m_pData->m_xPrintable = 0; 346 } 347 348 void SAL_CALL SfxPrintHelperListener_Impl::printJobEvent( const view::PrintJobEvent& rEvent ) throw (uno::RuntimeException) 349 { 350 ::cppu::OInterfaceContainerHelper* pContainer = m_pData->m_aInterfaceContainer.getContainer( ::getCppuType( ( const uno::Reference< view::XPrintJobListener >*) NULL ) ); 351 if ( pContainer!=NULL ) 352 { 353 ::cppu::OInterfaceIteratorHelper pIterator(*pContainer); 354 while (pIterator.hasMoreElements()) 355 ((view::XPrintJobListener*)pIterator.next())->printJobEvent( rEvent ); 356 } 357 } 358 359 // SfxOwnFramesLocker ==================================================================================== 360 // allows to lock all the frames related to the provided SfxObjectShell 361 class SfxOwnFramesLocker 362 { 363 uno::Sequence< uno::Reference< frame::XFrame > > m_aLockedFrames; 364 365 Window* GetVCLWindow( const uno::Reference< frame::XFrame >& xFrame ); 366 public: 367 SfxOwnFramesLocker( SfxObjectShell* ObjechShell ); 368 ~SfxOwnFramesLocker(); 369 void UnlockFrames(); 370 }; 371 372 SfxOwnFramesLocker::SfxOwnFramesLocker( SfxObjectShell* pObjectShell ) 373 { 374 if ( !pObjectShell ) 375 return; 376 377 for ( SfxViewFrame *pFrame = SfxViewFrame::GetFirst( pObjectShell ); 378 pFrame; 379 pFrame = SfxViewFrame::GetNext( *pFrame, pObjectShell ) 380 ) 381 { 382 SfxFrame& rSfxFrame = pFrame->GetFrame(); 383 try 384 { 385 // get vcl window related to the frame and lock it if it is still not locked 386 uno::Reference< frame::XFrame > xFrame = rSfxFrame.GetFrameInterface(); 387 Window* pWindow = GetVCLWindow( xFrame ); 388 if ( !pWindow ) 389 throw uno::RuntimeException(); 390 391 if ( pWindow->IsEnabled() ) 392 { 393 pWindow->Disable(); 394 395 try 396 { 397 sal_Int32 nLen = m_aLockedFrames.getLength(); 398 m_aLockedFrames.realloc( nLen + 1 ); 399 m_aLockedFrames[nLen] = xFrame; 400 } 401 catch( uno::Exception& ) 402 { 403 pWindow->Enable(); 404 throw; 405 } 406 } 407 } 408 catch( uno::Exception& ) 409 { 410 OSL_ENSURE( sal_False, "Not possible to lock the frame window!\n" ); 411 } 412 } 413 } 414 415 SfxOwnFramesLocker::~SfxOwnFramesLocker() 416 { 417 UnlockFrames(); 418 } 419 420 Window* SfxOwnFramesLocker::GetVCLWindow( const uno::Reference< frame::XFrame >& xFrame ) 421 { 422 Window* pWindow = NULL; 423 424 if ( xFrame.is() ) 425 { 426 uno::Reference< awt::XWindow > xWindow = xFrame->getContainerWindow(); 427 if ( xWindow.is() ) 428 pWindow = VCLUnoHelper::GetWindow( xWindow ); 429 } 430 431 return pWindow; 432 } 433 434 void SfxOwnFramesLocker::UnlockFrames() 435 { 436 for ( sal_Int32 nInd = 0; nInd < m_aLockedFrames.getLength(); nInd++ ) 437 { 438 try 439 { 440 if ( m_aLockedFrames[nInd].is() ) 441 { 442 // get vcl window related to the frame and unlock it 443 Window* pWindow = GetVCLWindow( m_aLockedFrames[nInd] ); 444 if ( !pWindow ) 445 throw uno::RuntimeException(); 446 447 pWindow->Enable(); 448 449 m_aLockedFrames[nInd] = uno::Reference< frame::XFrame >(); 450 } 451 } 452 catch( uno::Exception& ) 453 { 454 OSL_ENSURE( sal_False, "Can't unlock the frame window!\n" ); 455 } 456 } 457 } 458 459 // SfxSaveGuard ==================================================================================== 460 class SfxSaveGuard 461 { 462 private: 463 uno::Reference< frame::XModel > m_xModel; 464 IMPL_SfxBaseModel_DataContainer* m_pData; 465 SfxOwnFramesLocker* m_pFramesLock; 466 467 public: 468 SfxSaveGuard(const uno::Reference< frame::XModel >& xModel , 469 IMPL_SfxBaseModel_DataContainer* pData , 470 sal_Bool bRejectConcurrentSaveRequest); 471 ~SfxSaveGuard(); 472 }; 473 474 SfxSaveGuard::SfxSaveGuard(const uno::Reference< frame::XModel >& xModel , 475 IMPL_SfxBaseModel_DataContainer* pData , 476 sal_Bool bRejectConcurrentSaveRequest) 477 : m_xModel (xModel) 478 , m_pData (pData ) 479 , m_pFramesLock(0 ) 480 { 481 static ::rtl::OUString MSG_1 = ::rtl::OUString::createFromAscii("Object already disposed." ); 482 static ::rtl::OUString MSG_2 = ::rtl::OUString::createFromAscii("Concurrent save requests on the same document are not possible."); 483 484 if ( m_pData->m_bClosed ) 485 throw ::com::sun::star::lang::DisposedException( 486 MSG_1, 487 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >()); 488 489 if ( 490 bRejectConcurrentSaveRequest && 491 m_pData->m_bSaving 492 ) 493 throw ::com::sun::star::io::IOException( 494 MSG_2, 495 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >()); 496 497 m_pData->m_bSaving = sal_True; 498 m_pFramesLock = new SfxOwnFramesLocker(m_pData->m_pObjectShell); 499 } 500 501 SfxSaveGuard::~SfxSaveGuard() 502 { 503 SfxOwnFramesLocker* pFramesLock = m_pFramesLock; 504 m_pFramesLock = 0; 505 delete pFramesLock; 506 507 m_pData->m_bSaving = sal_False; 508 509 // m_bSuicide was set e.g. in case somewhere tried to close a document, while it was used for 510 // storing at the same time. Further m_bSuicide was set to sal_True only if close(sal_True) was called. 511 // So the owner ship was delegated to the place where a veto exception was thrown. 512 // Now we have to call close() again and delegate the owner ship to the next one, which 513 // cant accept that. Close(sal_False) cant work in this case. Because then the document will may be never closed ... 514 515 if ( m_pData->m_bSuicide ) 516 { 517 // Reset this state. In case the new close() request is not accepted by somehwere else ... 518 // it's not a good idea to have two "owners" for close .-) 519 m_pData->m_bSuicide = sal_False; 520 try 521 { 522 uno::Reference< util::XCloseable > xClose(m_xModel, uno::UNO_QUERY); 523 if (xClose.is()) 524 xClose->close(sal_True); 525 } 526 catch(const util::CloseVetoException&) 527 {} 528 } 529 } 530 531 // ======================================================================================================= 532 533 //________________________________________________________________________________________________________ 534 // constructor 535 //________________________________________________________________________________________________________ 536 DBG_NAME(sfx2_SfxBaseModel) 537 SfxBaseModel::SfxBaseModel( SfxObjectShell *pObjectShell ) 538 : BaseMutex() 539 , m_pData( new IMPL_SfxBaseModel_DataContainer( m_aMutex, pObjectShell ) ) 540 , m_bSupportEmbeddedScripts( pObjectShell && pObjectShell->Get_Impl() ? !pObjectShell->Get_Impl()->m_bNoBasicCapabilities : false ) 541 , m_bSupportDocRecovery( pObjectShell && pObjectShell->Get_Impl() ? pObjectShell->Get_Impl()->m_bDocRecoverySupport : false ) 542 { 543 DBG_CTOR(sfx2_SfxBaseModel,NULL); 544 if ( pObjectShell != NULL ) 545 { 546 StartListening( *pObjectShell ) ; 547 } 548 } 549 550 //________________________________________________________________________________________________________ 551 // destructor 552 //________________________________________________________________________________________________________ 553 554 SfxBaseModel::~SfxBaseModel() 555 { 556 DBG_DTOR(sfx2_SfxBaseModel,NULL); 557 } 558 559 //________________________________________________________________________________________________________ 560 // XInterface 561 //________________________________________________________________________________________________________ 562 563 uno::Any SAL_CALL SfxBaseModel::queryInterface( const UNOTYPE& rType ) throw( uno::RuntimeException ) 564 { 565 if ( ( !m_bSupportEmbeddedScripts && rType.equals( XEMBEDDEDSCRIPTS::static_type() ) ) 566 || ( !m_bSupportDocRecovery && rType.equals( XDocumentRecovery::static_type() ) ) 567 ) 568 return Any(); 569 570 return SfxBaseModel_Base::queryInterface( rType ); 571 } 572 573 //________________________________________________________________________________________________________ 574 // XInterface 575 //________________________________________________________________________________________________________ 576 577 void SAL_CALL SfxBaseModel::acquire() throw( ) 578 { 579 // Attention: 580 // Don't use mutex or guard in this method!!! Is a method of XInterface. 581 582 // Forward to baseclass 583 OWeakObject::acquire() ; 584 } 585 586 //________________________________________________________________________________________________________ 587 // XInterface 588 //________________________________________________________________________________________________________ 589 590 void SAL_CALL SfxBaseModel::release() throw( ) 591 { 592 // Attention: 593 // Don't use mutex or guard in this method!!! Is a method of XInterface. 594 595 // Forward to baseclass 596 OWeakObject::release() ; 597 } 598 599 //________________________________________________________________________________________________________ 600 // XTypeProvider 601 //________________________________________________________________________________________________________ 602 603 namespace 604 { 605 void lcl_stripType( Sequence< Type >& io_rTypes, const Type& i_rTypeToStrip ) 606 { 607 Sequence< UNOTYPE > aStrippedTypes( io_rTypes.getLength() - 1 ); 608 ::std::remove_copy_if( 609 io_rTypes.getConstArray(), 610 io_rTypes.getConstArray() + io_rTypes.getLength(), 611 aStrippedTypes.getArray(), 612 ::std::bind2nd( ::std::equal_to< Type >(), i_rTypeToStrip ) 613 ); 614 io_rTypes = aStrippedTypes; 615 } 616 } 617 618 uno::Sequence< UNOTYPE > SAL_CALL SfxBaseModel::getTypes() throw( uno::RuntimeException ) 619 { 620 uno::Sequence< UNOTYPE > aTypes( SfxBaseModel_Base::getTypes() ); 621 622 if ( !m_bSupportEmbeddedScripts ) 623 lcl_stripType( aTypes, XEMBEDDEDSCRIPTS::static_type() ); 624 625 if ( !m_bSupportDocRecovery ) 626 lcl_stripType( aTypes, XDocumentRecovery::static_type() ); 627 628 return aTypes; 629 } 630 631 //________________________________________________________________________________________________________ 632 // XTypeProvider 633 //________________________________________________________________________________________________________ 634 635 uno::Sequence< sal_Int8 > SAL_CALL SfxBaseModel::getImplementationId() throw( uno::RuntimeException ) 636 { 637 // Create one Id for all instances of this class. 638 // Use ethernet address to do this! (sal_True) 639 640 // Optimize this method 641 // We initialize a static variable only one time. And we don't must use a mutex at every call! 642 // For the first call; pID is NULL - for the second call pID is different from NULL! 643 static ::cppu::OImplementationId* pID = NULL ; 644 645 if ( pID == NULL ) 646 { 647 // Ready for multithreading; get global mutex for first call of this method only! see before 648 ::osl::MutexGuard aGuard( MUTEX::getGlobalMutex() ) ; 649 650 // Control these pointer again ... it can be, that another instance will be faster then these! 651 if ( pID == NULL ) 652 { 653 // Create a new static ID ... 654 static ::cppu::OImplementationId aID( sal_False ) ; 655 // ... and set his address to static pointer! 656 pID = &aID ; 657 } 658 } 659 660 return pID->getImplementationId() ; 661 } 662 663 //________________________________________________________________________________________________________ 664 // XStarBasicAccess 665 //________________________________________________________________________________________________________ 666 667 uno::Reference< script::XStarBasicAccess > implGetStarBasicAccess( SfxObjectShell* pObjectShell ) 668 { 669 uno::Reference< script::XStarBasicAccess > xRet; 670 if( pObjectShell ) 671 { 672 BasicManager* pMgr = pObjectShell->GetBasicManager(); 673 xRet = getStarBasicAccess( pMgr ); 674 } 675 return xRet; 676 } 677 678 uno::Reference< XNAMECONTAINER > SAL_CALL SfxBaseModel::getLibraryContainer() throw( uno::RuntimeException ) 679 { 680 SfxModelGuard aGuard( *this ); 681 682 uno::Reference< script::XStarBasicAccess >& rxAccess = m_pData->m_xStarBasicAccess; 683 if( !rxAccess.is() && m_pData->m_pObjectShell.Is() ) 684 rxAccess = implGetStarBasicAccess( m_pData->m_pObjectShell ); 685 686 uno::Reference< XNAMECONTAINER > xRet; 687 if( rxAccess.is() ) 688 xRet = rxAccess->getLibraryContainer(); 689 return xRet; 690 } 691 692 /**___________________________________________________________________________________________________ 693 @seealso XStarBasicAccess 694 */ 695 void SAL_CALL SfxBaseModel::createLibrary( const ::rtl::OUString& LibName, const ::rtl::OUString& Password, 696 const ::rtl::OUString& ExternalSourceURL, const ::rtl::OUString& LinkTargetURL ) 697 throw(ELEMENTEXISTEXCEPTION, uno::RuntimeException) 698 { 699 SfxModelGuard aGuard( *this ); 700 701 uno::Reference< script::XStarBasicAccess >& rxAccess = m_pData->m_xStarBasicAccess; 702 if( !rxAccess.is() && m_pData->m_pObjectShell.Is() ) 703 rxAccess = implGetStarBasicAccess( m_pData->m_pObjectShell ); 704 705 if( rxAccess.is() ) 706 rxAccess->createLibrary( LibName, Password, ExternalSourceURL, LinkTargetURL ); 707 } 708 709 /**___________________________________________________________________________________________________ 710 @seealso XStarBasicAccess 711 */ 712 void SAL_CALL SfxBaseModel::addModule( const ::rtl::OUString& LibraryName, const ::rtl::OUString& ModuleName, 713 const ::rtl::OUString& Language, const ::rtl::OUString& Source ) 714 throw( NOSUCHELEMENTEXCEPTION, uno::RuntimeException) 715 { 716 SfxModelGuard aGuard( *this ); 717 718 uno::Reference< script::XStarBasicAccess >& rxAccess = m_pData->m_xStarBasicAccess; 719 if( !rxAccess.is() && m_pData->m_pObjectShell.Is() ) 720 rxAccess = implGetStarBasicAccess( m_pData->m_pObjectShell ); 721 722 if( rxAccess.is() ) 723 rxAccess->addModule( LibraryName, ModuleName, Language, Source ); 724 } 725 726 /**___________________________________________________________________________________________________ 727 @seealso XStarBasicAccess 728 */ 729 void SAL_CALL SfxBaseModel::addDialog( const ::rtl::OUString& LibraryName, const ::rtl::OUString& DialogName, 730 const ::com::sun::star::uno::Sequence< sal_Int8 >& Data ) 731 throw(NOSUCHELEMENTEXCEPTION, uno::RuntimeException) 732 { 733 SfxModelGuard aGuard( *this ); 734 735 uno::Reference< script::XStarBasicAccess >& rxAccess = m_pData->m_xStarBasicAccess; 736 if( !rxAccess.is() && m_pData->m_pObjectShell.Is() ) 737 rxAccess = implGetStarBasicAccess( m_pData->m_pObjectShell ); 738 739 if( rxAccess.is() ) 740 rxAccess->addDialog( LibraryName, DialogName, Data ); 741 } 742 743 744 //________________________________________________________________________________________________________ 745 // XChild 746 //________________________________________________________________________________________________________ 747 748 uno::Reference< uno::XInterface > SAL_CALL SfxBaseModel::getParent() throw( uno::RuntimeException ) 749 { 750 SfxModelGuard aGuard( *this ); 751 752 return m_pData->m_xParent; 753 } 754 755 //________________________________________________________________________________________________________ 756 // XChild 757 //________________________________________________________________________________________________________ 758 759 void SAL_CALL SfxBaseModel::setParent(const uno::Reference< uno::XInterface >& Parent) throw(NOSUPPORTEXCEPTION, uno::RuntimeException) 760 { 761 SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING ); 762 m_pData->m_xParent = Parent; 763 } 764 765 //________________________________________________________________________________________________________ 766 // XChild 767 //________________________________________________________________________________________________________ 768 769 void SAL_CALL SfxBaseModel::dispose() throw(::com::sun::star::uno::RuntimeException) 770 { 771 SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING ); 772 773 if ( !m_pData->m_bClosed ) 774 { 775 // gracefully accept wrong dispose calls instead of close call 776 // and try to make it work (may be really disposed later!) 777 try 778 { 779 close( sal_True ); 780 } 781 catch ( com::sun::star::util::CloseVetoException& ) 782 { 783 } 784 785 return; 786 } 787 788 if ( m_pData->m_pStorageModifyListen.is() ) 789 { 790 m_pData->m_pStorageModifyListen->dispose(); 791 m_pData->m_pStorageModifyListen = NULL; 792 } 793 794 if ( m_pData->m_pDocumentUndoManager.is() ) 795 { 796 m_pData->m_pDocumentUndoManager->disposing(); 797 m_pData->m_pDocumentUndoManager = NULL; 798 } 799 800 lang::EventObject aEvent( (frame::XModel *)this ); 801 m_pData->m_aInterfaceContainer.disposeAndClear( aEvent ); 802 803 if ( m_pData->m_xDocumentInfo.is() ) 804 { 805 // as long as an SfxObjectShell is assigned to an SfxBaseModel it is still existing here 806 // so we can't dispose the shared DocumentInfoObject here 807 // uno::Reference < lang::XComponent > xComp( m_pData->m_xDocumentInfo, uno::UNO_QUERY ); 808 // xComp->dispose(); 809 m_pData->m_xDocumentInfo = 0; 810 } 811 812 m_pData->m_xDocumentProperties.clear(); 813 814 m_pData->m_xDocumentMetadata.clear(); 815 816 EndListening( *m_pData->m_pObjectShell ); 817 818 m_pData->m_xCurrent = uno::Reference< frame::XController > (); 819 m_pData->m_seqControllers = uno::Sequence< uno::Reference< frame::XController > > () ; 820 821 // m_pData member must be set to zero before 0delete is called to 822 // force disposed exception whenever someone tries to access our 823 // instance while in the dtor. 824 IMPL_SfxBaseModel_DataContainer* pData = m_pData; 825 m_pData = 0; 826 delete pData; 827 } 828 829 //________________________________________________________________________________________________________ 830 // XChild 831 //________________________________________________________________________________________________________ 832 833 void SAL_CALL SfxBaseModel::addEventListener( const uno::Reference< XEVENTLISTENER >& aListener ) 834 throw(::com::sun::star::uno::RuntimeException) 835 { 836 SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING ); 837 m_pData->m_aInterfaceContainer.addInterface( ::getCppuType((const uno::Reference< XEVENTLISTENER >*)0), aListener ); 838 } 839 840 //________________________________________________________________________________________________________ 841 // XChild 842 //________________________________________________________________________________________________________ 843 844 void SAL_CALL SfxBaseModel::removeEventListener( const uno::Reference< XEVENTLISTENER >& aListener ) 845 throw(::com::sun::star::uno::RuntimeException) 846 { 847 SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING ); 848 m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< XEVENTLISTENER >*)0), aListener ); 849 } 850 851 //________________________________________________________________________________________________________ 852 // document::XDocumentInfoSupplier 853 //________________________________________________________________________________________________________ 854 855 uno::Reference< document::XDocumentInfo > SAL_CALL SfxBaseModel::getDocumentInfo() throw(::com::sun::star::uno::RuntimeException) 856 { 857 SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING ); 858 if ( !m_pData->m_xDocumentInfo.is() ) 859 { 860 // WARNING: this will only work if (when loading a document) the 861 // document meta-data has already been read and completely written 862 // into the XDocumentProperties at this point 863 // ==> DO NOT call getDocumentInfo before document info has been read! 864 uno::Reference< document::XDocumentInfo > xDocInfo = 865 new SfxDocumentInfoObject; 866 uno::Reference< document::XDocumentProperties > xDocProps = 867 getDocumentProperties(); 868 uno::Sequence< uno::Any > args(1); 869 args[0] <<= xDocProps; 870 uno::Reference< lang::XInitialization > xInit( 871 xDocInfo, uno::UNO_QUERY_THROW); 872 try { 873 xInit->initialize(args); 874 ((SfxBaseModel*)this)->m_pData->m_xDocumentInfo = xDocInfo; 875 } catch (uno::RuntimeException &) { 876 throw; 877 } catch (uno::Exception & e) { 878 throw lang::WrappedTargetRuntimeException(::rtl::OUString::createFromAscii( 879 "SfxBaseModel::getDocumentInfo: cannot initialize"), *this, 880 uno::makeAny(e)); 881 } 882 try { 883 rtl::OUString aName = rtl::OUString::createFromAscii("MediaType"); 884 uno::Reference < beans::XPropertySet > xSet( 885 getDocumentStorage(), uno::UNO_QUERY ); 886 uno::Any aMediaType = xSet->getPropertyValue( aName ); 887 uno::Reference < beans::XPropertySet > xDocSet( 888 m_pData->m_xDocumentInfo, uno::UNO_QUERY ); 889 xDocSet->setPropertyValue( aName, aMediaType ); 890 } catch (uno::Exception &) { 891 //ignore 892 } 893 } 894 895 return m_pData->m_xDocumentInfo; 896 } 897 898 // document::XDocumentPropertiesSupplier: 899 uno::Reference< document::XDocumentProperties > SAL_CALL 900 SfxBaseModel::getDocumentProperties() 901 throw(::com::sun::star::uno::RuntimeException) 902 { 903 SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING ); 904 if ( !m_pData->m_xDocumentProperties.is() ) 905 { 906 uno::Reference< lang::XInitialization > xDocProps( 907 ::comphelper::getProcessServiceFactory()->createInstance( 908 DEFINE_CONST_UNICODE("com.sun.star.document.DocumentProperties") ), 909 uno::UNO_QUERY_THROW); 910 // xDocProps->initialize(uno::Sequence<uno::Any>()); 911 m_pData->m_xDocumentProperties.set(xDocProps, uno::UNO_QUERY_THROW); 912 uno::Reference<util::XModifyBroadcaster> xMB(m_pData->m_xDocumentProperties, uno::UNO_QUERY_THROW); 913 xMB->addModifyListener(new SfxDocInfoListener_Impl(*m_pData->m_pObjectShell)); 914 } 915 916 return m_pData->m_xDocumentProperties; 917 } 918 919 920 //________________________________________________________________________________________________________ 921 // XEVENTLISTENER 922 //________________________________________________________________________________________________________ 923 924 void SAL_CALL SfxBaseModel::disposing( const lang::EventObject& aObject ) 925 throw(::com::sun::star::uno::RuntimeException) 926 { 927 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 928 if ( impl_isDisposed() ) 929 return; 930 931 uno::Reference< XMODIFYLISTENER > xMod( aObject.Source, uno::UNO_QUERY ); 932 uno::Reference< XEVENTLISTENER > xListener( aObject.Source, uno::UNO_QUERY ); 933 uno::Reference< XDOCEVENTLISTENER > xDocListener( aObject.Source, uno::UNO_QUERY ); 934 935 if ( xMod.is() ) 936 m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< XMODIFYLISTENER >*)0), xMod ); 937 else if ( xListener.is() ) 938 m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< XEVENTLISTENER >*)0), xListener ); 939 else if ( xDocListener.is() ) 940 m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< XDOCEVENTLISTENER >*)0), xListener ); 941 } 942 943 //________________________________________________________________________________________________________ 944 // frame::XModel 945 //________________________________________________________________________________________________________ 946 947 sal_Bool SAL_CALL SfxBaseModel::attachResource( const ::rtl::OUString& rURL , 948 const uno::Sequence< beans::PropertyValue >& rArgs ) 949 throw(::com::sun::star::uno::RuntimeException) 950 { 951 SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING ); 952 if ( rURL.getLength() == 0 && rArgs.getLength() == 1 && rArgs[0].Name.equalsAscii( "SetEmbedded" ) ) 953 { 954 // allows to set a windowless document to EMBEDDED state 955 // but _only_ before load() or initNew() methods 956 if ( m_pData->m_pObjectShell.Is() && !m_pData->m_pObjectShell->GetMedium() ) 957 { 958 sal_Bool bEmb = sal_Bool(); 959 if ( ( rArgs[0].Value >>= bEmb ) && bEmb ) 960 m_pData->m_pObjectShell->SetCreateMode_Impl( SFX_CREATE_MODE_EMBEDDED ); 961 } 962 963 return sal_True; 964 } 965 966 if ( m_pData->m_pObjectShell.Is() ) 967 { 968 m_pData->m_sURL = rURL; 969 970 SfxObjectShell* pObjectShell = m_pData->m_pObjectShell; 971 972 ::comphelper::NamedValueCollection aArgs( rArgs ); 973 974 Sequence< sal_Int32 > aWinExtent; 975 if ( ( aArgs.get( "WinExtent" ) >>= aWinExtent )&& ( aWinExtent.getLength() == 4 ) ) 976 { 977 Rectangle aVisArea( aWinExtent[0], aWinExtent[1], aWinExtent[2], aWinExtent[3] ); 978 aVisArea = OutputDevice::LogicToLogic( aVisArea, MAP_100TH_MM, pObjectShell->GetMapUnit() ); 979 pObjectShell->SetVisArea( aVisArea ); 980 } 981 982 sal_Bool bBreakMacroSign = sal_False; 983 if ( aArgs.get( "BreakMacroSignature" ) >>= bBreakMacroSign ) 984 { 985 pObjectShell->BreakMacroSign_Impl( bBreakMacroSign ); 986 } 987 988 aArgs.remove( "WinExtent" ); 989 aArgs.remove( "BreakMacroSignature" ); 990 aArgs.remove( "Stream" ); 991 aArgs.remove( "InputStream" ); 992 aArgs.remove( "URL" ); 993 aArgs.remove( "Frame" ); 994 aArgs.remove( "Password" ); 995 aArgs.remove( "EncryptionData" ); 996 997 // TODO/LATER: all the parameters that are accepted by ItemSet of the DocShell must be removed here 998 999 m_pData->m_seqArguments = aArgs.getPropertyValues(); 1000 1001 SfxMedium* pMedium = pObjectShell->GetMedium(); 1002 if ( pMedium ) 1003 { 1004 SfxAllItemSet aSet( pObjectShell->GetPool() ); 1005 TransformParameters( SID_OPENDOC, rArgs, aSet ); 1006 1007 // the arguments are not allowed to reach the medium 1008 aSet.ClearItem( SID_FILE_NAME ); 1009 aSet.ClearItem( SID_FILLFRAME ); 1010 1011 pMedium->GetItemSet()->Put( aSet ); 1012 SFX_ITEMSET_ARG( &aSet, pItem, SfxStringItem, SID_FILTER_NAME, sal_False ); 1013 if ( pItem ) 1014 pMedium->SetFilter( 1015 pObjectShell->GetFactory().GetFilterContainer()->GetFilter4FilterName( pItem->GetValue() ) ); 1016 1017 SFX_ITEMSET_ARG( &aSet, pTitleItem, SfxStringItem, SID_DOCINFO_TITLE, sal_False ); 1018 if ( pTitleItem ) 1019 { 1020 SfxViewFrame* pFrame = SfxViewFrame::GetFirst( pObjectShell ); 1021 if ( pFrame ) 1022 pFrame->UpdateTitle(); 1023 } 1024 } 1025 } 1026 1027 return sal_True ; 1028 } 1029 1030 //________________________________________________________________________________________________________ 1031 // frame::XModel 1032 //________________________________________________________________________________________________________ 1033 1034 ::rtl::OUString SAL_CALL SfxBaseModel::getURL() throw(::com::sun::star::uno::RuntimeException) 1035 { 1036 SfxModelGuard aGuard( *this ); 1037 return m_pData->m_sURL ; 1038 } 1039 1040 //________________________________________________________________________________________________________ 1041 // frame::XModel 1042 //________________________________________________________________________________________________________ 1043 1044 uno::Sequence< beans::PropertyValue > SAL_CALL SfxBaseModel::getArgs() throw(::com::sun::star::uno::RuntimeException) 1045 { 1046 SfxModelGuard aGuard( *this ); 1047 if ( m_pData->m_pObjectShell.Is() ) 1048 { 1049 uno::Sequence< beans::PropertyValue > seqArgsNew; 1050 uno::Sequence< beans::PropertyValue > seqArgsOld; 1051 SfxAllItemSet aSet( m_pData->m_pObjectShell->GetPool() ); 1052 1053 // we need to know which properties are supported by the transformer 1054 // hopefully it is a temporary solution, I guess nonconvertable properties 1055 // should not be supported so then there will be only ItemSet from medium 1056 1057 TransformItems( SID_OPENDOC, *(m_pData->m_pObjectShell->GetMedium()->GetItemSet()), seqArgsNew ); 1058 TransformParameters( SID_OPENDOC, m_pData->m_seqArguments, aSet ); 1059 TransformItems( SID_OPENDOC, aSet, seqArgsOld ); 1060 1061 sal_Int32 nOrgLength = m_pData->m_seqArguments.getLength(); 1062 sal_Int32 nOldLength = seqArgsOld.getLength(); 1063 sal_Int32 nNewLength = seqArgsNew.getLength(); 1064 1065 // "WinExtent" property should be updated always. 1066 // We can store it now to overwrite an old value 1067 // since it is not from ItemSet 1068 Rectangle aTmpRect = m_pData->m_pObjectShell->GetVisArea( ASPECT_CONTENT ); 1069 aTmpRect = OutputDevice::LogicToLogic( aTmpRect, m_pData->m_pObjectShell->GetMapUnit(), MAP_100TH_MM ); 1070 1071 Sequence< sal_Int32 > aRectSeq(4); 1072 aRectSeq[0] = aTmpRect.Left(); 1073 aRectSeq[1] = aTmpRect.Top(); 1074 aRectSeq[2] = aTmpRect.Right(); 1075 aRectSeq[3] = aTmpRect.Bottom(); 1076 1077 seqArgsNew.realloc( ++nNewLength ); 1078 seqArgsNew[ nNewLength - 1 ].Name = ::rtl::OUString::createFromAscii( "WinExtent" ); 1079 seqArgsNew[ nNewLength - 1 ].Value <<= aRectSeq; 1080 1081 if ( m_pData->m_aPreusedFilterName.getLength() ) 1082 { 1083 seqArgsNew.realloc( ++nNewLength ); 1084 seqArgsNew[ nNewLength - 1 ].Name = ::rtl::OUString::createFromAscii( "PreusedFilterName" ); 1085 seqArgsNew[ nNewLength - 1 ].Value <<= m_pData->m_aPreusedFilterName; 1086 } 1087 1088 SfxViewFrame* pFrame = SfxViewFrame::GetFirst( m_pData->m_pObjectShell ); 1089 if ( pFrame ) 1090 { 1091 SvBorder aBorder = pFrame->GetBorderPixelImpl( pFrame->GetViewShell() ); 1092 1093 Sequence< sal_Int32 > aBorderSeq(4); 1094 aBorderSeq[0] = aBorder.Left(); 1095 aBorderSeq[1] = aBorder.Top(); 1096 aBorderSeq[2] = aBorder.Right(); 1097 aBorderSeq[3] = aBorder.Bottom(); 1098 1099 seqArgsNew.realloc( ++nNewLength ); 1100 seqArgsNew[ nNewLength - 1 ].Name = ::rtl::OUString::createFromAscii( "DocumentBorder" ); 1101 seqArgsNew[ nNewLength - 1 ].Value <<= aBorderSeq; 1102 } 1103 1104 // only the values that are not supported by the ItemSet must be cached here 1105 uno::Sequence< beans::PropertyValue > aFinalCache; 1106 sal_Int32 nFinalLength = 0; 1107 1108 for ( sal_Int32 nOrg = 0; nOrg < nOrgLength; nOrg++ ) 1109 { 1110 sal_Int32 nOldInd = 0; 1111 while ( nOldInd < nOldLength ) 1112 { 1113 if ( m_pData->m_seqArguments[nOrg].Name.equals( seqArgsOld[nOldInd].Name ) ) 1114 break; 1115 nOldInd++; 1116 } 1117 1118 if ( nOldInd == nOldLength ) 1119 { 1120 // the entity with this name should be new for seqArgsNew 1121 // since it is not supported by transformer 1122 1123 seqArgsNew.realloc( ++nNewLength ); 1124 seqArgsNew[ nNewLength - 1 ] = m_pData->m_seqArguments[nOrg]; 1125 1126 aFinalCache.realloc( ++nFinalLength ); 1127 aFinalCache[ nFinalLength - 1 ] = m_pData->m_seqArguments[nOrg]; 1128 } 1129 } 1130 1131 m_pData->m_seqArguments = aFinalCache; 1132 1133 return seqArgsNew; 1134 } 1135 1136 return m_pData->m_seqArguments; 1137 } 1138 1139 //________________________________________________________________________________________________________ 1140 // frame::XModel 1141 //________________________________________________________________________________________________________ 1142 1143 void SAL_CALL SfxBaseModel::connectController( const uno::Reference< frame::XController >& xController ) 1144 throw(::com::sun::star::uno::RuntimeException) 1145 { 1146 SfxModelGuard aGuard( *this ); 1147 OSL_PRECOND( xController.is(), "SfxBaseModel::connectController: invalid controller!" ); 1148 if ( !xController.is() ) 1149 return; 1150 1151 sal_uInt32 nOldCount = m_pData->m_seqControllers.getLength(); 1152 uno::Sequence< uno::Reference< frame::XController > > aNewSeq( nOldCount + 1 ); 1153 for ( sal_uInt32 n = 0; n < nOldCount; n++ ) 1154 aNewSeq.getArray()[n] = m_pData->m_seqControllers.getConstArray()[n]; 1155 aNewSeq.getArray()[nOldCount] = xController; 1156 m_pData->m_seqControllers = aNewSeq; 1157 1158 if ( m_pData->m_seqControllers.getLength() == 1 ) 1159 { 1160 SfxViewFrame* pViewFrame = SfxViewFrame::Get( xController, GetObjectShell() ); 1161 ENSURE_OR_THROW( pViewFrame, "SFX document without SFX view!?" ); 1162 pViewFrame->UpdateDocument_Impl(); 1163 const String sDocumentURL = GetObjectShell()->GetMedium()->GetName(); 1164 if ( sDocumentURL.Len() ) 1165 SFX_APP()->Broadcast( SfxStringHint( SID_OPENURL, sDocumentURL ) ); 1166 } 1167 } 1168 1169 //________________________________________________________________________________________________________ 1170 // frame::XModel 1171 //________________________________________________________________________________________________________ 1172 1173 void SAL_CALL SfxBaseModel::disconnectController( const uno::Reference< frame::XController >& xController ) throw(::com::sun::star::uno::RuntimeException) 1174 { 1175 SfxModelGuard aGuard( *this ); 1176 1177 sal_uInt32 nOldCount = m_pData->m_seqControllers.getLength(); 1178 if ( !nOldCount ) 1179 return; 1180 1181 uno::Sequence< uno::Reference< frame::XController > > aNewSeq( nOldCount - 1 ); 1182 for ( sal_uInt32 nOld = 0, nNew = 0; nOld < nOldCount; ++nOld ) 1183 { 1184 if ( xController != m_pData->m_seqControllers.getConstArray()[nOld] ) 1185 { 1186 aNewSeq.getArray()[nNew] = m_pData->m_seqControllers.getConstArray()[nOld]; 1187 ++nNew; 1188 } 1189 } 1190 1191 m_pData->m_seqControllers = aNewSeq; 1192 1193 if ( xController == m_pData->m_xCurrent ) 1194 m_pData->m_xCurrent = uno::Reference< frame::XController > (); 1195 } 1196 1197 namespace 1198 { 1199 typedef ::cppu::WeakImplHelper1< XUndoAction > ControllerLockUndoAction_Base; 1200 class ControllerLockUndoAction : public ControllerLockUndoAction_Base 1201 { 1202 public: 1203 ControllerLockUndoAction( const Reference< XModel >& i_model, const bool i_undoIsUnlock ) 1204 :m_xModel( i_model ) 1205 ,m_bUndoIsUnlock( i_undoIsUnlock ) 1206 { 1207 } 1208 1209 // XUndoAction 1210 virtual ::rtl::OUString SAL_CALL getTitle() throw (RuntimeException); 1211 virtual void SAL_CALL undo( ) throw (UndoFailedException, RuntimeException); 1212 virtual void SAL_CALL redo( ) throw (UndoFailedException, RuntimeException); 1213 1214 private: 1215 const Reference< XModel > m_xModel; 1216 const bool m_bUndoIsUnlock; 1217 }; 1218 1219 ::rtl::OUString SAL_CALL ControllerLockUndoAction::getTitle() throw (RuntimeException) 1220 { 1221 // this action is intended to be used within an UndoContext only, so nobody will ever see this title ... 1222 return ::rtl::OUString(); 1223 } 1224 1225 void SAL_CALL ControllerLockUndoAction::undo( ) throw (UndoFailedException, RuntimeException) 1226 { 1227 if ( m_bUndoIsUnlock ) 1228 m_xModel->unlockControllers(); 1229 else 1230 m_xModel->lockControllers(); 1231 } 1232 1233 void SAL_CALL ControllerLockUndoAction::redo( ) throw (UndoFailedException, RuntimeException) 1234 { 1235 if ( m_bUndoIsUnlock ) 1236 m_xModel->lockControllers(); 1237 else 1238 m_xModel->unlockControllers(); 1239 } 1240 } 1241 1242 //________________________________________________________________________________________________________ 1243 // frame::XModel 1244 //________________________________________________________________________________________________________ 1245 1246 void SAL_CALL SfxBaseModel::lockControllers() throw(::com::sun::star::uno::RuntimeException) 1247 { 1248 SfxModelGuard aGuard( *this ); 1249 1250 ++m_pData->m_nControllerLockCount ; 1251 1252 if ( m_pData->m_pDocumentUndoManager.is() 1253 && m_pData->m_pDocumentUndoManager->isInContext() 1254 && !m_pData->m_pDocumentUndoManager->isLocked() 1255 ) 1256 { 1257 m_pData->m_pDocumentUndoManager->addUndoAction( new ControllerLockUndoAction( this, true ) ); 1258 } 1259 } 1260 1261 //________________________________________________________________________________________________________ 1262 // frame::XModel 1263 //________________________________________________________________________________________________________ 1264 1265 void SAL_CALL SfxBaseModel::unlockControllers() throw(::com::sun::star::uno::RuntimeException) 1266 { 1267 SfxModelGuard aGuard( *this ); 1268 1269 --m_pData->m_nControllerLockCount ; 1270 1271 if ( m_pData->m_pDocumentUndoManager.is() 1272 && m_pData->m_pDocumentUndoManager->isInContext() 1273 && !m_pData->m_pDocumentUndoManager->isLocked() 1274 ) 1275 { 1276 m_pData->m_pDocumentUndoManager->addUndoAction( new ControllerLockUndoAction( this, false ) ); 1277 } 1278 } 1279 1280 //________________________________________________________________________________________________________ 1281 // frame::XModel 1282 //________________________________________________________________________________________________________ 1283 1284 sal_Bool SAL_CALL SfxBaseModel::hasControllersLocked() throw(::com::sun::star::uno::RuntimeException) 1285 { 1286 SfxModelGuard aGuard( *this ); 1287 return ( m_pData->m_nControllerLockCount != 0 ) ; 1288 } 1289 1290 //________________________________________________________________________________________________________ 1291 // frame::XModel 1292 //________________________________________________________________________________________________________ 1293 1294 uno::Reference< frame::XController > SAL_CALL SfxBaseModel::getCurrentController() throw(::com::sun::star::uno::RuntimeException) 1295 { 1296 SfxModelGuard aGuard( *this ); 1297 1298 // get the last active controller of this model 1299 if ( m_pData->m_xCurrent.is() ) 1300 return m_pData->m_xCurrent; 1301 1302 // get the first controller of this model 1303 return m_pData->m_seqControllers.getLength() ? m_pData->m_seqControllers.getConstArray()[0] : m_pData->m_xCurrent; 1304 } 1305 1306 //________________________________________________________________________________________________________ 1307 // frame::XModel 1308 //________________________________________________________________________________________________________ 1309 1310 void SAL_CALL SfxBaseModel::setCurrentController( const uno::Reference< frame::XController >& xCurrentController ) 1311 throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException) 1312 { 1313 SfxModelGuard aGuard( *this ); 1314 1315 m_pData->m_xCurrent = xCurrentController; 1316 } 1317 1318 //________________________________________________________________________________________________________ 1319 // frame::XModel 1320 //________________________________________________________________________________________________________ 1321 1322 uno::Reference< uno::XInterface > SAL_CALL SfxBaseModel::getCurrentSelection() throw(::com::sun::star::uno::RuntimeException) 1323 { 1324 SfxModelGuard aGuard( *this ); 1325 1326 uno::Reference< uno::XInterface > xReturn; 1327 uno::Reference< frame::XController > xController = getCurrentController() ; 1328 1329 if ( xController.is() ) 1330 { 1331 uno::Reference< view::XSelectionSupplier > xDocView( xController, uno::UNO_QUERY ); 1332 if ( xDocView.is() ) 1333 { 1334 uno::Any xSel = xDocView->getSelection(); 1335 xSel >>= xReturn ; 1336 } 1337 } 1338 1339 return xReturn ; 1340 } 1341 1342 //________________________________________________________________________________________________________ 1343 // XModifiable2 1344 //________________________________________________________________________________________________________ 1345 1346 sal_Bool SAL_CALL SfxBaseModel::disableSetModified() throw (::com::sun::star::uno::RuntimeException) 1347 { 1348 SfxModelGuard aGuard( *this ); 1349 1350 if ( !m_pData->m_pObjectShell.Is() ) 1351 throw uno::RuntimeException(); 1352 1353 sal_Bool bResult = m_pData->m_pObjectShell->IsEnableSetModified(); 1354 m_pData->m_pObjectShell->EnableSetModified( sal_False ); 1355 1356 return bResult; 1357 } 1358 1359 sal_Bool SAL_CALL SfxBaseModel::enableSetModified() throw (::com::sun::star::uno::RuntimeException) 1360 { 1361 SfxModelGuard aGuard( *this ); 1362 1363 if ( !m_pData->m_pObjectShell.Is() ) 1364 throw uno::RuntimeException(); 1365 1366 sal_Bool bResult = m_pData->m_pObjectShell->IsEnableSetModified(); 1367 m_pData->m_pObjectShell->EnableSetModified( sal_True ); 1368 1369 return bResult; 1370 } 1371 1372 sal_Bool SAL_CALL SfxBaseModel::isSetModifiedEnabled() throw (::com::sun::star::uno::RuntimeException) 1373 { 1374 SfxModelGuard aGuard( *this ); 1375 1376 if ( !m_pData->m_pObjectShell.Is() ) 1377 throw uno::RuntimeException(); 1378 1379 return m_pData->m_pObjectShell->IsEnableSetModified(); 1380 } 1381 1382 //________________________________________________________________________________________________________ 1383 // XModifiable 1384 //________________________________________________________________________________________________________ 1385 1386 sal_Bool SAL_CALL SfxBaseModel::isModified() throw(::com::sun::star::uno::RuntimeException) 1387 { 1388 SfxModelGuard aGuard( *this ); 1389 1390 return m_pData->m_pObjectShell.Is() ? m_pData->m_pObjectShell->IsModified() : sal_False; 1391 } 1392 1393 //________________________________________________________________________________________________________ 1394 // XModifiable 1395 //________________________________________________________________________________________________________ 1396 1397 void SAL_CALL SfxBaseModel::setModified( sal_Bool bModified ) 1398 throw (::com::sun::star::beans::PropertyVetoException, ::com::sun::star::uno::RuntimeException) 1399 { 1400 SfxModelGuard aGuard( *this ); 1401 1402 if ( m_pData->m_pObjectShell.Is() ) 1403 m_pData->m_pObjectShell->SetModified(bModified); 1404 } 1405 1406 //________________________________________________________________________________________________________ 1407 // XModifiable 1408 //________________________________________________________________________________________________________ 1409 1410 void SAL_CALL SfxBaseModel::addModifyListener(const uno::Reference< XMODIFYLISTENER >& xListener) throw( uno::RuntimeException ) 1411 { 1412 SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING ); 1413 1414 m_pData->m_aInterfaceContainer.addInterface( ::getCppuType((const uno::Reference< XMODIFYLISTENER >*)0),xListener ); 1415 } 1416 1417 //________________________________________________________________________________________________________ 1418 // XModifiable 1419 //________________________________________________________________________________________________________ 1420 1421 void SAL_CALL SfxBaseModel::removeModifyListener(const uno::Reference< XMODIFYLISTENER >& xListener) throw( uno::RuntimeException ) 1422 { 1423 SfxModelGuard aGuard( *this ); 1424 1425 m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< XMODIFYLISTENER >*)0), xListener ); 1426 } 1427 1428 //____________________________________________________________________________________________________ 1429 // XCloseable 1430 //____________________________________________________________________________________________________ 1431 1432 void SAL_CALL SfxBaseModel::close( sal_Bool bDeliverOwnership ) throw (util::CloseVetoException, uno::RuntimeException) 1433 { 1434 static ::rtl::OUString MSG_1 = ::rtl::OUString::createFromAscii("Cant close while saving."); 1435 1436 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 1437 if ( impl_isDisposed() || m_pData->m_bClosed || m_pData->m_bClosing ) 1438 return; 1439 1440 uno::Reference< uno::XInterface > xSelfHold( static_cast< ::cppu::OWeakObject* >(this) ); 1441 lang::EventObject aSource (static_cast< ::cppu::OWeakObject*>(this)); 1442 ::cppu::OInterfaceContainerHelper* pContainer = m_pData->m_aInterfaceContainer.getContainer( ::getCppuType( ( const uno::Reference< util::XCloseListener >*) NULL ) ); 1443 if (pContainer!=NULL) 1444 { 1445 ::cppu::OInterfaceIteratorHelper pIterator(*pContainer); 1446 while (pIterator.hasMoreElements()) 1447 { 1448 try 1449 { 1450 ((util::XCloseListener*)pIterator.next())->queryClosing( aSource, bDeliverOwnership ); 1451 } 1452 catch( uno::RuntimeException& ) 1453 { 1454 pIterator.remove(); 1455 } 1456 } 1457 } 1458 1459 if ( m_pData->m_bSaving ) 1460 { 1461 if (bDeliverOwnership) 1462 m_pData->m_bSuicide = sal_True; 1463 throw util::CloseVetoException( 1464 MSG_1, 1465 static_cast< ::com::sun::star::util::XCloseable* >(this)); 1466 } 1467 1468 // no own objections against closing! 1469 m_pData->m_bClosing = sal_True; 1470 pContainer = m_pData->m_aInterfaceContainer.getContainer( ::getCppuType( ( const uno::Reference< util::XCloseListener >*) NULL ) ); 1471 if (pContainer!=NULL) 1472 { 1473 ::cppu::OInterfaceIteratorHelper pCloseIterator(*pContainer); 1474 while (pCloseIterator.hasMoreElements()) 1475 { 1476 try 1477 { 1478 ((util::XCloseListener*)pCloseIterator.next())->notifyClosing( aSource ); 1479 } 1480 catch( uno::RuntimeException& ) 1481 { 1482 pCloseIterator.remove(); 1483 } 1484 } 1485 } 1486 1487 m_pData->m_bClosed = sal_True; 1488 m_pData->m_bClosing = sal_False; 1489 1490 dispose(); 1491 } 1492 1493 //____________________________________________________________________________________________________ 1494 // XCloseBroadcaster 1495 //____________________________________________________________________________________________________ 1496 1497 void SAL_CALL SfxBaseModel::addCloseListener( const uno::Reference< XCLOSELISTENER >& xListener ) throw (uno::RuntimeException) 1498 { 1499 SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING ); 1500 1501 m_pData->m_aInterfaceContainer.addInterface( ::getCppuType((const uno::Reference< XCLOSELISTENER >*)0), xListener ); 1502 } 1503 1504 //____________________________________________________________________________________________________ 1505 // XCloseBroadcaster 1506 //____________________________________________________________________________________________________ 1507 1508 void SAL_CALL SfxBaseModel::removeCloseListener( const uno::Reference< XCLOSELISTENER >& xListener ) throw (uno::RuntimeException) 1509 { 1510 SfxModelGuard aGuard( *this ); 1511 1512 m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< XCLOSELISTENER >*)0), xListener ); 1513 } 1514 1515 //________________________________________________________________________________________________________ 1516 // XPrintable 1517 //________________________________________________________________________________________________________ 1518 1519 uno::Sequence< beans::PropertyValue > SAL_CALL SfxBaseModel::getPrinter() throw(::com::sun::star::uno::RuntimeException) 1520 { 1521 SfxModelGuard aGuard( *this ); 1522 1523 if ( impl_getPrintHelper() ) 1524 return m_pData->m_xPrintable->getPrinter(); 1525 else 1526 return uno::Sequence< beans::PropertyValue >(); 1527 } 1528 1529 void SAL_CALL SfxBaseModel::setPrinter(const uno::Sequence< beans::PropertyValue >& rPrinter) 1530 throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) 1531 { 1532 SfxModelGuard aGuard( *this ); 1533 1534 if ( impl_getPrintHelper() ) 1535 m_pData->m_xPrintable->setPrinter( rPrinter ); 1536 } 1537 1538 void SAL_CALL SfxBaseModel::print(const uno::Sequence< beans::PropertyValue >& rOptions) 1539 throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) 1540 { 1541 SfxModelGuard aGuard( *this ); 1542 1543 if ( impl_getPrintHelper() ) 1544 m_pData->m_xPrintable->print( rOptions ); 1545 } 1546 1547 //________________________________________________________________________________________________________ 1548 // XStorable 1549 //________________________________________________________________________________________________________ 1550 1551 sal_Bool SAL_CALL SfxBaseModel::hasLocation() throw(::com::sun::star::uno::RuntimeException) 1552 { 1553 SfxModelGuard aGuard( *this ); 1554 1555 return m_pData->m_pObjectShell.Is() ? m_pData->m_pObjectShell->HasName() : sal_False; 1556 } 1557 1558 //________________________________________________________________________________________________________ 1559 // XStorable 1560 //________________________________________________________________________________________________________ 1561 1562 ::rtl::OUString SAL_CALL SfxBaseModel::getLocation() throw(::com::sun::star::uno::RuntimeException) 1563 { 1564 SfxModelGuard aGuard( *this ); 1565 1566 if ( m_pData->m_pObjectShell.Is() ) 1567 { 1568 // TODO/LATER: is it correct that the shared document returns shared file location? 1569 if ( m_pData->m_pObjectShell->IsDocShared() ) 1570 return m_pData->m_pObjectShell->GetSharedFileURL(); 1571 else 1572 return ::rtl::OUString(m_pData->m_pObjectShell->GetMedium()->GetName()); 1573 } 1574 1575 return m_pData->m_sURL; 1576 } 1577 1578 //________________________________________________________________________________________________________ 1579 // XStorable 1580 //________________________________________________________________________________________________________ 1581 1582 sal_Bool SAL_CALL SfxBaseModel::isReadonly() throw(::com::sun::star::uno::RuntimeException) 1583 { 1584 SfxModelGuard aGuard( *this ); 1585 1586 return m_pData->m_pObjectShell.Is() ? m_pData->m_pObjectShell->IsReadOnly() : sal_True; 1587 } 1588 1589 //________________________________________________________________________________________________________ 1590 // XStorable2 1591 //________________________________________________________________________________________________________ 1592 1593 void SAL_CALL SfxBaseModel::storeSelf( const uno::Sequence< beans::PropertyValue >& aSeqArgs ) 1594 throw ( ::com::sun::star::lang::IllegalArgumentException, 1595 ::com::sun::star::io::IOException, 1596 ::com::sun::star::uno::RuntimeException ) 1597 { 1598 RTL_LOGFILE_PRODUCT_CONTEXT( aPerfLog, "PERFORMANCE - SfxBaseModel::storeSelf" ); 1599 1600 SfxModelGuard aGuard( *this ); 1601 1602 if ( m_pData->m_pObjectShell.Is() ) 1603 { 1604 m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "storeSelf" ) ) ); 1605 SfxSaveGuard aSaveGuard(this, m_pData, sal_False); 1606 1607 for ( sal_Int32 nInd = 0; nInd < aSeqArgs.getLength(); nInd++ ) 1608 { 1609 // check that only acceptable parameters are provided here 1610 if ( !aSeqArgs[nInd].Name.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "VersionComment" ) ) ) 1611 && !aSeqArgs[nInd].Name.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Author" ) ) ) 1612 && !aSeqArgs[nInd].Name.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "InteractionHandler" ) ) ) 1613 && !aSeqArgs[nInd].Name.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "StatusIndicator" ) ) ) ) 1614 { 1615 m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "unexpected parameter for storeSelf, might be no problem if SaveAs is executed." ) ) ); 1616 m_pData->m_pObjectShell->StoreLog(); 1617 1618 ::rtl::OUString aMessage( RTL_CONSTASCII_USTRINGPARAM( "Unexpected MediaDescriptor parameter: " ) ); 1619 aMessage += aSeqArgs[nInd].Name; 1620 throw lang::IllegalArgumentException( aMessage, uno::Reference< uno::XInterface >(), 1 ); 1621 } 1622 } 1623 1624 SfxAllItemSet *pParams = new SfxAllItemSet( SFX_APP()->GetPool() ); 1625 TransformParameters( SID_SAVEDOC, aSeqArgs, *pParams ); 1626 1627 SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_SAVEDOC, GlobalEventConfig::GetEventName(STR_EVENT_SAVEDOC), m_pData->m_pObjectShell ) ); 1628 1629 sal_Bool bRet = sal_False; 1630 1631 // TODO/LATER: let the embedded case of saving be handled more careful 1632 if ( m_pData->m_pObjectShell->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED ) 1633 { 1634 // If this is an embedded object that has no URL based location it should be stored to own storage. 1635 // An embedded object can have a location based on URL in case it is a link, then it should be 1636 // stored in normal way. 1637 if ( !hasLocation() || getLocation().compareToAscii( "private:", 8 ) == 0 ) 1638 { 1639 // actually in this very rare case only UI parameters have sence 1640 // TODO/LATER: should be done later, after integration of sb19 1641 bRet = m_pData->m_pObjectShell->DoSave() 1642 && m_pData->m_pObjectShell->DoSaveCompleted(); 1643 } 1644 else 1645 { 1646 bRet = m_pData->m_pObjectShell->Save_Impl( pParams ); 1647 } 1648 } 1649 else 1650 bRet = m_pData->m_pObjectShell->Save_Impl( pParams ); 1651 1652 DELETEZ( pParams ); 1653 1654 sal_uInt32 nErrCode = m_pData->m_pObjectShell->GetError() ? m_pData->m_pObjectShell->GetError() 1655 : ERRCODE_IO_CANTWRITE; 1656 m_pData->m_pObjectShell->ResetError(); 1657 1658 if ( bRet ) 1659 { 1660 m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "successful saving." ) ) ); 1661 m_pData->m_aPreusedFilterName = GetMediumFilterName_Impl(); 1662 1663 SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_SAVEDOCDONE, GlobalEventConfig::GetEventName(STR_EVENT_SAVEDOCDONE), m_pData->m_pObjectShell ) ); 1664 } 1665 else 1666 { 1667 m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Storing failed!" ) ) ); 1668 m_pData->m_pObjectShell->StoreLog(); 1669 1670 // write the contents of the logger to the file 1671 SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_SAVEDOCFAILED, GlobalEventConfig::GetEventName(STR_EVENT_SAVEDOCFAILED), m_pData->m_pObjectShell ) ); 1672 1673 throw task::ErrorCodeIOException( ::rtl::OUString(), uno::Reference< uno::XInterface >(), nErrCode ); 1674 } 1675 } 1676 1677 } 1678 1679 //________________________________________________________________________________________________________ 1680 // XStorable 1681 //________________________________________________________________________________________________________ 1682 1683 void SAL_CALL SfxBaseModel::store() throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) 1684 { 1685 storeSelf( uno::Sequence< beans::PropertyValue >() ); 1686 } 1687 1688 //________________________________________________________________________________________________________ 1689 // XStorable 1690 //________________________________________________________________________________________________________ 1691 1692 void SAL_CALL SfxBaseModel::storeAsURL( const ::rtl::OUString& rURL , 1693 const uno::Sequence< beans::PropertyValue >& rArgs ) 1694 throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) 1695 { 1696 RTL_LOGFILE_PRODUCT_CONTEXT( aPerfLog, "PERFORMANCE - SfxBaseModel::storeAsURL" ); 1697 1698 SfxModelGuard aGuard( *this ); 1699 1700 if ( m_pData->m_pObjectShell.Is() ) 1701 { 1702 m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "storeAsURL" ) ) ); 1703 SfxSaveGuard aSaveGuard(this, m_pData, sal_False); 1704 1705 impl_store( rURL, rArgs, sal_False ); 1706 1707 uno::Sequence< beans::PropertyValue > aSequence ; 1708 TransformItems( SID_OPENDOC, *m_pData->m_pObjectShell->GetMedium()->GetItemSet(), aSequence ); 1709 attachResource( rURL, aSequence ); 1710 1711 #if OSL_DEBUG_LEVEL > 0 1712 SFX_ITEMSET_ARG( m_pData->m_pObjectShell->GetMedium()->GetItemSet(), pPasswdItem, SfxStringItem, SID_PASSWORD, sal_False); 1713 OSL_ENSURE( !pPasswdItem, "There should be no Password property in the document MediaDescriptor!" ); 1714 #endif 1715 } 1716 } 1717 1718 //________________________________________________________________________________________________________ 1719 // XUndoManagerSupplier 1720 //________________________________________________________________________________________________________ 1721 Reference< XUndoManager > SAL_CALL SfxBaseModel::getUndoManager( ) throw (RuntimeException) 1722 { 1723 SfxModelGuard aGuard( *this ); 1724 if ( !m_pData->m_pDocumentUndoManager.is() ) 1725 m_pData->m_pDocumentUndoManager.set( new ::sfx2::DocumentUndoManager( *this ) ); 1726 return m_pData->m_pDocumentUndoManager.get(); 1727 } 1728 1729 //________________________________________________________________________________________________________ 1730 // XStorable 1731 //________________________________________________________________________________________________________ 1732 1733 void SAL_CALL SfxBaseModel::storeToURL( const ::rtl::OUString& rURL , 1734 const uno::Sequence< beans::PropertyValue >& rArgs ) 1735 throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) 1736 { 1737 SfxModelGuard aGuard( *this ); 1738 1739 if ( m_pData->m_pObjectShell.Is() ) 1740 { 1741 m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "storeToURL" ) ) ); 1742 SfxSaveGuard aSaveGuard(this, m_pData, sal_False); 1743 impl_store( rURL, rArgs, sal_True ); 1744 } 1745 } 1746 1747 ::sal_Bool SAL_CALL SfxBaseModel::wasModifiedSinceLastSave() throw ( RuntimeException ) 1748 { 1749 SfxModelGuard aGuard( *this ); 1750 return m_pData->m_bModifiedSinceLastSave; 1751 } 1752 1753 void SAL_CALL SfxBaseModel::storeToRecoveryFile( const ::rtl::OUString& i_TargetLocation, const Sequence< PropertyValue >& i_MediaDescriptor ) throw ( RuntimeException, IOException, WrappedTargetException ) 1754 { 1755 SfxModelGuard aGuard( *this ); 1756 1757 // delegate 1758 SfxSaveGuard aSaveGuard( this, m_pData, sal_False ); 1759 impl_store( i_TargetLocation, i_MediaDescriptor, sal_True ); 1760 1761 // no need for subsequent calls to storeToRecoveryFile, unless we're modified, again 1762 m_pData->m_bModifiedSinceLastSave = sal_False; 1763 } 1764 1765 void SAL_CALL SfxBaseModel::recoverFromFile( const ::rtl::OUString& i_SourceLocation, const ::rtl::OUString& i_SalvagedFile, const Sequence< PropertyValue >& i_MediaDescriptor ) throw ( RuntimeException, IOException, WrappedTargetException ) 1766 { 1767 SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING ); 1768 1769 // delegate to our "load" method 1770 ::comphelper::NamedValueCollection aMediaDescriptor( i_MediaDescriptor ); 1771 1772 // our load implementation expects the SalvagedFile to be in the media descriptor 1773 OSL_ENSURE( !aMediaDescriptor.has( "SalvagedFile" ) || ( aMediaDescriptor.getOrDefault( "SalvagedFile", ::rtl::OUString() ) == i_SalvagedFile ), 1774 "SfxBaseModel::recoverFromFile: inconsistent information!" ); 1775 aMediaDescriptor.put( "SalvagedFile", i_SalvagedFile ); 1776 1777 // similar for the to-be-loaded file 1778 OSL_ENSURE( !aMediaDescriptor.has( "URL" ) || ( aMediaDescriptor.getOrDefault( "URL", ::rtl::OUString() ) == i_SourceLocation ), 1779 "SfxBaseModel::recoverFromFile: inconsistent information!" ); 1780 aMediaDescriptor.put( "URL", i_SourceLocation ); 1781 1782 load( aMediaDescriptor.getPropertyValues() ); 1783 1784 // Note: The XDocumentRecovery interface specification requires us to do an attachResource after loading. 1785 // However, we will not do this here, as we know that our load implementation (respectively some method 1786 // called from there) already did so. 1787 // In particular, the load process might already have modified some elements of the media 1788 // descriptor, for instance the MacroExecMode (in case the user was involved to decide about it), and we do 1789 // not want to overwrite it with the "old" elements passed to this method here. 1790 } 1791 1792 //________________________________________________________________________________________________________ 1793 // XLoadable 1794 //________________________________________________________________________________________________________ 1795 1796 void SAL_CALL SfxBaseModel::initNew() 1797 throw (::com::sun::star::frame::DoubleInitializationException, 1798 ::com::sun::star::io::IOException, 1799 ::com::sun::star::uno::RuntimeException, 1800 ::com::sun::star::uno::Exception) 1801 { 1802 SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING ); 1803 if ( IsInitialized() ) 1804 throw ::com::sun::star::frame::DoubleInitializationException( ::rtl::OUString(), *this ); 1805 1806 // the object shell should exist always 1807 DBG_ASSERT( m_pData->m_pObjectShell.Is(), "Model is useless without an ObjectShell" ); 1808 if ( m_pData->m_pObjectShell.Is() ) 1809 { 1810 if( m_pData->m_pObjectShell->GetMedium() ) 1811 throw DOUBLEINITIALIZATIONEXCEPTION(); 1812 1813 sal_Bool bRes = m_pData->m_pObjectShell->DoInitNew( NULL ); 1814 sal_uInt32 nErrCode = m_pData->m_pObjectShell->GetError() ? 1815 m_pData->m_pObjectShell->GetError() : ERRCODE_IO_CANTCREATE; 1816 m_pData->m_pObjectShell->ResetError(); 1817 1818 if ( !bRes ) 1819 throw task::ErrorCodeIOException( ::rtl::OUString(), uno::Reference< uno::XInterface >(), nErrCode ); 1820 } 1821 } 1822 1823 //________________________________________________________________________________________________________ 1824 // XLoadable 1825 //________________________________________________________________________________________________________ 1826 1827 void SAL_CALL SfxBaseModel::load( const uno::Sequence< beans::PropertyValue >& seqArguments ) 1828 throw (::com::sun::star::frame::DoubleInitializationException, 1829 ::com::sun::star::io::IOException, 1830 ::com::sun::star::uno::RuntimeException, 1831 ::com::sun::star::uno::Exception) 1832 { 1833 SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING ); 1834 if ( IsInitialized() ) 1835 throw ::com::sun::star::frame::DoubleInitializationException( ::rtl::OUString(), *this ); 1836 1837 // the object shell should exist always 1838 DBG_ASSERT( m_pData->m_pObjectShell.Is(), "Model is useless without an ObjectShell" ); 1839 1840 if ( m_pData->m_pObjectShell.Is() ) 1841 { 1842 if( m_pData->m_pObjectShell->GetMedium() ) 1843 // if a Medium is present, the document is already initialized 1844 throw DOUBLEINITIALIZATIONEXCEPTION(); 1845 1846 SfxMedium* pMedium = new SfxMedium( seqArguments ); 1847 String aFilterName; 1848 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pFilterNameItem, SfxStringItem, SID_FILTER_NAME, sal_False ); 1849 if( pFilterNameItem ) 1850 aFilterName = pFilterNameItem->GetValue(); 1851 if( !m_pData->m_pObjectShell->GetFactory().GetFilterContainer()->GetFilter4FilterName( aFilterName ) ) 1852 { 1853 // filtername is not valid 1854 delete pMedium; 1855 throw frame::IllegalArgumentIOException(); 1856 } 1857 1858 // !TODO: currently not working 1859 //SFX_ITEMSET_ARG( pParams, pFrameItem, SfxFrameItem, SID_DOCFRAME, sal_False ); 1860 //if( pFrameItem && pFrameItem->GetFrame() ) 1861 //{ 1862 // SfxFrame* pFrame = pFrameItem->GetFrame(); 1863 // pMedium->SetLoadTargetFrame( pFrame ); 1864 //} 1865 1866 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False ); 1867 sal_Bool bSalvage = pSalvageItem ? sal_True : sal_False; 1868 1869 // SFX_ITEMSET_ARG( pMedium->GetItemSet(), pTemplateItem, SfxBoolItem, SID_TEMPLATE, sal_False); 1870 // sal_Bool bTemplate = pTemplateItem && pTemplateItem->GetValue(); 1871 // 1872 // does already happen in DoLoad call 1873 //m_pData->m_pObjectShell->SetActivateEvent_Impl( bTemplate ? SFX_EVENT_CREATEDOC : SFX_EVENT_OPENDOC ); 1874 1875 // load document 1876 sal_uInt32 nError = ERRCODE_NONE; 1877 if ( !m_pData->m_pObjectShell->DoLoad(pMedium) ) 1878 nError=ERRCODE_IO_GENERAL; 1879 1880 // QUESTION: if the following happens outside of DoLoad, something important is missing there! 1881 ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler > xHandler = pMedium->GetInteractionHandler(); 1882 if( m_pData->m_pObjectShell->GetErrorCode() ) 1883 { 1884 nError = m_pData->m_pObjectShell->GetErrorCode(); 1885 if ( nError == ERRCODE_IO_BROKENPACKAGE && xHandler.is() ) 1886 { 1887 ::rtl::OUString aDocName = pMedium->GetURLObject().getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET ); 1888 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pRepairItem, SfxBoolItem, SID_REPAIRPACKAGE, sal_False ); 1889 if ( !pRepairItem || !pRepairItem->GetValue() ) 1890 { 1891 RequestPackageReparation aRequest( aDocName ); 1892 xHandler->handle( aRequest.GetRequest() ); 1893 if( aRequest.isApproved() ) 1894 { 1895 // broken package: try second loading and allow repair 1896 pMedium->GetItemSet()->Put( SfxBoolItem( SID_REPAIRPACKAGE, sal_True ) ); 1897 pMedium->GetItemSet()->Put( SfxBoolItem( SID_TEMPLATE, sal_True ) ); 1898 pMedium->GetItemSet()->Put( SfxStringItem( SID_DOCINFO_TITLE, aDocName ) ); 1899 1900 // the error must be reset and the storage must be reopened in new mode 1901 pMedium->ResetError(); 1902 pMedium->CloseStorage(); 1903 m_pData->m_pObjectShell->PrepareSecondTryLoad_Impl(); 1904 if ( !m_pData->m_pObjectShell->DoLoad(pMedium) ) 1905 nError=ERRCODE_IO_GENERAL; 1906 nError = m_pData->m_pObjectShell->GetErrorCode(); 1907 } 1908 } 1909 1910 if ( nError == ERRCODE_IO_BROKENPACKAGE ) 1911 { 1912 // repair either not allowed or not successful 1913 NotifyBrokenPackage aRequest( aDocName ); 1914 xHandler->handle( aRequest.GetRequest() ); 1915 } 1916 } 1917 } 1918 1919 if( m_pData->m_pObjectShell->IsAbortingImport() ) 1920 nError = ERRCODE_ABORT; 1921 1922 if( bSalvage ) 1923 { 1924 // file recovery: restore original filter 1925 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pFilterItem, SfxStringItem, SID_FILTER_NAME, sal_False ); 1926 SfxFilterMatcher& rMatcher = SFX_APP()->GetFilterMatcher(); 1927 const SfxFilter* pSetFilter = rMatcher.GetFilter4FilterName( pFilterItem->GetValue() ); 1928 pMedium->SetFilter( pSetFilter ); 1929 m_pData->m_pObjectShell->SetModified(sal_True); 1930 } 1931 1932 // TODO/LATER: may be the mode should be retrieved from outside and the preused filter should not be set 1933 if ( m_pData->m_pObjectShell->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED ) 1934 { 1935 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pFilterItem, SfxStringItem, SID_FILTER_NAME, sal_False ); 1936 if ( pFilterItem ) 1937 m_pData->m_aPreusedFilterName = pFilterItem->GetValue(); 1938 } 1939 1940 if ( !nError ) 1941 nError = pMedium->GetError(); 1942 1943 m_pData->m_pObjectShell->ResetError(); 1944 1945 if ( nError ) 1946 { 1947 sal_Bool bSilent = sal_False; 1948 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSilentItem, SfxBoolItem, SID_SILENT, sal_False); 1949 if( pSilentItem ) 1950 bSilent = pSilentItem->GetValue(); 1951 1952 sal_Bool bWarning = ((nError & ERRCODE_WARNING_MASK) == ERRCODE_WARNING_MASK); 1953 if ( nError != ERRCODE_IO_BROKENPACKAGE && !bSilent ) 1954 { 1955 // broken package was handled already 1956 if ( SfxObjectShell::UseInteractionToHandleError( xHandler, nError ) && !bWarning ) 1957 { 1958 // abort loading (except for warnings) 1959 nError = ERRCODE_IO_ABORT; 1960 } 1961 } 1962 1963 if ( m_pData->m_pObjectShell->GetMedium() != pMedium ) 1964 { 1965 // for whatever reason document now has another medium 1966 DBG_ERROR("Document has rejected the medium?!"); 1967 delete pMedium; 1968 } 1969 1970 if ( !bWarning ) // #i30711# don't abort loading if it's only a warning 1971 { 1972 throw task::ErrorCodeIOException( ::rtl::OUString(), 1973 uno::Reference< uno::XInterface >(), 1974 nError ? nError : ERRCODE_IO_CANTREAD ); 1975 } 1976 } 1977 1978 sal_Bool bHidden = sal_False; 1979 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pHidItem, SfxBoolItem, SID_HIDDEN, sal_False); 1980 if ( pHidItem ) 1981 bHidden = pHidItem->GetValue(); 1982 1983 #if OSL_DEBUG_LEVEL > 0 1984 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pPasswdItem, SfxStringItem, SID_PASSWORD, sal_False); 1985 OSL_ENSURE( !pPasswdItem, "There should be no Password property in the document MediaDescriptor!" ); 1986 #endif 1987 // !TODO: will be done by Framework! 1988 pMedium->SetUpdatePickList( !bHidden ); 1989 } 1990 } 1991 1992 //________________________________________________________________________________________________________ 1993 // XTransferable 1994 //________________________________________________________________________________________________________ 1995 1996 uno::Any SAL_CALL SfxBaseModel::getTransferData( const DATAFLAVOR& aFlavor ) 1997 throw (::com::sun::star::datatransfer::UnsupportedFlavorException, 1998 ::com::sun::star::io::IOException, 1999 ::com::sun::star::uno::RuntimeException) 2000 { 2001 SfxModelGuard aGuard( *this ); 2002 2003 uno::Any aAny; 2004 2005 if ( m_pData->m_pObjectShell.Is() ) 2006 { 2007 if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-objectdescriptor-xml;windows_formatname=\"Star Object Descriptor (XML)\"" ) ) 2008 { 2009 if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) ) 2010 { 2011 TransferableObjectDescriptor aDesc; 2012 2013 aDesc.maClassName = m_pData->m_pObjectShell->GetClassName(); 2014 aDesc.maTypeName = aFlavor.HumanPresentableName; 2015 2016 // TODO/LATER: ViewAspect needs to be sal_Int64 2017 aDesc.mnViewAspect = sal::static_int_cast< sal_uInt16 >( embed::Aspects::MSOLE_CONTENT ); 2018 2019 //TODO/LATER: status needs to become sal_Int64 2020 aDesc.mnOle2Misc = m_pData->m_pObjectShell->GetMiscStatus(); 2021 Size aSize = m_pData->m_pObjectShell->GetVisArea().GetSize(); 2022 2023 MapUnit aMapUnit = m_pData->m_pObjectShell->GetMapUnit(); 2024 aDesc.maSize = OutputDevice::LogicToLogic( aSize, aMapUnit, MAP_100TH_MM ); 2025 aDesc.maDragStartPos = Point(); 2026 aDesc.maDisplayName = String(); 2027 aDesc.mbCanLink = sal_False; 2028 2029 SvMemoryStream aMemStm( 1024, 1024 ); 2030 aMemStm << aDesc; 2031 aAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ), aMemStm.Tell() ); 2032 } 2033 else 2034 throw datatransfer::UnsupportedFlavorException(); 2035 } 2036 else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-embed-source;windows_formatname=\"Star EMBS\"" ) ) 2037 { 2038 if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) ) 2039 { 2040 try 2041 { 2042 utl::TempFile aTmp; 2043 aTmp.EnableKillingFile( sal_True ); 2044 storeToURL( aTmp.GetURL(), uno::Sequence < beans::PropertyValue >() ); 2045 SvStream* pStream = aTmp.GetStream( STREAM_READ ); 2046 const sal_uInt32 nLen = pStream->Seek( STREAM_SEEK_TO_END ); 2047 ::com::sun::star::uno::Sequence< sal_Int8 > aSeq( nLen ); 2048 pStream->Seek( STREAM_SEEK_TO_BEGIN ); 2049 pStream->Read( aSeq.getArray(), nLen ); 2050 delete pStream; 2051 if( aSeq.getLength() ) 2052 aAny <<= aSeq; 2053 } 2054 catch ( uno::Exception& ) 2055 { 2056 } 2057 } 2058 else 2059 throw datatransfer::UnsupportedFlavorException(); 2060 } 2061 else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" ) ) 2062 { 2063 if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) ) 2064 { 2065 2066 ::boost::shared_ptr<GDIMetaFile> pMetaFile = 2067 m_pData->m_pObjectShell->GetPreviewMetaFile( sal_True ); 2068 2069 if ( pMetaFile ) 2070 { 2071 SvMemoryStream aMemStm( 65535, 65535 ); 2072 aMemStm.SetVersion( SOFFICE_FILEFORMAT_CURRENT ); 2073 2074 pMetaFile->Write( aMemStm ); 2075 aAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ), 2076 aMemStm.Seek( STREAM_SEEK_TO_END ) ); 2077 } 2078 } 2079 else 2080 throw datatransfer::UnsupportedFlavorException(); 2081 } 2082 else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-highcontrast-gdimetafile;windows_formatname=\"GDIMetaFile\"" ) ) 2083 { 2084 if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) ) 2085 { 2086 ::boost::shared_ptr<GDIMetaFile> pMetaFile = 2087 m_pData->m_pObjectShell->CreatePreviewMetaFile_Impl( sal_True, sal_True ); 2088 2089 if ( pMetaFile ) 2090 { 2091 SvMemoryStream aMemStm( 65535, 65535 ); 2092 aMemStm.SetVersion( SOFFICE_FILEFORMAT_CURRENT ); 2093 2094 pMetaFile->Write( aMemStm ); 2095 aAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ), 2096 aMemStm.Seek( STREAM_SEEK_TO_END ) ); 2097 } 2098 } 2099 else 2100 throw datatransfer::UnsupportedFlavorException(); 2101 } 2102 else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-emf;windows_formatname=\"Image EMF\"" ) ) 2103 { 2104 if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) ) 2105 { 2106 ::boost::shared_ptr<GDIMetaFile> pMetaFile = 2107 m_pData->m_pObjectShell->GetPreviewMetaFile( sal_True ); 2108 2109 if ( pMetaFile ) 2110 { 2111 ::boost::shared_ptr<SvMemoryStream> pStream( 2112 GraphicHelper::getFormatStrFromGDI_Impl( 2113 pMetaFile.get(), CVT_EMF ) ); 2114 if ( pStream ) 2115 { 2116 pStream->SetVersion( SOFFICE_FILEFORMAT_CURRENT ); 2117 aAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( pStream->GetData() ), 2118 pStream->Seek( STREAM_SEEK_TO_END ) ); 2119 } 2120 } 2121 } 2122 else if ( GraphicHelper::supportsMetaFileHandle_Impl() 2123 && aFlavor.DataType == getCppuType( (const sal_uInt64*) 0 ) ) 2124 { 2125 ::boost::shared_ptr<GDIMetaFile> pMetaFile = 2126 m_pData->m_pObjectShell->GetPreviewMetaFile( sal_True ); 2127 2128 if ( pMetaFile ) 2129 { 2130 aAny <<= reinterpret_cast< const sal_uInt64 >( 2131 GraphicHelper::getEnhMetaFileFromGDI_Impl( pMetaFile.get() ) ); 2132 } 2133 } 2134 else 2135 throw datatransfer::UnsupportedFlavorException(); 2136 } 2137 else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"" ) ) 2138 { 2139 if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) ) 2140 { 2141 ::boost::shared_ptr<GDIMetaFile> pMetaFile = 2142 m_pData->m_pObjectShell->GetPreviewMetaFile( sal_True ); 2143 2144 if ( pMetaFile ) 2145 { 2146 ::boost::shared_ptr<SvMemoryStream> pStream( 2147 GraphicHelper::getFormatStrFromGDI_Impl( 2148 pMetaFile.get(), CVT_WMF ) ); 2149 2150 if ( pStream ) 2151 { 2152 pStream->SetVersion( SOFFICE_FILEFORMAT_CURRENT ); 2153 aAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( pStream->GetData() ), 2154 pStream->Seek( STREAM_SEEK_TO_END ) ); 2155 } 2156 } 2157 } 2158 else if ( GraphicHelper::supportsMetaFileHandle_Impl() 2159 && aFlavor.DataType == getCppuType( (const sal_uInt64*) 0 ) ) 2160 { 2161 // means HGLOBAL handler to memory storage containing METAFILEPICT structure 2162 2163 ::boost::shared_ptr<GDIMetaFile> pMetaFile = 2164 m_pData->m_pObjectShell->GetPreviewMetaFile( sal_True ); 2165 2166 if ( pMetaFile ) 2167 { 2168 Size aMetaSize = pMetaFile->GetPrefSize(); 2169 aAny <<= reinterpret_cast< const sal_uInt64 >( 2170 GraphicHelper::getWinMetaFileFromGDI_Impl( 2171 pMetaFile.get(), aMetaSize ) ); 2172 } 2173 } 2174 else 2175 throw datatransfer::UnsupportedFlavorException(); 2176 } 2177 else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-bitmap;windows_formatname=\"Bitmap\"" ) ) 2178 { 2179 if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) ) 2180 { 2181 ::boost::shared_ptr<GDIMetaFile> pMetaFile = 2182 m_pData->m_pObjectShell->GetPreviewMetaFile( sal_True ); 2183 2184 if ( pMetaFile ) 2185 { 2186 ::boost::shared_ptr<SvMemoryStream> pStream( 2187 GraphicHelper::getFormatStrFromGDI_Impl( 2188 pMetaFile.get(), CVT_BMP ) ); 2189 2190 if ( pStream ) 2191 { 2192 pStream->SetVersion( SOFFICE_FILEFORMAT_CURRENT ); 2193 aAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( pStream->GetData() ), 2194 pStream->Seek( STREAM_SEEK_TO_END ) ); 2195 } 2196 } 2197 } 2198 else 2199 throw datatransfer::UnsupportedFlavorException(); 2200 } 2201 else if ( aFlavor.MimeType.equalsAscii( "image/png" ) ) 2202 { 2203 if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) ) 2204 { 2205 ::boost::shared_ptr<GDIMetaFile> pMetaFile = 2206 m_pData->m_pObjectShell->GetPreviewMetaFile( sal_True ); 2207 2208 if ( pMetaFile ) 2209 { 2210 ::boost::shared_ptr<SvMemoryStream> pStream( 2211 GraphicHelper::getFormatStrFromGDI_Impl( 2212 pMetaFile.get(), CVT_PNG ) ); 2213 2214 if ( pStream ) 2215 { 2216 pStream->SetVersion( SOFFICE_FILEFORMAT_CURRENT ); 2217 aAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( pStream->GetData() ), 2218 pStream->Seek( STREAM_SEEK_TO_END ) ); 2219 } 2220 } 2221 } 2222 else 2223 throw datatransfer::UnsupportedFlavorException(); 2224 } 2225 else 2226 throw datatransfer::UnsupportedFlavorException(); 2227 } 2228 2229 return aAny; 2230 } 2231 2232 //________________________________________________________________________________________________________ 2233 // XTransferable 2234 //________________________________________________________________________________________________________ 2235 2236 2237 uno::Sequence< DATAFLAVOR > SAL_CALL SfxBaseModel::getTransferDataFlavors() 2238 throw (::com::sun::star::uno::RuntimeException) 2239 { 2240 SfxModelGuard aGuard( *this ); 2241 2242 sal_Int32 nSuppFlavors = GraphicHelper::supportsMetaFileHandle_Impl() ? 10 : 8; 2243 uno::Sequence< DATAFLAVOR > aFlavorSeq( nSuppFlavors ); 2244 2245 aFlavorSeq[0].MimeType = 2246 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" ) ); 2247 aFlavorSeq[0].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "GDIMetaFile" ) ); 2248 aFlavorSeq[0].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 ); 2249 2250 aFlavorSeq[1].MimeType = 2251 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-highcontrast-gdimetafile;windows_formatname=\"GDIMetaFile\"" ) ); 2252 aFlavorSeq[1].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "GDIMetaFile" ) ); 2253 aFlavorSeq[1].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 ); 2254 2255 aFlavorSeq[2].MimeType = 2256 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-emf;windows_formatname=\"Image EMF\"" ) ); 2257 aFlavorSeq[2].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Enhanced Windows MetaFile" ) ); 2258 aFlavorSeq[2].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 ); 2259 2260 aFlavorSeq[3].MimeType = 2261 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"" ) ); 2262 aFlavorSeq[3].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Windows MetaFile" ) ); 2263 aFlavorSeq[3].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 ); 2264 2265 aFlavorSeq[4].MimeType = 2266 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-objectdescriptor-xml;windows_formatname=\"Star Object Descriptor (XML)\"" ) ); 2267 aFlavorSeq[4].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Star Object Descriptor (XML)" ) ); 2268 aFlavorSeq[4].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 ); 2269 2270 aFlavorSeq[5].MimeType = 2271 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-embed-source-xml;windows_formatname=\"Star Embed Source (XML)\"" ) ); 2272 aFlavorSeq[5].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Star Embed Source (XML)" ) ); 2273 aFlavorSeq[5].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 ); 2274 2275 aFlavorSeq[6].MimeType = 2276 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-bitmap;windows_formatname=\"Bitmap\"" ) ); 2277 aFlavorSeq[6].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Bitmap" ) ); 2278 aFlavorSeq[6].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 ); 2279 2280 aFlavorSeq[7].MimeType = 2281 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "image/png" ) ); 2282 aFlavorSeq[7].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PNG" ) ); 2283 aFlavorSeq[7].DataType = getCppuType( (const Sequence< sal_Int8 >*) 0 ); 2284 2285 if ( nSuppFlavors == 10 ) 2286 { 2287 aFlavorSeq[8].MimeType = 2288 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-emf;windows_formatname=\"Image EMF\"" ) ); 2289 aFlavorSeq[8].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Enhanced Windows MetaFile" ) ); 2290 aFlavorSeq[8].DataType = getCppuType( (const sal_uInt64*) 0 ); 2291 2292 aFlavorSeq[9].MimeType = 2293 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"" ) ); 2294 aFlavorSeq[9].HumanPresentableName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Windows MetaFile" ) ); 2295 aFlavorSeq[9].DataType = getCppuType( (const sal_uInt64*) 0 ); 2296 } 2297 2298 return aFlavorSeq; 2299 } 2300 2301 //________________________________________________________________________________________________________ 2302 // XTransferable 2303 //________________________________________________________________________________________________________ 2304 2305 2306 sal_Bool SAL_CALL SfxBaseModel::isDataFlavorSupported( const DATAFLAVOR& aFlavor ) 2307 throw (::com::sun::star::uno::RuntimeException) 2308 { 2309 SfxModelGuard aGuard( *this ); 2310 2311 if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" ) ) 2312 { 2313 if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) ) 2314 return sal_True; 2315 } 2316 else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-highcontrast-gdimetafile;windows_formatname=\"GDIMetaFile\"" ) ) 2317 { 2318 if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) ) 2319 return sal_True; 2320 } 2321 else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-emf;windows_formatname=\"Image EMF\"" ) ) 2322 { 2323 if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) ) 2324 return sal_True; 2325 else if ( GraphicHelper::supportsMetaFileHandle_Impl() 2326 && aFlavor.DataType == getCppuType( (const sal_uInt64*) 0 ) ) 2327 return sal_True; 2328 } 2329 else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"" ) ) 2330 { 2331 if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) ) 2332 return sal_True; 2333 else if ( GraphicHelper::supportsMetaFileHandle_Impl() 2334 && aFlavor.DataType == getCppuType( (const sal_uInt64*) 0 ) ) 2335 return sal_True; 2336 } 2337 else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-objectdescriptor-xml;windows_formatname=\"Star Object Descriptor (XML)\"" ) ) 2338 { 2339 if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) ) 2340 return sal_True; 2341 } 2342 else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-embed-source;windows_formatname=\"Star EMBS\"" ) ) 2343 { 2344 if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) ) 2345 return sal_True; 2346 } 2347 else if ( aFlavor.MimeType.equalsAscii( "application/x-openoffice-bitmap;windows_formatname=\"Bitmap\"" ) ) 2348 { 2349 if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) ) 2350 return sal_True; 2351 } 2352 else if ( aFlavor.MimeType.equalsAscii( "image/png" ) ) 2353 { 2354 if ( aFlavor.DataType == getCppuType( (const Sequence< sal_Int8 >*) 0 ) ) 2355 return sal_True; 2356 } 2357 2358 return sal_False; 2359 } 2360 2361 2362 //-------------------------------------------------------------------------------------------------------- 2363 // XEventsSupplier 2364 //-------------------------------------------------------------------------------------------------------- 2365 2366 uno::Reference< container::XNameReplace > SAL_CALL SfxBaseModel::getEvents() throw( uno::RuntimeException ) 2367 { 2368 SfxModelGuard aGuard( *this ); 2369 2370 if ( ! m_pData->m_xEvents.is() ) 2371 { 2372 m_pData->m_xEvents = new SfxEvents_Impl( m_pData->m_pObjectShell, this ); 2373 } 2374 2375 return m_pData->m_xEvents; 2376 } 2377 2378 //-------------------------------------------------------------------------------------------------------- 2379 // XEmbeddedScripts 2380 //-------------------------------------------------------------------------------------------------------- 2381 2382 uno::Reference< script::XStorageBasedLibraryContainer > SAL_CALL SfxBaseModel::getBasicLibraries() throw (RuntimeException) 2383 { 2384 SfxModelGuard aGuard( *this ); 2385 2386 uno::Reference< script::XStorageBasedLibraryContainer > xBasicLibraries; 2387 if ( m_pData->m_pObjectShell ) 2388 xBasicLibraries.set( m_pData->m_pObjectShell->GetBasicContainer(), UNO_QUERY_THROW ); 2389 return xBasicLibraries; 2390 } 2391 2392 uno::Reference< script::XStorageBasedLibraryContainer > SAL_CALL SfxBaseModel::getDialogLibraries() throw (RuntimeException) 2393 { 2394 SfxModelGuard aGuard( *this ); 2395 2396 uno::Reference< script::XStorageBasedLibraryContainer > xDialogLibraries; 2397 if ( m_pData->m_pObjectShell ) 2398 xDialogLibraries.set( m_pData->m_pObjectShell->GetDialogContainer(), UNO_QUERY_THROW ); 2399 return xDialogLibraries; 2400 } 2401 2402 ::sal_Bool SAL_CALL SfxBaseModel::getAllowMacroExecution() throw (RuntimeException) 2403 { 2404 SfxModelGuard aGuard( *this ); 2405 2406 if ( m_pData->m_pObjectShell ) 2407 return m_pData->m_pObjectShell->AdjustMacroMode( String(), false ); 2408 return sal_False; 2409 } 2410 2411 //-------------------------------------------------------------------------------------------------------- 2412 // XScriptInvocationContext 2413 //-------------------------------------------------------------------------------------------------------- 2414 2415 Reference< document::XEmbeddedScripts > SAL_CALL SfxBaseModel::getScriptContainer() throw (RuntimeException) 2416 { 2417 SfxModelGuard aGuard( *this ); 2418 2419 Reference< document::XEmbeddedScripts > xDocumentScripts; 2420 2421 try 2422 { 2423 Reference< frame::XModel > xDocument( this ); 2424 xDocumentScripts.set( xDocument, uno::UNO_QUERY ); 2425 while ( !xDocumentScripts.is() && xDocument.is() ) 2426 { 2427 Reference< container::XChild > xDocAsChild( xDocument, uno::UNO_QUERY ); 2428 if ( !xDocAsChild.is() ) 2429 { 2430 xDocument = NULL; 2431 break; 2432 } 2433 2434 xDocument.set( xDocAsChild->getParent(), uno::UNO_QUERY ); 2435 xDocumentScripts.set( xDocument, uno::UNO_QUERY ); 2436 } 2437 } 2438 catch( const Exception& ) 2439 { 2440 DBG_UNHANDLED_EXCEPTION(); 2441 xDocumentScripts = NULL; 2442 } 2443 2444 return xDocumentScripts; 2445 } 2446 2447 //-------------------------------------------------------------------------------------------------------- 2448 // XEventBroadcaster 2449 //-------------------------------------------------------------------------------------------------------- 2450 2451 void SAL_CALL SfxBaseModel::addEventListener( const uno::Reference< XDOCEVENTLISTENER >& aListener ) throw( uno::RuntimeException ) 2452 { 2453 SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING ); 2454 2455 m_pData->m_aInterfaceContainer.addInterface( ::getCppuType((const uno::Reference< XDOCEVENTLISTENER >*)0), aListener ); 2456 } 2457 2458 //-------------------------------------------------------------------------------------------------------- 2459 // XEventBroadcaster 2460 //-------------------------------------------------------------------------------------------------------- 2461 2462 void SAL_CALL SfxBaseModel::removeEventListener( const uno::Reference< XDOCEVENTLISTENER >& aListener ) throw( uno::RuntimeException ) 2463 { 2464 SfxModelGuard aGuard( *this ); 2465 2466 m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< XDOCEVENTLISTENER >*)0), aListener ); 2467 } 2468 2469 //-------------------------------------------------------------------------------------------------------- 2470 // XDocumentEventBroadcaster 2471 //-------------------------------------------------------------------------------------------------------- 2472 // --------------------------------- 2473 void SAL_CALL SfxBaseModel::addDocumentEventListener( const uno::Reference< document::XDocumentEventListener >& aListener ) 2474 throw ( uno::RuntimeException ) 2475 { 2476 SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING ); 2477 m_pData->m_aInterfaceContainer.addInterface( ::getCppuType((const uno::Reference< document::XDocumentEventListener >*)0), aListener ); 2478 } 2479 2480 // --------------------------------- 2481 void SAL_CALL SfxBaseModel::removeDocumentEventListener( const uno::Reference< document::XDocumentEventListener >& aListener ) 2482 throw ( uno::RuntimeException ) 2483 { 2484 SfxModelGuard aGuard( *this ); 2485 m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< document::XDocumentEventListener >*)0), aListener ); 2486 } 2487 2488 // --------------------------------- 2489 void SAL_CALL SfxBaseModel::notifyDocumentEvent( const ::rtl::OUString&, const uno::Reference< frame::XController2 >&, const uno::Any& ) 2490 throw ( lang::IllegalArgumentException, lang::NoSupportException, uno::RuntimeException ) 2491 { 2492 throw lang::NoSupportException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SfxBaseModel controlls all the sent notifications itself!" ) ), uno::Reference< uno::XInterface >() ); 2493 } 2494 2495 //________________________________________________________________________________________________________ 2496 // SfxListener 2497 //________________________________________________________________________________________________________ 2498 2499 void addTitle_Impl( Sequence < ::com::sun::star::beans::PropertyValue >& rSeq, const ::rtl::OUString& rTitle ) 2500 { 2501 sal_Int32 nCount = rSeq.getLength(); 2502 sal_Int32 nArg; 2503 2504 for ( nArg = 0; nArg < nCount; nArg++ ) 2505 { 2506 ::com::sun::star::beans::PropertyValue& rProp = rSeq[nArg]; 2507 if ( rProp.Name.equalsAscii("Title") ) 2508 { 2509 rProp.Value <<= rTitle; 2510 break; 2511 } 2512 } 2513 2514 if ( nArg == nCount ) 2515 { 2516 rSeq.realloc( nCount+1 ); 2517 rSeq[nCount].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Title") ); 2518 rSeq[nCount].Value <<= rTitle; 2519 } 2520 } 2521 2522 void SfxBaseModel::NotifyStorageListeners_Impl() 2523 { 2524 uno::Reference< uno::XInterface > xSelfHold( static_cast< ::cppu::OWeakObject* >(this) ); 2525 2526 if ( m_pData->m_pObjectShell ) 2527 { 2528 ::cppu::OInterfaceContainerHelper* pContainer = 2529 m_pData->m_aInterfaceContainer.getContainer( 2530 ::getCppuType( ( const uno::Reference< document::XStorageChangeListener >*) NULL ) ); 2531 if ( pContainer != NULL ) 2532 { 2533 uno::Reference< embed::XStorage > xNewStorage = m_pData->m_pObjectShell->GetStorage(); 2534 ::cppu::OInterfaceIteratorHelper pIterator(*pContainer); 2535 while ( pIterator.hasMoreElements() ) 2536 { 2537 try 2538 { 2539 ((document::XStorageChangeListener*)pIterator.next())->notifyStorageChange( 2540 xSelfHold, 2541 xNewStorage ); 2542 } 2543 catch( uno::RuntimeException& ) 2544 { 2545 pIterator.remove(); 2546 } 2547 } 2548 } 2549 } 2550 } 2551 2552 void SfxBaseModel::Notify( SfxBroadcaster& rBC , 2553 const SfxHint& rHint ) 2554 { 2555 if ( !m_pData ) 2556 return; 2557 2558 if ( &rBC == m_pData->m_pObjectShell ) 2559 { 2560 SfxSimpleHint* pSimpleHint = PTR_CAST( SfxSimpleHint, &rHint ); 2561 if ( pSimpleHint && pSimpleHint->GetId() == SFX_HINT_DOCCHANGED ) 2562 changing(); 2563 2564 SfxEventHint* pNamedHint = PTR_CAST( SfxEventHint, &rHint ); 2565 if ( pNamedHint ) 2566 { 2567 2568 switch ( pNamedHint->GetEventId() ) 2569 { 2570 case SFX_EVENT_STORAGECHANGED: 2571 { 2572 // for now this event is sent only on creation of a new storage for new document 2573 // and in case of reload of medium without document reload 2574 // other events are used to detect storage change 2575 // NotifyStorageListeners_Impl(); 2576 2577 if ( m_pData->m_xUIConfigurationManager.is() 2578 && m_pData->m_pObjectShell->GetCreateMode() != SFX_CREATE_MODE_EMBEDDED ) 2579 { 2580 uno::Reference< XSTORAGE > xConfigStorage; 2581 rtl::OUString aUIConfigFolderName( RTL_CONSTASCII_USTRINGPARAM( "Configurations2" )); 2582 2583 xConfigStorage = getDocumentSubStorage( aUIConfigFolderName, com::sun::star::embed::ElementModes::READWRITE ); 2584 if ( !xConfigStorage.is() ) 2585 xConfigStorage = getDocumentSubStorage( aUIConfigFolderName, com::sun::star::embed::ElementModes::READ ); 2586 2587 if ( xConfigStorage.is() || !m_pData->m_pObjectShell->GetStorage()->hasByName( aUIConfigFolderName ) ) 2588 { 2589 // the storage is different, since otherwise it could not be opened, so it must be exchanged 2590 Reference< ui::XUIConfigurationStorage > xUIConfigStorage( m_pData->m_xUIConfigurationManager, uno::UNO_QUERY ); 2591 xUIConfigStorage->setStorage( xConfigStorage ); 2592 } 2593 else 2594 { 2595 OSL_ENSURE( sal_False, "Unexpected scenario!\n" ); 2596 } 2597 } 2598 2599 ListenForStorage_Impl( m_pData->m_pObjectShell->GetStorage() ); 2600 } 2601 break; 2602 2603 case SFX_EVENT_LOADFINISHED: 2604 { 2605 impl_getPrintHelper(); 2606 ListenForStorage_Impl( m_pData->m_pObjectShell->GetStorage() ); 2607 m_pData->m_bModifiedSinceLastSave = sal_False; 2608 } 2609 break; 2610 2611 case SFX_EVENT_SAVEASDOCDONE: 2612 { 2613 m_pData->m_sURL = m_pData->m_pObjectShell->GetMedium()->GetName(); 2614 2615 SfxItemSet *pSet = m_pData->m_pObjectShell->GetMedium()->GetItemSet(); 2616 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs; 2617 ::rtl::OUString aTitle = m_pData->m_pObjectShell->GetTitle(); 2618 TransformItems( SID_SAVEASDOC, *pSet, aArgs ); 2619 addTitle_Impl( aArgs, aTitle ); 2620 attachResource( m_pData->m_pObjectShell->GetMedium()->GetName(), aArgs ); 2621 } 2622 break; 2623 2624 case SFX_EVENT_DOCCREATED: 2625 { 2626 impl_getPrintHelper(); 2627 m_pData->m_bModifiedSinceLastSave = sal_False; 2628 } 2629 break; 2630 2631 case SFX_EVENT_MODIFYCHANGED: 2632 { 2633 m_pData->m_bModifiedSinceLastSave = isModified(); 2634 } 2635 break; 2636 } 2637 2638 2639 SfxViewEventHint* pViewHint = PTR_CAST( SfxViewEventHint, &rHint ); 2640 postEvent_Impl( pNamedHint->GetEventName(), pViewHint ? pViewHint->GetController() : uno::Reference< frame::XController2 >() ); 2641 } 2642 2643 if ( pSimpleHint ) 2644 { 2645 if ( pSimpleHint->GetId() == SFX_HINT_TITLECHANGED ) 2646 { 2647 ::rtl::OUString aTitle = m_pData->m_pObjectShell->GetTitle(); 2648 addTitle_Impl( m_pData->m_seqArguments, aTitle ); 2649 postEvent_Impl( GlobalEventConfig::GetEventName( STR_EVENT_TITLECHANGED ) ); 2650 } 2651 if ( pSimpleHint->GetId() == SFX_HINT_MODECHANGED ) 2652 { 2653 postEvent_Impl( GlobalEventConfig::GetEventName( STR_EVENT_MODECHANGED ) ); 2654 } 2655 /* 2656 else if ( pSimpleHint->GetId() == SFX_HINT_DYING 2657 || pSimpleHint->GetId() == SFX_HINT_DEINITIALIZING ) 2658 { 2659 SfxObjectShellLock pShellLock = m_pData->m_pObjectShellLock; 2660 m_pData->m_pObjectShellLock = SfxObjectShellLock(); 2661 } 2662 */ 2663 } 2664 } 2665 } 2666 2667 //________________________________________________________________________________________________________ 2668 // public impl. 2669 //________________________________________________________________________________________________________ 2670 2671 void SfxBaseModel::NotifyModifyListeners_Impl() const 2672 { 2673 ::cppu::OInterfaceContainerHelper* pIC = m_pData->m_aInterfaceContainer.getContainer( ::getCppuType((const uno::Reference< XMODIFYLISTENER >*)0) ); 2674 if ( pIC ) 2675 { 2676 lang::EventObject aEvent( (frame::XModel *)this ); 2677 pIC->notifyEach( &util::XModifyListener::modified, aEvent ); 2678 } 2679 2680 // this notification here is done too generously, we cannot simply assume that we're really modified 2681 // now, but we need to check it ... 2682 m_pData->m_bModifiedSinceLastSave = const_cast< SfxBaseModel* >( this )->isModified(); 2683 } 2684 2685 void SfxBaseModel::changing() 2686 { 2687 SfxModelGuard aGuard( *this ); 2688 2689 // the notification should not be sent if the document can not be modified 2690 if ( !m_pData->m_pObjectShell.Is() || !m_pData->m_pObjectShell->IsEnableSetModified() ) 2691 return; 2692 2693 NotifyModifyListeners_Impl(); 2694 } 2695 2696 void SfxBaseModel::impl_change() 2697 { 2698 // object already disposed? 2699 if ( impl_isDisposed() ) 2700 return; 2701 2702 NotifyModifyListeners_Impl(); 2703 } 2704 2705 //________________________________________________________________________________________________________ 2706 // public impl. 2707 //________________________________________________________________________________________________________ 2708 2709 SfxObjectShell* SfxBaseModel::GetObjectShell() const 2710 { 2711 return m_pData ? (SfxObjectShell*) m_pData->m_pObjectShell : 0; 2712 } 2713 2714 SfxObjectShell* SfxBaseModel::impl_getObjectShell() const 2715 { 2716 return m_pData ? (SfxObjectShell*) m_pData->m_pObjectShell : 0; 2717 } 2718 2719 //________________________________________________________________________________________________________ 2720 // public impl. 2721 //________________________________________________________________________________________________________ 2722 2723 sal_Bool SfxBaseModel::IsInitialized() const 2724 { 2725 if ( !m_pData || !m_pData->m_pObjectShell ) 2726 { 2727 OSL_ENSURE( false, "SfxBaseModel::IsInitialized: this should have been caught earlier!" ); 2728 return sal_False; 2729 } 2730 2731 return m_pData->m_pObjectShell->GetMedium() != NULL; 2732 } 2733 2734 void SfxBaseModel::MethodEntryCheck( const bool i_mustBeInitialized ) const 2735 { 2736 if ( impl_isDisposed() ) 2737 throw ::com::sun::star::lang::DisposedException( ::rtl::OUString(), *const_cast< SfxBaseModel* >( this ) ); 2738 if ( i_mustBeInitialized && !IsInitialized() ) 2739 throw ::com::sun::star::lang::NotInitializedException( ::rtl::OUString(), *const_cast< SfxBaseModel* >( this ) ); 2740 } 2741 2742 sal_Bool SfxBaseModel::impl_isDisposed() const 2743 { 2744 return ( m_pData == NULL ) ; 2745 } 2746 2747 //________________________________________________________________________________________________________ 2748 // private impl. 2749 //________________________________________________________________________________________________________ 2750 2751 ::rtl::OUString SfxBaseModel::GetMediumFilterName_Impl() 2752 { 2753 const SfxFilter* pFilter = NULL; 2754 SfxMedium* pMedium = m_pData->m_pObjectShell->GetMedium(); 2755 if ( pMedium ) 2756 pFilter = pMedium->GetFilter(); 2757 2758 if ( pFilter ) 2759 return pFilter->GetName(); 2760 2761 return ::rtl::OUString(); 2762 } 2763 2764 void SfxBaseModel::impl_store( const ::rtl::OUString& sURL , 2765 const uno::Sequence< beans::PropertyValue >& seqArguments , 2766 sal_Bool bSaveTo ) 2767 { 2768 if( !sURL.getLength() ) 2769 throw frame::IllegalArgumentIOException(); 2770 2771 //sal_Bool aSaveAsTemplate = sal_False; 2772 2773 sal_Bool bSaved = sal_False; 2774 if ( !bSaveTo && m_pData->m_pObjectShell && sURL.getLength() 2775 && sURL.compareToAscii( "private:stream", 14 ) != COMPARE_EQUAL 2776 && ::utl::UCBContentHelper::EqualURLs( getLocation(), sURL ) ) 2777 { 2778 // this is the same file URL as the current document location, try to use storeOwn if possible 2779 2780 ::comphelper::SequenceAsHashMap aArgHash( seqArguments ); 2781 ::rtl::OUString aFilterString( RTL_CONSTASCII_USTRINGPARAM( "FilterName" ) ); 2782 ::rtl::OUString aFilterName = aArgHash.getUnpackedValueOrDefault( aFilterString, ::rtl::OUString() ); 2783 if ( aFilterName.getLength() ) 2784 { 2785 SfxMedium* pMedium = m_pData->m_pObjectShell->GetMedium(); 2786 if ( pMedium ) 2787 { 2788 const SfxFilter* pFilter = pMedium->GetFilter(); 2789 if ( pFilter && aFilterName.equals( pFilter->GetFilterName() ) ) 2790 { 2791 aArgHash.erase( aFilterString ); 2792 aArgHash.erase( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) ) ); 2793 2794 try 2795 { 2796 storeSelf( aArgHash.getAsConstPropertyValueList() ); 2797 bSaved = sal_True; 2798 } 2799 catch( const lang::IllegalArgumentException& ) 2800 { 2801 // some additional arguments do not allow to use saving, SaveAs should be done 2802 // but only for normal documents, the shared documents would be overwritten in this case 2803 // that would mean an information loss 2804 // TODO/LATER: need a new interaction for this case 2805 if ( m_pData->m_pObjectShell->IsDocShared() ) 2806 { 2807 m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't store shared document!" ) ) ); 2808 m_pData->m_pObjectShell->StoreLog(); 2809 2810 uno::Sequence< beans::NamedValue > aNewEncryptionData = aArgHash.getUnpackedValueOrDefault( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "EncryptionData" ) ), uno::Sequence< beans::NamedValue >() ); 2811 if ( !aNewEncryptionData.getLength() ) 2812 { 2813 ::rtl::OUString aNewPassword = aArgHash.getUnpackedValueOrDefault( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Password" ) ), ::rtl::OUString() ); 2814 aNewEncryptionData = ::comphelper::OStorageHelper::CreatePackageEncryptionData( aNewPassword ); 2815 } 2816 2817 uno::Sequence< beans::NamedValue > aOldEncryptionData; 2818 GetEncryptionData_Impl( pMedium->GetItemSet(), aOldEncryptionData ); 2819 2820 if ( !aOldEncryptionData.getLength() && !aNewEncryptionData.getLength() ) 2821 throw; 2822 else 2823 { 2824 // if the password is changed a special error should be used in case of shared document 2825 throw task::ErrorCodeIOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Cant change password for shared document." ) ), uno::Reference< uno::XInterface >(), ERRCODE_SFX_SHARED_NOPASSWORDCHANGE ); 2826 } 2827 } 2828 } 2829 } 2830 } 2831 } 2832 } 2833 2834 if ( !bSaved && m_pData->m_pObjectShell ) 2835 { 2836 SFX_APP()->NotifyEvent( SfxEventHint( bSaveTo ? SFX_EVENT_SAVETODOC : SFX_EVENT_SAVEASDOC, GlobalEventConfig::GetEventName( bSaveTo ? STR_EVENT_SAVETODOC : STR_EVENT_SAVEASDOC ), 2837 m_pData->m_pObjectShell ) ); 2838 2839 SfxAllItemSet *aParams = new SfxAllItemSet( SFX_APP()->GetPool() ); 2840 aParams->Put( SfxStringItem( SID_FILE_NAME, String(sURL) ) ); 2841 if ( bSaveTo ) 2842 aParams->Put( SfxBoolItem( SID_SAVETO, sal_True ) ); 2843 2844 TransformParameters( SID_SAVEASDOC, seqArguments, *aParams ); 2845 2846 SFX_ITEMSET_ARG( aParams, pCopyStreamItem, SfxBoolItem, SID_COPY_STREAM_IF_POSSIBLE, sal_False ); 2847 2848 if ( pCopyStreamItem && pCopyStreamItem->GetValue() && !bSaveTo ) 2849 { 2850 m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Misuse of CopyStreamIfPossible!" ) ) ); 2851 m_pData->m_pObjectShell->StoreLog(); 2852 2853 throw frame::IllegalArgumentIOException( 2854 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CopyStreamIfPossible parameter is not acceptable for storeAsURL() call!") ), 2855 uno::Reference< uno::XInterface >() ); 2856 } 2857 2858 sal_uInt32 nModifyPasswordHash = 0; 2859 uno::Sequence< beans::PropertyValue > aModifyPasswordInfo; 2860 SFX_ITEMSET_ARG( aParams, pModifyPasswordInfoItem, SfxUnoAnyItem, SID_MODIFYPASSWORDINFO, sal_False ); 2861 if ( pModifyPasswordInfoItem ) 2862 { 2863 // it contains either a simple hash or a set of PropertyValues 2864 // TODO/LATER: the sequence of PropertyValue should replace the hash completely in future 2865 sal_Int32 nMPHTmp = 0; 2866 pModifyPasswordInfoItem->GetValue() >>= nMPHTmp; 2867 nModifyPasswordHash = (sal_uInt32)nMPHTmp; 2868 pModifyPasswordInfoItem->GetValue() >>= aModifyPasswordInfo; 2869 } 2870 aParams->ClearItem( SID_MODIFYPASSWORDINFO ); 2871 sal_uInt32 nOldModifyPasswordHash = m_pData->m_pObjectShell->GetModifyPasswordHash(); 2872 m_pData->m_pObjectShell->SetModifyPasswordHash( nModifyPasswordHash ); 2873 uno::Sequence< beans::PropertyValue > aOldModifyPasswordInfo = m_pData->m_pObjectShell->GetModifyPasswordInfo(); 2874 m_pData->m_pObjectShell->SetModifyPasswordInfo( aModifyPasswordInfo ); 2875 2876 // since saving a document modifies its DocumentInfo, the current 2877 // DocumentInfo must be saved on "SaveTo", so it can be restored 2878 // after saving 2879 sal_Bool bCopyTo = bSaveTo || 2880 m_pData->m_pObjectShell->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED; 2881 uno::Reference<document::XDocumentProperties> xOldDocProps; 2882 uno::Reference<document::XDocumentInfo> xOldDocInfo; 2883 if ( bCopyTo ) 2884 { 2885 xOldDocProps = getDocumentProperties(); 2886 if (m_pData->m_xDocumentInfo.is()) 2887 { 2888 xOldDocInfo = getDocumentInfo(); 2889 const Reference<util::XCloneable> xCloneable(xOldDocInfo, 2890 UNO_QUERY_THROW); 2891 const Reference<document::XDocumentInfo> xNewDocInfo( 2892 xCloneable->createClone(), UNO_QUERY_THROW); 2893 const Reference<document::XDocumentPropertiesSupplier> xDPS( 2894 xNewDocInfo, UNO_QUERY_THROW); 2895 const Reference<document::XDocumentProperties> xNewDocProps( 2896 xDPS->getDocumentProperties()); 2897 m_pData->m_xDocumentProperties = xNewDocProps; 2898 m_pData->m_xDocumentInfo = xNewDocInfo; 2899 } 2900 else // try not to create DocumentInfo if it does not exist... 2901 { 2902 const Reference<util::XCloneable> xCloneable(xOldDocProps, 2903 UNO_QUERY_THROW); 2904 const Reference<document::XDocumentProperties> xNewDocProps( 2905 xCloneable->createClone(), UNO_QUERY_THROW); 2906 m_pData->m_xDocumentProperties = xNewDocProps; 2907 } 2908 } 2909 2910 sal_Bool bRet = m_pData->m_pObjectShell->APISaveAs_Impl( sURL, aParams ); 2911 2912 if ( bCopyTo ) 2913 { 2914 // restore DocumentInfo if a copy was created 2915 m_pData->m_xDocumentProperties = xOldDocProps; 2916 m_pData->m_xDocumentInfo = xOldDocInfo; 2917 } 2918 2919 uno::Reference < task::XInteractionHandler > xHandler; 2920 SFX_ITEMSET_ARG( aParams, pItem, SfxUnoAnyItem, SID_INTERACTIONHANDLER, sal_False); 2921 if ( pItem ) 2922 pItem->GetValue() >>= xHandler; 2923 2924 DELETEZ( aParams ); 2925 2926 sal_uInt32 nErrCode = m_pData->m_pObjectShell->GetErrorCode(); 2927 if ( !bRet && !nErrCode ) 2928 { 2929 m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Storing has failed, no error is set!" ) ) ); 2930 nErrCode = ERRCODE_IO_CANTWRITE; 2931 } 2932 m_pData->m_pObjectShell->ResetError(); 2933 2934 if ( bRet ) 2935 { 2936 if ( nErrCode ) 2937 { 2938 // must be a warning - use Interactionhandler if possible or abandone 2939 if ( xHandler.is() ) 2940 { 2941 // TODO/LATER: a general way to set the error context should be available 2942 SfxErrorContext aEc( ERRCTX_SFX_SAVEASDOC, m_pData->m_pObjectShell->GetTitle() ); 2943 2944 ::com::sun::star::task::ErrorCodeRequest aErrorCode; 2945 aErrorCode.ErrCode = nErrCode; 2946 SfxMedium::CallApproveHandler( xHandler, uno::makeAny( aErrorCode ), sal_False ); 2947 } 2948 } 2949 2950 m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Storing succeeded!" ) ) ); 2951 if ( !bSaveTo ) 2952 { 2953 m_pData->m_aPreusedFilterName = GetMediumFilterName_Impl(); 2954 m_pData->m_pObjectShell->SetModifyPasswordEntered(); 2955 2956 SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_SAVEASDOCDONE, GlobalEventConfig::GetEventName(STR_EVENT_SAVEASDOCDONE), m_pData->m_pObjectShell ) ); 2957 } 2958 else 2959 { 2960 m_pData->m_pObjectShell->SetModifyPasswordHash( nOldModifyPasswordHash ); 2961 m_pData->m_pObjectShell->SetModifyPasswordInfo( aOldModifyPasswordInfo ); 2962 2963 SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_SAVETODOCDONE, GlobalEventConfig::GetEventName(STR_EVENT_SAVETODOCDONE), m_pData->m_pObjectShell ) ); 2964 } 2965 } 2966 else 2967 { 2968 // let the logring be stored to the related file 2969 m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Storing failed!" ) ) ); 2970 m_pData->m_pObjectShell->StoreLog(); 2971 2972 m_pData->m_pObjectShell->SetModifyPasswordHash( nOldModifyPasswordHash ); 2973 m_pData->m_pObjectShell->SetModifyPasswordInfo( aOldModifyPasswordInfo ); 2974 2975 2976 SFX_APP()->NotifyEvent( SfxEventHint( bSaveTo ? SFX_EVENT_SAVETODOCFAILED : SFX_EVENT_SAVEASDOCFAILED, GlobalEventConfig::GetEventName( bSaveTo ? STR_EVENT_SAVETODOCFAILED : STR_EVENT_SAVEASDOCFAILED), 2977 m_pData->m_pObjectShell ) ); 2978 2979 throw task::ErrorCodeIOException( ::rtl::OUString(), uno::Reference< uno::XInterface >(), nErrCode ); 2980 } 2981 } 2982 } 2983 2984 //******************************************************************************************************** 2985 namespace { 2986 template< typename ListenerT, typename EventT > 2987 class NotifySingleListenerIgnoreRE 2988 { 2989 private: 2990 typedef void ( SAL_CALL ListenerT::*NotificationMethod )( const EventT& ); 2991 NotificationMethod m_pMethod; 2992 const EventT& m_rEvent; 2993 public: 2994 NotifySingleListenerIgnoreRE( NotificationMethod method, const EventT& event ) : m_pMethod( method ), m_rEvent( event ) { } 2995 2996 void operator()( const uno::Reference<ListenerT>& listener ) const 2997 { 2998 try 2999 { 3000 (listener.get()->*m_pMethod)( m_rEvent ); 3001 } 3002 catch( uno::RuntimeException& ) 3003 { 3004 // this exception is ignored to avoid problems with invalid listeners, the listener should be probably thrown away in future 3005 } 3006 } 3007 }; 3008 } // anonymous namespace 3009 3010 void SfxBaseModel::postEvent_Impl( const ::rtl::OUString& aName, const uno::Reference< frame::XController2 >& xController ) 3011 { 3012 // object already disposed? 3013 if ( impl_isDisposed() ) 3014 return; 3015 3016 DBG_ASSERT( aName.getLength(), "Empty event name!" ); 3017 if (!aName.getLength()) 3018 return; 3019 3020 ::cppu::OInterfaceContainerHelper* pIC = 3021 m_pData->m_aInterfaceContainer.getContainer( ::getCppuType( (const uno::Reference< document::XDocumentEventListener >*)0 ) ); 3022 if ( pIC ) 3023 { 3024 #ifdef DBG_UTIL 3025 ByteString aTmp( "SfxDocumentEvent: " ); 3026 aTmp += ByteString( String(aName), RTL_TEXTENCODING_UTF8 ); 3027 DBG_TRACE( aTmp.GetBuffer() ); 3028 #endif 3029 3030 document::DocumentEvent aDocumentEvent( (frame::XModel*)this, aName, xController, uno::Any() ); 3031 3032 pIC->forEach< document::XDocumentEventListener, NotifySingleListenerIgnoreRE< document::XDocumentEventListener, document::DocumentEvent > >( 3033 NotifySingleListenerIgnoreRE< document::XDocumentEventListener, document::DocumentEvent >( 3034 &document::XDocumentEventListener::documentEventOccured, 3035 aDocumentEvent ) ); 3036 } 3037 3038 pIC = m_pData->m_aInterfaceContainer.getContainer( ::getCppuType( (const uno::Reference< document::XEventListener >*)0 ) ); 3039 if ( pIC ) 3040 { 3041 #ifdef DBG_UTIL 3042 ByteString aTmp( "SfxEvent: " ); 3043 aTmp += ByteString( String(aName), RTL_TEXTENCODING_UTF8 ); 3044 DBG_TRACE( aTmp.GetBuffer() ); 3045 #endif 3046 3047 document::EventObject aEvent( (frame::XModel*)this, aName ); 3048 3049 pIC->forEach< document::XEventListener, NotifySingleListenerIgnoreRE< document::XEventListener, document::EventObject > >( 3050 NotifySingleListenerIgnoreRE< document::XEventListener, document::EventObject >( 3051 &document::XEventListener::notifyEvent, 3052 aEvent ) ); 3053 } 3054 3055 } 3056 3057 uno::Reference < container::XIndexAccess > SAL_CALL SfxBaseModel::getViewData() throw(::com::sun::star::uno::RuntimeException) 3058 { 3059 SfxModelGuard aGuard( *this ); 3060 3061 if ( m_pData->m_pObjectShell.Is() && !m_pData->m_contViewData.is() ) 3062 { 3063 SfxViewFrame *pActFrame = SfxViewFrame::Current(); 3064 if ( !pActFrame || pActFrame->GetObjectShell() != m_pData->m_pObjectShell ) 3065 pActFrame = SfxViewFrame::GetFirst( m_pData->m_pObjectShell ); 3066 3067 if ( !pActFrame || !pActFrame->GetViewShell() ) 3068 // currently no frame for this document at all or View is under construction 3069 return uno::Reference < container::XIndexAccess >(); 3070 3071 m_pData->m_contViewData = Reference < container::XIndexAccess >( 3072 ::comphelper::getProcessServiceFactory()->createInstance( 3073 DEFINE_CONST_UNICODE("com.sun.star.document.IndexedPropertyValues") ), 3074 uno::UNO_QUERY ); 3075 3076 if ( !m_pData->m_contViewData.is() ) 3077 { 3078 // error: no container class available! 3079 return uno::Reference < container::XIndexAccess >(); 3080 } 3081 3082 uno::Reference < container::XIndexContainer > xCont( m_pData->m_contViewData, uno::UNO_QUERY ); 3083 sal_Int32 nCount = 0; 3084 uno::Sequence < beans::PropertyValue > aSeq; 3085 ::com::sun::star::uno::Any aAny; 3086 for ( SfxViewFrame *pFrame = SfxViewFrame::GetFirst( m_pData->m_pObjectShell ); pFrame; 3087 pFrame = SfxViewFrame::GetNext( *pFrame, m_pData->m_pObjectShell ) ) 3088 { 3089 sal_Bool bIsActive = ( pFrame == pActFrame ); 3090 pFrame->GetViewShell()->WriteUserDataSequence( aSeq ); 3091 aAny <<= aSeq; 3092 xCont->insertByIndex( bIsActive ? 0 : nCount, aAny ); 3093 nCount++; 3094 } 3095 } 3096 3097 return m_pData->m_contViewData; 3098 } 3099 3100 void SAL_CALL SfxBaseModel::setViewData( const uno::Reference < container::XIndexAccess >& aData ) throw(::com::sun::star::uno::RuntimeException) 3101 { 3102 SfxModelGuard aGuard( *this ); 3103 3104 m_pData->m_contViewData = aData; 3105 } 3106 3107 /** calls all XEventListeners */ 3108 void SfxBaseModel::notifyEvent( const ::com::sun::star::document::EventObject& aEvent ) const 3109 { 3110 // object already disposed? 3111 if ( impl_isDisposed() ) 3112 return; 3113 3114 ::cppu::OInterfaceContainerHelper* pIC = m_pData->m_aInterfaceContainer.getContainer( 3115 ::getCppuType((const uno::Reference< XDOCEVENTLISTENER >*)0) ); 3116 if( pIC ) 3117 3118 { 3119 ::cppu::OInterfaceIteratorHelper aIt( *pIC ); 3120 while( aIt.hasMoreElements() ) 3121 { 3122 try 3123 { 3124 ((XDOCEVENTLISTENER *)aIt.next())->notifyEvent( aEvent ); 3125 } 3126 catch( uno::RuntimeException& ) 3127 { 3128 aIt.remove(); 3129 } 3130 } 3131 } 3132 } 3133 3134 /** returns true if someone added a XEventListener to this XEventBroadcaster */ 3135 sal_Bool SfxBaseModel::hasEventListeners() const 3136 { 3137 return !impl_isDisposed() && (NULL != m_pData->m_aInterfaceContainer.getContainer( ::getCppuType((const uno::Reference< XDOCEVENTLISTENER >*)0) ) ); 3138 } 3139 3140 void SAL_CALL SfxBaseModel::addPrintJobListener( const uno::Reference< view::XPrintJobListener >& xListener ) throw (uno::RuntimeException) 3141 { 3142 SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING ); 3143 3144 if ( impl_getPrintHelper() ) 3145 { 3146 uno::Reference < view::XPrintJobBroadcaster > xPJB( m_pData->m_xPrintable, uno::UNO_QUERY ); 3147 if ( xPJB.is() ) 3148 xPJB->addPrintJobListener( xListener ); 3149 } 3150 // else 3151 // m_pData->m_aInterfaceContainer.addInterface( ::getCppuType((const uno::Reference< view::XPrintJobListener >*)0), xListener ); 3152 } 3153 3154 void SAL_CALL SfxBaseModel::removePrintJobListener( const uno::Reference< view::XPrintJobListener >& xListener ) throw (uno::RuntimeException) 3155 { 3156 SfxModelGuard aGuard( *this ); 3157 3158 if ( impl_getPrintHelper() ) 3159 { 3160 uno::Reference < view::XPrintJobBroadcaster > xPJB( m_pData->m_xPrintable, uno::UNO_QUERY ); 3161 if ( xPJB.is() ) 3162 xPJB->removePrintJobListener( xListener ); 3163 } 3164 // else 3165 // m_pData->m_aInterfaceContainer.addInterface( ::getCppuType((const uno::Reference< view::XPrintJobListener >*)0), xListener ); 3166 } 3167 3168 // simple declaration of class SvObject is enough 3169 // the corresponding <so3/iface.hxx> cannon be included because it provides 3170 // declaration of class SvBorder that conflicts with ../../inc/viewfrm.hxx 3171 class SvObject; 3172 sal_Int64 SAL_CALL SfxBaseModel::getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException) 3173 { 3174 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 3175 if ( GetObjectShell() ) 3176 { 3177 SvGlobalName aName( aIdentifier ); 3178 if ( aName == SvGlobalName( SO3_GLOBAL_CLASSID ) ) 3179 return (sal_Int64)(sal_IntPtr)(SvObject*)GetObjectShell(); 3180 else if ( aName == SvGlobalName( SFX_GLOBAL_CLASSID ) ) 3181 return (sal_Int64)(sal_IntPtr)(SfxObjectShell*)GetObjectShell(); 3182 } 3183 3184 return 0; 3185 } 3186 3187 //____________________________________________________________________________________________________ 3188 // XDocumentSubStorageSupplier 3189 //____________________________________________________________________________________________________ 3190 3191 void SfxBaseModel::ListenForStorage_Impl( const uno::Reference< embed::XStorage >& xStorage ) 3192 { 3193 uno::Reference< util::XModifiable > xModifiable( xStorage, uno::UNO_QUERY ); 3194 if ( xModifiable.is() ) 3195 { 3196 if ( !m_pData->m_pStorageModifyListen.is() ) 3197 { 3198 m_pData->m_pStorageModifyListen = new ::sfx2::DocumentStorageModifyListener( *m_pData, Application::GetSolarMutex() ); 3199 } 3200 3201 // no need to deregister the listening for old storage since it should be disposed automatically 3202 xModifiable->addModifyListener( m_pData->m_pStorageModifyListen.get() ); 3203 } 3204 } 3205 3206 uno::Reference< XSTORAGE > SAL_CALL SfxBaseModel::getDocumentSubStorage( const ::rtl::OUString& aStorageName, sal_Int32 nMode ) 3207 throw ( uno::RuntimeException) 3208 { 3209 SfxModelGuard aGuard( *this ); 3210 3211 uno::Reference< XSTORAGE > xResult; 3212 if ( m_pData->m_pObjectShell.Is() ) 3213 { 3214 uno::Reference< embed::XStorage > xStorage = m_pData->m_pObjectShell->GetStorage(); 3215 if ( xStorage.is() ) 3216 { 3217 try 3218 { 3219 xResult = xStorage->openStorageElement( aStorageName, nMode ); 3220 } 3221 catch ( uno::Exception& ) 3222 { 3223 } 3224 } 3225 } 3226 3227 return xResult; 3228 } 3229 3230 Sequence< ::rtl::OUString > SAL_CALL SfxBaseModel::getDocumentSubStoragesNames() 3231 throw ( io::IOException, 3232 RuntimeException ) 3233 { 3234 SfxModelGuard aGuard( *this ); 3235 3236 Sequence< ::rtl::OUString > aResult; 3237 sal_Int32 nResultSize = 0; 3238 sal_Bool bSuccess = sal_False; 3239 if ( m_pData->m_pObjectShell.Is() ) 3240 { 3241 uno::Reference < embed::XStorage > xStorage = m_pData->m_pObjectShell->GetStorage(); 3242 uno::Reference < container::XNameAccess > xAccess( xStorage, uno::UNO_QUERY ); 3243 if ( xAccess.is() ) 3244 { 3245 Sequence< ::rtl::OUString > aTemp = xAccess->getElementNames(); 3246 for ( sal_Int32 n = 0; n < aTemp.getLength(); n++ ) 3247 { 3248 if ( xStorage->isStorageElement( aTemp[n] ) ) 3249 { 3250 aResult.realloc( ++nResultSize ); 3251 aResult[ nResultSize - 1 ] = aTemp[n]; 3252 } 3253 } 3254 3255 bSuccess = sal_True; 3256 } 3257 } 3258 3259 if ( !bSuccess ) 3260 throw io::IOException(); 3261 3262 return aResult; 3263 } 3264 3265 //____________________________________________________________________________________________________ 3266 // XScriptProviderSupplier 3267 //____________________________________________________________________________________________________ 3268 3269 3270 uno::Reference< script::provider::XScriptProvider > SAL_CALL SfxBaseModel::getScriptProvider() 3271 throw ( uno::RuntimeException ) 3272 { 3273 SfxModelGuard aGuard( *this ); 3274 3275 uno::Reference< script::provider::XScriptProvider > xScriptProvider; 3276 3277 ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() ); 3278 Reference< script::provider::XScriptProviderFactory > xScriptProviderFactory( 3279 aContext.getSingleton( "com.sun.star.script.provider.theMasterScriptProviderFactory" ), uno::UNO_QUERY_THROW ); 3280 3281 try 3282 { 3283 Reference< XScriptInvocationContext > xScriptContext( this ); 3284 xScriptProvider.set( xScriptProviderFactory->createScriptProvider( makeAny( xScriptContext ) ), uno::UNO_SET_THROW ); 3285 } 3286 catch( const uno::RuntimeException& ) 3287 { 3288 throw; 3289 } 3290 catch( const lang::IllegalArgumentException& ) 3291 { 3292 throw lang::WrappedTargetRuntimeException( 3293 ::rtl::OUString(), 3294 *this, 3295 ::cppu::getCaughtException() 3296 ); 3297 } 3298 3299 return xScriptProvider; 3300 } 3301 3302 //____________________________________________________________________________________________________ 3303 // XUIConfigurationManagerSupplier 3304 //____________________________________________________________________________________________________ 3305 3306 rtl::OUString SfxBaseModel::getRuntimeUID() const 3307 { 3308 OSL_ENSURE( m_pData->m_sRuntimeUID.getLength() > 0, 3309 "SfxBaseModel::getRuntimeUID - ID is empty!" ); 3310 return m_pData->m_sRuntimeUID; 3311 } 3312 3313 sal_Bool SfxBaseModel::hasValidSignatures() const 3314 { 3315 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 3316 if ( m_pData->m_pObjectShell.Is() ) 3317 return ( m_pData->m_pObjectShell->ImplGetSignatureState( sal_False ) == SIGNATURESTATE_SIGNATURES_OK ); 3318 return sal_False; 3319 } 3320 3321 static void GetCommandFromSequence( rtl::OUString& rCommand, sal_Int32& nIndex, const uno::Sequence< beans::PropertyValue >& rSeqPropValue ) 3322 { 3323 rtl::OUString aCommand; 3324 nIndex = -1; 3325 3326 for ( sal_Int32 i = 0; i < rSeqPropValue.getLength(); i++ ) 3327 { 3328 if ( rSeqPropValue[i].Name.equalsAsciiL( "Command", 7 )) 3329 { 3330 rSeqPropValue[i].Value >>= rCommand; 3331 nIndex = i; 3332 return; 3333 } 3334 } 3335 } 3336 3337 static void ConvertSlotsToCommands( SfxObjectShell* pDoc, uno::Reference< container::XIndexContainer >& rToolbarDefinition ) 3338 { 3339 if ( pDoc ) 3340 { 3341 Any aAny; 3342 SfxModule* pModule( pDoc->GetFactory().GetModule() ); 3343 rtl::OUString aSlotCmd( RTL_CONSTASCII_USTRINGPARAM( "slot:" )); 3344 rtl::OUString aUnoCmd( RTL_CONSTASCII_USTRINGPARAM( ".uno:" )); 3345 uno::Sequence< beans::PropertyValue > aSeqPropValue; 3346 3347 for ( sal_Int32 i = 0; i < rToolbarDefinition->getCount(); i++ ) 3348 { 3349 sal_Int32 nIndex( -1 ); 3350 rtl::OUString aCommand; 3351 3352 if ( rToolbarDefinition->getByIndex( i ) >>= aSeqPropValue ) 3353 { 3354 GetCommandFromSequence( aCommand, nIndex, aSeqPropValue ); 3355 if ( nIndex >= 0 && ( aCommand.indexOf( aSlotCmd ) == 0 )) 3356 { 3357 rtl::OUString aSlot( aCommand.copy( 5 )); 3358 3359 // We have to replace the old "slot-Command" with our new ".uno:-Command" 3360 const SfxSlot* pSlot = pModule->GetSlotPool()->GetSlot( sal_uInt16( aSlot.toInt32() )); 3361 if ( pSlot ) 3362 { 3363 rtl::OUStringBuffer aStrBuf( aUnoCmd ); 3364 aStrBuf.appendAscii( pSlot->GetUnoName() ); 3365 3366 aCommand = aStrBuf.makeStringAndClear(); 3367 aSeqPropValue[nIndex].Value <<= aCommand; 3368 rToolbarDefinition->replaceByIndex( i, Any( aSeqPropValue )); 3369 } 3370 } 3371 } 3372 } 3373 } 3374 } 3375 3376 uno::Reference< ui::XUIConfigurationManager > SAL_CALL SfxBaseModel::getUIConfigurationManager() 3377 throw ( uno::RuntimeException ) 3378 { 3379 SfxModelGuard aGuard( *this ); 3380 3381 if ( !m_pData->m_xUIConfigurationManager.is() ) 3382 { 3383 uno::Reference< ui::XUIConfigurationManager > xNewUIConfMan( 3384 ::comphelper::getProcessServiceFactory()->createInstance( 3385 ::rtl::OUString::createFromAscii( "com.sun.star.ui.UIConfigurationManager" )), 3386 uno::UNO_QUERY ); 3387 3388 Reference< ui::XUIConfigurationStorage > xUIConfigStorage( xNewUIConfMan, uno::UNO_QUERY ); 3389 if ( xUIConfigStorage.is() ) 3390 { 3391 uno::Reference< XSTORAGE > xConfigStorage; 3392 3393 rtl::OUString aUIConfigFolderName( RTL_CONSTASCII_USTRINGPARAM( "Configurations2" )); 3394 // First try to open with READWRITE and then READ 3395 xConfigStorage = getDocumentSubStorage( aUIConfigFolderName, embed::ElementModes::READWRITE ); 3396 if ( xConfigStorage.is() ) 3397 { 3398 rtl::OUString aMediaTypeProp( RTL_CONSTASCII_USTRINGPARAM( "MediaType" )); 3399 rtl::OUString aUIConfigMediaType( 3400 RTL_CONSTASCII_USTRINGPARAM( "application/vnd.sun.xml.ui.configuration" ) ); 3401 rtl::OUString aMediaType; 3402 uno::Reference< beans::XPropertySet > xPropSet( xConfigStorage, uno::UNO_QUERY ); 3403 Any a = xPropSet->getPropertyValue( aMediaTypeProp ); 3404 if ( !( a >>= aMediaType ) || ( aMediaType.getLength() == 0 )) 3405 { 3406 a <<= aUIConfigMediaType; 3407 xPropSet->setPropertyValue( aMediaTypeProp, a ); 3408 } 3409 } 3410 else 3411 xConfigStorage = getDocumentSubStorage( aUIConfigFolderName, embed::ElementModes::READ ); 3412 3413 // initialize ui configuration manager with document substorage 3414 xUIConfigStorage->setStorage( xConfigStorage ); 3415 3416 // embedded objects did not support local configuration data until OOo 3.0, so there's nothing to 3417 // migrate 3418 if ( m_pData->m_pObjectShell->GetCreateMode() != SFX_CREATE_MODE_EMBEDDED ) 3419 { 3420 // Import old UI configuration from OOo 1.x 3421 uno::Reference< XSTORAGE > xOOo1ConfigStorage; 3422 rtl::OUString aOOo1UIConfigFolderName( RTL_CONSTASCII_USTRINGPARAM( "Configurations" )); 3423 3424 // Try to open with READ 3425 xOOo1ConfigStorage = getDocumentSubStorage( aOOo1UIConfigFolderName, embed::ElementModes::READ ); 3426 if ( xOOo1ConfigStorage.is() ) 3427 { 3428 uno::Reference< lang::XMultiServiceFactory > xServiceMgr( ::comphelper::getProcessServiceFactory() ); 3429 uno::Sequence< uno::Reference< container::XIndexContainer > > rToolbars; 3430 3431 sal_Bool bImported = framework::UIConfigurationImporterOOo1x::ImportCustomToolbars( 3432 xNewUIConfMan, rToolbars, xServiceMgr, xOOo1ConfigStorage ); 3433 if ( bImported ) 3434 { 3435 SfxObjectShell* pObjShell = SfxBaseModel::GetObjectShell(); 3436 3437 char aNum[] = "private:resource/toolbar/custom_OOo1x_0"; 3438 char aTitle[] = "Toolbar 0"; 3439 sal_Int32 nNumIndex = strlen( aNum )-1; 3440 sal_Int32 nTitleIndex = strlen( aTitle )-1; 3441 for ( sal_Int32 i = 0; i < rToolbars.getLength(); i++ ) 3442 { 3443 aNum[nNumIndex]++; 3444 aTitle[nTitleIndex]++; 3445 3446 rtl::OUString aCustomTbxName( RTL_CONSTASCII_USTRINGPARAM( aNum )); 3447 rtl::OUString aCustomTbxTitle( RTL_CONSTASCII_USTRINGPARAM( aTitle )); 3448 3449 uno::Reference< container::XIndexContainer > xToolbar = rToolbars[i]; 3450 ConvertSlotsToCommands( pObjShell, xToolbar ); 3451 if ( !xNewUIConfMan->hasSettings( aCustomTbxName )) 3452 { 3453 // Set UIName for the toolbar with container property 3454 uno::Reference< beans::XPropertySet > xPropSet( xToolbar, UNO_QUERY ); 3455 if ( xPropSet.is() ) 3456 { 3457 try 3458 { 3459 rtl::OUString aPropName( RTL_CONSTASCII_USTRINGPARAM( "UIName" )); 3460 Any aAny( aCustomTbxTitle ); 3461 xPropSet->setPropertyValue( aPropName, aAny ); 3462 } 3463 catch ( beans::UnknownPropertyException& ) 3464 { 3465 } 3466 } 3467 3468 uno::Reference< container::XIndexAccess > xToolbarData( xToolbar, uno::UNO_QUERY ); 3469 xNewUIConfMan->insertSettings( aCustomTbxName, xToolbarData ); 3470 uno::Reference< ui::XUIConfigurationPersistence > xPersist( xNewUIConfMan, uno::UNO_QUERY ); 3471 xPersist->store(); 3472 } 3473 } 3474 } 3475 } 3476 } 3477 } 3478 3479 m_pData->m_xUIConfigurationManager = xNewUIConfMan; 3480 } 3481 3482 return m_pData->m_xUIConfigurationManager; 3483 } 3484 3485 //____________________________________________________________________________________________________ 3486 // XVisualObject 3487 //____________________________________________________________________________________________________ 3488 3489 void SAL_CALL SfxBaseModel::setVisualAreaSize( sal_Int64 nAspect, const awt::Size& aSize ) 3490 throw ( lang::IllegalArgumentException, 3491 embed::WrongStateException, 3492 uno::Exception, 3493 uno::RuntimeException ) 3494 { 3495 SfxModelGuard aGuard( *this ); 3496 3497 if ( !m_pData->m_pObjectShell.Is() ) 3498 throw uno::Exception(); // TODO: error handling 3499 3500 SfxViewFrame* pViewFrm = SfxViewFrame::GetFirst( m_pData->m_pObjectShell, sal_False ); 3501 if ( pViewFrm && m_pData->m_pObjectShell->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED && !pViewFrm->GetFrame().IsInPlace() ) 3502 { 3503 Window* pWindow = VCLUnoHelper::GetWindow( pViewFrm->GetFrame().GetFrameInterface()->getContainerWindow() ); 3504 Size aWinSize = pWindow->GetSizePixel(); 3505 awt::Size aCurrent = getVisualAreaSize( nAspect ); 3506 Size aDiff( aSize.Width-aCurrent.Width, aSize.Height-aCurrent.Height ); 3507 Size aWrongDiff = OutputDevice::LogicToLogic( aDiff , m_pData->m_pObjectShell->GetMapUnit(), pWindow->GetMapMode() ); 3508 aDiff = pViewFrm->GetViewShell()->GetWindow()->LogicToPixel( aDiff ); 3509 aWinSize.Width() += aDiff.Width(); 3510 aWinSize.Height() += aDiff.Height(); 3511 pWindow->SetSizePixel( aWinSize ); 3512 } 3513 else 3514 { 3515 Rectangle aTmpRect = m_pData->m_pObjectShell->GetVisArea( ASPECT_CONTENT ); 3516 aTmpRect.SetSize( Size( aSize.Width, aSize.Height ) ); 3517 m_pData->m_pObjectShell->SetVisArea( aTmpRect ); 3518 } 3519 } 3520 3521 awt::Size SAL_CALL SfxBaseModel::getVisualAreaSize( sal_Int64 /*nAspect*/ ) 3522 throw ( lang::IllegalArgumentException, 3523 embed::WrongStateException, 3524 uno::Exception, 3525 uno::RuntimeException) 3526 { 3527 SfxModelGuard aGuard( *this ); 3528 3529 if ( !m_pData->m_pObjectShell.Is() ) 3530 throw uno::Exception(); // TODO: error handling 3531 3532 Rectangle aTmpRect = m_pData->m_pObjectShell->GetVisArea( ASPECT_CONTENT ); 3533 3534 #if 0 3535 Window* pWindow = NULL; 3536 SfxViewFrame* pViewFrm = m_pData->m_pObjectShell.Is() ? 3537 SfxViewFrame::GetFirst( m_pData->m_pObjectShell, 0, sal_False ) : 0; 3538 3539 if ( pWindow ) 3540 { 3541 MapMode aInternalMapMode( pViewFrm->GetWindow().GetMapMode() ); 3542 MapMode aExternalMapMode( m_pData->m_pObjectShell->GetMapUnit() ); 3543 3544 aTmpRect = OutputDevice::LogicToLogic( aTmpRect, aInternalMapMode, aExternalMapMode ); 3545 } 3546 #endif 3547 3548 return awt::Size( aTmpRect.GetWidth(), aTmpRect.GetHeight() ); 3549 } 3550 3551 3552 sal_Int32 SAL_CALL SfxBaseModel::getMapUnit( sal_Int64 /*nAspect*/ ) 3553 throw ( uno::Exception, 3554 uno::RuntimeException) 3555 { 3556 SfxModelGuard aGuard( *this ); 3557 3558 if ( !m_pData->m_pObjectShell.Is() ) 3559 throw uno::Exception(); // TODO: error handling 3560 3561 return VCLUnoHelper::VCL2UnoEmbedMapUnit( m_pData->m_pObjectShell->GetMapUnit() ); 3562 } 3563 3564 embed::VisualRepresentation SAL_CALL SfxBaseModel::getPreferredVisualRepresentation( ::sal_Int64 /*nAspect*/ ) 3565 throw ( lang::IllegalArgumentException, 3566 embed::WrongStateException, 3567 uno::Exception, 3568 uno::RuntimeException ) 3569 { 3570 SfxModelGuard aGuard( *this ); 3571 3572 datatransfer::DataFlavor aDataFlavor( 3573 ::rtl::OUString::createFromAscii( "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" ), 3574 ::rtl::OUString::createFromAscii( "GDIMetaFile" ), 3575 ::getCppuType( (const uno::Sequence< sal_Int8 >*) NULL ) ); 3576 3577 embed::VisualRepresentation aVisualRepresentation; 3578 aVisualRepresentation.Data = getTransferData( aDataFlavor ); 3579 aVisualRepresentation.Flavor = aDataFlavor; 3580 3581 return aVisualRepresentation; 3582 } 3583 3584 //____________________________________________________________________________________________________ 3585 // XStorageBasedDocument 3586 //____________________________________________________________________________________________________ 3587 3588 void SAL_CALL SfxBaseModel::loadFromStorage( const uno::Reference< XSTORAGE >& xStorage, 3589 const uno::Sequence< beans::PropertyValue >& aMediaDescriptor ) 3590 throw ( lang::IllegalArgumentException, 3591 DOUBLEINITIALIZATIONEXCEPTION, 3592 IOEXCEPTION, 3593 EXCEPTION, 3594 uno::RuntimeException ) 3595 { 3596 SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING ); 3597 if ( IsInitialized() ) 3598 throw ::com::sun::star::frame::DoubleInitializationException( ::rtl::OUString(), *this ); 3599 3600 // after i36090 is fixed the pool from object shell can be used 3601 // SfxAllItemSet aSet( m_pData->m_pObjectShell->GetPool() ); 3602 SfxAllItemSet aSet( SFX_APP()->GetPool() ); 3603 3604 // the BaseURL is part of the ItemSet 3605 SfxMedium* pMedium = new SfxMedium( xStorage, String() ); 3606 TransformParameters( SID_OPENDOC, aMediaDescriptor, aSet ); 3607 pMedium->GetItemSet()->Put( aSet ); 3608 3609 // allow to use an interactionhandler (if there is one) 3610 pMedium->UseInteractionHandler( sal_True ); 3611 3612 SFX_ITEMSET_ARG( &aSet, pTemplateItem, SfxBoolItem, SID_TEMPLATE, sal_False); 3613 sal_Bool bTemplate = pTemplateItem && pTemplateItem->GetValue(); 3614 m_pData->m_pObjectShell->SetActivateEvent_Impl( bTemplate ? SFX_EVENT_CREATEDOC : SFX_EVENT_OPENDOC ); 3615 m_pData->m_pObjectShell->Get_Impl()->bOwnsStorage = sal_False; 3616 3617 // load document 3618 if ( !m_pData->m_pObjectShell->DoLoad(pMedium) ) 3619 { 3620 sal_uInt32 nError = m_pData->m_pObjectShell->GetErrorCode(); 3621 throw task::ErrorCodeIOException( ::rtl::OUString(), 3622 uno::Reference< uno::XInterface >(), 3623 nError ? nError : ERRCODE_IO_CANTREAD ); 3624 } 3625 } 3626 3627 void SAL_CALL SfxBaseModel::storeToStorage( const uno::Reference< XSTORAGE >& xStorage, 3628 const uno::Sequence< beans::PropertyValue >& aMediaDescriptor ) 3629 throw ( lang::IllegalArgumentException, 3630 IOEXCEPTION, 3631 EXCEPTION, 3632 uno::RuntimeException ) 3633 { 3634 SfxModelGuard aGuard( *this ); 3635 3636 uno::Reference< XSTORAGE > xResult; 3637 if ( !m_pData->m_pObjectShell.Is() ) 3638 throw IOEXCEPTION(); // TODO: 3639 3640 SfxAllItemSet aSet( m_pData->m_pObjectShell->GetPool() ); 3641 TransformParameters( SID_SAVEASDOC, aMediaDescriptor, aSet ); 3642 3643 // TODO/LATER: may be a special URL "private:storage" should be used 3644 SFX_ITEMSET_ARG( &aSet, pItem, SfxStringItem, SID_FILTER_NAME, sal_False ); 3645 sal_Int32 nVersion = SOFFICE_FILEFORMAT_CURRENT; 3646 if( pItem ) 3647 { 3648 String aFilterName = pItem->GetValue(); 3649 const SfxFilter* pFilter = SFX_APP()->GetFilterMatcher().GetFilter4FilterName( aFilterName ); 3650 if ( pFilter && pFilter->UsesStorage() ) 3651 nVersion = pFilter->GetVersion(); 3652 } 3653 3654 sal_Bool bSuccess = sal_False; 3655 if ( xStorage == m_pData->m_pObjectShell->GetStorage() ) 3656 { 3657 // storing to the own storage 3658 bSuccess = m_pData->m_pObjectShell->DoSave(); 3659 } 3660 else 3661 { 3662 // TODO/LATER: if the provided storage has some data inside the storing might fail, probably the storage must be truncated 3663 // TODO/LATER: is it possible to have a template here? 3664 m_pData->m_pObjectShell->SetupStorage( xStorage, nVersion, sal_False ); 3665 3666 // BaseURL is part of the ItemSet 3667 SfxMedium aMedium( xStorage, String(), &aSet ); 3668 aMedium.CanDisposeStorage_Impl( sal_False ); 3669 if ( aMedium.GetFilter() ) 3670 { 3671 // storing without a valid filter will often crash 3672 bSuccess = m_pData->m_pObjectShell->DoSaveObjectAs( aMedium, sal_True ); 3673 m_pData->m_pObjectShell->DoSaveCompleted( NULL ); 3674 } 3675 } 3676 3677 sal_uInt32 nError = m_pData->m_pObjectShell->GetErrorCode(); 3678 m_pData->m_pObjectShell->ResetError(); 3679 3680 // the warnings are currently not transported 3681 if ( !bSuccess ) 3682 { 3683 throw task::ErrorCodeIOException( ::rtl::OUString(), 3684 uno::Reference< uno::XInterface >(), 3685 nError ? nError : ERRCODE_IO_GENERAL ); 3686 } 3687 } 3688 3689 void SAL_CALL SfxBaseModel::switchToStorage( const uno::Reference< XSTORAGE >& xStorage ) 3690 throw ( lang::IllegalArgumentException, 3691 IOEXCEPTION, 3692 EXCEPTION, 3693 uno::RuntimeException ) 3694 { 3695 SfxModelGuard aGuard( *this ); 3696 3697 uno::Reference< XSTORAGE > xResult; 3698 if ( !m_pData->m_pObjectShell.Is() ) 3699 throw IOEXCEPTION(); // TODO: 3700 3701 // the persistence should be switched only if the storage is different 3702 if ( xStorage != m_pData->m_pObjectShell->GetStorage() 3703 && !m_pData->m_pObjectShell->SwitchPersistance( xStorage ) ) 3704 { 3705 sal_uInt32 nError = m_pData->m_pObjectShell->GetErrorCode(); 3706 throw task::ErrorCodeIOException( ::rtl::OUString(), 3707 uno::Reference< uno::XInterface >(), 3708 nError ? nError : ERRCODE_IO_GENERAL ); 3709 } 3710 3711 m_pData->m_pObjectShell->Get_Impl()->bOwnsStorage = sal_False; 3712 } 3713 3714 uno::Reference< XSTORAGE > SAL_CALL SfxBaseModel::getDocumentStorage() 3715 throw ( IOEXCEPTION, 3716 EXCEPTION, 3717 uno::RuntimeException ) 3718 { 3719 SfxModelGuard aGuard( *this ); 3720 3721 uno::Reference< XSTORAGE > xResult; 3722 if ( !m_pData->m_pObjectShell.Is() ) 3723 throw IOEXCEPTION(); // TODO 3724 3725 return m_pData->m_pObjectShell->GetStorage(); 3726 } 3727 3728 void SAL_CALL SfxBaseModel::addStorageChangeListener( 3729 const uno::Reference< document::XStorageChangeListener >& xListener ) 3730 throw ( uno::RuntimeException ) 3731 { 3732 SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING ); 3733 3734 m_pData->m_aInterfaceContainer.addInterface( 3735 ::getCppuType((const uno::Reference< document::XStorageChangeListener >*)0), xListener ); 3736 } 3737 3738 void SAL_CALL SfxBaseModel::removeStorageChangeListener( 3739 const uno::Reference< document::XStorageChangeListener >& xListener ) 3740 throw ( uno::RuntimeException ) 3741 { 3742 SfxModelGuard aGuard( *this ); 3743 3744 m_pData->m_aInterfaceContainer.removeInterface( 3745 ::getCppuType((const uno::Reference< document::XStorageChangeListener >*)0), xListener ); 3746 } 3747 3748 #include "printhelper.hxx" 3749 bool SfxBaseModel::impl_getPrintHelper() 3750 { 3751 if ( m_pData->m_xPrintable.is() ) 3752 return true; 3753 m_pData->m_xPrintable = new SfxPrintHelper(); 3754 uno::Reference < lang::XInitialization > xInit( m_pData->m_xPrintable, uno::UNO_QUERY ); 3755 uno::Sequence < uno::Any > aValues(1); 3756 aValues[0] <<= uno::Reference < frame::XModel > (static_cast< frame::XModel* >(this), uno::UNO_QUERY ); 3757 xInit->initialize( aValues ); 3758 uno::Reference < view::XPrintJobBroadcaster > xBrd( m_pData->m_xPrintable, uno::UNO_QUERY ); 3759 xBrd->addPrintJobListener( new SfxPrintHelperListener_Impl( m_pData ) ); 3760 return true; 3761 } 3762 3763 //============================================================================= 3764 // css.frame.XModule 3765 void SAL_CALL SfxBaseModel::setIdentifier(const ::rtl::OUString& Identifier) 3766 throw (css::uno::RuntimeException) 3767 { 3768 SfxModelGuard aGuard( *this ); 3769 m_pData->m_sModuleIdentifier = Identifier; 3770 } 3771 3772 //============================================================================= 3773 // css.frame.XModule 3774 ::rtl::OUString SAL_CALL SfxBaseModel::getIdentifier() 3775 throw (css::uno::RuntimeException) 3776 { 3777 SfxModelGuard aGuard( *this ); 3778 if (m_pData->m_sModuleIdentifier.getLength() > 0) 3779 return m_pData->m_sModuleIdentifier; 3780 if (m_pData->m_pObjectShell) 3781 return m_pData->m_pObjectShell->GetFactory().GetDocumentServiceName(); 3782 return ::rtl::OUString(); 3783 } 3784 3785 //============================================================================= 3786 css::uno::Reference< css::frame::XTitle > SfxBaseModel::impl_getTitleHelper () 3787 { 3788 SfxModelGuard aGuard( *this ); 3789 3790 if ( ! m_pData->m_xTitleHelper.is ()) 3791 { 3792 css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory (); 3793 css::uno::Reference< css::frame::XUntitledNumbers > xDesktop(xSMGR->createInstance(SERVICENAME_DESKTOP), css::uno::UNO_QUERY_THROW); 3794 css::uno::Reference< css::frame::XModel > xThis (static_cast< css::frame::XModel* >(this), css::uno::UNO_QUERY_THROW); 3795 3796 ::framework::TitleHelper* pHelper = new ::framework::TitleHelper(xSMGR); 3797 m_pData->m_xTitleHelper = css::uno::Reference< css::frame::XTitle >(static_cast< ::cppu::OWeakObject* >(pHelper), css::uno::UNO_QUERY_THROW); 3798 pHelper->setOwner (xThis ); 3799 pHelper->connectWithUntitledNumbers (xDesktop); 3800 } 3801 3802 return m_pData->m_xTitleHelper; 3803 } 3804 3805 //============================================================================= 3806 css::uno::Reference< css::frame::XUntitledNumbers > SfxBaseModel::impl_getUntitledHelper () 3807 { 3808 SfxModelGuard aGuard( *this ); 3809 3810 if ( ! m_pData->m_xNumberedControllers.is ()) 3811 { 3812 css::uno::Reference< css::frame::XModel > xThis (static_cast< css::frame::XModel* >(this), css::uno::UNO_QUERY_THROW); 3813 ::comphelper::NumberedCollection* pHelper = new ::comphelper::NumberedCollection(); 3814 3815 m_pData->m_xNumberedControllers = css::uno::Reference< css::frame::XUntitledNumbers >(static_cast< ::cppu::OWeakObject* >(pHelper), css::uno::UNO_QUERY_THROW); 3816 3817 pHelper->setOwner (xThis); 3818 pHelper->setUntitledPrefix (::rtl::OUString::createFromAscii(" : ")); 3819 } 3820 3821 return m_pData->m_xNumberedControllers; 3822 } 3823 3824 //============================================================================= 3825 // css.frame.XTitle 3826 ::rtl::OUString SAL_CALL SfxBaseModel::getTitle() 3827 throw (css::uno::RuntimeException) 3828 { 3829 // SYNCHRONIZED -> 3830 SfxModelGuard aGuard( *this ); 3831 3832 ::rtl::OUString aResult = impl_getTitleHelper()->getTitle (); 3833 if ( !m_pData->m_bExternalTitle && m_pData->m_pObjectShell ) 3834 { 3835 SfxMedium* pMedium = m_pData->m_pObjectShell->GetMedium(); 3836 if ( pMedium ) 3837 { 3838 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pRepairedDocItem, SfxBoolItem, SID_REPAIRPACKAGE, sal_False ); 3839 if ( pRepairedDocItem && pRepairedDocItem->GetValue() ) 3840 aResult += String( SfxResId(STR_REPAIREDDOCUMENT) ); 3841 } 3842 3843 if ( m_pData->m_pObjectShell->IsReadOnlyUI() || (pMedium && pMedium->IsReadOnly()) ) 3844 aResult += ::rtl::OUString( String( SfxResId(STR_READONLY) ) ); 3845 else if ( m_pData->m_pObjectShell->IsDocShared() ) 3846 aResult += ::rtl::OUString( String( SfxResId(STR_SHARED) ) ); 3847 3848 if ( m_pData->m_pObjectShell->GetDocumentSignatureState() == SIGNATURESTATE_SIGNATURES_OK ) 3849 aResult += String( SfxResId( RID_XMLSEC_DOCUMENTSIGNED ) ); 3850 } 3851 3852 return aResult; 3853 } 3854 3855 //============================================================================= 3856 // css.frame.XTitle 3857 void SAL_CALL SfxBaseModel::setTitle( const ::rtl::OUString& sTitle ) 3858 throw (css::uno::RuntimeException) 3859 { 3860 // SYNCHRONIZED -> 3861 SfxModelGuard aGuard( *this ); 3862 3863 impl_getTitleHelper()->setTitle (sTitle); 3864 m_pData->m_bExternalTitle = sal_True; 3865 } 3866 3867 //============================================================================= 3868 // css.frame.XTitleChangeBroadcaster 3869 void SAL_CALL SfxBaseModel::addTitleChangeListener( const css::uno::Reference< css::frame::XTitleChangeListener >& xListener ) 3870 throw (css::uno::RuntimeException) 3871 { 3872 // SYNCHRONIZED -> 3873 SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING ); 3874 3875 css::uno::Reference< css::frame::XTitleChangeBroadcaster > xBroadcaster(impl_getTitleHelper(), css::uno::UNO_QUERY); 3876 if (xBroadcaster.is ()) 3877 xBroadcaster->addTitleChangeListener (xListener); 3878 } 3879 3880 //============================================================================= 3881 // css.frame.XTitleChangeBroadcaster 3882 void SAL_CALL SfxBaseModel::removeTitleChangeListener( const css::uno::Reference< css::frame::XTitleChangeListener >& xListener ) 3883 throw (css::uno::RuntimeException) 3884 { 3885 // SYNCHRONIZED -> 3886 SfxModelGuard aGuard( *this ); 3887 3888 css::uno::Reference< css::frame::XTitleChangeBroadcaster > xBroadcaster(impl_getTitleHelper(), css::uno::UNO_QUERY); 3889 if (xBroadcaster.is ()) 3890 xBroadcaster->removeTitleChangeListener (xListener); 3891 } 3892 3893 //============================================================================= 3894 // css.frame.XUntitledNumbers 3895 ::sal_Int32 SAL_CALL SfxBaseModel::leaseNumber( const css::uno::Reference< css::uno::XInterface >& xComponent ) 3896 throw (css::lang::IllegalArgumentException, 3897 css::uno::RuntimeException ) 3898 { 3899 SfxModelGuard aGuard( *this ); 3900 3901 return impl_getUntitledHelper ()->leaseNumber (xComponent); 3902 } 3903 3904 //============================================================================= 3905 // css.frame.XUntitledNumbers 3906 void SAL_CALL SfxBaseModel::releaseNumber( ::sal_Int32 nNumber ) 3907 throw (css::lang::IllegalArgumentException, 3908 css::uno::RuntimeException ) 3909 { 3910 SfxModelGuard aGuard( *this ); 3911 impl_getUntitledHelper ()->releaseNumber (nNumber); 3912 } 3913 3914 //============================================================================= 3915 // css.frame.XUntitledNumbers 3916 void SAL_CALL SfxBaseModel::releaseNumberForComponent( const css::uno::Reference< css::uno::XInterface >& xComponent ) 3917 throw (css::lang::IllegalArgumentException, 3918 css::uno::RuntimeException ) 3919 { 3920 SfxModelGuard aGuard( *this ); 3921 impl_getUntitledHelper ()->releaseNumberForComponent (xComponent); 3922 } 3923 3924 //============================================================================= 3925 // css.frame.XUntitledNumbers 3926 ::rtl::OUString SAL_CALL SfxBaseModel::getUntitledPrefix() 3927 throw (css::uno::RuntimeException) 3928 { 3929 SfxModelGuard aGuard( *this ); 3930 return impl_getUntitledHelper ()->getUntitledPrefix (); 3931 } 3932 3933 //============================================================================= 3934 // css::frame::XModel2 3935 css::uno::Reference< css::container::XEnumeration > SAL_CALL SfxBaseModel::getControllers() 3936 throw (css::uno::RuntimeException) 3937 { 3938 SfxModelGuard aGuard( *this ); 3939 3940 sal_Int32 c = m_pData->m_seqControllers.getLength(); 3941 sal_Int32 i = 0; 3942 css::uno::Sequence< css::uno::Any > lEnum(c); 3943 for (i=0; i<c; ++i) 3944 lEnum[i] <<= m_pData->m_seqControllers[i]; 3945 3946 ::comphelper::OAnyEnumeration* pEnum = new ::comphelper::OAnyEnumeration(lEnum); 3947 css::uno::Reference< css::container::XEnumeration > xEnum(static_cast< css::container::XEnumeration* >(pEnum), css::uno::UNO_QUERY_THROW); 3948 return xEnum; 3949 } 3950 3951 //============================================================================= 3952 // css::frame::XModel2 3953 css::uno::Sequence< ::rtl::OUString > SAL_CALL SfxBaseModel::getAvailableViewControllerNames() 3954 throw (css::uno::RuntimeException) 3955 { 3956 SfxModelGuard aGuard( *this ); 3957 3958 const SfxObjectFactory& rDocumentFactory = GetObjectShell()->GetFactory(); 3959 const sal_Int32 nViewFactoryCount = rDocumentFactory.GetViewFactoryCount(); 3960 3961 Sequence< ::rtl::OUString > aViewNames( nViewFactoryCount ); 3962 for ( sal_Int32 nViewNo = 0; nViewNo < nViewFactoryCount; ++nViewNo ) 3963 aViewNames[nViewNo] = rDocumentFactory.GetViewFactory( nViewNo ).GetAPIViewName(); 3964 return aViewNames; 3965 } 3966 3967 //============================================================================= 3968 // css::frame::XModel2 3969 css::uno::Reference< css::frame::XController2 > SAL_CALL SfxBaseModel::createDefaultViewController( const css::uno::Reference< css::frame::XFrame >& i_rFrame ) 3970 throw (css::uno::RuntimeException , 3971 css::lang::IllegalArgumentException, 3972 css::uno::Exception ) 3973 { 3974 SfxModelGuard aGuard( *this ); 3975 3976 const SfxObjectFactory& rDocumentFactory = GetObjectShell()->GetFactory(); 3977 const ::rtl::OUString sDefaultViewName = rDocumentFactory.GetViewFactory( 0 ).GetAPIViewName(); 3978 3979 aGuard.clear(); 3980 3981 return createViewController( sDefaultViewName, Sequence< PropertyValue >(), i_rFrame ); 3982 } 3983 3984 //============================================================================= 3985 namespace sfx { namespace intern { 3986 3987 /** a class which, in its dtor, cleans up variuos objects (well, at the moment only the frame) collected during 3988 the creation of a document view, unless the creation was successful. 3989 */ 3990 class SAL_DLLPRIVATE ViewCreationGuard 3991 { 3992 public: 3993 ViewCreationGuard() 3994 :m_bSuccess( false ) 3995 { 3996 } 3997 3998 ~ViewCreationGuard() 3999 { 4000 if ( !m_bSuccess ) 4001 impl_closeAll(); 4002 } 4003 4004 void takeFrameOwnership( SfxFrame* i_pFrame ) 4005 { 4006 OSL_PRECOND( !m_aWeakFrame, "ViewCreationGuard::takeFrameOwnership: already have a frame!" ); 4007 OSL_PRECOND( i_pFrame != NULL, "ViewCreationGuard::takeFrameOwnership: invalid frame!" ); 4008 m_aWeakFrame = i_pFrame; 4009 } 4010 4011 void releaseAll() 4012 { 4013 m_bSuccess = true; 4014 } 4015 4016 private: 4017 void impl_closeAll() 4018 { 4019 if ( m_aWeakFrame && !m_aWeakFrame->GetCurrentDocument() ) 4020 { 4021 m_aWeakFrame->SetFrameInterface_Impl( NULL ); 4022 m_aWeakFrame->DoClose(); 4023 } 4024 } 4025 4026 private: 4027 bool m_bSuccess; 4028 SfxFrameWeak m_aWeakFrame; 4029 }; 4030 } } 4031 4032 //============================================================================= 4033 SfxViewFrame* SfxBaseModel::FindOrCreateViewFrame_Impl( const Reference< XFrame >& i_rFrame, ::sfx::intern::ViewCreationGuard& i_rGuard ) const 4034 { 4035 SfxViewFrame* pViewFrame = NULL; 4036 for ( pViewFrame = SfxViewFrame::GetFirst( GetObjectShell(), sal_False ); 4037 pViewFrame; 4038 pViewFrame= SfxViewFrame::GetNext( *pViewFrame, GetObjectShell(), sal_False ) 4039 ) 4040 { 4041 if ( pViewFrame->GetFrame().GetFrameInterface() == i_rFrame ) 4042 break; 4043 } 4044 if ( !pViewFrame ) 4045 { 4046 #if OSL_DEBUG_LEVEL > 0 4047 for ( SfxFrame* pCheckFrame = SfxFrame::GetFirst(); 4048 pCheckFrame; 4049 pCheckFrame = SfxFrame::GetNext( *pCheckFrame ) 4050 ) 4051 { 4052 if ( pCheckFrame->GetFrameInterface() == i_rFrame ) 4053 { 4054 if ( ( pCheckFrame->GetCurrentViewFrame() != NULL ) 4055 || ( pCheckFrame->GetCurrentDocument() != NULL ) 4056 ) 4057 // Note that it is perfectly letgitimate that during loading into an XFrame which already contains 4058 // a document, there exist two SfxFrame instances bound to this XFrame - the old one, which will be 4059 // destroyed later, and the new one, which we're going to create 4060 continue; 4061 4062 OSL_ENSURE( false, "SfxBaseModel::FindOrCreateViewFrame_Impl: there already is an SfxFrame for the given XFrame, but no view in it!" ); 4063 // nowadays, we're the only instance allowed to create an SfxFrame for an XFrame, so this case here should not happen 4064 break; 4065 } 4066 } 4067 #endif 4068 4069 SfxFrame* pTargetFrame = SfxFrame::Create( i_rFrame ); 4070 ENSURE_OR_THROW( pTargetFrame, "could not create an SfxFrame" ); 4071 i_rGuard.takeFrameOwnership( pTargetFrame ); 4072 4073 // prepare it 4074 pTargetFrame->PrepareForDoc_Impl( *GetObjectShell() ); 4075 4076 // create view frame 4077 pViewFrame = new SfxViewFrame( *pTargetFrame, GetObjectShell() ); 4078 } 4079 return pViewFrame; 4080 } 4081 4082 //============================================================================= 4083 // css::frame::XModel2 4084 css::uno::Reference< css::frame::XController2 > SAL_CALL SfxBaseModel::createViewController( 4085 const ::rtl::OUString& i_rViewName, const Sequence< PropertyValue >& i_rArguments, const Reference< XFrame >& i_rFrame ) 4086 throw (css::uno::RuntimeException , 4087 css::lang::IllegalArgumentException, 4088 css::uno::Exception ) 4089 { 4090 SfxModelGuard aGuard( *this ); 4091 4092 if ( !i_rFrame.is() ) 4093 throw css::lang::IllegalArgumentException( ::rtl::OUString(), *this, 3 ); 4094 4095 // find the proper SFX view factory 4096 SfxViewFactory* pViewFactory = GetObjectShell()->GetFactory().GetViewFactoryByViewName( i_rViewName ); 4097 if ( !pViewFactory ) 4098 throw IllegalArgumentException( ::rtl::OUString(), *this, 1 ); 4099 4100 // determine previous shell (used in some special cases) 4101 Reference< XController > xPreviousController( i_rFrame->getController() ); 4102 const Reference< XModel > xMe( this ); 4103 if ( ( xPreviousController.is() ) 4104 && ( xMe != xPreviousController->getModel() ) 4105 ) 4106 { 4107 xPreviousController.clear(); 4108 } 4109 SfxViewShell* pOldViewShell = SfxViewShell::Get( xPreviousController ); 4110 OSL_ENSURE( !xPreviousController.is() || ( pOldViewShell != NULL ), 4111 "SfxBaseModel::createViewController: invalid old controller!" ); 4112 4113 // a guard which will clean up in case of failure 4114 ::sfx::intern::ViewCreationGuard aViewCreationGuard; 4115 4116 // determine the ViewFrame belonging to the given XFrame 4117 SfxViewFrame* pViewFrame = FindOrCreateViewFrame_Impl( i_rFrame, aViewCreationGuard ); 4118 OSL_POSTCOND( pViewFrame, "SfxBaseModel::createViewController: no frame?" ); 4119 4120 // delegate to SFX' view factory 4121 pViewFrame->GetBindings().ENTERREGISTRATIONS(); 4122 SfxViewShell* pViewShell = pViewFactory->CreateInstance( pViewFrame, pOldViewShell ); 4123 pViewFrame->GetBindings().LEAVEREGISTRATIONS(); 4124 ENSURE_OR_THROW( pViewShell, "invalid view shell provided by factory" ); 4125 4126 // by setting the ViewShell it is prevented that disposing the Controller will destroy this ViewFrame also 4127 pViewFrame->GetDispatcher()->SetDisableFlags( 0 ); 4128 pViewFrame->SetViewShell_Impl( pViewShell ); 4129 4130 // remember ViewID 4131 pViewFrame->SetCurViewId_Impl( pViewFactory->GetOrdinal() ); 4132 4133 // ensure a default controller, if the view shell did not provide an own implementation 4134 if ( !pViewShell->GetController().is() ) 4135 pViewShell->SetController( new SfxBaseController( pViewShell ) ); 4136 4137 // pass the creation arguments to the controller 4138 SfxBaseController* pBaseController = pViewShell->GetBaseController_Impl(); 4139 ENSURE_OR_THROW( pBaseController, "invalid controller implementation!" ); 4140 pBaseController->SetCreationArguments_Impl( i_rArguments ); 4141 4142 // some initial view settings, coming from our most recent attachResource call 4143 ::comphelper::NamedValueCollection aDocumentLoadArgs( getArgs() ); 4144 if ( aDocumentLoadArgs.getOrDefault( "ViewOnly", false ) ) 4145 pViewFrame->GetFrame().SetMenuBarOn_Impl( sal_False ); 4146 4147 const sal_Int16 nPluginMode = aDocumentLoadArgs.getOrDefault( "PluginMode", sal_Int16( 0 ) ); 4148 if ( nPluginMode == 1 ) 4149 { 4150 pViewFrame->ForceOuterResize_Impl( sal_False ); 4151 pViewFrame->GetBindings().HidePopups( sal_True ); 4152 4153 SfxFrame& rFrame = pViewFrame->GetFrame(); 4154 // MBA: layoutmanager of inplace frame starts locked and invisible 4155 rFrame.GetWorkWindow_Impl()->MakeVisible_Impl( sal_False ); 4156 rFrame.GetWorkWindow_Impl()->Lock_Impl( sal_True ); 4157 4158 rFrame.GetWindow().SetBorderStyle( WINDOW_BORDER_NOBORDER ); 4159 pViewFrame->GetWindow().SetBorderStyle( WINDOW_BORDER_NOBORDER ); 4160 } 4161 4162 // tell the guard we were successful 4163 aViewCreationGuard.releaseAll(); 4164 4165 // outta gere 4166 return pBaseController; 4167 } 4168 4169 //============================================================================= 4170 // RDF DocumentMetadataAccess 4171 4172 // ::com::sun::star::rdf::XRepositorySupplier: 4173 uno::Reference< rdf::XRepository > SAL_CALL 4174 SfxBaseModel::getRDFRepository() throw (uno::RuntimeException) 4175 { 4176 SfxModelGuard aGuard( *this ); 4177 4178 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA()); 4179 if (!xDMA.is()) { 4180 throw uno::RuntimeException( ::rtl::OUString::createFromAscii( 4181 "model has no document metadata"), *this ); 4182 } 4183 4184 return xDMA->getRDFRepository(); 4185 } 4186 4187 // ::com::sun::star::rdf::XNode: 4188 ::rtl::OUString SAL_CALL 4189 SfxBaseModel::getStringValue() throw (uno::RuntimeException) 4190 { 4191 SfxModelGuard aGuard( *this ); 4192 4193 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA()); 4194 if (!xDMA.is()) { 4195 throw uno::RuntimeException( ::rtl::OUString::createFromAscii( 4196 "model has no document metadata"), *this ); 4197 } 4198 4199 return xDMA->getStringValue(); 4200 } 4201 4202 // ::com::sun::star::rdf::XURI: 4203 ::rtl::OUString SAL_CALL 4204 SfxBaseModel::getNamespace() throw (uno::RuntimeException) 4205 { 4206 SfxModelGuard aGuard( *this ); 4207 4208 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA()); 4209 if (!xDMA.is()) { 4210 throw uno::RuntimeException( ::rtl::OUString::createFromAscii( 4211 "model has no document metadata"), *this ); 4212 } 4213 4214 return xDMA->getNamespace(); 4215 } 4216 4217 ::rtl::OUString SAL_CALL 4218 SfxBaseModel::getLocalName() throw (uno::RuntimeException) 4219 { 4220 SfxModelGuard aGuard( *this ); 4221 4222 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA()); 4223 if (!xDMA.is()) { 4224 throw uno::RuntimeException( ::rtl::OUString::createFromAscii( 4225 "model has no document metadata"), *this ); 4226 } 4227 4228 return xDMA->getLocalName(); 4229 } 4230 4231 // ::com::sun::star::rdf::XDocumentMetadataAccess: 4232 uno::Reference< rdf::XMetadatable > SAL_CALL 4233 SfxBaseModel::getElementByMetadataReference( 4234 const ::com::sun::star::beans::StringPair & i_rReference) 4235 throw (uno::RuntimeException) 4236 { 4237 SfxModelGuard aGuard( *this ); 4238 4239 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA()); 4240 if (!xDMA.is()) { 4241 throw uno::RuntimeException( ::rtl::OUString::createFromAscii( 4242 "model has no document metadata"), *this ); 4243 } 4244 4245 return xDMA->getElementByMetadataReference(i_rReference); 4246 } 4247 4248 uno::Reference< rdf::XMetadatable > SAL_CALL 4249 SfxBaseModel::getElementByURI(const uno::Reference< rdf::XURI > & i_xURI) 4250 throw (uno::RuntimeException, lang::IllegalArgumentException) 4251 { 4252 SfxModelGuard aGuard( *this ); 4253 4254 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA()); 4255 if (!xDMA.is()) { 4256 throw uno::RuntimeException( ::rtl::OUString::createFromAscii( 4257 "model has no document metadata"), *this ); 4258 } 4259 4260 return xDMA->getElementByURI(i_xURI); 4261 } 4262 4263 uno::Sequence< uno::Reference< rdf::XURI > > SAL_CALL 4264 SfxBaseModel::getMetadataGraphsWithType( 4265 const uno::Reference<rdf::XURI> & i_xType) 4266 throw (uno::RuntimeException, lang::IllegalArgumentException) 4267 { 4268 SfxModelGuard aGuard( *this ); 4269 4270 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA()); 4271 if (!xDMA.is()) { 4272 throw uno::RuntimeException( ::rtl::OUString::createFromAscii( 4273 "model has no document metadata"), *this ); 4274 } 4275 4276 return xDMA->getMetadataGraphsWithType(i_xType); 4277 } 4278 4279 uno::Reference<rdf::XURI> SAL_CALL 4280 SfxBaseModel::addMetadataFile(const ::rtl::OUString & i_rFileName, 4281 const uno::Sequence < uno::Reference< rdf::XURI > > & i_rTypes) 4282 throw (uno::RuntimeException, lang::IllegalArgumentException, 4283 container::ElementExistException) 4284 { 4285 SfxModelGuard aGuard( *this ); 4286 4287 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA()); 4288 if (!xDMA.is()) { 4289 throw uno::RuntimeException( ::rtl::OUString::createFromAscii( 4290 "model has no document metadata"), *this ); 4291 } 4292 4293 return xDMA->addMetadataFile(i_rFileName, i_rTypes); 4294 } 4295 4296 uno::Reference<rdf::XURI> SAL_CALL 4297 SfxBaseModel::importMetadataFile(::sal_Int16 i_Format, 4298 const uno::Reference< io::XInputStream > & i_xInStream, 4299 const ::rtl::OUString & i_rFileName, 4300 const uno::Reference< rdf::XURI > & i_xBaseURI, 4301 const uno::Sequence < uno::Reference< rdf::XURI > > & i_rTypes) 4302 throw (uno::RuntimeException, lang::IllegalArgumentException, 4303 datatransfer::UnsupportedFlavorException, 4304 container::ElementExistException, rdf::ParseException, io::IOException) 4305 { 4306 SfxModelGuard aGuard( *this ); 4307 4308 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA()); 4309 if (!xDMA.is()) { 4310 throw uno::RuntimeException( ::rtl::OUString::createFromAscii( 4311 "model has no document metadata"), *this ); 4312 } 4313 4314 return xDMA->importMetadataFile(i_Format, 4315 i_xInStream, i_rFileName, i_xBaseURI, i_rTypes); 4316 } 4317 4318 void SAL_CALL 4319 SfxBaseModel::removeMetadataFile( 4320 const uno::Reference< rdf::XURI > & i_xGraphName) 4321 throw (uno::RuntimeException, lang::IllegalArgumentException, 4322 container::NoSuchElementException) 4323 { 4324 SfxModelGuard aGuard( *this ); 4325 4326 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA()); 4327 if (!xDMA.is()) { 4328 throw uno::RuntimeException( ::rtl::OUString::createFromAscii( 4329 "model has no document metadata"), *this ); 4330 } 4331 4332 return xDMA->removeMetadataFile(i_xGraphName); 4333 } 4334 4335 void SAL_CALL 4336 SfxBaseModel::addContentOrStylesFile(const ::rtl::OUString & i_rFileName) 4337 throw (uno::RuntimeException, lang::IllegalArgumentException, 4338 container::ElementExistException) 4339 { 4340 SfxModelGuard aGuard( *this ); 4341 4342 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA()); 4343 if (!xDMA.is()) { 4344 throw uno::RuntimeException( ::rtl::OUString::createFromAscii( 4345 "model has no document metadata"), *this ); 4346 } 4347 4348 return xDMA->addContentOrStylesFile(i_rFileName); 4349 } 4350 4351 void SAL_CALL 4352 SfxBaseModel::removeContentOrStylesFile(const ::rtl::OUString & i_rFileName) 4353 throw (uno::RuntimeException, lang::IllegalArgumentException, 4354 container::NoSuchElementException) 4355 { 4356 SfxModelGuard aGuard( *this ); 4357 4358 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA()); 4359 if (!xDMA.is()) { 4360 throw uno::RuntimeException( ::rtl::OUString::createFromAscii( 4361 "model has no document metadata"), *this ); 4362 } 4363 4364 return xDMA->removeContentOrStylesFile(i_rFileName); 4365 } 4366 4367 void SAL_CALL 4368 SfxBaseModel::loadMetadataFromStorage( 4369 uno::Reference< embed::XStorage > const & i_xStorage, 4370 uno::Reference<rdf::XURI> const & i_xBaseURI, 4371 uno::Reference<task::XInteractionHandler> const & i_xHandler) 4372 throw (uno::RuntimeException, lang::IllegalArgumentException, 4373 lang::WrappedTargetException) 4374 { 4375 SfxModelGuard aGuard( *this ); 4376 4377 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA( 4378 m_pData->CreateDMAUninitialized()); 4379 if (!xDMA.is()) { 4380 throw uno::RuntimeException( ::rtl::OUString::createFromAscii( 4381 "model has no document metadata"), *this ); 4382 } 4383 4384 try { 4385 xDMA->loadMetadataFromStorage(i_xStorage, i_xBaseURI, i_xHandler); 4386 } catch (lang::IllegalArgumentException &) { 4387 throw; // not initialized 4388 } catch (uno::Exception &) { 4389 // UGLY: if it's a RuntimeException, we can't be sure DMA is initialzed 4390 m_pData->m_xDocumentMetadata = xDMA; 4391 throw; 4392 } 4393 m_pData->m_xDocumentMetadata = xDMA; 4394 4395 } 4396 4397 void SAL_CALL 4398 SfxBaseModel::storeMetadataToStorage( 4399 uno::Reference< embed::XStorage > const & i_xStorage) 4400 throw (uno::RuntimeException, lang::IllegalArgumentException, 4401 lang::WrappedTargetException) 4402 { 4403 SfxModelGuard aGuard( *this ); 4404 4405 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA()); 4406 if (!xDMA.is()) { 4407 throw uno::RuntimeException( ::rtl::OUString::createFromAscii( 4408 "model has no document metadata"), *this ); 4409 } 4410 4411 return xDMA->storeMetadataToStorage(i_xStorage); 4412 } 4413 4414 void SAL_CALL 4415 SfxBaseModel::loadMetadataFromMedium( 4416 const uno::Sequence< beans::PropertyValue > & i_rMedium) 4417 throw (uno::RuntimeException, lang::IllegalArgumentException, 4418 lang::WrappedTargetException) 4419 { 4420 SfxModelGuard aGuard( *this ); 4421 4422 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA( 4423 m_pData->CreateDMAUninitialized()); 4424 if (!xDMA.is()) { 4425 throw uno::RuntimeException( ::rtl::OUString::createFromAscii( 4426 "model has no document metadata"), *this ); 4427 } 4428 4429 try { 4430 xDMA->loadMetadataFromMedium(i_rMedium); 4431 } catch (lang::IllegalArgumentException &) { 4432 throw; // not initialized 4433 } catch (uno::Exception &) { 4434 // UGLY: if it's a RuntimeException, we can't be sure DMA is initialzed 4435 m_pData->m_xDocumentMetadata = xDMA; 4436 throw; 4437 } 4438 m_pData->m_xDocumentMetadata = xDMA; 4439 } 4440 4441 void SAL_CALL 4442 SfxBaseModel::storeMetadataToMedium( 4443 const uno::Sequence< beans::PropertyValue > & i_rMedium) 4444 throw (uno::RuntimeException, lang::IllegalArgumentException, 4445 lang::WrappedTargetException) 4446 { 4447 SfxModelGuard aGuard( *this ); 4448 4449 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA()); 4450 if (!xDMA.is()) { 4451 throw uno::RuntimeException( ::rtl::OUString::createFromAscii( 4452 "model has no document metadata"), *this ); 4453 } 4454 4455 return xDMA->storeMetadataToMedium(i_rMedium); 4456 } 4457 4458 // ===================================================================================================================== 4459 // = SfxModelSubComponent 4460 // ===================================================================================================================== 4461 4462 SfxModelSubComponent::~SfxModelSubComponent() 4463 { 4464 } 4465 4466 void SfxModelSubComponent::disposing() 4467 { 4468 // nothing to do here 4469 } 4470 4471