1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #include "basctldllapi.h"
24 #include <com/sun/star/script/XLibraryContainer.hpp>
25 #include <com/sun/star/frame/XModel.hpp>
26 #include <com/sun/star/task/XStatusIndicator.hpp>
27 #include <com/sun/star/io/XInputStreamProvider.hpp>
40 enum LibraryContainerType
48 LIBRARY_LOCATION_UNKNOWN
,
49 LIBRARY_LOCATION_USER
,
50 LIBRARY_LOCATION_SHARE
,
51 LIBRARY_LOCATION_DOCUMENT
54 enum class LibraryType
62 typedef std::vector
< ScriptDocument
> ScriptDocuments
;
64 /** encapsulates a document which contains Basic scripts and dialogs
66 class BASCTL_DLLPUBLIC ScriptDocument
70 std::shared_ptr
<Impl
> m_pImpl
;
73 /** creates a ScriptDocument instance which operates on the application-wide
79 enum SpecialDocument
{ NoDocument
};
80 /** creates a ScriptDocument instance which does refers to neither the application-wide,
81 nor a specific real document's scripts.
83 This constructor might come handy when you need some kind of uninitialized
84 ScriptDocument, which you do not want to operate on (yet), but initialize later
87 <member>isValid</member> will return <FALSE/> for a ScriptDocument constructed
90 explicit ScriptDocument( SpecialDocument _eType
);
92 /** creates a ScriptDocument instance which refers to a document given as
96 the document. Must not be <NULL/>.
98 explicit ScriptDocument( const css::uno::Reference
< css::frame::XModel
>& _rxDocument
);
100 /** returns a reference to a shared ScriptDocument instance which
101 operates on the application-wide scripts and dialogs
103 static const ScriptDocument
&
104 getApplicationScriptDocument();
106 /** returns a (newly created) ScriptDocument instance for the document to
107 which a given BasicManager belongs
109 If the basic manager is the application's basic manager, then the (shared)
110 ScriptDocument instance which is responsible for the application is returned.
112 @see getApplicationScriptDocument
114 static ScriptDocument
115 getDocumentForBasicManager( const BasicManager
* _pManager
);
117 /** returns a (newly created) ScriptDocument instance for the document
118 with a given caption or URL
120 If there is no document with the given caption, then the (shared)
121 ScriptDocument instance which is responsible for the application is returned.
123 @see getApplicationScriptDocument
125 static ScriptDocument
126 getDocumentWithURLOrCaption( std::u16string_view _rUrlOrCaption
);
128 /** operation mode for getAllScriptDocuments
130 enum ScriptDocumentList
132 /** all ScriptDocuments, including the dedicated one which represents
133 the application-wide scripts/dialogs.
136 /** real documents only, sorted lexicographically by their title (using the sys locale's default
142 /** returns the set of ScriptDocument instances, one for each open document which
143 contains Basic/Dialog containers; plus an additional instance for
144 the application, if desired
146 Documents which are not visible - i.e. do not have a visible frame.
148 @param _bIncludingApplication
149 <TRUE/> if the application-wide scripts/dialogs should also be represented
152 static ScriptDocuments
153 getAllScriptDocuments( ScriptDocumentList _eListType
);
156 bool operator==( const ScriptDocument
& _rhs
) const;
158 /// retrieves a (pretty simple) hash code for the document
159 sal_Int32
hashCode() const;
161 /** determines whether the document is actually able to contain Basic/Dialog libraries
163 Note that validity does not automatically imply the document can be used for active
164 work. Instead, it is possible the document is closed already (or being closed currently).
165 In this case, isValid will return <TRUE/>, but isAlive will return <FALSE/>.
168 <TRUE/> if the instance refers to a document which contains Basic/Dialog libraries,
169 or the application as a whole, <FALSE/> otherwise.
173 bool isValid() const;
175 /** determines whether the document instance is alive
177 If the instance is not valid, <FALSE/> is returned.
179 If the instance refers to a real document, which is already closed, or just being closed,
180 the method returns <FALSE/>.
182 If the instance refers to the application, <TRUE/> is returned.
186 bool isAlive() const;
188 bool isInVBAMode() const;
189 /// returns the BasicManager associated with this instance
191 getBasicManager() const;
193 /** returns the UNO component representing the document which the instance operates on
195 Must not be used when the instance operates on the application-wide
196 Basic/Dialog libraries.
198 css::uno::Reference
< css::frame::XModel
>
201 /** returns the UNO component representing the document which the instance operates on
203 May be used when the instance operates on the application-wide
204 Basic/Dialog libraries, in this case it returns <NULL/>.
206 css::uno::Reference
< css::frame::XModel
>
207 getDocumentOrNull() const;
209 /** returns the Basic or Dialog library container of the document
211 If the document is not valid, <NULL/> is returned.
213 css::uno::Reference
< css::script::XLibraryContainer
>
214 getLibraryContainer( LibraryContainerType _eType
) const;
216 /** determines whether there exists a library of the given type, with the given name
218 bool hasLibrary( LibraryContainerType _eType
, const OUString
& _rLibName
) const;
220 /** returns a script or dialog library given by name
223 the type of library to load
225 the name of the script library
227 <TRUE/> if and only if the library should be loaded.
229 @throws NoSuchElementException
230 if there is no script library with the given name
232 css::uno::Reference
< css::container::XNameContainer
>
233 getLibrary( LibraryContainerType _eType
, const OUString
& _rLibName
, bool _bLoadLibrary
) const;
235 /** creates a script or dialog library in the document, or returns an existing one
237 If <code>_rLibName</code> denotes an existing library which does not need to be created,
238 then this library will automatically be loaded, and then returned.
240 css::uno::Reference
< css::container::XNameContainer
>
241 getOrCreateLibrary( LibraryContainerType _eType
, const OUString
& _rLibName
) const;
243 /** returns the names of the modules in a given script or dialog library of the document
245 css::uno::Sequence
< OUString
>
246 getObjectNames( LibraryContainerType _eType
, const OUString
& _rLibName
) const;
248 /** retrieves a name for a newly to be created module or dialog
250 OUString
createObjectName( LibraryContainerType _eType
, const OUString
& _rLibName
) const;
252 /** loads a script or dialog library given by name, if there is such a library
254 void loadLibraryIfExists( LibraryContainerType _eType
, const OUString
& _rLibrary
);
256 /// retrieves the (combined) names of all script and dialog libraries
257 css::uno::Sequence
< OUString
>
258 getLibraryNames() const;
260 /** removes a given script module from the document
263 <TRUE/> if and only if the removal was successful. When <FALSE/> is returned,
264 this will reported as assertion in a non-product build.
266 bool removeModule( const OUString
& _rLibName
, const OUString
& _rModuleName
) const;
268 /** creates a module with the given name in the given library
272 the name of the to-be-created module
274 determines whether or not a function Main should be created
275 @param _out_rNewModuleCode
276 the source code of the newly created module
278 <TRUE/> if and only if the creation was successful
280 bool createModule( const OUString
& _rLibName
, const OUString
& _rModName
, bool _bCreateMain
, OUString
& _out_rNewModuleCode
) const;
282 /** inserts a given piece as code as module
284 the name of the library to insert the module into. If a library with this name does
285 not yet exist, it will be created.
287 the name of the module to insert the code as. Must denote a name which is not yet
288 used in the module library.
290 the code of the new module
292 <TRUE/> if and only if the insertion was successful.
294 bool insertModule( const OUString
& _rLibName
, const OUString
& _rModName
, const OUString
& _rModuleCode
) const;
296 /** updates a given module with new code
298 the name of the library the modules lives in. Must denote an existing module library.
300 the name of the module to update. Must denote an existing module in the given library.
304 <TRUE/> if and only if the insertion was successful.
306 bool updateModule( const OUString
& _rLibName
, const OUString
& _rModName
, const OUString
& _rModuleCode
) const;
308 /// determines whether a module with the given name exists in the given library
309 bool hasModule( const OUString
& _rLibName
, const OUString
& _rModName
) const;
311 /** retrieves a module's source
313 the library name where the module is located
316 @param _out_rModuleSource
317 takes the module's source upon successful return
319 <TRUE/> if and only if the code could be successfully retrieved, <FALSE/> otherwise
321 bool getModule( const OUString
& _rLibName
, const OUString
& _rModName
, OUString
& _rModuleSource
) const;
325 the library where the module lives in. Must denote an existing library.
327 the old module name. Must denote an existing module.
331 <TRUE/> if and only if renaming was successful.
333 bool renameModule( const OUString
& _rLibName
, const OUString
& _rOldName
, const OUString
& _rNewName
) const;
335 /** removes a given dialog from the document
338 <TRUE/> if and only if the removal was successful. When <FALSE/> is returned,
339 this will reported as assertion in a non-product build.
341 bool removeDialog( const OUString
& _rLibName
, const OUString
& _rDialogName
) const;
343 /// determines whether a dialog with the given name exists in the given library
344 bool hasDialog( const OUString
& _rLibName
, const OUString
& _rDialogName
) const;
346 /** retrieves a dialog
348 the library name where the module is located
351 @param _out_rDialogSource
352 takes the provider for the dialog's description, upon successful return
354 <TRUE/> if and only if the dialog could be successfully retrieved, <FALSE/> otherwise
357 const OUString
& _rLibName
,
358 const OUString
& _rDialogName
,
359 css::uno::Reference
< css::io::XInputStreamProvider
>& _out_rDialogProvider
364 the library where the dialog lives in. Must denote an existing library.
366 the old dialog name. Must denote an existing dialog.
369 @param _rxExistingDialogModel
370 the existing model of the dialog, if already loaded in the IDE
372 <TRUE/> if and only if renaming was successful.
375 const OUString
& _rLibName
,
376 const OUString
& _rOldName
,
377 const OUString
& _rNewName
,
378 const css::uno::Reference
< css::container::XNameContainer
>& _rxExistingDialogModel
383 the library name where the module is located
386 @param _out_rDialogSource
387 takes the provider for the dialog's description, upon successful return
389 <TRUE/> if and only if the dialog could be successfully retrieved, <FALSE/> otherwise
392 const OUString
& _rLibName
,
393 const OUString
& _rDialogName
,
394 css::uno::Reference
< css::io::XInputStreamProvider
>& _out_rDialogProvider
397 /** inserts a given dialog into a given library
400 the name of the library to insert the dialog into. If a library with this name does
401 not yet exist, it will be created.
403 the name of the dialog to insert. Must denote a name which is not yet
404 used in the dialog library.
405 @param _rDialogProvider
406 the provider of the dialog's description
408 <TRUE/> if and only if the insertion was successful.
411 const OUString
& _rLibName
,
412 const OUString
& _rDialogName
,
413 const css::uno::Reference
< css::io::XInputStreamProvider
>& _rDialogProvider
416 /** determines whether the document is read-only
418 cannot be called if the document operates on the application-wide scripts
420 bool isReadOnly() const;
422 /** determines whether the ScriptDocument instance operates on the whole application,
423 as opposed to a real document
425 bool isApplication() const;
427 /** determines whether the ScriptDocument instance operates on a real document,
428 as opposed to the whole application
430 bool isDocument() const { return isValid() && !isApplication(); }
432 /** marks the document as modified
434 the instance operates on a real document, not on the application
437 void setDocumentModified() const;
439 /** determines whether the document is modified
441 the instance operates on a real document, not on the application
444 bool isDocumentModified() const;
446 /** saves the document, if the instance refers to a real document
448 <code>isApplication</code> returns <FALSE/>
451 const css::uno::Reference
< css::task::XStatusIndicator
>& _rxStatusIndicator
454 /// returns the location of a library given by name
456 getLibraryLocation( const OUString
& _rLibName
) const;
458 /// returns the title for the document
459 OUString
getTitle( LibraryLocation _eLocation
, LibraryType _eType
= LibraryType::All
) const;
461 /** returns the title of the document
463 to be used for valid documents only
465 OUString
getTitle() const;
467 /** determines whether the document is currently the one-and-only application-wide active document
469 bool isActive() const;
471 /** determines whether macro execution for this document is allowed
473 only to be called for real documents (->isDocument)
475 bool allowMacros() const;
479 } // namespace basctl
482 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */