LibreOffice Module basctl (master) 1
scriptdocument.hxx
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#pragma once
21
22#include <com/sun/star/script/XLibraryContainer.hpp>
23#include <com/sun/star/frame/XModel.hpp>
24#include <com/sun/star/task/XStatusIndicator.hpp>
25#include <com/sun/star/io/XInputStreamProvider.hpp>
26
27#include <memory>
28#include <vector>
29
30class SfxListener;
31
32class BasicManager;
33
34
35namespace basctl
36{
37
39 {
42 };
43
45 {
50 };
51
52 enum class LibraryType
53 {
54 Module,
55 Dialog,
56 All
57 };
58
59 class ScriptDocument;
60 typedef std::vector< ScriptDocument > ScriptDocuments;
61
65 {
66 private:
67 class Impl;
68 std::shared_ptr<Impl> m_pImpl;
69
70 private:
75
76 public:
88 explicit ScriptDocument( SpecialDocument _eType );
89
96 explicit ScriptDocument( const css::uno::Reference< css::frame::XModel >& _rxDocument );
97
101 static const ScriptDocument&
103
112 static ScriptDocument
113 getDocumentForBasicManager( const BasicManager* _pManager );
114
123 static ScriptDocument
124 getDocumentWithURLOrCaption( std::u16string_view _rUrlOrCaption );
125
129 {
138 };
139
150 static ScriptDocuments
152
153 // comparison
154 bool operator==( const ScriptDocument& _rhs ) const;
155 bool operator!=( const ScriptDocument& _rhs ) const { return !( *this == _rhs ); }
156
158 sal_Int32 hashCode() const;
159
172 bool isValid() const;
173
185 bool isAlive() const;
186
187 bool isInVBAMode() const;
190 getBasicManager() const;
191
197 css::uno::Reference< css::frame::XModel >
198 getDocument() const;
199
205 css::uno::Reference< css::frame::XModel >
206 getDocumentOrNull() const;
207
212 css::uno::Reference< css::script::XLibraryContainer >
214
217 bool hasLibrary( LibraryContainerType _eType, const OUString& _rLibName ) const;
218
231 css::uno::Reference< css::container::XNameContainer >
232 getLibrary( LibraryContainerType _eType, const OUString& _rLibName, bool _bLoadLibrary ) const;
233
239 css::uno::Reference< css::container::XNameContainer >
240 getOrCreateLibrary( LibraryContainerType _eType, const OUString& _rLibName ) const;
241
244 css::uno::Sequence< OUString >
245 getObjectNames( LibraryContainerType _eType, const OUString& _rLibName ) const;
246
249 OUString createObjectName( LibraryContainerType _eType, const OUString& _rLibName ) const;
250
253 void loadLibraryIfExists( LibraryContainerType _eType, const OUString& _rLibrary );
254
256 css::uno::Sequence< OUString >
257 getLibraryNames() const;
258
265 bool removeModule( const OUString& _rLibName, const OUString& _rModuleName ) const;
266
279 bool createModule( const OUString& _rLibName, const OUString& _rModName, bool _bCreateMain, OUString& _out_rNewModuleCode ) const;
280
293 bool insertModule( const OUString& _rLibName, const OUString& _rModName, const OUString& _rModuleCode ) const;
294
305 bool updateModule( const OUString& _rLibName, const OUString& _rModName, const OUString& _rModuleCode ) const;
306
308 bool hasModule( const OUString& _rLibName, const OUString& _rModName ) const;
309
320 bool getModule( const OUString& _rLibName, const OUString& _rModName, OUString& _rModuleSource ) const;
321
332 bool renameModule( const OUString& _rLibName, const OUString& _rOldName, const OUString& _rNewName ) const;
333
340 bool removeDialog( const OUString& _rLibName, const OUString& _rDialogName ) const;
341
343 bool hasDialog( const OUString& _rLibName, const OUString& _rDialogName ) const;
344
355 bool getDialog(
356 const OUString& _rLibName,
357 const OUString& _rDialogName,
358 css::uno::Reference< css::io::XInputStreamProvider >& _out_rDialogProvider
359 ) const;
360
373 bool renameDialog(
374 const OUString& _rLibName,
375 const OUString& _rOldName,
376 const OUString& _rNewName,
377 const css::uno::Reference< css::container::XNameContainer >& _rxExistingDialogModel
378 ) const;
379
390 bool createDialog(
391 const OUString& _rLibName,
392 const OUString& _rDialogName,
393 css::uno::Reference< css::io::XInputStreamProvider >& _out_rDialogProvider
394 ) const;
395
409 bool insertDialog(
410 const OUString& _rLibName,
411 const OUString& _rDialogName,
412 const css::uno::Reference< css::io::XInputStreamProvider >& _rDialogProvider
413 ) const;
414
419 bool isReadOnly() const;
420
424 bool isApplication() const;
425
429 bool isDocument() const { return isValid() && !isApplication(); }
430
436 void setDocumentModified() const;
437
443 bool isDocumentModified() const;
444
449 void saveDocument(
450 const css::uno::Reference< css::task::XStatusIndicator >& _rxStatusIndicator
451 ) const;
452
455 getLibraryLocation( const OUString& _rLibName ) const;
456
458 OUString getTitle( LibraryLocation _eLocation, LibraryType _eType = LibraryType::All ) const;
459
464 OUString getTitle() const;
465
468 bool isActive() const;
469
474 bool allowMacros() const;
475 };
476
477
478} // namespace basctl
479
480
481/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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
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(const css::uno::Reference< css::frame::XModel > &_rxDocument)
creates a ScriptDocument instance which refers to a document given as XModel
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
bool operator!=(const ScriptDocument &_rhs) const
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
@ LIBRARY_LOCATION_USER
@ LIBRARY_LOCATION_UNKNOWN
@ LIBRARY_LOCATION_SHARE
@ LIBRARY_LOCATION_DOCUMENT
std::vector< ScriptDocument > ScriptDocuments