LibreOffice Module vcl (master) 1
qt5/QtClipboard.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 */
10
11#pragma once
12
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>
20
21#include <QtGui/QClipboard>
22
30class QtClipboard final
31 : public QObject,
32 public cppu::WeakComponentImplHelper<css::datatransfer::clipboard::XSystemClipboard,
33 css::datatransfer::clipboard::XFlushableClipboard,
34 css::lang::XServiceInfo>
35{
36 Q_OBJECT
37
38 osl::Mutex m_aMutex;
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
44 // true, if LO really wants to give up clipboard ownership
46
47 // if not empty, this holds the setContents provided XTransferable or a QtClipboardTransferable
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;
52
53 static bool isOwner(const QClipboard::Mode aMode);
54 static bool isSupported(const QClipboard::Mode aMode);
55
56 explicit QtClipboard(OUString aModeString, const QClipboard::Mode aMode);
57
58private Q_SLOTS:
59 void handleChanged(QClipboard::Mode mode);
61
62signals:
64
65public:
66 // factory function to construct only valid QtClipboard objects by name
67 static css::uno::Reference<css::uno::XInterface> create(const OUString& aModeString);
68
69 // XServiceInfo
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;
73
74 // XClipboard
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)
79 override;
80 virtual OUString SAL_CALL getName() override;
81
82 // XClipboardEx
83 virtual sal_Int8 SAL_CALL getRenderingCapabilities() override;
84
85 // XFlushableClipboard
86 virtual void SAL_CALL flushClipboard() override;
87
88 // XClipboardNotifier
89 virtual void SAL_CALL addClipboardListener(
90 const css::uno::Reference<css::datatransfer::clipboard::XClipboardListener>& listener)
91 override;
92 virtual void SAL_CALL removeClipboardListener(
93 const css::uno::Reference<css::datatransfer::clipboard::XClipboardListener>& listener)
94 override;
95};
96
97/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
This implementation has two main functions, which handle the clipboard content: the XClipboard::setCo...
virtual OUString SAL_CALL getName() override
void handleChanged(QClipboard::Mode mode)
virtual OUString SAL_CALL getImplementationName() override
void handleClearClipboard()
css::uno::Reference< css::datatransfer::clipboard::XClipboardOwner > m_aOwner
virtual void SAL_CALL flushClipboard() override
static css::uno::Reference< css::uno::XInterface > create(const OUString &aModeString)
static bool isSupported(const QClipboard::Mode aMode)
virtual void SAL_CALL removeClipboardListener(const css::uno::Reference< css::datatransfer::clipboard::XClipboardListener > &listener) override
virtual void SAL_CALL addClipboardListener(const css::uno::Reference< css::datatransfer::clipboard::XClipboardListener > &listener) override
void clearClipboard()
QtClipboard(OUString aModeString, const QClipboard::Mode aMode)
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
osl::Mutex m_aMutex
const OUString m_aClipboardName
virtual void SAL_CALL setContents(const css::uno::Reference< css::datatransfer::XTransferable > &xTrans, const css::uno::Reference< css::datatransfer::clipboard::XClipboardOwner > &xClipboardOwner) override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
bool m_bOwnClipboardChange
const QClipboard::Mode m_aClipboardMode
css::uno::Reference< css::datatransfer::XTransferable > m_aContents
std::vector< css::uno::Reference< css::datatransfer::clipboard::XClipboardListener > > m_aListeners
virtual css::uno::Reference< css::datatransfer::XTransferable > SAL_CALL getContents() override
static bool isOwner(const QClipboard::Mode aMode)
virtual sal_Int8 SAL_CALL getRenderingCapabilities() override
unsigned char sal_Bool
signed char sal_Int8