lok: vcl: fix multiple floatwin removal case more robustly.
[LibreOffice.git] / desktop / source / lib / lokclipboard.hxx
blob7da5f3ef390032455a6f6f5062854a713c5f292b
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 #ifndef INCLUDED_DESKTOP_SOURCE_LIB_LOKCLIPBOARD_HXX
11 #define INCLUDED_DESKTOP_SOURCE_LIB_LOKCLIPBOARD_HXX
13 #include <vector>
14 #include <unordered_map>
16 #include <rtl/ref.hxx>
17 #include <cppuhelper/implbase.hxx>
18 #include <cppuhelper/compbase.hxx>
19 #include <comphelper/sequence.hxx>
20 #include <com/sun/star/lang/XServiceInfo.hpp>
21 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
22 #include <com/sun/star/datatransfer/clipboard/XSystemClipboard.hpp>
24 using namespace css::uno;
26 /// A clipboard implementation for LibreOfficeKit.
27 class LOKClipboard
28 : public cppu::WeakComponentImplHelper<css::datatransfer::clipboard::XSystemClipboard,
29 css::lang::XServiceInfo>
31 osl::Mutex m_aMutex;
32 css::uno::Reference<css::datatransfer::XTransferable> m_xTransferable;
33 css::uno::Reference<css::datatransfer::clipboard::XClipboardOwner> m_aOwner;
34 std::vector<css::uno::Reference<css::datatransfer::clipboard::XClipboardListener>> m_aListeners;
36 public:
37 LOKClipboard();
39 /// get an XInterface easily.
40 css::uno::Reference<css::uno::XInterface> getXI()
42 return css::uno::Reference<css::uno::XInterface>(static_cast<cppu::OWeakObject*>(this));
45 // XServiceInfo
46 virtual OUString SAL_CALL getImplementationName() override;
47 virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
48 virtual Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
49 static Sequence<OUString> getSupportedServiceNames_static();
51 // XClipboard
52 css::uno::Reference<css::datatransfer::XTransferable> SAL_CALL getContents() override;
53 void SAL_CALL setContents(
54 const css::uno::Reference<css::datatransfer::XTransferable>& xTransferable,
55 const css::uno::Reference<css::datatransfer::clipboard::XClipboardOwner>& xClipboardOwner)
56 override;
57 OUString SAL_CALL getName() override { return "CLIPBOARD"; }
59 // XClipboardEx
60 sal_Int8 SAL_CALL getRenderingCapabilities() override { return 0; }
62 // XClipboardNotifier
63 void SAL_CALL addClipboardListener(
64 const css::uno::Reference<css::datatransfer::clipboard::XClipboardListener>& listener)
65 override;
66 void SAL_CALL removeClipboardListener(
67 const css::uno::Reference<css::datatransfer::clipboard::XClipboardListener>& listener)
68 override;
71 /// Represents the contents of LOKClipboard.
72 class LOKTransferable : public cppu::WeakImplHelper<css::datatransfer::XTransferable>
74 css::uno::Sequence<css::datatransfer::DataFlavor> m_aFlavors;
75 std::vector<css::uno::Any> m_aContent;
77 static void initFlavourFromMime(css::datatransfer::DataFlavor& rFlavor, OUString sMimeType);
79 public:
80 LOKTransferable();
81 LOKTransferable(const size_t nInCount, const char** pInMimeTypes, const size_t* pInSizes,
82 const char** pInStreams);
83 LOKTransferable(const OUString& sMimeType, const css::uno::Sequence<sal_Int8>& aSequence);
85 css::uno::Any SAL_CALL getTransferData(const css::datatransfer::DataFlavor& rFlavor) override;
87 css::uno::Sequence<css::datatransfer::DataFlavor> SAL_CALL getTransferDataFlavors() override;
89 sal_Bool SAL_CALL isDataFlavorSupported(const css::datatransfer::DataFlavor& rFlavor) override;
92 /// Theoretically to hook into the (horrible) vcl dtranscomp.cxx code.
93 class LOKClipboardFactory : public ::cppu::WeakComponentImplHelper<css::lang::XSingleServiceFactory>
95 static osl::Mutex gMutex;
97 public:
98 LOKClipboardFactory()
99 : cppu::WeakComponentImplHelper<css::lang::XSingleServiceFactory>(gMutex)
103 css::uno::Reference<css::uno::XInterface> SAL_CALL createInstance() override
105 return createInstanceWithArguments(css::uno::Sequence<css::uno::Any>());
107 css::uno::Reference<css::uno::XInterface> SAL_CALL
108 createInstanceWithArguments(const css::uno::Sequence<css::uno::Any>& /* rArgs */) override;
110 /// Fetch clipboard from the gobal pool.
111 static rtl::Reference<LOKClipboard> getClipboardForCurView();
113 /// Release a clipboard before its document dies, nViewId of -1 clears all.
114 static void releaseClipboardForView(int nViewId);
117 #endif
119 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */