/src/libreoffice/desktop/source/lib/lokclipboard.hxx
Line | Count | Source |
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 | | #pragma once |
11 | | |
12 | | #include <vector> |
13 | | |
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> |
20 | | |
21 | | using namespace css::uno; |
22 | | |
23 | | /// A clipboard implementation for LibreOfficeKit. |
24 | | class LOKClipboard final |
25 | | : public cppu::WeakComponentImplHelper<css::datatransfer::clipboard::XSystemClipboard, |
26 | | css::lang::XServiceInfo> |
27 | | { |
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; |
32 | | |
33 | | public: |
34 | | LOKClipboard(); |
35 | | |
36 | | /// get an XInterface easily. |
37 | | css::uno::Reference<css::uno::XInterface> getXI() |
38 | 0 | { |
39 | 0 | return { static_cast<cppu::OWeakObject*>(this) }; |
40 | 0 | } |
41 | | |
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(); |
47 | | |
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 | 0 | OUString SAL_CALL getName() override { return u"CLIPBOARD"_ustr; } |
55 | | |
56 | | // XClipboardEx |
57 | 0 | sal_Int8 SAL_CALL getRenderingCapabilities() override { return 0; } |
58 | | |
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; |
66 | | }; |
67 | | |
68 | | /// Represents the contents of LOKClipboard. |
69 | | class LOKTransferable : public cppu::WeakImplHelper<css::datatransfer::XTransferable> |
70 | | { |
71 | | css::uno::Sequence<css::datatransfer::DataFlavor> m_aFlavors; |
72 | | std::vector<css::uno::Any> m_aContent; |
73 | | |
74 | | static void initFlavourFromMime(css::datatransfer::DataFlavor& rFlavor, OUString aMimeType); |
75 | | |
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); |
81 | | |
82 | | css::uno::Any SAL_CALL getTransferData(const css::datatransfer::DataFlavor& rFlavor) override; |
83 | | |
84 | | css::uno::Sequence<css::datatransfer::DataFlavor> SAL_CALL getTransferDataFlavors() override; |
85 | | |
86 | | sal_Bool SAL_CALL isDataFlavorSupported(const css::datatransfer::DataFlavor& rFlavor) override; |
87 | | }; |
88 | | |
89 | | /// Theoretically to hook into the (horrible) vcl dtranscomp.cxx code. |
90 | | class LOKClipboardFactory : public ::cppu::WeakComponentImplHelper<css::lang::XSingleServiceFactory> |
91 | | { |
92 | | static osl::Mutex gMutex; |
93 | | |
94 | | public: |
95 | | LOKClipboardFactory() |
96 | | : cppu::WeakComponentImplHelper<css::lang::XSingleServiceFactory>(gMutex) |
97 | 0 | { |
98 | 0 | } |
99 | | |
100 | | css::uno::Reference<css::uno::XInterface> SAL_CALL createInstance() override |
101 | 0 | { |
102 | 0 | return createInstanceWithArguments(css::uno::Sequence<css::uno::Any>()); |
103 | 0 | } |
104 | | css::uno::Reference<css::uno::XInterface> SAL_CALL |
105 | | createInstanceWithArguments(const css::uno::Sequence<css::uno::Any>& /* rArgs */) override; |
106 | | |
107 | | /// Fetch clipboard from the global pool. |
108 | | static rtl::Reference<LOKClipboard> getClipboardForCurView(); |
109 | | |
110 | | /// Release a clipboard before its document dies, nViewId of -1 clears all. |
111 | | static void releaseClipboardForView(int nViewId); |
112 | | }; |
113 | | |
114 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |