xref: /trunk/main/ucb/source/ucp/tdoc/tdoc_docmgr.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 
101             virtual void SAL_CALL notifyClosing(
102                     const ::com::sun::star::lang::EventObject& Source );
103 
104             // lang::XEventListener (base of util::XCloseListener)
105             virtual void SAL_CALL disposing(
106                     const com::sun::star::lang::EventObject & Source );
107         private:
108             OfficeDocumentsManager * m_pManager;
109         };
110 
111     public:
112         OfficeDocumentsManager(
113             const com::sun::star::uno::Reference<
114                 com::sun::star::lang::XMultiServiceFactory > & xSMgr,
115             OfficeDocumentsEventListener * pDocEventListener );
116         virtual ~OfficeDocumentsManager();
117 
118         void destroy();
119 
120         // document::XEventListener
121         virtual void SAL_CALL notifyEvent(
122                 const com::sun::star::document::EventObject & Event );
123 
124         // lang::XEventListener (base of document::XEventListener)
125         virtual void SAL_CALL disposing(
126                 const com::sun::star::lang::EventObject & Source );
127 
128         // Non-interface
129         com::sun::star::uno::Reference< com::sun::star::embed::XStorage >
130         queryStorage( const rtl::OUString & rDocId );
131 
132         rtl::OUString
133         queryDocumentId(
134             const com::sun::star::uno::Reference<
135                 com::sun::star::frame::XModel > & xModel );
136 
137         com::sun::star::uno::Reference< com::sun::star::frame::XModel >
138         queryDocumentModel( const rtl::OUString & rDocId );
139 
140         com::sun::star::uno::Sequence< rtl::OUString >
141         queryDocuments();
142 
143         rtl::OUString
144         queryStorageTitle( const rtl::OUString & rDocId );
145 
146     private:
147         static com::sun::star::uno::Reference<
148             com::sun::star::document::XEventBroadcaster >
149         createDocumentEventNotifier(
150             const com::sun::star::uno::Reference<
151                 com::sun::star::lang::XMultiServiceFactory >& rXSMgr );
152 
153         void buildDocumentsList();
154 
155         bool
156         isOfficeDocument(
157             const com::sun::star::uno::Reference<
158                 com::sun::star::uno::XInterface > & xDoc );
159 
160         bool
161         isDocumentPreview(
162             const com::sun::star::uno::Reference<
163                 com::sun::star::frame::XModel > & xModel );
164 
165         bool
166         isWithoutOrInTopLevelFrame(
167             const com::sun::star::uno::Reference<
168                 com::sun::star::frame::XModel > & xModel );
169 
170         bool
171         isBasicIDE(
172             const com::sun::star::uno::Reference<
173                 com::sun::star::frame::XModel > & xModel );
174 
175         bool
176         isHelpDocument(
177             const com::sun::star::uno::Reference<
178                 com::sun::star::frame::XModel > & xModel );
179 
180         osl::Mutex                                          m_aMtx;
181         com::sun::star::uno::Reference<
182             com::sun::star::lang::XMultiServiceFactory >    m_xSMgr;
183         com::sun::star::uno::Reference<
184             com::sun::star::document::XEventBroadcaster >   m_xDocEvtNotifier;
185         com::sun::star::uno::Reference<
186             com::sun::star::frame::XModuleManager >         m_xModuleMgr;
187         DocumentList                                        m_aDocs;
188         OfficeDocumentsEventListener *                      m_pDocEventListener;
189         com::sun::star::uno::Reference<
190             com::sun::star::util::XCloseListener >          m_xDocCloseListener;
191     };
192 
193 } // namespace tdoc_ucp
194 
195 #endif /* !INCLUDED_TDOC_DOCMGR_HXX */
196