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 <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>
38 enum LibraryContainerType
46 LIBRARY_LOCATION_UNKNOWN
,
47 LIBRARY_LOCATION_USER
,
48 LIBRARY_LOCATION_SHARE
,
49 LIBRARY_LOCATION_DOCUMENT
52 enum class LibraryType
60 typedef std::vector
< ScriptDocument
> ScriptDocuments
;
62 /** encapsulates a document which contains Basic scripts and dialogs
68 std::shared_ptr
<Impl
> m_pImpl
;
71 /** creates a ScriptDocument instance which operates on the application-wide
77 enum SpecialDocument
{ NoDocument
};
78 /** creates a ScriptDocument instance which does refers to neither the application-wide,
79 nor a specific real document's scripts.
81 This constructor might come handy when you need some kind of uninitialized
82 ScriptDocument, which you do not want to operate on (yet), but initialize later
85 <member>isValid</member> will return <FALSE/> for a ScriptDocument constructed
88 explicit ScriptDocument( SpecialDocument _eType
);
90 /** creates a ScriptDocument instance which refers to a document given as
94 the document. Must not be <NULL/>.
96 explicit ScriptDocument( const css::uno::Reference
< css::frame::XModel
>& _rxDocument
);
98 /** returns a reference to a shared ScriptDocument instance which
99 operates on the application-wide scripts and dialogs
101 static const ScriptDocument
&
102 getApplicationScriptDocument();
104 /** returns a (newly created) ScriptDocument instance for the document to
105 which a given BasicManager belongs
107 If the basic manager is the application's basic manager, then the (shared)
108 ScriptDocument instance which is responsible for the application is returned.
110 @see getApplicationScriptDocument
112 static ScriptDocument
113 getDocumentForBasicManager( const BasicManager
* _pManager
);
115 /** returns a (newly created) ScriptDocument instance for the document
116 with a given caption or URL
118 If there is no document with the given caption, then the (shared)
119 ScriptDocument instance which is responsible for the application is returned.
121 @see getApplicationScriptDocument
123 static ScriptDocument
124 getDocumentWithURLOrCaption( std::u16string_view _rUrlOrCaption
);
126 /** operation mode for getAllScriptDocuments
128 enum ScriptDocumentList
130 /** all ScriptDocuments, including the dedicated one which represents
131 the application-wide scripts/dialogs.
134 /** real documents only, sorted lexicographically by their title (using the sys locale's default
140 /** returns the set of ScriptDocument instances, one for each open document which
141 contains Basic/Dialog containers; plus an additional instance for
142 the application, if desired
144 Documents which are not visible - i.e. do not have a visible frame.
146 @param _bIncludingApplication
147 <TRUE/> if the application-wide scripts/dialogs should also be represented
150 static ScriptDocuments
151 getAllScriptDocuments( ScriptDocumentList _eListType
);
154 bool operator==( const ScriptDocument
& _rhs
) const;
155 bool operator!=( const ScriptDocument
& _rhs
) const { return !( *this == _rhs
); }
157 /// retrieves a (pretty simple) hash code for the document
158 sal_Int32
hashCode() const;
160 /** determines whether the document is actually able to contain Basic/Dialog libraries
162 Note that validity does not automatically imply the document can be used for active
163 work. Instead, it is possible the document is closed already (or being closed currently).
164 In this case, isValid will return <TRUE/>, but isAlive will return <FALSE/>.
167 <TRUE/> if the instance refers to a document which contains Basic/Dialog libraries,
168 or the application as a whole, <FALSE/> otherwise.
172 bool isValid() const;
174 /** determines whether the document instance is alive
176 If the instance is not valid, <FALSE/> is returned.
178 If the instance refers to a real document, which is already closed, or just being closed,
179 the method returns <FALSE/>.
181 If the instance refers to the application, <TRUE/> is returned.
185 bool isAlive() const;
187 bool isInVBAMode() const;
188 /// returns the BasicManager associated with this instance
190 getBasicManager() const;
192 /** returns the UNO component representing the document which the instance operates on
194 Must not be used when the instance operates on the application-wide
195 Basic/Dialog libraries.
197 css::uno::Reference
< css::frame::XModel
>
200 /** returns the UNO component representing the document which the instance operates on
202 May be used when the instance operates on the application-wide
203 Basic/Dialog libraries, in this case it returns <NULL/>.
205 css::uno::Reference
< css::frame::XModel
>
206 getDocumentOrNull() const;
208 /** returns the Basic or Dialog library container of the document
210 If the document is not valid, <NULL/> is returned.
212 css::uno::Reference
< css::script::XLibraryContainer
>
213 getLibraryContainer( LibraryContainerType _eType
) const;
215 /** determines whether there exists a library of the given type, with the given name
217 bool hasLibrary( LibraryContainerType _eType
, const OUString
& _rLibName
) const;
219 /** returns a script or dialog library given by name
222 the type of library to load
224 the name of the script library
226 <TRUE/> if and only if the library should be loaded.
228 @throws NoSuchElementException
229 if there is no script library with the given name
231 css::uno::Reference
< css::container::XNameContainer
>
232 getLibrary( LibraryContainerType _eType
, const OUString
& _rLibName
, bool _bLoadLibrary
) const;
234 /** creates a script or dialog library in the document, or returns an existing one
236 If <code>_rLibName</code> denotes an existing library which does not need to be created,
237 then this library will automatically be loaded, and then returned.
239 css::uno::Reference
< css::container::XNameContainer
>
240 getOrCreateLibrary( LibraryContainerType _eType
, const OUString
& _rLibName
) const;
242 /** returns the names of the modules in a given script or dialog library of the document
244 css::uno::Sequence
< OUString
>
245 getObjectNames( LibraryContainerType _eType
, const OUString
& _rLibName
) const;
247 /** retrieves a name for a newly to be created module or dialog
249 OUString
createObjectName( LibraryContainerType _eType
, const OUString
& _rLibName
) const;
251 /** loads a script or dialog library given by name, if there is such a library
253 void loadLibraryIfExists( LibraryContainerType _eType
, const OUString
& _rLibrary
);
255 /// retrieves the (combined) names of all script and dialog libraries
256 css::uno::Sequence
< OUString
>
257 getLibraryNames() const;
259 /** removes a given script module from the document
262 <TRUE/> if and only if the removal was successful. When <FALSE/> is returned,
263 this will reported as assertion in a non-product build.
265 bool removeModule( const OUString
& _rLibName
, const OUString
& _rModuleName
) const;
267 /** creates a module with the given name in the given library
271 the name of the to-be-created module
273 determines whether or not a function Main should be created
274 @param _out_rNewModuleCode
275 the source code of the newly created module
277 <TRUE/> if and only if the creation was successful
279 bool createModule( const OUString
& _rLibName
, const OUString
& _rModName
, bool _bCreateMain
, OUString
& _out_rNewModuleCode
) const;
281 /** inserts a given piece as code as module
283 the name of the library to insert the module into. If a library with this name does
284 not yet exist, it will be created.
286 the name of the module to insert the code as. Must denote a name which is not yet
287 used in the module library.
289 the code of the new module
291 <TRUE/> if and only if the insertion was successful.
293 bool insertModule( const OUString
& _rLibName
, const OUString
& _rModName
, const OUString
& _rModuleCode
) const;
295 /** updates a given module with new code
297 the name of the library the modules lives in. Must denote an existing module library.
299 the name of the module to update. Must denote an existing module in the given library.
303 <TRUE/> if and only if the insertion was successful.
305 bool updateModule( const OUString
& _rLibName
, const OUString
& _rModName
, const OUString
& _rModuleCode
) const;
307 /// determines whether a module with the given name exists in the given library
308 bool hasModule( const OUString
& _rLibName
, const OUString
& _rModName
) const;
310 /** retrieves a module's source
312 the library name where the module is located
315 @param _out_rModuleSource
316 takes the module's source upon successful return
318 <TRUE/> if and only if the code could be successfully retrieved, <FALSE/> otherwise
320 bool getModule( const OUString
& _rLibName
, const OUString
& _rModName
, OUString
& _rModuleSource
) const;
324 the library where the module lives in. Must denote an existing library.
326 the old module name. Must denote an existing module.
330 <TRUE/> if and only if renaming was successful.
332 bool renameModule( const OUString
& _rLibName
, const OUString
& _rOldName
, const OUString
& _rNewName
) const;
334 /** removes a given dialog from the document
337 <TRUE/> if and only if the removal was successful. When <FALSE/> is returned,
338 this will reported as assertion in a non-product build.
340 bool removeDialog( const OUString
& _rLibName
, const OUString
& _rDialogName
) const;
342 /// determines whether a dialog with the given name exists in the given library
343 bool hasDialog( const OUString
& _rLibName
, const OUString
& _rDialogName
) const;
345 /** retrieves a dialog
347 the library name where the module is located
350 @param _out_rDialogSource
351 takes the provider for the dialog's description, upon successful return
353 <TRUE/> if and only if the dialog could be successfully retrieved, <FALSE/> otherwise
356 const OUString
& _rLibName
,
357 const OUString
& _rDialogName
,
358 css::uno::Reference
< css::io::XInputStreamProvider
>& _out_rDialogProvider
363 the library where the dialog lives in. Must denote an existing library.
365 the old dialog name. Must denote an existing dialog.
368 @param _rxExistingDialogModel
369 the existing model of the dialog, if already loaded in the IDE
371 <TRUE/> if and only if renaming was successful.
374 const OUString
& _rLibName
,
375 const OUString
& _rOldName
,
376 const OUString
& _rNewName
,
377 const css::uno::Reference
< css::container::XNameContainer
>& _rxExistingDialogModel
382 the library name where the module is located
385 @param _out_rDialogSource
386 takes the provider for the dialog's description, upon successful return
388 <TRUE/> if and only if the dialog could be successfully retrieved, <FALSE/> otherwise
391 const OUString
& _rLibName
,
392 const OUString
& _rDialogName
,
393 css::uno::Reference
< css::io::XInputStreamProvider
>& _out_rDialogProvider
396 /** inserts a given dialog into a given library
399 the name of the library to insert the dialog into. If a library with this name does
400 not yet exist, it will be created.
402 the name of the dialog to insert. Must denote a name which is not yet
403 used in the dialog library.
404 @param _rDialogProvider
405 the provider of the dialog's description
407 <TRUE/> if and only if the insertion was successful.
410 const OUString
& _rLibName
,
411 const OUString
& _rDialogName
,
412 const css::uno::Reference
< css::io::XInputStreamProvider
>& _rDialogProvider
415 /** determines whether the document is read-only
417 cannot be called if the document operates on the application-wide scripts
419 bool isReadOnly() const;
421 /** determines whether the ScriptDocument instance operates on the whole application,
422 as opposed to a real document
424 bool isApplication() const;
426 /** determines whether the ScriptDocument instance operates on a real document,
427 as opposed to the whole application
429 bool isDocument() const { return isValid() && !isApplication(); }
431 /** marks the document as modified
433 the instance operates on a real document, not on the application
436 void setDocumentModified() const;
438 /** determines whether the document is modified
440 the instance operates on a real document, not on the application
443 bool isDocumentModified() const;
445 /** saves the document, if the instance refers to a real document
447 <code>isApplication</code> returns <FALSE/>
450 const css::uno::Reference
< css::task::XStatusIndicator
>& _rxStatusIndicator
453 /// returns the location of a library given by name
455 getLibraryLocation( const OUString
& _rLibName
) const;
457 /// returns the title for the document
458 OUString
getTitle( LibraryLocation _eLocation
, LibraryType _eType
= LibraryType::All
) const;
460 /** returns the title of the document
462 to be used for valid documents only
464 OUString
getTitle() const;
466 /** determines whether the document is currently the one-and-only application-wide active document
468 bool isActive() const;
470 /** determines whether macro execution for this document is allowed
472 only to be called for real documents (->isDocument)
474 bool allowMacros() const;
478 } // namespace basctl
481 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */