Avoid potential negative array index access to cached text.
[LibreOffice.git] / vcl / inc / qt5 / QtClipboard.hxx
blobf07414bfbc702ab7b12744439259343f976adb77
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
9 */
11 #pragma once
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>
23 /**
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.
29 **/
30 class QtClipboard final
31 : public QObject,
32 public cppu::WeakComponentImplHelper<css::datatransfer::clipboard::XSystemClipboard,
33 css::datatransfer::clipboard::XFlushableClipboard,
34 css::lang::XServiceInfo>
36 Q_OBJECT
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
43 bool m_bOwnClipboardChange;
44 // true, if LO really wants to give up clipboard ownership
45 bool m_bDoClear;
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;
53 static bool isOwner(const QClipboard::Mode aMode);
54 static bool isSupported(const QClipboard::Mode aMode);
56 explicit QtClipboard(OUString aModeString, const QClipboard::Mode aMode);
58 private Q_SLOTS:
59 void handleChanged(QClipboard::Mode mode);
60 void handleClearClipboard();
62 signals:
63 void clearClipboard();
65 public:
66 // factory function to construct only valid QtClipboard objects by name
67 static css::uno::Reference<css::uno::XInterface> create(const OUString& aModeString);
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;
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;
82 // XClipboardEx
83 virtual sal_Int8 SAL_CALL getRenderingCapabilities() override;
85 // XFlushableClipboard
86 virtual void SAL_CALL flushClipboard() override;
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;
97 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */