1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: scriptdocument.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_basctl.hxx"
34 #include "scriptdocument.hxx"
36 #include "basidesh.hrc"
38 #include "dlgeddef.hxx"
39 #include "localizationmgr.hxx"
40 #include "doceventnotifier.hxx"
41 #include "documentenumeration.hxx"
43 /** === begin UNO includes === **/
44 #include <com/sun/star/beans/XPropertySet.hpp>
45 #include <com/sun/star/script/XLibraryContainer2.hpp>
46 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
47 #include <com/sun/star/uri/XUriReferenceFactory.hpp>
48 #include <com/sun/star/util/XMacroExpander.hpp>
49 #include <com/sun/star/document/MacroExecMode.hpp>
50 #include <com/sun/star/document/XEventBroadcaster.hpp>
51 #include <com/sun/star/frame/XStorable.hpp>
52 #include <com/sun/star/util/XModifiable.hpp>
53 #include <com/sun/star/frame/XDispatchProvider.hpp>
54 #include <com/sun/star/frame/FrameSearchFlag.hpp>
55 #include <com/sun/star/frame/XDesktop.hpp>
56 #include <com/sun/star/frame/XModel2.hpp>
57 #include <com/sun/star/awt/XWindow2.hpp>
58 #include <com/sun/star/document/XEmbeddedScripts.hpp>
59 #include <com/sun/star/script/ModuleInfo.hpp>
60 /** === end UNO includes === **/
62 #include <sfx2/objsh.hxx>
63 #include <sfx2/app.hxx>
64 #include <sfx2/viewfrm.hxx>
65 #include <sfx2/bindings.hxx>
66 #include <sfx2/docfile.hxx>
68 #include <vcl/svapp.hxx>
70 #include <basic/basicmanagerrepository.hxx>
72 #include <xmlscript/xmldlg_imexp.hxx>
74 #include <svtools/syslocale.hxx>
76 #include <unotools/collatorwrapper.hxx>
78 #include <tools/diagnose_ex.h>
79 #include <tools/urlobj.hxx>
81 #include <comphelper/processfactory.hxx>
82 #include <comphelper/documentinfo.hxx>
83 #include <comphelper/componentcontext.hxx>
85 #include <vos/mutex.hxx>
87 #include <cppuhelper/implbase1.hxx>
89 #include <rtl/uri.hxx>
90 #include <rtl/bootstrap.hxx>
92 #include <osl/process.h>
93 #include <osl/file.hxx>
99 //........................................................................
102 //........................................................................
104 /** === begin UNO using === **/
105 using ::com::sun::star::uno::Sequence
;
106 using ::com::sun::star::uno::Reference
;
107 using ::com::sun::star::frame::XModel
;
108 using ::com::sun::star::beans::XPropertySet
;
109 using ::com::sun::star::script::XLibraryContainer
;
110 using ::com::sun::star::uno::UNO_QUERY_THROW
;
111 using ::com::sun::star::uno::UNO_SET_THROW
;
112 using ::com::sun::star::beans::XPropertySetInfo
;
113 using ::com::sun::star::uno::Exception
;
114 using ::com::sun::star::container::XNameContainer
;
115 using ::com::sun::star::container::NoSuchElementException
;
116 using ::com::sun::star::uno::UNO_QUERY
;
117 using ::com::sun::star::task::XStatusIndicator
;
118 using ::com::sun::star::uno::makeAny
;
119 using ::com::sun::star::script::XLibraryContainer2
;
120 using ::com::sun::star::lang::XMultiServiceFactory
;
121 using ::com::sun::star::uri::XUriReferenceFactory
;
122 using ::com::sun::star::uri::XUriReference
;
123 using ::com::sun::star::uno::XComponentContext
;
124 using ::com::sun::star::util::XMacroExpander
;
125 using ::com::sun::star::io::XInputStreamProvider
;
126 using ::com::sun::star::uno::Any
;
127 using ::com::sun::star::io::XInputStream
;
128 using ::com::sun::star::frame::XStorable
;
129 using ::com::sun::star::util::XModifiable
;
130 using ::com::sun::star::frame::XController
;
131 using ::com::sun::star::frame::XFrame
;
132 using ::com::sun::star::util::URL
;
133 using ::com::sun::star::frame::XDispatchProvider
;
134 using ::com::sun::star::frame::XDispatch
;
135 using ::com::sun::star::beans::PropertyValue
;
136 using ::com::sun::star::frame::XDesktop
;
137 using ::com::sun::star::container::XEnumerationAccess
;
138 using ::com::sun::star::container::XEnumeration
;
139 using ::com::sun::star::frame::XModel2
;
140 using ::com::sun::star::awt::XWindow2
;
141 using ::com::sun::star::document::XEventListener
;
142 using ::com::sun::star::lang::EventObject
;
143 using ::com::sun::star::uno::RuntimeException
;
144 using ::com::sun::star::document::XEventBroadcaster
;
145 using ::com::sun::star::document::XEmbeddedScripts
;
146 using ::com::sun::star::script::ModuleInfo
;
147 /** === end UNO using === **/
148 namespace MacroExecMode
= ::com::sun::star::document::MacroExecMode
;
149 namespace FrameSearchFlag
= ::com::sun::star::frame::FrameSearchFlag
;
151 //====================================================================
153 //====================================================================
156 //................................................................
157 static bool StringCompareLessThan( const String
& lhs
, const String
& rhs
)
159 return ( lhs
.CompareIgnoreCaseToAscii( rhs
) == COMPARE_LESS
);
162 //................................................................
163 class FilterDocuments
: public docs::IDocumentDescriptorFilter
166 FilterDocuments( bool _bFilterInvisible
) : m_bFilterInvisible( _bFilterInvisible
) { }
168 virtual bool includeDocument( const docs::DocumentDescriptor
& _rDocument
) const;
171 bool impl_isDocumentVisible_nothrow( const docs::DocumentDescriptor
& _rDocument
) const;
174 bool m_bFilterInvisible
;
177 //................................................................
178 bool FilterDocuments::impl_isDocumentVisible_nothrow( const docs::DocumentDescriptor
& _rDocument
) const
182 for ( docs::Controllers::const_iterator controller
= _rDocument
.aControllers
.begin();
183 controller
!= _rDocument
.aControllers
.end();
187 Reference
< XFrame
> xFrame( (*controller
)->getFrame(), UNO_SET_THROW
);
188 Reference
< XWindow2
> xContainer( xFrame
->getContainerWindow(), UNO_QUERY_THROW
);
189 if ( xContainer
->isVisible() )
193 catch( const Exception
& )
195 DBG_UNHANDLED_EXCEPTION();
200 //................................................................
201 bool FilterDocuments::includeDocument( const docs::DocumentDescriptor
& _rDocument
) const
203 Reference
< XEmbeddedScripts
> xScripts( _rDocument
.xModel
, UNO_QUERY
);
204 if ( !xScripts
.is() )
206 if ( !m_bFilterInvisible
|| impl_isDocumentVisible_nothrow( _rDocument
) )
211 //................................................................
212 void lcl_getAllModels_throw( docs::Documents
& _out_rModels
, bool _bVisibleOnly
)
214 _out_rModels
.clear();
216 ::comphelper::ComponentContext
aContext( ::comphelper::getProcessServiceFactory() );
217 FilterDocuments
aFilter( _bVisibleOnly
);
218 docs::DocumentEnumeration
aEnum( aContext
, &aFilter
);
220 aEnum
.getDocuments( _out_rModels
);
224 //====================================================================
225 //= ScriptDocument_Impl - declaration
226 //====================================================================
227 class ScriptDocument_Impl
: public DocumentEventListener
230 bool m_bIsApplication
;
232 bool m_bDocumentClosed
;
233 Reference
< XModel
> m_xDocument
;
234 Reference
< XModifiable
> m_xDocModify
;
235 Reference
< XEmbeddedScripts
> m_xScriptAccess
;
236 ::std::auto_ptr
< DocumentEventNotifier
>
240 ScriptDocument_Impl( );
241 ScriptDocument_Impl( const Reference
< XModel
>& _rxDocument
);
242 ~ScriptDocument_Impl();
244 /** determines whether the instance refers to a valid "document" with script and
247 inline bool isValid() const { return m_bValid
; }
248 /** determines whether the instance refers to a non-closed document
250 inline bool isAlive() const { return m_bValid
? ( m_bIsApplication
? true : !m_bDocumentClosed
) : false; }
251 /// determines whether the "document" refers to the application in real
252 inline bool isApplication() const { return m_bValid
&& m_bIsApplication
; }
253 /// determines whether the document refers to a real document (instead of the application)
254 inline bool isDocument() const { return m_bValid
&& !m_bIsApplication
; }
256 /** invalidates the instance
260 const Reference
< XModel
>&
261 getDocumentRef() const { return m_xDocument
; }
263 /// returns a library container belonging to the document
264 Reference
< XLibraryContainer
>
265 getLibraryContainer( LibraryContainerType _eType
) const;
267 /// determines whether a given library is part of the shared installation
268 bool isLibraryShared( const ::rtl::OUString
& _rLibName
, LibraryContainerType _eType
);
270 /** returns the current frame of the document
272 To be called for documents only, not for the application.
274 If <FALSE/> is returned, an assertion will be raised in non-product builds.
276 bool getCurrentFrame( Reference
< XFrame
>& _out_rxFrame
) const;
278 // versions with the same signature/semantics as in ScriptDocument itself
279 bool isReadOnly() const;
281 getBasicManager() const;
284 void setDocumentModified() const;
285 bool isDocumentModified() const;
286 bool saveDocument( const Reference
< XStatusIndicator
>& _rxStatusIndicator
) const;
293 bool allowMacros() const;
295 Reference
< XNameContainer
>
296 getLibrary( LibraryContainerType _eType
, const ::rtl::OUString
& _rLibName
, bool _bLoadLibrary
) const
297 SAL_THROW((NoSuchElementException
));
298 bool hasLibrary( LibraryContainerType _eType
, const ::rtl::OUString
& _rLibName
) const;
299 Reference
< XNameContainer
>
300 getOrCreateLibrary( LibraryContainerType _eType
, const ::rtl::OUString
& _rLibName
) const;
302 void loadLibraryIfExists( LibraryContainerType _eType
, const ::rtl::OUString
& _rLibrary
);
304 bool removeModuleOrDialog( LibraryContainerType _eType
, const ::rtl::OUString
& _rLibName
, const ::rtl::OUString
& _rModuleName
);
305 bool hasModuleOrDialog( LibraryContainerType _eType
, const ::rtl::OUString
& _rLibName
, const ::rtl::OUString
& _rModName
) const;
306 bool getModuleOrDialog( LibraryContainerType _eType
, const ::rtl::OUString
& _rLibName
, const ::rtl::OUString
& _rObjectName
, Any
& _out_rModuleOrDialog
);
307 bool renameModuleOrDialog( LibraryContainerType _eType
, const ::rtl::OUString
& _rLibName
, const ::rtl::OUString
& _rOldName
, const ::rtl::OUString
& _rNewName
, const Reference
< XNameContainer
>& _rxExistingDialogModel
);
308 bool createModule( const ::rtl::OUString
& _rLibName
, const ::rtl::OUString
& _rModName
, bool _bCreateMain
, ::rtl::OUString
& _out_rNewModuleCode
) const;
309 bool insertModuleOrDialog( LibraryContainerType _eType
, const ::rtl::OUString
& _rObjectName
, const ::rtl::OUString
& _rModName
, const Any
& _rElement
) const;
310 bool updateModule( const ::rtl::OUString
& _rLibName
, const ::rtl::OUString
& _rModName
, const ::rtl::OUString
& _rModuleCode
) const;
311 bool createDialog( const ::rtl::OUString
& _rLibName
, const ::rtl::OUString
& _rDialogName
, Reference
< XInputStreamProvider
>& _out_rDialogProvider
) const;
314 // DocumentEventListener
315 virtual void onDocumentCreated( const ScriptDocument
& _rDocument
);
316 virtual void onDocumentOpened( const ScriptDocument
& _rDocument
);
317 virtual void onDocumentSave( const ScriptDocument
& _rDocument
);
318 virtual void onDocumentSaveDone( const ScriptDocument
& _rDocument
);
319 virtual void onDocumentSaveAs( const ScriptDocument
& _rDocument
);
320 virtual void onDocumentSaveAsDone( const ScriptDocument
& _rDocument
);
321 virtual void onDocumentClosed( const ScriptDocument
& _rDocument
);
322 virtual void onDocumentTitleChanged( const ScriptDocument
& _rDocument
);
323 virtual void onDocumentModeChanged( const ScriptDocument
& _rDocument
);
326 bool impl_initDocument_nothrow( const Reference
< XModel
>& _rxModel
);
329 //====================================================================
330 //= ScriptDocument_Impl - implementation
331 //====================================================================
332 //--------------------------------------------------------------------
333 ScriptDocument_Impl::ScriptDocument_Impl()
334 :m_bIsApplication( true )
336 ,m_bDocumentClosed( false )
340 //--------------------------------------------------------------------
341 ScriptDocument_Impl::ScriptDocument_Impl( const Reference
< XModel
>& _rxDocument
)
342 :m_bIsApplication( false )
344 ,m_bDocumentClosed( false )
346 if ( _rxDocument
.is() )
348 if ( impl_initDocument_nothrow( _rxDocument
) )
354 //--------------------------------------------------------------------
355 ScriptDocument_Impl::~ScriptDocument_Impl()
360 //--------------------------------------------------------------------
361 void ScriptDocument_Impl::invalidate()
363 m_bIsApplication
= false;
365 m_bDocumentClosed
= false;
368 m_xDocModify
.clear();
369 m_xScriptAccess
.clear();
371 if ( m_pDocListener
.get() )
372 m_pDocListener
->dispose();
375 //--------------------------------------------------------------------
376 bool ScriptDocument_Impl::impl_initDocument_nothrow( const Reference
< XModel
>& _rxModel
)
380 m_xDocument
.set ( _rxModel
, UNO_SET_THROW
);
381 m_xDocModify
.set ( _rxModel
, UNO_QUERY_THROW
);
382 m_xScriptAccess
.set ( _rxModel
, UNO_QUERY
);
384 m_bValid
= m_xScriptAccess
.is();
387 m_pDocListener
.reset( new DocumentEventNotifier( *this, _rxModel
) );
389 catch( const Exception
& )
391 DBG_UNHANDLED_EXCEPTION();
402 //--------------------------------------------------------------------
403 Reference
< XLibraryContainer
> ScriptDocument_Impl::getLibraryContainer( LibraryContainerType _eType
) const
405 OSL_ENSURE( isValid(), "ScriptDocument_Impl::getLibraryContainer: invalid!" );
407 Reference
< XLibraryContainer
> xContainer
;
413 if ( isApplication() )
414 xContainer
.set( _eType
== E_SCRIPTS
? SFX_APP()->GetBasicContainer() : SFX_APP()->GetDialogContainer(), UNO_QUERY_THROW
);
418 _eType
== E_SCRIPTS
? m_xScriptAccess
->getBasicLibraries() : m_xScriptAccess
->getDialogLibraries(),
422 catch( const Exception
& )
424 DBG_UNHANDLED_EXCEPTION();
429 //--------------------------------------------------------------------
430 bool ScriptDocument_Impl::isReadOnly() const
432 OSL_ENSURE( isValid(), "ScriptDocument_Impl::isReadOnly: invalid state!" );
433 OSL_ENSURE( !isApplication(), "ScriptDocument_Impl::isReadOnly: not allowed to be called for the application!" );
435 bool bIsReadOnly
= true;
436 if ( isValid() && !isApplication() )
440 // note that XStorable is required by the OfficeDocument service
441 Reference
< XStorable
> xDocStorable( m_xDocument
, UNO_QUERY_THROW
);
442 bIsReadOnly
= xDocStorable
->isReadonly();
444 catch( const Exception
& )
446 DBG_UNHANDLED_EXCEPTION();
452 //--------------------------------------------------------------------
453 BasicManager
* ScriptDocument_Impl::getBasicManager() const
455 OSL_ENSURE( isValid(), "ScriptDocument_Impl::getBasicManager: invalid state!" );
459 if ( isApplication() )
460 return SFX_APP()->GetBasicManager();
462 return ::basic::BasicManagerRepository::getDocumentBasicManager( m_xDocument
);
465 //--------------------------------------------------------------------
466 Reference
< XModel
> ScriptDocument_Impl::getDocument() const
468 OSL_ENSURE( isValid(), "ScriptDocument_Impl::getDocument: invalid state!" );
469 OSL_ENSURE( isDocument(), "ScriptDocument_Impl::getDocument: for documents only!" );
470 if ( !isValid() || !isDocument() )
476 //--------------------------------------------------------------------
477 Reference
< XNameContainer
> ScriptDocument_Impl::getLibrary( LibraryContainerType _eType
, const ::rtl::OUString
& _rLibName
, bool _bLoadLibrary
) const
478 SAL_THROW((NoSuchElementException
))
480 OSL_ENSURE( isValid(), "ScriptDocument_Impl::getLibrary: invalid state!" );
482 Reference
< XNameContainer
> xContainer
;
485 Reference
< XLibraryContainer
> xLibContainer
= getLibraryContainer( _eType
);
488 if ( xLibContainer
.is() )
489 xContainer
.set( xLibContainer
->getByName( _rLibName
), UNO_QUERY_THROW
);
492 if ( !xContainer
.is() )
493 throw NoSuchElementException();
496 if ( _bLoadLibrary
&& !xLibContainer
->isLibraryLoaded( _rLibName
) )
497 xLibContainer
->loadLibrary( _rLibName
);
499 catch( const NoSuchElementException
& )
501 throw; // allowed to leave
503 catch( const Exception
& )
505 DBG_UNHANDLED_EXCEPTION();
511 //--------------------------------------------------------------------
512 bool ScriptDocument_Impl::hasLibrary( LibraryContainerType _eType
, const ::rtl::OUString
& _rLibName
) const
517 Reference
< XLibraryContainer
> xLibContainer
= getLibraryContainer( _eType
);
518 bHas
= xLibContainer
.is() && xLibContainer
->hasByName( _rLibName
);
520 catch( const Exception
& )
522 DBG_UNHANDLED_EXCEPTION();
527 //--------------------------------------------------------------------
528 Reference
< XNameContainer
> ScriptDocument_Impl::getOrCreateLibrary( LibraryContainerType _eType
, const ::rtl::OUString
& _rLibName
) const
530 Reference
< XNameContainer
> xLibrary
;
533 Reference
< XLibraryContainer
> xLibContainer( getLibraryContainer( _eType
), UNO_QUERY_THROW
);
534 if ( xLibContainer
->hasByName( _rLibName
) )
535 xLibrary
.set( xLibContainer
->getByName( _rLibName
), UNO_QUERY_THROW
);
537 xLibrary
.set( xLibContainer
->createLibrary( _rLibName
), UNO_QUERY_THROW
);
539 if ( !xLibContainer
->isLibraryLoaded( _rLibName
) )
540 xLibContainer
->loadLibrary( _rLibName
);
542 catch( const Exception
& )
544 DBG_UNHANDLED_EXCEPTION();
549 //--------------------------------------------------------------------
550 void ScriptDocument_Impl::loadLibraryIfExists( LibraryContainerType _eType
, const ::rtl::OUString
& _rLibrary
)
554 Reference
< XLibraryContainer
> xLibContainer( getLibraryContainer( _eType
) );
555 if ( xLibContainer
.is() && xLibContainer
->hasByName( _rLibrary
) && !xLibContainer
->isLibraryLoaded( _rLibrary
) )
556 xLibContainer
->loadLibrary( _rLibrary
);
558 catch( const Exception
& )
560 DBG_UNHANDLED_EXCEPTION();
564 //--------------------------------------------------------------------
565 bool ScriptDocument_Impl::removeModuleOrDialog( LibraryContainerType _eType
, const ::rtl::OUString
& _rLibName
, const ::rtl::OUString
& _rModuleName
)
567 OSL_ENSURE( isValid(), "ScriptDocument_Impl::removeModuleOrDialog: invalid!" );
572 Reference
< XNameContainer
> xLib( getLibrary( _eType
, _rLibName
, TRUE
) );
575 xLib
->removeByName( _rModuleName
);
579 catch( const Exception
& )
581 DBG_UNHANDLED_EXCEPTION();
587 //--------------------------------------------------------------------
588 bool ScriptDocument_Impl::hasModuleOrDialog( LibraryContainerType _eType
, const ::rtl::OUString
& _rLibName
, const ::rtl::OUString
& _rModName
) const
590 OSL_ENSURE( isValid(), "ScriptDocument_Impl::hasModuleOrDialog: invalid!" );
596 Reference
< XNameContainer
> xLib( getLibrary( _eType
, _rLibName
, TRUE
) );
598 return xLib
->hasByName( _rModName
);
600 catch( const Exception
& )
602 DBG_UNHANDLED_EXCEPTION();
607 //--------------------------------------------------------------------
608 bool ScriptDocument_Impl::getModuleOrDialog( LibraryContainerType _eType
, const ::rtl::OUString
& _rLibName
, const ::rtl::OUString
& _rObjectName
, Any
& _out_rModuleOrDialog
)
610 OSL_ENSURE( isValid(), "ScriptDocument_Impl::getModuleOrDialog: invalid!" );
614 _out_rModuleOrDialog
.clear();
617 Reference
< XNameContainer
> xLib( getLibrary( _eType
, _rLibName
, TRUE
), UNO_QUERY_THROW
);
618 if ( xLib
->hasByName( _rObjectName
) )
620 _out_rModuleOrDialog
= xLib
->getByName( _rObjectName
);
624 catch( const Exception
& )
626 DBG_UNHANDLED_EXCEPTION();
631 //--------------------------------------------------------------------
632 bool ScriptDocument_Impl::renameModuleOrDialog( LibraryContainerType _eType
, const ::rtl::OUString
& _rLibName
,
633 const ::rtl::OUString
& _rOldName
, const ::rtl::OUString
& _rNewName
, const Reference
< XNameContainer
>& _rxExistingDialogModel
)
635 OSL_ENSURE( isValid(), "ScriptDocument_Impl::renameModuleOrDialog: invalid!" );
641 Reference
< XNameContainer
> xLib( getLibrary( _eType
, _rLibName
, TRUE
), UNO_QUERY_THROW
);
644 Any
aElement( xLib
->getByName( _rOldName
) );
646 // remove element from container
647 xLib
->removeByName( _rOldName
);
649 // if it's a dialog, import and export, to reflect the new name
650 if ( _eType
== E_DIALOGS
)
652 // create dialog model
653 ::comphelper::ComponentContext
aContext( ::comphelper::getProcessServiceFactory() );
654 Reference
< XNameContainer
> xDialogModel
;
655 if ( _rxExistingDialogModel
.is() )
656 xDialogModel
= _rxExistingDialogModel
;
658 if ( !aContext
.createComponent( "com.sun.star.awt.UnoControlDialogModel", xDialogModel
) )
661 // import dialog model
662 Reference
< XInputStreamProvider
> xISP( aElement
, UNO_QUERY_THROW
);
663 if ( !_rxExistingDialogModel
.is() )
665 Reference
< XInputStream
> xInput( xISP
->createInputStream(), UNO_QUERY_THROW
);
666 ::xmlscript::importDialogModel( xInput
, xDialogModel
, aContext
.getUNOContext(), getDocument() );
669 // set new name as property
670 Reference
< XPropertySet
> xDlgPSet( xDialogModel
, UNO_QUERY_THROW
);
671 xDlgPSet
->setPropertyValue( DLGED_PROP_NAME
, makeAny( _rNewName
) );
673 // export dialog model
674 xISP
= ::xmlscript::exportDialogModel( xDialogModel
, aContext
.getUNOContext(), getDocument() );
678 // insert element by new name in container
679 if ( _eType
== E_SCRIPTS
)
681 ModuleInfo sModuleInfo
;
682 if ( aElement
>>= sModuleInfo
)
684 sModuleInfo
.ModuleName
= _rNewName
;
685 aElement
<<= sModuleInfo
;
688 xLib
->insertByName( _rNewName
, aElement
);
691 catch( const Exception
& )
693 DBG_UNHANDLED_EXCEPTION();
698 //--------------------------------------------------------------------
699 bool ScriptDocument_Impl::createModule( const ::rtl::OUString
& _rLibName
, const ::rtl::OUString
& _rModName
, bool _bCreateMain
, ::rtl::OUString
& _out_rNewModuleCode
) const
701 _out_rNewModuleCode
= ::rtl::OUString();
704 Reference
< XNameContainer
> xLib( getLibrary( E_SCRIPTS
, _rLibName
, TRUE
) );
705 if ( !xLib
.is() || xLib
->hasByName( _rModName
) )
709 _out_rNewModuleCode
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "REM ***** BASIC *****\n\n" ) );
711 _out_rNewModuleCode
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Sub Main\n\nEnd Sub\n" ) );
713 // insert module into library
714 xLib
->insertByName( _rModName
, makeAny( _out_rNewModuleCode
) );
716 catch( const Exception
& )
718 DBG_UNHANDLED_EXCEPTION();
725 //--------------------------------------------------------------------
726 bool ScriptDocument_Impl::insertModuleOrDialog( LibraryContainerType _eType
, const ::rtl::OUString
& _rLibName
, const ::rtl::OUString
& _rObjectName
, const Any
& _rElement
) const
730 Reference
< XNameContainer
> xLib( getOrCreateLibrary( _eType
, _rLibName
), UNO_QUERY_THROW
);
731 if ( xLib
->hasByName( _rObjectName
) )
734 xLib
->insertByName( _rObjectName
, _rElement
);
737 catch( const Exception
& )
739 DBG_UNHANDLED_EXCEPTION();
744 //--------------------------------------------------------------------
745 bool ScriptDocument_Impl::updateModule( const ::rtl::OUString
& _rLibName
, const ::rtl::OUString
& _rModName
, const ::rtl::OUString
& _rModuleCode
) const
749 Reference
< XNameContainer
> xLib( getOrCreateLibrary( E_SCRIPTS
, _rLibName
), UNO_QUERY_THROW
);
750 if ( !xLib
->hasByName( _rModName
) )
754 if ( xLib
->getByName( _rModName
) >>= mInfo
)
756 mInfo
.ModuleSource
= _rModuleCode
;
760 aMod
<<= _rModuleCode
;
761 xLib
->replaceByName( _rModName
, aMod
);
764 catch( const Exception
& )
766 DBG_UNHANDLED_EXCEPTION();
771 //--------------------------------------------------------------------
772 bool ScriptDocument_Impl::createDialog( const ::rtl::OUString
& _rLibName
, const ::rtl::OUString
& _rDialogName
, Reference
< XInputStreamProvider
>& _out_rDialogProvider
) const
776 Reference
< XNameContainer
> xLib( getLibrary( E_DIALOGS
, _rLibName
, TRUE
), UNO_QUERY_THROW
);
779 _out_rDialogProvider
.clear();
780 if ( xLib
->hasByName( _rDialogName
) )
783 // create new dialog model
784 ::comphelper::ComponentContext
aContext( ::comphelper::getProcessServiceFactory() );
785 Reference
< XNameContainer
> xDialogModel
;
786 if ( !aContext
.createComponent( "com.sun.star.awt.UnoControlDialogModel", xDialogModel
) )
790 Reference
< XPropertySet
> xDlgPSet( xDialogModel
, UNO_QUERY_THROW
);
791 xDlgPSet
->setPropertyValue( DLGED_PROP_NAME
, makeAny( _rDialogName
) );
793 // export dialog model
794 _out_rDialogProvider
= ::xmlscript::exportDialogModel( xDialogModel
, aContext
.getUNOContext(), getDocument() );
796 // insert dialog into library
797 xLib
->insertByName( _rDialogName
, makeAny( _out_rDialogProvider
) );
799 catch( const Exception
& )
801 DBG_UNHANDLED_EXCEPTION();
804 return _out_rDialogProvider
.is();
807 //--------------------------------------------------------------------
808 void ScriptDocument_Impl::setDocumentModified() const
810 OSL_ENSURE( isValid() && isDocument(), "ScriptDocument_Impl::setDocumentModified: only to be called for real documents!" );
811 if ( isValid() && isDocument() )
815 m_xDocModify
->setModified( sal_True
);
817 catch( const Exception
& )
819 DBG_UNHANDLED_EXCEPTION();
824 //--------------------------------------------------------------------
825 bool ScriptDocument_Impl::isDocumentModified() const
827 OSL_ENSURE( isValid() && isDocument(), "ScriptDocument_Impl::isDocumentModified: only to be called for real documents!" );
828 bool bIsModified
= false;
829 if ( isValid() && isDocument() )
833 bIsModified
= m_xDocModify
->isModified();
835 catch( const Exception
& )
837 DBG_UNHANDLED_EXCEPTION();
843 //--------------------------------------------------------------------
844 bool ScriptDocument_Impl::saveDocument( const Reference
< XStatusIndicator
>& _rxStatusIndicator
) const
846 Reference
< XFrame
> xFrame
;
847 if ( !getCurrentFrame( xFrame
) )
850 Sequence
< PropertyValue
> aArgs
;
851 if ( _rxStatusIndicator
.is() )
854 aArgs
[0].Name
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "StatusIndicator" ) );
855 aArgs
[0].Value
<<= _rxStatusIndicator
;
861 aURL
.Complete
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:Save" ) );
862 aURL
.Main
= aURL
.Complete
;
863 aURL
.Protocol
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:" ) );
864 aURL
.Path
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Save" ) );
866 Reference
< XDispatchProvider
> xDispProv( xFrame
, UNO_QUERY_THROW
);
867 Reference
< XDispatch
> xDispatch(
868 xDispProv
->queryDispatch( aURL
, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_self" ) ), FrameSearchFlag::AUTO
),
871 xDispatch
->dispatch( aURL
, aArgs
);
873 catch( const Exception
& )
875 DBG_UNHANDLED_EXCEPTION();
882 //--------------------------------------------------------------------
883 ::rtl::OUString
ScriptDocument_Impl::getTitle() const
885 OSL_PRECOND( isValid() && isDocument(), "ScriptDocument_Impl::getTitle: for documents only!" );
887 ::rtl::OUString sTitle
;
888 if ( isValid() && isDocument() )
890 sTitle
= ::comphelper::DocumentInfo::getDocumentTitle( m_xDocument
);
895 //--------------------------------------------------------------------
896 ::rtl::OUString
ScriptDocument_Impl::getURL() const
898 OSL_PRECOND( isValid() && isDocument(), "ScriptDocument_Impl::getURL: for documents only!" );
900 ::rtl::OUString sURL
;
901 if ( isValid() && isDocument() )
905 sURL
= m_xDocument
->getURL();
907 catch( const Exception
& )
909 DBG_UNHANDLED_EXCEPTION();
915 //--------------------------------------------------------------------
916 bool ScriptDocument_Impl::allowMacros() const
918 OSL_ENSURE( isValid() && isDocument(), "ScriptDocument_Impl::allowMacros: for documents only!" );
920 if ( isValid() && isDocument() )
924 bAllow
= m_xScriptAccess
->getAllowMacroExecution();
926 catch( const Exception
& )
928 DBG_UNHANDLED_EXCEPTION();
934 //--------------------------------------------------------------------
935 bool ScriptDocument_Impl::getCurrentFrame( Reference
< XFrame
>& _out_rxFrame
) const
937 _out_rxFrame
.clear();
938 OSL_PRECOND( isValid() && isDocument(), "ScriptDocument_Impl::getCurrentFrame: documents only!" );
939 if ( !isValid() || !isDocument() )
944 Reference
< XModel
> xDocument( m_xDocument
, UNO_SET_THROW
);
945 Reference
< XController
> xController( xDocument
->getCurrentController(), UNO_SET_THROW
);
946 _out_rxFrame
.set( xController
->getFrame(), UNO_SET_THROW
);
948 catch( const Exception
& )
950 DBG_UNHANDLED_EXCEPTION();
953 return _out_rxFrame
.is();
956 //--------------------------------------------------------------------
957 bool ScriptDocument_Impl::isLibraryShared( const ::rtl::OUString
& _rLibName
, LibraryContainerType _eType
)
959 bool bIsShared
= false;
962 Reference
< XLibraryContainer2
> xLibContainer( getLibraryContainer( _eType
), UNO_QUERY_THROW
);
964 if ( !xLibContainer
->hasByName( _rLibName
) || !xLibContainer
->isLibraryLink( _rLibName
) )
966 ::rtl::OUString aFileURL
;
967 Reference
< XMultiServiceFactory
> xMSF( ::comphelper::getProcessServiceFactory() );
968 Reference
< XUriReferenceFactory
> xUriFac
;
972 xMSF
->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.uri.UriReferenceFactory" ) ) ),
976 ::rtl::OUString
aLinkURL( xLibContainer
->getLibraryLinkURL( _rLibName
) );
977 Reference
< XUriReference
> xUriRef( xUriFac
->parse( aLinkURL
), UNO_QUERY_THROW
);
979 ::rtl::OUString aScheme
= xUriRef
->getScheme();
980 if ( aScheme
.equalsIgnoreAsciiCaseAscii( "file" ) )
984 else if ( aScheme
.equalsIgnoreAsciiCaseAscii( "vnd.sun.star.pkg" ) )
986 ::rtl::OUString aAuthority
= xUriRef
->getAuthority();
987 if ( aAuthority
.matchIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "vnd.sun.star.expand:" ) ) )
989 ::rtl::OUString
aDecodedURL( aAuthority
.copy( sizeof ( "vnd.sun.star.expand:" ) - 1 ) );
990 aDecodedURL
= ::rtl::Uri::decode( aDecodedURL
, rtl_UriDecodeWithCharset
, RTL_TEXTENCODING_UTF8
);
991 Reference
< XComponentContext
> xContext
;
992 Reference
< XPropertySet
> xProps( xMSF
, UNO_QUERY_THROW
);
993 xContext
.set( xProps
->getPropertyValue( ::rtl::OUString::createFromAscii( "DefaultContext" ) ), UNO_QUERY_THROW
);
994 Reference
< XMacroExpander
> xMacroExpander(
995 xContext
->getValueByName(
996 ::rtl::OUString::createFromAscii( "/singletons/com.sun.star.util.theMacroExpander" ) ),
998 aFileURL
= xMacroExpander
->expandMacros( aDecodedURL
);
1002 if ( aFileURL
.getLength() )
1004 ::osl::DirectoryItem aFileItem
;
1005 ::osl::FileStatus
aFileStatus( FileStatusMask_FileURL
);
1006 OSL_VERIFY( ::osl::DirectoryItem::get( aFileURL
, aFileItem
) == ::osl::FileBase::E_None
);
1007 OSL_VERIFY( aFileItem
.getFileStatus( aFileStatus
) == ::osl::FileBase::E_None
);
1008 ::rtl::OUString
aCanonicalFileURL( aFileStatus
.getFileURL() );
1010 ::rtl::OUString
aSearchURL1( RTL_CONSTASCII_USTRINGPARAM( "share/basic" ) );
1011 ::rtl::OUString
aSearchURL2( RTL_CONSTASCII_USTRINGPARAM( "share/uno_packages" ) );
1012 if( aCanonicalFileURL
.indexOf( aSearchURL1
) != -1 || aCanonicalFileURL
.indexOf( aSearchURL2
) != -1 )
1016 catch( const Exception
& )
1018 DBG_UNHANDLED_EXCEPTION();
1024 //--------------------------------------------------------------------
1025 void ScriptDocument_Impl::onDocumentCreated( const ScriptDocument
& /*_rDocument*/ )
1027 // not interested in
1030 //--------------------------------------------------------------------
1031 void ScriptDocument_Impl::onDocumentOpened( const ScriptDocument
& /*_rDocument*/ )
1033 // not interested in
1036 //--------------------------------------------------------------------
1037 void ScriptDocument_Impl::onDocumentSave( const ScriptDocument
& /*_rDocument*/ )
1039 // not interested in
1042 //--------------------------------------------------------------------
1043 void ScriptDocument_Impl::onDocumentSaveDone( const ScriptDocument
& /*_rDocument*/ )
1045 // not interested in
1048 //--------------------------------------------------------------------
1049 void ScriptDocument_Impl::onDocumentSaveAs( const ScriptDocument
& /*_rDocument*/ )
1051 // not interested in
1054 //--------------------------------------------------------------------
1055 void ScriptDocument_Impl::onDocumentSaveAsDone( const ScriptDocument
& /*_rDocument*/ )
1057 // not interested in
1060 //--------------------------------------------------------------------
1061 void ScriptDocument_Impl::onDocumentClosed( const ScriptDocument
& _rDocument
)
1063 DBG_TESTSOLARMUTEX();
1064 OSL_PRECOND( isValid(), "ScriptDocument_Impl::onDocumentClosed: should not be listening if I'm not valid!" );
1066 bool bMyDocument
= m_xDocument
== _rDocument
.getDocument();
1067 OSL_PRECOND( bMyDocument
, "ScriptDocument_Impl::onDocumentClosed: didn't want to know *this*!" );
1070 m_bDocumentClosed
= true;
1074 //--------------------------------------------------------------------
1075 void ScriptDocument_Impl::onDocumentTitleChanged( const ScriptDocument
& /*_rDocument*/ )
1077 // not interested in
1080 //--------------------------------------------------------------------
1081 void ScriptDocument_Impl::onDocumentModeChanged( const ScriptDocument
& /*_rDocument*/ )
1083 // not interested in
1086 //====================================================================
1088 //====================================================================
1089 //--------------------------------------------------------------------
1090 ScriptDocument::ScriptDocument()
1091 :m_pImpl( new ScriptDocument_Impl() )
1095 //--------------------------------------------------------------------
1096 ScriptDocument::ScriptDocument( ScriptDocument::SpecialDocument _eType
)
1097 :m_pImpl( new ScriptDocument_Impl( Reference
< XModel
>() ) )
1099 OSL_ENSURE( _eType
== NoDocument
, "ScriptDocument::ScriptDocument: unknown SpecialDocument type!" );
1103 //--------------------------------------------------------------------
1104 ScriptDocument::ScriptDocument( const Reference
< XModel
>& _rxDocument
)
1105 :m_pImpl( new ScriptDocument_Impl( _rxDocument
) )
1107 OSL_ENSURE( _rxDocument
.is(), "ScriptDocument::ScriptDocument: document must not be NULL!" );
1108 // a NULL document results in an uninitialized instance, and for this
1109 // purpose, there is a dedicated constructor
1112 //--------------------------------------------------------------------
1113 ScriptDocument::ScriptDocument( const ScriptDocument
& _rSource
)
1114 :m_pImpl( _rSource
.m_pImpl
)
1118 //--------------------------------------------------------------------
1119 ScriptDocument::~ScriptDocument()
1123 //--------------------------------------------------------------------
1124 const ScriptDocument
& ScriptDocument::getApplicationScriptDocument()
1126 static ScriptDocument s_aApplicationScripts
;
1127 return s_aApplicationScripts
;
1130 //--------------------------------------------------------------------
1131 ScriptDocument
ScriptDocument::getDocumentForBasicManager( const BasicManager
* _pManager
)
1133 if ( _pManager
== SFX_APP()->GetBasicManager() )
1134 return getApplicationScriptDocument();
1136 docs::Documents aDocuments
;
1137 lcl_getAllModels_throw( aDocuments
, false );
1139 for ( docs::Documents::const_iterator doc
= aDocuments
.begin();
1140 doc
!= aDocuments
.end();
1144 const BasicManager
* pDocBasicManager
= ::basic::BasicManagerRepository::getDocumentBasicManager( doc
->xModel
);
1145 if ( ( pDocBasicManager
!= SFX_APP()->GetBasicManager() )
1146 && ( pDocBasicManager
== _pManager
)
1149 return ScriptDocument( doc
->xModel
);
1153 OSL_ENSURE( false, "ScriptDocument::getDocumentForBasicManager: did not find a document for this manager!" );
1154 return ScriptDocument( NoDocument
);
1157 //--------------------------------------------------------------------
1158 ScriptDocument
ScriptDocument::getDocumentWithURLOrCaption( const ::rtl::OUString
& _rUrlOrCaption
)
1160 ScriptDocument
aDocument( getApplicationScriptDocument() );
1161 if ( _rUrlOrCaption
.getLength() == 0 )
1164 docs::Documents aDocuments
;
1165 lcl_getAllModels_throw( aDocuments
, false );
1167 for ( docs::Documents::const_iterator doc
= aDocuments
.begin();
1168 doc
!= aDocuments
.end();
1172 const ScriptDocument aCheck
= ScriptDocument( doc
->xModel
);
1173 if ( _rUrlOrCaption
== aCheck
.getTitle()
1174 || _rUrlOrCaption
== aCheck
.getURL()
1185 //--------------------------------------------------------------------
1188 struct DocumentTitleLess
: public ::std::binary_function
< ScriptDocument
, ScriptDocument
, bool >
1190 DocumentTitleLess( const CollatorWrapper
& _rCollator
)
1191 :m_aCollator( _rCollator
)
1195 bool operator()( const ScriptDocument
& _lhs
, const ScriptDocument
& _rhs
) const
1197 return m_aCollator
.compareString( _lhs
.getTitle(), _rhs
.getTitle() ) < 0;
1200 const CollatorWrapper m_aCollator
;
1204 //--------------------------------------------------------------------
1205 ScriptDocuments
ScriptDocument::getAllScriptDocuments( ScriptDocument::ScriptDocumentList _eListType
)
1207 ScriptDocuments aScriptDocs
;
1209 // include application?
1210 if ( _eListType
== AllWithApplication
)
1211 aScriptDocs
.push_back( getApplicationScriptDocument() );
1216 docs::Documents aDocuments
;
1217 lcl_getAllModels_throw( aDocuments
, true /* exclude invisible */ );
1219 for ( docs::Documents::const_iterator doc
= aDocuments
.begin();
1220 doc
!= aDocuments
.end();
1224 // exclude documents without script/library containers
1225 ScriptDocument
aDoc( doc
->xModel
);
1226 if ( !aDoc
.isValid() )
1229 aScriptDocs
.push_back( aDoc
);
1232 catch( const Exception
& )
1234 DBG_UNHANDLED_EXCEPTION();
1237 // sort document list by doc title?
1238 if ( _eListType
== DocumentsSorted
)
1240 CollatorWrapper
aCollator( ::comphelper::getProcessServiceFactory() );
1241 aCollator
.loadDefaultCollator( SvtSysLocale().GetLocaleData().getLocale(), 0 );
1242 ::std::sort( aScriptDocs
.begin(), aScriptDocs
.end(), DocumentTitleLess( aCollator
) );
1248 //--------------------------------------------------------------------
1249 bool ScriptDocument::operator==( const ScriptDocument
& _rhs
) const
1251 return m_pImpl
->getDocumentRef() == _rhs
.m_pImpl
->getDocumentRef();
1254 //--------------------------------------------------------------------
1255 sal_Int32
ScriptDocument::hashCode() const
1257 return sal::static_int_cast
<sal_Int32
>(reinterpret_cast< sal_IntPtr
>( m_pImpl
->getDocumentRef().get() ));
1260 //--------------------------------------------------------------------
1261 bool ScriptDocument::isValid() const
1263 return m_pImpl
->isValid();
1266 //--------------------------------------------------------------------
1267 bool ScriptDocument::isAlive() const
1269 return m_pImpl
->isAlive();
1272 //--------------------------------------------------------------------
1273 Reference
< XLibraryContainer
> ScriptDocument::getLibraryContainer( LibraryContainerType _eType
) const
1275 return m_pImpl
->getLibraryContainer( _eType
);
1278 //--------------------------------------------------------------------
1279 Reference
< XNameContainer
> ScriptDocument::getLibrary( LibraryContainerType _eType
, const ::rtl::OUString
& _rLibName
, bool _bLoadLibrary
) const
1280 SAL_THROW((NoSuchElementException
))
1282 return m_pImpl
->getLibrary( _eType
, _rLibName
, _bLoadLibrary
);
1285 //--------------------------------------------------------------------
1286 bool ScriptDocument::hasLibrary( LibraryContainerType _eType
, const ::rtl::OUString
& _rLibName
) const
1288 return m_pImpl
->hasLibrary( _eType
, _rLibName
);
1291 //--------------------------------------------------------------------
1292 Reference
< XNameContainer
> ScriptDocument::getOrCreateLibrary( LibraryContainerType _eType
, const ::rtl::OUString
& _rLibName
) const
1294 return m_pImpl
->getOrCreateLibrary( _eType
, _rLibName
);
1297 //--------------------------------------------------------------------
1298 void ScriptDocument::loadLibraryIfExists( LibraryContainerType _eType
, const ::rtl::OUString
& _rLibrary
)
1300 m_pImpl
->loadLibraryIfExists( _eType
, _rLibrary
);
1303 //--------------------------------------------------------------------
1304 Sequence
< ::rtl::OUString
> ScriptDocument::getObjectNames( LibraryContainerType _eType
, const ::rtl::OUString
& _rLibName
) const
1306 Sequence
< ::rtl::OUString
> aModuleNames
;
1310 if ( hasLibrary( _eType
, _rLibName
) )
1312 Reference
< XNameContainer
> xLib( getLibrary( _eType
, _rLibName
, false ) );
1314 aModuleNames
= xLib
->getElementNames();
1317 catch( const Exception
& )
1319 DBG_UNHANDLED_EXCEPTION();
1323 ::std::sort( aModuleNames
.getArray() , aModuleNames
.getArray() + aModuleNames
.getLength() , StringCompareLessThan
);
1325 return aModuleNames
;
1328 //--------------------------------------------------------------------
1329 ::rtl::OUString
ScriptDocument::createObjectName( LibraryContainerType _eType
, const ::rtl::OUString
& _rLibName
) const
1331 ::rtl::OUString aObjectName
;
1333 ::rtl::OUString aBaseName
= _eType
== E_SCRIPTS
1334 ? ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Module" ) )
1335 : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Dialog" ) );
1337 Sequence
< ::rtl::OUString
> aUsedNames( getObjectNames( _eType
, _rLibName
) );
1338 ::std::set
< ::rtl::OUString
> aUsedNamesCheck
;
1339 ::std::copy( aUsedNames
.getConstArray(), aUsedNames
.getConstArray() + aUsedNames
.getLength(),
1340 ::std::insert_iterator
< ::std::set
< ::rtl::OUString
> >( aUsedNamesCheck
, aUsedNamesCheck
.begin() ) );
1342 bool bValid
= false;
1346 aObjectName
= aBaseName
;
1347 aObjectName
+= String::CreateFromInt32( i
);
1349 if ( aUsedNamesCheck
.find( aObjectName
) == aUsedNamesCheck
.end() )
1358 //--------------------------------------------------------------------
1359 Sequence
< ::rtl::OUString
> ScriptDocument::getLibraryNames() const
1361 return BasicIDE::GetMergedLibraryNames( getLibraryContainer( E_SCRIPTS
), getLibraryContainer( E_DIALOGS
) );
1364 //--------------------------------------------------------------------
1365 bool ScriptDocument::isReadOnly() const
1367 return m_pImpl
->isReadOnly();
1370 //--------------------------------------------------------------------
1371 bool ScriptDocument::isApplication() const
1373 return m_pImpl
->isApplication();
1376 //--------------------------------------------------------------------
1377 BasicManager
* ScriptDocument::getBasicManager() const
1379 return m_pImpl
->getBasicManager();
1382 //--------------------------------------------------------------------
1383 Reference
< XModel
> ScriptDocument::getDocument() const
1385 return m_pImpl
->getDocument();
1388 //--------------------------------------------------------------------
1389 Reference
< XModel
> ScriptDocument::getDocumentOrNull() const
1392 return m_pImpl
->getDocument();
1396 //--------------------------------------------------------------------
1397 bool ScriptDocument::removeModule( const ::rtl::OUString
& _rLibName
, const ::rtl::OUString
& _rModuleName
) const
1399 return m_pImpl
->removeModuleOrDialog( E_SCRIPTS
, _rLibName
, _rModuleName
);
1402 //--------------------------------------------------------------------
1403 bool ScriptDocument::hasModule( const ::rtl::OUString
& _rLibName
, const ::rtl::OUString
& _rModuleName
) const
1405 return m_pImpl
->hasModuleOrDialog( E_SCRIPTS
, _rLibName
, _rModuleName
);
1408 //--------------------------------------------------------------------
1409 bool ScriptDocument::getModule( const ::rtl::OUString
& _rLibName
, const ::rtl::OUString
& _rModName
, ::rtl::OUString
& _out_rModuleSource
) const
1412 if ( !m_pImpl
->getModuleOrDialog( E_SCRIPTS
, _rLibName
, _rModName
, aCode
) )
1414 ModuleInfo sModuleInfo
;
1415 if ( aCode
>>= sModuleInfo
)
1417 _out_rModuleSource
= sModuleInfo
.ModuleSource
;
1421 OSL_VERIFY( aCode
>>= _out_rModuleSource
);
1426 //--------------------------------------------------------------------
1427 bool ScriptDocument::renameModule( const ::rtl::OUString
& _rLibName
, const ::rtl::OUString
& _rOldName
, const ::rtl::OUString
& _rNewName
) const
1429 return m_pImpl
->renameModuleOrDialog( E_SCRIPTS
, _rLibName
, _rOldName
, _rNewName
, NULL
);
1432 //--------------------------------------------------------------------
1433 bool ScriptDocument::createModule( const ::rtl::OUString
& _rLibName
, const ::rtl::OUString
& _rModName
, bool _bCreateMain
, ::rtl::OUString
& _out_rNewModuleCode
) const
1435 if ( !m_pImpl
->createModule( _rLibName
, _rModName
, _bCreateMain
, _out_rNewModuleCode
) )
1438 // doc shell modified
1439 BasicIDE::MarkDocumentModified( *const_cast< ScriptDocument
* >( this ) ); // here?
1443 //--------------------------------------------------------------------
1444 bool ScriptDocument::insertModule( const ::rtl::OUString
& _rLibName
, const ::rtl::OUString
& _rModName
, const ::rtl::OUString
& _rModuleCode
) const
1446 return m_pImpl
->insertModuleOrDialog( E_SCRIPTS
, _rLibName
, _rModName
, makeAny( _rModuleCode
) );
1449 //--------------------------------------------------------------------
1450 bool ScriptDocument::updateModule( const ::rtl::OUString
& _rLibName
, const ::rtl::OUString
& _rModName
, const ::rtl::OUString
& _rModuleCode
) const
1452 return m_pImpl
->updateModule( _rLibName
, _rModName
, _rModuleCode
);
1455 //--------------------------------------------------------------------
1456 bool ScriptDocument::removeDialog( const ::rtl::OUString
& _rLibName
, const ::rtl::OUString
& _rDialogName
) const
1458 return m_pImpl
->removeModuleOrDialog( E_DIALOGS
, _rLibName
, _rDialogName
);
1461 //--------------------------------------------------------------------
1462 bool ScriptDocument::hasDialog( const ::rtl::OUString
& _rLibName
, const ::rtl::OUString
& _rDialogName
) const
1464 return m_pImpl
->hasModuleOrDialog( E_DIALOGS
, _rLibName
, _rDialogName
);
1467 //--------------------------------------------------------------------
1468 bool ScriptDocument::getDialog( const ::rtl::OUString
& _rLibName
, const ::rtl::OUString
& _rDialogName
, Reference
< XInputStreamProvider
>& _out_rDialogProvider
) const
1471 if ( !m_pImpl
->getModuleOrDialog( E_DIALOGS
, _rLibName
, _rDialogName
, aCode
) )
1473 OSL_VERIFY( aCode
>>= _out_rDialogProvider
);
1474 return _out_rDialogProvider
.is();
1477 //--------------------------------------------------------------------
1478 bool ScriptDocument::renameDialog( const ::rtl::OUString
& _rLibName
, const ::rtl::OUString
& _rOldName
, const ::rtl::OUString
& _rNewName
, const Reference
< XNameContainer
>& _rxExistingDialogModel
) const
1480 return m_pImpl
->renameModuleOrDialog( E_DIALOGS
, _rLibName
, _rOldName
, _rNewName
, _rxExistingDialogModel
);
1483 //--------------------------------------------------------------------
1484 bool ScriptDocument::createDialog( const ::rtl::OUString
& _rLibName
, const ::rtl::OUString
& _rDialogName
, Reference
< XInputStreamProvider
>& _out_rDialogProvider
) const
1486 if ( !m_pImpl
->createDialog( _rLibName
, _rDialogName
, _out_rDialogProvider
) )
1489 BasicIDE::MarkDocumentModified( *const_cast< ScriptDocument
* >( this ) ); // here?
1493 //--------------------------------------------------------------------
1494 bool ScriptDocument::insertDialog( const ::rtl::OUString
& _rLibName
, const ::rtl::OUString
& _rDialogName
, const Reference
< XInputStreamProvider
>& _rxDialogProvider
) const
1496 return m_pImpl
->insertModuleOrDialog( E_DIALOGS
, _rLibName
, _rDialogName
, makeAny( _rxDialogProvider
) );
1499 //--------------------------------------------------------------------
1500 void ScriptDocument::setDocumentModified() const
1502 m_pImpl
->setDocumentModified();
1505 //--------------------------------------------------------------------
1506 bool ScriptDocument::isDocumentModified() const
1508 return m_pImpl
->isDocumentModified();
1511 //--------------------------------------------------------------------
1512 bool ScriptDocument::saveDocument( const Reference
< XStatusIndicator
>& _rxStatusIndicator
) const
1514 return m_pImpl
->saveDocument( _rxStatusIndicator
);
1517 //--------------------------------------------------------------------
1518 LibraryLocation
ScriptDocument::getLibraryLocation( const ::rtl::OUString
& _rLibName
) const
1520 LibraryLocation eLocation
= LIBRARY_LOCATION_UNKNOWN
;
1521 if ( _rLibName
.getLength() )
1525 eLocation
= LIBRARY_LOCATION_DOCUMENT
;
1529 if ( ( hasLibrary( E_SCRIPTS
, _rLibName
) && !m_pImpl
->isLibraryShared( _rLibName
, E_SCRIPTS
) )
1530 || ( hasLibrary( E_DIALOGS
, _rLibName
) && !m_pImpl
->isLibraryShared( _rLibName
, E_DIALOGS
) )
1533 eLocation
= LIBRARY_LOCATION_USER
;
1537 eLocation
= LIBRARY_LOCATION_SHARE
;
1545 //--------------------------------------------------------------------
1546 ::rtl::OUString
ScriptDocument::getTitle( LibraryLocation _eLocation
, LibraryType _eType
) const
1548 ::rtl::OUString aTitle
;
1550 switch ( _eLocation
)
1552 case LIBRARY_LOCATION_USER
:
1556 case LIBRARY_TYPE_MODULE
: aTitle
= String( IDEResId( RID_STR_USERMACROS
) ); break;
1557 case LIBRARY_TYPE_DIALOG
: aTitle
= String( IDEResId( RID_STR_USERDIALOGS
) ); break;
1558 case LIBRARY_TYPE_ALL
: aTitle
= String( IDEResId( RID_STR_USERMACROSDIALOGS
) ); break;
1563 case LIBRARY_LOCATION_SHARE
:
1567 case LIBRARY_TYPE_MODULE
: aTitle
= String( IDEResId( RID_STR_SHAREMACROS
) ); break;
1568 case LIBRARY_TYPE_DIALOG
: aTitle
= String( IDEResId( RID_STR_SHAREDIALOGS
) ); break;
1569 case LIBRARY_TYPE_ALL
: aTitle
= String( IDEResId( RID_STR_SHAREMACROSDIALOGS
) ); break;
1575 case LIBRARY_LOCATION_DOCUMENT
:
1576 aTitle
= getTitle();
1586 //--------------------------------------------------------------------
1587 ::rtl::OUString
ScriptDocument::getTitle() const
1589 return m_pImpl
->getTitle();
1592 //--------------------------------------------------------------------
1593 ::rtl::OUString
ScriptDocument::getURL() const
1595 return m_pImpl
->getURL();
1598 //--------------------------------------------------------------------
1599 bool ScriptDocument::isActive() const
1601 bool bIsActive( false );
1604 Reference
< XFrame
> xFrame
;
1605 if ( m_pImpl
->getCurrentFrame( xFrame
) )
1606 bIsActive
= xFrame
->isActive();
1608 catch( const Exception
& )
1610 DBG_UNHANDLED_EXCEPTION();
1615 //--------------------------------------------------------------------
1616 bool ScriptDocument::allowMacros() const
1618 return m_pImpl
->allowMacros();
1621 //........................................................................
1622 } // namespace basctl
1623 //........................................................................