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