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 <cppuhelper/compbase.hxx>
25 #include <com/sun/star/datatransfer/XTransferable.hpp>
26 #include <com/sun/star/datatransfer/clipboard/XClipboardEx.hpp>
27 #include <com/sun/star/datatransfer/clipboard/XClipboardOwner.hpp>
28 #include <com/sun/star/datatransfer/clipboard/XClipboardListener.hpp>
29 #include <com/sun/star/datatransfer/clipboard/XClipboardNotifier.hpp>
30 #include <com/sun/star/datatransfer/clipboard/XSystemClipboard.hpp>
31 #include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp>
32 #include <com/sun/star/lang/XServiceInfo.hpp>
33 #include <com/sun/star/uno/XComponentContext.hpp>
34 #include <osl/conditn.hxx>
35 #include <systools/win32/comtools.hxx>
37 #include "MtaOleClipb.hxx"
38 #include "XNotifyingDataObject.hxx"
40 // implements the XClipboard[Ex] ... interfaces
41 // for the clipboard viewer mechanism we need a static callback function
42 // and a static member to reassociate from this static function to the
44 // watch out: we are using only one static member variable and not a list
45 // because we assume to be instantiated only once
46 // this will be assured by a OneInstanceFactory of the service and not
49 // helper class, so that the mutex is constructed
50 // before the constructor of WeakComponentImplHelper
51 // will be called and initialized with this mutex
52 class CWinClipboardDummy
56 osl::Mutex m_aCbListenerMutex
;
59 class CWinClipboard final
60 : public CWinClipboardDummy
,
61 public cppu::WeakComponentImplHelper
<css::datatransfer::clipboard::XSystemClipboard
,
62 css::datatransfer::clipboard::XFlushableClipboard
,
63 css::lang::XServiceInfo
>
65 friend STDMETHODIMP_(ULONG
) CXNotifyingDataObject::Release();
67 css::uno::Reference
<css::uno::XComponentContext
> m_xContext
;
68 const OUString m_itsName
;
69 CMtaOleClipboard m_MtaOleClipboard
;
70 CXNotifyingDataObject
* m_pCurrentClipContent
;
71 com::sun::star::uno::Reference
<com::sun::star::datatransfer::XTransferable
> m_foreignContent
;
72 osl::Mutex m_ClipContentMutex
;
74 static osl::Mutex s_aMutex
;
75 static CWinClipboard
* s_pCWinClipbImpl
;
77 void notifyAllClipboardListener();
78 void onReleaseDataObject(CXNotifyingDataObject
* theCaller
);
80 void registerClipboardViewer();
81 void unregisterClipboardViewer();
83 static void WINAPI
onClipboardContentChanged();
86 CWinClipboard(const css::uno::Reference
<css::uno::XComponentContext
>& rxContext
,
87 const OUString
& aClipboardName
);
88 virtual ~CWinClipboard() override
;
91 virtual css::uno::Reference
<css::datatransfer::XTransferable
> SAL_CALL
getContents() override
;
92 virtual void SAL_CALL
setContents(
93 const css::uno::Reference
<css::datatransfer::XTransferable
>& xTransferable
,
94 const css::uno::Reference
<css::datatransfer::clipboard::XClipboardOwner
>& xClipboardOwner
)
96 virtual OUString SAL_CALL
getName() override
;
98 // XFlushableClipboard
99 virtual void SAL_CALL
flushClipboard() override
;
102 virtual sal_Int8 SAL_CALL
getRenderingCapabilities() override
;
104 // XClipboardNotifier
105 virtual void SAL_CALL
addClipboardListener(
106 const css::uno::Reference
<css::datatransfer::clipboard::XClipboardListener
>& listener
)
108 virtual void SAL_CALL
removeClipboardListener(
109 const css::uno::Reference
<css::datatransfer::clipboard::XClipboardListener
>& listener
)
113 virtual OUString SAL_CALL
getImplementationName() override
;
114 virtual sal_Bool SAL_CALL
supportsService(const OUString
& ServiceName
) override
;
115 virtual css::uno::Sequence
<OUString
> SAL_CALL
getSupportedServiceNames() override
;
117 IDataObjectPtr
getIDataObject();
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */