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
{
30 namespace sheet
{ class XSpreadsheetDocument
; }
33 namespace utl
{ class CloseVeto
; }
36 namespace connectivity::calc
39 class OCalcConnection
: public file::OConnection
41 // the spreadsheet document:
42 css::uno::Reference
< css::sheet::XSpreadsheetDocument
> m_xDoc
;
45 oslInterlockedCount m_nDocCount
;
47 class CloseVetoButTerminateListener
: public cppu::WeakComponentImplHelper
<css::frame::XTerminateListener
>
50 /// close listener that vetoes so nobody else disposes m_xDoc
51 std::unique_ptr
<utl::CloseVeto
> m_pCloseListener
;
52 /// but also listen to XDesktop and if app is terminating anyway, dispose m_xDoc while
53 /// its still possible to do so properly
54 css::uno::Reference
<css::frame::XDesktop2
> m_xDesktop
;
57 CloseVetoButTerminateListener()
58 : cppu::WeakComponentImplHelper
<css::frame::XTerminateListener
>(m_aMutex
)
62 void start(const css::uno::Reference
<css::uno::XInterface
>& rCloseable
,
63 const css::uno::Reference
<css::frame::XDesktop2
>& rDesktop
)
65 m_xDesktop
= rDesktop
;
66 m_xDesktop
->addTerminateListener(this);
67 m_pCloseListener
.reset(new utl::CloseVeto(rCloseable
, true));
72 m_pCloseListener
.reset();
75 m_xDesktop
->removeTerminateListener(this);
80 virtual void SAL_CALL
queryTermination(const css::lang::EventObject
& /*rEvent*/) override
84 virtual void SAL_CALL
notifyTermination(const css::lang::EventObject
& /*rEvent*/) override
89 virtual void SAL_CALL
disposing() override
92 cppu::WeakComponentImplHelperBase::disposing();
95 virtual void SAL_CALL
disposing(const css::lang::EventObject
& rEvent
) override
97 const bool bShutDown
= (rEvent
.Source
== m_xDesktop
);
103 rtl::Reference
<CloseVetoButTerminateListener
> m_xCloseVetoButTerminateListener
;
106 OCalcConnection(ODriver
* _pDriver
);
107 virtual ~OCalcConnection() override
;
109 virtual void construct(const OUString
& _rUrl
,
110 const css::uno::Sequence
< css::beans::PropertyValue
>& _rInfo
) override
;
113 DECLARE_SERVICE_INFO();
116 virtual void SAL_CALL
disposing() override
;
119 virtual css::uno::Reference
< css::sdbc::XDatabaseMetaData
> SAL_CALL
getMetaData( ) override
;
120 virtual css::uno::Reference
< css::sdbcx::XTablesSupplier
> createCatalog() override
;
121 virtual css::uno::Reference
< css::sdbc::XStatement
> SAL_CALL
createStatement( ) override
;
122 virtual css::uno::Reference
< css::sdbc::XPreparedStatement
> SAL_CALL
prepareStatement( const OUString
& sql
) override
;
123 virtual css::uno::Reference
< css::sdbc::XPreparedStatement
> SAL_CALL
prepareCall( const OUString
& sql
) override
;
125 // no interface methods
126 css::uno::Reference
< css::sheet::XSpreadsheetDocument
> const & acquireDoc();
131 OCalcConnection
* m_pConnection
;
132 css::uno::Reference
< css::sheet::XSpreadsheetDocument
> m_xDoc
;
134 ODocHolder(OCalcConnection
* _pConnection
) : m_pConnection(_pConnection
)
136 m_xDoc
= m_pConnection
->acquireDoc();
141 m_pConnection
->releaseDoc();
143 const css::uno::Reference
< css::sheet::XSpreadsheetDocument
>& getDoc() const { return m_xDoc
; }
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */