LCOV - code coverage report
Current view: top level - ucb/source/ucp/tdoc - tdoc_docmgr.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 12 12 100.0 %
Date: 2015-06-13 12:38:46 Functions: 11 11 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_UCB_SOURCE_UCP_TDOC_TDOC_DOCMGR_HXX
      21             : #define INCLUDED_UCB_SOURCE_UCP_TDOC_TDOC_DOCMGR_HXX
      22             : 
      23             : #include <map>
      24             : 
      25             : #include <rtl/ref.hxx>
      26             : #include "osl/mutex.hxx"
      27             : 
      28             : #include "cppuhelper/implbase1.hxx"
      29             : 
      30             : #include "com/sun/star/document/XDocumentEventListener.hpp"
      31             : #include "com/sun/star/embed/XStorage.hpp"
      32             : #include "com/sun/star/frame/XModel.hpp"
      33             : #include "com/sun/star/frame/XModuleManager2.hpp"
      34             : #include "com/sun/star/frame/XGlobalEventBroadcaster.hpp"
      35             : #include "com/sun/star/util/XCloseListener.hpp"
      36             : 
      37             : namespace tdoc_ucp {
      38             : 
      39          61 :     class OfficeDocumentsEventListener
      40             :     {
      41             :     public:
      42             :         virtual void notifyDocumentOpened( const OUString & rDocId ) = 0;
      43             :         virtual void notifyDocumentClosed( const OUString & rDocId ) = 0;
      44             : 
      45             :     protected:
      46          59 :         ~OfficeDocumentsEventListener() {}
      47             :     };
      48             : 
      49             : 
      50             : 
      51        8564 :     struct StorageInfo
      52             :     {
      53             :         OUString aTitle;
      54             :         com::sun::star::uno::Reference<
      55             :             com::sun::star::embed::XStorage > xStorage;
      56             :         com::sun::star::uno::Reference<
      57             :             com::sun::star::frame::XModel >   xModel;
      58             : 
      59        1331 :         StorageInfo() {}; // needed for STL map only.
      60             : 
      61        3617 :         StorageInfo(
      62             :             const OUString & rTitle,
      63             :             const com::sun::star::uno::Reference<
      64             :                 com::sun::star::embed::XStorage > & rxStorage,
      65             :             const com::sun::star::uno::Reference<
      66             :                 com::sun::star::frame::XModel > & rxModel )
      67        3617 :         : aTitle( rTitle ), xStorage( rxStorage ), xModel( rxModel ) {}
      68             :     };
      69             : 
      70             : 
      71             : 
      72             :     struct ltref
      73             :     {
      74        9058 :         bool operator()(
      75             :             const OUString & r1, const OUString & r2 ) const
      76             :         {
      77        9058 :             return r1 < r2;
      78             :         }
      79             :     };
      80             : 
      81             :     typedef std::map< OUString, StorageInfo, ltref > DocumentList;
      82             : 
      83             : 
      84             : 
      85             :     class OfficeDocumentsManager :
      86             :         public cppu::WeakImplHelper1< com::sun::star::document::XDocumentEventListener >
      87             :     {
      88         102 :         class OfficeDocumentsCloseListener :
      89             :            public cppu::WeakImplHelper1< com::sun::star::util::XCloseListener >
      90             : 
      91             :         {
      92             :         public:
      93          61 :             explicit OfficeDocumentsCloseListener( OfficeDocumentsManager * pMgr )
      94          61 :                 : m_pManager( pMgr ) {}
      95             : 
      96             :             // util::XCloseListener
      97             :             virtual void SAL_CALL queryClosing(
      98             :                     const ::com::sun::star::lang::EventObject& Source,
      99             :                     sal_Bool GetsOwnership )
     100             :                 throw (::com::sun::star::util::CloseVetoException,
     101             :                        ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     102             : 
     103             :             virtual void SAL_CALL notifyClosing(
     104             :                     const ::com::sun::star::lang::EventObject& Source )
     105             :                 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     106             : 
     107             :             // lang::XEventListener (base of util::XCloseListener)
     108             :             virtual void SAL_CALL disposing(
     109             :                     const com::sun::star::lang::EventObject & Source )
     110             :                 throw ( com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     111             : 
     112          59 :             void Dispose() { m_pManager = 0; }
     113             : 
     114             :         private:
     115             :             OfficeDocumentsManager * m_pManager;
     116             :         };
     117             : 
     118             :     public:
     119             :         OfficeDocumentsManager(
     120             :             const com::sun::star::uno::Reference<
     121             :                 com::sun::star::uno::XComponentContext > & rxContext,
     122             :             OfficeDocumentsEventListener * pDocEventListener );
     123             :         virtual ~OfficeDocumentsManager();
     124             : 
     125             :         void destroy();
     126             : 
     127             :         // document::XDocumentEventListener
     128             :         virtual void SAL_CALL documentEventOccured(
     129             :                 const com::sun::star::document::DocumentEvent & Event )
     130             :             throw ( com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     131             : 
     132             :         // lang::XEventListener (base of document::XDocumentEventListener)
     133             :         virtual void SAL_CALL disposing(
     134             :                 const com::sun::star::lang::EventObject & Source )
     135             :             throw ( com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     136             : 
     137             :         // Non-interface
     138             :         com::sun::star::uno::Reference< com::sun::star::embed::XStorage >
     139             :         queryStorage( const OUString & rDocId );
     140             : 
     141             :         static OUString queryDocumentId(
     142             :             const com::sun::star::uno::Reference<
     143             :                 com::sun::star::frame::XModel > & xModel );
     144             : 
     145             :         com::sun::star::uno::Reference< com::sun::star::frame::XModel >
     146             :         queryDocumentModel( const OUString & rDocId );
     147             : 
     148             :         com::sun::star::uno::Sequence< OUString >
     149             :         queryDocuments();
     150             : 
     151             :         OUString
     152             :         queryStorageTitle( const OUString & rDocId );
     153             : 
     154             :     private:
     155             :         void buildDocumentsList();
     156             : 
     157             :         bool isOfficeDocument(
     158             :             const com::sun::star::uno::Reference<
     159             :                 com::sun::star::uno::XInterface > & xDoc );
     160             : 
     161             :         static bool isDocumentPreview(
     162             :             const com::sun::star::uno::Reference<
     163             :                 com::sun::star::frame::XModel > & xModel );
     164             : 
     165             :         static bool isWithoutOrInTopLevelFrame(
     166             :             const com::sun::star::uno::Reference<
     167             :                 com::sun::star::frame::XModel > & xModel );
     168             : 
     169             :         bool
     170             :         isBasicIDE(
     171             :             const com::sun::star::uno::Reference<
     172             :                 com::sun::star::frame::XModel > & xModel );
     173             : 
     174             :         static bool isHelpDocument(
     175             :             const com::sun::star::uno::Reference<
     176             :                 com::sun::star::frame::XModel > & xModel );
     177             : 
     178             :         osl::Mutex                                          m_aMtx;
     179             :         com::sun::star::uno::Reference<
     180             :             com::sun::star::uno::XComponentContext >        m_xContext;
     181             :         com::sun::star::uno::Reference<
     182             :             com::sun::star::frame::XGlobalEventBroadcaster > m_xDocEvtNotifier;
     183             :         com::sun::star::uno::Reference<
     184             :             com::sun::star::frame::XModuleManager2 >        m_xModuleMgr;
     185             :         DocumentList                                        m_aDocs;
     186             :         OfficeDocumentsEventListener *                      m_pDocEventListener;
     187             :         ::rtl::Reference<OfficeDocumentsCloseListener> m_xDocCloseListener;
     188             :     };
     189             : 
     190             : } // namespace tdoc_ucp
     191             : 
     192             : #endif // INCLUDED_UCB_SOURCE_UCP_TDOC_TDOC_DOCMGR_HXX
     193             : 
     194             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11