24#include <tools/datetime.hxx>
30#include <com/sun/star/awt/XTopWindow.hpp>
31#include <com/sun/star/beans/XPropertySet.hpp>
32#include <com/sun/star/document/XDocumentEventBroadcaster.hpp>
33#include <com/sun/star/document/XStorageBasedDocument.hpp>
34#include <com/sun/star/frame/UnknownModuleException.hpp>
35#include <com/sun/star/frame/theGlobalEventBroadcaster.hpp>
36#include <com/sun/star/frame/ModuleManager.hpp>
37#include <com/sun/star/lang/DisposedException.hpp>
38#include <com/sun/star/lang/NotInitializedException.hpp>
39#include <com/sun/star/util/XCloseBroadcaster.hpp>
54void SAL_CALL OfficeDocumentsManager::OfficeDocumentsCloseListener::queryClosing(
55 const lang::EventObject& ,
sal_Bool )
61 const lang::EventObject& Source )
65 document::DocumentEvent aDocEvent;
66 aDocEvent.Source =
Source.Source;
67 aDocEvent.EventName =
"OfficeDocumentsListener::notifyClosing";
77 const lang::EventObject& )
86 const uno::Reference< uno::XComponentContext > & rxContext,
94 uno::Reference< document::XDocumentEventBroadcaster >(
114 uno::Reference< document::XDocumentEventBroadcaster >(
125 uno::Reference< beans::XPropertySet > xPropSet( xDoc, uno::UNO_QUERY );
130 uno::Any aValue = xPropSet->getPropertyValue(
"RuntimeUID");
133 catch ( beans::UnknownPropertyException
const & )
137 catch ( lang::WrappedTargetException
const & )
149 uno::Reference< uno::XInterface > xNormalizedIFace( xDoc, uno::UNO_QUERY );
150 sal_Int64
nId =
reinterpret_cast< sal_Int64
>( xNormalizedIFace.get() );
151 aId = OUString::number(
nId );
154 OSL_ENSURE( !aId.isEmpty(),
"getDocumentId - Empty id!" );
164 const document::DocumentEvent & Event )
171 if ( Event.EventName ==
"OnLoadFinished"
172 || Event.EventName ==
"OnCreate" )
176 uno::Reference<frame::XModel>
const xModel(
177 Event.Source, uno::UNO_QUERY );
178 OSL_ENSURE(
xModel.is(),
"Got no frame::XModel!" );
183 std::scoped_lock aGuard(
m_aMtx );
186 [&
xModel](
const DocumentList::value_type& rEntry) { return rEntry.second.xModel == xModel; });
196 uno::Reference< document::XStorageBasedDocument >
197 xDoc( Event.Source, uno::UNO_QUERY );
198 OSL_ENSURE( xDoc.is(),
"Got no document::XStorageBasedDocument!" );
200 uno::Reference< embed::XStorage > xStorage
201 = xDoc->getDocumentStorage();
202 OSL_ENSURE( xStorage.is(),
"Got no document storage!" );
206 uno::Reference< frame::XModel >( Event.Source, uno::UNO_QUERY ) );
209 std::scoped_lock g(
m_aMtx);
213 uno::Reference< util::XCloseBroadcaster > xCloseBroadcaster(
214 Event.Source, uno::UNO_QUERY );
215 OSL_ENSURE( xCloseBroadcaster.is(),
216 "OnLoadFinished/OnCreate event: got no close broadcaster!" );
218 if ( xCloseBroadcaster.is() )
223 "OnLoadFinished/OnCreate event: no owner for insert event propagation!" );
230 else if ( Event.EventName ==
"OfficeDocumentsListener::notifyClosing" )
242 uno::Reference< frame::XModel >
243 xModel( Event.Source, uno::UNO_QUERY );
244 OSL_ENSURE(
xModel.is(),
"Got no frame::XModel!" );
250 std::scoped_lock aGuard(
m_aMtx );
253 [&
xModel](
const DocumentList::value_type& rEntry) { return rEntry.second.xModel == xModel; });
256 aDocId = (*it).first;
263 "OnUnload event notified for unknown document!" );
269 "OnUnload event: no owner for close event propagation!" );
274 uno::Reference< util::XCloseBroadcaster > xCloseBroadcaster(
275 Event.Source, uno::UNO_QUERY );
276 OSL_ENSURE( xCloseBroadcaster.is(),
277 "OnUnload event: got no XCloseBroadcaster from XModel" );
278 if ( xCloseBroadcaster.is() )
283 else if ( Event.EventName ==
"OnSaveDone" )
288 uno::Reference<document::XStorageBasedDocument>
const xDoc(
289 Event.Source, uno::UNO_QUERY );
290 OSL_ENSURE( xDoc.is(),
291 "Got no document::XStorageBasedDocument!" );
292 uno::Reference<embed::XStorage>
const xStorage(
293 xDoc->getDocumentStorage());
294 OSL_ENSURE( xStorage.is(),
"Got no document storage!" );
296 uno::Reference< frame::XModel >
297 xModel( Event.Source, uno::UNO_QUERY );
298 OSL_ENSURE(
xModel.is(),
"Got no frame::XModel!" );
300 std::scoped_lock aGuard(
m_aMtx );
302 DocumentList::iterator it = std::find_if(
m_aDocs.begin(),
m_aDocs.end(),
303 [&
xModel](
const DocumentList::value_type& rEntry) { return rEntry.second.xModel == xModel; });
305 OSL_ENSURE( it !=
m_aDocs.end(),
306 "OnSaveDone event notified for unknown document!" );
309 (*it).second.xStorage = xStorage;
313 else if ( Event.EventName ==
"OnSaveAsDone" )
318 uno::Reference<document::XStorageBasedDocument>
const xDoc(
319 Event.Source, uno::UNO_QUERY );
320 OSL_ENSURE( xDoc.is(),
321 "Got no document::XStorageBasedDocument!" );
322 uno::Reference<embed::XStorage>
const xStorage(
323 xDoc->getDocumentStorage());
324 OSL_ENSURE( xStorage.is(),
"Got no document storage!" );
326 uno::Reference< frame::XModel >
327 xModel( Event.Source, uno::UNO_QUERY );
328 OSL_ENSURE(
xModel.is(),
"Got no frame::XModel!" );
332 std::scoped_lock aGuard(
m_aMtx );
334 DocumentList::iterator it = std::find_if(
m_aDocs.begin(),
m_aDocs.end(),
335 [&
xModel](
const DocumentList::value_type& rEntry) { return rEntry.second.xModel == xModel; });
337 OSL_ENSURE( it !=
m_aDocs.end(),
338 "OnSaveAsDone event notified for unknown document!" );
341 (*it).second.xStorage = xStorage;
344 (*it).second.aTitle = title;
348 else if ( Event.EventName ==
"OnTitleChanged"
349 || Event.EventName ==
"OnStorageChanged" )
354 uno::Reference<document::XStorageBasedDocument>
const xDoc(
355 Event.Source, uno::UNO_QUERY );
356 OSL_ENSURE( xDoc.is(),
357 "Got no document::XStorageBasedDocument!" );
358 uno::Reference<embed::XStorage>
const xStorage(
359 xDoc->getDocumentStorage());
360 OSL_ENSURE( xStorage.is(),
"Got no document storage!" );
362 uno::Reference< frame::XModel >
363 xModel( Event.Source, uno::UNO_QUERY );
364 OSL_ENSURE(
xModel.is(),
"Got no frame::XModel!" );
370 std::scoped_lock aGuard(
m_aMtx );
372 DocumentList::iterator it = std::find_if(
m_aDocs.begin(),
m_aDocs.end(),
373 [&
xModel](
const DocumentList::value_type& rEntry) { return rEntry.second.xModel == xModel; });
377 (*it).second.aTitle = aTitle;
400 const lang::EventObject& )
408 uno::Reference< container::XEnumeration > xEnum
411 while ( xEnum->hasMoreElements() )
413 uno::Any aValue = xEnum->nextElement();
419 uno::Reference< frame::XModel >
xModel;
429 std::scoped_lock aGuard(
m_aMtx );
432 [&
xModel](
const DocumentList::value_type& rEntry) { return rEntry.second.xModel == xModel; });
441 uno::Reference< document::XStorageBasedDocument >
442 xDoc(
xModel, uno::UNO_QUERY );
443 OSL_ENSURE( xDoc.is(),
444 "Got no document::XStorageBasedDocument!" );
446 uno::Reference< embed::XStorage > xStorage
447 = xDoc->getDocumentStorage();
448 OSL_ENSURE( xStorage.is(),
"Got no document storage!" );
451 std::scoped_lock aGuard(
m_aMtx );
456 uno::Reference< util::XCloseBroadcaster > xCloseBroadcaster(
458 OSL_ENSURE( xCloseBroadcaster.is(),
459 "buildDocumentsList: got no close broadcaster!" );
461 if ( xCloseBroadcaster.is() )
467 catch ( lang::DisposedException
const & )
472 catch ( lang::NotInitializedException
const & )
480uno::Reference< embed::XStorage >
483 std::scoped_lock aGuard(
m_aMtx );
485 DocumentList::const_iterator it =
m_aDocs.find( rDocId );
487 return uno::Reference< embed::XStorage >();
489 return (*it).second.xStorage;
494 const uno::Reference< frame::XModel > & xModel )
500uno::Reference< frame::XModel >
503 std::scoped_lock aGuard(
m_aMtx );
505 DocumentList::const_iterator it =
m_aDocs.find( rDocId );
507 return uno::Reference< frame::XModel >();
509 return (*it).second.xModel;
515 std::scoped_lock aGuard(
m_aMtx );
524 std::scoped_lock aGuard(
m_aMtx );
526 DocumentList::const_iterator it =
m_aDocs.find( rDocId );
530 return (*it).second.aTitle;
535 std::scoped_lock g(
m_aMtx);
538 auto const i2 = i1->second.streamDateModified.find(uri);
539 if (i2 != i1->second.streamDateModified.end()) {
548 std::scoped_lock g(
m_aMtx);
551 SAL_WARN(
"ucb.ucp.tdoc",
"No document info for <" << uri <<
">");
559 const uno::Reference< frame::XModel > & xModel )
570 const uno::Reference< frame::XModel > & xModel )
575 OUString sURL(
xModel->getURL() );
576 return sURL.match(
"vnd.sun.star.help://" );
581 const uno::Reference< frame::XModel > & xModel )
587 =
xModel->getCurrentController();
590 uno::Reference< frame::XFrame >
xFrame
596 uno::Reference< awt::XTopWindow > xFrameContainer(
597 xFrame->getContainerWindow(), uno::UNO_QUERY );
598 if ( !xFrameContainer.is() )
608 const uno::Reference< frame::XModel > & xModel )
612 std::scoped_lock aGuard(
m_aMtx );
619 catch ( uno::Exception
const & )
625 "Could not instantiate ModuleManager service!" );
636 catch ( lang::IllegalArgumentException
const & )
640 catch ( frame::UnknownModuleException
const & )
645 if ( !aModule.isEmpty() )
648 if ( aModule ==
"com.sun.star.script.BasicIDE" )
660 const uno::Reference< uno::XInterface > & xDoc )
662 uno::Reference< frame::XModel >
xModel( xDoc, uno::UNO_QUERY );
663 uno::Reference< document::XStorageBasedDocument >
664 xStorageBasedDoc(
xModel, uno::UNO_QUERY );
665 if ( !xStorageBasedDoc.is() )
css::util::DateTime GetUNODateTime() const
VALUE_TYPE getOrDefault(const OUString &_rValueName, const VALUE_TYPE &_rDefault) const
void notifyDocumentOpened(std::u16string_view rDocId)
void notifyDocumentClosed(std::u16string_view rDocId)
virtual void SAL_CALL notifyClosing(const css::lang::EventObject &Source) override
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
css::uno::Sequence< OUString > queryDocuments()
static bool isDocumentPreview(const css::uno::Reference< css::frame::XModel > &xModel)
virtual void SAL_CALL documentEventOccured(const css::document::DocumentEvent &Event) override
bool isBasicIDE(const css::uno::Reference< css::frame::XModel > &xModel)
ContentProvider *const m_pDocEventListener
void buildDocumentsList()
OUString queryStorageTitle(const OUString &rDocId)
OfficeDocumentsManager(const css::uno::Reference< css::uno::XComponentContext > &rxContext, ContentProvider *pDocEventListener)
css::uno::Reference< css::frame::XModuleManager2 > m_xModuleMgr
css::uno::Reference< css::frame::XModel > queryDocumentModel(const OUString &rDocId)
static OUString queryDocumentId(const css::uno::Reference< css::frame::XModel > &xModel)
virtual ~OfficeDocumentsManager() override
css::uno::Reference< css::frame::XGlobalEventBroadcaster > m_xDocEvtNotifier
void updateStreamDateModified(OUString const &uri)
bool isOfficeDocument(const css::uno::Reference< css::uno::XInterface > &xDoc)
css::util::DateTime queryStreamDateModified(OUString const &uri)
css::uno::Reference< css::embed::XStorage > queryStorage(const OUString &rDocId)
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
static bool isHelpDocument(const css::uno::Reference< css::frame::XModel > &xModel)
css::uno::Reference< css::uno::XComponentContext > m_xContext
::rtl::Reference< OfficeDocumentsCloseListener > const m_xDocCloseListener
static bool isWithoutOrInTopLevelFrame(const css::uno::Reference< css::frame::XModel > &xModel)
#define TOOLS_WARN_EXCEPTION(area, stream)
#define SAL_WARN(area, stream)
COMPHELPER_DLLPUBLIC OUString getDocumentTitle(const css::uno::Reference< css::frame::XModel > &_rxDocument)
css::uno::Sequence< typename M::key_type > mapKeysToSequence(M const &map)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
Reference< XController > xController
Reference< XFrame > xFrame
Reference< XModel > xModel
static OUString getDocumentId(const uno::Reference< uno::XInterface > &xDoc)