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 .
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 <boost/shared_ptr.hpp>
39 enum LibraryContainerType
47 LIBRARY_LOCATION_UNKNOWN
,
48 LIBRARY_LOCATION_USER
,
49 LIBRARY_LOCATION_SHARE
,
50 LIBRARY_LOCATION_DOCUMENT
62 typedef ::std::vector
< ScriptDocument
> ScriptDocuments
;
64 /** encapsulates a document which contains Basic scripts and dialogs
70 boost::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 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
>& _rxDocument
);
101 ScriptDocument( const ScriptDocument
& _rSource
);
106 /** returns a reference to a shared ScriptDocument instance which
107 operates on the application-wide scripts and dialogs
109 static const ScriptDocument
&
110 getApplicationScriptDocument();
112 /** returns a (newly created) ScriptDocument instance for the document to
113 which a given BasicManager belongs
115 If the basic manager is the application's basic manager, then the (shared)
116 ScriptDocument instance which is responsible for the application is returned.
118 @see getApplicationScriptDocument
120 static ScriptDocument
121 getDocumentForBasicManager( const BasicManager
* _pManager
);
123 /** returns a (newly created) ScriptDocument instance for the document
124 with a given caption or URL
126 If there is no document with the given caption, then the (shared)
127 ScriptDocument instance which is responsible for the application is returned.
129 @see getApplicationScriptDocument
131 static ScriptDocument
132 getDocumentWithURLOrCaption( const OUString
& _rUrlOrCaption
);
134 /** operation mode for getAllScriptDocuments
136 enum ScriptDocumentList
138 /** all ScriptDocuments, including the dedicated one which represents
139 the application-wide scripts/dialogs.
142 /** real documents only
145 /** real documents only, sorted lexicographically by their title (using the sys locale's default
151 /** returns the set of ScriptDocument instances, one for each open document which
152 contains Basic/Dialog containers; plus an additional instance for
153 the application, if desired
155 Documents which are not visible - i.e. do not have a visible frame.
157 @param _bIncludingApplication
158 <TRUE/> if the application-wide scripts/dialogs should also be represented
161 static ScriptDocuments
162 getAllScriptDocuments( ScriptDocumentList _eListType
);
165 bool operator==( const ScriptDocument
& _rhs
) const;
166 inline bool operator!=( const ScriptDocument
& _rhs
) const { return !( *this == _rhs
); }
168 /// retrieves a (pretty simple) hash code for the document
169 sal_Int32
hashCode() const;
171 /** determines whether the document is actually able to contain Basic/Dialog libraries
173 Note that validity does not automatically imply the document can be used for active
174 work. Instead, it is possible the document is closed already (or being closed currently).
175 In this case, isValid will return <TRUE/>, but isAlive will return <FALSE/>.
178 <TRUE/> if the instance refers to a document which contains Basic/Dialog libraries,
179 or the application as a whole, <FALSE/> otherwise.
183 bool isValid() const;
185 /** determines whether the document instance is alive
187 If the instance is not valid, <FALSE/> is returned.
189 If the instance refers to a real document, which is already closed, or just being closed,
190 the method returns <FALSE/>.
192 If the instance refers to the application, <TRUE/> is returned.
196 bool isAlive() const;
198 bool isInVBAMode() const;
199 /// returns the BasicManager associated with this instance
201 getBasicManager() const;
203 /** returns the UNO component representing the document which the instance operates on
205 Must not be used when the instance operates on the application-wide
206 Basic/Dialog libraries.
208 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
>
211 /** returns the UNO component representing the document which the instance operates on
213 May be used when the instance operates on the application-wide
214 Basic/Dialog libraries, in this case it returns <NULL/>.
216 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
>
217 getDocumentOrNull() const;
219 /** returns the Basic or Dialog library container of the document
221 If the document is not valid, <NULL/> is returned.
223 ::com::sun::star::uno::Reference
< ::com::sun::star::script::XLibraryContainer
>
224 getLibraryContainer( LibraryContainerType _eType
) const;
226 /** determines whether there exists a library of the given type, with the given name
228 bool hasLibrary( LibraryContainerType _eType
, const OUString
& _rLibName
) const;
230 /** returns a script or dialog library given by name
233 the type of library to load
235 the name of the script library
237 <TRUE/> if and only if the library should be loaded.
239 @throws NoSuchElementException
240 if there is no script library with the given name
242 ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
>
243 getLibrary( LibraryContainerType _eType
, const OUString
& _rLibName
, bool _bLoadLibrary
) const;
245 /** creates a script or dialog library in the document, or returns an existing one
247 If <code>_rLibName</code> denotes an existing library which does not need to be created,
248 then this library will automatically be loaded, and then returned.
250 ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
>
251 getOrCreateLibrary( LibraryContainerType _eType
, const OUString
& _rLibName
) const;
253 /** returns the names of the modules in a given script or dialog library of the document
255 ::com::sun::star::uno::Sequence
< OUString
>
256 getObjectNames( LibraryContainerType _eType
, const OUString
& _rLibName
) const;
258 /** retrieves a name for a newly to be created module or dialog
260 OUString
createObjectName( LibraryContainerType _eType
, const OUString
& _rLibName
) const;
262 /** loads a script or dialog library given by name, if there is such a library
264 void loadLibraryIfExists( LibraryContainerType _eType
, const OUString
& _rLibrary
);
266 /// retrieves the (combined) names of all script and dialog libraries
267 ::com::sun::star::uno::Sequence
< OUString
>
268 getLibraryNames() const;
270 /** removes a given script module from the document
273 <TRUE/> if and only if the removal was successful. When <FALSE/> is returned,
274 this will reported as assertion in a non-product build.
276 bool removeModule( const OUString
& _rLibName
, const OUString
& _rModuleName
) const;
278 /** creates a module with the given name in the given library
282 the name of the to-be-created module
284 determines whether or not a function Main should be created
285 @param _out_rNewModuleCode
286 the source code of the newly created module
288 <TRUE/> if and only if the creation was successful
290 bool createModule( const OUString
& _rLibName
, const OUString
& _rModName
, bool _bCreateMain
, OUString
& _out_rNewModuleCode
) const;
292 /** inserts a given piece as code as module
294 the name of the library to insert the module into. If a library with this name does
295 not yet exist, it will be created.
297 the name of the module to insert the code as. Must denote a name which is not yet
298 used in the module library.
300 the code of the new module
302 <TRUE/> if and only if the insertion was successful.
304 bool insertModule( const OUString
& _rLibName
, const OUString
& _rModName
, const OUString
& _rModuleCode
) const;
306 /** updates a given module with new code
308 the name of the library the modules lives in. Must denote an existing module library.
310 the name of the module to update. Must denote an existing module in the given library.
314 <TRUE/> if and only if the insertion was successful.
316 bool updateModule( const OUString
& _rLibName
, const OUString
& _rModName
, const OUString
& _rModuleCode
) const;
318 /// determines whether a module with the given name exists in the given library
319 bool hasModule( const OUString
& _rLibName
, const OUString
& _rModName
) const;
321 /** retrieves a module's source
323 the library name where the module is located
326 @param _out_rModuleSource
327 takes the module's source upon successful return
329 <TRUE/> if and only if the code could be successfully retrieved, <FALSE/> otherwise
331 bool getModule( const OUString
& _rLibName
, const OUString
& _rModName
, OUString
& _rModuleSource
) const;
335 the library where the module lives in. Must denote an existing library.
337 the old module name. Must denote an existing module.
341 <TRUE/> if and only if renaming was successful.
343 bool renameModule( const OUString
& _rLibName
, const OUString
& _rOldName
, const OUString
& _rNewName
) const;
345 /** removes a given dialog from the document
348 <TRUE/> if and only if the removal was successful. When <FALSE/> is returned,
349 this will reported as assertion in a non-product build.
351 bool removeDialog( const OUString
& _rLibName
, const OUString
& _rDialogName
) const;
353 /// determines whether a dialog with the given name exists in the given library
354 bool hasDialog( const OUString
& _rLibName
, const OUString
& _rDialogName
) const;
356 /** retrieves a dialog
358 the library name where the module is located
361 @param _out_rDialogSource
362 takes the provider for the dialog's desription, upon successful return
364 <TRUE/> if and only if the dialog could be successfully retrieved, <FALSE/> otherwise
367 const OUString
& _rLibName
,
368 const OUString
& _rDialogName
,
369 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStreamProvider
>& _out_rDialogProvider
374 the library where the dialog lives in. Must denote an existing library.
376 the old dialog name. Must denote an existing dialog.
379 @param _rxExistingDialogModel
380 the existing model of the dialog, if already loaded in the IDE
382 <TRUE/> if and only if renaming was successful.
385 const OUString
& _rLibName
,
386 const OUString
& _rOldName
,
387 const OUString
& _rNewName
,
388 const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
>& _rxExistingDialogModel
393 the library name where the module is located
396 @param _out_rDialogSource
397 takes the provider for the dialog's desription, upon successful return
399 <TRUE/> if and only if the dialog could be successfully retrieved, <FALSE/> otherwise
402 const OUString
& _rLibName
,
403 const OUString
& _rDialogName
,
404 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStreamProvider
>& _out_rDialogProvider
407 /** inserts a given dialog into a given library
410 the name of the library to insert the dialog into. If a library with this name does
411 not yet exist, it will be created.
413 the name of the dialog to insert. Must denote a name which is not yet
414 used in the dialog library.
415 @param _rDialogProvider
416 the provider of the dialog's description
418 <TRUE/> if and only if the insertion was successful.
421 const OUString
& _rLibName
,
422 const OUString
& _rDialogName
,
423 const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStreamProvider
>& _rDialogProvider
426 /** determines whether the document is read-only
428 cannot be called if the document operates on the application-wide scripts
430 bool isReadOnly() const;
432 /** determines whether the ScriptDocument instance operates on the whole application,
433 as opposed to a real document
435 bool isApplication() const;
437 /** determines whether the ScriptDocument instance operates on a real document,
438 as opposed to the whole application
440 bool isDocument() const { return isValid() && !isApplication(); }
442 /** marks the document as modified
444 the instance operates on a real document, not on the application
447 void setDocumentModified() const;
449 /** determines whether the document is modified
451 the instance operates on a real document, not on the application
454 bool isDocumentModified() const;
456 /** saves the document, if the instance refers to a real document
458 <code>isApplication</code> returns <FALSE/>
461 const ::com::sun::star::uno::Reference
< ::com::sun::star::task::XStatusIndicator
>& _rxStatusIndicator
464 /// returns the location of a library given by name
466 getLibraryLocation( const OUString
& _rLibName
) const;
468 /// returns the title for the document
469 OUString
getTitle( LibraryLocation _eLocation
, LibraryType _eType
= LIBRARY_TYPE_ALL
) const;
471 /** returns the title of the document
473 to be used for valid documents only
475 OUString
getTitle() const;
477 /** returns the URL of the document
479 to be used for valid documents only
481 OUString
getURL() const;
483 /** determines whether the document is currently the one-and-only application-wide active document
485 bool isActive() const;
487 /** determines whether macro execution for this document is allowed
489 only to be called for real documents (->isDocument)
491 bool allowMacros() const;
495 } // namespace basctl
498 #endif // INCLUDED_BASCTL_SOURCE_INC_SCRIPTDOCUMENT_HXX
500 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */