Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / desktop / source / lib / lokclipboard.hxx
blob699830756acb6a3b83bfdca853d85241b4cb20b0
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/.
8 */
10 #pragma once
12 #include <vector>
14 #include <rtl/ref.hxx>
15 #include <cppuhelper/implbase.hxx>
16 #include <cppuhelper/compbase.hxx>
17 #include <com/sun/star/lang/XServiceInfo.hpp>
18 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
19 #include <com/sun/star/datatransfer/clipboard/XSystemClipboard.hpp>
21 using namespace css::uno;
23 /// A clipboard implementation for LibreOfficeKit.
24 class LOKClipboard final
25 : public cppu::WeakComponentImplHelper<css::datatransfer::clipboard::XSystemClipboard,
26 css::lang::XServiceInfo>
28 osl::Mutex m_aMutex;
29 css::uno::Reference<css::datatransfer::XTransferable> m_xTransferable;
30 css::uno::Reference<css::datatransfer::clipboard::XClipboardOwner> m_aOwner;
31 std::vector<css::uno::Reference<css::datatransfer::clipboard::XClipboardListener>> m_aListeners;
33 public:
34 LOKClipboard();
36 /// get an XInterface easily.
37 css::uno::Reference<css::uno::XInterface> getXI()
39 return { static_cast<cppu::OWeakObject*>(this) };
42 // XServiceInfo
43 OUString SAL_CALL getImplementationName() override;
44 sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
45 Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
46 static Sequence<OUString> getSupportedServiceNames_static();
48 // XClipboard
49 css::uno::Reference<css::datatransfer::XTransferable> SAL_CALL getContents() override;
50 void SAL_CALL setContents(
51 const css::uno::Reference<css::datatransfer::XTransferable>& xTransferable,
52 const css::uno::Reference<css::datatransfer::clipboard::XClipboardOwner>& xClipboardOwner)
53 override;
54 OUString SAL_CALL getName() override { return "CLIPBOARD"; }
56 // XClipboardEx
57 sal_Int8 SAL_CALL getRenderingCapabilities() override { return 0; }
59 // XClipboardNotifier
60 void SAL_CALL addClipboardListener(
61 const css::uno::Reference<css::datatransfer::clipboard::XClipboardListener>& listener)
62 override;
63 void SAL_CALL removeClipboardListener(
64 const css::uno::Reference<css::datatransfer::clipboard::XClipboardListener>& listener)
65 override;
68 /// Represents the contents of LOKClipboard.
69 class LOKTransferable : public cppu::WeakImplHelper<css::datatransfer::XTransferable>
71 css::uno::Sequence<css::datatransfer::DataFlavor> m_aFlavors;
72 std::vector<css::uno::Any> m_aContent;
74 static void initFlavourFromMime(css::datatransfer::DataFlavor& rFlavor, OUString aMimeType);
76 public:
77 LOKTransferable();
78 LOKTransferable(size_t nInCount, const char** pInMimeTypes, const size_t* pInSizes,
79 const char** pInStreams);
80 LOKTransferable(const OUString& sMimeType, const css::uno::Sequence<sal_Int8>& aSequence);
82 css::uno::Any SAL_CALL getTransferData(const css::datatransfer::DataFlavor& rFlavor) override;
84 css::uno::Sequence<css::datatransfer::DataFlavor> SAL_CALL getTransferDataFlavors() override;
86 sal_Bool SAL_CALL isDataFlavorSupported(const css::datatransfer::DataFlavor& rFlavor) override;
89 /// Theoretically to hook into the (horrible) vcl dtranscomp.cxx code.
90 class LOKClipboardFactory : public ::cppu::WeakComponentImplHelper<css::lang::XSingleServiceFactory>
92 static osl::Mutex gMutex;
94 public:
95 LOKClipboardFactory()
96 : cppu::WeakComponentImplHelper<css::lang::XSingleServiceFactory>(gMutex)
100 css::uno::Reference<css::uno::XInterface> SAL_CALL createInstance() override
102 return createInstanceWithArguments(css::uno::Sequence<css::uno::Any>());
104 css::uno::Reference<css::uno::XInterface> SAL_CALL
105 createInstanceWithArguments(const css::uno::Sequence<css::uno::Any>& /* rArgs */) override;
107 /// Fetch clipboard from the global pool.
108 static rtl::Reference<LOKClipboard> getClipboardForCurView();
110 /// Release a clipboard before its document dies, nViewId of -1 clears all.
111 static void releaseClipboardForView(int nViewId);
114 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */