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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #include <rtl/ustring.hxx>
23 #include <sal/types.h>
24 #include <comphelper/compbase.hxx>
25 #include <comphelper/interfacecontainer4.hxx>
26 #include <com/sun/star/datatransfer/XTransferable.hpp>
27 #include <com/sun/star/datatransfer/clipboard/XClipboardEx.hpp>
28 #include <com/sun/star/datatransfer/clipboard/XClipboardOwner.hpp>
29 #include <com/sun/star/datatransfer/clipboard/XClipboardListener.hpp>
30 #include <com/sun/star/datatransfer/clipboard/XClipboardNotifier.hpp>
31 #include <com/sun/star/datatransfer/clipboard/XSystemClipboard.hpp>
32 #include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp>
33 #include <com/sun/star/lang/XServiceInfo.hpp>
34 #include <com/sun/star/uno/XComponentContext.hpp>
35 #include <osl/conditn.hxx>
36 #include <systools/win32/comtools.hxx>
38 #include "MtaOleClipb.hxx"
39 #include "XNotifyingDataObject.hxx"
41 // implements the XClipboard[Ex] ... interfaces
42 // for the clipboard viewer mechanism we need a static callback function
43 // and a static member to reassociate from this static function to the
45 // watch out: we are using only one static member variable and not a list
46 // because we assume to be instantiated only once
47 // this will be assured by a OneInstanceFactory of the service and not
50 class CWinClipboard final
51 : public comphelper::WeakComponentImplHelper
<css::datatransfer::clipboard::XSystemClipboard
,
52 css::datatransfer::clipboard::XFlushableClipboard
,
53 css::lang::XServiceInfo
>
55 friend CXNotifyingDataObject::~CXNotifyingDataObject();
57 css::uno::Reference
<css::uno::XComponentContext
> m_xContext
;
58 const OUString m_itsName
;
59 CMtaOleClipboard m_MtaOleClipboard
;
60 CXNotifyingDataObject
* m_pNewOwnClipContent
= nullptr; // until onClipboardContentChanged
61 CXNotifyingDataObject
* m_pCurrentOwnClipContent
= nullptr;
62 css::uno::Reference
<css::datatransfer::XTransferable
> m_foreignContent
;
63 comphelper::OInterfaceContainerHelper4
<css::datatransfer::clipboard::XClipboardListener
>
66 CXNotifyingDataObject
* getOwnClipContent() const;
68 void handleClipboardContentChanged();
69 void onReleaseDataObject(CXNotifyingDataObject
& theCaller
);
71 void registerClipboardViewer();
72 void unregisterClipboardViewer();
74 static void WINAPI
onClipboardContentChanged();
76 css::uno::Reference
<css::datatransfer::XTransferable
> getContents_noLock();
79 CWinClipboard(const css::uno::Reference
<css::uno::XComponentContext
>& rxContext
,
80 const OUString
& aClipboardName
);
81 virtual ~CWinClipboard() override
;
84 virtual css::uno::Reference
<css::datatransfer::XTransferable
> SAL_CALL
getContents() override
;
85 virtual void SAL_CALL
setContents(
86 const css::uno::Reference
<css::datatransfer::XTransferable
>& xTransferable
,
87 const css::uno::Reference
<css::datatransfer::clipboard::XClipboardOwner
>& xClipboardOwner
)
89 virtual OUString SAL_CALL
getName() override
;
91 // XFlushableClipboard
92 virtual void SAL_CALL
flushClipboard() override
;
95 virtual sal_Int8 SAL_CALL
getRenderingCapabilities() override
;
98 virtual void SAL_CALL
addClipboardListener(
99 const css::uno::Reference
<css::datatransfer::clipboard::XClipboardListener
>& listener
)
101 virtual void SAL_CALL
removeClipboardListener(
102 const css::uno::Reference
<css::datatransfer::clipboard::XClipboardListener
>& listener
)
106 virtual OUString SAL_CALL
getImplementationName() override
;
107 virtual sal_Bool SAL_CALL
supportsService(const OUString
& ServiceName
) override
;
108 virtual css::uno::Sequence
<OUString
> SAL_CALL
getSupportedServiceNames() override
;
110 IDataObjectPtr
getIDataObject();
112 virtual void disposing(std::unique_lock
<std::mutex
>&) override
;
115 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */