Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / basctl / source / basicide / scriptdocument.cxx
blob559f4f82a3012b8d9c2c06538ae36a44bac5e046
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <memory>
21 #include <scriptdocument.hxx>
22 #include <basobj.hxx>
23 #include <strings.hrc>
24 #include <iderid.hxx>
25 #include <dlgeddef.hxx>
26 #include <doceventnotifier.hxx>
27 #include "documentenumeration.hxx"
29 #include <com/sun/star/uri/UriReferenceFactory.hpp>
30 #include <com/sun/star/util/theMacroExpander.hpp>
31 #include <com/sun/star/document/MacroExecMode.hpp>
32 #include <com/sun/star/frame/XStorable.hpp>
33 #include <com/sun/star/frame/FrameSearchFlag.hpp>
34 #include <com/sun/star/awt/XWindow2.hpp>
35 #include <com/sun/star/document/XEmbeddedScripts.hpp>
36 #include <com/sun/star/script/vba/XVBACompatibility.hpp>
37 #include <com/sun/star/script/vba/XVBAModuleInfo.hpp>
38 #include <com/sun/star/script/ModuleInfo.hpp>
39 #include <com/sun/star/script/ModuleType.hpp>
41 #include <sfx2/objsh.hxx>
42 #include <sfx2/bindings.hxx>
43 #include <sfx2/docfile.hxx>
46 #include <basic/basicmanagerrepository.hxx>
48 #include <xmlscript/xmldlg_imexp.hxx>
50 #include <unotools/syslocale.hxx>
52 #include <unotools/collatorwrapper.hxx>
54 #include <tools/diagnose_ex.h>
56 #include <comphelper/documentinfo.hxx>
57 #include <comphelper/processfactory.hxx>
58 #include <comphelper/propertysequence.hxx>
60 #include <osl/file.hxx>
61 #include <rtl/uri.hxx>
62 #include <set>
65 namespace basctl
67 using ::com::sun::star::uno::Sequence;
68 using ::com::sun::star::uno::Reference;
69 using ::com::sun::star::frame::XModel;
70 using ::com::sun::star::beans::XPropertySet;
71 using ::com::sun::star::script::XLibraryContainer;
72 using ::com::sun::star::uno::UNO_QUERY_THROW;
73 using ::com::sun::star::uno::UNO_SET_THROW;
74 using ::com::sun::star::uno::Exception;
75 using ::com::sun::star::container::XNameContainer;
76 using ::com::sun::star::container::NoSuchElementException;
77 using ::com::sun::star::uno::UNO_QUERY;
78 using ::com::sun::star::task::XStatusIndicator;
79 using ::com::sun::star::uno::Any;
80 using ::com::sun::star::script::XLibraryContainer2;
81 using ::com::sun::star::uri::UriReferenceFactory;
82 using ::com::sun::star::uri::XUriReferenceFactory;
83 using ::com::sun::star::uri::XUriReference;
84 using ::com::sun::star::uno::XComponentContext;
85 using ::com::sun::star::util::XMacroExpander;
86 using ::com::sun::star::util::theMacroExpander;
87 using ::com::sun::star::io::XInputStreamProvider;
88 using ::com::sun::star::uno::Any;
89 using ::com::sun::star::io::XInputStream;
90 using ::com::sun::star::frame::XStorable;
91 using ::com::sun::star::util::XModifiable;
92 using ::com::sun::star::frame::XController;
93 using ::com::sun::star::frame::XFrame;
94 using ::com::sun::star::util::URL;
95 using ::com::sun::star::frame::XDispatchProvider;
96 using ::com::sun::star::frame::XDispatch;
97 using ::com::sun::star::beans::PropertyValue;
98 using ::com::sun::star::awt::XWindow2;
99 using ::com::sun::star::document::XEmbeddedScripts;
100 using ::com::sun::star::script::ModuleInfo;
101 using ::com::sun::star::script::vba::XVBACompatibility;
102 using ::com::sun::star::script::vba::XVBAModuleInfo;
104 namespace FrameSearchFlag = ::com::sun::star::frame::FrameSearchFlag;
107 namespace
109 bool StringCompareLessThan( const OUString& lhs, const OUString& rhs )
111 return lhs.compareToIgnoreAsciiCase( rhs ) < 0;
114 class FilterDocuments : public docs::IDocumentDescriptorFilter
116 public:
117 explicit FilterDocuments(bool _bFilterInvisible)
118 : m_bFilterInvisible(_bFilterInvisible)
122 virtual ~FilterDocuments() {}
124 virtual bool includeDocument( const docs::DocumentDescriptor& _rDocument ) const override;
126 private:
127 static bool impl_isDocumentVisible_nothrow( const docs::DocumentDescriptor& _rDocument );
129 private:
130 bool m_bFilterInvisible;
133 bool FilterDocuments::impl_isDocumentVisible_nothrow( const docs::DocumentDescriptor& _rDocument )
137 for (auto const& controller : _rDocument.aControllers)
139 Reference< XFrame > xFrame( controller->getFrame(), UNO_SET_THROW );
140 Reference< XWindow2 > xContainer( xFrame->getContainerWindow(), UNO_QUERY_THROW );
141 if ( xContainer->isVisible() )
142 return true;
145 catch( const Exception& )
147 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
149 return false;
152 bool FilterDocuments::includeDocument( const docs::DocumentDescriptor& _rDocument ) const
154 Reference< XEmbeddedScripts > xScripts( _rDocument.xModel, UNO_QUERY );
155 if ( !xScripts.is() )
156 return false;
157 return !m_bFilterInvisible || impl_isDocumentVisible_nothrow( _rDocument );
160 void lcl_getAllModels_throw( docs::Documents& _out_rModels, bool _bVisibleOnly )
162 _out_rModels.clear();
164 FilterDocuments aFilter( _bVisibleOnly );
165 docs::DocumentEnumeration aEnum(
166 comphelper::getProcessComponentContext(), &aFilter );
168 aEnum.getDocuments( _out_rModels );
172 class ScriptDocument::Impl : public DocumentEventListener
174 private:
175 bool m_bIsApplication;
176 bool m_bValid;
177 bool m_bDocumentClosed;
178 Reference< XModel > m_xDocument;
179 Reference< XModifiable > m_xDocModify;
180 Reference< XEmbeddedScripts > m_xScriptAccess;
181 std::unique_ptr< DocumentEventNotifier > m_pDocListener;
183 public:
184 Impl ();
185 explicit Impl(Reference<XModel> const& rxDocument);
186 virtual ~Impl() override;
188 /** determines whether the instance refers to a valid "document" with script and
189 dialog libraries
191 bool isValid() const { return m_bValid; }
192 /** determines whether the instance refers to a non-closed document
194 bool isAlive() const { return m_bValid && ( m_bIsApplication || !m_bDocumentClosed ); }
195 /// determines whether the "document" refers to the application in real
196 bool isApplication() const { return m_bValid && m_bIsApplication; }
197 /// determines whether the document refers to a real document (instead of the application)
198 bool isDocument() const { return m_bValid && !m_bIsApplication; }
200 /** invalidates the instance
202 void invalidate();
204 const Reference< XModel >&
205 getDocumentRef() const { return m_xDocument; }
207 /// returns a library container belonging to the document
208 Reference< XLibraryContainer >
209 getLibraryContainer( LibraryContainerType _eType ) const;
211 /// determines whether a given library is part of the shared installation
212 bool isLibraryShared( const OUString& _rLibName, LibraryContainerType _eType );
214 /** returns the current frame of the document
216 To be called for documents only, not for the application.
218 If <FALSE/> is returned, an assertion will be raised in non-product builds.
220 bool getCurrentFrame( Reference< XFrame >& _out_rxFrame ) const;
222 // versions with the same signature/semantics as in ScriptDocument itself
223 bool isReadOnly() const;
224 bool isInVBAMode() const;
225 BasicManager*
226 getBasicManager() const;
227 Reference< XModel >
228 getDocument() const;
229 void setDocumentModified() const;
230 bool isDocumentModified() const;
231 void saveDocument( const Reference< XStatusIndicator >& _rxStatusIndicator ) const;
233 OUString getTitle() const;
234 OUString getURL() const;
236 bool allowMacros() const;
238 Reference< XNameContainer >
239 getLibrary( LibraryContainerType _eType, const OUString& _rLibName, bool _bLoadLibrary ) const;
240 bool hasLibrary( LibraryContainerType _eType, const OUString& _rLibName ) const;
241 Reference< XNameContainer >
242 getOrCreateLibrary( LibraryContainerType _eType, const OUString& _rLibName ) const;
244 void loadLibraryIfExists( LibraryContainerType _eType, const OUString& _rLibrary );
246 bool removeModuleOrDialog( LibraryContainerType _eType, const OUString& _rLibName, const OUString& _rModuleName );
247 bool hasModuleOrDialog( LibraryContainerType _eType, const OUString& _rLibName, const OUString& _rModName ) const;
248 bool getModuleOrDialog( LibraryContainerType _eType, const OUString& _rLibName, const OUString& _rObjectName, Any& _out_rModuleOrDialog );
249 bool renameModuleOrDialog( LibraryContainerType _eType, const OUString& _rLibName, const OUString& _rOldName, const OUString& _rNewName, const Reference< XNameContainer >& _rxExistingDialogModel );
250 bool createModule( const OUString& _rLibName, const OUString& _rModName, bool _bCreateMain, OUString& _out_rNewModuleCode ) const;
251 bool insertModuleOrDialog( LibraryContainerType _eType, const OUString& _rObjectName, const OUString& _rModName, const Any& _rElement ) const;
252 bool updateModule( const OUString& _rLibName, const OUString& _rModName, const OUString& _rModuleCode ) const;
253 bool createDialog( const OUString& _rLibName, const OUString& _rDialogName, Reference< XInputStreamProvider >& _out_rDialogProvider ) const;
255 protected:
256 // DocumentEventListener
257 virtual void onDocumentCreated( const ScriptDocument& _rDocument ) override;
258 virtual void onDocumentOpened( const ScriptDocument& _rDocument ) override;
259 virtual void onDocumentSave( const ScriptDocument& _rDocument ) override;
260 virtual void onDocumentSaveDone( const ScriptDocument& _rDocument ) override;
261 virtual void onDocumentSaveAs( const ScriptDocument& _rDocument ) override;
262 virtual void onDocumentSaveAsDone( const ScriptDocument& _rDocument ) override;
263 virtual void onDocumentClosed( const ScriptDocument& _rDocument ) override;
264 virtual void onDocumentTitleChanged( const ScriptDocument& _rDocument ) override;
265 virtual void onDocumentModeChanged( const ScriptDocument& _rDocument ) override;
267 private:
268 bool impl_initDocument_nothrow( const Reference< XModel >& _rxModel );
272 ScriptDocument::Impl::Impl()
273 :m_bIsApplication( true )
274 ,m_bValid( true )
275 ,m_bDocumentClosed( false )
279 ScriptDocument::Impl::Impl( const Reference< XModel >& _rxDocument )
280 :m_bIsApplication( false )
281 ,m_bValid( false )
282 ,m_bDocumentClosed( false )
284 if ( _rxDocument.is() )
285 impl_initDocument_nothrow( _rxDocument );
288 ScriptDocument::Impl::~Impl()
290 invalidate();
293 void ScriptDocument::Impl::invalidate()
295 m_bIsApplication = false;
296 m_bValid = false;
297 m_bDocumentClosed = false;
299 m_xDocument.clear();
300 m_xDocModify.clear();
301 m_xScriptAccess.clear();
303 if ( m_pDocListener.get() )
304 m_pDocListener->dispose();
307 bool ScriptDocument::Impl::impl_initDocument_nothrow( const Reference< XModel >& _rxModel )
311 m_xDocument.set ( _rxModel, UNO_SET_THROW );
312 m_xDocModify.set ( _rxModel, UNO_QUERY_THROW );
313 m_xScriptAccess.set ( _rxModel, UNO_QUERY );
315 m_bValid = m_xScriptAccess.is();
317 if ( m_bValid )
318 m_pDocListener.reset( new DocumentEventNotifier( *this, _rxModel ) );
320 catch( const Exception& )
322 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
323 m_bValid = false;
326 if ( !m_bValid )
328 invalidate();
331 return m_bValid;
334 Reference< XLibraryContainer > ScriptDocument::Impl::getLibraryContainer( LibraryContainerType _eType ) const
336 OSL_ENSURE( isValid(), "ScriptDocument::Impl::getLibraryContainer: invalid!" );
338 Reference< XLibraryContainer > xContainer;
339 if ( !isValid() )
340 return xContainer;
344 if ( isApplication() )
345 xContainer.set( _eType == E_SCRIPTS ? SfxGetpApp()->GetBasicContainer() : SfxGetpApp()->GetDialogContainer(), UNO_QUERY_THROW );
346 else
348 xContainer.set(
349 _eType == E_SCRIPTS ? m_xScriptAccess->getBasicLibraries() : m_xScriptAccess->getDialogLibraries(),
350 UNO_QUERY_THROW );
353 catch( const Exception& )
355 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
357 return xContainer;
360 bool ScriptDocument::Impl::isReadOnly() const
362 OSL_ENSURE( isValid(), "ScriptDocument::Impl::isReadOnly: invalid state!" );
363 OSL_ENSURE( !isApplication(), "ScriptDocument::Impl::isReadOnly: not allowed to be called for the application!" );
365 bool bIsReadOnly = true;
366 if ( isValid() && !isApplication() )
370 // note that XStorable is required by the OfficeDocument service
371 Reference< XStorable > xDocStorable( m_xDocument, UNO_QUERY_THROW );
372 bIsReadOnly = xDocStorable->isReadonly();
374 catch( const Exception& )
376 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
379 return bIsReadOnly;
382 bool ScriptDocument::Impl::isInVBAMode() const
384 bool bResult = false;
385 if ( !isApplication() )
387 Reference< XVBACompatibility > xVBACompat( getLibraryContainer( E_SCRIPTS ), UNO_QUERY );
388 if ( xVBACompat.is() )
389 bResult = xVBACompat->getVBACompatibilityMode();
391 return bResult;
394 BasicManager* ScriptDocument::Impl::getBasicManager() const
398 OSL_ENSURE( isValid(), "ScriptDocument::Impl::getBasicManager: invalid state!" );
399 if ( !isValid() )
400 return nullptr;
402 if ( isApplication() )
403 return SfxApplication::GetBasicManager();
405 return ::basic::BasicManagerRepository::getDocumentBasicManager( m_xDocument );
407 catch (const css::ucb::ContentCreationException& e)
409 SAL_WARN( "basctl.basicide", "ScriptDocument::getBasicManager: Caught exception: " << e );
411 return nullptr;
414 Reference< XModel > ScriptDocument::Impl::getDocument() const
416 OSL_ENSURE( isValid(), "ScriptDocument::Impl::getDocument: invalid state!" );
417 OSL_ENSURE( isDocument(), "ScriptDocument::Impl::getDocument: for documents only!" );
418 if ( !isValid() || !isDocument() )
419 return nullptr;
421 return m_xDocument;
425 Reference< XNameContainer > ScriptDocument::Impl::getLibrary( LibraryContainerType _eType, const OUString& _rLibName, bool _bLoadLibrary ) const
427 OSL_ENSURE( isValid(), "ScriptDocument::Impl::getLibrary: invalid state!" );
429 Reference< XNameContainer > xContainer;
432 Reference< XLibraryContainer > xLibContainer = getLibraryContainer( _eType );
433 if ( isValid() )
435 if ( xLibContainer.is() )
436 xContainer.set( xLibContainer->getByName( _rLibName ), UNO_QUERY_THROW );
439 if ( !xContainer.is() )
440 throw NoSuchElementException();
442 // load library
443 if ( _bLoadLibrary && !xLibContainer->isLibraryLoaded( _rLibName ) )
444 xLibContainer->loadLibrary( _rLibName );
446 catch( const NoSuchElementException& )
448 throw; // allowed to leave
450 catch( const Exception& )
452 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
455 return xContainer;
459 bool ScriptDocument::Impl::hasLibrary( LibraryContainerType _eType, const OUString& _rLibName ) const
461 bool bHas = false;
464 Reference< XLibraryContainer > xLibContainer = getLibraryContainer( _eType );
465 bHas = xLibContainer.is() && xLibContainer->hasByName( _rLibName );
467 catch( const Exception& )
469 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
471 return bHas;
475 Reference< XNameContainer > ScriptDocument::Impl::getOrCreateLibrary( LibraryContainerType _eType, const OUString& _rLibName ) const
477 Reference< XNameContainer > xLibrary;
480 Reference< XLibraryContainer > xLibContainer( getLibraryContainer( _eType ), UNO_QUERY_THROW );
481 if ( xLibContainer->hasByName( _rLibName ) )
482 xLibrary.set( xLibContainer->getByName( _rLibName ), UNO_QUERY_THROW );
483 else
484 xLibrary.set( xLibContainer->createLibrary( _rLibName ), UNO_QUERY_THROW );
486 if ( !xLibContainer->isLibraryLoaded( _rLibName ) )
487 xLibContainer->loadLibrary( _rLibName );
489 catch( const Exception& )
491 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
493 return xLibrary;
497 void ScriptDocument::Impl::loadLibraryIfExists( LibraryContainerType _eType, const OUString& _rLibrary )
501 Reference< XLibraryContainer > xLibContainer( getLibraryContainer( _eType ) );
502 if ( xLibContainer.is() && xLibContainer->hasByName( _rLibrary ) && !xLibContainer->isLibraryLoaded( _rLibrary ) )
503 xLibContainer->loadLibrary( _rLibrary );
505 catch( const Exception& )
507 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
512 bool ScriptDocument::Impl::removeModuleOrDialog( LibraryContainerType _eType, const OUString& _rLibName, const OUString& _rModuleName )
514 OSL_ENSURE( isValid(), "ScriptDocument::Impl::removeModuleOrDialog: invalid!" );
515 if ( isValid() )
519 Reference< XNameContainer > xLib( getLibrary( _eType, _rLibName, true ) );
520 if ( xLib.is() )
522 xLib->removeByName( _rModuleName );
523 Reference< XVBAModuleInfo > xVBAModuleInfo(xLib, UNO_QUERY);
524 if(xVBAModuleInfo.is() && xVBAModuleInfo->hasModuleInfo(_rModuleName))
525 xVBAModuleInfo->removeModuleInfo(_rModuleName);
526 return true;
529 catch( const Exception& )
531 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
534 return false;
538 bool ScriptDocument::Impl::hasModuleOrDialog( LibraryContainerType _eType, const OUString& _rLibName, const OUString& _rModName ) const
540 OSL_ENSURE( isValid(), "ScriptDocument::Impl::hasModuleOrDialog: invalid!" );
541 if ( !isValid() )
542 return false;
546 Reference< XNameContainer > xLib( getLibrary( _eType, _rLibName, true ) );
547 if ( xLib.is() )
548 return xLib->hasByName( _rModName );
550 catch( const Exception& )
552 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
554 return false;
558 bool ScriptDocument::Impl::getModuleOrDialog( LibraryContainerType _eType, const OUString& _rLibName, const OUString& _rObjectName, Any& _out_rModuleOrDialog )
560 OSL_ENSURE( isValid(), "ScriptDocument::Impl::getModuleOrDialog: invalid!" );
561 if ( !isValid() )
562 return false;
564 _out_rModuleOrDialog.clear();
567 Reference< XNameContainer > xLib( getLibrary( _eType, _rLibName, true ), UNO_QUERY_THROW );
568 if ( xLib->hasByName( _rObjectName ) )
570 _out_rModuleOrDialog = xLib->getByName( _rObjectName );
571 return true;
574 catch( const Exception& )
576 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
578 return false;
582 bool ScriptDocument::Impl::renameModuleOrDialog( LibraryContainerType _eType, const OUString& _rLibName,
583 const OUString& _rOldName, const OUString& _rNewName, const Reference< XNameContainer >& _rxExistingDialogModel )
585 OSL_ENSURE( isValid(), "ScriptDocument::Impl::renameModuleOrDialog: invalid!" );
586 if ( !isValid() )
587 return false;
591 Reference< XNameContainer > xLib( getLibrary( _eType, _rLibName, true ), UNO_QUERY_THROW );
593 // get element
594 Any aElement( xLib->getByName( _rOldName ) );
596 // remove element from container
597 xLib->removeByName( _rOldName );
599 // if it's a dialog, import and export, to reflect the new name
600 if ( _eType == E_DIALOGS )
602 // create dialog model
603 Reference< XComponentContext > aContext(
604 comphelper::getProcessComponentContext() );
605 Reference< XNameContainer > xDialogModel;
606 if ( _rxExistingDialogModel.is() )
607 xDialogModel = _rxExistingDialogModel;
608 else
609 xDialogModel.set(
610 ( aContext->getServiceManager()->
611 createInstanceWithContext(
612 "com.sun.star.awt.UnoControlDialogModel",
613 aContext ) ),
614 UNO_QUERY_THROW );
616 // import dialog model
617 Reference< XInputStreamProvider > xISP( aElement, UNO_QUERY_THROW );
618 if ( !_rxExistingDialogModel.is() )
620 Reference< XInputStream > xInput( xISP->createInputStream(), UNO_QUERY_THROW );
621 ::xmlscript::importDialogModel( xInput, xDialogModel, aContext, isDocument() ? getDocument() : Reference< XModel >() );
624 // set new name as property
625 Reference< XPropertySet > xDlgPSet( xDialogModel, UNO_QUERY_THROW );
626 xDlgPSet->setPropertyValue( DLGED_PROP_NAME, Any( _rNewName ) );
628 // export dialog model
629 xISP = ::xmlscript::exportDialogModel( xDialogModel, aContext, isDocument() ? getDocument() : Reference< XModel >() );
630 aElement <<= xISP;
633 // insert element by new name in container
634 if ( _eType == E_SCRIPTS )
636 Reference< XVBAModuleInfo > xVBAModuleInfo( xLib, UNO_QUERY );
637 if ( xVBAModuleInfo.is() && xVBAModuleInfo->hasModuleInfo( _rOldName ) )
639 ModuleInfo sModuleInfo = xVBAModuleInfo->getModuleInfo( _rOldName );
640 xVBAModuleInfo->removeModuleInfo( _rOldName );
641 xVBAModuleInfo->insertModuleInfo( _rNewName, sModuleInfo );
644 xLib->insertByName( _rNewName, aElement );
645 return true;
647 catch( const Exception& )
649 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
651 return false;
655 bool ScriptDocument::Impl::createModule( const OUString& _rLibName, const OUString& _rModName, bool _bCreateMain, OUString& _out_rNewModuleCode ) const
657 _out_rNewModuleCode.clear();
660 Reference< XNameContainer > xLib( getLibrary( E_SCRIPTS, _rLibName, true ) );
661 if ( !xLib.is() || xLib->hasByName( _rModName ) )
662 return false;
664 // create new module
665 _out_rNewModuleCode = "REM ***** BASIC *****\n\n" ;
666 if ( _bCreateMain )
667 _out_rNewModuleCode += "Sub Main\n\nEnd Sub\n" ;
669 Reference< XVBAModuleInfo > xVBAModuleInfo(xLib, UNO_QUERY);
670 if (xVBAModuleInfo.is())
672 css::script::ModuleInfo aModuleInfo;
673 aModuleInfo.ModuleType = css::script::ModuleType::NORMAL;
674 xVBAModuleInfo->insertModuleInfo(_rModName, aModuleInfo);
677 // insert module into library
678 xLib->insertByName( _rModName, Any( _out_rNewModuleCode ) );
680 catch( const Exception& )
682 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
683 return false;
686 return true;
690 bool ScriptDocument::Impl::insertModuleOrDialog( LibraryContainerType _eType, const OUString& _rLibName, const OUString& _rObjectName, const Any& _rElement ) const
694 Reference< XNameContainer > xLib( getOrCreateLibrary( _eType, _rLibName ), UNO_QUERY_THROW );
695 if ( xLib->hasByName( _rObjectName ) )
696 return false;
698 xLib->insertByName( _rObjectName, _rElement );
699 return true;
701 catch( const Exception& )
703 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
705 return false;
709 bool ScriptDocument::Impl::updateModule( const OUString& _rLibName, const OUString& _rModName, const OUString& _rModuleCode ) const
713 Reference< XNameContainer > xLib( getOrCreateLibrary( E_SCRIPTS, _rLibName ), UNO_QUERY_THROW );
714 if ( !xLib->hasByName( _rModName ) )
715 return false;
716 xLib->replaceByName( _rModName, Any( _rModuleCode ) );
717 return true;
719 catch( const Exception& )
721 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
723 return false;
727 bool ScriptDocument::Impl::createDialog( const OUString& _rLibName, const OUString& _rDialogName, Reference< XInputStreamProvider >& _out_rDialogProvider ) const
731 Reference< XNameContainer > xLib( getLibrary( E_DIALOGS, _rLibName, true ), UNO_QUERY_THROW );
733 // create dialog
734 _out_rDialogProvider.clear();
735 if ( xLib->hasByName( _rDialogName ) )
736 return false;
738 // create new dialog model
739 Reference< XComponentContext > aContext(
740 comphelper::getProcessComponentContext() );
741 Reference< XNameContainer > xDialogModel(
742 aContext->getServiceManager()->createInstanceWithContext(
743 "com.sun.star.awt.UnoControlDialogModel", aContext ),
744 UNO_QUERY_THROW );
746 // set name property
747 Reference< XPropertySet > xDlgPSet( xDialogModel, UNO_QUERY_THROW );
748 xDlgPSet->setPropertyValue( DLGED_PROP_NAME, Any( _rDialogName ) );
750 // export dialog model
751 _out_rDialogProvider = ::xmlscript::exportDialogModel( xDialogModel, aContext, isDocument() ? getDocument() : Reference< XModel >() );
753 // insert dialog into library
754 xLib->insertByName( _rDialogName, Any( _out_rDialogProvider ) );
756 catch( const Exception& )
758 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
761 return _out_rDialogProvider.is();
765 void ScriptDocument::Impl::setDocumentModified() const
767 OSL_ENSURE( isValid() && isDocument(), "ScriptDocument::Impl::setDocumentModified: only to be called for real documents!" );
768 if ( isValid() && isDocument() )
772 m_xDocModify->setModified( true );
774 catch( const Exception& )
776 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
782 bool ScriptDocument::Impl::isDocumentModified() const
784 OSL_ENSURE( isValid() && isDocument(), "ScriptDocument::Impl::isDocumentModified: only to be called for real documents!" );
785 bool bIsModified = false;
786 if ( isValid() && isDocument() )
790 bIsModified = m_xDocModify->isModified();
792 catch( const Exception& )
794 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
797 return bIsModified;
801 void ScriptDocument::Impl::saveDocument( const Reference< XStatusIndicator >& _rxStatusIndicator ) const
803 Reference< XFrame > xFrame;
804 if ( !getCurrentFrame( xFrame ) )
805 return;
807 Sequence< PropertyValue > aArgs;
808 if ( _rxStatusIndicator.is() )
810 aArgs = ::comphelper::InitPropertySequence({
811 { "StatusIndicator", Any(_rxStatusIndicator) }
817 URL aURL;
818 aURL.Complete = ".uno:Save" ;
819 aURL.Main = aURL.Complete;
820 aURL.Protocol = ".uno:" ;
821 aURL.Path = "Save" ;
823 Reference< XDispatchProvider > xDispProv( xFrame, UNO_QUERY_THROW );
824 Reference< XDispatch > xDispatch(
825 xDispProv->queryDispatch( aURL, "_self", FrameSearchFlag::AUTO ),
826 UNO_SET_THROW );
828 xDispatch->dispatch( aURL, aArgs );
830 catch( const Exception& )
832 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
837 OUString ScriptDocument::Impl::getTitle() const
839 OSL_PRECOND( isValid() && isDocument(), "ScriptDocument::Impl::getTitle: for documents only!" );
841 OUString sTitle;
842 if ( isValid() && isDocument() )
844 sTitle = ::comphelper::DocumentInfo::getDocumentTitle( m_xDocument );
846 return sTitle;
850 OUString ScriptDocument::Impl::getURL() const
852 OSL_PRECOND( isValid() && isDocument(), "ScriptDocument::Impl::getURL: for documents only!" );
854 OUString sURL;
855 if ( isValid() && isDocument() )
859 sURL = m_xDocument->getURL();
861 catch( const Exception& )
863 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
866 return sURL;
870 bool ScriptDocument::Impl::allowMacros() const
872 OSL_ENSURE( isValid() && isDocument(), "ScriptDocument::Impl::allowMacros: for documents only!" );
873 bool bAllow = false;
874 if ( isValid() && isDocument() )
878 bAllow = m_xScriptAccess->getAllowMacroExecution();
880 catch( const Exception& )
882 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
885 return bAllow;
889 bool ScriptDocument::Impl::getCurrentFrame( Reference< XFrame >& _out_rxFrame ) const
891 _out_rxFrame.clear();
892 OSL_PRECOND( isValid() && isDocument(), "ScriptDocument::Impl::getCurrentFrame: documents only!" );
893 if ( !isValid() || !isDocument() )
894 return false;
898 Reference< XModel > xDocument( m_xDocument, UNO_SET_THROW );
899 Reference< XController > xController( xDocument->getCurrentController(), UNO_SET_THROW );
900 _out_rxFrame.set( xController->getFrame(), UNO_SET_THROW );
902 catch( const Exception& )
904 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
907 return _out_rxFrame.is();
911 bool ScriptDocument::Impl::isLibraryShared( const OUString& _rLibName, LibraryContainerType _eType )
913 bool bIsShared = false;
916 Reference< XLibraryContainer2 > xLibContainer( getLibraryContainer( _eType ), UNO_QUERY_THROW );
918 if ( !xLibContainer->hasByName( _rLibName ) || !xLibContainer->isLibraryLink( _rLibName ) )
919 return false;
920 OUString aFileURL;
921 Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
922 Reference< XUriReferenceFactory > xUriFac = UriReferenceFactory::create(xContext);
924 OUString aLinkURL( xLibContainer->getLibraryLinkURL( _rLibName ) );
925 Reference< XUriReference > xUriRef( xUriFac->parse( aLinkURL ), UNO_QUERY_THROW );
927 OUString aScheme = xUriRef->getScheme();
928 if ( aScheme.equalsIgnoreAsciiCase("file") )
930 aFileURL = aLinkURL;
932 else if ( aScheme.equalsIgnoreAsciiCase("vnd.sun.star.pkg") )
934 OUString aAuthority = xUriRef->getAuthority();
935 if ( aAuthority.matchIgnoreAsciiCase("vnd.sun.star.expand:") )
937 OUString aDecodedURL( aAuthority.copy( sizeof ( "vnd.sun.star.expand:" ) - 1 ) );
938 aDecodedURL = ::rtl::Uri::decode( aDecodedURL, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 );
939 Reference< XMacroExpander > xMacroExpander = theMacroExpander::get(xContext);
940 aFileURL = xMacroExpander->expandMacros( aDecodedURL );
944 if ( !aFileURL.isEmpty() )
946 ::osl::DirectoryItem aFileItem;
947 ::osl::FileStatus aFileStatus( osl_FileStatus_Mask_FileURL );
948 OSL_VERIFY( ::osl::DirectoryItem::get( aFileURL, aFileItem ) == ::osl::FileBase::E_None );
949 OSL_VERIFY( aFileItem.getFileStatus( aFileStatus ) == ::osl::FileBase::E_None );
950 OUString aCanonicalFileURL( aFileStatus.getFileURL() );
952 if( aCanonicalFileURL.indexOf( "share/basic" ) >= 0 ||
953 aCanonicalFileURL.indexOf( "share/uno_packages" ) >= 0 ||
954 aCanonicalFileURL.indexOf( "share/extensions" ) >= 0 )
955 bIsShared = true;
958 catch( const Exception& )
960 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
963 return bIsShared;
967 void ScriptDocument::Impl::onDocumentCreated( const ScriptDocument& /*_rDocument*/ )
969 // not interested in
972 void ScriptDocument::Impl::onDocumentOpened( const ScriptDocument& /*_rDocument*/ )
974 // not interested in
977 void ScriptDocument::Impl::onDocumentSave( const ScriptDocument& /*_rDocument*/ )
979 // not interested in
982 void ScriptDocument::Impl::onDocumentSaveDone( const ScriptDocument& /*_rDocument*/ )
984 // not interested in
987 void ScriptDocument::Impl::onDocumentSaveAs( const ScriptDocument& /*_rDocument*/ )
989 // not interested in
992 void ScriptDocument::Impl::onDocumentSaveAsDone( const ScriptDocument& /*_rDocument*/ )
994 // not interested in
997 void ScriptDocument::Impl::onDocumentClosed( const ScriptDocument& _rDocument )
999 DBG_TESTSOLARMUTEX();
1000 OSL_PRECOND( isValid(), "ScriptDocument::Impl::onDocumentClosed: should not be listening if I'm not valid!" );
1002 bool bMyDocument = m_xDocument == _rDocument.getDocument();
1003 OSL_PRECOND( bMyDocument, "ScriptDocument::Impl::onDocumentClosed: didn't want to know *this*!" );
1004 if ( bMyDocument )
1006 m_bDocumentClosed = true;
1011 void ScriptDocument::Impl::onDocumentTitleChanged( const ScriptDocument& /*_rDocument*/ )
1013 // not interested in
1016 void ScriptDocument::Impl::onDocumentModeChanged( const ScriptDocument& /*_rDocument*/ )
1018 // not interested in
1022 ScriptDocument::ScriptDocument()
1023 :m_pImpl(new Impl)
1027 ScriptDocument::ScriptDocument( ScriptDocument::SpecialDocument _eType )
1028 :m_pImpl( new Impl( Reference< XModel >() ) )
1030 OSL_ENSURE( _eType == NoDocument, "ScriptDocument::ScriptDocument: unknown SpecialDocument type!" );
1034 ScriptDocument::ScriptDocument( const Reference< XModel >& _rxDocument )
1035 :m_pImpl( new Impl( _rxDocument ) )
1037 OSL_ENSURE( _rxDocument.is(), "ScriptDocument::ScriptDocument: document must not be NULL!" );
1038 // a NULL document results in an uninitialized instance, and for this
1039 // purpose, there is a dedicated constructor
1043 const ScriptDocument& ScriptDocument::getApplicationScriptDocument()
1045 static ScriptDocument s_aApplicationScripts;
1046 return s_aApplicationScripts;
1050 ScriptDocument ScriptDocument::getDocumentForBasicManager( const BasicManager* _pManager )
1052 if ( _pManager == SfxApplication::GetBasicManager() )
1053 return getApplicationScriptDocument();
1055 docs::Documents aDocuments;
1056 lcl_getAllModels_throw( aDocuments, false );
1058 for (auto const& doc : aDocuments)
1060 const BasicManager* pDocBasicManager = ::basic::BasicManagerRepository::getDocumentBasicManager( doc.xModel );
1061 if ( ( pDocBasicManager != SfxApplication::GetBasicManager() )
1062 && ( pDocBasicManager == _pManager )
1065 return ScriptDocument( doc.xModel );
1069 OSL_FAIL( "ScriptDocument::getDocumentForBasicManager: did not find a document for this manager!" );
1070 return ScriptDocument( NoDocument );
1074 ScriptDocument ScriptDocument::getDocumentWithURLOrCaption( const OUString& _rUrlOrCaption )
1076 ScriptDocument aDocument( getApplicationScriptDocument() );
1077 if ( _rUrlOrCaption.isEmpty() )
1078 return aDocument;
1080 docs::Documents aDocuments;
1081 lcl_getAllModels_throw( aDocuments, false );
1083 for (auto const& doc : aDocuments)
1085 const ScriptDocument aCheck = ScriptDocument( doc.xModel );
1086 if ( _rUrlOrCaption == aCheck.getTitle()
1087 || _rUrlOrCaption == aCheck.m_pImpl->getURL()
1090 aDocument = aCheck;
1091 break;
1095 return aDocument;
1099 namespace
1101 struct DocumentTitleLess
1103 explicit DocumentTitleLess( const CollatorWrapper& _rCollator )
1104 :m_aCollator( _rCollator )
1108 bool operator()( const ScriptDocument& _lhs, const ScriptDocument& _rhs ) const
1110 return m_aCollator.compareString( _lhs.getTitle(), _rhs.getTitle() ) < 0;
1112 private:
1113 const CollatorWrapper m_aCollator;
1118 ScriptDocuments ScriptDocument::getAllScriptDocuments( ScriptDocument::ScriptDocumentList _eListType )
1120 ScriptDocuments aScriptDocs;
1122 // include application?
1123 if ( _eListType == AllWithApplication )
1124 aScriptDocs.push_back( getApplicationScriptDocument() );
1126 // obtain documents
1129 docs::Documents aDocuments;
1130 lcl_getAllModels_throw( aDocuments, true /* exclude invisible */ );
1132 for (auto const& doc : aDocuments)
1134 // exclude documents without script/library containers
1135 ScriptDocument aDoc( doc.xModel );
1136 if ( !aDoc.isValid() )
1137 continue;
1139 aScriptDocs.push_back( aDoc );
1142 catch( const Exception& )
1144 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
1147 // sort document list by doc title?
1148 if ( _eListType == DocumentsSorted )
1150 CollatorWrapper aCollator( ::comphelper::getProcessComponentContext() );
1151 aCollator.loadDefaultCollator( SvtSysLocale().GetLanguageTag().getLocale(), 0 );
1152 std::sort( aScriptDocs.begin(), aScriptDocs.end(), DocumentTitleLess( aCollator ) );
1155 return aScriptDocs;
1159 bool ScriptDocument::operator==( const ScriptDocument& _rhs ) const
1161 return m_pImpl->getDocumentRef() == _rhs.m_pImpl->getDocumentRef();
1165 sal_Int32 ScriptDocument::hashCode() const
1167 return sal::static_int_cast<sal_Int32>(reinterpret_cast< sal_IntPtr >( m_pImpl->getDocumentRef().get() ));
1171 bool ScriptDocument::isValid() const
1173 return m_pImpl->isValid();
1177 bool ScriptDocument::isAlive() const
1179 return m_pImpl->isAlive();
1183 Reference< XLibraryContainer > ScriptDocument::getLibraryContainer( LibraryContainerType _eType ) const
1185 return m_pImpl->getLibraryContainer( _eType );
1189 Reference< XNameContainer > ScriptDocument::getLibrary( LibraryContainerType _eType, const OUString& _rLibName, bool _bLoadLibrary ) const
1191 return m_pImpl->getLibrary( _eType, _rLibName, _bLoadLibrary );
1195 bool ScriptDocument::hasLibrary( LibraryContainerType _eType, const OUString& _rLibName ) const
1197 return m_pImpl->hasLibrary( _eType, _rLibName );
1201 Reference< XNameContainer > ScriptDocument::getOrCreateLibrary( LibraryContainerType _eType, const OUString& _rLibName ) const
1203 return m_pImpl->getOrCreateLibrary( _eType, _rLibName );
1207 void ScriptDocument::loadLibraryIfExists( LibraryContainerType _eType, const OUString& _rLibrary )
1209 m_pImpl->loadLibraryIfExists( _eType, _rLibrary );
1213 Sequence< OUString > ScriptDocument::getObjectNames( LibraryContainerType _eType, const OUString& _rLibName ) const
1215 Sequence< OUString > aModuleNames;
1219 if ( hasLibrary( _eType, _rLibName ) )
1221 Reference< XNameContainer > xLib( getLibrary( _eType, _rLibName, false ) );
1222 if ( xLib.is() )
1223 aModuleNames = xLib->getElementNames();
1226 catch( const Exception& )
1228 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
1231 // sort
1232 std::sort( aModuleNames.begin(), aModuleNames.end(), StringCompareLessThan );
1234 return aModuleNames;
1238 OUString ScriptDocument::createObjectName( LibraryContainerType _eType, const OUString& _rLibName ) const
1240 OUString aObjectName;
1242 OUString aBaseName = _eType == E_SCRIPTS ? OUString("Module") : OUString("Dialog");
1244 Sequence< OUString > aUsedNames( getObjectNames( _eType, _rLibName ) );
1245 std::set< OUString > aUsedNamesCheck;
1246 std::copy( aUsedNames.begin(), aUsedNames.end(),
1247 std::insert_iterator< std::set< OUString > >( aUsedNamesCheck, aUsedNamesCheck.begin() ) );
1249 bool bValid = false;
1250 sal_Int32 i = 1;
1251 while ( !bValid )
1253 aObjectName = aBaseName
1254 + OUString::number( i );
1256 if ( aUsedNamesCheck.find( aObjectName ) == aUsedNamesCheck.end() )
1257 bValid = true;
1259 ++i;
1262 return aObjectName;
1266 Sequence< OUString > ScriptDocument::getLibraryNames() const
1268 return GetMergedLibraryNames( getLibraryContainer( E_SCRIPTS ), getLibraryContainer( E_DIALOGS ) );
1272 bool ScriptDocument::isReadOnly() const
1274 return m_pImpl->isReadOnly();
1278 bool ScriptDocument::isApplication() const
1280 return m_pImpl->isApplication();
1283 bool ScriptDocument::isInVBAMode() const
1285 return m_pImpl->isInVBAMode();
1289 BasicManager* ScriptDocument::getBasicManager() const
1291 return m_pImpl->getBasicManager();
1295 Reference< XModel > ScriptDocument::getDocument() const
1297 return m_pImpl->getDocument();
1301 Reference< XModel > ScriptDocument::getDocumentOrNull() const
1303 if ( isDocument() )
1304 return m_pImpl->getDocument();
1305 return nullptr;
1309 bool ScriptDocument::removeModule( const OUString& _rLibName, const OUString& _rModuleName ) const
1311 return m_pImpl->removeModuleOrDialog( E_SCRIPTS, _rLibName, _rModuleName );
1315 bool ScriptDocument::hasModule( const OUString& _rLibName, const OUString& _rModuleName ) const
1317 return m_pImpl->hasModuleOrDialog( E_SCRIPTS, _rLibName, _rModuleName );
1321 bool ScriptDocument::getModule( const OUString& _rLibName, const OUString& _rModName, OUString& _out_rModuleSource ) const
1323 Any aCode;
1324 if ( !m_pImpl->getModuleOrDialog( E_SCRIPTS, _rLibName, _rModName, aCode ) )
1325 return false;
1326 OSL_VERIFY( aCode >>= _out_rModuleSource );
1327 return true;
1331 bool ScriptDocument::renameModule( const OUString& _rLibName, const OUString& _rOldName, const OUString& _rNewName ) const
1333 return m_pImpl->renameModuleOrDialog( E_SCRIPTS, _rLibName, _rOldName, _rNewName, nullptr );
1337 bool ScriptDocument::createModule( const OUString& _rLibName, const OUString& _rModName, bool _bCreateMain, OUString& _out_rNewModuleCode ) const
1339 if ( !m_pImpl->createModule( _rLibName, _rModName, _bCreateMain, _out_rNewModuleCode ) )
1340 return false;
1342 // doc shell modified
1343 MarkDocumentModified( *const_cast< ScriptDocument* >( this ) ); // here?
1344 return true;
1348 bool ScriptDocument::insertModule( const OUString& _rLibName, const OUString& _rModName, const OUString& _rModuleCode ) const
1350 return m_pImpl->insertModuleOrDialog( E_SCRIPTS, _rLibName, _rModName, Any( _rModuleCode ) );
1354 bool ScriptDocument::updateModule( const OUString& _rLibName, const OUString& _rModName, const OUString& _rModuleCode ) const
1356 return m_pImpl->updateModule( _rLibName, _rModName, _rModuleCode );
1360 bool ScriptDocument::removeDialog( const OUString& _rLibName, const OUString& _rDialogName ) const
1362 return m_pImpl->removeModuleOrDialog( E_DIALOGS, _rLibName, _rDialogName );
1366 bool ScriptDocument::hasDialog( const OUString& _rLibName, const OUString& _rDialogName ) const
1368 return m_pImpl->hasModuleOrDialog( E_DIALOGS, _rLibName, _rDialogName );
1372 bool ScriptDocument::getDialog( const OUString& _rLibName, const OUString& _rDialogName, Reference< XInputStreamProvider >& _out_rDialogProvider ) const
1374 Any aCode;
1375 if ( !m_pImpl->getModuleOrDialog( E_DIALOGS, _rLibName, _rDialogName, aCode ) )
1376 return false;
1377 OSL_VERIFY( aCode >>= _out_rDialogProvider );
1378 return _out_rDialogProvider.is();
1382 bool ScriptDocument::renameDialog( const OUString& _rLibName, const OUString& _rOldName, const OUString& _rNewName, const Reference< XNameContainer >& _rxExistingDialogModel ) const
1384 return m_pImpl->renameModuleOrDialog( E_DIALOGS, _rLibName, _rOldName, _rNewName, _rxExistingDialogModel );
1388 bool ScriptDocument::createDialog( const OUString& _rLibName, const OUString& _rDialogName, Reference< XInputStreamProvider >& _out_rDialogProvider ) const
1390 if ( !m_pImpl->createDialog( _rLibName, _rDialogName, _out_rDialogProvider ) )
1391 return false;
1393 MarkDocumentModified( *const_cast< ScriptDocument* >( this ) ); // here?
1394 return true;
1398 bool ScriptDocument::insertDialog( const OUString& _rLibName, const OUString& _rDialogName, const Reference< XInputStreamProvider >& _rxDialogProvider ) const
1400 return m_pImpl->insertModuleOrDialog( E_DIALOGS, _rLibName, _rDialogName, Any( _rxDialogProvider ) );
1404 void ScriptDocument::setDocumentModified() const
1406 m_pImpl->setDocumentModified();
1410 bool ScriptDocument::isDocumentModified() const
1412 return m_pImpl->isDocumentModified();
1416 void ScriptDocument::saveDocument( const Reference< XStatusIndicator >& _rxStatusIndicator ) const
1418 m_pImpl->saveDocument( _rxStatusIndicator );
1422 LibraryLocation ScriptDocument::getLibraryLocation( const OUString& _rLibName ) const
1424 LibraryLocation eLocation = LIBRARY_LOCATION_UNKNOWN;
1425 if ( !_rLibName.isEmpty() )
1427 if ( isDocument() )
1429 eLocation = LIBRARY_LOCATION_DOCUMENT;
1431 else
1433 if ( ( hasLibrary( E_SCRIPTS, _rLibName ) && !m_pImpl->isLibraryShared( _rLibName, E_SCRIPTS ) )
1434 || ( hasLibrary( E_DIALOGS, _rLibName ) && !m_pImpl->isLibraryShared( _rLibName, E_DIALOGS ) )
1437 eLocation = LIBRARY_LOCATION_USER;
1439 else
1441 eLocation = LIBRARY_LOCATION_SHARE;
1446 return eLocation;
1450 OUString ScriptDocument::getTitle( LibraryLocation _eLocation, LibraryType _eType ) const
1452 OUString aTitle;
1454 switch ( _eLocation )
1456 case LIBRARY_LOCATION_USER:
1458 switch ( _eType )
1460 case LibraryType::Module: aTitle = IDEResId(RID_STR_USERMACROS); break;
1461 case LibraryType::Dialog: aTitle = IDEResId(RID_STR_USERDIALOGS); break;
1462 case LibraryType::All: aTitle = IDEResId(RID_STR_USERMACROSDIALOGS); break;
1463 default:
1464 break;
1467 break;
1468 case LIBRARY_LOCATION_SHARE:
1470 switch ( _eType )
1472 case LibraryType::Module: aTitle = IDEResId(RID_STR_SHAREMACROS); break;
1473 case LibraryType::Dialog: aTitle = IDEResId(RID_STR_SHAREDIALOGS); break;
1474 case LibraryType::All: aTitle = IDEResId(RID_STR_SHAREMACROSDIALOGS); break;
1475 default:
1476 break;
1479 break;
1480 case LIBRARY_LOCATION_DOCUMENT:
1481 aTitle = getTitle();
1482 break;
1483 default:
1484 break;
1487 return aTitle;
1491 OUString ScriptDocument::getTitle() const
1493 return m_pImpl->getTitle();
1497 bool ScriptDocument::isActive() const
1499 bool bIsActive( false );
1502 Reference< XFrame > xFrame;
1503 if ( m_pImpl->getCurrentFrame( xFrame ) )
1504 bIsActive = xFrame->isActive();
1506 catch( const Exception& )
1508 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
1510 return bIsActive;
1514 bool ScriptDocument::allowMacros() const
1516 return m_pImpl->allowMacros();
1519 } // namespace basctl
1521 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */