1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef BASICMANAGERREPOSITORY_HXX
25 #define BASICMANAGERREPOSITORY_HXX
26 
27 /** === begin UNO includes === **/
28 #include <com/sun/star/frame/XModel.hpp>
29 #include <com/sun/star/embed/XStorage.hpp>
30 /** === end UNO includes === **/
31 
32 class BasicManager;
33 
34 //........................................................................
35 namespace basic
36 {
37 //........................................................................
38 
39 	//====================================================================
40 	//= BasicManagerRepository
41 	//====================================================================
42     /** specifies a callback for instances which are interested in BasicManagers
43         created by the BasicManagerRepository.
44     */
45     class SAL_NO_VTABLE BasicManagerCreationListener
46     {
47     public:
48         /** is called when a BasicManager has been created
49 
50             @param  _rxForDocument
51                 denotes the document for which the BasicManager has been created. If this is <NULL/>,
52                 then the BasicManager is the application-wide BasicManager.
53 
54             @param  _pBasicManager
55                 denotes the BasicManager which has been created. The listener might for instance
56                 decide to add global variables to it, or otherwise initialize it.
57         */
58         virtual void onBasicManagerCreated(
59             const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& _rxForDocument,
60             BasicManager& _rBasicManager
61         ) = 0;
62     };
63 
64 	//====================================================================
65 	//= BasicManagerRepository
66 	//====================================================================
67 	class BasicManagerRepository
68 	{
69     public:
70         /** returns the BasicManager belonging to the given document
71 
72             If the BasicManager does not yet exist, it is created. In this case, if the application's
73             BasicManager does not yet exist, it is also created. This is necessary since
74             the application's BasicManager acts as parent for all document's BasicManagers.
75 
76             If you're interested in this case - the implicit creation of the application's BasicManager -,
77             then you need to register as BasicManagerCreationListener.
78 
79             @param _rxDocumentModel
80                 denotes the document model whose BasicManager is to be retrieved. Must not be <NULL/>.
81                 The document should support the XDocumentInfoSupplier interface, for retrieving
82                 its title, which is needed in some error conditions.
83                 Also it <em>must</em> support the XStorageBasedDocument interface, since we
84                 must be able to retrieve the document's storage. If this interface is <em>not</em>
85                 supported, creating a new BasicManager will certainly fail.
86 
87             @return
88                 the BasicManager for this model.
89 
90             @attention
91                 The returned BasicManager instances is owned by the repository. In particular,
92                 you are not allowed to delete it. Instead, the given model is observed: As soon
93                 as it's closed, the associated BasicManager is deleted.
94         */
95         static BasicManager* getDocumentBasicManager(
96             const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& _rxDocumentModel
97         );
98 
99         /** returns the application-wide BasicManager
100 
101         @param _bCreate
102             determines whether the BasicManager should be created (<TRUE/>) if it
103             does not yet exist.
104 
105         @attention
106             If the BasicManager is newly created, then it is still owned by the repository.
107             In particular, you are not allowed to delete it. Instead, call resetApplicationBasicManager
108             to release the BasicManager.
109         */
110         static BasicManager* getApplicationBasicManager( bool _bCreate );
111 
112         /** resets the application-wide BasicManager to <NULL/>
113         */
114         static void resetApplicationBasicManager();
115 
116         /** registers a BasicManagerCreationListener instance which is notified whenever
117             the repository creates a BasicManager instance.
118 
119             Note that this listener is <em>not</em> called when somebody else
120             creates BasicManager instances.
121 
122             If the same listener is registered multiple times, it is also notified
123             multiple times, and needs to be revoked once for each registration.
124         */
125         static  void    registerCreationListener(
126                 BasicManagerCreationListener& _rListener
127             );
128 
129         /** reveokes a BasicManagerCreationListener instance which has previously
130             been registered to be notified about created BasicManager instances.
131         */
132         static  void    revokeCreationListener(
133                 BasicManagerCreationListener& _rListener
134             );
135 	};
136 
137 //........................................................................
138 } // namespace basic
139 //........................................................................
140 
141 #endif // BASICMANAGERREPOSITORY_HXX
142 
143