LibreOffice Module basctl (master) 1
scriptdocument.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
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>
28
29#include <com/sun/star/ucb/ContentCreationException.hpp>
30#include <com/sun/star/uri/UriReferenceFactory.hpp>
31#include <com/sun/star/util/theMacroExpander.hpp>
32#include <com/sun/star/frame/XStorable.hpp>
33#include <com/sun/star/frame/FrameSearchFlag.hpp>
34#include <com/sun/star/frame/XDispatchProvider.hpp>
35#include <com/sun/star/awt/XWindow2.hpp>
36#include <com/sun/star/beans/XPropertySet.hpp>
37#include <com/sun/star/document/XEmbeddedScripts.hpp>
38#include <com/sun/star/script/vba/XVBACompatibility.hpp>
39#include <com/sun/star/script/vba/XVBAModuleInfo.hpp>
40#include <com/sun/star/script/ModuleInfo.hpp>
41#include <com/sun/star/script/ModuleType.hpp>
42
43#include <sfx2/app.hxx>
44#include <sfx2/objsh.hxx>
45#include <sfx2/bindings.hxx>
46#include <sfx2/docfile.hxx>
47
49
51
53
55#include <config_folders.h>
56#include <tools/debug.hxx>
57
61#include <comphelper/string.hxx>
62
63#include <vcl/svapp.hxx>
64#include <vcl/settings.hxx>
65
66#include <osl/file.hxx>
67#include <rtl/uri.hxx>
68#include <set>
69
70
71namespace basctl
72{
73 using ::com::sun::star::uno::Sequence;
74 using ::com::sun::star::uno::Reference;
75 using ::com::sun::star::frame::XModel;
76 using ::com::sun::star::beans::XPropertySet;
77 using ::com::sun::star::script::XLibraryContainer;
78 using ::com::sun::star::uno::UNO_QUERY_THROW;
79 using ::com::sun::star::uno::UNO_SET_THROW;
80 using ::com::sun::star::uno::Exception;
81 using ::com::sun::star::container::XNameContainer;
82 using ::com::sun::star::container::NoSuchElementException;
83 using ::com::sun::star::uno::UNO_QUERY;
84 using ::com::sun::star::task::XStatusIndicator;
85 using ::com::sun::star::uno::Any;
86 using ::com::sun::star::script::XLibraryContainer2;
87 using ::com::sun::star::uri::UriReferenceFactory;
88 using ::com::sun::star::uri::XUriReferenceFactory;
89 using ::com::sun::star::uri::XUriReference;
90 using ::com::sun::star::uno::XComponentContext;
91 using ::com::sun::star::util::XMacroExpander;
92 using ::com::sun::star::util::theMacroExpander;
93 using ::com::sun::star::io::XInputStreamProvider;
94 using ::com::sun::star::uno::Any;
95 using ::com::sun::star::io::XInputStream;
96 using ::com::sun::star::frame::XStorable;
97 using ::com::sun::star::util::XModifiable;
98 using ::com::sun::star::frame::XController;
99 using ::com::sun::star::frame::XFrame;
100 using ::com::sun::star::util::URL;
101 using ::com::sun::star::frame::XDispatchProvider;
102 using ::com::sun::star::frame::XDispatch;
103 using ::com::sun::star::beans::PropertyValue;
104 using ::com::sun::star::awt::XWindow2;
105 using ::com::sun::star::document::XEmbeddedScripts;
106 using ::com::sun::star::script::ModuleInfo;
107 using ::com::sun::star::script::vba::XVBACompatibility;
108 using ::com::sun::star::script::vba::XVBAModuleInfo;
109
110 namespace FrameSearchFlag = ::com::sun::star::frame::FrameSearchFlag;
111
112
113 namespace
114 {
115 class FilterDocuments : public docs::IDocumentDescriptorFilter
116 {
117 public:
118 explicit FilterDocuments(bool _bFilterInvisible)
119 : m_bFilterInvisible(_bFilterInvisible)
120 {
121 }
122
123 virtual ~FilterDocuments() {}
124
125 virtual bool includeDocument( const docs::DocumentDescriptor& _rDocument ) const override;
126
127 private:
128 static bool impl_isDocumentVisible_nothrow( const docs::DocumentDescriptor& _rDocument );
129
130 private:
132 };
133
134 bool FilterDocuments::impl_isDocumentVisible_nothrow( const docs::DocumentDescriptor& _rDocument )
135 {
136 try
137 {
138 for (auto const& controller : _rDocument.aControllers)
139 {
140 Reference< XFrame > xFrame( controller->getFrame(), UNO_SET_THROW );
141 Reference< XWindow2 > xContainer( xFrame->getContainerWindow(), UNO_QUERY_THROW );
142 if ( xContainer->isVisible() )
143 return true;
144 }
145 }
146 catch( const Exception& )
147 {
148 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
149 }
150 return false;
151 }
152
153 bool FilterDocuments::includeDocument( const docs::DocumentDescriptor& _rDocument ) const
154 {
155 Reference< XEmbeddedScripts > xScripts( _rDocument.xModel, UNO_QUERY );
156 if ( !xScripts.is() )
157 return false;
158 return !m_bFilterInvisible || impl_isDocumentVisible_nothrow( _rDocument );
159 }
160
161 void lcl_getAllModels_throw( docs::Documents& _out_rModels, bool _bVisibleOnly )
162 {
163 _out_rModels.clear();
164
165 FilterDocuments aFilter( _bVisibleOnly );
166 docs::DocumentEnumeration aEnum(
168
169 aEnum.getDocuments( _out_rModels );
170 }
171 }
172
174 {
175 private:
182 std::unique_ptr< DocumentEventNotifier > m_pDocListener;
183
184 public:
185 Impl ();
186 explicit Impl(Reference<XModel> const& rxDocument);
187 virtual ~Impl() override;
188
192 bool isValid() const { return m_bValid; }
195 bool isAlive() const { return m_bValid && ( m_bIsApplication || !m_bDocumentClosed ); }
197 bool isApplication() const { return m_bValid && m_bIsApplication; }
199 bool isDocument() const { return m_bValid && !m_bIsApplication; }
200
203 void invalidate();
204
206 getDocumentRef() const { return m_xDocument; }
207
211
213 bool isLibraryShared( const OUString& _rLibName, LibraryContainerType _eType );
214
221 bool getCurrentFrame( Reference< XFrame >& _out_rxFrame ) const;
222
223 // versions with the same signature/semantics as in ScriptDocument itself
224 bool isReadOnly() const;
225 bool isInVBAMode() const;
227 getBasicManager() const;
229 getDocument() const;
230 void setDocumentModified() const;
231 bool isDocumentModified() const;
232 void saveDocument( const Reference< XStatusIndicator >& _rxStatusIndicator ) const;
233
234 OUString getTitle() const;
235 OUString getURL() const;
236
237 bool allowMacros() const;
238
240 getLibrary( LibraryContainerType _eType, const OUString& _rLibName, bool _bLoadLibrary ) const;
241 bool hasLibrary( LibraryContainerType _eType, const OUString& _rLibName ) const;
243 getOrCreateLibrary( LibraryContainerType _eType, const OUString& _rLibName ) const;
244
245 void loadLibraryIfExists( LibraryContainerType _eType, const OUString& _rLibrary );
246
247 bool removeModuleOrDialog( LibraryContainerType _eType, const OUString& _rLibName, const OUString& _rModuleName );
248 bool hasModuleOrDialog( LibraryContainerType _eType, const OUString& _rLibName, const OUString& _rModName ) const;
249 bool getModuleOrDialog( LibraryContainerType _eType, const OUString& _rLibName, const OUString& _rObjectName, Any& _out_rModuleOrDialog );
250 bool renameModuleOrDialog( LibraryContainerType _eType, const OUString& _rLibName, const OUString& _rOldName, const OUString& _rNewName, const Reference< XNameContainer >& _rxExistingDialogModel );
251 bool createModule( const OUString& _rLibName, const OUString& _rModName, bool _bCreateMain, OUString& _out_rNewModuleCode ) const;
252 bool insertModuleOrDialog( LibraryContainerType _eType, const OUString& _rObjectName, const OUString& _rModName, const Any& _rElement ) const;
253 bool updateModule( const OUString& _rLibName, const OUString& _rModName, const OUString& _rModuleCode ) const;
254 bool createDialog( const OUString& _rLibName, const OUString& _rDialogName, Reference< XInputStreamProvider >& _out_rDialogProvider ) const;
255
256 protected:
257 // DocumentEventListener
258 virtual void onDocumentCreated( const ScriptDocument& _rDocument ) override;
259 virtual void onDocumentOpened( const ScriptDocument& _rDocument ) override;
260 virtual void onDocumentSave( const ScriptDocument& _rDocument ) override;
261 virtual void onDocumentSaveDone( const ScriptDocument& _rDocument ) override;
262 virtual void onDocumentSaveAs( const ScriptDocument& _rDocument ) override;
263 virtual void onDocumentSaveAsDone( const ScriptDocument& _rDocument ) override;
264 virtual void onDocumentClosed( const ScriptDocument& _rDocument ) override;
265 virtual void onDocumentTitleChanged( const ScriptDocument& _rDocument ) override;
266 virtual void onDocumentModeChanged( const ScriptDocument& _rDocument ) override;
267
268 private:
269 bool impl_initDocument_nothrow( const Reference< XModel >& _rxModel );
270 };
271
272
274 :m_bIsApplication( true )
275 ,m_bValid( true )
276 ,m_bDocumentClosed( false )
277 {
278 }
279
281 :m_bIsApplication( false )
282 ,m_bValid( false )
283 ,m_bDocumentClosed( false )
284 {
285 if ( _rxDocument.is() )
286 impl_initDocument_nothrow( _rxDocument );
287 }
288
290 {
291 invalidate();
292 }
293
295 {
296 m_bIsApplication = false;
297 m_bValid = false;
298 m_bDocumentClosed = false;
299
300 m_xDocument.clear();
301 m_xDocModify.clear();
302 m_xScriptAccess.clear();
303
304 if (m_pDocListener)
305 m_pDocListener->dispose();
306 }
307
309 {
310 try
311 {
312 m_xDocument.set ( _rxModel, UNO_SET_THROW );
313 m_xDocModify.set ( _rxModel, UNO_QUERY_THROW );
314 m_xScriptAccess.set ( _rxModel, UNO_QUERY );
315
316 m_bValid = m_xScriptAccess.is();
317
318 if ( m_bValid )
319 m_pDocListener.reset( new DocumentEventNotifier( *this, _rxModel ) );
320 }
321 catch( const Exception& )
322 {
323 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
324 m_bValid = false;
325 }
326
327 if ( !m_bValid )
328 {
329 invalidate();
330 }
331
332 return m_bValid;
333 }
334
336 {
337 OSL_ENSURE( isValid(), "ScriptDocument::Impl::getLibraryContainer: invalid!" );
338
340 if ( !isValid() )
341 return xContainer;
342
343 try
344 {
345 if ( isApplication() )
346 xContainer.set( _eType == E_SCRIPTS ? SfxGetpApp()->GetBasicContainer() : SfxGetpApp()->GetDialogContainer(), UNO_QUERY_THROW );
347 else
348 {
349 xContainer.set(
350 _eType == E_SCRIPTS ? m_xScriptAccess->getBasicLibraries() : m_xScriptAccess->getDialogLibraries(),
351 UNO_QUERY_THROW );
352 }
353 }
354 catch( const Exception& )
355 {
356 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
357 }
358 return xContainer;
359 }
360
362 {
363 OSL_ENSURE( isValid(), "ScriptDocument::Impl::isReadOnly: invalid state!" );
364 OSL_ENSURE( !isApplication(), "ScriptDocument::Impl::isReadOnly: not allowed to be called for the application!" );
365
366 bool bIsReadOnly = true;
367 if ( isValid() && !isApplication() )
368 {
369 try
370 {
371 // note that XStorable is required by the OfficeDocument service
372 Reference< XStorable > xDocStorable( m_xDocument, UNO_QUERY_THROW );
373 bIsReadOnly = xDocStorable->isReadonly();
374 }
375 catch( const Exception& )
376 {
377 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
378 }
379 }
380 return bIsReadOnly;
381 }
382
384 {
385 bool bResult = false;
386 if ( !isApplication() )
387 {
389 if ( xVBACompat.is() )
390 bResult = xVBACompat->getVBACompatibilityMode();
391 }
392 return bResult;
393 }
394
396 {
397 try
398 {
399 OSL_ENSURE( isValid(), "ScriptDocument::Impl::getBasicManager: invalid state!" );
400 if ( !isValid() )
401 return nullptr;
402
403 if ( isApplication() )
405
406 return ::basic::BasicManagerRepository::getDocumentBasicManager( m_xDocument );
407 }
408 catch (const css::ucb::ContentCreationException&)
409 {
410 TOOLS_WARN_EXCEPTION( "basctl.basicide", "ScriptDocument::getBasicManager" );
411 }
412 return nullptr;
413 }
414
416 {
417 OSL_ENSURE( isValid(), "ScriptDocument::Impl::getDocument: invalid state!" );
418 OSL_ENSURE( isDocument(), "ScriptDocument::Impl::getDocument: for documents only!" );
419 if ( !isValid() || !isDocument() )
420 return nullptr;
421
422 return m_xDocument;
423 }
424
425
426 Reference< XNameContainer > ScriptDocument::Impl::getLibrary( LibraryContainerType _eType, const OUString& _rLibName, bool _bLoadLibrary ) const
427 {
428 OSL_ENSURE( isValid(), "ScriptDocument::Impl::getLibrary: invalid state!" );
429
431 try
432 {
433 Reference< XLibraryContainer > xLibContainer = getLibraryContainer( _eType );
434 if ( isValid() && xLibContainer.is() )
435 xContainer.set( xLibContainer->getByName( _rLibName ), UNO_QUERY_THROW );
436
437 if ( !xContainer.is() )
438 throw NoSuchElementException();
439
440 // load library
441 if ( _bLoadLibrary && !xLibContainer->isLibraryLoaded( _rLibName ) )
442 xLibContainer->loadLibrary( _rLibName );
443 }
444 catch( const NoSuchElementException& )
445 {
446 throw; // allowed to leave
447 }
448 catch( const Exception& )
449 {
450 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
451 }
452
453 return xContainer;
454 }
455
456
457 bool ScriptDocument::Impl::hasLibrary( LibraryContainerType _eType, const OUString& _rLibName ) const
458 {
459 bool bHas = false;
460 try
461 {
462 Reference< XLibraryContainer > xLibContainer = getLibraryContainer( _eType );
463 bHas = xLibContainer.is() && xLibContainer->hasByName( _rLibName );
464 }
465 catch( const Exception& )
466 {
467 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
468 }
469 return bHas;
470 }
471
472
474 {
476 try
477 {
478 Reference< XLibraryContainer > xLibContainer( getLibraryContainer( _eType ), UNO_SET_THROW );
479 if ( xLibContainer->hasByName( _rLibName ) )
480 xLibrary.set( xLibContainer->getByName( _rLibName ), UNO_QUERY_THROW );
481 else
482 xLibrary.set( xLibContainer->createLibrary( _rLibName ), UNO_SET_THROW );
483
484 if ( !xLibContainer->isLibraryLoaded( _rLibName ) )
485 xLibContainer->loadLibrary( _rLibName );
486 }
487 catch( const Exception& )
488 {
489 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
490 }
491 return xLibrary;
492 }
493
494
495 void ScriptDocument::Impl::loadLibraryIfExists( LibraryContainerType _eType, const OUString& _rLibrary )
496 {
497 try
498 {
499 Reference< XLibraryContainer > xLibContainer( getLibraryContainer( _eType ) );
500 if ( xLibContainer.is() && xLibContainer->hasByName( _rLibrary ) && !xLibContainer->isLibraryLoaded( _rLibrary ) )
501 xLibContainer->loadLibrary( _rLibrary );
502 }
503 catch( const Exception& )
504 {
505 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
506 }
507 }
508
509
510 bool ScriptDocument::Impl::removeModuleOrDialog( LibraryContainerType _eType, const OUString& _rLibName, const OUString& _rModuleName )
511 {
512 OSL_ENSURE( isValid(), "ScriptDocument::Impl::removeModuleOrDialog: invalid!" );
513 if ( !isValid() )
514 return false;
515 try
516 {
517 Reference< XNameContainer > xLib( getLibrary( _eType, _rLibName, true ) );
518 if ( xLib.is() )
519 {
520 xLib->removeByName( _rModuleName );
521 Reference< XVBAModuleInfo > xVBAModuleInfo(xLib, UNO_QUERY);
522 if(xVBAModuleInfo.is() && xVBAModuleInfo->hasModuleInfo(_rModuleName))
523 xVBAModuleInfo->removeModuleInfo(_rModuleName);
524 return true;
525 }
526 }
527 catch( const Exception& )
528 {
529 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
530 }
531 return false;
532 }
533
534
535 bool ScriptDocument::Impl::hasModuleOrDialog( LibraryContainerType _eType, const OUString& _rLibName, const OUString& _rModName ) const
536 {
537 OSL_ENSURE( isValid(), "ScriptDocument::Impl::hasModuleOrDialog: invalid!" );
538 if ( !isValid() )
539 return false;
540
541 try
542 {
543 Reference< XNameContainer > xLib( getLibrary( _eType, _rLibName, true ) );
544 if ( xLib.is() )
545 return xLib->hasByName( _rModName );
546 }
547 catch( const Exception& )
548 {
549 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
550 }
551 return false;
552 }
553
554
555 bool ScriptDocument::Impl::getModuleOrDialog( LibraryContainerType _eType, const OUString& _rLibName, const OUString& _rObjectName, Any& _out_rModuleOrDialog )
556 {
557 OSL_ENSURE( isValid(), "ScriptDocument::Impl::getModuleOrDialog: invalid!" );
558 if ( !isValid() )
559 return false;
560
561 _out_rModuleOrDialog.clear();
562 try
563 {
564 Reference< XNameContainer > xLib( getLibrary( _eType, _rLibName, true ), UNO_SET_THROW );
565 if ( xLib->hasByName( _rObjectName ) )
566 {
567 _out_rModuleOrDialog = xLib->getByName( _rObjectName );
568 return true;
569 }
570 }
571 catch( const Exception& )
572 {
573 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
574 }
575 return false;
576 }
577
578
580 const OUString& _rOldName, const OUString& _rNewName, const Reference< XNameContainer >& _rxExistingDialogModel )
581 {
582 OSL_ENSURE( isValid(), "ScriptDocument::Impl::renameModuleOrDialog: invalid!" );
583 if ( !isValid() )
584 return false;
585
586 try
587 {
588 Reference< XNameContainer > xLib( getLibrary( _eType, _rLibName, true ), UNO_SET_THROW );
589
590 // get element
591 Any aElement( xLib->getByName( _rOldName ) );
592
593 // remove element from container
594 xLib->removeByName( _rOldName );
595
596 // if it's a dialog, import and export, to reflect the new name
597 if ( _eType == E_DIALOGS )
598 {
599 // create dialog model
602 Reference< XNameContainer > xDialogModel;
603 if ( _rxExistingDialogModel.is() )
604 xDialogModel = _rxExistingDialogModel;
605 else
606 xDialogModel.set(
607 ( aContext->getServiceManager()->
608 createInstanceWithContext(
609 "com.sun.star.awt.UnoControlDialogModel",
610 aContext ) ),
611 UNO_QUERY_THROW );
612
613 // import dialog model
614 Reference< XInputStreamProvider > xISP( aElement, UNO_QUERY_THROW );
615 if ( !_rxExistingDialogModel.is() )
616 {
617 Reference< XInputStream > xInput( xISP->createInputStream(), UNO_SET_THROW );
618 ::xmlscript::importDialogModel( xInput, xDialogModel, aContext, isDocument() ? getDocument() : Reference< XModel >() );
619 }
620
621 // set new name as property
622 Reference< XPropertySet > xDlgPSet( xDialogModel, UNO_QUERY_THROW );
623 xDlgPSet->setPropertyValue( DLGED_PROP_NAME, Any( _rNewName ) );
624
625 // export dialog model
626 xISP = ::xmlscript::exportDialogModel( xDialogModel, aContext, isDocument() ? getDocument() : Reference< XModel >() );
627 aElement <<= xISP;
628 }
629
630 // insert element by new name in container
631 if ( _eType == E_SCRIPTS )
632 {
633 Reference< XVBAModuleInfo > xVBAModuleInfo( xLib, UNO_QUERY );
634 if ( xVBAModuleInfo.is() && xVBAModuleInfo->hasModuleInfo( _rOldName ) )
635 {
636 ModuleInfo sModuleInfo = xVBAModuleInfo->getModuleInfo( _rOldName );
637 xVBAModuleInfo->removeModuleInfo( _rOldName );
638 xVBAModuleInfo->insertModuleInfo( _rNewName, sModuleInfo );
639 }
640 }
641 xLib->insertByName( _rNewName, aElement );
642 return true;
643 }
644 catch( const Exception& )
645 {
646 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
647 }
648 return false;
649 }
650
651
652 bool ScriptDocument::Impl::createModule( const OUString& _rLibName, const OUString& _rModName, bool _bCreateMain, OUString& _out_rNewModuleCode ) const
653 {
654 _out_rNewModuleCode.clear();
655 try
656 {
657 Reference< XNameContainer > xLib( getLibrary( E_SCRIPTS, _rLibName, true ) );
658 if ( !xLib.is() || xLib->hasByName( _rModName ) )
659 return false;
660
661 // create new module
662 _out_rNewModuleCode = "REM ***** BASIC *****\n\n" ;
663 if ( _bCreateMain )
664 _out_rNewModuleCode += "Sub Main\n\nEnd Sub\n" ;
665
666 Reference< XVBAModuleInfo > xVBAModuleInfo(xLib, UNO_QUERY);
667 if (xVBAModuleInfo.is())
668 {
669 css::script::ModuleInfo aModuleInfo;
670 aModuleInfo.ModuleType = css::script::ModuleType::NORMAL;
671 xVBAModuleInfo->insertModuleInfo(_rModName, aModuleInfo);
672 }
673
674 // insert module into library
675 xLib->insertByName( _rModName, Any( _out_rNewModuleCode ) );
676 }
677 catch( const Exception& )
678 {
679 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
680 return false;
681 }
682
683 return true;
684 }
685
686
687 bool ScriptDocument::Impl::insertModuleOrDialog( LibraryContainerType _eType, const OUString& _rLibName, const OUString& _rObjectName, const Any& _rElement ) const
688 {
689 try
690 {
691 Reference< XNameContainer > xLib( getOrCreateLibrary( _eType, _rLibName ), UNO_SET_THROW );
692 if ( xLib->hasByName( _rObjectName ) )
693 return false;
694
695 xLib->insertByName( _rObjectName, _rElement );
696 return true;
697 }
698 catch( const Exception& )
699 {
700 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
701 }
702 return false;
703 }
704
705
706 bool ScriptDocument::Impl::updateModule( const OUString& _rLibName, const OUString& _rModName, const OUString& _rModuleCode ) const
707 {
708 try
709 {
710 Reference< XNameContainer > xLib( getOrCreateLibrary( E_SCRIPTS, _rLibName ), UNO_SET_THROW );
711 if ( !xLib->hasByName( _rModName ) )
712 return false;
713 xLib->replaceByName( _rModName, Any( _rModuleCode ) );
714 return true;
715 }
716 catch( const Exception& )
717 {
718 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
719 }
720 return false;
721 }
722
723
724 bool ScriptDocument::Impl::createDialog( const OUString& _rLibName, const OUString& _rDialogName, Reference< XInputStreamProvider >& _out_rDialogProvider ) const
725 {
726 try
727 {
728 Reference< XNameContainer > xLib( getLibrary( E_DIALOGS, _rLibName, true ), UNO_SET_THROW );
729
730 // create dialog
731 _out_rDialogProvider.clear();
732 if ( xLib->hasByName( _rDialogName ) )
733 return false;
734
735 // create new dialog model
738 Reference< XNameContainer > xDialogModel(
739 aContext->getServiceManager()->createInstanceWithContext(
740 "com.sun.star.awt.UnoControlDialogModel", aContext ),
741 UNO_QUERY_THROW );
742
743 // set name property
744 Reference< XPropertySet > xDlgPSet( xDialogModel, UNO_QUERY_THROW );
745 xDlgPSet->setPropertyValue( DLGED_PROP_NAME, Any( _rDialogName ) );
746
747 // export dialog model
748 _out_rDialogProvider = ::xmlscript::exportDialogModel( xDialogModel, aContext, isDocument() ? getDocument() : Reference< XModel >() );
749
750 // insert dialog into library
751 xLib->insertByName( _rDialogName, Any( _out_rDialogProvider ) );
752 }
753 catch( const Exception& )
754 {
755 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
756 }
757
758 return _out_rDialogProvider.is();
759 }
760
761
763 {
764 OSL_ENSURE( isValid() && isDocument(), "ScriptDocument::Impl::setDocumentModified: only to be called for real documents!" );
765 if ( isValid() && isDocument() )
766 {
767 try
768 {
769 m_xDocModify->setModified( true );
770 }
771 catch( const Exception& )
772 {
773 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
774 }
775 }
776 }
777
778
780 {
781 OSL_ENSURE( isValid() && isDocument(), "ScriptDocument::Impl::isDocumentModified: only to be called for real documents!" );
782 bool bIsModified = false;
783 if ( isValid() && isDocument() )
784 {
785 try
786 {
787 bIsModified = m_xDocModify->isModified();
788 }
789 catch( const Exception& )
790 {
791 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
792 }
793 }
794 return bIsModified;
795 }
796
797
799 {
801 if ( !getCurrentFrame( xFrame ) )
802 return;
803
805 if ( _rxStatusIndicator.is() )
806 {
807 aArgs = ::comphelper::InitPropertySequence({
808 { "StatusIndicator", Any(_rxStatusIndicator) }
809 });
810 }
811
812 try
813 {
814 URL aURL;
815 aURL.Complete = ".uno:Save" ;
816 aURL.Main = aURL.Complete;
817 aURL.Protocol = ".uno:" ;
818 aURL.Path = "Save" ;
819
820 Reference< XDispatchProvider > xDispProv( xFrame, UNO_QUERY_THROW );
822 xDispProv->queryDispatch( aURL, "_self", FrameSearchFlag::AUTO ),
823 UNO_SET_THROW );
824
825 xDispatch->dispatch( aURL, aArgs );
826 }
827 catch( const Exception& )
828 {
829 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
830 }
831 }
832
833
835 {
836 OSL_PRECOND( isValid() && isDocument(), "ScriptDocument::Impl::getTitle: for documents only!" );
837
838 OUString sTitle;
839 if ( isValid() && isDocument() )
840 {
841 sTitle = ::comphelper::DocumentInfo::getDocumentTitle( m_xDocument );
842 }
843 return sTitle;
844 }
845
846
848 {
849 OSL_PRECOND( isValid() && isDocument(), "ScriptDocument::Impl::getURL: for documents only!" );
850
851 OUString sURL;
852 if ( isValid() && isDocument() )
853 {
854 try
855 {
856 sURL = m_xDocument->getURL();
857 }
858 catch( const Exception& )
859 {
860 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
861 }
862 }
863 return sURL;
864 }
865
866
868 {
869 OSL_ENSURE( isValid() && isDocument(), "ScriptDocument::Impl::allowMacros: for documents only!" );
870 bool bAllow = false;
871 if ( isValid() && isDocument() )
872 {
873 try
874 {
875 bAllow = m_xScriptAccess->getAllowMacroExecution();
876 }
877 catch( const Exception& )
878 {
879 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
880 }
881 }
882 return bAllow;
883 }
884
885
887 {
888 _out_rxFrame.clear();
889 OSL_PRECOND( isValid() && isDocument(), "ScriptDocument::Impl::getCurrentFrame: documents only!" );
890 if ( !isValid() || !isDocument() )
891 return false;
892
893 try
894 {
895 Reference< XModel > xDocument( m_xDocument, UNO_SET_THROW );
896 Reference< XController > xController( xDocument->getCurrentController(), UNO_SET_THROW );
897 _out_rxFrame.set( xController->getFrame(), UNO_SET_THROW );
898 }
899 catch( const Exception& )
900 {
901 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
902 }
903
904 return _out_rxFrame.is();
905 }
906
907
908 bool ScriptDocument::Impl::isLibraryShared( const OUString& _rLibName, LibraryContainerType _eType )
909 {
910 bool bIsShared = false;
911 try
912 {
913 Reference< XLibraryContainer2 > xLibContainer( getLibraryContainer( _eType ), UNO_QUERY_THROW );
914
915 if ( !xLibContainer->hasByName( _rLibName ) || !xLibContainer->isLibraryLink( _rLibName ) )
916 return false;
917 OUString aFileURL;
918 Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
919 Reference< XUriReferenceFactory > xUriFac = UriReferenceFactory::create(xContext);
920
921 OUString aLinkURL( xLibContainer->getLibraryLinkURL( _rLibName ) );
922 Reference< XUriReference > xUriRef( xUriFac->parse( aLinkURL ), UNO_SET_THROW );
923
924 OUString aScheme = xUriRef->getScheme();
925 if ( aScheme.equalsIgnoreAsciiCase("file") )
926 {
927 aFileURL = aLinkURL;
928 }
929 else if ( aScheme.equalsIgnoreAsciiCase("vnd.sun.star.pkg") )
930 {
931 OUString aDecodedURL = xUriRef->getAuthority();
932 if (aDecodedURL.startsWithIgnoreAsciiCase("vnd.sun.star.expand:", &aDecodedURL))
933 {
934 aDecodedURL = ::rtl::Uri::decode( aDecodedURL, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 );
935 Reference< XMacroExpander > xMacroExpander = theMacroExpander::get(xContext);
936 aFileURL = xMacroExpander->expandMacros( aDecodedURL );
937 }
938 }
939
940 if ( !aFileURL.isEmpty() )
941 {
942 ::osl::DirectoryItem aFileItem;
943 ::osl::FileStatus aFileStatus( osl_FileStatus_Mask_FileURL );
944 OSL_VERIFY( ::osl::DirectoryItem::get( aFileURL, aFileItem ) == ::osl::FileBase::E_None );
945 OSL_VERIFY( aFileItem.getFileStatus( aFileStatus ) == ::osl::FileBase::E_None );
946 OUString aCanonicalFileURL( aFileStatus.getFileURL() );
947
948 if( aCanonicalFileURL.indexOf( LIBO_SHARE_FOLDER "/basic" ) >= 0 ||
949 aCanonicalFileURL.indexOf( LIBO_SHARE_FOLDER "/uno_packages" ) >= 0 ||
950 aCanonicalFileURL.indexOf( LIBO_SHARE_FOLDER "/extensions" ) >= 0 )
951 bIsShared = true;
952 }
953 }
954 catch( const Exception& )
955 {
956 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
957 }
958
959 return bIsShared;
960 }
961
962
964 {
965 // not interested in
966 }
967
969 {
970 // not interested in
971 }
972
974 {
975 // not interested in
976 }
977
979 {
980 // not interested in
981 }
982
984 {
985 // not interested in
986 }
987
989 {
990 // not interested in
991 }
992
994 {
996 OSL_PRECOND( isValid(), "ScriptDocument::Impl::onDocumentClosed: should not be listening if I'm not valid!" );
997
998 bool bMyDocument = m_xDocument == _rDocument.getDocument();
999 OSL_PRECOND( bMyDocument, "ScriptDocument::Impl::onDocumentClosed: didn't want to know *this*!" );
1000 if ( bMyDocument )
1001 {
1002 m_bDocumentClosed = true;
1003 }
1004 }
1005
1006
1008 {
1009 // not interested in
1010 }
1011
1013 {
1014 // not interested in
1015 }
1016
1017
1020 { }
1021
1022
1024 :m_pImpl( std::make_shared<Impl>( Reference< XModel >() ) )
1025 {
1026 OSL_ENSURE( _eType == NoDocument, "ScriptDocument::ScriptDocument: unknown SpecialDocument type!" );
1027 }
1028
1029
1031 :m_pImpl( std::make_shared<Impl>( _rxDocument ) )
1032 {
1033 OSL_ENSURE( _rxDocument.is(), "ScriptDocument::ScriptDocument: document must not be NULL!" );
1034 // a NULL document results in an uninitialized instance, and for this
1035 // purpose, there is a dedicated constructor
1036 }
1037
1038
1040 {
1041 static ScriptDocument s_aApplicationScripts;
1042 return s_aApplicationScripts;
1043 }
1044
1045
1047 {
1048 if ( _pManager == SfxApplication::GetBasicManager() )
1050
1051 docs::Documents aDocuments;
1052 lcl_getAllModels_throw( aDocuments, false );
1053
1054 for (auto const& doc : aDocuments)
1055 {
1056 const BasicManager* pDocBasicManager = ::basic::BasicManagerRepository::getDocumentBasicManager( doc.xModel );
1057 if ( ( pDocBasicManager != SfxApplication::GetBasicManager() )
1058 && ( pDocBasicManager == _pManager )
1059 )
1060 {
1061 return ScriptDocument( doc.xModel );
1062 }
1063 }
1064
1065 OSL_FAIL( "ScriptDocument::getDocumentForBasicManager: did not find a document for this manager!" );
1066 return ScriptDocument( NoDocument );
1067 }
1068
1069
1071 {
1073 if ( _rUrlOrCaption.empty() )
1074 return aDocument;
1075
1076 docs::Documents aDocuments;
1077 lcl_getAllModels_throw( aDocuments, false );
1078
1079 for (auto const& doc : aDocuments)
1080 {
1081 const ScriptDocument aCheck( doc.xModel );
1082 if ( _rUrlOrCaption == aCheck.getTitle()
1083 || _rUrlOrCaption == aCheck.m_pImpl->getURL()
1084 )
1085 {
1086 aDocument = aCheck;
1087 break;
1088 }
1089 }
1090
1091 return aDocument;
1092 }
1093
1095 {
1096 ScriptDocuments aScriptDocs;
1097
1098 // include application?
1099 if ( _eListType == AllWithApplication )
1100 aScriptDocs.push_back( getApplicationScriptDocument() );
1101
1102 // obtain documents
1103 try
1104 {
1105 docs::Documents aDocuments;
1106 lcl_getAllModels_throw( aDocuments, true /* exclude invisible */ );
1107
1108 for (auto const& doc : aDocuments)
1109 {
1110 // exclude documents without script/library containers
1111 ScriptDocument aDoc( doc.xModel );
1112 if ( !aDoc.isValid() )
1113 continue;
1114
1115 aScriptDocs.push_back( aDoc );
1116 }
1117 }
1118 catch( const Exception& )
1119 {
1120 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
1121 }
1122
1123 // sort document list by doc title?
1124 if ( _eListType == DocumentsSorted )
1125 {
1128 Application::GetSettings().GetUILanguageTag().getLocale());
1129 std::sort(aScriptDocs.begin(), aScriptDocs.end(),
1130 [&sort](const ScriptDocument& rLHS, const ScriptDocument& rRHS) {
1131 return sort.compare(rLHS.getTitle(), rRHS.getTitle()) < 0;
1132 });
1133 }
1134
1135 return aScriptDocs;
1136 }
1137
1138
1140 {
1141 return m_pImpl->getDocumentRef() == _rhs.m_pImpl->getDocumentRef();
1142 }
1143
1144
1146 {
1147 return sal::static_int_cast<sal_Int32>(reinterpret_cast< sal_IntPtr >( m_pImpl->getDocumentRef().get() ));
1148 }
1149
1150
1152 {
1153 return m_pImpl->isValid();
1154 }
1155
1156
1158 {
1159 return m_pImpl->isAlive();
1160 }
1161
1162
1164 {
1165 return m_pImpl->getLibraryContainer( _eType );
1166 }
1167
1168
1169 Reference< XNameContainer > ScriptDocument::getLibrary( LibraryContainerType _eType, const OUString& _rLibName, bool _bLoadLibrary ) const
1170 {
1171 return m_pImpl->getLibrary( _eType, _rLibName, _bLoadLibrary );
1172 }
1173
1174
1175 bool ScriptDocument::hasLibrary( LibraryContainerType _eType, const OUString& _rLibName ) const
1176 {
1177 return m_pImpl->hasLibrary( _eType, _rLibName );
1178 }
1179
1180
1182 {
1183 return m_pImpl->getOrCreateLibrary( _eType, _rLibName );
1184 }
1185
1186
1187 void ScriptDocument::loadLibraryIfExists( LibraryContainerType _eType, const OUString& _rLibrary )
1188 {
1189 m_pImpl->loadLibraryIfExists( _eType, _rLibrary );
1190 }
1191
1192
1194 {
1195 Sequence< OUString > aModuleNames;
1196
1197 try
1198 {
1199 if ( hasLibrary( _eType, _rLibName ) )
1200 {
1201 Reference< XNameContainer > xLib( getLibrary( _eType, _rLibName, false ) );
1202 if ( xLib.is() )
1203 aModuleNames = xLib->getElementNames();
1204 }
1205 }
1206 catch( const Exception& )
1207 {
1208 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
1209 }
1210
1211 // sort
1214 Application::GetSettings().GetUILanguageTag().getLocale());
1215 auto [begin, end] = asNonConstRange(aModuleNames);
1216 std::sort(begin, end,
1217 [&sort](const OUString& rLHS, const OUString& rRHS) {
1218 return sort.compare(rLHS, rRHS) < 0;
1219 });
1220 return aModuleNames;
1221 }
1222
1223
1224 OUString ScriptDocument::createObjectName( LibraryContainerType _eType, const OUString& _rLibName ) const
1225 {
1226 OUString aObjectName;
1227
1228 OUString aBaseName = _eType == E_SCRIPTS ? OUString("Module") : OUString("Dialog");
1229
1230 const Sequence< OUString > aUsedNames( getObjectNames( _eType, _rLibName ) );
1231 std::set< OUString > aUsedNamesCheck( aUsedNames.begin(), aUsedNames.end() );
1232
1233 bool bValid = false;
1234 sal_Int32 i = 1;
1235 while ( !bValid )
1236 {
1237 aObjectName = aBaseName
1238 + OUString::number( i );
1239
1240 if ( aUsedNamesCheck.find( aObjectName ) == aUsedNamesCheck.end() )
1241 bValid = true;
1242
1243 ++i;
1244 }
1245
1246 return aObjectName;
1247 }
1248
1249
1251 {
1253 }
1254
1255
1257 {
1258 return m_pImpl->isReadOnly();
1259 }
1260
1261
1263 {
1264 return m_pImpl->isApplication();
1265 }
1266
1268 {
1269 return m_pImpl->isInVBAMode();
1270 }
1271
1272
1274 {
1275 return m_pImpl->getBasicManager();
1276 }
1277
1278
1280 {
1281 return m_pImpl->getDocument();
1282 }
1283
1284
1286 {
1287 if ( isDocument() )
1288 return m_pImpl->getDocument();
1289 return nullptr;
1290 }
1291
1292
1293 bool ScriptDocument::removeModule( const OUString& _rLibName, const OUString& _rModuleName ) const
1294 {
1295 return m_pImpl->removeModuleOrDialog( E_SCRIPTS, _rLibName, _rModuleName );
1296 }
1297
1298
1299 bool ScriptDocument::hasModule( const OUString& _rLibName, const OUString& _rModuleName ) const
1300 {
1301 return m_pImpl->hasModuleOrDialog( E_SCRIPTS, _rLibName, _rModuleName );
1302 }
1303
1304
1305 bool ScriptDocument::getModule( const OUString& _rLibName, const OUString& _rModName, OUString& _out_rModuleSource ) const
1306 {
1307 Any aCode;
1308 if ( !m_pImpl->getModuleOrDialog( E_SCRIPTS, _rLibName, _rModName, aCode ) )
1309 return false;
1310 OSL_VERIFY( aCode >>= _out_rModuleSource );
1311 return true;
1312 }
1313
1314
1315 bool ScriptDocument::renameModule( const OUString& _rLibName, const OUString& _rOldName, const OUString& _rNewName ) const
1316 {
1317 return m_pImpl->renameModuleOrDialog( E_SCRIPTS, _rLibName, _rOldName, _rNewName, nullptr );
1318 }
1319
1320
1321 bool ScriptDocument::createModule( const OUString& _rLibName, const OUString& _rModName, bool _bCreateMain, OUString& _out_rNewModuleCode ) const
1322 {
1323 if ( !m_pImpl->createModule( _rLibName, _rModName, _bCreateMain, _out_rNewModuleCode ) )
1324 return false;
1325
1326 // doc shell modified
1327 MarkDocumentModified( *const_cast< ScriptDocument* >( this ) ); // here?
1328 return true;
1329 }
1330
1331
1332 bool ScriptDocument::insertModule( const OUString& _rLibName, const OUString& _rModName, const OUString& _rModuleCode ) const
1333 {
1334 return m_pImpl->insertModuleOrDialog( E_SCRIPTS, _rLibName, _rModName, Any( _rModuleCode ) );
1335 }
1336
1337
1338 bool ScriptDocument::updateModule( const OUString& _rLibName, const OUString& _rModName, const OUString& _rModuleCode ) const
1339 {
1340 return m_pImpl->updateModule( _rLibName, _rModName, _rModuleCode );
1341 }
1342
1343
1344 bool ScriptDocument::removeDialog( const OUString& _rLibName, const OUString& _rDialogName ) const
1345 {
1346 return m_pImpl->removeModuleOrDialog( E_DIALOGS, _rLibName, _rDialogName );
1347 }
1348
1349
1350 bool ScriptDocument::hasDialog( const OUString& _rLibName, const OUString& _rDialogName ) const
1351 {
1352 return m_pImpl->hasModuleOrDialog( E_DIALOGS, _rLibName, _rDialogName );
1353 }
1354
1355
1356 bool ScriptDocument::getDialog( const OUString& _rLibName, const OUString& _rDialogName, Reference< XInputStreamProvider >& _out_rDialogProvider ) const
1357 {
1358 Any aCode;
1359 if ( !m_pImpl->getModuleOrDialog( E_DIALOGS, _rLibName, _rDialogName, aCode ) )
1360 return false;
1361 OSL_VERIFY( aCode >>= _out_rDialogProvider );
1362 return _out_rDialogProvider.is();
1363 }
1364
1365
1366 bool ScriptDocument::renameDialog( const OUString& _rLibName, const OUString& _rOldName, const OUString& _rNewName, const Reference< XNameContainer >& _rxExistingDialogModel ) const
1367 {
1368 return m_pImpl->renameModuleOrDialog( E_DIALOGS, _rLibName, _rOldName, _rNewName, _rxExistingDialogModel );
1369 }
1370
1371
1372 bool ScriptDocument::createDialog( const OUString& _rLibName, const OUString& _rDialogName, Reference< XInputStreamProvider >& _out_rDialogProvider ) const
1373 {
1374 if ( !m_pImpl->createDialog( _rLibName, _rDialogName, _out_rDialogProvider ) )
1375 return false;
1376
1377 MarkDocumentModified( *const_cast< ScriptDocument* >( this ) ); // here?
1378 return true;
1379 }
1380
1381
1382 bool ScriptDocument::insertDialog( const OUString& _rLibName, const OUString& _rDialogName, const Reference< XInputStreamProvider >& _rxDialogProvider ) const
1383 {
1384 return m_pImpl->insertModuleOrDialog( E_DIALOGS, _rLibName, _rDialogName, Any( _rxDialogProvider ) );
1385 }
1386
1387
1389 {
1390 m_pImpl->setDocumentModified();
1391 }
1392
1393
1395 {
1396 return m_pImpl->isDocumentModified();
1397 }
1398
1399
1400 void ScriptDocument::saveDocument( const Reference< XStatusIndicator >& _rxStatusIndicator ) const
1401 {
1402 m_pImpl->saveDocument( _rxStatusIndicator );
1403 }
1404
1405
1406 LibraryLocation ScriptDocument::getLibraryLocation( const OUString& _rLibName ) const
1407 {
1409 if ( !_rLibName.isEmpty() )
1410 {
1411 if ( isDocument() )
1412 {
1413 eLocation = LIBRARY_LOCATION_DOCUMENT;
1414 }
1415 else
1416 {
1417 if ( ( hasLibrary( E_SCRIPTS, _rLibName ) && !m_pImpl->isLibraryShared( _rLibName, E_SCRIPTS ) )
1418 || ( hasLibrary( E_DIALOGS, _rLibName ) && !m_pImpl->isLibraryShared( _rLibName, E_DIALOGS ) )
1419 )
1420 {
1421 eLocation = LIBRARY_LOCATION_USER;
1422 }
1423 else
1424 {
1425 eLocation = LIBRARY_LOCATION_SHARE;
1426 }
1427 }
1428 }
1429
1430 return eLocation;
1431 }
1432
1433
1434 OUString ScriptDocument::getTitle( LibraryLocation _eLocation, LibraryType _eType ) const
1435 {
1436 OUString aTitle;
1437
1438 switch ( _eLocation )
1439 {
1441 {
1442 switch ( _eType )
1443 {
1444 case LibraryType::Module: aTitle = IDEResId(RID_STR_USERMACROS); break;
1445 case LibraryType::Dialog: aTitle = IDEResId(RID_STR_USERDIALOGS); break;
1446 case LibraryType::All: aTitle = IDEResId(RID_STR_USERMACROSDIALOGS); break;
1447 default:
1448 break;
1449 }
1450 }
1451 break;
1453 {
1454 switch ( _eType )
1455 {
1456 case LibraryType::Module: aTitle = IDEResId(RID_STR_SHAREMACROS); break;
1457 case LibraryType::Dialog: aTitle = IDEResId(RID_STR_SHAREDIALOGS); break;
1458 case LibraryType::All: aTitle = IDEResId(RID_STR_SHAREMACROSDIALOGS); break;
1459 default:
1460 break;
1461 }
1462 }
1463 break;
1465 aTitle = getTitle();
1466 break;
1467 default:
1468 break;
1469 }
1470
1471 return aTitle;
1472 }
1473
1474
1476 {
1477 return m_pImpl->getTitle();
1478 }
1479
1480
1482 {
1483 bool bIsActive( false );
1484 try
1485 {
1487 if ( m_pImpl->getCurrentFrame( xFrame ) )
1488 bIsActive = xFrame->isActive();
1489 }
1490 catch( const Exception& )
1491 {
1492 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
1493 }
1494 return bIsActive;
1495 }
1496
1497
1499 {
1500 return m_pImpl->allowMacros();
1501 }
1502
1503} // namespace basctl
1504
1505/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::std::unique_ptr< XmlIdRegistry_Impl > m_pImpl
SfxApplication * SfxGetpApp()
ScriptDocument aDocument
Definition: basobj2.cxx:194
static const AllSettings & GetSettings()
static BasicManager * GetBasicManager()
allows registering at theGlobalEventBroadcaster for global document events
virtual void onDocumentSaveAs(const ScriptDocument &_rDocument) override
virtual void onDocumentOpened(const ScriptDocument &_rDocument) override
bool createModule(const OUString &_rLibName, const OUString &_rModName, bool _bCreateMain, OUString &_out_rNewModuleCode) const
virtual void onDocumentModeChanged(const ScriptDocument &_rDocument) override
virtual void onDocumentSaveDone(const ScriptDocument &_rDocument) override
Reference< XNameContainer > getOrCreateLibrary(LibraryContainerType _eType, const OUString &_rLibName) const
bool hasLibrary(LibraryContainerType _eType, const OUString &_rLibName) const
bool hasModuleOrDialog(LibraryContainerType _eType, const OUString &_rLibName, const OUString &_rModName) const
void saveDocument(const Reference< XStatusIndicator > &_rxStatusIndicator) const
bool createDialog(const OUString &_rLibName, const OUString &_rDialogName, Reference< XInputStreamProvider > &_out_rDialogProvider) const
Reference< XModel > getDocument() const
Reference< XLibraryContainer > getLibraryContainer(LibraryContainerType _eType) const
returns a library container belonging to the document
Reference< XModifiable > m_xDocModify
bool isValid() const
determines whether the instance refers to a valid "document" with script and dialog libraries
Reference< XEmbeddedScripts > m_xScriptAccess
virtual void onDocumentClosed(const ScriptDocument &_rDocument) override
bool impl_initDocument_nothrow(const Reference< XModel > &_rxModel)
bool renameModuleOrDialog(LibraryContainerType _eType, const OUString &_rLibName, const OUString &_rOldName, const OUString &_rNewName, const Reference< XNameContainer > &_rxExistingDialogModel)
virtual void onDocumentSave(const ScriptDocument &_rDocument) override
bool isAlive() const
determines whether the instance refers to a non-closed document
bool removeModuleOrDialog(LibraryContainerType _eType, const OUString &_rLibName, const OUString &_rModuleName)
bool insertModuleOrDialog(LibraryContainerType _eType, const OUString &_rObjectName, const OUString &_rModName, const Any &_rElement) const
void invalidate()
invalidates the instance
BasicManager * getBasicManager() const
bool isApplication() const
determines whether the "document" refers to the application in real
bool updateModule(const OUString &_rLibName, const OUString &_rModName, const OUString &_rModuleCode) const
bool isDocument() const
determines whether the document refers to a real document (instead of the application)
bool isLibraryShared(const OUString &_rLibName, LibraryContainerType _eType)
determines whether a given library is part of the shared installation
virtual void onDocumentSaveAsDone(const ScriptDocument &_rDocument) override
virtual void onDocumentTitleChanged(const ScriptDocument &_rDocument) override
virtual void onDocumentCreated(const ScriptDocument &_rDocument) override
void loadLibraryIfExists(LibraryContainerType _eType, const OUString &_rLibrary)
std::unique_ptr< DocumentEventNotifier > m_pDocListener
Reference< XModel > m_xDocument
const Reference< XModel > & getDocumentRef() const
bool getModuleOrDialog(LibraryContainerType _eType, const OUString &_rLibName, const OUString &_rObjectName, Any &_out_rModuleOrDialog)
Reference< XNameContainer > getLibrary(LibraryContainerType _eType, const OUString &_rLibName, bool _bLoadLibrary) const
bool getCurrentFrame(Reference< XFrame > &_out_rxFrame) const
returns the current frame of the document
encapsulates a document which contains Basic scripts and dialogs
css::uno::Reference< css::container::XNameContainer > getOrCreateLibrary(LibraryContainerType _eType, const OUString &_rLibName) const
creates a script or dialog library in the document, or returns an existing one
OUString getTitle(LibraryLocation _eLocation, LibraryType _eType=LibraryType::All) const
returns the title for the document
bool getModule(const OUString &_rLibName, const OUString &_rModName, OUString &_rModuleSource) const
retrieves a module's source
sal_Int32 hashCode() const
retrieves a (pretty simple) hash code for the document
bool insertModule(const OUString &_rLibName, const OUString &_rModName, const OUString &_rModuleCode) const
inserts a given piece as code as module
bool renameDialog(const OUString &_rLibName, const OUString &_rOldName, const OUString &_rNewName, const css::uno::Reference< css::container::XNameContainer > &_rxExistingDialogModel) const
renames a dialog
bool allowMacros() const
determines whether macro execution for this document is allowed
bool hasLibrary(LibraryContainerType _eType, const OUString &_rLibName) const
determines whether there exists a library of the given type, with the given name
css::uno::Reference< css::script::XLibraryContainer > getLibraryContainer(LibraryContainerType _eType) const
returns the Basic or Dialog library container of the document
bool isDocumentModified() const
determines whether the document is modified @precond the instance operates on a real document,...
bool removeModule(const OUString &_rLibName, const OUString &_rModuleName) const
removes a given script module from the document
css::uno::Reference< css::frame::XModel > getDocumentOrNull() const
returns the UNO component representing the document which the instance operates on
bool getDialog(const OUString &_rLibName, const OUString &_rDialogName, css::uno::Reference< css::io::XInputStreamProvider > &_out_rDialogProvider) const
retrieves a dialog
css::uno::Reference< css::frame::XModel > getDocument() const
returns the UNO component representing the document which the instance operates on
bool isDocument() const
determines whether the ScriptDocument instance operates on a real document, as opposed to the whole a...
BasicManager * getBasicManager() const
returns the BasicManager associated with this instance
ScriptDocumentList
operation mode for getAllScriptDocuments
@ AllWithApplication
all ScriptDocuments, including the dedicated one which represents the application-wide scripts/dialog...
@ DocumentsSorted
real documents only, sorted lexicographically by their title (using the sys locale's default collator...
static ScriptDocuments getAllScriptDocuments(ScriptDocumentList _eListType)
returns the set of ScriptDocument instances, one for each open document which contains Basic/Dialog c...
ScriptDocument()
creates a ScriptDocument instance which operates on the application-wide scripts and dialogs
bool removeDialog(const OUString &_rLibName, const OUString &_rDialogName) const
removes a given dialog from the document
bool updateModule(const OUString &_rLibName, const OUString &_rModName, const OUString &_rModuleCode) const
updates a given module with new code
static const ScriptDocument & getApplicationScriptDocument()
returns a reference to a shared ScriptDocument instance which operates on the application-wide script...
css::uno::Reference< css::container::XNameContainer > getLibrary(LibraryContainerType _eType, const OUString &_rLibName, bool _bLoadLibrary) const
returns a script or dialog library given by name
std::shared_ptr< Impl > m_pImpl
bool isReadOnly() const
determines whether the document is read-only
static ScriptDocument getDocumentForBasicManager(const BasicManager *_pManager)
returns a (newly created) ScriptDocument instance for the document to which a given BasicManager belo...
bool createModule(const OUString &_rLibName, const OUString &_rModName, bool _bCreateMain, OUString &_out_rNewModuleCode) const
creates a module with the given name in the given library
bool renameModule(const OUString &_rLibName, const OUString &_rOldName, const OUString &_rNewName) const
renames a module
bool isAlive() const
determines whether the document instance is alive
static ScriptDocument getDocumentWithURLOrCaption(std::u16string_view _rUrlOrCaption)
returns a (newly created) ScriptDocument instance for the document with a given caption or URL
void saveDocument(const css::uno::Reference< css::task::XStatusIndicator > &_rxStatusIndicator) const
saves the document, if the instance refers to a real document @precond isApplication returns <FALSE>
void setDocumentModified() const
marks the document as modified @precond the instance operates on a real document, not on the applicat...
bool insertDialog(const OUString &_rLibName, const OUString &_rDialogName, const css::uno::Reference< css::io::XInputStreamProvider > &_rDialogProvider) const
inserts a given dialog into a given library
css::uno::Sequence< OUString > getLibraryNames() const
retrieves the (combined) names of all script and dialog libraries
OUString getTitle() const
returns the title of the document
bool operator==(const ScriptDocument &_rhs) const
bool isActive() const
determines whether the document is currently the one-and-only application-wide active document
bool hasDialog(const OUString &_rLibName, const OUString &_rDialogName) const
determines whether a dialog with the given name exists in the given library
css::uno::Sequence< OUString > getObjectNames(LibraryContainerType _eType, const OUString &_rLibName) const
returns the names of the modules in a given script or dialog library of the document
bool hasModule(const OUString &_rLibName, const OUString &_rModName) const
determines whether a module with the given name exists in the given library
void loadLibraryIfExists(LibraryContainerType _eType, const OUString &_rLibrary)
loads a script or dialog library given by name, if there is such a library
bool createDialog(const OUString &_rLibName, const OUString &_rDialogName, css::uno::Reference< css::io::XInputStreamProvider > &_out_rDialogProvider) const
create a dialog
LibraryLocation getLibraryLocation(const OUString &_rLibName) const
returns the location of a library given by name
bool isApplication() const
determines whether the ScriptDocument instance operates on the whole application, as opposed to a rea...
bool isValid() const
determines whether the document is actually able to contain Basic/Dialog libraries
OUString createObjectName(LibraryContainerType _eType, const OUString &_rLibName) const
retrieves a name for a newly to be created module or dialog
static BasicManager * getDocumentBasicManager(const css::uno::Reference< css::frame::XModel > &_rxDocumentModel)
Reference< XOfficeDatabaseDocument > m_xDocument
#define DBG_TESTSOLARMUTEX()
#define TOOLS_WARN_EXCEPTION(area, stream)
#define DBG_UNHANDLED_EXCEPTION(...)
Reference< XDispatch > xDispatch
URL aURL
std::vector< DocumentDescriptor > Documents
constexpr OUStringLiteral DLGED_PROP_NAME
Definition: dlgeddef.hxx:33
@ LIBRARY_LOCATION_USER
@ LIBRARY_LOCATION_UNKNOWN
@ LIBRARY_LOCATION_SHARE
@ LIBRARY_LOCATION_DOCUMENT
void MarkDocumentModified(const ScriptDocument &rDocument)
Definition: basobj3.cxx:249
std::vector< ScriptDocument > ScriptDocuments
Sequence< OUString > GetMergedLibraryNames(const Reference< script::XLibraryContainer > &xModLibContainer, const Reference< script::XLibraryContainer > &xDlgLibContainer)
Definition: basobj2.cxx:98
OUString IDEResId(TranslateId aId)
Definition: iderdll.cxx:108
@ Exception
const LanguageTag & getLocale()
Reference< XComponentContext > getProcessComponentContext()
int i
std::shared_ptr< T > make_shared(Args &&... args)
enumrange< T >::Iterator begin(enumrange< T >)
end
bool m_bFilterInvisible
Reference< XController > xController
Reference< XFrame > xFrame