LibreOffice Module ucb (master)  1
tdoc_docmgr.hxx
Go to the documentation of this file.
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/implbase.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/uno/XComponentContext.hpp>
36 #include <com/sun/star/util/XCloseListener.hpp>
37 
38 namespace tdoc_ucp {
39 
40  class ContentProvider;
41 
42  struct StorageInfo
43  {
44  OUString aTitle;
45  css::uno::Reference< css::embed::XStorage > xStorage;
46  css::uno::Reference< css::frame::XModel > xModel;
47 
48  StorageInfo() {}; // needed for STL map only.
49 
51  const OUString & rTitle,
52  const css::uno::Reference< css::embed::XStorage > & rxStorage,
53  const css::uno::Reference< css::frame::XModel > & rxModel )
54  : aTitle( rTitle ), xStorage( rxStorage ), xModel( rxModel ) {}
55  };
56 
57 
58  typedef std::map< OUString, StorageInfo > DocumentList;
59 
60 
62  public cppu::WeakImplHelper< css::document::XDocumentEventListener >
63  {
65  public cppu::WeakImplHelper< css::util::XCloseListener >
66 
67  {
68  public:
70  : m_pManager( pMgr ) {}
71 
72  // util::XCloseListener
73  virtual void SAL_CALL queryClosing(
74  const css::lang::EventObject& Source,
75  sal_Bool GetsOwnership ) override;
76 
77  virtual void SAL_CALL notifyClosing(
78  const css::lang::EventObject& Source ) override;
79 
80  // lang::XEventListener (base of util::XCloseListener)
81  virtual void SAL_CALL disposing(
82  const css::lang::EventObject & Source ) override;
83 
84  void Dispose() { m_pManager = nullptr; }
85 
86  private:
88  };
89 
90  public:
92  const css::uno::Reference< css::uno::XComponentContext > & rxContext,
93  ContentProvider * pDocEventListener );
94  virtual ~OfficeDocumentsManager() override;
95 
96  void destroy();
97 
98  // document::XDocumentEventListener
99  virtual void SAL_CALL documentEventOccured(
100  const css::document::DocumentEvent & Event ) override;
101 
102  // lang::XEventListener (base of document::XDocumentEventListener)
103  virtual void SAL_CALL disposing(
104  const css::lang::EventObject & Source ) override;
105 
106  // Non-interface
107  css::uno::Reference< css::embed::XStorage >
108  queryStorage( const OUString & rDocId );
109 
110  static OUString queryDocumentId(
111  const css::uno::Reference< css::frame::XModel > & xModel );
112 
113  css::uno::Reference< css::frame::XModel >
114  queryDocumentModel( const OUString & rDocId );
115 
116  css::uno::Sequence< OUString >
117  queryDocuments();
118 
119  OUString
120  queryStorageTitle( const OUString & rDocId );
121 
122  private:
123  void buildDocumentsList();
124 
125  bool isOfficeDocument(
126  const css::uno::Reference< css::uno::XInterface > & xDoc );
127 
128  static bool isDocumentPreview(
129  const css::uno::Reference< css::frame::XModel > & xModel );
130 
131  static bool isWithoutOrInTopLevelFrame(
132  const css::uno::Reference< css::frame::XModel > & xModel );
133 
134  bool
135  isBasicIDE(
136  const css::uno::Reference< css::frame::XModel > & xModel );
137 
138  static bool isHelpDocument(
139  const css::uno::Reference< css::frame::XModel > & xModel );
140 
141  osl::Mutex m_aMtx;
142  css::uno::Reference< css::uno::XComponentContext > m_xContext;
143  css::uno::Reference< css::frame::XGlobalEventBroadcaster > m_xDocEvtNotifier;
144  css::uno::Reference< css::frame::XModuleManager2 > m_xModuleMgr;
145  DocumentList m_aDocs;
148  };
149 
150 } // namespace tdoc_ucp
151 
152 #endif // INCLUDED_UCB_SOURCE_UCP_TDOC_TDOC_DOCMGR_HXX
153 
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL queryClosing(const css::lang::EventObject &Source, sal_Bool GetsOwnership) override
Definition: tdoc_docmgr.cxx:52
css::uno::Reference< css::frame::XModel > xModel
Definition: tdoc_docmgr.hxx:46
css::uno::Reference< css::uno::XComponentContext > m_xContext
::rtl::Reference< OfficeDocumentsCloseListener > const m_xDocCloseListener
static bool isDocumentPreview(const css::uno::Reference< css::frame::XModel > &xModel)
css::uno::Reference< css::embed::XStorage > xStorage
Definition: tdoc_docmgr.hxx:45
css::uno::Reference< css::embed::XStorage > queryStorage(const OUString &rDocId)
static bool isWithoutOrInTopLevelFrame(const css::uno::Reference< css::frame::XModel > &xModel)
OfficeDocumentsManager(const css::uno::Reference< css::uno::XComponentContext > &rxContext, ContentProvider *pDocEventListener)
Definition: tdoc_docmgr.cxx:83
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
Definition: tdoc_docmgr.cxx:74
css::uno::Reference< css::frame::XGlobalEventBroadcaster > m_xDocEvtNotifier
StorageInfo(const OUString &rTitle, const css::uno::Reference< css::embed::XStorage > &rxStorage, const css::uno::Reference< css::frame::XModel > &rxModel)
Definition: tdoc_docmgr.hxx:50
css::uno::Sequence< OUString > queryDocuments()
ContentProvider *const m_pDocEventListener
std::map< OUString, StorageInfo > DocumentList
Definition: tdoc_docmgr.hxx:58
css::uno::Reference< css::frame::XModel > queryDocumentModel(const OUString &rDocId)
unsigned char sal_Bool
bool isBasicIDE(const css::uno::Reference< css::frame::XModel > &xModel)
static OUString queryDocumentId(const css::uno::Reference< css::frame::XModel > &xModel)
css::uno::Reference< css::frame::XModuleManager2 > m_xModuleMgr
bool isOfficeDocument(const css::uno::Reference< css::uno::XInterface > &xDoc)
static bool isHelpDocument(const css::uno::Reference< css::frame::XModel > &xModel)
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
virtual void SAL_CALL notifyClosing(const css::lang::EventObject &Source) override
Definition: tdoc_docmgr.cxx:58
virtual ~OfficeDocumentsManager() override
Definition: tdoc_docmgr.cxx:99
virtual void SAL_CALL documentEventOccured(const css::document::DocumentEvent &Event) override
OUString queryStorageTitle(const OUString &rDocId)