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 BASCTL_SCRIPTDOCUMENT_HXX
21 #define BASCTL_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>
35 //........................................................................
38 //........................................................................
40 //====================================================================
41 //= LibraryContainerType
42 //====================================================================
43 enum LibraryContainerType
51 LIBRARY_LOCATION_UNKNOWN
,
52 LIBRARY_LOCATION_USER
,
53 LIBRARY_LOCATION_SHARE
,
54 LIBRARY_LOCATION_DOCUMENT
65 //====================================================================
67 //====================================================================
69 typedef ::std::vector
< ScriptDocument
> ScriptDocuments
;
71 /** encapsulates a document which contains Basic scripts and dialogs
77 boost::shared_ptr
<Impl
> m_pImpl
;
80 /** creates a ScriptDocument instance which operates on the application-wide
86 enum SpecialDocument
{ NoDocument
};
87 /** creates a ScriptDocument instance which does refers to neither the application-wide,
88 nor a specific real document's scripts.
90 This constructor might come handy when you need some kind of uninitialized
91 ScriptDocument, which you do not want to operate on (yet), but initialize later
94 <member>isValid</member> will return <FALSE/> for a ScriptDocument constructed
97 explicit ScriptDocument( SpecialDocument _eType
);
99 /** creates a ScriptDocument instance which refers to a document given as
103 the document. Must not be <NULL/>.
105 explicit ScriptDocument( const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
>& _rxDocument
);
108 ScriptDocument( const ScriptDocument
& _rSource
);
113 /** returns a reference to a shared ScriptDocument instance which
114 operates on the application-wide scripts and dialogs
116 static const ScriptDocument
&
117 getApplicationScriptDocument();
119 /** returns a (newly created) ScriptDocument instance for the document to
120 which a given BasicManager belongs
122 If the basic manager is the application's basic manager, then the (shared)
123 ScriptDocument instance which is responsible for the application is returned.
125 @see getApplicationScriptDocument
127 static ScriptDocument
128 getDocumentForBasicManager( const BasicManager
* _pManager
);
130 /** returns a (newly created) ScriptDocument instance for the document
131 with a given caption or URL
133 If there is no document with the given caption, then the (shared)
134 ScriptDocument instance which is responsible for the application is returned.
136 @see getApplicationScriptDocument
138 static ScriptDocument
139 getDocumentWithURLOrCaption( const OUString
& _rUrlOrCaption
);
141 /** operation mode for getAllScriptDocuments
143 enum ScriptDocumentList
145 /** all ScriptDocuments, including the dedicated one which represents
146 the application-wide scripts/dialogs.
149 /** real documents only
152 /** real documents only, sorted lexicographically by their title (using the sys locale's default
158 /** returns the set of ScriptDocument instances, one for each open document which
159 contains Basic/Dialog containers; plus an additional instance for
160 the application, if desired
162 Documents which are not visible - i.e. do not have a visible frame.
164 @param _bIncludingApplication
165 <TRUE/> if the application-wide scripts/dialogs should also be represented
168 static ScriptDocuments
169 getAllScriptDocuments( ScriptDocumentList _eListType
);
172 bool operator==( const ScriptDocument
& _rhs
) const;
173 inline bool operator!=( const ScriptDocument
& _rhs
) const { return !( *this == _rhs
); }
175 /// retrieves a (pretty simple) hash code for the document
176 sal_Int32
hashCode() const;
178 /** determines whether the document is actually able to contain Basic/Dialog libraries
180 Note that validity does not automatically imply the document can be used for active
181 work. Instead, it is possible the document is closed already (or being closed currently).
182 In this case, isValid will return <TRUE/>, but isAlive will return <FALSE/>.
185 <TRUE/> if the instance refers to a document which contains Basic/Dialog libraries,
186 or the application as a whole, <FALSE/> otherwise.
190 bool isValid() const;
192 /** determines whether the document instance is alive
194 If the instance is not valid, <FALSE/> is returned.
196 If the instance refers to a real document, which is already closed, or just being closed,
197 the method returns <FALSE/>.
199 If the instance refers to the application, <TRUE/> is returned.
203 bool isAlive() const;
205 bool isInVBAMode() const;
206 /// returns the BasicManager associated with this instance
208 getBasicManager() const;
210 /** returns the UNO component representing the document which the instance operates on
212 Must not be used when the instance operates on the application-wide
213 Basic/Dialog libraries.
215 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
>
218 /** returns the UNO component representing the document which the instance operates on
220 May be used when the instance operates on the application-wide
221 Basic/Dialog libraries, in this case it returns <NULL/>.
223 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
>
224 getDocumentOrNull() const;
226 /** returns the Basic or Dialog library container of the document
228 If the document is not valid, <NULL/> is returned.
230 ::com::sun::star::uno::Reference
< ::com::sun::star::script::XLibraryContainer
>
231 getLibraryContainer( LibraryContainerType _eType
) const;
233 /** determines whether there exists a library of the given type, with the given name
235 bool hasLibrary( LibraryContainerType _eType
, const OUString
& _rLibName
) const;
237 /** returns a script or dialog library given by name
240 the type of library to load
242 the name of the script library
244 <TRUE/> if and only if the library should be loaded.
246 @throws NoSuchElementException
247 if there is no script library with the given name
249 ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
>
250 getLibrary( LibraryContainerType _eType
, const OUString
& _rLibName
, bool _bLoadLibrary
) const
251 SAL_THROW((::com::sun::star::container::NoSuchElementException
));
253 /** creates a script or dialog library in the document, or returns an existing one
255 If <code>_rLibName</code> denotes an existing library which does not need to be created,
256 then this library will automatically be loaded, and then returned.
258 ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
>
259 getOrCreateLibrary( LibraryContainerType _eType
, const OUString
& _rLibName
) const;
261 /** returns the names of the modules in a given script or dialog library of the document
263 ::com::sun::star::uno::Sequence
< OUString
>
264 getObjectNames( LibraryContainerType _eType
, const OUString
& _rLibName
) const;
266 /** retrieves a name for a newly to be created module or dialog
268 OUString
createObjectName( LibraryContainerType _eType
, const OUString
& _rLibName
) const;
270 /** loads a script or dialog library given by name, if there is such a library
272 void loadLibraryIfExists( LibraryContainerType _eType
, const OUString
& _rLibrary
);
274 /// retrieves the (combined) names of all script and dialog libraries
275 ::com::sun::star::uno::Sequence
< OUString
>
276 getLibraryNames() const;
278 /** removes a given script module from the document
281 <TRUE/> if and only if the removal was successful. When <FALSE/> is returned,
282 this will reported as assertion in a non-product build.
284 bool removeModule( const OUString
& _rLibName
, const OUString
& _rModuleName
) const;
286 /** creates a module with the given name in the given library
290 the name of the to-be-created module
292 determines whether or not a function Main should be created
293 @param _out_rNewModuleCode
294 the source code of the newly created module
296 <TRUE/> if and only if the creation was successful
298 bool createModule( const OUString
& _rLibName
, const OUString
& _rModName
, bool _bCreateMain
, OUString
& _out_rNewModuleCode
) const;
300 /** inserts a given piece as code as module
302 the name of the library to insert the module into. If a library with this name does
303 not yet exist, it will be created.
305 the name of the module to insert the code as. Must denote a name which is not yet
306 used in the module library.
308 the code of the new module
310 <TRUE/> if and only if the insertion was successful.
312 bool insertModule( const OUString
& _rLibName
, const OUString
& _rModName
, const OUString
& _rModuleCode
) const;
314 /** updates a given module with new code
316 the name of the library the modules lives in. Must denote an existing module library.
318 the name of the module to update. Must denote an existing module in the given library.
322 <TRUE/> if and only if the insertion was successful.
324 bool updateModule( const OUString
& _rLibName
, const OUString
& _rModName
, const OUString
& _rModuleCode
) const;
326 /// determines whether a module with the given name exists in the given library
327 bool hasModule( const OUString
& _rLibName
, const OUString
& _rModName
) const;
329 /** retrieves a module's source
331 the library name where the module is located
334 @param _out_rModuleSource
335 takes the module's source upon successful return
337 <TRUE/> if and only if the code could be successfully retrieved, <FALSE/> otherwise
339 bool getModule( const OUString
& _rLibName
, const OUString
& _rModName
, OUString
& _rModuleSource
) const;
343 the library where the module lives in. Must denote an existing library.
345 the old module name. Must denote an existing module.
349 <TRUE/> if and only if renaming was successful.
351 bool renameModule( const OUString
& _rLibName
, const OUString
& _rOldName
, const OUString
& _rNewName
) const;
353 /** removes a given dialog from the document
356 <TRUE/> if and only if the removal was successful. When <FALSE/> is returned,
357 this will reported as assertion in a non-product build.
359 bool removeDialog( const OUString
& _rLibName
, const OUString
& _rDialogName
) const;
361 /// determines whether a dialog with the given name exists in the given library
362 bool hasDialog( const OUString
& _rLibName
, const OUString
& _rDialogName
) const;
364 /** retrieves a dialog
366 the library name where the module is located
369 @param _out_rDialogSource
370 takes the provider for the dialog's desription, upon successful return
372 <TRUE/> if and only if the dialog could be successfully retrieved, <FALSE/> otherwise
375 const OUString
& _rLibName
,
376 const OUString
& _rDialogName
,
377 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStreamProvider
>& _out_rDialogProvider
382 the library where the dialog lives in. Must denote an existing library.
384 the old dialog name. Must denote an existing dialog.
387 @param _rxExistingDialogModel
388 the existing model of the dialog, if already loaded in the IDE
390 <TRUE/> if and only if renaming was successful.
393 const OUString
& _rLibName
,
394 const OUString
& _rOldName
,
395 const OUString
& _rNewName
,
396 const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
>& _rxExistingDialogModel
401 the library name where the module is located
404 @param _out_rDialogSource
405 takes the provider for the dialog's desription, upon successful return
407 <TRUE/> if and only if the dialog could be successfully retrieved, <FALSE/> otherwise
410 const OUString
& _rLibName
,
411 const OUString
& _rDialogName
,
412 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStreamProvider
>& _out_rDialogProvider
415 /** inserts a given dialog into a given library
418 the name of the library to insert the dialog into. If a library with this name does
419 not yet exist, it will be created.
421 the name of the dialog to insert. Must denote a name which is not yet
422 used in the dialog library.
423 @param _rDialogProvider
424 the provider of the dialog's description
426 <TRUE/> if and only if the insertion was successful.
429 const OUString
& _rLibName
,
430 const OUString
& _rDialogName
,
431 const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStreamProvider
>& _rDialogProvider
434 /** determines whether the document is read-only
436 cannot be called if the document operates on the application-wide scripts
438 bool isReadOnly() const;
440 /** determines whether the ScriptDocument instance operates on the whole application,
441 as opposed to a real document
443 bool isApplication() const;
445 /** determines whether the ScriptDocument instance operates on a real document,
446 as opposed to the whole application
448 bool isDocument() const { return isValid() && !isApplication(); }
450 /** marks the document as modified
452 the instance operates on a real document, not on the application
455 void setDocumentModified() const;
457 /** determines whether the document is modified
459 the instance operates on a real document, not on the application
462 bool isDocumentModified() const;
464 /** saves the document, if the instance refers to a real document
466 <code>isApplication</code> returns <FALSE/>
469 const ::com::sun::star::uno::Reference
< ::com::sun::star::task::XStatusIndicator
>& _rxStatusIndicator
472 /// returns the location of a library given by name
474 getLibraryLocation( const OUString
& _rLibName
) const;
476 /// returns the title for the document
477 OUString
getTitle( LibraryLocation _eLocation
, LibraryType _eType
= LIBRARY_TYPE_ALL
) const;
479 /** returns the title of the document
481 to be used for valid documents only
483 OUString
getTitle() const;
485 /** returns the URL of the document
487 to be used for valid documents only
489 OUString
getURL() const;
491 /** determines whether the document is currently the one-and-only application-wide active document
493 bool isActive() const;
495 /** determines whether macro execution for this document is allowed
497 only to be called for real documents (->isDocument)
499 bool allowMacros() const;
502 //........................................................................
503 } // namespace basctl
504 //........................................................................
506 #endif // BASCTL_SCRIPTDOCUMENT_HXX
508 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */