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