1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: scriptdocument.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef SCRIPTDOCUMENT_HXX
32 #define SCRIPTDOCUMENT_HXX
34 /** === begin UNO includes === **/
35 #include <com/sun/star/script/XLibraryContainer.hpp>
36 #include <com/sun/star/frame/XModel.hpp>
37 #include <com/sun/star/task/XStatusIndicator.hpp>
38 #include <com/sun/star/io/XInputStreamProvider.hpp>
39 /** === end UNO includes === **/
41 #include <boost/shared_ptr.hpp>
47 //........................................................................
50 //........................................................................
52 //====================================================================
53 //= LibraryContainerType
54 //====================================================================
55 enum LibraryContainerType
63 LIBRARY_LOCATION_UNKNOWN
,
64 LIBRARY_LOCATION_USER
,
65 LIBRARY_LOCATION_SHARE
,
66 LIBRARY_LOCATION_DOCUMENT
77 //====================================================================
79 //====================================================================
80 class ScriptDocument_Impl
;
83 typedef ::std::vector
< ScriptDocument
> ScriptDocuments
;
85 /** encapsulates a document which contains Basic scripts and dialogs
90 ::boost::shared_ptr
< ScriptDocument_Impl
> m_pImpl
;
93 /** creates a ScriptDocument instance which operates on the application-wide
99 enum SpecialDocument
{ NoDocument
};
100 /** creates a ScriptDocument instance which does refers to neither the application-wide,
101 nor a specific real document's scripts.
103 This constructor might come handy when you need some kind of uninitialized
104 ScriptDocument, which you do not want to operate on (yet), but initialize later
107 <member>isValid</member> will return <FALSE/> for a ScriptDocument constructed
110 explicit ScriptDocument( SpecialDocument _eType
);
112 /** creates a ScriptDocument instance which refers to a document given as
116 the document. Must not be <NULL/>.
118 explicit ScriptDocument( const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
>& _rxDocument
);
121 ScriptDocument( const ScriptDocument
& _rSource
);
126 /** returns a reference to a shared ScriptDocument instance which
127 operates on the application-wide scripts and dialogs
129 static const ScriptDocument
&
130 getApplicationScriptDocument();
132 /** returns a (newly created) ScriptDocument instance for the document to
133 which a given BasicManager belongs
135 If the basic manager is the application's basic manager, then the (shared)
136 ScriptDocument instance which is responsible for the application is returned.
138 @see getApplicationScriptDocument
140 static ScriptDocument
141 getDocumentForBasicManager( const BasicManager
* _pManager
);
143 /** returns a (newly created) ScriptDocument instance for the document
144 with a given caption or URL
146 If there is no document with the given caption, then the (shared)
147 ScriptDocument instance which is responsible for the application is returned.
149 @see getApplicationScriptDocument
151 static ScriptDocument
152 getDocumentWithURLOrCaption( const ::rtl::OUString
& _rUrlOrCaption
);
154 /** operation mode for getAllScriptDocuments
156 enum ScriptDocumentList
158 /** all ScriptDocuments, including the dedicated one which represents
159 the application-wide scripts/dialogs.
162 /** real documents only
165 /** real documents only, sorted lexicographically by their title (using the sys locale's default
171 /** returns the set of ScriptDocument instances, one for each open document which
172 contains Basic/Dialog containers; plus an additional instance for
173 the application, if desired
175 Documents which are not visible - i.e. do not have a visible frame.
177 @param _bIncludingApplication
178 <TRUE/> if the application-wide scripts/dialogs should also be represented
181 static ScriptDocuments
182 getAllScriptDocuments( ScriptDocumentList _eListType
);
185 bool operator==( const ScriptDocument
& _rhs
) const;
186 inline bool operator!=( const ScriptDocument
& _rhs
) const { return !( *this == _rhs
); }
188 /// retrieves a (pretty simple) hash code for the document
189 sal_Int32
hashCode() const;
191 /** determines whether the document is actually able to contain Basic/Dialog libraries
193 Note that validity does not automatically imply the document can be used for active
194 work. Instead, it is possible the document is closed already (or being closed currently).
195 In this case, isValid will return <TRUE/>, but isAlive will return <FALSE/>.
198 <TRUE/> if the instance refers to a document which contains Basic/Dialog libraries,
199 or the application as a whole, <FALSE/> otherwise.
203 bool isValid() const;
205 /** determines whether the document instance is alive
207 If the instance is not valid, <FALSE/> is returned.
209 If the instance refers to a real document, which is already closed, or just being closed,
210 the method returns <FALSE/>.
212 If the instance refers to the application, <TRUE/> is returned.
216 bool isAlive() const;
218 /// returns the BasicManager associated with this instance
220 getBasicManager() const;
222 /** returns the UNO component representing the document which the instance operates on
224 Must not be used when the instance operates on the application-wide
225 Basic/Dialog libraries.
227 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
>
230 /** returns the UNO component representing the document which the instance operates on
232 May be used when the instance operates on the application-wide
233 Basic/Dialog libraries, in this case it returns <NULL/>.
235 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
>
236 getDocumentOrNull() const;
238 /** returns the Basic or Dialog library container of the document
240 If the document is not valid, <NULL/> is returned.
242 ::com::sun::star::uno::Reference
< ::com::sun::star::script::XLibraryContainer
>
243 getLibraryContainer( LibraryContainerType _eType
) const;
245 /** determines whether there exists a library of the given type, with the given name
247 bool hasLibrary( LibraryContainerType _eType
, const ::rtl::OUString
& _rLibName
) const;
249 /** returns a script or dialog library given by name
252 the type of library to load
254 the name of the script library
256 <TRUE/> if and only if the library should be loaded.
258 @throws NoSuchElementException
259 if there is no script library with the given name
261 ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
>
262 getLibrary( LibraryContainerType _eType
, const ::rtl::OUString
& _rLibName
, bool _bLoadLibrary
) const
263 SAL_THROW((::com::sun::star::container::NoSuchElementException
));
265 /** creates a script or dialog library in the document, or returns an existing one
267 If <code>_rLibName</code> denotes an existing library which does not need to be created,
268 then this library will automatically be loaded, and then returned.
270 ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
>
271 getOrCreateLibrary( LibraryContainerType _eType
, const ::rtl::OUString
& _rLibName
) const;
273 /** returns the names of the modules in a given script or dialog library of the document
275 ::com::sun::star::uno::Sequence
< ::rtl::OUString
>
276 getObjectNames( LibraryContainerType _eType
, const ::rtl::OUString
& _rLibName
) const;
278 /** retrieves a name for a newly to be created module or dialog
281 createObjectName( LibraryContainerType _eType
, const ::rtl::OUString
& _rLibName
) const;
283 /** loads a script or dialog library given by name, if there is such a library
285 void loadLibraryIfExists( LibraryContainerType _eType
, const ::rtl::OUString
& _rLibrary
);
287 /// retrieves the (combined) names of all script and dialog libraries
288 ::com::sun::star::uno::Sequence
< ::rtl::OUString
>
289 getLibraryNames() const;
291 /** removes a given script module from the document
294 <TRUE/> if and only if the removal was successful. When <FALSE/> is returned,
295 this will reported as assertion in a non-product build.
297 bool removeModule( const ::rtl::OUString
& _rLibName
, const ::rtl::OUString
& _rModuleName
) const;
299 /** creates a module with the given name in the given library
303 the name of the to-be-created module
305 determines whether or not a function Main should be created
306 @param _out_rNewModuleCode
307 the source code of the newly created module
309 <TRUE/> if and only if the creation was successful
311 bool createModule( const ::rtl::OUString
& _rLibName
, const ::rtl::OUString
& _rModName
, bool _bCreateMain
, ::rtl::OUString
& _out_rNewModuleCode
) const;
313 /** inserts a given piece as code as module
315 the name of the library to insert the module into. If a library with this name does
316 not yet exist, it will be created.
318 the name of the module to insert the code as. Must denote a name which is not yet
319 used in the module library.
321 the code of the new module
323 <TRUE/> if and only if the insertion was successful.
325 bool insertModule( const ::rtl::OUString
& _rLibName
, const ::rtl::OUString
& _rModName
, const ::rtl::OUString
& _rModuleCode
) const;
327 /** updates a given module with new code
329 the name of the library the modules lives in. Must denote an existing module library.
331 the name of the module to update. Must denote an existing module in the given library.
335 <TRUE/> if and only if the insertion was successful.
337 bool updateModule( const ::rtl::OUString
& _rLibName
, const ::rtl::OUString
& _rModName
, const ::rtl::OUString
& _rModuleCode
) const;
339 /// determines whether a module with the given name exists in the given library
340 bool hasModule( const ::rtl::OUString
& _rLibName
, const ::rtl::OUString
& _rModName
) const;
342 /** retrieves a module's source
344 the library name where the module is located
347 @param _out_rModuleSource
348 takes the module's source upon successful return
350 <TRUE/> if and only if the code could be successfully retrieved, <FALSE/> otherwise
352 bool getModule( const ::rtl::OUString
& _rLibName
, const ::rtl::OUString
& _rModName
, ::rtl::OUString
& _rModuleSource
) const;
356 the library where the module lives in. Must denote an existing library.
358 the old module name. Must denote an existing module.
362 <TRUE/> if and only if renaming was successful.
364 bool renameModule( const ::rtl::OUString
& _rLibName
, const ::rtl::OUString
& _rOldName
, const ::rtl::OUString
& _rNewName
) const;
366 /** removes a given dialog from the document
369 <TRUE/> if and only if the removal was successful. When <FALSE/> is returned,
370 this will reported as assertion in a non-product build.
372 bool removeDialog( const ::rtl::OUString
& _rLibName
, const ::rtl::OUString
& _rDialogName
) const;
374 /// determines whether a dialog with the given name exists in the given library
375 bool hasDialog( const ::rtl::OUString
& _rLibName
, const ::rtl::OUString
& _rDialogName
) const;
377 /** retrieves a dialog
379 the library name where the module is located
382 @param _out_rDialogSource
383 takes the provider for the dialog's desription, upon successful return
385 <TRUE/> if and only if the dialog could be successfully retrieved, <FALSE/> otherwise
388 const ::rtl::OUString
& _rLibName
,
389 const ::rtl::OUString
& _rDialogName
,
390 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStreamProvider
>& _out_rDialogProvider
395 the library where the dialog lives in. Must denote an existing library.
397 the old dialog name. Must denote an existing dialog.
400 @param _rxExistingDialogModel
401 the existing model of the dialog, if already loaded in the IDE
403 <TRUE/> if and only if renaming was successful.
406 const ::rtl::OUString
& _rLibName
,
407 const ::rtl::OUString
& _rOldName
,
408 const ::rtl::OUString
& _rNewName
,
409 const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
>& _rxExistingDialogModel
414 the library name where the module is located
417 @param _out_rDialogSource
418 takes the provider for the dialog's desription, upon successful return
420 <TRUE/> if and only if the dialog could be successfully retrieved, <FALSE/> otherwise
423 const ::rtl::OUString
& _rLibName
,
424 const ::rtl::OUString
& _rDialogName
,
425 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStreamProvider
>& _out_rDialogProvider
428 /** inserts a given dialog into a given library
431 the name of the library to insert the dialog into. If a library with this name does
432 not yet exist, it will be created.
434 the name of the dialog to insert. Must denote a name which is not yet
435 used in the dialog library.
436 @param _rDialogProvider
437 the provider of the dialog's description
439 <TRUE/> if and only if the insertion was successful.
442 const ::rtl::OUString
& _rLibName
,
443 const ::rtl::OUString
& _rDialogName
,
444 const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStreamProvider
>& _rDialogProvider
447 /** determines whether the document is read-only
449 cannot be called if the document operates on the application-wide scripts
451 bool isReadOnly() const;
453 /** determines whether the ScriptDocument instance operates on the whole application,
454 as opposed to a real document
456 bool isApplication() const;
458 /** determines whether the ScriptDocument instance operates on a real document,
459 as opposed to the whole application
461 bool isDocument() const { return isValid() && !isApplication(); }
463 /** marks the document as modified
465 the instance operates on a real document, not on the application
468 void setDocumentModified() const;
470 /** determines whether the document is modified
472 the instance operates on a real document, not on the application
475 bool isDocumentModified() const;
477 /** saves the document, if the instance refers to a real document
479 <code>isApplication</code> returns <FALSE/>
482 const ::com::sun::star::uno::Reference
< ::com::sun::star::task::XStatusIndicator
>& _rxStatusIndicator
485 /// returns the location of a library given by name
487 getLibraryLocation( const ::rtl::OUString
& _rLibName
) const;
489 /// returns the title for the document
491 getTitle( LibraryLocation _eLocation
, LibraryType _eType
= LIBRARY_TYPE_ALL
) const;
493 /** returns the title of the document
495 to be used for valid documents only
500 /** returns the URL of the document
502 to be used for valid documents only
507 /** determines whether the document is currently the one-and-only application-wide active document
509 bool isActive() const;
511 /** determines whether macro execution for this document is allowed
513 only to be called for real documents (->isDocument)
515 bool allowMacros() const;
518 //........................................................................
519 } // namespace basctl
520 //........................................................................
522 // convenience ... better would be all classes in the project are in
523 // the same namespace ...
524 using ::basctl::ScriptDocument
;
525 using ::basctl::ScriptDocuments
;
526 using ::basctl::E_SCRIPTS
;
527 using ::basctl::E_DIALOGS
;
528 using ::basctl::LibraryLocation
;
529 using ::basctl::LIBRARY_LOCATION_UNKNOWN
;
530 using ::basctl::LIBRARY_LOCATION_USER
;
531 using ::basctl::LIBRARY_LOCATION_SHARE
;
532 using ::basctl::LIBRARY_LOCATION_DOCUMENT
;
533 using ::basctl::LibraryType
;
534 using ::basctl::LIBRARY_TYPE_UNKNOWN
;
535 using ::basctl::LIBRARY_TYPE_MODULE
;
536 using ::basctl::LIBRARY_TYPE_DIALOG
;
537 using ::basctl::LIBRARY_TYPE_ALL
;
539 #endif // SCRIPTDOCUMENT_HXX