Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef INCLUDED_TDOC_DOCMGR_HXX
30 : : #define INCLUDED_TDOC_DOCMGR_HXX
31 : :
32 : : #include <map>
33 : :
34 : : #include "osl/mutex.hxx"
35 : :
36 : : #include "cppuhelper/implbase1.hxx"
37 : :
38 : : #include "com/sun/star/document/XEventBroadcaster.hpp"
39 : : #include "com/sun/star/document/XEventListener.hpp"
40 : : #include "com/sun/star/embed/XStorage.hpp"
41 : : #include "com/sun/star/frame/XModel.hpp"
42 : : #include "com/sun/star/frame/XModuleManager.hpp"
43 : : #include "com/sun/star/util/XCloseListener.hpp"
44 : :
45 : : namespace tdoc_ucp {
46 : :
47 : 17 : class OfficeDocumentsEventListener
48 : : {
49 : : public:
50 : : virtual void notifyDocumentOpened( const rtl::OUString & rDocId ) = 0;
51 : : virtual void notifyDocumentClosed( const rtl::OUString & rDocId ) = 0;
52 : :
53 : : protected:
54 : 17 : ~OfficeDocumentsEventListener() {}
55 : : };
56 : :
57 : : //=======================================================================
58 : :
59 : 2297 : struct StorageInfo
60 : : {
61 : : rtl::OUString aTitle;
62 : : com::sun::star::uno::Reference<
63 : : com::sun::star::embed::XStorage > xStorage;
64 : : com::sun::star::uno::Reference<
65 : : com::sun::star::frame::XModel > xModel;
66 : :
67 : 195 : StorageInfo() {}; // needed for STL map only.
68 : :
69 : 661 : StorageInfo(
70 : : const rtl::OUString & rTitle,
71 : : const com::sun::star::uno::Reference<
72 : : com::sun::star::embed::XStorage > & rxStorage,
73 : : const com::sun::star::uno::Reference<
74 : : com::sun::star::frame::XModel > & rxModel )
75 : 661 : : aTitle( rTitle ), xStorage( rxStorage ), xModel( rxModel ) {}
76 : : };
77 : :
78 : : //=======================================================================
79 : :
80 : : struct ltref
81 : : {
82 : 1648 : bool operator()(
83 : : const rtl::OUString & r1, const rtl::OUString & r2 ) const
84 : : {
85 : 1648 : return r1 < r2;
86 : : }
87 : : };
88 : :
89 : : typedef std::map< rtl::OUString, StorageInfo, ltref > DocumentList;
90 : :
91 : : //=======================================================================
92 : :
93 : : class OfficeDocumentsManager :
94 : : public cppu::WeakImplHelper1< com::sun::star::document::XEventListener >
95 : : {
96 [ - + ]: 30 : class OfficeDocumentsCloseListener :
97 : : public cppu::WeakImplHelper1< com::sun::star::util::XCloseListener >
98 : :
99 : : {
100 : : public:
101 : 17 : OfficeDocumentsCloseListener( OfficeDocumentsManager * pMgr )
102 : 17 : : m_pManager( pMgr ) {};
103 : :
104 : : // util::XCloseListener
105 : : virtual void SAL_CALL queryClosing(
106 : : const ::com::sun::star::lang::EventObject& Source,
107 : : ::sal_Bool GetsOwnership )
108 : : throw (::com::sun::star::util::CloseVetoException,
109 : : ::com::sun::star::uno::RuntimeException);
110 : :
111 : : virtual void SAL_CALL notifyClosing(
112 : : const ::com::sun::star::lang::EventObject& Source )
113 : : throw (::com::sun::star::uno::RuntimeException);
114 : :
115 : : // lang::XEventListener (base of util::XCloseListener)
116 : : virtual void SAL_CALL disposing(
117 : : const com::sun::star::lang::EventObject & Source )
118 : : throw ( com::sun::star::uno::RuntimeException );
119 : : private:
120 : : OfficeDocumentsManager * m_pManager;
121 : : };
122 : :
123 : : public:
124 : : OfficeDocumentsManager(
125 : : const com::sun::star::uno::Reference<
126 : : com::sun::star::lang::XMultiServiceFactory > & xSMgr,
127 : : OfficeDocumentsEventListener * pDocEventListener );
128 : : virtual ~OfficeDocumentsManager();
129 : :
130 : : void destroy();
131 : :
132 : : // document::XEventListener
133 : : virtual void SAL_CALL notifyEvent(
134 : : const com::sun::star::document::EventObject & Event )
135 : : throw ( com::sun::star::uno::RuntimeException );
136 : :
137 : : // lang::XEventListener (base of document::XEventListener)
138 : : virtual void SAL_CALL disposing(
139 : : const com::sun::star::lang::EventObject & Source )
140 : : throw ( com::sun::star::uno::RuntimeException );
141 : :
142 : : // Non-interface
143 : : com::sun::star::uno::Reference< com::sun::star::embed::XStorage >
144 : : queryStorage( const rtl::OUString & rDocId );
145 : :
146 : : rtl::OUString
147 : : queryDocumentId(
148 : : const com::sun::star::uno::Reference<
149 : : com::sun::star::frame::XModel > & xModel );
150 : :
151 : : com::sun::star::uno::Reference< com::sun::star::frame::XModel >
152 : : queryDocumentModel( const rtl::OUString & rDocId );
153 : :
154 : : com::sun::star::uno::Sequence< rtl::OUString >
155 : : queryDocuments();
156 : :
157 : : rtl::OUString
158 : : queryStorageTitle( const rtl::OUString & rDocId );
159 : :
160 : : private:
161 : : static com::sun::star::uno::Reference<
162 : : com::sun::star::document::XEventBroadcaster >
163 : : createDocumentEventNotifier(
164 : : const com::sun::star::uno::Reference<
165 : : com::sun::star::lang::XMultiServiceFactory >& rXSMgr );
166 : :
167 : : void buildDocumentsList();
168 : :
169 : : bool
170 : : isOfficeDocument(
171 : : const com::sun::star::uno::Reference<
172 : : com::sun::star::uno::XInterface > & xDoc );
173 : :
174 : : bool
175 : : isDocumentPreview(
176 : : const com::sun::star::uno::Reference<
177 : : com::sun::star::frame::XModel > & xModel );
178 : :
179 : : bool
180 : : isWithoutOrInTopLevelFrame(
181 : : const com::sun::star::uno::Reference<
182 : : com::sun::star::frame::XModel > & xModel );
183 : :
184 : : bool
185 : : isBasicIDE(
186 : : const com::sun::star::uno::Reference<
187 : : com::sun::star::frame::XModel > & xModel );
188 : :
189 : : bool
190 : : isHelpDocument(
191 : : const com::sun::star::uno::Reference<
192 : : com::sun::star::frame::XModel > & xModel );
193 : :
194 : : osl::Mutex m_aMtx;
195 : : com::sun::star::uno::Reference<
196 : : com::sun::star::lang::XMultiServiceFactory > m_xSMgr;
197 : : com::sun::star::uno::Reference<
198 : : com::sun::star::document::XEventBroadcaster > m_xDocEvtNotifier;
199 : : com::sun::star::uno::Reference<
200 : : com::sun::star::frame::XModuleManager > m_xModuleMgr;
201 : : DocumentList m_aDocs;
202 : : OfficeDocumentsEventListener * m_pDocEventListener;
203 : : com::sun::star::uno::Reference<
204 : : com::sun::star::util::XCloseListener > m_xDocCloseListener;
205 : : };
206 : :
207 : : } // namespace tdoc_ucp
208 : :
209 : : #endif /* !INCLUDED_TDOC_DOCMGR_HXX */
210 : :
211 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|