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_basctl.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "scriptdocument.hxx" 32*cdf0e10cSrcweir #include "basobj.hxx" 33*cdf0e10cSrcweir #include "basidesh.hrc" 34*cdf0e10cSrcweir #include "iderid.hxx" 35*cdf0e10cSrcweir #include "dlgeddef.hxx" 36*cdf0e10cSrcweir #include "localizationmgr.hxx" 37*cdf0e10cSrcweir #include "doceventnotifier.hxx" 38*cdf0e10cSrcweir #include "documentenumeration.hxx" 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir /** === begin UNO includes === **/ 41*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 42*cdf0e10cSrcweir #include <com/sun/star/script/XLibraryContainer2.hpp> 43*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 44*cdf0e10cSrcweir #include <com/sun/star/uri/XUriReferenceFactory.hpp> 45*cdf0e10cSrcweir #include <com/sun/star/util/XMacroExpander.hpp> 46*cdf0e10cSrcweir #include <com/sun/star/document/MacroExecMode.hpp> 47*cdf0e10cSrcweir #include <com/sun/star/document/XEventBroadcaster.hpp> 48*cdf0e10cSrcweir #include <com/sun/star/frame/XStorable.hpp> 49*cdf0e10cSrcweir #include <com/sun/star/util/XModifiable.hpp> 50*cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProvider.hpp> 51*cdf0e10cSrcweir #include <com/sun/star/frame/FrameSearchFlag.hpp> 52*cdf0e10cSrcweir #include <com/sun/star/frame/XDesktop.hpp> 53*cdf0e10cSrcweir #include <com/sun/star/frame/XModel2.hpp> 54*cdf0e10cSrcweir #include <com/sun/star/awt/XWindow2.hpp> 55*cdf0e10cSrcweir #include <com/sun/star/document/XEmbeddedScripts.hpp> 56*cdf0e10cSrcweir #include <com/sun/star/script/vba/XVBACompatibility.hpp> 57*cdf0e10cSrcweir #include <com/sun/star/script/vba/XVBAModuleInfo.hpp> 58*cdf0e10cSrcweir /** === end UNO includes === **/ 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir #include <sfx2/objsh.hxx> 61*cdf0e10cSrcweir #include <sfx2/app.hxx> 62*cdf0e10cSrcweir #include <sfx2/viewfrm.hxx> 63*cdf0e10cSrcweir #include <sfx2/bindings.hxx> 64*cdf0e10cSrcweir #include <sfx2/docfile.hxx> 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir #include <vcl/svapp.hxx> 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir #include <basic/basicmanagerrepository.hxx> 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir #include <xmlscript/xmldlg_imexp.hxx> 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir #include <unotools/syslocale.hxx> 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir #include <unotools/collatorwrapper.hxx> 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir #include <tools/diagnose_ex.h> 77*cdf0e10cSrcweir #include <tools/urlobj.hxx> 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 80*cdf0e10cSrcweir #include <comphelper/documentinfo.hxx> 81*cdf0e10cSrcweir #include <comphelper/componentcontext.hxx> 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir #include <vos/mutex.hxx> 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir #include <rtl/uri.hxx> 88*cdf0e10cSrcweir #include <rtl/bootstrap.hxx> 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir #include <osl/process.h> 91*cdf0e10cSrcweir #include <osl/file.hxx> 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir #include <algorithm> 94*cdf0e10cSrcweir #include <functional> 95*cdf0e10cSrcweir #include <set> 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir //........................................................................ 98*cdf0e10cSrcweir namespace basctl 99*cdf0e10cSrcweir { 100*cdf0e10cSrcweir //........................................................................ 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir /** === begin UNO using === **/ 103*cdf0e10cSrcweir using ::com::sun::star::uno::Sequence; 104*cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 105*cdf0e10cSrcweir using ::com::sun::star::frame::XModel; 106*cdf0e10cSrcweir using ::com::sun::star::beans::XPropertySet; 107*cdf0e10cSrcweir using ::com::sun::star::script::XLibraryContainer; 108*cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY_THROW; 109*cdf0e10cSrcweir using ::com::sun::star::uno::UNO_SET_THROW; 110*cdf0e10cSrcweir using ::com::sun::star::beans::XPropertySetInfo; 111*cdf0e10cSrcweir using ::com::sun::star::uno::Exception; 112*cdf0e10cSrcweir using ::com::sun::star::container::XNameContainer; 113*cdf0e10cSrcweir using ::com::sun::star::container::NoSuchElementException; 114*cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY; 115*cdf0e10cSrcweir using ::com::sun::star::task::XStatusIndicator; 116*cdf0e10cSrcweir using ::com::sun::star::uno::makeAny; 117*cdf0e10cSrcweir using ::com::sun::star::script::XLibraryContainer2; 118*cdf0e10cSrcweir using ::com::sun::star::lang::XMultiServiceFactory; 119*cdf0e10cSrcweir using ::com::sun::star::uri::XUriReferenceFactory; 120*cdf0e10cSrcweir using ::com::sun::star::uri::XUriReference; 121*cdf0e10cSrcweir using ::com::sun::star::uno::XComponentContext; 122*cdf0e10cSrcweir using ::com::sun::star::util::XMacroExpander; 123*cdf0e10cSrcweir using ::com::sun::star::io::XInputStreamProvider; 124*cdf0e10cSrcweir using ::com::sun::star::uno::Any; 125*cdf0e10cSrcweir using ::com::sun::star::io::XInputStream; 126*cdf0e10cSrcweir using ::com::sun::star::frame::XStorable; 127*cdf0e10cSrcweir using ::com::sun::star::util::XModifiable; 128*cdf0e10cSrcweir using ::com::sun::star::frame::XController; 129*cdf0e10cSrcweir using ::com::sun::star::frame::XFrame; 130*cdf0e10cSrcweir using ::com::sun::star::util::URL; 131*cdf0e10cSrcweir using ::com::sun::star::frame::XDispatchProvider; 132*cdf0e10cSrcweir using ::com::sun::star::frame::XDispatch; 133*cdf0e10cSrcweir using ::com::sun::star::beans::PropertyValue; 134*cdf0e10cSrcweir using ::com::sun::star::frame::XDesktop; 135*cdf0e10cSrcweir using ::com::sun::star::container::XEnumerationAccess; 136*cdf0e10cSrcweir using ::com::sun::star::container::XEnumeration; 137*cdf0e10cSrcweir using ::com::sun::star::frame::XModel2; 138*cdf0e10cSrcweir using ::com::sun::star::awt::XWindow2; 139*cdf0e10cSrcweir using ::com::sun::star::document::XEventListener; 140*cdf0e10cSrcweir using ::com::sun::star::lang::EventObject; 141*cdf0e10cSrcweir using ::com::sun::star::uno::RuntimeException; 142*cdf0e10cSrcweir using ::com::sun::star::document::XEventBroadcaster; 143*cdf0e10cSrcweir using ::com::sun::star::document::XEmbeddedScripts; 144*cdf0e10cSrcweir using ::com::sun::star::script::ModuleInfo; 145*cdf0e10cSrcweir using ::com::sun::star::script::vba::XVBACompatibility; 146*cdf0e10cSrcweir using ::com::sun::star::script::vba::XVBAModuleInfo; 147*cdf0e10cSrcweir /** === end UNO using === **/ 148*cdf0e10cSrcweir namespace MacroExecMode = ::com::sun::star::document::MacroExecMode; 149*cdf0e10cSrcweir namespace FrameSearchFlag = ::com::sun::star::frame::FrameSearchFlag; 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir //==================================================================== 152*cdf0e10cSrcweir //= helper 153*cdf0e10cSrcweir //==================================================================== 154*cdf0e10cSrcweir namespace 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir //................................................................ 157*cdf0e10cSrcweir static bool StringCompareLessThan( const String& lhs, const String& rhs ) 158*cdf0e10cSrcweir { 159*cdf0e10cSrcweir return ( lhs.CompareIgnoreCaseToAscii( rhs ) == COMPARE_LESS ); 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir //................................................................ 163*cdf0e10cSrcweir class FilterDocuments : public docs::IDocumentDescriptorFilter 164*cdf0e10cSrcweir { 165*cdf0e10cSrcweir public: 166*cdf0e10cSrcweir FilterDocuments( bool _bFilterInvisible ) : m_bFilterInvisible( _bFilterInvisible ) { } 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir virtual bool includeDocument( const docs::DocumentDescriptor& _rDocument ) const; 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir private: 171*cdf0e10cSrcweir bool impl_isDocumentVisible_nothrow( const docs::DocumentDescriptor& _rDocument ) const; 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir private: 174*cdf0e10cSrcweir bool m_bFilterInvisible; 175*cdf0e10cSrcweir }; 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir //................................................................ 178*cdf0e10cSrcweir bool FilterDocuments::impl_isDocumentVisible_nothrow( const docs::DocumentDescriptor& _rDocument ) const 179*cdf0e10cSrcweir { 180*cdf0e10cSrcweir try 181*cdf0e10cSrcweir { 182*cdf0e10cSrcweir for ( docs::Controllers::const_iterator controller = _rDocument.aControllers.begin(); 183*cdf0e10cSrcweir controller != _rDocument.aControllers.end(); 184*cdf0e10cSrcweir ++controller 185*cdf0e10cSrcweir ) 186*cdf0e10cSrcweir { 187*cdf0e10cSrcweir Reference< XFrame > xFrame( (*controller)->getFrame(), UNO_SET_THROW ); 188*cdf0e10cSrcweir Reference< XWindow2 > xContainer( xFrame->getContainerWindow(), UNO_QUERY_THROW ); 189*cdf0e10cSrcweir if ( xContainer->isVisible() ) 190*cdf0e10cSrcweir return true; 191*cdf0e10cSrcweir } 192*cdf0e10cSrcweir } 193*cdf0e10cSrcweir catch( const Exception& ) 194*cdf0e10cSrcweir { 195*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 196*cdf0e10cSrcweir } 197*cdf0e10cSrcweir return false; 198*cdf0e10cSrcweir } 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir //................................................................ 201*cdf0e10cSrcweir bool FilterDocuments::includeDocument( const docs::DocumentDescriptor& _rDocument ) const 202*cdf0e10cSrcweir { 203*cdf0e10cSrcweir Reference< XEmbeddedScripts > xScripts( _rDocument.xModel, UNO_QUERY ); 204*cdf0e10cSrcweir if ( !xScripts.is() ) 205*cdf0e10cSrcweir return false; 206*cdf0e10cSrcweir if ( !m_bFilterInvisible || impl_isDocumentVisible_nothrow( _rDocument ) ) 207*cdf0e10cSrcweir return true; 208*cdf0e10cSrcweir return false; 209*cdf0e10cSrcweir } 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir //................................................................ 212*cdf0e10cSrcweir void lcl_getAllModels_throw( docs::Documents& _out_rModels, bool _bVisibleOnly ) 213*cdf0e10cSrcweir { 214*cdf0e10cSrcweir _out_rModels.clear(); 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() ); 217*cdf0e10cSrcweir FilterDocuments aFilter( _bVisibleOnly ); 218*cdf0e10cSrcweir docs::DocumentEnumeration aEnum( aContext, &aFilter ); 219*cdf0e10cSrcweir 220*cdf0e10cSrcweir aEnum.getDocuments( _out_rModels ); 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir } 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir //==================================================================== 225*cdf0e10cSrcweir //= ScriptDocument_Impl - declaration 226*cdf0e10cSrcweir //==================================================================== 227*cdf0e10cSrcweir class ScriptDocument_Impl : public DocumentEventListener 228*cdf0e10cSrcweir { 229*cdf0e10cSrcweir private: 230*cdf0e10cSrcweir bool m_bIsApplication; 231*cdf0e10cSrcweir bool m_bValid; 232*cdf0e10cSrcweir bool m_bDocumentClosed; 233*cdf0e10cSrcweir Reference< XModel > m_xDocument; 234*cdf0e10cSrcweir Reference< XModifiable > m_xDocModify; 235*cdf0e10cSrcweir Reference< XEmbeddedScripts > m_xScriptAccess; 236*cdf0e10cSrcweir ::std::auto_ptr< DocumentEventNotifier > 237*cdf0e10cSrcweir m_pDocListener; 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir public: 240*cdf0e10cSrcweir ScriptDocument_Impl( ); 241*cdf0e10cSrcweir ScriptDocument_Impl( const Reference< XModel >& _rxDocument ); 242*cdf0e10cSrcweir ~ScriptDocument_Impl(); 243*cdf0e10cSrcweir 244*cdf0e10cSrcweir /** determines whether the instance refers to a valid "document" with script and 245*cdf0e10cSrcweir dialog libraries 246*cdf0e10cSrcweir */ 247*cdf0e10cSrcweir inline bool isValid() const { return m_bValid; } 248*cdf0e10cSrcweir /** determines whether the instance refers to a non-closed document 249*cdf0e10cSrcweir */ 250*cdf0e10cSrcweir inline bool isAlive() const { return m_bValid ? ( m_bIsApplication ? true : !m_bDocumentClosed ) : false; } 251*cdf0e10cSrcweir /// determines whether the "document" refers to the application in real 252*cdf0e10cSrcweir inline bool isApplication() const { return m_bValid && m_bIsApplication; } 253*cdf0e10cSrcweir /// determines whether the document refers to a real document (instead of the application) 254*cdf0e10cSrcweir inline bool isDocument() const { return m_bValid && !m_bIsApplication; } 255*cdf0e10cSrcweir 256*cdf0e10cSrcweir /** invalidates the instance 257*cdf0e10cSrcweir */ 258*cdf0e10cSrcweir void invalidate(); 259*cdf0e10cSrcweir 260*cdf0e10cSrcweir const Reference< XModel >& 261*cdf0e10cSrcweir getDocumentRef() const { return m_xDocument; } 262*cdf0e10cSrcweir 263*cdf0e10cSrcweir /// returns a library container belonging to the document 264*cdf0e10cSrcweir Reference< XLibraryContainer > 265*cdf0e10cSrcweir getLibraryContainer( LibraryContainerType _eType ) const; 266*cdf0e10cSrcweir 267*cdf0e10cSrcweir /// determines whether a given library is part of the shared installation 268*cdf0e10cSrcweir bool isLibraryShared( const ::rtl::OUString& _rLibName, LibraryContainerType _eType ); 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir /** returns the current frame of the document 271*cdf0e10cSrcweir 272*cdf0e10cSrcweir To be called for documents only, not for the application. 273*cdf0e10cSrcweir 274*cdf0e10cSrcweir If <FALSE/> is returned, an assertion will be raised in non-product builds. 275*cdf0e10cSrcweir */ 276*cdf0e10cSrcweir bool getCurrentFrame( Reference< XFrame >& _out_rxFrame ) const; 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir // versions with the same signature/semantics as in ScriptDocument itself 279*cdf0e10cSrcweir bool isReadOnly() const; 280*cdf0e10cSrcweir bool isInVBAMode() const; 281*cdf0e10cSrcweir BasicManager* 282*cdf0e10cSrcweir getBasicManager() const; 283*cdf0e10cSrcweir Reference< XModel > 284*cdf0e10cSrcweir getDocument() const; 285*cdf0e10cSrcweir void setDocumentModified() const; 286*cdf0e10cSrcweir bool isDocumentModified() const; 287*cdf0e10cSrcweir bool saveDocument( const Reference< XStatusIndicator >& _rxStatusIndicator ) const; 288*cdf0e10cSrcweir 289*cdf0e10cSrcweir ::rtl::OUString 290*cdf0e10cSrcweir getTitle() const; 291*cdf0e10cSrcweir ::rtl::OUString 292*cdf0e10cSrcweir getURL() const; 293*cdf0e10cSrcweir 294*cdf0e10cSrcweir bool allowMacros() const; 295*cdf0e10cSrcweir 296*cdf0e10cSrcweir Reference< XNameContainer > 297*cdf0e10cSrcweir getLibrary( LibraryContainerType _eType, const ::rtl::OUString& _rLibName, bool _bLoadLibrary ) const 298*cdf0e10cSrcweir SAL_THROW((NoSuchElementException)); 299*cdf0e10cSrcweir bool hasLibrary( LibraryContainerType _eType, const ::rtl::OUString& _rLibName ) const; 300*cdf0e10cSrcweir Reference< XNameContainer > 301*cdf0e10cSrcweir getOrCreateLibrary( LibraryContainerType _eType, const ::rtl::OUString& _rLibName ) const; 302*cdf0e10cSrcweir 303*cdf0e10cSrcweir void loadLibraryIfExists( LibraryContainerType _eType, const ::rtl::OUString& _rLibrary ); 304*cdf0e10cSrcweir 305*cdf0e10cSrcweir bool removeModuleOrDialog( LibraryContainerType _eType, const ::rtl::OUString& _rLibName, const ::rtl::OUString& _rModuleName ); 306*cdf0e10cSrcweir bool hasModuleOrDialog( LibraryContainerType _eType, const ::rtl::OUString& _rLibName, const ::rtl::OUString& _rModName ) const; 307*cdf0e10cSrcweir bool getModuleOrDialog( LibraryContainerType _eType, const ::rtl::OUString& _rLibName, const ::rtl::OUString& _rObjectName, Any& _out_rModuleOrDialog ); 308*cdf0e10cSrcweir bool renameModuleOrDialog( LibraryContainerType _eType, const ::rtl::OUString& _rLibName, const ::rtl::OUString& _rOldName, const ::rtl::OUString& _rNewName, const Reference< XNameContainer >& _rxExistingDialogModel ); 309*cdf0e10cSrcweir bool createModule( const ::rtl::OUString& _rLibName, const ::rtl::OUString& _rModName, bool _bCreateMain, ::rtl::OUString& _out_rNewModuleCode ) const; 310*cdf0e10cSrcweir bool insertModuleOrDialog( LibraryContainerType _eType, const ::rtl::OUString& _rObjectName, const ::rtl::OUString& _rModName, const Any& _rElement ) const; 311*cdf0e10cSrcweir bool updateModule( const ::rtl::OUString& _rLibName, const ::rtl::OUString& _rModName, const ::rtl::OUString& _rModuleCode ) const; 312*cdf0e10cSrcweir bool createDialog( const ::rtl::OUString& _rLibName, const ::rtl::OUString& _rDialogName, Reference< XInputStreamProvider >& _out_rDialogProvider ) const; 313*cdf0e10cSrcweir 314*cdf0e10cSrcweir protected: 315*cdf0e10cSrcweir // DocumentEventListener 316*cdf0e10cSrcweir virtual void onDocumentCreated( const ScriptDocument& _rDocument ); 317*cdf0e10cSrcweir virtual void onDocumentOpened( const ScriptDocument& _rDocument ); 318*cdf0e10cSrcweir virtual void onDocumentSave( const ScriptDocument& _rDocument ); 319*cdf0e10cSrcweir virtual void onDocumentSaveDone( const ScriptDocument& _rDocument ); 320*cdf0e10cSrcweir virtual void onDocumentSaveAs( const ScriptDocument& _rDocument ); 321*cdf0e10cSrcweir virtual void onDocumentSaveAsDone( const ScriptDocument& _rDocument ); 322*cdf0e10cSrcweir virtual void onDocumentClosed( const ScriptDocument& _rDocument ); 323*cdf0e10cSrcweir virtual void onDocumentTitleChanged( const ScriptDocument& _rDocument ); 324*cdf0e10cSrcweir virtual void onDocumentModeChanged( const ScriptDocument& _rDocument ); 325*cdf0e10cSrcweir 326*cdf0e10cSrcweir private: 327*cdf0e10cSrcweir bool impl_initDocument_nothrow( const Reference< XModel >& _rxModel ); 328*cdf0e10cSrcweir }; 329*cdf0e10cSrcweir 330*cdf0e10cSrcweir //==================================================================== 331*cdf0e10cSrcweir //= ScriptDocument_Impl - implementation 332*cdf0e10cSrcweir //==================================================================== 333*cdf0e10cSrcweir //-------------------------------------------------------------------- 334*cdf0e10cSrcweir ScriptDocument_Impl::ScriptDocument_Impl() 335*cdf0e10cSrcweir :m_bIsApplication( true ) 336*cdf0e10cSrcweir ,m_bValid( true ) 337*cdf0e10cSrcweir ,m_bDocumentClosed( false ) 338*cdf0e10cSrcweir { 339*cdf0e10cSrcweir } 340*cdf0e10cSrcweir 341*cdf0e10cSrcweir //-------------------------------------------------------------------- 342*cdf0e10cSrcweir ScriptDocument_Impl::ScriptDocument_Impl( const Reference< XModel >& _rxDocument ) 343*cdf0e10cSrcweir :m_bIsApplication( false ) 344*cdf0e10cSrcweir ,m_bValid( false ) 345*cdf0e10cSrcweir ,m_bDocumentClosed( false ) 346*cdf0e10cSrcweir { 347*cdf0e10cSrcweir if ( _rxDocument.is() ) 348*cdf0e10cSrcweir { 349*cdf0e10cSrcweir if ( impl_initDocument_nothrow( _rxDocument ) ) 350*cdf0e10cSrcweir { 351*cdf0e10cSrcweir } 352*cdf0e10cSrcweir } 353*cdf0e10cSrcweir } 354*cdf0e10cSrcweir 355*cdf0e10cSrcweir //-------------------------------------------------------------------- 356*cdf0e10cSrcweir ScriptDocument_Impl::~ScriptDocument_Impl() 357*cdf0e10cSrcweir { 358*cdf0e10cSrcweir invalidate(); 359*cdf0e10cSrcweir } 360*cdf0e10cSrcweir 361*cdf0e10cSrcweir //-------------------------------------------------------------------- 362*cdf0e10cSrcweir void ScriptDocument_Impl::invalidate() 363*cdf0e10cSrcweir { 364*cdf0e10cSrcweir m_bIsApplication = false; 365*cdf0e10cSrcweir m_bValid = false; 366*cdf0e10cSrcweir m_bDocumentClosed = false; 367*cdf0e10cSrcweir 368*cdf0e10cSrcweir m_xDocument.clear(); 369*cdf0e10cSrcweir m_xDocModify.clear(); 370*cdf0e10cSrcweir m_xScriptAccess.clear(); 371*cdf0e10cSrcweir 372*cdf0e10cSrcweir if ( m_pDocListener.get() ) 373*cdf0e10cSrcweir m_pDocListener->dispose(); 374*cdf0e10cSrcweir } 375*cdf0e10cSrcweir 376*cdf0e10cSrcweir //-------------------------------------------------------------------- 377*cdf0e10cSrcweir bool ScriptDocument_Impl::impl_initDocument_nothrow( const Reference< XModel >& _rxModel ) 378*cdf0e10cSrcweir { 379*cdf0e10cSrcweir try 380*cdf0e10cSrcweir { 381*cdf0e10cSrcweir m_xDocument.set ( _rxModel, UNO_SET_THROW ); 382*cdf0e10cSrcweir m_xDocModify.set ( _rxModel, UNO_QUERY_THROW ); 383*cdf0e10cSrcweir m_xScriptAccess.set ( _rxModel, UNO_QUERY ); 384*cdf0e10cSrcweir 385*cdf0e10cSrcweir m_bValid = m_xScriptAccess.is(); 386*cdf0e10cSrcweir 387*cdf0e10cSrcweir if ( m_bValid ) 388*cdf0e10cSrcweir m_pDocListener.reset( new DocumentEventNotifier( *this, _rxModel ) ); 389*cdf0e10cSrcweir } 390*cdf0e10cSrcweir catch( const Exception& ) 391*cdf0e10cSrcweir { 392*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 393*cdf0e10cSrcweir m_bValid = false; 394*cdf0e10cSrcweir } 395*cdf0e10cSrcweir 396*cdf0e10cSrcweir if ( !m_bValid ) 397*cdf0e10cSrcweir { 398*cdf0e10cSrcweir invalidate(); 399*cdf0e10cSrcweir } 400*cdf0e10cSrcweir 401*cdf0e10cSrcweir return m_bValid; 402*cdf0e10cSrcweir } 403*cdf0e10cSrcweir //-------------------------------------------------------------------- 404*cdf0e10cSrcweir Reference< XLibraryContainer > ScriptDocument_Impl::getLibraryContainer( LibraryContainerType _eType ) const 405*cdf0e10cSrcweir { 406*cdf0e10cSrcweir OSL_ENSURE( isValid(), "ScriptDocument_Impl::getLibraryContainer: invalid!" ); 407*cdf0e10cSrcweir 408*cdf0e10cSrcweir Reference< XLibraryContainer > xContainer; 409*cdf0e10cSrcweir if ( !isValid() ) 410*cdf0e10cSrcweir return xContainer; 411*cdf0e10cSrcweir 412*cdf0e10cSrcweir try 413*cdf0e10cSrcweir { 414*cdf0e10cSrcweir if ( isApplication() ) 415*cdf0e10cSrcweir xContainer.set( _eType == E_SCRIPTS ? SFX_APP()->GetBasicContainer() : SFX_APP()->GetDialogContainer(), UNO_QUERY_THROW ); 416*cdf0e10cSrcweir else 417*cdf0e10cSrcweir { 418*cdf0e10cSrcweir xContainer.set( 419*cdf0e10cSrcweir _eType == E_SCRIPTS ? m_xScriptAccess->getBasicLibraries() : m_xScriptAccess->getDialogLibraries(), 420*cdf0e10cSrcweir UNO_QUERY_THROW ); 421*cdf0e10cSrcweir } 422*cdf0e10cSrcweir } 423*cdf0e10cSrcweir catch( const Exception& ) 424*cdf0e10cSrcweir { 425*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 426*cdf0e10cSrcweir } 427*cdf0e10cSrcweir return xContainer; 428*cdf0e10cSrcweir } 429*cdf0e10cSrcweir 430*cdf0e10cSrcweir //-------------------------------------------------------------------- 431*cdf0e10cSrcweir bool ScriptDocument_Impl::isReadOnly() const 432*cdf0e10cSrcweir { 433*cdf0e10cSrcweir OSL_ENSURE( isValid(), "ScriptDocument_Impl::isReadOnly: invalid state!" ); 434*cdf0e10cSrcweir OSL_ENSURE( !isApplication(), "ScriptDocument_Impl::isReadOnly: not allowed to be called for the application!" ); 435*cdf0e10cSrcweir 436*cdf0e10cSrcweir bool bIsReadOnly = true; 437*cdf0e10cSrcweir if ( isValid() && !isApplication() ) 438*cdf0e10cSrcweir { 439*cdf0e10cSrcweir try 440*cdf0e10cSrcweir { 441*cdf0e10cSrcweir // note that XStorable is required by the OfficeDocument service 442*cdf0e10cSrcweir Reference< XStorable > xDocStorable( m_xDocument, UNO_QUERY_THROW ); 443*cdf0e10cSrcweir bIsReadOnly = xDocStorable->isReadonly(); 444*cdf0e10cSrcweir } 445*cdf0e10cSrcweir catch( const Exception& ) 446*cdf0e10cSrcweir { 447*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 448*cdf0e10cSrcweir } 449*cdf0e10cSrcweir } 450*cdf0e10cSrcweir return bIsReadOnly; 451*cdf0e10cSrcweir } 452*cdf0e10cSrcweir 453*cdf0e10cSrcweir bool ScriptDocument_Impl::isInVBAMode() const 454*cdf0e10cSrcweir { 455*cdf0e10cSrcweir bool bResult = false; 456*cdf0e10cSrcweir #ifdef FUTURE_VBA_CWS 457*cdf0e10cSrcweir if ( !isApplication() ) 458*cdf0e10cSrcweir { 459*cdf0e10cSrcweir Reference< XVBACompatibility > xVBACompat( getLibraryContainer( E_SCRIPTS ), UNO_QUERY ); 460*cdf0e10cSrcweir if ( xVBACompat.is() ) 461*cdf0e10cSrcweir bResult = xVBACompat->getVBACompatibilityMode(); 462*cdf0e10cSrcweir } 463*cdf0e10cSrcweir #endif 464*cdf0e10cSrcweir return bResult; 465*cdf0e10cSrcweir } 466*cdf0e10cSrcweir 467*cdf0e10cSrcweir //-------------------------------------------------------------------- 468*cdf0e10cSrcweir BasicManager* ScriptDocument_Impl::getBasicManager() const 469*cdf0e10cSrcweir { 470*cdf0e10cSrcweir OSL_ENSURE( isValid(), "ScriptDocument_Impl::getBasicManager: invalid state!" ); 471*cdf0e10cSrcweir if ( !isValid() ) 472*cdf0e10cSrcweir return NULL; 473*cdf0e10cSrcweir 474*cdf0e10cSrcweir if ( isApplication() ) 475*cdf0e10cSrcweir return SFX_APP()->GetBasicManager(); 476*cdf0e10cSrcweir 477*cdf0e10cSrcweir return ::basic::BasicManagerRepository::getDocumentBasicManager( m_xDocument ); 478*cdf0e10cSrcweir } 479*cdf0e10cSrcweir 480*cdf0e10cSrcweir //-------------------------------------------------------------------- 481*cdf0e10cSrcweir Reference< XModel > ScriptDocument_Impl::getDocument() const 482*cdf0e10cSrcweir { 483*cdf0e10cSrcweir OSL_ENSURE( isValid(), "ScriptDocument_Impl::getDocument: invalid state!" ); 484*cdf0e10cSrcweir OSL_ENSURE( isDocument(), "ScriptDocument_Impl::getDocument: for documents only!" ); 485*cdf0e10cSrcweir if ( !isValid() || !isDocument() ) 486*cdf0e10cSrcweir return NULL; 487*cdf0e10cSrcweir 488*cdf0e10cSrcweir return m_xDocument; 489*cdf0e10cSrcweir } 490*cdf0e10cSrcweir 491*cdf0e10cSrcweir //-------------------------------------------------------------------- 492*cdf0e10cSrcweir Reference< XNameContainer > ScriptDocument_Impl::getLibrary( LibraryContainerType _eType, const ::rtl::OUString& _rLibName, bool _bLoadLibrary ) const 493*cdf0e10cSrcweir SAL_THROW((NoSuchElementException)) 494*cdf0e10cSrcweir { 495*cdf0e10cSrcweir OSL_ENSURE( isValid(), "ScriptDocument_Impl::getLibrary: invalid state!" ); 496*cdf0e10cSrcweir 497*cdf0e10cSrcweir Reference< XNameContainer > xContainer; 498*cdf0e10cSrcweir try 499*cdf0e10cSrcweir { 500*cdf0e10cSrcweir Reference< XLibraryContainer > xLibContainer = getLibraryContainer( _eType ); 501*cdf0e10cSrcweir if ( isValid() ) 502*cdf0e10cSrcweir { 503*cdf0e10cSrcweir if ( xLibContainer.is() ) 504*cdf0e10cSrcweir xContainer.set( xLibContainer->getByName( _rLibName ), UNO_QUERY_THROW ); 505*cdf0e10cSrcweir } 506*cdf0e10cSrcweir 507*cdf0e10cSrcweir if ( !xContainer.is() ) 508*cdf0e10cSrcweir throw NoSuchElementException(); 509*cdf0e10cSrcweir 510*cdf0e10cSrcweir // load library 511*cdf0e10cSrcweir if ( _bLoadLibrary && !xLibContainer->isLibraryLoaded( _rLibName ) ) 512*cdf0e10cSrcweir xLibContainer->loadLibrary( _rLibName ); 513*cdf0e10cSrcweir } 514*cdf0e10cSrcweir catch( const NoSuchElementException& ) 515*cdf0e10cSrcweir { 516*cdf0e10cSrcweir throw; // allowed to leave 517*cdf0e10cSrcweir } 518*cdf0e10cSrcweir catch( const Exception& ) 519*cdf0e10cSrcweir { 520*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 521*cdf0e10cSrcweir } 522*cdf0e10cSrcweir 523*cdf0e10cSrcweir return xContainer; 524*cdf0e10cSrcweir } 525*cdf0e10cSrcweir 526*cdf0e10cSrcweir //-------------------------------------------------------------------- 527*cdf0e10cSrcweir bool ScriptDocument_Impl::hasLibrary( LibraryContainerType _eType, const ::rtl::OUString& _rLibName ) const 528*cdf0e10cSrcweir { 529*cdf0e10cSrcweir bool bHas = false; 530*cdf0e10cSrcweir try 531*cdf0e10cSrcweir { 532*cdf0e10cSrcweir Reference< XLibraryContainer > xLibContainer = getLibraryContainer( _eType ); 533*cdf0e10cSrcweir bHas = xLibContainer.is() && xLibContainer->hasByName( _rLibName ); 534*cdf0e10cSrcweir } 535*cdf0e10cSrcweir catch( const Exception& ) 536*cdf0e10cSrcweir { 537*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 538*cdf0e10cSrcweir } 539*cdf0e10cSrcweir return bHas; 540*cdf0e10cSrcweir } 541*cdf0e10cSrcweir 542*cdf0e10cSrcweir //-------------------------------------------------------------------- 543*cdf0e10cSrcweir Reference< XNameContainer > ScriptDocument_Impl::getOrCreateLibrary( LibraryContainerType _eType, const ::rtl::OUString& _rLibName ) const 544*cdf0e10cSrcweir { 545*cdf0e10cSrcweir Reference< XNameContainer > xLibrary; 546*cdf0e10cSrcweir try 547*cdf0e10cSrcweir { 548*cdf0e10cSrcweir Reference< XLibraryContainer > xLibContainer( getLibraryContainer( _eType ), UNO_QUERY_THROW ); 549*cdf0e10cSrcweir if ( xLibContainer->hasByName( _rLibName ) ) 550*cdf0e10cSrcweir xLibrary.set( xLibContainer->getByName( _rLibName ), UNO_QUERY_THROW ); 551*cdf0e10cSrcweir else 552*cdf0e10cSrcweir xLibrary.set( xLibContainer->createLibrary( _rLibName ), UNO_QUERY_THROW ); 553*cdf0e10cSrcweir 554*cdf0e10cSrcweir if ( !xLibContainer->isLibraryLoaded( _rLibName ) ) 555*cdf0e10cSrcweir xLibContainer->loadLibrary( _rLibName ); 556*cdf0e10cSrcweir } 557*cdf0e10cSrcweir catch( const Exception& ) 558*cdf0e10cSrcweir { 559*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 560*cdf0e10cSrcweir } 561*cdf0e10cSrcweir return xLibrary; 562*cdf0e10cSrcweir } 563*cdf0e10cSrcweir 564*cdf0e10cSrcweir //-------------------------------------------------------------------- 565*cdf0e10cSrcweir void ScriptDocument_Impl::loadLibraryIfExists( LibraryContainerType _eType, const ::rtl::OUString& _rLibrary ) 566*cdf0e10cSrcweir { 567*cdf0e10cSrcweir try 568*cdf0e10cSrcweir { 569*cdf0e10cSrcweir Reference< XLibraryContainer > xLibContainer( getLibraryContainer( _eType ) ); 570*cdf0e10cSrcweir if ( xLibContainer.is() && xLibContainer->hasByName( _rLibrary ) && !xLibContainer->isLibraryLoaded( _rLibrary ) ) 571*cdf0e10cSrcweir xLibContainer->loadLibrary( _rLibrary ); 572*cdf0e10cSrcweir } 573*cdf0e10cSrcweir catch( const Exception& ) 574*cdf0e10cSrcweir { 575*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 576*cdf0e10cSrcweir } 577*cdf0e10cSrcweir } 578*cdf0e10cSrcweir 579*cdf0e10cSrcweir //-------------------------------------------------------------------- 580*cdf0e10cSrcweir bool ScriptDocument_Impl::removeModuleOrDialog( LibraryContainerType _eType, const ::rtl::OUString& _rLibName, const ::rtl::OUString& _rModuleName ) 581*cdf0e10cSrcweir { 582*cdf0e10cSrcweir OSL_ENSURE( isValid(), "ScriptDocument_Impl::removeModuleOrDialog: invalid!" ); 583*cdf0e10cSrcweir if ( isValid() ) 584*cdf0e10cSrcweir { 585*cdf0e10cSrcweir try 586*cdf0e10cSrcweir { 587*cdf0e10cSrcweir Reference< XNameContainer > xLib( getLibrary( _eType, _rLibName, sal_True ) ); 588*cdf0e10cSrcweir if ( xLib.is() ) 589*cdf0e10cSrcweir { 590*cdf0e10cSrcweir xLib->removeByName( _rModuleName ); 591*cdf0e10cSrcweir return true; 592*cdf0e10cSrcweir } 593*cdf0e10cSrcweir } 594*cdf0e10cSrcweir catch( const Exception& ) 595*cdf0e10cSrcweir { 596*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 597*cdf0e10cSrcweir } 598*cdf0e10cSrcweir } 599*cdf0e10cSrcweir return false; 600*cdf0e10cSrcweir } 601*cdf0e10cSrcweir 602*cdf0e10cSrcweir //-------------------------------------------------------------------- 603*cdf0e10cSrcweir bool ScriptDocument_Impl::hasModuleOrDialog( LibraryContainerType _eType, const ::rtl::OUString& _rLibName, const ::rtl::OUString& _rModName ) const 604*cdf0e10cSrcweir { 605*cdf0e10cSrcweir OSL_ENSURE( isValid(), "ScriptDocument_Impl::hasModuleOrDialog: invalid!" ); 606*cdf0e10cSrcweir if ( !isValid() ) 607*cdf0e10cSrcweir return false; 608*cdf0e10cSrcweir 609*cdf0e10cSrcweir try 610*cdf0e10cSrcweir { 611*cdf0e10cSrcweir Reference< XNameContainer > xLib( getLibrary( _eType, _rLibName, sal_True ) ); 612*cdf0e10cSrcweir if ( xLib.is() ) 613*cdf0e10cSrcweir return xLib->hasByName( _rModName ); 614*cdf0e10cSrcweir } 615*cdf0e10cSrcweir catch( const Exception& ) 616*cdf0e10cSrcweir { 617*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 618*cdf0e10cSrcweir } 619*cdf0e10cSrcweir return false; 620*cdf0e10cSrcweir } 621*cdf0e10cSrcweir 622*cdf0e10cSrcweir //-------------------------------------------------------------------- 623*cdf0e10cSrcweir bool ScriptDocument_Impl::getModuleOrDialog( LibraryContainerType _eType, const ::rtl::OUString& _rLibName, const ::rtl::OUString& _rObjectName, Any& _out_rModuleOrDialog ) 624*cdf0e10cSrcweir { 625*cdf0e10cSrcweir OSL_ENSURE( isValid(), "ScriptDocument_Impl::getModuleOrDialog: invalid!" ); 626*cdf0e10cSrcweir if ( !isValid() ) 627*cdf0e10cSrcweir return false; 628*cdf0e10cSrcweir 629*cdf0e10cSrcweir _out_rModuleOrDialog.clear(); 630*cdf0e10cSrcweir try 631*cdf0e10cSrcweir { 632*cdf0e10cSrcweir Reference< XNameContainer > xLib( getLibrary( _eType, _rLibName, sal_True ), UNO_QUERY_THROW ); 633*cdf0e10cSrcweir if ( xLib->hasByName( _rObjectName ) ) 634*cdf0e10cSrcweir { 635*cdf0e10cSrcweir _out_rModuleOrDialog = xLib->getByName( _rObjectName ); 636*cdf0e10cSrcweir return true; 637*cdf0e10cSrcweir } 638*cdf0e10cSrcweir } 639*cdf0e10cSrcweir catch( const Exception& ) 640*cdf0e10cSrcweir { 641*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 642*cdf0e10cSrcweir } 643*cdf0e10cSrcweir return false; 644*cdf0e10cSrcweir } 645*cdf0e10cSrcweir 646*cdf0e10cSrcweir //-------------------------------------------------------------------- 647*cdf0e10cSrcweir bool ScriptDocument_Impl::renameModuleOrDialog( LibraryContainerType _eType, const ::rtl::OUString& _rLibName, 648*cdf0e10cSrcweir const ::rtl::OUString& _rOldName, const ::rtl::OUString& _rNewName, const Reference< XNameContainer >& _rxExistingDialogModel ) 649*cdf0e10cSrcweir { 650*cdf0e10cSrcweir OSL_ENSURE( isValid(), "ScriptDocument_Impl::renameModuleOrDialog: invalid!" ); 651*cdf0e10cSrcweir if ( !isValid() ) 652*cdf0e10cSrcweir return false; 653*cdf0e10cSrcweir 654*cdf0e10cSrcweir try 655*cdf0e10cSrcweir { 656*cdf0e10cSrcweir Reference< XNameContainer > xLib( getLibrary( _eType, _rLibName, sal_True ), UNO_QUERY_THROW ); 657*cdf0e10cSrcweir 658*cdf0e10cSrcweir // get element 659*cdf0e10cSrcweir Any aElement( xLib->getByName( _rOldName ) ); 660*cdf0e10cSrcweir 661*cdf0e10cSrcweir // remove element from container 662*cdf0e10cSrcweir xLib->removeByName( _rOldName ); 663*cdf0e10cSrcweir 664*cdf0e10cSrcweir // if it's a dialog, import and export, to reflect the new name 665*cdf0e10cSrcweir if ( _eType == E_DIALOGS ) 666*cdf0e10cSrcweir { 667*cdf0e10cSrcweir // create dialog model 668*cdf0e10cSrcweir ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() ); 669*cdf0e10cSrcweir Reference< XNameContainer > xDialogModel; 670*cdf0e10cSrcweir if ( _rxExistingDialogModel.is() ) 671*cdf0e10cSrcweir xDialogModel = _rxExistingDialogModel; 672*cdf0e10cSrcweir else 673*cdf0e10cSrcweir if ( !aContext.createComponent( "com.sun.star.awt.UnoControlDialogModel", xDialogModel ) ) 674*cdf0e10cSrcweir return false; 675*cdf0e10cSrcweir 676*cdf0e10cSrcweir // import dialog model 677*cdf0e10cSrcweir Reference< XInputStreamProvider > xISP( aElement, UNO_QUERY_THROW ); 678*cdf0e10cSrcweir if ( !_rxExistingDialogModel.is() ) 679*cdf0e10cSrcweir { 680*cdf0e10cSrcweir Reference< XInputStream > xInput( xISP->createInputStream(), UNO_QUERY_THROW ); 681*cdf0e10cSrcweir ::xmlscript::importDialogModel( xInput, xDialogModel, aContext.getUNOContext() ); 682*cdf0e10cSrcweir } 683*cdf0e10cSrcweir 684*cdf0e10cSrcweir // set new name as property 685*cdf0e10cSrcweir Reference< XPropertySet > xDlgPSet( xDialogModel, UNO_QUERY_THROW ); 686*cdf0e10cSrcweir xDlgPSet->setPropertyValue( DLGED_PROP_NAME, makeAny( _rNewName ) ); 687*cdf0e10cSrcweir 688*cdf0e10cSrcweir // export dialog model 689*cdf0e10cSrcweir xISP = ::xmlscript::exportDialogModel( xDialogModel, aContext.getUNOContext() ); 690*cdf0e10cSrcweir aElement <<= xISP; 691*cdf0e10cSrcweir } 692*cdf0e10cSrcweir 693*cdf0e10cSrcweir // insert element by new name in container 694*cdf0e10cSrcweir else if ( _eType == E_SCRIPTS ) 695*cdf0e10cSrcweir { 696*cdf0e10cSrcweir Reference< XVBAModuleInfo > xVBAModuleInfo( xLib, UNO_QUERY ); 697*cdf0e10cSrcweir if ( xVBAModuleInfo->hasModuleInfo( _rOldName ) ) 698*cdf0e10cSrcweir { 699*cdf0e10cSrcweir ModuleInfo sModuleInfo = xVBAModuleInfo->getModuleInfo( _rOldName ); 700*cdf0e10cSrcweir xVBAModuleInfo->removeModuleInfo( _rOldName ); 701*cdf0e10cSrcweir xVBAModuleInfo->insertModuleInfo( _rNewName, sModuleInfo ); 702*cdf0e10cSrcweir } 703*cdf0e10cSrcweir } 704*cdf0e10cSrcweir xLib->insertByName( _rNewName, aElement ); 705*cdf0e10cSrcweir return true; 706*cdf0e10cSrcweir } 707*cdf0e10cSrcweir catch( const Exception& ) 708*cdf0e10cSrcweir { 709*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 710*cdf0e10cSrcweir } 711*cdf0e10cSrcweir return false; 712*cdf0e10cSrcweir } 713*cdf0e10cSrcweir 714*cdf0e10cSrcweir //-------------------------------------------------------------------- 715*cdf0e10cSrcweir bool ScriptDocument_Impl::createModule( const ::rtl::OUString& _rLibName, const ::rtl::OUString& _rModName, bool _bCreateMain, ::rtl::OUString& _out_rNewModuleCode ) const 716*cdf0e10cSrcweir { 717*cdf0e10cSrcweir _out_rNewModuleCode = ::rtl::OUString(); 718*cdf0e10cSrcweir try 719*cdf0e10cSrcweir { 720*cdf0e10cSrcweir Reference< XNameContainer > xLib( getLibrary( E_SCRIPTS, _rLibName, sal_True ) ); 721*cdf0e10cSrcweir if ( !xLib.is() || xLib->hasByName( _rModName ) ) 722*cdf0e10cSrcweir return false; 723*cdf0e10cSrcweir 724*cdf0e10cSrcweir // create new module 725*cdf0e10cSrcweir _out_rNewModuleCode = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "REM ***** BASIC *****\n\n" ) ); 726*cdf0e10cSrcweir if ( _bCreateMain ) 727*cdf0e10cSrcweir _out_rNewModuleCode += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Sub Main\n\nEnd Sub\n" ) ); 728*cdf0e10cSrcweir 729*cdf0e10cSrcweir // insert module into library 730*cdf0e10cSrcweir xLib->insertByName( _rModName, makeAny( _out_rNewModuleCode ) ); 731*cdf0e10cSrcweir } 732*cdf0e10cSrcweir catch( const Exception& ) 733*cdf0e10cSrcweir { 734*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 735*cdf0e10cSrcweir return false; 736*cdf0e10cSrcweir } 737*cdf0e10cSrcweir 738*cdf0e10cSrcweir return true; 739*cdf0e10cSrcweir } 740*cdf0e10cSrcweir 741*cdf0e10cSrcweir //-------------------------------------------------------------------- 742*cdf0e10cSrcweir bool ScriptDocument_Impl::insertModuleOrDialog( LibraryContainerType _eType, const ::rtl::OUString& _rLibName, const ::rtl::OUString& _rObjectName, const Any& _rElement ) const 743*cdf0e10cSrcweir { 744*cdf0e10cSrcweir try 745*cdf0e10cSrcweir { 746*cdf0e10cSrcweir Reference< XNameContainer > xLib( getOrCreateLibrary( _eType, _rLibName ), UNO_QUERY_THROW ); 747*cdf0e10cSrcweir if ( xLib->hasByName( _rObjectName ) ) 748*cdf0e10cSrcweir return false; 749*cdf0e10cSrcweir 750*cdf0e10cSrcweir xLib->insertByName( _rObjectName, _rElement ); 751*cdf0e10cSrcweir return true; 752*cdf0e10cSrcweir } 753*cdf0e10cSrcweir catch( const Exception& ) 754*cdf0e10cSrcweir { 755*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 756*cdf0e10cSrcweir } 757*cdf0e10cSrcweir return false; 758*cdf0e10cSrcweir } 759*cdf0e10cSrcweir 760*cdf0e10cSrcweir //-------------------------------------------------------------------- 761*cdf0e10cSrcweir bool ScriptDocument_Impl::updateModule( const ::rtl::OUString& _rLibName, const ::rtl::OUString& _rModName, const ::rtl::OUString& _rModuleCode ) const 762*cdf0e10cSrcweir { 763*cdf0e10cSrcweir try 764*cdf0e10cSrcweir { 765*cdf0e10cSrcweir Reference< XNameContainer > xLib( getOrCreateLibrary( E_SCRIPTS, _rLibName ), UNO_QUERY_THROW ); 766*cdf0e10cSrcweir if ( !xLib->hasByName( _rModName ) ) 767*cdf0e10cSrcweir return false; 768*cdf0e10cSrcweir xLib->replaceByName( _rModName, makeAny( _rModuleCode ) ); 769*cdf0e10cSrcweir return true; 770*cdf0e10cSrcweir } 771*cdf0e10cSrcweir catch( const Exception& ) 772*cdf0e10cSrcweir { 773*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 774*cdf0e10cSrcweir } 775*cdf0e10cSrcweir return false; 776*cdf0e10cSrcweir } 777*cdf0e10cSrcweir 778*cdf0e10cSrcweir //-------------------------------------------------------------------- 779*cdf0e10cSrcweir bool ScriptDocument_Impl::createDialog( const ::rtl::OUString& _rLibName, const ::rtl::OUString& _rDialogName, Reference< XInputStreamProvider >& _out_rDialogProvider ) const 780*cdf0e10cSrcweir { 781*cdf0e10cSrcweir try 782*cdf0e10cSrcweir { 783*cdf0e10cSrcweir Reference< XNameContainer > xLib( getLibrary( E_DIALOGS, _rLibName, sal_True ), UNO_QUERY_THROW ); 784*cdf0e10cSrcweir 785*cdf0e10cSrcweir // create dialog 786*cdf0e10cSrcweir _out_rDialogProvider.clear(); 787*cdf0e10cSrcweir if ( xLib->hasByName( _rDialogName ) ) 788*cdf0e10cSrcweir return false; 789*cdf0e10cSrcweir 790*cdf0e10cSrcweir // create new dialog model 791*cdf0e10cSrcweir ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() ); 792*cdf0e10cSrcweir Reference< XNameContainer > xDialogModel; 793*cdf0e10cSrcweir if ( !aContext.createComponent( "com.sun.star.awt.UnoControlDialogModel", xDialogModel ) ) 794*cdf0e10cSrcweir return false; 795*cdf0e10cSrcweir 796*cdf0e10cSrcweir // set name property 797*cdf0e10cSrcweir Reference< XPropertySet > xDlgPSet( xDialogModel, UNO_QUERY_THROW ); 798*cdf0e10cSrcweir xDlgPSet->setPropertyValue( DLGED_PROP_NAME, makeAny( _rDialogName ) ); 799*cdf0e10cSrcweir 800*cdf0e10cSrcweir // export dialog model 801*cdf0e10cSrcweir _out_rDialogProvider = ::xmlscript::exportDialogModel( xDialogModel, aContext.getUNOContext() ); 802*cdf0e10cSrcweir 803*cdf0e10cSrcweir // insert dialog into library 804*cdf0e10cSrcweir xLib->insertByName( _rDialogName, makeAny( _out_rDialogProvider ) ); 805*cdf0e10cSrcweir } 806*cdf0e10cSrcweir catch( const Exception& ) 807*cdf0e10cSrcweir { 808*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 809*cdf0e10cSrcweir } 810*cdf0e10cSrcweir 811*cdf0e10cSrcweir return _out_rDialogProvider.is(); 812*cdf0e10cSrcweir } 813*cdf0e10cSrcweir 814*cdf0e10cSrcweir //-------------------------------------------------------------------- 815*cdf0e10cSrcweir void ScriptDocument_Impl::setDocumentModified() const 816*cdf0e10cSrcweir { 817*cdf0e10cSrcweir OSL_ENSURE( isValid() && isDocument(), "ScriptDocument_Impl::setDocumentModified: only to be called for real documents!" ); 818*cdf0e10cSrcweir if ( isValid() && isDocument() ) 819*cdf0e10cSrcweir { 820*cdf0e10cSrcweir try 821*cdf0e10cSrcweir { 822*cdf0e10cSrcweir m_xDocModify->setModified( sal_True ); 823*cdf0e10cSrcweir } 824*cdf0e10cSrcweir catch( const Exception& ) 825*cdf0e10cSrcweir { 826*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 827*cdf0e10cSrcweir } 828*cdf0e10cSrcweir } 829*cdf0e10cSrcweir } 830*cdf0e10cSrcweir 831*cdf0e10cSrcweir //-------------------------------------------------------------------- 832*cdf0e10cSrcweir bool ScriptDocument_Impl::isDocumentModified() const 833*cdf0e10cSrcweir { 834*cdf0e10cSrcweir OSL_ENSURE( isValid() && isDocument(), "ScriptDocument_Impl::isDocumentModified: only to be called for real documents!" ); 835*cdf0e10cSrcweir bool bIsModified = false; 836*cdf0e10cSrcweir if ( isValid() && isDocument() ) 837*cdf0e10cSrcweir { 838*cdf0e10cSrcweir try 839*cdf0e10cSrcweir { 840*cdf0e10cSrcweir bIsModified = m_xDocModify->isModified(); 841*cdf0e10cSrcweir } 842*cdf0e10cSrcweir catch( const Exception& ) 843*cdf0e10cSrcweir { 844*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 845*cdf0e10cSrcweir } 846*cdf0e10cSrcweir } 847*cdf0e10cSrcweir return bIsModified; 848*cdf0e10cSrcweir } 849*cdf0e10cSrcweir 850*cdf0e10cSrcweir //-------------------------------------------------------------------- 851*cdf0e10cSrcweir bool ScriptDocument_Impl::saveDocument( const Reference< XStatusIndicator >& _rxStatusIndicator ) const 852*cdf0e10cSrcweir { 853*cdf0e10cSrcweir Reference< XFrame > xFrame; 854*cdf0e10cSrcweir if ( !getCurrentFrame( xFrame ) ) 855*cdf0e10cSrcweir return false; 856*cdf0e10cSrcweir 857*cdf0e10cSrcweir Sequence< PropertyValue > aArgs; 858*cdf0e10cSrcweir if ( _rxStatusIndicator.is() ) 859*cdf0e10cSrcweir { 860*cdf0e10cSrcweir aArgs.realloc(1); 861*cdf0e10cSrcweir aArgs[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "StatusIndicator" ) ); 862*cdf0e10cSrcweir aArgs[0].Value <<= _rxStatusIndicator; 863*cdf0e10cSrcweir } 864*cdf0e10cSrcweir 865*cdf0e10cSrcweir try 866*cdf0e10cSrcweir { 867*cdf0e10cSrcweir URL aURL; 868*cdf0e10cSrcweir aURL.Complete = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:Save" ) ); 869*cdf0e10cSrcweir aURL.Main = aURL.Complete; 870*cdf0e10cSrcweir aURL.Protocol = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:" ) ); 871*cdf0e10cSrcweir aURL.Path = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Save" ) ); 872*cdf0e10cSrcweir 873*cdf0e10cSrcweir Reference< XDispatchProvider > xDispProv( xFrame, UNO_QUERY_THROW ); 874*cdf0e10cSrcweir Reference< XDispatch > xDispatch( 875*cdf0e10cSrcweir xDispProv->queryDispatch( aURL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_self" ) ), FrameSearchFlag::AUTO ), 876*cdf0e10cSrcweir UNO_SET_THROW ); 877*cdf0e10cSrcweir 878*cdf0e10cSrcweir xDispatch->dispatch( aURL, aArgs ); 879*cdf0e10cSrcweir } 880*cdf0e10cSrcweir catch( const Exception& ) 881*cdf0e10cSrcweir { 882*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 883*cdf0e10cSrcweir return false; 884*cdf0e10cSrcweir } 885*cdf0e10cSrcweir 886*cdf0e10cSrcweir return true; 887*cdf0e10cSrcweir } 888*cdf0e10cSrcweir 889*cdf0e10cSrcweir //-------------------------------------------------------------------- 890*cdf0e10cSrcweir ::rtl::OUString ScriptDocument_Impl::getTitle() const 891*cdf0e10cSrcweir { 892*cdf0e10cSrcweir OSL_PRECOND( isValid() && isDocument(), "ScriptDocument_Impl::getTitle: for documents only!" ); 893*cdf0e10cSrcweir 894*cdf0e10cSrcweir ::rtl::OUString sTitle; 895*cdf0e10cSrcweir if ( isValid() && isDocument() ) 896*cdf0e10cSrcweir { 897*cdf0e10cSrcweir sTitle = ::comphelper::DocumentInfo::getDocumentTitle( m_xDocument ); 898*cdf0e10cSrcweir } 899*cdf0e10cSrcweir return sTitle; 900*cdf0e10cSrcweir } 901*cdf0e10cSrcweir 902*cdf0e10cSrcweir //-------------------------------------------------------------------- 903*cdf0e10cSrcweir ::rtl::OUString ScriptDocument_Impl::getURL() const 904*cdf0e10cSrcweir { 905*cdf0e10cSrcweir OSL_PRECOND( isValid() && isDocument(), "ScriptDocument_Impl::getURL: for documents only!" ); 906*cdf0e10cSrcweir 907*cdf0e10cSrcweir ::rtl::OUString sURL; 908*cdf0e10cSrcweir if ( isValid() && isDocument() ) 909*cdf0e10cSrcweir { 910*cdf0e10cSrcweir try 911*cdf0e10cSrcweir { 912*cdf0e10cSrcweir sURL = m_xDocument->getURL(); 913*cdf0e10cSrcweir } 914*cdf0e10cSrcweir catch( const Exception& ) 915*cdf0e10cSrcweir { 916*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 917*cdf0e10cSrcweir } 918*cdf0e10cSrcweir } 919*cdf0e10cSrcweir return sURL; 920*cdf0e10cSrcweir } 921*cdf0e10cSrcweir 922*cdf0e10cSrcweir //-------------------------------------------------------------------- 923*cdf0e10cSrcweir bool ScriptDocument_Impl::allowMacros() const 924*cdf0e10cSrcweir { 925*cdf0e10cSrcweir OSL_ENSURE( isValid() && isDocument(), "ScriptDocument_Impl::allowMacros: for documents only!" ); 926*cdf0e10cSrcweir bool bAllow = false; 927*cdf0e10cSrcweir if ( isValid() && isDocument() ) 928*cdf0e10cSrcweir { 929*cdf0e10cSrcweir try 930*cdf0e10cSrcweir { 931*cdf0e10cSrcweir bAllow = m_xScriptAccess->getAllowMacroExecution(); 932*cdf0e10cSrcweir } 933*cdf0e10cSrcweir catch( const Exception& ) 934*cdf0e10cSrcweir { 935*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 936*cdf0e10cSrcweir } 937*cdf0e10cSrcweir } 938*cdf0e10cSrcweir return bAllow; 939*cdf0e10cSrcweir } 940*cdf0e10cSrcweir 941*cdf0e10cSrcweir //-------------------------------------------------------------------- 942*cdf0e10cSrcweir bool ScriptDocument_Impl::getCurrentFrame( Reference< XFrame >& _out_rxFrame ) const 943*cdf0e10cSrcweir { 944*cdf0e10cSrcweir _out_rxFrame.clear(); 945*cdf0e10cSrcweir OSL_PRECOND( isValid() && isDocument(), "ScriptDocument_Impl::getCurrentFrame: documents only!" ); 946*cdf0e10cSrcweir if ( !isValid() || !isDocument() ) 947*cdf0e10cSrcweir return false; 948*cdf0e10cSrcweir 949*cdf0e10cSrcweir try 950*cdf0e10cSrcweir { 951*cdf0e10cSrcweir Reference< XModel > xDocument( m_xDocument, UNO_SET_THROW ); 952*cdf0e10cSrcweir Reference< XController > xController( xDocument->getCurrentController(), UNO_SET_THROW ); 953*cdf0e10cSrcweir _out_rxFrame.set( xController->getFrame(), UNO_SET_THROW ); 954*cdf0e10cSrcweir } 955*cdf0e10cSrcweir catch( const Exception& ) 956*cdf0e10cSrcweir { 957*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 958*cdf0e10cSrcweir } 959*cdf0e10cSrcweir 960*cdf0e10cSrcweir return _out_rxFrame.is(); 961*cdf0e10cSrcweir } 962*cdf0e10cSrcweir 963*cdf0e10cSrcweir //-------------------------------------------------------------------- 964*cdf0e10cSrcweir bool ScriptDocument_Impl::isLibraryShared( const ::rtl::OUString& _rLibName, LibraryContainerType _eType ) 965*cdf0e10cSrcweir { 966*cdf0e10cSrcweir bool bIsShared = false; 967*cdf0e10cSrcweir try 968*cdf0e10cSrcweir { 969*cdf0e10cSrcweir Reference< XLibraryContainer2 > xLibContainer( getLibraryContainer( _eType ), UNO_QUERY_THROW ); 970*cdf0e10cSrcweir 971*cdf0e10cSrcweir if ( !xLibContainer->hasByName( _rLibName ) || !xLibContainer->isLibraryLink( _rLibName ) ) 972*cdf0e10cSrcweir return false; 973*cdf0e10cSrcweir ::rtl::OUString aFileURL; 974*cdf0e10cSrcweir Reference< XMultiServiceFactory > xMSF( ::comphelper::getProcessServiceFactory() ); 975*cdf0e10cSrcweir Reference< XUriReferenceFactory > xUriFac; 976*cdf0e10cSrcweir if ( xMSF.is() ) 977*cdf0e10cSrcweir { 978*cdf0e10cSrcweir xUriFac.set( 979*cdf0e10cSrcweir xMSF->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.uri.UriReferenceFactory" ) ) ), 980*cdf0e10cSrcweir UNO_QUERY_THROW ); 981*cdf0e10cSrcweir } 982*cdf0e10cSrcweir 983*cdf0e10cSrcweir ::rtl::OUString aLinkURL( xLibContainer->getLibraryLinkURL( _rLibName ) ); 984*cdf0e10cSrcweir Reference< XUriReference > xUriRef( xUriFac->parse( aLinkURL ), UNO_QUERY_THROW ); 985*cdf0e10cSrcweir 986*cdf0e10cSrcweir ::rtl::OUString aScheme = xUriRef->getScheme(); 987*cdf0e10cSrcweir if ( aScheme.equalsIgnoreAsciiCaseAscii( "file" ) ) 988*cdf0e10cSrcweir { 989*cdf0e10cSrcweir aFileURL = aLinkURL; 990*cdf0e10cSrcweir } 991*cdf0e10cSrcweir else if ( aScheme.equalsIgnoreAsciiCaseAscii( "vnd.sun.star.pkg" ) ) 992*cdf0e10cSrcweir { 993*cdf0e10cSrcweir ::rtl::OUString aAuthority = xUriRef->getAuthority(); 994*cdf0e10cSrcweir if ( aAuthority.matchIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "vnd.sun.star.expand:" ) ) ) 995*cdf0e10cSrcweir { 996*cdf0e10cSrcweir ::rtl::OUString aDecodedURL( aAuthority.copy( sizeof ( "vnd.sun.star.expand:" ) - 1 ) ); 997*cdf0e10cSrcweir aDecodedURL = ::rtl::Uri::decode( aDecodedURL, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 ); 998*cdf0e10cSrcweir Reference< XComponentContext > xContext; 999*cdf0e10cSrcweir Reference< XPropertySet > xProps( xMSF, UNO_QUERY_THROW ); 1000*cdf0e10cSrcweir xContext.set( xProps->getPropertyValue( ::rtl::OUString::createFromAscii( "DefaultContext" ) ), UNO_QUERY_THROW ); 1001*cdf0e10cSrcweir Reference< XMacroExpander > xMacroExpander( 1002*cdf0e10cSrcweir xContext->getValueByName( 1003*cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "/singletons/com.sun.star.util.theMacroExpander" ) ), 1004*cdf0e10cSrcweir UNO_QUERY_THROW ); 1005*cdf0e10cSrcweir aFileURL = xMacroExpander->expandMacros( aDecodedURL ); 1006*cdf0e10cSrcweir } 1007*cdf0e10cSrcweir } 1008*cdf0e10cSrcweir 1009*cdf0e10cSrcweir if ( aFileURL.getLength() ) 1010*cdf0e10cSrcweir { 1011*cdf0e10cSrcweir ::osl::DirectoryItem aFileItem; 1012*cdf0e10cSrcweir ::osl::FileStatus aFileStatus( FileStatusMask_FileURL ); 1013*cdf0e10cSrcweir OSL_VERIFY( ::osl::DirectoryItem::get( aFileURL, aFileItem ) == ::osl::FileBase::E_None ); 1014*cdf0e10cSrcweir OSL_VERIFY( aFileItem.getFileStatus( aFileStatus ) == ::osl::FileBase::E_None ); 1015*cdf0e10cSrcweir ::rtl::OUString aCanonicalFileURL( aFileStatus.getFileURL() ); 1016*cdf0e10cSrcweir 1017*cdf0e10cSrcweir ::rtl::OUString aSearchURL1( RTL_CONSTASCII_USTRINGPARAM( "share/basic" ) ); 1018*cdf0e10cSrcweir ::rtl::OUString aSearchURL2( RTL_CONSTASCII_USTRINGPARAM( "share/uno_packages" ) ); 1019*cdf0e10cSrcweir ::rtl::OUString aSearchURL3( RTL_CONSTASCII_USTRINGPARAM( "share/extensions" ) ); 1020*cdf0e10cSrcweir if( aCanonicalFileURL.indexOf( aSearchURL1 ) != -1 || 1021*cdf0e10cSrcweir aCanonicalFileURL.indexOf( aSearchURL2 ) != -1 || 1022*cdf0e10cSrcweir aCanonicalFileURL.indexOf( aSearchURL3 ) != -1 ) 1023*cdf0e10cSrcweir bIsShared = true; 1024*cdf0e10cSrcweir } 1025*cdf0e10cSrcweir } 1026*cdf0e10cSrcweir catch( const Exception& ) 1027*cdf0e10cSrcweir { 1028*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 1029*cdf0e10cSrcweir } 1030*cdf0e10cSrcweir 1031*cdf0e10cSrcweir return bIsShared; 1032*cdf0e10cSrcweir } 1033*cdf0e10cSrcweir 1034*cdf0e10cSrcweir //-------------------------------------------------------------------- 1035*cdf0e10cSrcweir void ScriptDocument_Impl::onDocumentCreated( const ScriptDocument& /*_rDocument*/ ) 1036*cdf0e10cSrcweir { 1037*cdf0e10cSrcweir // not interested in 1038*cdf0e10cSrcweir } 1039*cdf0e10cSrcweir 1040*cdf0e10cSrcweir //-------------------------------------------------------------------- 1041*cdf0e10cSrcweir void ScriptDocument_Impl::onDocumentOpened( const ScriptDocument& /*_rDocument*/ ) 1042*cdf0e10cSrcweir { 1043*cdf0e10cSrcweir // not interested in 1044*cdf0e10cSrcweir } 1045*cdf0e10cSrcweir 1046*cdf0e10cSrcweir //-------------------------------------------------------------------- 1047*cdf0e10cSrcweir void ScriptDocument_Impl::onDocumentSave( const ScriptDocument& /*_rDocument*/ ) 1048*cdf0e10cSrcweir { 1049*cdf0e10cSrcweir // not interested in 1050*cdf0e10cSrcweir } 1051*cdf0e10cSrcweir 1052*cdf0e10cSrcweir //-------------------------------------------------------------------- 1053*cdf0e10cSrcweir void ScriptDocument_Impl::onDocumentSaveDone( const ScriptDocument& /*_rDocument*/ ) 1054*cdf0e10cSrcweir { 1055*cdf0e10cSrcweir // not interested in 1056*cdf0e10cSrcweir } 1057*cdf0e10cSrcweir 1058*cdf0e10cSrcweir //-------------------------------------------------------------------- 1059*cdf0e10cSrcweir void ScriptDocument_Impl::onDocumentSaveAs( const ScriptDocument& /*_rDocument*/ ) 1060*cdf0e10cSrcweir { 1061*cdf0e10cSrcweir // not interested in 1062*cdf0e10cSrcweir } 1063*cdf0e10cSrcweir 1064*cdf0e10cSrcweir //-------------------------------------------------------------------- 1065*cdf0e10cSrcweir void ScriptDocument_Impl::onDocumentSaveAsDone( const ScriptDocument& /*_rDocument*/ ) 1066*cdf0e10cSrcweir { 1067*cdf0e10cSrcweir // not interested in 1068*cdf0e10cSrcweir } 1069*cdf0e10cSrcweir 1070*cdf0e10cSrcweir //-------------------------------------------------------------------- 1071*cdf0e10cSrcweir void ScriptDocument_Impl::onDocumentClosed( const ScriptDocument& _rDocument ) 1072*cdf0e10cSrcweir { 1073*cdf0e10cSrcweir DBG_TESTSOLARMUTEX(); 1074*cdf0e10cSrcweir OSL_PRECOND( isValid(), "ScriptDocument_Impl::onDocumentClosed: should not be listening if I'm not valid!" ); 1075*cdf0e10cSrcweir 1076*cdf0e10cSrcweir bool bMyDocument = m_xDocument == _rDocument.getDocument(); 1077*cdf0e10cSrcweir OSL_PRECOND( bMyDocument, "ScriptDocument_Impl::onDocumentClosed: didn't want to know *this*!" ); 1078*cdf0e10cSrcweir if ( bMyDocument ) 1079*cdf0e10cSrcweir { 1080*cdf0e10cSrcweir m_bDocumentClosed = true; 1081*cdf0e10cSrcweir } 1082*cdf0e10cSrcweir } 1083*cdf0e10cSrcweir 1084*cdf0e10cSrcweir //-------------------------------------------------------------------- 1085*cdf0e10cSrcweir void ScriptDocument_Impl::onDocumentTitleChanged( const ScriptDocument& /*_rDocument*/ ) 1086*cdf0e10cSrcweir { 1087*cdf0e10cSrcweir // not interested in 1088*cdf0e10cSrcweir } 1089*cdf0e10cSrcweir 1090*cdf0e10cSrcweir //-------------------------------------------------------------------- 1091*cdf0e10cSrcweir void ScriptDocument_Impl::onDocumentModeChanged( const ScriptDocument& /*_rDocument*/ ) 1092*cdf0e10cSrcweir { 1093*cdf0e10cSrcweir // not interested in 1094*cdf0e10cSrcweir } 1095*cdf0e10cSrcweir 1096*cdf0e10cSrcweir //==================================================================== 1097*cdf0e10cSrcweir //= ScriptDocument 1098*cdf0e10cSrcweir //==================================================================== 1099*cdf0e10cSrcweir //-------------------------------------------------------------------- 1100*cdf0e10cSrcweir ScriptDocument::ScriptDocument() 1101*cdf0e10cSrcweir :m_pImpl( new ScriptDocument_Impl() ) 1102*cdf0e10cSrcweir { 1103*cdf0e10cSrcweir } 1104*cdf0e10cSrcweir 1105*cdf0e10cSrcweir //-------------------------------------------------------------------- 1106*cdf0e10cSrcweir ScriptDocument::ScriptDocument( ScriptDocument::SpecialDocument _eType ) 1107*cdf0e10cSrcweir :m_pImpl( new ScriptDocument_Impl( Reference< XModel >() ) ) 1108*cdf0e10cSrcweir { 1109*cdf0e10cSrcweir OSL_ENSURE( _eType == NoDocument, "ScriptDocument::ScriptDocument: unknown SpecialDocument type!" ); 1110*cdf0e10cSrcweir (void)_eType; 1111*cdf0e10cSrcweir } 1112*cdf0e10cSrcweir 1113*cdf0e10cSrcweir //-------------------------------------------------------------------- 1114*cdf0e10cSrcweir ScriptDocument::ScriptDocument( const Reference< XModel >& _rxDocument ) 1115*cdf0e10cSrcweir :m_pImpl( new ScriptDocument_Impl( _rxDocument ) ) 1116*cdf0e10cSrcweir { 1117*cdf0e10cSrcweir OSL_ENSURE( _rxDocument.is(), "ScriptDocument::ScriptDocument: document must not be NULL!" ); 1118*cdf0e10cSrcweir // a NULL document results in an uninitialized instance, and for this 1119*cdf0e10cSrcweir // purpose, there is a dedicated constructor 1120*cdf0e10cSrcweir } 1121*cdf0e10cSrcweir 1122*cdf0e10cSrcweir //-------------------------------------------------------------------- 1123*cdf0e10cSrcweir ScriptDocument::ScriptDocument( const ScriptDocument& _rSource ) 1124*cdf0e10cSrcweir :m_pImpl( _rSource.m_pImpl ) 1125*cdf0e10cSrcweir { 1126*cdf0e10cSrcweir } 1127*cdf0e10cSrcweir 1128*cdf0e10cSrcweir //-------------------------------------------------------------------- 1129*cdf0e10cSrcweir ScriptDocument::~ScriptDocument() 1130*cdf0e10cSrcweir { 1131*cdf0e10cSrcweir } 1132*cdf0e10cSrcweir 1133*cdf0e10cSrcweir //-------------------------------------------------------------------- 1134*cdf0e10cSrcweir const ScriptDocument& ScriptDocument::getApplicationScriptDocument() 1135*cdf0e10cSrcweir { 1136*cdf0e10cSrcweir static ScriptDocument s_aApplicationScripts; 1137*cdf0e10cSrcweir return s_aApplicationScripts; 1138*cdf0e10cSrcweir } 1139*cdf0e10cSrcweir 1140*cdf0e10cSrcweir //-------------------------------------------------------------------- 1141*cdf0e10cSrcweir ScriptDocument ScriptDocument::getDocumentForBasicManager( const BasicManager* _pManager ) 1142*cdf0e10cSrcweir { 1143*cdf0e10cSrcweir if ( _pManager == SFX_APP()->GetBasicManager() ) 1144*cdf0e10cSrcweir return getApplicationScriptDocument(); 1145*cdf0e10cSrcweir 1146*cdf0e10cSrcweir docs::Documents aDocuments; 1147*cdf0e10cSrcweir lcl_getAllModels_throw( aDocuments, false ); 1148*cdf0e10cSrcweir 1149*cdf0e10cSrcweir for ( docs::Documents::const_iterator doc = aDocuments.begin(); 1150*cdf0e10cSrcweir doc != aDocuments.end(); 1151*cdf0e10cSrcweir ++doc 1152*cdf0e10cSrcweir ) 1153*cdf0e10cSrcweir { 1154*cdf0e10cSrcweir const BasicManager* pDocBasicManager = ::basic::BasicManagerRepository::getDocumentBasicManager( doc->xModel ); 1155*cdf0e10cSrcweir if ( ( pDocBasicManager != SFX_APP()->GetBasicManager() ) 1156*cdf0e10cSrcweir && ( pDocBasicManager == _pManager ) 1157*cdf0e10cSrcweir ) 1158*cdf0e10cSrcweir { 1159*cdf0e10cSrcweir return ScriptDocument( doc->xModel ); 1160*cdf0e10cSrcweir } 1161*cdf0e10cSrcweir } 1162*cdf0e10cSrcweir 1163*cdf0e10cSrcweir OSL_ENSURE( false, "ScriptDocument::getDocumentForBasicManager: did not find a document for this manager!" ); 1164*cdf0e10cSrcweir return ScriptDocument( NoDocument ); 1165*cdf0e10cSrcweir } 1166*cdf0e10cSrcweir 1167*cdf0e10cSrcweir //-------------------------------------------------------------------- 1168*cdf0e10cSrcweir ScriptDocument ScriptDocument::getDocumentWithURLOrCaption( const ::rtl::OUString& _rUrlOrCaption ) 1169*cdf0e10cSrcweir { 1170*cdf0e10cSrcweir ScriptDocument aDocument( getApplicationScriptDocument() ); 1171*cdf0e10cSrcweir if ( _rUrlOrCaption.getLength() == 0 ) 1172*cdf0e10cSrcweir return aDocument; 1173*cdf0e10cSrcweir 1174*cdf0e10cSrcweir docs::Documents aDocuments; 1175*cdf0e10cSrcweir lcl_getAllModels_throw( aDocuments, false ); 1176*cdf0e10cSrcweir 1177*cdf0e10cSrcweir for ( docs::Documents::const_iterator doc = aDocuments.begin(); 1178*cdf0e10cSrcweir doc != aDocuments.end(); 1179*cdf0e10cSrcweir ++doc 1180*cdf0e10cSrcweir ) 1181*cdf0e10cSrcweir { 1182*cdf0e10cSrcweir const ScriptDocument aCheck = ScriptDocument( doc->xModel ); 1183*cdf0e10cSrcweir if ( _rUrlOrCaption == aCheck.getTitle() 1184*cdf0e10cSrcweir || _rUrlOrCaption == aCheck.getURL() 1185*cdf0e10cSrcweir ) 1186*cdf0e10cSrcweir { 1187*cdf0e10cSrcweir aDocument = aCheck; 1188*cdf0e10cSrcweir break; 1189*cdf0e10cSrcweir } 1190*cdf0e10cSrcweir } 1191*cdf0e10cSrcweir 1192*cdf0e10cSrcweir return aDocument; 1193*cdf0e10cSrcweir } 1194*cdf0e10cSrcweir 1195*cdf0e10cSrcweir //-------------------------------------------------------------------- 1196*cdf0e10cSrcweir namespace 1197*cdf0e10cSrcweir { 1198*cdf0e10cSrcweir struct DocumentTitleLess : public ::std::binary_function< ScriptDocument, ScriptDocument, bool > 1199*cdf0e10cSrcweir { 1200*cdf0e10cSrcweir DocumentTitleLess( const CollatorWrapper& _rCollator ) 1201*cdf0e10cSrcweir :m_aCollator( _rCollator ) 1202*cdf0e10cSrcweir { 1203*cdf0e10cSrcweir } 1204*cdf0e10cSrcweir 1205*cdf0e10cSrcweir bool operator()( const ScriptDocument& _lhs, const ScriptDocument& _rhs ) const 1206*cdf0e10cSrcweir { 1207*cdf0e10cSrcweir return m_aCollator.compareString( _lhs.getTitle(), _rhs.getTitle() ) < 0; 1208*cdf0e10cSrcweir } 1209*cdf0e10cSrcweir private: 1210*cdf0e10cSrcweir const CollatorWrapper m_aCollator; 1211*cdf0e10cSrcweir }; 1212*cdf0e10cSrcweir } 1213*cdf0e10cSrcweir 1214*cdf0e10cSrcweir //-------------------------------------------------------------------- 1215*cdf0e10cSrcweir ScriptDocuments ScriptDocument::getAllScriptDocuments( ScriptDocument::ScriptDocumentList _eListType ) 1216*cdf0e10cSrcweir { 1217*cdf0e10cSrcweir ScriptDocuments aScriptDocs; 1218*cdf0e10cSrcweir 1219*cdf0e10cSrcweir // include application? 1220*cdf0e10cSrcweir if ( _eListType == AllWithApplication ) 1221*cdf0e10cSrcweir aScriptDocs.push_back( getApplicationScriptDocument() ); 1222*cdf0e10cSrcweir 1223*cdf0e10cSrcweir // obtain documents 1224*cdf0e10cSrcweir try 1225*cdf0e10cSrcweir { 1226*cdf0e10cSrcweir docs::Documents aDocuments; 1227*cdf0e10cSrcweir lcl_getAllModels_throw( aDocuments, true /* exclude invisible */ ); 1228*cdf0e10cSrcweir 1229*cdf0e10cSrcweir for ( docs::Documents::const_iterator doc = aDocuments.begin(); 1230*cdf0e10cSrcweir doc != aDocuments.end(); 1231*cdf0e10cSrcweir ++doc 1232*cdf0e10cSrcweir ) 1233*cdf0e10cSrcweir { 1234*cdf0e10cSrcweir // exclude documents without script/library containers 1235*cdf0e10cSrcweir ScriptDocument aDoc( doc->xModel ); 1236*cdf0e10cSrcweir if ( !aDoc.isValid() ) 1237*cdf0e10cSrcweir continue; 1238*cdf0e10cSrcweir 1239*cdf0e10cSrcweir aScriptDocs.push_back( aDoc ); 1240*cdf0e10cSrcweir } 1241*cdf0e10cSrcweir } 1242*cdf0e10cSrcweir catch( const Exception& ) 1243*cdf0e10cSrcweir { 1244*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 1245*cdf0e10cSrcweir } 1246*cdf0e10cSrcweir 1247*cdf0e10cSrcweir // sort document list by doc title? 1248*cdf0e10cSrcweir if ( _eListType == DocumentsSorted ) 1249*cdf0e10cSrcweir { 1250*cdf0e10cSrcweir CollatorWrapper aCollator( ::comphelper::getProcessServiceFactory() ); 1251*cdf0e10cSrcweir aCollator.loadDefaultCollator( SvtSysLocale().GetLocaleData().getLocale(), 0 ); 1252*cdf0e10cSrcweir ::std::sort( aScriptDocs.begin(), aScriptDocs.end(), DocumentTitleLess( aCollator ) ); 1253*cdf0e10cSrcweir } 1254*cdf0e10cSrcweir 1255*cdf0e10cSrcweir return aScriptDocs; 1256*cdf0e10cSrcweir } 1257*cdf0e10cSrcweir 1258*cdf0e10cSrcweir //-------------------------------------------------------------------- 1259*cdf0e10cSrcweir bool ScriptDocument::operator==( const ScriptDocument& _rhs ) const 1260*cdf0e10cSrcweir { 1261*cdf0e10cSrcweir return m_pImpl->getDocumentRef() == _rhs.m_pImpl->getDocumentRef(); 1262*cdf0e10cSrcweir } 1263*cdf0e10cSrcweir 1264*cdf0e10cSrcweir //-------------------------------------------------------------------- 1265*cdf0e10cSrcweir sal_Int32 ScriptDocument::hashCode() const 1266*cdf0e10cSrcweir { 1267*cdf0e10cSrcweir return sal::static_int_cast<sal_Int32>(reinterpret_cast< sal_IntPtr >( m_pImpl->getDocumentRef().get() )); 1268*cdf0e10cSrcweir } 1269*cdf0e10cSrcweir 1270*cdf0e10cSrcweir //-------------------------------------------------------------------- 1271*cdf0e10cSrcweir bool ScriptDocument::isValid() const 1272*cdf0e10cSrcweir { 1273*cdf0e10cSrcweir return m_pImpl->isValid(); 1274*cdf0e10cSrcweir } 1275*cdf0e10cSrcweir 1276*cdf0e10cSrcweir //-------------------------------------------------------------------- 1277*cdf0e10cSrcweir bool ScriptDocument::isAlive() const 1278*cdf0e10cSrcweir { 1279*cdf0e10cSrcweir return m_pImpl->isAlive(); 1280*cdf0e10cSrcweir } 1281*cdf0e10cSrcweir 1282*cdf0e10cSrcweir //-------------------------------------------------------------------- 1283*cdf0e10cSrcweir Reference< XLibraryContainer > ScriptDocument::getLibraryContainer( LibraryContainerType _eType ) const 1284*cdf0e10cSrcweir { 1285*cdf0e10cSrcweir return m_pImpl->getLibraryContainer( _eType ); 1286*cdf0e10cSrcweir } 1287*cdf0e10cSrcweir 1288*cdf0e10cSrcweir //-------------------------------------------------------------------- 1289*cdf0e10cSrcweir Reference< XNameContainer > ScriptDocument::getLibrary( LibraryContainerType _eType, const ::rtl::OUString& _rLibName, bool _bLoadLibrary ) const 1290*cdf0e10cSrcweir SAL_THROW((NoSuchElementException)) 1291*cdf0e10cSrcweir { 1292*cdf0e10cSrcweir return m_pImpl->getLibrary( _eType, _rLibName, _bLoadLibrary ); 1293*cdf0e10cSrcweir } 1294*cdf0e10cSrcweir 1295*cdf0e10cSrcweir //-------------------------------------------------------------------- 1296*cdf0e10cSrcweir bool ScriptDocument::hasLibrary( LibraryContainerType _eType, const ::rtl::OUString& _rLibName ) const 1297*cdf0e10cSrcweir { 1298*cdf0e10cSrcweir return m_pImpl->hasLibrary( _eType, _rLibName ); 1299*cdf0e10cSrcweir } 1300*cdf0e10cSrcweir 1301*cdf0e10cSrcweir //-------------------------------------------------------------------- 1302*cdf0e10cSrcweir Reference< XNameContainer > ScriptDocument::getOrCreateLibrary( LibraryContainerType _eType, const ::rtl::OUString& _rLibName ) const 1303*cdf0e10cSrcweir { 1304*cdf0e10cSrcweir return m_pImpl->getOrCreateLibrary( _eType, _rLibName ); 1305*cdf0e10cSrcweir } 1306*cdf0e10cSrcweir 1307*cdf0e10cSrcweir //-------------------------------------------------------------------- 1308*cdf0e10cSrcweir void ScriptDocument::loadLibraryIfExists( LibraryContainerType _eType, const ::rtl::OUString& _rLibrary ) 1309*cdf0e10cSrcweir { 1310*cdf0e10cSrcweir m_pImpl->loadLibraryIfExists( _eType, _rLibrary ); 1311*cdf0e10cSrcweir } 1312*cdf0e10cSrcweir 1313*cdf0e10cSrcweir //-------------------------------------------------------------------- 1314*cdf0e10cSrcweir Sequence< ::rtl::OUString > ScriptDocument::getObjectNames( LibraryContainerType _eType, const ::rtl::OUString& _rLibName ) const 1315*cdf0e10cSrcweir { 1316*cdf0e10cSrcweir Sequence< ::rtl::OUString > aModuleNames; 1317*cdf0e10cSrcweir 1318*cdf0e10cSrcweir try 1319*cdf0e10cSrcweir { 1320*cdf0e10cSrcweir if ( hasLibrary( _eType, _rLibName ) ) 1321*cdf0e10cSrcweir { 1322*cdf0e10cSrcweir Reference< XNameContainer > xLib( getLibrary( _eType, _rLibName, false ) ); 1323*cdf0e10cSrcweir if ( xLib.is() ) 1324*cdf0e10cSrcweir aModuleNames = xLib->getElementNames(); 1325*cdf0e10cSrcweir } 1326*cdf0e10cSrcweir } 1327*cdf0e10cSrcweir catch( const Exception& ) 1328*cdf0e10cSrcweir { 1329*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 1330*cdf0e10cSrcweir } 1331*cdf0e10cSrcweir 1332*cdf0e10cSrcweir // sort 1333*cdf0e10cSrcweir ::std::sort( aModuleNames.getArray() , aModuleNames.getArray() + aModuleNames.getLength() , StringCompareLessThan ); 1334*cdf0e10cSrcweir 1335*cdf0e10cSrcweir return aModuleNames; 1336*cdf0e10cSrcweir } 1337*cdf0e10cSrcweir 1338*cdf0e10cSrcweir //-------------------------------------------------------------------- 1339*cdf0e10cSrcweir ::rtl::OUString ScriptDocument::createObjectName( LibraryContainerType _eType, const ::rtl::OUString& _rLibName ) const 1340*cdf0e10cSrcweir { 1341*cdf0e10cSrcweir ::rtl::OUString aObjectName; 1342*cdf0e10cSrcweir 1343*cdf0e10cSrcweir ::rtl::OUString aBaseName = _eType == E_SCRIPTS 1344*cdf0e10cSrcweir ? ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Module" ) ) 1345*cdf0e10cSrcweir : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Dialog" ) ); 1346*cdf0e10cSrcweir 1347*cdf0e10cSrcweir Sequence< ::rtl::OUString > aUsedNames( getObjectNames( _eType, _rLibName ) ); 1348*cdf0e10cSrcweir ::std::set< ::rtl::OUString > aUsedNamesCheck; 1349*cdf0e10cSrcweir ::std::copy( aUsedNames.getConstArray(), aUsedNames.getConstArray() + aUsedNames.getLength(), 1350*cdf0e10cSrcweir ::std::insert_iterator< ::std::set< ::rtl::OUString > >( aUsedNamesCheck, aUsedNamesCheck.begin() ) ); 1351*cdf0e10cSrcweir 1352*cdf0e10cSrcweir bool bValid = false; 1353*cdf0e10cSrcweir sal_uInt16 i = 1; 1354*cdf0e10cSrcweir while ( !bValid ) 1355*cdf0e10cSrcweir { 1356*cdf0e10cSrcweir aObjectName = aBaseName; 1357*cdf0e10cSrcweir aObjectName += String::CreateFromInt32( i ); 1358*cdf0e10cSrcweir 1359*cdf0e10cSrcweir if ( aUsedNamesCheck.find( aObjectName ) == aUsedNamesCheck.end() ) 1360*cdf0e10cSrcweir bValid = sal_True; 1361*cdf0e10cSrcweir 1362*cdf0e10cSrcweir ++i; 1363*cdf0e10cSrcweir } 1364*cdf0e10cSrcweir 1365*cdf0e10cSrcweir return aObjectName; 1366*cdf0e10cSrcweir } 1367*cdf0e10cSrcweir 1368*cdf0e10cSrcweir //-------------------------------------------------------------------- 1369*cdf0e10cSrcweir Sequence< ::rtl::OUString > ScriptDocument::getLibraryNames() const 1370*cdf0e10cSrcweir { 1371*cdf0e10cSrcweir return BasicIDE::GetMergedLibraryNames( getLibraryContainer( E_SCRIPTS ), getLibraryContainer( E_DIALOGS ) ); 1372*cdf0e10cSrcweir } 1373*cdf0e10cSrcweir 1374*cdf0e10cSrcweir //-------------------------------------------------------------------- 1375*cdf0e10cSrcweir bool ScriptDocument::isReadOnly() const 1376*cdf0e10cSrcweir { 1377*cdf0e10cSrcweir return m_pImpl->isReadOnly(); 1378*cdf0e10cSrcweir } 1379*cdf0e10cSrcweir 1380*cdf0e10cSrcweir //-------------------------------------------------------------------- 1381*cdf0e10cSrcweir bool ScriptDocument::isApplication() const 1382*cdf0e10cSrcweir { 1383*cdf0e10cSrcweir return m_pImpl->isApplication(); 1384*cdf0e10cSrcweir } 1385*cdf0e10cSrcweir 1386*cdf0e10cSrcweir bool ScriptDocument::isInVBAMode() const 1387*cdf0e10cSrcweir { 1388*cdf0e10cSrcweir return m_pImpl->isInVBAMode(); 1389*cdf0e10cSrcweir } 1390*cdf0e10cSrcweir 1391*cdf0e10cSrcweir //-------------------------------------------------------------------- 1392*cdf0e10cSrcweir BasicManager* ScriptDocument::getBasicManager() const 1393*cdf0e10cSrcweir { 1394*cdf0e10cSrcweir return m_pImpl->getBasicManager(); 1395*cdf0e10cSrcweir } 1396*cdf0e10cSrcweir 1397*cdf0e10cSrcweir //-------------------------------------------------------------------- 1398*cdf0e10cSrcweir Reference< XModel > ScriptDocument::getDocument() const 1399*cdf0e10cSrcweir { 1400*cdf0e10cSrcweir return m_pImpl->getDocument(); 1401*cdf0e10cSrcweir } 1402*cdf0e10cSrcweir 1403*cdf0e10cSrcweir //-------------------------------------------------------------------- 1404*cdf0e10cSrcweir Reference< XModel > ScriptDocument::getDocumentOrNull() const 1405*cdf0e10cSrcweir { 1406*cdf0e10cSrcweir if ( isDocument() ) 1407*cdf0e10cSrcweir return m_pImpl->getDocument(); 1408*cdf0e10cSrcweir return NULL; 1409*cdf0e10cSrcweir } 1410*cdf0e10cSrcweir 1411*cdf0e10cSrcweir //-------------------------------------------------------------------- 1412*cdf0e10cSrcweir bool ScriptDocument::removeModule( const ::rtl::OUString& _rLibName, const ::rtl::OUString& _rModuleName ) const 1413*cdf0e10cSrcweir { 1414*cdf0e10cSrcweir return m_pImpl->removeModuleOrDialog( E_SCRIPTS, _rLibName, _rModuleName ); 1415*cdf0e10cSrcweir } 1416*cdf0e10cSrcweir 1417*cdf0e10cSrcweir //-------------------------------------------------------------------- 1418*cdf0e10cSrcweir bool ScriptDocument::hasModule( const ::rtl::OUString& _rLibName, const ::rtl::OUString& _rModuleName ) const 1419*cdf0e10cSrcweir { 1420*cdf0e10cSrcweir return m_pImpl->hasModuleOrDialog( E_SCRIPTS, _rLibName, _rModuleName ); 1421*cdf0e10cSrcweir } 1422*cdf0e10cSrcweir 1423*cdf0e10cSrcweir //-------------------------------------------------------------------- 1424*cdf0e10cSrcweir bool ScriptDocument::getModule( const ::rtl::OUString& _rLibName, const ::rtl::OUString& _rModName, ::rtl::OUString& _out_rModuleSource ) const 1425*cdf0e10cSrcweir { 1426*cdf0e10cSrcweir Any aCode; 1427*cdf0e10cSrcweir if ( !m_pImpl->getModuleOrDialog( E_SCRIPTS, _rLibName, _rModName, aCode ) ) 1428*cdf0e10cSrcweir return false; 1429*cdf0e10cSrcweir OSL_VERIFY( aCode >>= _out_rModuleSource ); 1430*cdf0e10cSrcweir return true; 1431*cdf0e10cSrcweir } 1432*cdf0e10cSrcweir 1433*cdf0e10cSrcweir //-------------------------------------------------------------------- 1434*cdf0e10cSrcweir bool ScriptDocument::renameModule( const ::rtl::OUString& _rLibName, const ::rtl::OUString& _rOldName, const ::rtl::OUString& _rNewName ) const 1435*cdf0e10cSrcweir { 1436*cdf0e10cSrcweir return m_pImpl->renameModuleOrDialog( E_SCRIPTS, _rLibName, _rOldName, _rNewName, NULL ); 1437*cdf0e10cSrcweir } 1438*cdf0e10cSrcweir 1439*cdf0e10cSrcweir //-------------------------------------------------------------------- 1440*cdf0e10cSrcweir bool ScriptDocument::createModule( const ::rtl::OUString& _rLibName, const ::rtl::OUString& _rModName, bool _bCreateMain, ::rtl::OUString& _out_rNewModuleCode ) const 1441*cdf0e10cSrcweir { 1442*cdf0e10cSrcweir if ( !m_pImpl->createModule( _rLibName, _rModName, _bCreateMain, _out_rNewModuleCode ) ) 1443*cdf0e10cSrcweir return false; 1444*cdf0e10cSrcweir 1445*cdf0e10cSrcweir // doc shell modified 1446*cdf0e10cSrcweir BasicIDE::MarkDocumentModified( *const_cast< ScriptDocument* >( this ) ); // here? 1447*cdf0e10cSrcweir return true; 1448*cdf0e10cSrcweir } 1449*cdf0e10cSrcweir 1450*cdf0e10cSrcweir //-------------------------------------------------------------------- 1451*cdf0e10cSrcweir bool ScriptDocument::insertModule( const ::rtl::OUString& _rLibName, const ::rtl::OUString& _rModName, const ::rtl::OUString& _rModuleCode ) const 1452*cdf0e10cSrcweir { 1453*cdf0e10cSrcweir return m_pImpl->insertModuleOrDialog( E_SCRIPTS, _rLibName, _rModName, makeAny( _rModuleCode ) ); 1454*cdf0e10cSrcweir } 1455*cdf0e10cSrcweir 1456*cdf0e10cSrcweir //-------------------------------------------------------------------- 1457*cdf0e10cSrcweir bool ScriptDocument::updateModule( const ::rtl::OUString& _rLibName, const ::rtl::OUString& _rModName, const ::rtl::OUString& _rModuleCode ) const 1458*cdf0e10cSrcweir { 1459*cdf0e10cSrcweir return m_pImpl->updateModule( _rLibName, _rModName, _rModuleCode ); 1460*cdf0e10cSrcweir } 1461*cdf0e10cSrcweir 1462*cdf0e10cSrcweir //-------------------------------------------------------------------- 1463*cdf0e10cSrcweir bool ScriptDocument::removeDialog( const ::rtl::OUString& _rLibName, const ::rtl::OUString& _rDialogName ) const 1464*cdf0e10cSrcweir { 1465*cdf0e10cSrcweir return m_pImpl->removeModuleOrDialog( E_DIALOGS, _rLibName, _rDialogName ); 1466*cdf0e10cSrcweir } 1467*cdf0e10cSrcweir 1468*cdf0e10cSrcweir //-------------------------------------------------------------------- 1469*cdf0e10cSrcweir bool ScriptDocument::hasDialog( const ::rtl::OUString& _rLibName, const ::rtl::OUString& _rDialogName ) const 1470*cdf0e10cSrcweir { 1471*cdf0e10cSrcweir return m_pImpl->hasModuleOrDialog( E_DIALOGS, _rLibName, _rDialogName ); 1472*cdf0e10cSrcweir } 1473*cdf0e10cSrcweir 1474*cdf0e10cSrcweir //-------------------------------------------------------------------- 1475*cdf0e10cSrcweir bool ScriptDocument::getDialog( const ::rtl::OUString& _rLibName, const ::rtl::OUString& _rDialogName, Reference< XInputStreamProvider >& _out_rDialogProvider ) const 1476*cdf0e10cSrcweir { 1477*cdf0e10cSrcweir Any aCode; 1478*cdf0e10cSrcweir if ( !m_pImpl->getModuleOrDialog( E_DIALOGS, _rLibName, _rDialogName, aCode ) ) 1479*cdf0e10cSrcweir return false; 1480*cdf0e10cSrcweir OSL_VERIFY( aCode >>= _out_rDialogProvider ); 1481*cdf0e10cSrcweir return _out_rDialogProvider.is(); 1482*cdf0e10cSrcweir } 1483*cdf0e10cSrcweir 1484*cdf0e10cSrcweir //-------------------------------------------------------------------- 1485*cdf0e10cSrcweir bool ScriptDocument::renameDialog( const ::rtl::OUString& _rLibName, const ::rtl::OUString& _rOldName, const ::rtl::OUString& _rNewName, const Reference< XNameContainer >& _rxExistingDialogModel ) const 1486*cdf0e10cSrcweir { 1487*cdf0e10cSrcweir return m_pImpl->renameModuleOrDialog( E_DIALOGS, _rLibName, _rOldName, _rNewName, _rxExistingDialogModel ); 1488*cdf0e10cSrcweir } 1489*cdf0e10cSrcweir 1490*cdf0e10cSrcweir //-------------------------------------------------------------------- 1491*cdf0e10cSrcweir bool ScriptDocument::createDialog( const ::rtl::OUString& _rLibName, const ::rtl::OUString& _rDialogName, Reference< XInputStreamProvider >& _out_rDialogProvider ) const 1492*cdf0e10cSrcweir { 1493*cdf0e10cSrcweir if ( !m_pImpl->createDialog( _rLibName, _rDialogName, _out_rDialogProvider ) ) 1494*cdf0e10cSrcweir return false; 1495*cdf0e10cSrcweir 1496*cdf0e10cSrcweir BasicIDE::MarkDocumentModified( *const_cast< ScriptDocument* >( this ) ); // here? 1497*cdf0e10cSrcweir return true; 1498*cdf0e10cSrcweir } 1499*cdf0e10cSrcweir 1500*cdf0e10cSrcweir //-------------------------------------------------------------------- 1501*cdf0e10cSrcweir bool ScriptDocument::insertDialog( const ::rtl::OUString& _rLibName, const ::rtl::OUString& _rDialogName, const Reference< XInputStreamProvider >& _rxDialogProvider ) const 1502*cdf0e10cSrcweir { 1503*cdf0e10cSrcweir return m_pImpl->insertModuleOrDialog( E_DIALOGS, _rLibName, _rDialogName, makeAny( _rxDialogProvider ) ); 1504*cdf0e10cSrcweir } 1505*cdf0e10cSrcweir 1506*cdf0e10cSrcweir //-------------------------------------------------------------------- 1507*cdf0e10cSrcweir void ScriptDocument::setDocumentModified() const 1508*cdf0e10cSrcweir { 1509*cdf0e10cSrcweir m_pImpl->setDocumentModified(); 1510*cdf0e10cSrcweir } 1511*cdf0e10cSrcweir 1512*cdf0e10cSrcweir //-------------------------------------------------------------------- 1513*cdf0e10cSrcweir bool ScriptDocument::isDocumentModified() const 1514*cdf0e10cSrcweir { 1515*cdf0e10cSrcweir return m_pImpl->isDocumentModified(); 1516*cdf0e10cSrcweir } 1517*cdf0e10cSrcweir 1518*cdf0e10cSrcweir //-------------------------------------------------------------------- 1519*cdf0e10cSrcweir bool ScriptDocument::saveDocument( const Reference< XStatusIndicator >& _rxStatusIndicator ) const 1520*cdf0e10cSrcweir { 1521*cdf0e10cSrcweir return m_pImpl->saveDocument( _rxStatusIndicator ); 1522*cdf0e10cSrcweir } 1523*cdf0e10cSrcweir 1524*cdf0e10cSrcweir //-------------------------------------------------------------------- 1525*cdf0e10cSrcweir LibraryLocation ScriptDocument::getLibraryLocation( const ::rtl::OUString& _rLibName ) const 1526*cdf0e10cSrcweir { 1527*cdf0e10cSrcweir LibraryLocation eLocation = LIBRARY_LOCATION_UNKNOWN; 1528*cdf0e10cSrcweir if ( _rLibName.getLength() ) 1529*cdf0e10cSrcweir { 1530*cdf0e10cSrcweir if ( isDocument() ) 1531*cdf0e10cSrcweir { 1532*cdf0e10cSrcweir eLocation = LIBRARY_LOCATION_DOCUMENT; 1533*cdf0e10cSrcweir } 1534*cdf0e10cSrcweir else 1535*cdf0e10cSrcweir { 1536*cdf0e10cSrcweir if ( ( hasLibrary( E_SCRIPTS, _rLibName ) && !m_pImpl->isLibraryShared( _rLibName, E_SCRIPTS ) ) 1537*cdf0e10cSrcweir || ( hasLibrary( E_DIALOGS, _rLibName ) && !m_pImpl->isLibraryShared( _rLibName, E_DIALOGS ) ) 1538*cdf0e10cSrcweir ) 1539*cdf0e10cSrcweir { 1540*cdf0e10cSrcweir eLocation = LIBRARY_LOCATION_USER; 1541*cdf0e10cSrcweir } 1542*cdf0e10cSrcweir else 1543*cdf0e10cSrcweir { 1544*cdf0e10cSrcweir eLocation = LIBRARY_LOCATION_SHARE; 1545*cdf0e10cSrcweir } 1546*cdf0e10cSrcweir } 1547*cdf0e10cSrcweir } 1548*cdf0e10cSrcweir 1549*cdf0e10cSrcweir return eLocation; 1550*cdf0e10cSrcweir } 1551*cdf0e10cSrcweir 1552*cdf0e10cSrcweir //-------------------------------------------------------------------- 1553*cdf0e10cSrcweir ::rtl::OUString ScriptDocument::getTitle( LibraryLocation _eLocation, LibraryType _eType ) const 1554*cdf0e10cSrcweir { 1555*cdf0e10cSrcweir ::rtl::OUString aTitle; 1556*cdf0e10cSrcweir 1557*cdf0e10cSrcweir switch ( _eLocation ) 1558*cdf0e10cSrcweir { 1559*cdf0e10cSrcweir case LIBRARY_LOCATION_USER: 1560*cdf0e10cSrcweir { 1561*cdf0e10cSrcweir switch ( _eType ) 1562*cdf0e10cSrcweir { 1563*cdf0e10cSrcweir case LIBRARY_TYPE_MODULE: aTitle = String( IDEResId( RID_STR_USERMACROS ) ); break; 1564*cdf0e10cSrcweir case LIBRARY_TYPE_DIALOG: aTitle = String( IDEResId( RID_STR_USERDIALOGS ) ); break; 1565*cdf0e10cSrcweir case LIBRARY_TYPE_ALL: aTitle = String( IDEResId( RID_STR_USERMACROSDIALOGS ) ); break; 1566*cdf0e10cSrcweir default: 1567*cdf0e10cSrcweir break; 1568*cdf0e10cSrcweir } 1569*cdf0e10cSrcweir break; 1570*cdf0e10cSrcweir case LIBRARY_LOCATION_SHARE: 1571*cdf0e10cSrcweir { 1572*cdf0e10cSrcweir switch ( _eType ) 1573*cdf0e10cSrcweir { 1574*cdf0e10cSrcweir case LIBRARY_TYPE_MODULE: aTitle = String( IDEResId( RID_STR_SHAREMACROS ) ); break; 1575*cdf0e10cSrcweir case LIBRARY_TYPE_DIALOG: aTitle = String( IDEResId( RID_STR_SHAREDIALOGS ) ); break; 1576*cdf0e10cSrcweir case LIBRARY_TYPE_ALL: aTitle = String( IDEResId( RID_STR_SHAREMACROSDIALOGS ) ); break; 1577*cdf0e10cSrcweir default: 1578*cdf0e10cSrcweir break; 1579*cdf0e10cSrcweir } 1580*cdf0e10cSrcweir } 1581*cdf0e10cSrcweir break; 1582*cdf0e10cSrcweir case LIBRARY_LOCATION_DOCUMENT: 1583*cdf0e10cSrcweir aTitle = getTitle(); 1584*cdf0e10cSrcweir break; 1585*cdf0e10cSrcweir default: 1586*cdf0e10cSrcweir break; 1587*cdf0e10cSrcweir } 1588*cdf0e10cSrcweir } 1589*cdf0e10cSrcweir 1590*cdf0e10cSrcweir return aTitle; 1591*cdf0e10cSrcweir } 1592*cdf0e10cSrcweir 1593*cdf0e10cSrcweir //-------------------------------------------------------------------- 1594*cdf0e10cSrcweir ::rtl::OUString ScriptDocument::getTitle() const 1595*cdf0e10cSrcweir { 1596*cdf0e10cSrcweir return m_pImpl->getTitle(); 1597*cdf0e10cSrcweir } 1598*cdf0e10cSrcweir 1599*cdf0e10cSrcweir //-------------------------------------------------------------------- 1600*cdf0e10cSrcweir ::rtl::OUString ScriptDocument::getURL() const 1601*cdf0e10cSrcweir { 1602*cdf0e10cSrcweir return m_pImpl->getURL(); 1603*cdf0e10cSrcweir } 1604*cdf0e10cSrcweir 1605*cdf0e10cSrcweir //-------------------------------------------------------------------- 1606*cdf0e10cSrcweir bool ScriptDocument::isActive() const 1607*cdf0e10cSrcweir { 1608*cdf0e10cSrcweir bool bIsActive( false ); 1609*cdf0e10cSrcweir try 1610*cdf0e10cSrcweir { 1611*cdf0e10cSrcweir Reference< XFrame > xFrame; 1612*cdf0e10cSrcweir if ( m_pImpl->getCurrentFrame( xFrame ) ) 1613*cdf0e10cSrcweir bIsActive = xFrame->isActive(); 1614*cdf0e10cSrcweir } 1615*cdf0e10cSrcweir catch( const Exception& ) 1616*cdf0e10cSrcweir { 1617*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 1618*cdf0e10cSrcweir } 1619*cdf0e10cSrcweir return bIsActive; 1620*cdf0e10cSrcweir } 1621*cdf0e10cSrcweir 1622*cdf0e10cSrcweir //-------------------------------------------------------------------- 1623*cdf0e10cSrcweir bool ScriptDocument::allowMacros() const 1624*cdf0e10cSrcweir { 1625*cdf0e10cSrcweir return m_pImpl->allowMacros(); 1626*cdf0e10cSrcweir } 1627*cdf0e10cSrcweir 1628*cdf0e10cSrcweir //........................................................................ 1629*cdf0e10cSrcweir } // namespace basctl 1630*cdf0e10cSrcweir //........................................................................ 1631