[Libreoffice-commits] core.git: vcl/inc vcl/Library_vclplug_qt5.mk vcl/qt5
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Thu Oct 4 08:19:58 UTC 2018
vcl/Library_vclplug_qt5.mk | 1
vcl/inc/qt5/Qt5Clipboard.hxx | 95 ++++++++++++++++++++++++++++
vcl/inc/qt5/Qt5Instance.hxx | 3
vcl/qt5/Qt5Clipboard.cxx | 142 +++++++++++++++++++++++++++++++++++++++++++
vcl/qt5/Qt5Instance.cxx | 23 ++++++
5 files changed, 264 insertions(+)
New commits:
commit de40fe552e51e1d634c2401afef305ba4af91799
Author: Katarina Behrens <Katarina.Behrens at cib.de>
AuthorDate: Fri Sep 14 14:53:40 2018 +0200
Commit: Katarina Behrens <Katarina.Behrens at cib.de>
CommitDate: Thu Oct 4 10:19:33 2018 +0200
Clipboard support for qt5, first cut
this adds just enough of basic UNO ifaces to have SID_PASTE enabled.
It can't actually paste anything yet.
Change-Id: I82e8ef37e11e9df21d27f08d4d199f3e5924ed84
Reviewed-on: https://gerrit.libreoffice.org/60494
Tested-by: Jenkins
Reviewed-by: Katarina Behrens <Katarina.Behrens at cib.de>
diff --git a/vcl/Library_vclplug_qt5.mk b/vcl/Library_vclplug_qt5.mk
index eda2e104d941..c7fa015442b0 100644
--- a/vcl/Library_vclplug_qt5.mk
+++ b/vcl/Library_vclplug_qt5.mk
@@ -82,6 +82,7 @@ endif
$(eval $(call gb_Library_add_exception_objects,vclplug_qt5,\
vcl/qt5/Qt5AccessibleWidget \
vcl/qt5/Qt5Bitmap \
+ vcl/qt5/Qt5Clipboard \
vcl/qt5/Qt5Data \
vcl/qt5/Qt5FilePicker \
vcl/qt5/Qt5Font \
diff --git a/vcl/inc/qt5/Qt5Clipboard.hxx b/vcl/inc/qt5/Qt5Clipboard.hxx
new file mode 100644
index 000000000000..a2ba86a06870
--- /dev/null
+++ b/vcl/inc/qt5/Qt5Clipboard.hxx
@@ -0,0 +1,95 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#pragma once
+
+#include <cppuhelper/compbase.hxx>
+
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/datatransfer/XTransferable.hpp>
+#include <com/sun/star/datatransfer/clipboard/XSystemClipboard.hpp>
+#include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp>
+#include <com/sun/star/datatransfer/clipboard/XClipboardOwner.hpp>
+#include <com/sun/star/datatransfer/clipboard/XClipboardListener.hpp>
+
+using namespace com::sun::star;
+using namespace com::sun::star::uno;
+using namespace com::sun::star::lang;
+
+class Qt5Transferable : public cppu::WeakImplHelper<css::datatransfer::XTransferable>
+{
+public:
+ virtual css::uno::Any SAL_CALL
+ getTransferData(const css::datatransfer::DataFlavor& rFlavor) override;
+
+ virtual std::vector<css::datatransfer::DataFlavor> getTransferDataFlavorsAsVector();
+
+ virtual css::uno::Sequence<css::datatransfer::DataFlavor>
+ SAL_CALL getTransferDataFlavors() override;
+ virtual sal_Bool SAL_CALL
+ isDataFlavorSupported(const css::datatransfer::DataFlavor& rFlavor) override;
+};
+
+class VclQt5Clipboard
+ : public cppu::WeakComponentImplHelper<datatransfer::clipboard::XSystemClipboard,
+ datatransfer::clipboard::XFlushableClipboard,
+ XServiceInfo>
+{
+ osl::Mutex m_aMutex;
+ Reference<css::datatransfer::XTransferable> m_aContents;
+ Reference<css::datatransfer::clipboard::XClipboardOwner> m_aOwner;
+ std::vector<Reference<css::datatransfer::clipboard::XClipboardListener>> m_aListeners;
+
+public:
+ explicit VclQt5Clipboard();
+ virtual ~VclQt5Clipboard();
+
+ /*
+ * XServiceInfo
+ */
+
+ virtual OUString SAL_CALL getImplementationName() override;
+ virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
+ virtual Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
+
+ /*
+ * XClipboard
+ */
+
+ virtual Reference<css::datatransfer::XTransferable> SAL_CALL getContents() override;
+
+ virtual void SAL_CALL setContents(
+ const Reference<css::datatransfer::XTransferable>& xTrans,
+ const Reference<css::datatransfer::clipboard::XClipboardOwner>& xClipboardOwner) override;
+
+ virtual OUString SAL_CALL getName() override;
+
+ /*
+ * XClipboardEx
+ */
+
+ virtual sal_Int8 SAL_CALL getRenderingCapabilities() override;
+
+ /*
+ * XFlushableClipboard
+ */
+ virtual void SAL_CALL flushClipboard() override;
+
+ /*
+ * XClipboardNotifier
+ */
+ virtual void SAL_CALL addClipboardListener(
+ const Reference<css::datatransfer::clipboard::XClipboardListener>& listener) override;
+
+ virtual void SAL_CALL removeClipboardListener(
+ const Reference<css::datatransfer::clipboard::XClipboardListener>& listener) override;
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/qt5/Qt5Instance.hxx b/vcl/inc/qt5/Qt5Instance.hxx
index a2ceae0139e2..58ab6e329544 100644
--- a/vcl/inc/qt5/Qt5Instance.hxx
+++ b/vcl/inc/qt5/Qt5Instance.hxx
@@ -109,6 +109,9 @@ public:
virtual css::uno::Reference<css::ui::dialogs::XFolderPicker2>
createFolderPicker(const css::uno::Reference<css::uno::XComponentContext>&) override;
+
+ virtual css::uno::Reference<css::uno::XInterface>
+ CreateClipboard(const css::uno::Sequence<css::uno::Any>& i_rArguments) override;
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qt5/Qt5Clipboard.cxx b/vcl/qt5/Qt5Clipboard.cxx
new file mode 100644
index 000000000000..ac2daae520c8
--- /dev/null
+++ b/vcl/qt5/Qt5Clipboard.cxx
@@ -0,0 +1,142 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#include <comphelper/solarmutex.hxx>
+#include <comphelper/sequence.hxx>
+#include <cppuhelper/supportsservice.hxx>
+#include <vcl/svapp.hxx>
+
+#include <Qt5Clipboard.hxx>
+
+std::vector<css::datatransfer::DataFlavor> Qt5Transferable::getTransferDataFlavorsAsVector()
+{
+ std::vector<css::datatransfer::DataFlavor> aVector;
+
+ // FIXME: this is fake
+ css::datatransfer::DataFlavor aFlavor;
+ aFlavor.MimeType = "text/plain;charset=utf-16";
+ aFlavor.DataType = cppu::UnoType<OUString>::get();
+ aVector.push_back(aFlavor);
+
+ return aVector;
+}
+
+css::uno::Sequence<css::datatransfer::DataFlavor> SAL_CALL Qt5Transferable::getTransferDataFlavors()
+{
+ return comphelper::containerToSequence(getTransferDataFlavorsAsVector());
+}
+
+sal_Bool SAL_CALL
+Qt5Transferable::isDataFlavorSupported(const css::datatransfer::DataFlavor& /*rFlavor*/)
+{
+ const std::vector<css::datatransfer::DataFlavor> aAll = getTransferDataFlavorsAsVector();
+
+ return !aAll.empty(); //FIXME
+}
+
+/*
+ * XTransferable
+ */
+
+css::uno::Any SAL_CALL
+Qt5Transferable::getTransferData(const css::datatransfer::DataFlavor& /*rFlavor*/)
+{
+ css::uno::Any aRet;
+ Sequence<sal_Int8> aSeq(0, 4); //FIXME
+ aRet <<= aSeq;
+ return aRet;
+}
+
+VclQt5Clipboard::VclQt5Clipboard()
+ : cppu::WeakComponentImplHelper<datatransfer::clipboard::XSystemClipboard,
+ datatransfer::clipboard::XFlushableClipboard, XServiceInfo>(
+ m_aMutex)
+{
+}
+
+void VclQt5Clipboard::flushClipboard()
+{
+ SolarMutexGuard aGuard;
+ return;
+}
+
+VclQt5Clipboard::~VclQt5Clipboard() {}
+
+OUString VclQt5Clipboard::getImplementationName()
+{
+ return OUString("com.sun.star.datatransfer.VclQt5Clipboard");
+}
+
+Sequence<OUString> VclQt5Clipboard::getSupportedServiceNames()
+{
+ Sequence<OUString> aRet{ "com.sun.star.datatransfer.clipboard.SystemClipboard" };
+ return aRet;
+}
+
+sal_Bool VclQt5Clipboard::supportsService(const OUString& ServiceName)
+{
+ return cppu::supportsService(this, ServiceName);
+}
+
+Reference<css::datatransfer::XTransferable> VclQt5Clipboard::getContents()
+{
+ if (!m_aContents.is())
+ m_aContents = new Qt5Transferable();
+
+ return m_aContents;
+}
+
+void VclQt5Clipboard::setContents(
+ const Reference<css::datatransfer::XTransferable>& xTrans,
+ const Reference<css::datatransfer::clipboard::XClipboardOwner>& xClipboardOwner)
+{
+ osl::ClearableMutexGuard aGuard(m_aMutex);
+ Reference<datatransfer::clipboard::XClipboardOwner> xOldOwner(m_aOwner);
+ Reference<datatransfer::XTransferable> xOldContents(m_aContents);
+ m_aContents = xTrans;
+ m_aOwner = xClipboardOwner;
+
+ std::vector<Reference<datatransfer::clipboard::XClipboardListener>> aListeners(m_aListeners);
+ datatransfer::clipboard::ClipboardEvent aEv;
+
+ aEv.Contents = getContents();
+
+ aGuard.clear();
+
+ if (xOldOwner.is() && xOldOwner != xClipboardOwner)
+ xOldOwner->lostOwnership(this, xOldContents);
+ for (auto const& listener : aListeners)
+ {
+ listener->changedContents(aEv);
+ }
+}
+
+OUString VclQt5Clipboard::getName() { return OUString("CLIPBOARD"); }
+
+sal_Int8 VclQt5Clipboard::getRenderingCapabilities() { return 0; }
+
+void VclQt5Clipboard::addClipboardListener(
+ const Reference<datatransfer::clipboard::XClipboardListener>& listener)
+{
+ osl::ClearableMutexGuard aGuard(m_aMutex);
+
+ m_aListeners.push_back(listener);
+}
+
+void VclQt5Clipboard::removeClipboardListener(
+ const Reference<datatransfer::clipboard::XClipboardListener>& listener)
+{
+ osl::ClearableMutexGuard aGuard(m_aMutex);
+
+ m_aListeners.erase(std::remove(m_aListeners.begin(), m_aListeners.end(), listener),
+ m_aListeners.end());
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qt5/Qt5Instance.cxx b/vcl/qt5/Qt5Instance.cxx
index f2811e46db5a..71e9883416f1 100644
--- a/vcl/qt5/Qt5Instance.cxx
+++ b/vcl/qt5/Qt5Instance.cxx
@@ -20,7 +20,10 @@
#include <Qt5Instance.hxx>
#include <Qt5Instance.moc>
+#include <com/sun/star/lang/IllegalArgumentException.hpp>
+
#include <Qt5Bitmap.hxx>
+#include <Qt5Clipboard.hxx>
#include <Qt5Data.hxx>
#include <Qt5FilePicker.hxx>
#include <Qt5Frame.hxx>
@@ -218,6 +221,26 @@ Qt5Instance::createFolderPicker(const css::uno::Reference<css::uno::XComponentCo
new Qt5FilePicker(QFileDialog::Directory));
}
+css::uno::Reference<css::uno::XInterface>
+Qt5Instance::CreateClipboard(const css::uno::Sequence<css::uno::Any>& arguments)
+{
+ OUString sel;
+ if (arguments.getLength() == 0)
+ {
+ sel = "CLIPBOARD";
+ }
+ else if (arguments.getLength() != 1 || !(arguments[0] >>= sel))
+ {
+ throw css::lang::IllegalArgumentException("bad Qt5Instance::CreateClipboard arguments",
+ css::uno::Reference<css::uno::XInterface>(), -1);
+ }
+
+ css::uno::Reference<css::uno::XInterface> xClipboard(
+ static_cast<cppu::OWeakObject*>(new VclQt5Clipboard()));
+
+ return xClipboard;
+}
+
extern "C" {
VCLPLUG_QT5_PUBLIC SalInstance* create_SalInstance()
{
More information about the Libreoffice-commits
mailing list