1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
23 #include <file/FConnection.hxx>
24 #include <com/sun/star/frame/XDesktop2.hpp>
25 #include <com/sun/star/frame/XTerminateListener.hpp>
26 #include <rtl/ref.hxx>
27 #include <unotools/closeveto.hxx>
29 namespace com::sun::star::text
38 namespace connectivity::writer
41 class OWriterConnection
: public file::OConnection
44 css::uno::Reference
<css::text::XTextDocument
> m_xDoc
;
47 oslInterlockedCount m_nDocCount
= 0;
49 class CloseVetoButTerminateListener
50 : public cppu::WeakComponentImplHelper
<css::frame::XTerminateListener
>
53 /// close listener that vetoes so nobody else disposes m_xDoc
54 std::unique_ptr
<utl::CloseVeto
> m_pCloseListener
;
55 /// but also listen to XDesktop and if app is terminating anyway, dispose m_xDoc while
56 /// its still possible to do so properly
57 css::uno::Reference
<css::frame::XDesktop2
> m_xDesktop
;
61 CloseVetoButTerminateListener()
62 : cppu::WeakComponentImplHelper
<css::frame::XTerminateListener
>(m_aMutex
)
66 void start(const css::uno::Reference
<css::uno::XInterface
>& rCloseable
,
67 const css::uno::Reference
<css::frame::XDesktop2
>& rDesktop
)
69 m_xDesktop
= rDesktop
;
70 m_xDesktop
->addTerminateListener(this);
71 m_pCloseListener
= std::make_unique
<utl::CloseVeto
>(rCloseable
, true);
76 m_pCloseListener
.reset();
79 m_xDesktop
->removeTerminateListener(this);
84 void SAL_CALL
queryTermination(const css::lang::EventObject
& /*rEvent*/) override
{}
86 void SAL_CALL
notifyTermination(const css::lang::EventObject
& /*rEvent*/) override
91 void SAL_CALL
disposing() override
94 cppu::WeakComponentImplHelperBase::disposing();
97 void SAL_CALL
disposing(const css::lang::EventObject
& rEvent
) override
99 const bool bShutDown
= (rEvent
.Source
== m_xDesktop
);
105 rtl::Reference
<CloseVetoButTerminateListener
> m_xCloseVetoButTerminateListener
;
108 OWriterConnection(ODriver
* _pDriver
);
109 ~OWriterConnection() override
;
111 void construct(const OUString
& rURL
,
112 const css::uno::Sequence
<css::beans::PropertyValue
>& rInfo
) override
;
115 DECLARE_SERVICE_INFO();
118 void SAL_CALL
disposing() override
;
121 css::uno::Reference
<css::sdbc::XDatabaseMetaData
> SAL_CALL
getMetaData() override
;
122 css::uno::Reference
<css::sdbcx::XTablesSupplier
> createCatalog() override
;
123 css::uno::Reference
<css::sdbc::XStatement
> SAL_CALL
createStatement() override
;
124 css::uno::Reference
<css::sdbc::XPreparedStatement
>
125 SAL_CALL
prepareStatement(const OUString
& sql
) override
;
126 css::uno::Reference
<css::sdbc::XPreparedStatement
>
127 SAL_CALL
prepareCall(const OUString
& sql
) override
;
129 // no interface methods
130 css::uno::Reference
<css::text::XTextDocument
> const& acquireDoc();
135 OWriterConnection
* m_pConnection
;
136 css::uno::Reference
<css::text::XTextDocument
> m_xDoc
;
139 ODocHolder(OWriterConnection
* _pConnection
)
140 : m_pConnection(_pConnection
)
142 m_xDoc
= m_pConnection
->acquireDoc();
147 m_pConnection
->releaseDoc();
149 const css::uno::Reference
<css::text::XTextDocument
>& getDoc() const { return m_xDoc
; }
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */