LibreOffice Module desktop (master) 1
lokclipboard.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#pragma once
11
12#include <vector>
13
14#include <rtl/ref.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
21using namespace css::uno;
22
24class 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
33public:
35
37 css::uno::Reference<css::uno::XInterface> getXI()
38 {
39 return { static_cast<cppu::OWeakObject*>(this) };
40 }
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 OUString SAL_CALL getName() override { return "CLIPBOARD"; }
55
56 // XClipboardEx
57 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
69class 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
76public:
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
90class LOKClipboardFactory : public ::cppu::WeakComponentImplHelper<css::lang::XSingleServiceFactory>
91{
92 static osl::Mutex gMutex;
93
94public:
96 : cppu::WeakComponentImplHelper<css::lang::XSingleServiceFactory>(gMutex)
97 {
98 }
99
100 css::uno::Reference<css::uno::XInterface> SAL_CALL createInstance() override
101 {
102 return createInstanceWithArguments(css::uno::Sequence<css::uno::Any>());
103 }
104 css::uno::Reference<css::uno::XInterface> SAL_CALL
105 createInstanceWithArguments(const css::uno::Sequence<css::uno::Any>& /* rArgs */) override;
106
109
111 static void releaseClipboardForView(int nViewId);
112};
113
114/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Theoretically to hook into the (horrible) vcl dtranscomp.cxx code.
static rtl::Reference< LOKClipboard > getClipboardForCurView()
Fetch clipboard from the global pool.
static void releaseClipboardForView(int nViewId)
Release a clipboard before its document dies, nViewId of -1 clears all.
static osl::Mutex gMutex
css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceWithArguments(const css::uno::Sequence< css::uno::Any > &) override
css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance() override
A clipboard implementation for LibreOfficeKit.
OUString SAL_CALL getImplementationName() override
static Sequence< OUString > getSupportedServiceNames_static()
css::uno::Reference< css::uno::XInterface > getXI()
get an XInterface easily.
osl::Mutex m_aMutex
void SAL_CALL setContents(const css::uno::Reference< css::datatransfer::XTransferable > &xTransferable, const css::uno::Reference< css::datatransfer::clipboard::XClipboardOwner > &xClipboardOwner) override
std::vector< css::uno::Reference< css::datatransfer::clipboard::XClipboardListener > > m_aListeners
OUString SAL_CALL getName() override
sal_Int8 SAL_CALL getRenderingCapabilities() override
void SAL_CALL addClipboardListener(const css::uno::Reference< css::datatransfer::clipboard::XClipboardListener > &listener) override
void SAL_CALL removeClipboardListener(const css::uno::Reference< css::datatransfer::clipboard::XClipboardListener > &listener) override
css::uno::Reference< css::datatransfer::clipboard::XClipboardOwner > m_aOwner
css::uno::Reference< css::datatransfer::XTransferable > SAL_CALL getContents() override
Sequence< OUString > SAL_CALL getSupportedServiceNames() override
sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
css::uno::Reference< css::datatransfer::XTransferable > m_xTransferable
Represents the contents of LOKClipboard.
LOKTransferable()
Use to ensure we have some dummy content on the clipboard to allow a 1st 'paste'.
css::uno::Sequence< css::datatransfer::DataFlavor > SAL_CALL getTransferDataFlavors() override
sal_Bool SAL_CALL isDataFlavorSupported(const css::datatransfer::DataFlavor &rFlavor) override
static void initFlavourFromMime(css::datatransfer::DataFlavor &rFlavor, OUString aMimeType)
css::uno::Any SAL_CALL getTransferData(const css::datatransfer::DataFlavor &rFlavor) override
css::uno::Sequence< css::datatransfer::DataFlavor > m_aFlavors
std::vector< css::uno::Any > m_aContent
unsigned char sal_Bool
signed char sal_Int8