xref: /aoo41x/main/ucb/source/ucp/tdoc/tdoc_docmgr.hxx (revision 6df1ea1f)
1*6df1ea1fSAndrew Rist /**************************************************************
2*6df1ea1fSAndrew Rist  *
3*6df1ea1fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*6df1ea1fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*6df1ea1fSAndrew Rist  * distributed with this work for additional information
6*6df1ea1fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*6df1ea1fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*6df1ea1fSAndrew Rist  * "License"); you may not use this file except in compliance
9*6df1ea1fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*6df1ea1fSAndrew Rist  *
11*6df1ea1fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*6df1ea1fSAndrew Rist  *
13*6df1ea1fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*6df1ea1fSAndrew Rist  * software distributed under the License is distributed on an
15*6df1ea1fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*6df1ea1fSAndrew Rist  * KIND, either express or implied.  See the License for the
17*6df1ea1fSAndrew Rist  * specific language governing permissions and limitations
18*6df1ea1fSAndrew Rist  * under the License.
19*6df1ea1fSAndrew Rist  *
20*6df1ea1fSAndrew Rist  *************************************************************/
21*6df1ea1fSAndrew Rist 
22*6df1ea1fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef INCLUDED_TDOC_DOCMGR_HXX
25cdf0e10cSrcweir #define INCLUDED_TDOC_DOCMGR_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <map>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include "osl/mutex.hxx"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include "cppuhelper/implbase1.hxx"
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include "com/sun/star/document/XEventBroadcaster.hpp"
34cdf0e10cSrcweir #include "com/sun/star/document/XEventListener.hpp"
35cdf0e10cSrcweir #include "com/sun/star/embed/XStorage.hpp"
36cdf0e10cSrcweir #include "com/sun/star/frame/XModel.hpp"
37cdf0e10cSrcweir #include "com/sun/star/frame/XModuleManager.hpp"
38cdf0e10cSrcweir #include "com/sun/star/util/XCloseListener.hpp"
39cdf0e10cSrcweir 
40cdf0e10cSrcweir namespace tdoc_ucp {
41cdf0e10cSrcweir 
42cdf0e10cSrcweir     class OfficeDocumentsEventListener
43cdf0e10cSrcweir     {
44cdf0e10cSrcweir     public:
45cdf0e10cSrcweir         virtual void notifyDocumentOpened( const rtl::OUString & rDocId ) = 0;
46cdf0e10cSrcweir         virtual void notifyDocumentClosed( const rtl::OUString & rDocId ) = 0;
47cdf0e10cSrcweir     };
48cdf0e10cSrcweir 
49cdf0e10cSrcweir     //=======================================================================
50cdf0e10cSrcweir 
51cdf0e10cSrcweir     struct StorageInfo
52cdf0e10cSrcweir     {
53cdf0e10cSrcweir         rtl::OUString aTitle;
54cdf0e10cSrcweir         com::sun::star::uno::Reference<
55cdf0e10cSrcweir             com::sun::star::embed::XStorage > xStorage;
56cdf0e10cSrcweir         com::sun::star::uno::Reference<
57cdf0e10cSrcweir             com::sun::star::frame::XModel >   xModel;
58cdf0e10cSrcweir 
StorageInfotdoc_ucp::StorageInfo59cdf0e10cSrcweir         StorageInfo() {}; // needed for STL map only.
60cdf0e10cSrcweir 
StorageInfotdoc_ucp::StorageInfo61cdf0e10cSrcweir         StorageInfo(
62cdf0e10cSrcweir             const rtl::OUString & rTitle,
63cdf0e10cSrcweir             const com::sun::star::uno::Reference<
64cdf0e10cSrcweir                 com::sun::star::embed::XStorage > & rxStorage,
65cdf0e10cSrcweir             const com::sun::star::uno::Reference<
66cdf0e10cSrcweir                 com::sun::star::frame::XModel > & rxModel )
67cdf0e10cSrcweir         : aTitle( rTitle ), xStorage( rxStorage ), xModel( rxModel ) {}
68cdf0e10cSrcweir     };
69cdf0e10cSrcweir 
70cdf0e10cSrcweir     //=======================================================================
71cdf0e10cSrcweir 
72cdf0e10cSrcweir     struct ltref
73cdf0e10cSrcweir     {
operator ()tdoc_ucp::ltref74cdf0e10cSrcweir         bool operator()(
75cdf0e10cSrcweir             const rtl::OUString & r1, const rtl::OUString & r2 ) const
76cdf0e10cSrcweir         {
77cdf0e10cSrcweir             return r1 < r2;
78cdf0e10cSrcweir         }
79cdf0e10cSrcweir     };
80cdf0e10cSrcweir 
81cdf0e10cSrcweir     typedef std::map< rtl::OUString, StorageInfo, ltref > DocumentList;
82cdf0e10cSrcweir 
83cdf0e10cSrcweir     //=======================================================================
84cdf0e10cSrcweir 
85cdf0e10cSrcweir     class OfficeDocumentsManager :
86cdf0e10cSrcweir         public cppu::WeakImplHelper1< com::sun::star::document::XEventListener >
87cdf0e10cSrcweir     {
88cdf0e10cSrcweir         class OfficeDocumentsCloseListener :
89cdf0e10cSrcweir            public cppu::WeakImplHelper1< com::sun::star::util::XCloseListener >
90cdf0e10cSrcweir 
91cdf0e10cSrcweir         {
92cdf0e10cSrcweir         public:
OfficeDocumentsCloseListener(OfficeDocumentsManager * pMgr)93cdf0e10cSrcweir             OfficeDocumentsCloseListener( OfficeDocumentsManager * pMgr )
94cdf0e10cSrcweir             : m_pManager( pMgr ) {};
95cdf0e10cSrcweir 
96cdf0e10cSrcweir             // util::XCloseListener
97cdf0e10cSrcweir             virtual void SAL_CALL queryClosing(
98cdf0e10cSrcweir                     const ::com::sun::star::lang::EventObject& Source,
99cdf0e10cSrcweir                     ::sal_Bool GetsOwnership )
100cdf0e10cSrcweir                 throw (::com::sun::star::util::CloseVetoException,
101cdf0e10cSrcweir                        ::com::sun::star::uno::RuntimeException);
102cdf0e10cSrcweir 
103cdf0e10cSrcweir             virtual void SAL_CALL notifyClosing(
104cdf0e10cSrcweir                     const ::com::sun::star::lang::EventObject& Source )
105cdf0e10cSrcweir                 throw (::com::sun::star::uno::RuntimeException);
106cdf0e10cSrcweir 
107cdf0e10cSrcweir             // lang::XEventListener (base of util::XCloseListener)
108cdf0e10cSrcweir             virtual void SAL_CALL disposing(
109cdf0e10cSrcweir                     const com::sun::star::lang::EventObject & Source )
110cdf0e10cSrcweir                 throw ( com::sun::star::uno::RuntimeException );
111cdf0e10cSrcweir         private:
112cdf0e10cSrcweir             OfficeDocumentsManager * m_pManager;
113cdf0e10cSrcweir         };
114cdf0e10cSrcweir 
115cdf0e10cSrcweir     public:
116cdf0e10cSrcweir         OfficeDocumentsManager(
117cdf0e10cSrcweir             const com::sun::star::uno::Reference<
118cdf0e10cSrcweir                 com::sun::star::lang::XMultiServiceFactory > & xSMgr,
119cdf0e10cSrcweir             OfficeDocumentsEventListener * pDocEventListener );
120cdf0e10cSrcweir         virtual ~OfficeDocumentsManager();
121cdf0e10cSrcweir 
122cdf0e10cSrcweir         void destroy();
123cdf0e10cSrcweir 
124cdf0e10cSrcweir         // document::XEventListener
125cdf0e10cSrcweir         virtual void SAL_CALL notifyEvent(
126cdf0e10cSrcweir                 const com::sun::star::document::EventObject & Event )
127cdf0e10cSrcweir             throw ( com::sun::star::uno::RuntimeException );
128cdf0e10cSrcweir 
129cdf0e10cSrcweir         // lang::XEventListener (base of document::XEventListener)
130cdf0e10cSrcweir         virtual void SAL_CALL disposing(
131cdf0e10cSrcweir                 const com::sun::star::lang::EventObject & Source )
132cdf0e10cSrcweir             throw ( com::sun::star::uno::RuntimeException );
133cdf0e10cSrcweir 
134cdf0e10cSrcweir         // Non-interface
135cdf0e10cSrcweir         com::sun::star::uno::Reference< com::sun::star::embed::XStorage >
136cdf0e10cSrcweir         queryStorage( const rtl::OUString & rDocId );
137cdf0e10cSrcweir 
138cdf0e10cSrcweir         rtl::OUString
139cdf0e10cSrcweir         queryDocumentId(
140cdf0e10cSrcweir             const com::sun::star::uno::Reference<
141cdf0e10cSrcweir                 com::sun::star::frame::XModel > & xModel );
142cdf0e10cSrcweir 
143cdf0e10cSrcweir         com::sun::star::uno::Reference< com::sun::star::frame::XModel >
144cdf0e10cSrcweir         queryDocumentModel( const rtl::OUString & rDocId );
145cdf0e10cSrcweir 
146cdf0e10cSrcweir         com::sun::star::uno::Sequence< rtl::OUString >
147cdf0e10cSrcweir         queryDocuments();
148cdf0e10cSrcweir 
149cdf0e10cSrcweir         rtl::OUString
150cdf0e10cSrcweir         queryStorageTitle( const rtl::OUString & rDocId );
151cdf0e10cSrcweir 
152cdf0e10cSrcweir     private:
153cdf0e10cSrcweir         static com::sun::star::uno::Reference<
154cdf0e10cSrcweir             com::sun::star::document::XEventBroadcaster >
155cdf0e10cSrcweir         createDocumentEventNotifier(
156cdf0e10cSrcweir             const com::sun::star::uno::Reference<
157cdf0e10cSrcweir                 com::sun::star::lang::XMultiServiceFactory >& rXSMgr );
158cdf0e10cSrcweir 
159cdf0e10cSrcweir         void buildDocumentsList();
160cdf0e10cSrcweir 
161cdf0e10cSrcweir         bool
162cdf0e10cSrcweir         isOfficeDocument(
163cdf0e10cSrcweir             const com::sun::star::uno::Reference<
164cdf0e10cSrcweir                 com::sun::star::uno::XInterface > & xDoc );
165cdf0e10cSrcweir 
166cdf0e10cSrcweir         bool
167cdf0e10cSrcweir         isDocumentPreview(
168cdf0e10cSrcweir             const com::sun::star::uno::Reference<
169cdf0e10cSrcweir                 com::sun::star::frame::XModel > & xModel );
170cdf0e10cSrcweir 
171cdf0e10cSrcweir         bool
172cdf0e10cSrcweir         isWithoutOrInTopLevelFrame(
173cdf0e10cSrcweir             const com::sun::star::uno::Reference<
174cdf0e10cSrcweir                 com::sun::star::frame::XModel > & xModel );
175cdf0e10cSrcweir 
176cdf0e10cSrcweir         bool
177cdf0e10cSrcweir         isBasicIDE(
178cdf0e10cSrcweir             const com::sun::star::uno::Reference<
179cdf0e10cSrcweir                 com::sun::star::frame::XModel > & xModel );
180cdf0e10cSrcweir 
181cdf0e10cSrcweir         bool
182cdf0e10cSrcweir         isHelpDocument(
183cdf0e10cSrcweir             const com::sun::star::uno::Reference<
184cdf0e10cSrcweir                 com::sun::star::frame::XModel > & xModel );
185cdf0e10cSrcweir 
186cdf0e10cSrcweir         osl::Mutex                                          m_aMtx;
187cdf0e10cSrcweir         com::sun::star::uno::Reference<
188cdf0e10cSrcweir             com::sun::star::lang::XMultiServiceFactory >    m_xSMgr;
189cdf0e10cSrcweir         com::sun::star::uno::Reference<
190cdf0e10cSrcweir             com::sun::star::document::XEventBroadcaster >   m_xDocEvtNotifier;
191cdf0e10cSrcweir         com::sun::star::uno::Reference<
192cdf0e10cSrcweir             com::sun::star::frame::XModuleManager >         m_xModuleMgr;
193cdf0e10cSrcweir         DocumentList                                        m_aDocs;
194cdf0e10cSrcweir         OfficeDocumentsEventListener *                      m_pDocEventListener;
195cdf0e10cSrcweir         com::sun::star::uno::Reference<
196cdf0e10cSrcweir             com::sun::star::util::XCloseListener >          m_xDocCloseListener;
197cdf0e10cSrcweir     };
198cdf0e10cSrcweir 
199cdf0e10cSrcweir } // namespace tdoc_ucp
200cdf0e10cSrcweir 
201cdf0e10cSrcweir #endif /* !INCLUDED_TDOC_DOCMGR_HXX */
202