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/.
13 #include <com/sun/star/lang/XServiceInfo.hpp>
14 #include <com/sun/star/datatransfer/XTransferable.hpp>
15 #include <com/sun/star/datatransfer/clipboard/XSystemClipboard.hpp>
16 #include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp>
17 #include <com/sun/star/datatransfer/clipboard/XClipboardOwner.hpp>
18 #include <com/sun/star/datatransfer/clipboard/XClipboardListener.hpp>
19 #include <cppuhelper/compbase.hxx>
21 #include <QtGui/QClipboard>
24 * This implementation has two main functions, which handle the clipboard content:
25 * the XClipboard::setContent function and the QClipboard::change signal handler.
27 * The first just sets the respective clipboard to the expected content from LO,
28 * the latter will handle any reported changes.
30 class Qt5Clipboard final
32 public cppu::WeakComponentImplHelper
<css::datatransfer::clipboard::XSystemClipboard
,
33 css::datatransfer::clipboard::XFlushableClipboard
,
34 css::lang::XServiceInfo
>
39 const OUString m_aClipboardName
;
40 const QClipboard::Mode m_aClipboardMode
;
41 // has to be set, if LO changes the QClipboard itself, so it won't instantly lose
42 // ownership by it's self-triggered QClipboard::changed handler
43 bool m_bOwnClipboardChange
;
44 // true, if LO really wants to give up clipboard ownership
47 // if not empty, this holds the setContents provided XTransferable or a Qt5ClipboardTransferable
48 css::uno::Reference
<css::datatransfer::XTransferable
> m_aContents
;
49 // the owner of the current contents, which must be informed on content change
50 css::uno::Reference
<css::datatransfer::clipboard::XClipboardOwner
> m_aOwner
;
51 std::vector
<css::uno::Reference
<css::datatransfer::clipboard::XClipboardListener
>> m_aListeners
;
53 static bool isOwner(const QClipboard::Mode aMode
);
54 static bool isSupported(const QClipboard::Mode aMode
);
56 explicit Qt5Clipboard(const OUString
& aModeString
, const QClipboard::Mode aMode
);
59 void handleChanged(QClipboard::Mode mode
);
60 void handleClearClipboard();
63 void clearClipboard();
66 // factory function to construct only valid Qt5Clipboard objects by name
67 static css::uno::Reference
<css::uno::XInterface
> create(const OUString
& aModeString
);
70 virtual OUString SAL_CALL
getImplementationName() override
;
71 virtual sal_Bool SAL_CALL
supportsService(const OUString
& ServiceName
) override
;
72 virtual css::uno::Sequence
<OUString
> SAL_CALL
getSupportedServiceNames() override
;
75 virtual css::uno::Reference
<css::datatransfer::XTransferable
> SAL_CALL
getContents() override
;
76 virtual void SAL_CALL
setContents(
77 const css::uno::Reference
<css::datatransfer::XTransferable
>& xTrans
,
78 const css::uno::Reference
<css::datatransfer::clipboard::XClipboardOwner
>& xClipboardOwner
)
80 virtual OUString SAL_CALL
getName() override
;
83 virtual sal_Int8 SAL_CALL
getRenderingCapabilities() override
;
85 // XFlushableClipboard
86 virtual void SAL_CALL
flushClipboard() override
;
89 virtual void SAL_CALL
addClipboardListener(
90 const css::uno::Reference
<css::datatransfer::clipboard::XClipboardListener
>& listener
)
92 virtual void SAL_CALL
removeClipboardListener(
93 const css::uno::Reference
<css::datatransfer::clipboard::XClipboardListener
>& listener
)
97 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */