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