calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / connectivity / source / inc / writer / WConnection.hxx
blob5ae8b2818e0f17c86b5520b9a6aada26850986f1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #pragma once
22 #include <memory>
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
31 class XTextDocument;
33 namespace utl
35 class CloseVeto;
38 namespace connectivity::writer
40 class ODriver;
41 class OWriterConnection : public file::OConnection
43 // the text document:
44 css::uno::Reference<css::text::XTextDocument> m_xDoc;
45 OUString m_sPassword;
46 OUString m_aFileName;
47 oslInterlockedCount m_nDocCount = 0;
49 class CloseVetoButTerminateListener
50 : public cppu::WeakComponentImplHelper<css::frame::XTerminateListener>
52 private:
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;
58 osl::Mutex m_aMutex;
60 public:
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);
74 void stop()
76 m_pCloseListener.reset();
77 if (!m_xDesktop.is())
78 return;
79 m_xDesktop->removeTerminateListener(this);
80 m_xDesktop.clear();
83 // XTerminateListener
84 void SAL_CALL queryTermination(const css::lang::EventObject& /*rEvent*/) override {}
86 void SAL_CALL notifyTermination(const css::lang::EventObject& /*rEvent*/) override
88 stop();
91 void SAL_CALL disposing() override
93 stop();
94 cppu::WeakComponentImplHelperBase::disposing();
97 void SAL_CALL disposing(const css::lang::EventObject& rEvent) override
99 const bool bShutDown = (rEvent.Source == m_xDesktop);
100 if (bShutDown)
101 stop();
105 rtl::Reference<CloseVetoButTerminateListener> m_xCloseVetoButTerminateListener;
107 public:
108 OWriterConnection(ODriver* _pDriver);
109 ~OWriterConnection() override;
111 void construct(const OUString& rURL,
112 const css::uno::Sequence<css::beans::PropertyValue>& rInfo) override;
114 // XServiceInfo
115 DECLARE_SERVICE_INFO();
117 // OComponentHelper
118 void SAL_CALL disposing() override;
120 // XConnection
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();
131 void releaseDoc();
133 class ODocHolder
135 OWriterConnection* m_pConnection;
136 css::uno::Reference<css::text::XTextDocument> m_xDoc;
138 public:
139 ODocHolder(OWriterConnection* _pConnection)
140 : m_pConnection(_pConnection)
142 m_xDoc = m_pConnection->acquireDoc();
144 ~ODocHolder()
146 m_xDoc.clear();
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: */