Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / basctl / source / inc / scriptdocument.hxx
blobe03c66546a2e131a45d3f9b4ac56867530d09211
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 #ifndef INCLUDED_BASCTL_SOURCE_INC_SCRIPTDOCUMENT_HXX
21 #define INCLUDED_BASCTL_SOURCE_INC_SCRIPTDOCUMENT_HXX
23 #include <com/sun/star/script/XLibraryContainer.hpp>
24 #include <com/sun/star/frame/XModel.hpp>
25 #include <com/sun/star/task/XStatusIndicator.hpp>
26 #include <com/sun/star/io/XInputStreamProvider.hpp>
28 #include <memory>
29 #include <vector>
31 class SfxListener;
33 class BasicManager;
36 namespace basctl
39 enum LibraryContainerType
41 E_SCRIPTS,
42 E_DIALOGS
45 enum LibraryLocation
47 LIBRARY_LOCATION_UNKNOWN,
48 LIBRARY_LOCATION_USER,
49 LIBRARY_LOCATION_SHARE,
50 LIBRARY_LOCATION_DOCUMENT
53 enum class LibraryType
55 Module,
56 Dialog,
57 All
60 class ScriptDocument;
61 typedef std::vector< ScriptDocument > ScriptDocuments;
63 /** encapsulates a document which contains Basic scripts and dialogs
65 class ScriptDocument
67 private:
68 class Impl;
69 std::shared_ptr<Impl> m_pImpl;
71 private:
72 /** creates a ScriptDocument instance which operates on the application-wide
73 scripts and dialogs
75 ScriptDocument();
77 public:
78 enum SpecialDocument { NoDocument };
79 /** creates a ScriptDocument instance which does refers to neither the application-wide,
80 nor a specific real document's scripts.
82 This constructor might come handy when you need some kind of uninitialized
83 ScriptDocument, which you do not want to operate on (yet), but initialize later
84 by assignment.
86 <member>isValid</member> will return <FALSE/> for a ScriptDocument constructed
87 this way.
89 explicit ScriptDocument( SpecialDocument _eType );
91 /** creates a ScriptDocument instance which refers to a document given as
92 XModel
94 @param _rxDocument
95 the document. Must not be <NULL/>.
97 explicit ScriptDocument( const css::uno::Reference< css::frame::XModel >& _rxDocument );
99 /** returns a reference to a shared ScriptDocument instance which
100 operates on the application-wide scripts and dialogs
102 static const ScriptDocument&
103 getApplicationScriptDocument();
105 /** returns a (newly created) ScriptDocument instance for the document to
106 which a given BasicManager belongs
108 If the basic manager is the application's basic manager, then the (shared)
109 ScriptDocument instance which is responsible for the application is returned.
111 @see getApplicationScriptDocument
113 static ScriptDocument
114 getDocumentForBasicManager( const BasicManager* _pManager );
116 /** returns a (newly created) ScriptDocument instance for the document
117 with a given caption or URL
119 If there is no document with the given caption, then the (shared)
120 ScriptDocument instance which is responsible for the application is returned.
122 @see getApplicationScriptDocument
124 static ScriptDocument
125 getDocumentWithURLOrCaption( const OUString& _rUrlOrCaption );
127 /** operation mode for getAllScriptDocuments
129 enum ScriptDocumentList
131 /** all ScriptDocuments, including the dedicated one which represents
132 the application-wide scripts/dialogs.
134 AllWithApplication,
135 /** real documents only, sorted lexicographically by their title (using the sys locale's default
136 collator)
138 DocumentsSorted
141 /** returns the set of ScriptDocument instances, one for each open document which
142 contains Basic/Dialog containers; plus an additional instance for
143 the application, if desired
145 Documents which are not visible - i.e. do not have a visible frame.
147 @param _bIncludingApplication
148 <TRUE/> if the application-wide scripts/dialogs should also be represented
149 by a ScriptDocument
151 static ScriptDocuments
152 getAllScriptDocuments( ScriptDocumentList _eListType );
154 // comparison
155 bool operator==( const ScriptDocument& _rhs ) const;
156 bool operator!=( const ScriptDocument& _rhs ) const { return !( *this == _rhs ); }
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/>.
167 @return
168 <TRUE/> if the instance refers to a document which contains Basic/Dialog libraries,
169 or the application as a whole, <FALSE/> otherwise.
171 @see isAlive
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.
184 @see isValid
186 bool isAlive() const;
188 bool isInVBAMode() const;
189 /// returns the BasicManager associated with this instance
190 BasicManager*
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 >
199 getDocument() const;
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
222 @param _eType
223 the type of library to load
224 @param _rLibName
225 the name of the script library
226 @param _bLoadLibrary
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
262 @return
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
269 @param _rLibName
270 the library name
271 @param _rModName
272 the name of the to-be-created module
273 @param _bCreateMain
274 determines whether or not a function Main should be created
275 @param _out_rNewModuleCode
276 the source code of the newly created module
277 @return
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
283 @param _rLibName
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.
286 @param _rModName
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.
289 @param _rModuleCode
290 the code of the new module
291 @return
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
297 @param _rLibName
298 the name of the library the modules lives in. Must denote an existing module library.
299 @param _rModName
300 the name of the module to update. Must denote an existing module in the given library.
301 @param _rModuleCode
302 the new module code.
303 @return
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
312 @param _rLibName
313 the library name where the module is located
314 @param _rModName
315 the module name
316 @param _out_rModuleSource
317 takes the module's source upon successful return
318 @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;
323 /** renames a module
324 @param _rLibName
325 the library where the module lives in. Must denote an existing library.
326 @param _rOldName
327 the old module name. Must denote an existing module.
328 @param _rNewName
329 the new module name
330 @return
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
337 @return
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
347 @param _rLibName
348 the library name where the module is located
349 @param _rDialogName
350 the dialog's name
351 @param _out_rDialogSource
352 takes the provider for the dialog's description, upon successful return
353 @return
354 <TRUE/> if and only if the dialog could be successfully retrieved, <FALSE/> otherwise
356 bool getDialog(
357 const OUString& _rLibName,
358 const OUString& _rDialogName,
359 css::uno::Reference< css::io::XInputStreamProvider >& _out_rDialogProvider
360 ) const;
362 /** renames a dialog
363 @param _rLibName
364 the library where the dialog lives in. Must denote an existing library.
365 @param _rOldName
366 the old dialog name. Must denote an existing dialog.
367 @param _rNewName
368 the new dialog name
369 @param _rxExistingDialogModel
370 the existing model of the dialog, if already loaded in the IDE
371 @return
372 <TRUE/> if and only if renaming was successful.
374 bool renameDialog(
375 const OUString& _rLibName,
376 const OUString& _rOldName,
377 const OUString& _rNewName,
378 const css::uno::Reference< css::container::XNameContainer >& _rxExistingDialogModel
379 ) const;
381 /** create a dialog
382 @param _rLibName
383 the library name where the module is located
384 @param _rDialogName
385 the dialog's name
386 @param _out_rDialogSource
387 takes the provider for the dialog's description, upon successful return
388 @return
389 <TRUE/> if and only if the dialog could be successfully retrieved, <FALSE/> otherwise
391 bool createDialog(
392 const OUString& _rLibName,
393 const OUString& _rDialogName,
394 css::uno::Reference< css::io::XInputStreamProvider >& _out_rDialogProvider
395 ) const;
397 /** inserts a given dialog into a given library
399 @param _rLibName
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.
402 @param _rModName
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
407 @return
408 <TRUE/> if and only if the insertion was successful.
410 bool insertDialog(
411 const OUString& _rLibName,
412 const OUString& _rDialogName,
413 const css::uno::Reference< css::io::XInputStreamProvider >& _rDialogProvider
414 ) const;
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
433 @precond
434 the instance operates on a real document, not on the application
435 @see isDocument
437 void setDocumentModified() const;
439 /** determines whether the document is modified
440 @precond
441 the instance operates on a real document, not on the application
442 @see isDocument
444 bool isDocumentModified() const;
446 /** saves the document, if the instance refers to a real document
447 @precond
448 <code>isApplication</code> returns <FALSE/>
450 void saveDocument(
451 const css::uno::Reference< css::task::XStatusIndicator >& _rxStatusIndicator
452 ) const;
454 /// returns the location of a library given by name
455 LibraryLocation
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 #endif // INCLUDED_BASCTL_SOURCE_INC_SCRIPTDOCUMENT_HXX
484 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */