blob: 52c43a2541b192035deb5a9038426f3fe460d9f7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
/* -*- 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 <QtWidgets/QApplication>
#include <QtGui/QClipboard>
#include <Qt5Clipboard.hxx>
#include <Qt5Tools.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;
if (rFlavor.MimeType == "text/plain;charset=utf-16")
{
const QClipboard* clipboard = QApplication::clipboard();
QString clipboardContent = clipboard->text();
OUString sContent = toOUString(clipboardContent);
aRet <<= sContent.replaceAll("\r\n", "\n");
}
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;
if (m_aContents.is())
{
css::datatransfer::DataFlavor aFlavor;
aFlavor.MimeType = "text/plain;charset=utf-16";
aFlavor.DataType = cppu::UnoType<OUString>::get();
Any aValue;
try
{
aValue = xTrans->getTransferData(aFlavor);
}
catch (...)
{
}
OUString aString;
aValue >>= aString;
QClipboard* clipboard = QApplication::clipboard();
clipboard->setText(toQString(aString));
}
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: */
|