1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 #ifndef SCRIPTDOCUMENT_HXX
29 #define SCRIPTDOCUMENT_HXX
31 /** === begin UNO includes === **/
32 #include <com/sun/star/script/XLibraryContainer.hpp>
33 #include <com/sun/star/frame/XModel.hpp>
34 #include <com/sun/star/task/XStatusIndicator.hpp>
35 #include <com/sun/star/io/XInputStreamProvider.hpp>
36 /** === end UNO includes === **/
38 #include <boost/shared_ptr.hpp>
44 //........................................................................
47 //........................................................................
49 //====================================================================
50 //= LibraryContainerType
51 //====================================================================
52 enum LibraryContainerType
60 LIBRARY_LOCATION_UNKNOWN
,
61 LIBRARY_LOCATION_USER
,
62 LIBRARY_LOCATION_SHARE
,
63 LIBRARY_LOCATION_DOCUMENT
74 //====================================================================
76 //====================================================================
77 class ScriptDocument_Impl
;
80 typedef ::std::vector
< ScriptDocument
> ScriptDocuments
;
82 /** encapsulates a document which contains Basic scripts and dialogs
87 ::boost::shared_ptr
< ScriptDocument_Impl
> m_pImpl
;
90 /** creates a ScriptDocument instance which operates on the application-wide
96 enum SpecialDocument
{ NoDocument
};
97 /** creates a ScriptDocument instance which does refers to neither the application-wide,
98 nor a specific real document's scripts.
100 This constructor might come handy when you need some kind of uninitialized
101 ScriptDocument, which you do not want to operate on (yet), but initialize later
104 <member>isValid</member> will return <FALSE/> for a ScriptDocument constructed
107 explicit ScriptDocument( SpecialDocument _eType
);
109 /** creates a ScriptDocument instance which refers to a document given as
113 the document. Must not be <NULL/>.
115 explicit ScriptDocument( const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
>& _rxDocument
);
118 ScriptDocument( const ScriptDocument
& _rSource
);
123 /** returns a reference to a shared ScriptDocument instance which
124 operates on the application-wide scripts and dialogs
126 static const ScriptDocument
&
127 getApplicationScriptDocument();
129 /** returns a (newly created) ScriptDocument instance for the document to
130 which a given BasicManager belongs
132 If the basic manager is the application's basic manager, then the (shared)
133 ScriptDocument instance which is responsible for the application is returned.
135 @see getApplicationScriptDocument
137 static ScriptDocument
138 getDocumentForBasicManager( const BasicManager
* _pManager
);
140 /** returns a (newly created) ScriptDocument instance for the document
141 with a given caption or URL
143 If there is no document with the given caption, then the (shared)
144 ScriptDocument instance which is responsible for the application is returned.
146 @see getApplicationScriptDocument
148 static ScriptDocument
149 getDocumentWithURLOrCaption( const ::rtl::OUString
& _rUrlOrCaption
);
151 /** operation mode for getAllScriptDocuments
153 enum ScriptDocumentList
155 /** all ScriptDocuments, including the dedicated one which represents
156 the application-wide scripts/dialogs.
159 /** real documents only
162 /** real documents only, sorted lexicographically by their title (using the sys locale's default
168 /** returns the set of ScriptDocument instances, one for each open document which
169 contains Basic/Dialog containers; plus an additional instance for
170 the application, if desired
172 Documents which are not visible - i.e. do not have a visible frame.
174 @param _bIncludingApplication
175 <TRUE/> if the application-wide scripts/dialogs should also be represented
178 static ScriptDocuments
179 getAllScriptDocuments( ScriptDocumentList _eListType
);
182 bool operator==( const ScriptDocument
& _rhs
) const;
183 inline bool operator!=( const ScriptDocument
& _rhs
) const { return !( *this == _rhs
); }
185 /// retrieves a (pretty simple) hash code for the document
186 sal_Int32
hashCode() const;
188 /** determines whether the document is actually able to contain Basic/Dialog libraries
190 Note that validity does not automatically imply the document can be used for active
191 work. Instead, it is possible the document is closed already (or being closed currently).
192 In this case, isValid will return <TRUE/>, but isAlive will return <FALSE/>.
195 <TRUE/> if the instance refers to a document which contains Basic/Dialog libraries,
196 or the application as a whole, <FALSE/> otherwise.
200 bool isValid() const;
202 /** determines whether the document instance is alive
204 If the instance is not valid, <FALSE/> is returned.
206 If the instance refers to a real document, which is already closed, or just being closed,
207 the method returns <FALSE/>.
209 If the instance refers to the application, <TRUE/> is returned.
213 bool isAlive() const;
215 bool isInVBAMode() const;
216 /// returns the BasicManager associated with this instance
218 getBasicManager() const;
220 /** returns the UNO component representing the document which the instance operates on
222 Must not be used when the instance operates on the application-wide
223 Basic/Dialog libraries.
225 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
>
228 /** returns the UNO component representing the document which the instance operates on
230 May be used when the instance operates on the application-wide
231 Basic/Dialog libraries, in this case it returns <NULL/>.
233 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
>
234 getDocumentOrNull() const;
236 /** returns the Basic or Dialog library container of the document
238 If the document is not valid, <NULL/> is returned.
240 ::com::sun::star::uno::Reference
< ::com::sun::star::script::XLibraryContainer
>
241 getLibraryContainer( LibraryContainerType _eType
) const;
243 /** determines whether there exists a library of the given type, with the given name
245 bool hasLibrary( LibraryContainerType _eType
, const ::rtl::OUString
& _rLibName
) const;
247 /** returns a script or dialog library given by name
250 the type of library to load
252 the name of the script library
254 <TRUE/> if and only if the library should be loaded.
256 @throws NoSuchElementException
257 if there is no script library with the given name
259 ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
>
260 getLibrary( LibraryContainerType _eType
, const ::rtl::OUString
& _rLibName
, bool _bLoadLibrary
) const
261 SAL_THROW((::com::sun::star::container::NoSuchElementException
));
263 /** creates a script or dialog library in the document, or returns an existing one
265 If <code>_rLibName</code> denotes an existing library which does not need to be created,
266 then this library will automatically be loaded, and then returned.
268 ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
>
269 getOrCreateLibrary( LibraryContainerType _eType
, const ::rtl::OUString
& _rLibName
) const;
271 /** returns the names of the modules in a given script or dialog library of the document
273 ::com::sun::star::uno::Sequence
< ::rtl::OUString
>
274 getObjectNames( LibraryContainerType _eType
, const ::rtl::OUString
& _rLibName
) const;
276 /** retrieves a name for a newly to be created module or dialog
279 createObjectName( LibraryContainerType _eType
, const ::rtl::OUString
& _rLibName
) const;
281 /** loads a script or dialog library given by name, if there is such a library
283 void loadLibraryIfExists( LibraryContainerType _eType
, const ::rtl::OUString
& _rLibrary
);
285 /// retrieves the (combined) names of all script and dialog libraries
286 ::com::sun::star::uno::Sequence
< ::rtl::OUString
>
287 getLibraryNames() const;
289 /** removes a given script module from the document
292 <TRUE/> if and only if the removal was successful. When <FALSE/> is returned,
293 this will reported as assertion in a non-product build.
295 bool removeModule( const ::rtl::OUString
& _rLibName
, const ::rtl::OUString
& _rModuleName
) const;
297 /** creates a module with the given name in the given library
301 the name of the to-be-created module
303 determines whether or not a function Main should be created
304 @param _out_rNewModuleCode
305 the source code of the newly created module
307 <TRUE/> if and only if the creation was successful
309 bool createModule( const ::rtl::OUString
& _rLibName
, const ::rtl::OUString
& _rModName
, bool _bCreateMain
, ::rtl::OUString
& _out_rNewModuleCode
) const;
311 /** inserts a given piece as code as module
313 the name of the library to insert the module into. If a library with this name does
314 not yet exist, it will be created.
316 the name of the module to insert the code as. Must denote a name which is not yet
317 used in the module library.
319 the code of the new module
321 <TRUE/> if and only if the insertion was successful.
323 bool insertModule( const ::rtl::OUString
& _rLibName
, const ::rtl::OUString
& _rModName
, const ::rtl::OUString
& _rModuleCode
) const;
325 /** updates a given module with new code
327 the name of the library the modules lives in. Must denote an existing module library.
329 the name of the module to update. Must denote an existing module in the given library.
333 <TRUE/> if and only if the insertion was successful.
335 bool updateModule( const ::rtl::OUString
& _rLibName
, const ::rtl::OUString
& _rModName
, const ::rtl::OUString
& _rModuleCode
) const;
337 /// determines whether a module with the given name exists in the given library
338 bool hasModule( const ::rtl::OUString
& _rLibName
, const ::rtl::OUString
& _rModName
) const;
340 /** retrieves a module's source
342 the library name where the module is located
345 @param _out_rModuleSource
346 takes the module's source upon successful return
348 <TRUE/> if and only if the code could be successfully retrieved, <FALSE/> otherwise
350 bool getModule( const ::rtl::OUString
& _rLibName
, const ::rtl::OUString
& _rModName
, ::rtl::OUString
& _rModuleSource
) const;
354 the library where the module lives in. Must denote an existing library.
356 the old module name. Must denote an existing module.
360 <TRUE/> if and only if renaming was successful.
362 bool renameModule( const ::rtl::OUString
& _rLibName
, const ::rtl::OUString
& _rOldName
, const ::rtl::OUString
& _rNewName
) const;
364 /** removes a given dialog from the document
367 <TRUE/> if and only if the removal was successful. When <FALSE/> is returned,
368 this will reported as assertion in a non-product build.
370 bool removeDialog( const ::rtl::OUString
& _rLibName
, const ::rtl::OUString
& _rDialogName
) const;
372 /// determines whether a dialog with the given name exists in the given library
373 bool hasDialog( const ::rtl::OUString
& _rLibName
, const ::rtl::OUString
& _rDialogName
) const;
375 /** retrieves a dialog
377 the library name where the module is located
380 @param _out_rDialogSource
381 takes the provider for the dialog's desription, upon successful return
383 <TRUE/> if and only if the dialog could be successfully retrieved, <FALSE/> otherwise
386 const ::rtl::OUString
& _rLibName
,
387 const ::rtl::OUString
& _rDialogName
,
388 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStreamProvider
>& _out_rDialogProvider
393 the library where the dialog lives in. Must denote an existing library.
395 the old dialog name. Must denote an existing dialog.
398 @param _rxExistingDialogModel
399 the existing model of the dialog, if already loaded in the IDE
401 <TRUE/> if and only if renaming was successful.
404 const ::rtl::OUString
& _rLibName
,
405 const ::rtl::OUString
& _rOldName
,
406 const ::rtl::OUString
& _rNewName
,
407 const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
>& _rxExistingDialogModel
412 the library name where the module is located
415 @param _out_rDialogSource
416 takes the provider for the dialog's desription, upon successful return
418 <TRUE/> if and only if the dialog could be successfully retrieved, <FALSE/> otherwise
421 const ::rtl::OUString
& _rLibName
,
422 const ::rtl::OUString
& _rDialogName
,
423 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStreamProvider
>& _out_rDialogProvider
426 /** inserts a given dialog into a given library
429 the name of the library to insert the dialog into. If a library with this name does
430 not yet exist, it will be created.
432 the name of the dialog to insert. Must denote a name which is not yet
433 used in the dialog library.
434 @param _rDialogProvider
435 the provider of the dialog's description
437 <TRUE/> if and only if the insertion was successful.
440 const ::rtl::OUString
& _rLibName
,
441 const ::rtl::OUString
& _rDialogName
,
442 const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStreamProvider
>& _rDialogProvider
445 /** determines whether the document is read-only
447 cannot be called if the document operates on the application-wide scripts
449 bool isReadOnly() const;
451 /** determines whether the ScriptDocument instance operates on the whole application,
452 as opposed to a real document
454 bool isApplication() const;
456 /** determines whether the ScriptDocument instance operates on a real document,
457 as opposed to the whole application
459 bool isDocument() const { return isValid() && !isApplication(); }
461 /** marks the document as modified
463 the instance operates on a real document, not on the application
466 void setDocumentModified() const;
468 /** determines whether the document is modified
470 the instance operates on a real document, not on the application
473 bool isDocumentModified() const;
475 /** saves the document, if the instance refers to a real document
477 <code>isApplication</code> returns <FALSE/>
480 const ::com::sun::star::uno::Reference
< ::com::sun::star::task::XStatusIndicator
>& _rxStatusIndicator
483 /// returns the location of a library given by name
485 getLibraryLocation( const ::rtl::OUString
& _rLibName
) const;
487 /// returns the title for the document
489 getTitle( LibraryLocation _eLocation
, LibraryType _eType
= LIBRARY_TYPE_ALL
) const;
491 /** returns the title of the document
493 to be used for valid documents only
498 /** returns the URL of the document
500 to be used for valid documents only
505 /** determines whether the document is currently the one-and-only application-wide active document
507 bool isActive() const;
509 /** determines whether macro execution for this document is allowed
511 only to be called for real documents (->isDocument)
513 bool allowMacros() const;
516 //........................................................................
517 } // namespace basctl
518 //........................................................................
520 // convenience ... better would be all classes in the project are in
521 // the same namespace ...
522 using ::basctl::ScriptDocument
;
523 using ::basctl::ScriptDocuments
;
524 using ::basctl::E_SCRIPTS
;
525 using ::basctl::E_DIALOGS
;
526 using ::basctl::LibraryLocation
;
527 using ::basctl::LIBRARY_LOCATION_UNKNOWN
;
528 using ::basctl::LIBRARY_LOCATION_USER
;
529 using ::basctl::LIBRARY_LOCATION_SHARE
;
530 using ::basctl::LIBRARY_LOCATION_DOCUMENT
;
531 using ::basctl::LibraryType
;
532 using ::basctl::LIBRARY_TYPE_UNKNOWN
;
533 using ::basctl::LIBRARY_TYPE_MODULE
;
534 using ::basctl::LIBRARY_TYPE_DIALOG
;
535 using ::basctl::LIBRARY_TYPE_ALL
;
537 #endif // SCRIPTDOCUMENT_HXX