bump product version to 6.4.0.3
[LibreOffice.git] / vcl / inc / qt5 / Qt5Transferable.hxx
blob0d1cc70502aa4e1e42bd8e162d873b824951dc3c
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 */
11 #pragma once
13 #include <cppuhelper/compbase.hxx>
14 #include <com/sun/star/datatransfer/XTransferable.hpp>
16 #include <QtCore/QMimeData>
17 #include <QtCore/QStringList>
18 #include <QtGui/QClipboard>
20 /**
21 * Qt5Transferable classes are used to read QMimeData via the XTransferable
22 * interface. All the functionality is already implemented in the Qt5Transferable.
24 * The specialisations map to the two users, which provide QMimeData: the Clipboard
25 * and the Drag'n'Drop functionality.
27 * LO itself seem to just accept "text/plain;charset=utf-16", so it relies on the
28 * backend to convert to this charset, but still offers "text/plain" itself.
30 * It's the "mirror" interface of the Qt5MimeData, which is defined below.
31 **/
32 class Qt5Transferable : public cppu::WeakImplHelper<css::datatransfer::XTransferable>
34 Qt5Transferable(const Qt5Transferable&) = delete;
36 const QMimeData* m_pMimeData;
37 osl::Mutex m_aMutex;
38 bool m_bConvertFromLocale;
39 css::uno::Sequence<css::datatransfer::DataFlavor> m_aMimeTypeSeq;
41 public:
42 Qt5Transferable(const QMimeData* pMimeData);
43 const QMimeData* mimeData() const { return m_pMimeData; }
45 css::uno::Sequence<css::datatransfer::DataFlavor> SAL_CALL getTransferDataFlavors() override;
46 sal_Bool SAL_CALL isDataFlavorSupported(const css::datatransfer::DataFlavor& rFlavor) override;
47 css::uno::Any SAL_CALL getTransferData(const css::datatransfer::DataFlavor& rFlavor) override;
50 /**
51 * The QClipboard's QMimeData is volatile. As written in the QClipboard::mimeData
52 * documentation, "the pointer returned might become invalidated when the contents
53 * of the clipboard changes". Therefore it can just be accessed reliably inside
54 * the QClipboard's object thread, which is the QApplication's thread, so all of
55 * the access has to go through RunInMainThread().
57 * If we detect a QMimeData change, we simply drop reporting any content. In theory
58 * we can recover in the case where there hadn't been any calls of the XTransferable
59 * interface, but currently we don't. But we ensure to never report mixed content,
60 * so we'll just cease operation on QMimeData change.
61 **/
62 class Qt5ClipboardTransferable final : public Qt5Transferable
64 // to detect in-flight QMimeData changes
65 const QClipboard::Mode m_aMode;
67 bool hasInFlightChanged() const;
69 public:
70 explicit Qt5ClipboardTransferable(const QClipboard::Mode aMode, const QMimeData* pMimeData);
72 // these are the same then Qt5Transferable, except they go through RunInMainThread
73 css::uno::Sequence<css::datatransfer::DataFlavor> SAL_CALL getTransferDataFlavors() override;
74 sal_Bool SAL_CALL isDataFlavorSupported(const css::datatransfer::DataFlavor& rFlavor) override;
75 css::uno::Any SAL_CALL getTransferData(const css::datatransfer::DataFlavor& rFlavor) override;
78 /**
79 * Convenience typedef for better code readability
81 * This just uses the QMimeData provided by the QWidgets D'n'D events.
82 **/
83 typedef Qt5Transferable Qt5DnDTransferable;
85 /**
86 * A lazy loading QMimeData for XTransferable reads
88 * This is an interface class to make a XTransferable read accessible as a
89 * QMimeData. The mime data is just stored inside the XTransferable, never
90 * in the QMimeData itself! It's objects are just used for QClipboard to read
91 * the XTransferable data.
93 * Like XTransferable itself, this class should be considered an immutable
94 * container for mime data. There is no need to ever set any of its data.
96 * LO will offer at least UTF-16, if there is a viable text representation.
97 * If LO misses to offer a UTF-8 or a locale encoded string, these objects
98 * will offer them themselves and convert from UTF-16 on demand.
100 * It's the "mirror" interface of the Qt5Transferable.
102 class Qt5MimeData final : public QMimeData
104 friend class Qt5ClipboardTransferable;
106 const css::uno::Reference<css::datatransfer::XTransferable> m_aContents;
107 mutable bool m_bHaveNoCharset; // = uses the locale charset
108 mutable bool m_bHaveUTF8;
109 mutable QStringList m_aMimeTypeList;
111 QVariant retrieveData(const QString& mimeType, QVariant::Type type) const override;
113 public:
114 explicit Qt5MimeData(const css::uno::Reference<css::datatransfer::XTransferable>& aContents);
116 bool hasFormat(const QString& mimeType) const override;
117 QStringList formats() const override;
119 bool deepCopy(QMimeData** const) const;
121 css::datatransfer::XTransferable* xTransferable() const { return m_aContents.get(); }
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */