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 "DataFlavorMapping.hxx"
23 #include <rtl/ustring.hxx>
24 #include <sal/types.h>
25 #include <cppuhelper/compbase.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/XMimeContentTypeFactory.hpp>
33 #include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp>
34 #include <com/sun/star/lang/XServiceInfo.hpp>
35 #include <cppuhelper/basemutex.hxx>
36 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
41 #import <Cocoa/Cocoa.h>
46 @interface EventListener
: NSObject
48 AquaClipboard
* pAquaClipboard
;
51 // Init the pasteboard change listener with a reference to the OfficeClipboard
53 - (EventListener
*)initWithAquaClipboard
: (AquaClipboard
*) pcb
;
55 // Promise resolver function
56 - (void)pasteboard
:(NSPasteboard
*)sender provideDataForType
:(const NSString
*)type
;
58 -(void)applicationDidBecomeActive
:(NSNotification
*)aNotification
;
63 class AquaClipboard
: public ::cppu::BaseMutex
,
64 public ::cppu::WeakComponentImplHelper
<css::datatransfer::clipboard::XSystemClipboard
,
65 css::datatransfer::clipboard::XFlushableClipboard
,
66 css::lang::XServiceInfo
>
69 /* Create a clipboard instance.
72 If not equal NULL the instance will be instantiated with the provided
73 pasteboard reference and 'bUseSystemClipboard' will be ignored
75 @param bUseSystemClipboard
76 If 'pasteboard' is NULL 'bUseSystemClipboard' determines whether the
77 system clipboard will be created (bUseSystemClipboard == true) or if
78 the DragPasteboard if bUseSystemClipboard == false
80 AquaClipboard(NSPasteboard
* pasteboard
,
81 bool bUseSystemClipboard
);
83 virtual ~AquaClipboard() override
;
84 AquaClipboard(const AquaClipboard
&) = delete;
85 AquaClipboard
& operator=(const AquaClipboard
&) = delete;
89 virtual css::uno::Reference
<css::datatransfer::XTransferable
> SAL_CALL
getContents() override
;
91 virtual void SAL_CALL
setContents(css::uno::Reference
<css::datatransfer::XTransferable
> const & xTransferable
,
92 css::uno::Reference
<css::datatransfer::clipboard::XClipboardOwner
> const & xClipboardOwner
) override
;
94 virtual OUString SAL_CALL
getName() override
;
98 virtual sal_Int8 SAL_CALL
getRenderingCapabilities() override
;
100 // XClipboardNotifier
102 virtual void SAL_CALL
addClipboardListener(css::uno::Reference
<css::datatransfer::clipboard::XClipboardListener
> const & listener
) override
;
103 virtual void SAL_CALL
removeClipboardListener(css::uno::Reference
<css::datatransfer::clipboard::XClipboardListener
> const & listener
) override
;
105 // XFlushableClipboard
107 virtual void SAL_CALL
flushClipboard() override
;
111 virtual OUString SAL_CALL
getImplementationName() override
;
112 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
113 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
115 /* Get a reference to the used pastboard.
117 NSPasteboard
* getPasteboard() const;
119 /* Notify the current clipboard owner that he is no longer the clipboard owner.
121 void fireLostClipboardOwnershipEvent(css::uno::Reference
<css::datatransfer::clipboard::XClipboardOwner
> const & oldOwner
,
122 css::uno::Reference
<css::datatransfer::XTransferable
> const & oldContent
);
124 void pasteboardChangedOwner();
126 void provideDataForType(NSPasteboard
* sender
, const NSString
* type
);
128 void applicationDidBecomeActive(NSNotification
* aNotification
);
132 /* Notify all registered XClipboardListener that the clipboard content
135 void fireClipboardChangedEvent();
138 css::uno::Reference
<css::datatransfer::XMimeContentTypeFactory
> mrXMimeCntFactory
;
139 std::list
<css::uno::Reference
<css::datatransfer::clipboard::XClipboardListener
>> mClipboardListeners
;
140 css::uno::Reference
<css::datatransfer::XTransferable
> mXClipboardContent
;
141 css::uno::Reference
<css::datatransfer::clipboard::XClipboardOwner
> mXClipboardOwner
;
142 DataFlavorMapperPtr_t mpDataFlavorMapper
;
143 bool mIsSystemPasteboard
;
144 NSPasteboard
* mPasteboard
;
145 int mPasteboardChangeCount
;
146 EventListener
* mEventListener
;
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */