xref: /trunk/main/ucb/source/ucp/tdoc/tdoc_docmgr.hxx (revision 6df1ea1f)
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 INCLUDED_TDOC_DOCMGR_HXX
25 #define INCLUDED_TDOC_DOCMGR_HXX
26 
27 #include <map>
28 
29 #include "osl/mutex.hxx"
30 
31 #include "cppuhelper/implbase1.hxx"
32 
33 #include "com/sun/star/document/XEventBroadcaster.hpp"
34 #include "com/sun/star/document/XEventListener.hpp"
35 #include "com/sun/star/embed/XStorage.hpp"
36 #include "com/sun/star/frame/XModel.hpp"
37 #include "com/sun/star/frame/XModuleManager.hpp"
38 #include "com/sun/star/util/XCloseListener.hpp"
39 
40 namespace tdoc_ucp {
41 
42     class OfficeDocumentsEventListener
43     {
44     public:
45         virtual void notifyDocumentOpened( const rtl::OUString & rDocId ) = 0;
46         virtual void notifyDocumentClosed( const rtl::OUString & rDocId ) = 0;
47     };
48 
49     //=======================================================================
50 
51     struct StorageInfo
52     {
53         rtl::OUString aTitle;
54         com::sun::star::uno::Reference<
55             com::sun::star::embed::XStorage > xStorage;
56         com::sun::star::uno::Reference<
57             com::sun::star::frame::XModel >   xModel;
58 
StorageInfotdoc_ucp::StorageInfo59         StorageInfo() {}; // needed for STL map only.
60 
StorageInfotdoc_ucp::StorageInfo61         StorageInfo(
62             const rtl::OUString & rTitle,
63             const com::sun::star::uno::Reference<
64                 com::sun::star::embed::XStorage > & rxStorage,
65             const com::sun::star::uno::Reference<
66                 com::sun::star::frame::XModel > & rxModel )
67         : aTitle( rTitle ), xStorage( rxStorage ), xModel( rxModel ) {}
68     };
69 
70     //=======================================================================
71 
72     struct ltref
73     {
operator ()tdoc_ucp::ltref74         bool operator()(
75             const rtl::OUString & r1, const rtl::OUString & r2 ) const
76         {
77             return r1 < r2;
78         }
79     };
80 
81     typedef std::map< rtl::OUString, StorageInfo, ltref > DocumentList;
82 
83     //=======================================================================
84 
85     class OfficeDocumentsManager :
86         public cppu::WeakImplHelper1< com::sun::star::document::XEventListener >
87     {
88         class OfficeDocumentsCloseListener :
89            public cppu::WeakImplHelper1< com::sun::star::util::XCloseListener >
90 
91         {
92         public:
OfficeDocumentsCloseListener(OfficeDocumentsManager * pMgr)93             OfficeDocumentsCloseListener( OfficeDocumentsManager * pMgr )
94             : m_pManager( pMgr ) {};
95 
96             // util::XCloseListener
97             virtual void SAL_CALL queryClosing(
98                     const ::com::sun::star::lang::EventObject& Source,
99                     ::sal_Bool GetsOwnership )
100                 throw (::com::sun::star::util::CloseVetoException,
101                        ::com::sun::star::uno::RuntimeException);
102 
103             virtual void SAL_CALL notifyClosing(
104                     const ::com::sun::star::lang::EventObject& Source )
105                 throw (::com::sun::star::uno::RuntimeException);
106 
107             // lang::XEventListener (base of util::XCloseListener)
108             virtual void SAL_CALL disposing(
109                     const com::sun::star::lang::EventObject & Source )
110                 throw ( com::sun::star::uno::RuntimeException );
111         private:
112             OfficeDocumentsManager * m_pManager;
113         };
114 
115     public:
116         OfficeDocumentsManager(
117             const com::sun::star::uno::Reference<
118                 com::sun::star::lang::XMultiServiceFactory > & xSMgr,
119             OfficeDocumentsEventListener * pDocEventListener );
120         virtual ~OfficeDocumentsManager();
121 
122         void destroy();
123 
124         // document::XEventListener
125         virtual void SAL_CALL notifyEvent(
126                 const com::sun::star::document::EventObject & Event )
127             throw ( com::sun::star::uno::RuntimeException );
128 
129         // lang::XEventListener (base of document::XEventListener)
130         virtual void SAL_CALL disposing(
131                 const com::sun::star::lang::EventObject & Source )
132             throw ( com::sun::star::uno::RuntimeException );
133 
134         // Non-interface
135         com::sun::star::uno::Reference< com::sun::star::embed::XStorage >
136         queryStorage( const rtl::OUString & rDocId );
137 
138         rtl::OUString
139         queryDocumentId(
140             const com::sun::star::uno::Reference<
141                 com::sun::star::frame::XModel > & xModel );
142 
143         com::sun::star::uno::Reference< com::sun::star::frame::XModel >
144         queryDocumentModel( const rtl::OUString & rDocId );
145 
146         com::sun::star::uno::Sequence< rtl::OUString >
147         queryDocuments();
148 
149         rtl::OUString
150         queryStorageTitle( const rtl::OUString & rDocId );
151 
152     private:
153         static com::sun::star::uno::Reference<
154             com::sun::star::document::XEventBroadcaster >
155         createDocumentEventNotifier(
156             const com::sun::star::uno::Reference<
157                 com::sun::star::lang::XMultiServiceFactory >& rXSMgr );
158 
159         void buildDocumentsList();
160 
161         bool
162         isOfficeDocument(
163             const com::sun::star::uno::Reference<
164                 com::sun::star::uno::XInterface > & xDoc );
165 
166         bool
167         isDocumentPreview(
168             const com::sun::star::uno::Reference<
169                 com::sun::star::frame::XModel > & xModel );
170 
171         bool
172         isWithoutOrInTopLevelFrame(
173             const com::sun::star::uno::Reference<
174                 com::sun::star::frame::XModel > & xModel );
175 
176         bool
177         isBasicIDE(
178             const com::sun::star::uno::Reference<
179                 com::sun::star::frame::XModel > & xModel );
180 
181         bool
182         isHelpDocument(
183             const com::sun::star::uno::Reference<
184                 com::sun::star::frame::XModel > & xModel );
185 
186         osl::Mutex                                          m_aMtx;
187         com::sun::star::uno::Reference<
188             com::sun::star::lang::XMultiServiceFactory >    m_xSMgr;
189         com::sun::star::uno::Reference<
190             com::sun::star::document::XEventBroadcaster >   m_xDocEvtNotifier;
191         com::sun::star::uno::Reference<
192             com::sun::star::frame::XModuleManager >         m_xModuleMgr;
193         DocumentList                                        m_aDocs;
194         OfficeDocumentsEventListener *                      m_pDocEventListener;
195         com::sun::star::uno::Reference<
196             com::sun::star::util::XCloseListener >          m_xDocCloseListener;
197     };
198 
199 } // namespace tdoc_ucp
200 
201 #endif /* !INCLUDED_TDOC_DOCMGR_HXX */
202