1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
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
>
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
;
36 /// get an XInterface easily.
37 css::uno::Reference
<css::uno::XInterface
> getXI()
39 return { static_cast<cppu::OWeakObject
*>(this) };
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();
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
)
54 OUString SAL_CALL
getName() override
{ return "CLIPBOARD"; }
57 sal_Int8 SAL_CALL
getRenderingCapabilities() override
{ return 0; }
60 void SAL_CALL
addClipboardListener(
61 const css::uno::Reference
<css::datatransfer::clipboard::XClipboardListener
>& listener
)
63 void SAL_CALL
removeClipboardListener(
64 const css::uno::Reference
<css::datatransfer::clipboard::XClipboardListener
>& listener
)
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
);
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
;
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: */