Version 4.0.2.1, tag libreoffice-4.0.2.1
[LibreOffice.git] / ucb / source / ucp / tdoc / tdoc_docmgr.hxx
blob02046341f1c980cb55cf1396fb2bc37b8241ef22
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_TDOC_DOCMGR_HXX
21 #define INCLUDED_TDOC_DOCMGR_HXX
23 #include <map>
25 #include "osl/mutex.hxx"
27 #include "cppuhelper/implbase1.hxx"
29 #include "com/sun/star/document/XEventListener.hpp"
30 #include "com/sun/star/embed/XStorage.hpp"
31 #include "com/sun/star/frame/XModel.hpp"
32 #include "com/sun/star/frame/XModuleManager2.hpp"
33 #include "com/sun/star/frame/XGlobalEventBroadcaster.hpp"
34 #include "com/sun/star/util/XCloseListener.hpp"
36 namespace tdoc_ucp {
38 class OfficeDocumentsEventListener
40 public:
41 virtual void notifyDocumentOpened( const rtl::OUString & rDocId ) = 0;
42 virtual void notifyDocumentClosed( const rtl::OUString & rDocId ) = 0;
44 protected:
45 ~OfficeDocumentsEventListener() {}
48 //=======================================================================
50 struct StorageInfo
52 rtl::OUString aTitle;
53 com::sun::star::uno::Reference<
54 com::sun::star::embed::XStorage > xStorage;
55 com::sun::star::uno::Reference<
56 com::sun::star::frame::XModel > xModel;
58 StorageInfo() {}; // needed for STL map only.
60 StorageInfo(
61 const rtl::OUString & rTitle,
62 const com::sun::star::uno::Reference<
63 com::sun::star::embed::XStorage > & rxStorage,
64 const com::sun::star::uno::Reference<
65 com::sun::star::frame::XModel > & rxModel )
66 : aTitle( rTitle ), xStorage( rxStorage ), xModel( rxModel ) {}
69 //=======================================================================
71 struct ltref
73 bool operator()(
74 const rtl::OUString & r1, const rtl::OUString & r2 ) const
76 return r1 < r2;
80 typedef std::map< rtl::OUString, StorageInfo, ltref > DocumentList;
82 //=======================================================================
84 class OfficeDocumentsManager :
85 public cppu::WeakImplHelper1< com::sun::star::document::XEventListener >
87 class OfficeDocumentsCloseListener :
88 public cppu::WeakImplHelper1< com::sun::star::util::XCloseListener >
91 public:
92 OfficeDocumentsCloseListener( OfficeDocumentsManager * pMgr )
93 : m_pManager( pMgr ) {};
95 // util::XCloseListener
96 virtual void SAL_CALL queryClosing(
97 const ::com::sun::star::lang::EventObject& Source,
98 ::sal_Bool GetsOwnership )
99 throw (::com::sun::star::util::CloseVetoException,
100 ::com::sun::star::uno::RuntimeException);
102 virtual void SAL_CALL notifyClosing(
103 const ::com::sun::star::lang::EventObject& Source )
104 throw (::com::sun::star::uno::RuntimeException);
106 // lang::XEventListener (base of util::XCloseListener)
107 virtual void SAL_CALL disposing(
108 const com::sun::star::lang::EventObject & Source )
109 throw ( com::sun::star::uno::RuntimeException );
110 private:
111 OfficeDocumentsManager * m_pManager;
114 public:
115 OfficeDocumentsManager(
116 const com::sun::star::uno::Reference<
117 com::sun::star::uno::XComponentContext > & rxContext,
118 OfficeDocumentsEventListener * pDocEventListener );
119 virtual ~OfficeDocumentsManager();
121 void destroy();
123 // document::XEventListener
124 virtual void SAL_CALL notifyEvent(
125 const com::sun::star::document::EventObject & Event )
126 throw ( com::sun::star::uno::RuntimeException );
128 // lang::XEventListener (base of document::XEventListener)
129 virtual void SAL_CALL disposing(
130 const com::sun::star::lang::EventObject & Source )
131 throw ( com::sun::star::uno::RuntimeException );
133 // Non-interface
134 com::sun::star::uno::Reference< com::sun::star::embed::XStorage >
135 queryStorage( const rtl::OUString & rDocId );
137 rtl::OUString
138 queryDocumentId(
139 const com::sun::star::uno::Reference<
140 com::sun::star::frame::XModel > & xModel );
142 com::sun::star::uno::Reference< com::sun::star::frame::XModel >
143 queryDocumentModel( const rtl::OUString & rDocId );
145 com::sun::star::uno::Sequence< rtl::OUString >
146 queryDocuments();
148 rtl::OUString
149 queryStorageTitle( const rtl::OUString & rDocId );
151 private:
152 void buildDocumentsList();
154 bool
155 isOfficeDocument(
156 const com::sun::star::uno::Reference<
157 com::sun::star::uno::XInterface > & xDoc );
159 bool
160 isDocumentPreview(
161 const com::sun::star::uno::Reference<
162 com::sun::star::frame::XModel > & xModel );
164 bool
165 isWithoutOrInTopLevelFrame(
166 const com::sun::star::uno::Reference<
167 com::sun::star::frame::XModel > & xModel );
169 bool
170 isBasicIDE(
171 const com::sun::star::uno::Reference<
172 com::sun::star::frame::XModel > & xModel );
174 bool
175 isHelpDocument(
176 const com::sun::star::uno::Reference<
177 com::sun::star::frame::XModel > & xModel );
179 osl::Mutex m_aMtx;
180 com::sun::star::uno::Reference<
181 com::sun::star::uno::XComponentContext > m_xContext;
182 com::sun::star::uno::Reference<
183 com::sun::star::frame::XGlobalEventBroadcaster > m_xDocEvtNotifier;
184 com::sun::star::uno::Reference<
185 com::sun::star::frame::XModuleManager2 > m_xModuleMgr;
186 DocumentList m_aDocs;
187 OfficeDocumentsEventListener * m_pDocEventListener;
188 com::sun::star::uno::Reference<
189 com::sun::star::util::XCloseListener > m_xDocCloseListener;
192 } // namespace tdoc_ucp
194 #endif /* !INCLUDED_TDOC_DOCMGR_HXX */
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */