Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / vcl / osx / clipboard.hxx
blob638eb4e7875b5926ce364a2a10aefd80c2421102
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
39 #include <list>
41 #include <premac.h>
42 #import <Cocoa/Cocoa.h>
43 #include <postmac.h>
45 class AquaClipboard;
47 @interface EventListener : NSObject
49 AquaClipboard* pAquaClipboard;
52 // Init the pasteboard change listener with a reference to the OfficeClipboard
53 // instance
54 - (EventListener*)initWithAquaClipboard: (AquaClipboard*) pcb;
56 // Promise resolver function
57 - (void)pasteboard:(NSPasteboard*)sender provideDataForType:(const NSString *)type;
59 -(void)applicationDidBecomeActive:(NSNotification*)aNotification;
61 -(void)disposing;
62 @end
64 class AquaClipboard : public ::cppu::BaseMutex,
65 public ::cppu::WeakComponentImplHelper< css::datatransfer::clipboard::XSystemClipboard,
66 css::datatransfer::clipboard::XFlushableClipboard,
67 css::lang::XServiceInfo >
69 public:
70 /* Create a clipboard instance.
72 @param pasteboard
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 = nullptr,
82 bool bUseSystemClipboard = true);
84 virtual ~AquaClipboard() override;
85 AquaClipboard(const AquaClipboard&) = delete;
86 AquaClipboard& operator=(const AquaClipboard&) = delete;
88 // XClipboard
90 virtual css::uno::Reference< css::datatransfer::XTransferable > SAL_CALL getContents() override;
92 virtual void SAL_CALL setContents( const css::uno::Reference< css::datatransfer::XTransferable >& xTransferable,
93 const css::uno::Reference< css::datatransfer::clipboard::XClipboardOwner >& xClipboardOwner ) override;
95 virtual OUString SAL_CALL getName() override;
97 // XClipboardEx
99 virtual sal_Int8 SAL_CALL getRenderingCapabilities() override;
101 // XClipboardNotifier
103 virtual void SAL_CALL addClipboardListener( const css::uno::Reference< css::datatransfer::clipboard::XClipboardListener >& listener ) override;
105 virtual void SAL_CALL removeClipboardListener( const css::uno::Reference< css::datatransfer::clipboard::XClipboardListener >& listener ) override;
107 // XFlushableClipboard
109 virtual void SAL_CALL flushClipboard( ) override;
111 // XServiceInfo
113 virtual OUString SAL_CALL getImplementationName() override;
115 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
117 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
119 /* Get a reference to the used pastboard.
121 NSPasteboard* getPasteboard() const;
123 /* Notify the current clipboard owner that he is no longer the clipboard owner.
125 void fireLostClipboardOwnershipEvent(css::uno::Reference< css::datatransfer::clipboard::XClipboardOwner> const & oldOwner,
126 css::uno::Reference< css::datatransfer::XTransferable > const & oldContent);
128 void pasteboardChangedOwner();
130 void provideDataForType(NSPasteboard* sender, const NSString* type);
132 void applicationDidBecomeActive(NSNotification* aNotification);
134 private:
136 /* Notify all registered XClipboardListener that the clipboard content
137 has changed.
139 void fireClipboardChangedEvent();
141 private:
142 css::uno::Reference< css::datatransfer::XMimeContentTypeFactory > mrXMimeCntFactory;
143 ::std::list< css::uno::Reference< css::datatransfer::clipboard::XClipboardListener > > mClipboardListeners;
144 css::uno::Reference< css::datatransfer::XTransferable > mXClipboardContent;
145 css::uno::Reference< css::datatransfer::clipboard::XClipboardOwner > mXClipboardOwner;
146 DataFlavorMapperPtr_t mpDataFlavorMapper;
147 bool mIsSystemPasteboard;
148 NSPasteboard* mPasteboard;
149 int mPasteboardChangeCount;
150 EventListener* mEventListener;
153 #endif // INCLUDED_VCL_OSX_CLIPBOARD_HXX
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */