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 .
20 #ifndef INCLUDED_VCL_OSX_CLIPBOARD_HXX
21 #define INCLUDED_VCL_OSX_CLIPBOARD_HXX
23 #include "DataFlavorMapping.hxx"
24 #include <rtl/ustring.hxx>
25 #include <sal/types.h>
26 #include <cppuhelper/compbase.hxx>
27 #include <com/sun/star/datatransfer/XTransferable.hpp>
28 #include <com/sun/star/datatransfer/clipboard/XClipboardEx.hpp>
29 #include <com/sun/star/datatransfer/clipboard/XClipboardOwner.hpp>
30 #include <com/sun/star/datatransfer/clipboard/XClipboardListener.hpp>
31 #include <com/sun/star/datatransfer/clipboard/XClipboardNotifier.hpp>
32 #include <com/sun/star/datatransfer/clipboard/XSystemClipboard.hpp>
33 #include <com/sun/star/datatransfer/XMimeContentTypeFactory.hpp>
34 #include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp>
35 #include <com/sun/star/lang/XServiceInfo.hpp>
36 #include <cppuhelper/basemutex.hxx>
37 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
42 #import <Cocoa/Cocoa.h>
47 @interface EventListener
: NSObject
49 AquaClipboard
* pAquaClipboard
;
52 // Init the pasteboard change listener with a reference to the OfficeClipboard
54 - (EventListener
*)initWithAquaClipboard
: (AquaClipboard
*) pcb
;
56 // Promise resolver function
57 - (void)pasteboard
:(NSPasteboard
*)sender provideDataForType
:(const NSString
*)type
;
59 -(void)applicationDidBecomeActive
:(NSNotification
*)aNotification
;
64 class AquaClipboard
: public ::cppu::BaseMutex
,
65 public ::cppu::WeakComponentImplHelper
<css::datatransfer::clipboard::XSystemClipboard
,
66 css::datatransfer::clipboard::XFlushableClipboard
,
67 css::lang::XServiceInfo
>
70 /* Create a clipboard instance.
73 If not equal NULL the instance will be instantiated with the provided
74 pasteboard reference and 'bUseSystemClipboard' will be ignored
76 @param bUseSystemClipboard
77 If 'pasteboard' is NULL 'bUseSystemClipboard' determines whether the
78 system clipboard will be created (bUseSystemClipboard == true) or if
79 the DragPasteboard if bUseSystemClipboard == false
81 AquaClipboard(NSPasteboard
* pasteboard
,
82 bool bUseSystemClipboard
);
84 virtual ~AquaClipboard() override
;
85 AquaClipboard(const AquaClipboard
&) = delete;
86 AquaClipboard
& operator=(const AquaClipboard
&) = delete;
90 virtual css::uno::Reference
<css::datatransfer::XTransferable
> SAL_CALL
getContents() override
;
92 virtual void SAL_CALL
setContents(css::uno::Reference
<css::datatransfer::XTransferable
> const & xTransferable
,
93 css::uno::Reference
<css::datatransfer::clipboard::XClipboardOwner
> const & xClipboardOwner
) override
;
95 virtual OUString SAL_CALL
getName() override
;
99 virtual sal_Int8 SAL_CALL
getRenderingCapabilities() override
;
101 // XClipboardNotifier
103 virtual void SAL_CALL
addClipboardListener(css::uno::Reference
<css::datatransfer::clipboard::XClipboardListener
> const & listener
) override
;
104 virtual void SAL_CALL
removeClipboardListener(css::uno::Reference
<css::datatransfer::clipboard::XClipboardListener
> const & listener
) override
;
106 // XFlushableClipboard
108 virtual void SAL_CALL
flushClipboard() override
;
112 virtual OUString SAL_CALL
getImplementationName() override
;
113 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
114 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
116 /* Get a reference to the used pastboard.
118 NSPasteboard
* getPasteboard() const;
120 /* Notify the current clipboard owner that he is no longer the clipboard owner.
122 void fireLostClipboardOwnershipEvent(css::uno::Reference
<css::datatransfer::clipboard::XClipboardOwner
> const & oldOwner
,
123 css::uno::Reference
<css::datatransfer::XTransferable
> const & oldContent
);
125 void pasteboardChangedOwner();
127 void provideDataForType(NSPasteboard
* sender
, const NSString
* type
);
129 void applicationDidBecomeActive(NSNotification
* aNotification
);
133 /* Notify all registered XClipboardListener that the clipboard content
136 void fireClipboardChangedEvent();
139 css::uno::Reference
<css::datatransfer::XMimeContentTypeFactory
> mrXMimeCntFactory
;
140 std::list
<css::uno::Reference
<css::datatransfer::clipboard::XClipboardListener
>> mClipboardListeners
;
141 css::uno::Reference
<css::datatransfer::XTransferable
> mXClipboardContent
;
142 css::uno::Reference
<css::datatransfer::clipboard::XClipboardOwner
> mXClipboardOwner
;
143 DataFlavorMapperPtr_t mpDataFlavorMapper
;
144 bool mIsSystemPasteboard
;
145 NSPasteboard
* mPasteboard
;
146 int mPasteboardChangeCount
;
147 EventListener
* mEventListener
;
150 #endif // INCLUDED_VCL_OSX_CLIPBOARD_HXX
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */