LibreOffice Module vcl (master)  1
Qt5Clipboard.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>
19 #include <cppuhelper/compbase.hxx>
20 
21 #include <QtGui/QClipboard>
22 
30 class Qt5Clipboard 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 
45  // if not empty, this holds the setContents provided XTransferable or a Qt5ClipboardTransferable
46  css::uno::Reference<css::datatransfer::XTransferable> m_aContents;
47  // the owner of the current contents, which must be informed on content change
48  css::uno::Reference<css::datatransfer::clipboard::XClipboardOwner> m_aOwner;
49  std::vector<css::uno::Reference<css::datatransfer::clipboard::XClipboardListener>> m_aListeners;
50 
51  static bool isOwner(const QClipboard::Mode aMode);
52  static bool isSupported(const QClipboard::Mode aMode);
53 
54  explicit Qt5Clipboard(const OUString& aModeString, const QClipboard::Mode aMode);
55 
56 private Q_SLOTS:
57  void handleChanged(QClipboard::Mode mode);
58 
59 public:
60  // factory function to construct only valid Qt5Clipboard objects by name
61  static css::uno::Reference<css::uno::XInterface> create(const OUString& aModeString);
62 
63  // XServiceInfo
64  virtual OUString SAL_CALL getImplementationName() override;
65  virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
66  virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
67 
68  // XClipboard
69  virtual css::uno::Reference<css::datatransfer::XTransferable> SAL_CALL getContents() override;
70  virtual void SAL_CALL setContents(
71  const css::uno::Reference<css::datatransfer::XTransferable>& xTrans,
72  const css::uno::Reference<css::datatransfer::clipboard::XClipboardOwner>& xClipboardOwner)
73  override;
74  virtual OUString SAL_CALL getName() override;
75 
76  // XClipboardEx
77  virtual sal_Int8 SAL_CALL getRenderingCapabilities() override;
78 
79  // XFlushableClipboard
80  virtual void SAL_CALL flushClipboard() override;
81 
82  // XClipboardNotifier
83  virtual void SAL_CALL addClipboardListener(
84  const css::uno::Reference<css::datatransfer::clipboard::XClipboardListener>& listener)
85  override;
86  virtual void SAL_CALL removeClipboardListener(
87  const css::uno::Reference<css::datatransfer::clipboard::XClipboardListener>& listener)
88  override;
89 };
90 
91 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL flushClipboard() override
virtual void SAL_CALL setContents(const css::uno::Reference< css::datatransfer::XTransferable > &xTrans, const css::uno::Reference< css::datatransfer::clipboard::XClipboardOwner > &xClipboardOwner) override
This implementation has two main functions, which handle the clipboard content: the XClipboard::setCo...
signed char sal_Int8
virtual sal_Int8 SAL_CALL getRenderingCapabilities() override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
osl::Mutex m_aMutex
static css::uno::Reference< css::uno::XInterface > create(const OUString &aModeString)
Qt5Clipboard(const OUString &aModeString, const QClipboard::Mode aMode)
virtual void SAL_CALL addClipboardListener(const css::uno::Reference< css::datatransfer::clipboard::XClipboardListener > &listener) override
virtual OUString SAL_CALL getImplementationName() override
void handleChanged(QClipboard::Mode mode)
css::uno::Reference< css::datatransfer::clipboard::XClipboardOwner > m_aOwner
unsigned char sal_Bool
virtual css::uno::Reference< css::datatransfer::XTransferable > SAL_CALL getContents() override
bool m_bOwnClipboardChange
virtual void SAL_CALL removeClipboardListener(const css::uno::Reference< css::datatransfer::clipboard::XClipboardListener > &listener) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
const QClipboard::Mode m_aClipboardMode
css::uno::Reference< css::datatransfer::XTransferable > m_aContents
virtual OUString SAL_CALL getName() override
static bool isOwner(const QClipboard::Mode aMode)
const OUString m_aClipboardName
static bool isSupported(const QClipboard::Mode aMode)
std::vector< css::uno::Reference< css::datatransfer::clipboard::XClipboardListener > > m_aListeners