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>
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 
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 
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 
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:
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 
90 class LOKClipboardFactory : public ::cppu::WeakComponentImplHelper<css::lang::XSingleServiceFactory>
91 {
92  static osl::Mutex gMutex;
93 
94 public:
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 
108  static rtl::Reference<LOKClipboard> getClipboardForCurView();
109 
111  static void releaseClipboardForView(int nViewId);
112 };
113 
114 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::datatransfer::clipboard::XClipboardOwner > m_aOwner
css::uno::Reference< css::uno::XInterface > getXI()
get an XInterface easily.
signed char sal_Int8
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
osl::Mutex m_aMutex
css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance() override
unsigned char sal_Bool
OUString SAL_CALL getName() override
css::uno::Sequence< css::datatransfer::DataFlavor > m_aFlavors
std::vector< css::uno::Reference< css::datatransfer::clipboard::XClipboardListener > > m_aListeners
Theoretically to hook into the (horrible) vcl dtranscomp.cxx code.
A clipboard implementation for LibreOfficeKit.
css::uno::Reference< css::datatransfer::XTransferable > m_xTransferable
std::vector< css::uno::Any > m_aContent
sal_Int8 SAL_CALL getRenderingCapabilities() override
static osl::Mutex gMutex
Represents the contents of LOKClipboard.