1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /* 3 * This file is part of the LibreOffice project. 4 * 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/. 8 * 9 * This file incorporates work covered by the following license notice: 10 * 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 . 18 */ 19 20 #ifndef INCLUDED_VCL_OSX_CLIPBOARD_HXX 21 #define INCLUDED_VCL_OSX_CLIPBOARD_HXX 22 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> 38 39 #include <list> 40 41 #include <premac.h> 42 #import <Cocoa/Cocoa.h> 43 #include <postmac.h> 44 45 class AquaClipboard; 46 47 @interface EventListener : NSObject 48 { 49 AquaClipboard* pAquaClipboard; 50 } 51 52 // Init the pasteboard change listener with a reference to the OfficeClipboard 53 // instance 54 - (EventListener*)initWithAquaClipboard: (AquaClipboard*) pcb; 55 56 // Promise resolver function 57 - (void)pasteboard:(NSPasteboard*)sender provideDataForType:(const NSString *)type; 58 59 -(void)applicationDidBecomeActive:(NSNotification*)aNotification; 60 61 -(void)disposing; 62 @end 63 64 class AquaClipboard : public ::cppu::BaseMutex, 65 public ::cppu::WeakComponentImplHelper<css::datatransfer::clipboard::XSystemClipboard, 66 css::datatransfer::clipboard::XFlushableClipboard, 67 css::lang::XServiceInfo> 68 { 69 public: 70 /* Create a clipboard instance. 71 72 @param pasteboard 73 If not equal NULL the instance will be instantiated with the provided 74 pasteboard reference and 'bUseSystemClipboard' will be ignored 75 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 80 */ 81 AquaClipboard(NSPasteboard* pasteboard, 82 bool bUseSystemClipboard); 83 84 virtual ~AquaClipboard() override; 85 AquaClipboard(const AquaClipboard&) = delete; 86 AquaClipboard& operator=(const AquaClipboard&) = delete; 87 88 // XClipboard 89 90 virtual css::uno::Reference<css::datatransfer::XTransferable> SAL_CALL getContents() override; 91 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; 94 95 virtual OUString SAL_CALL getName() override; 96 97 // XClipboardEx 98 99 virtual sal_Int8 SAL_CALL getRenderingCapabilities() override; 100 101 // XClipboardNotifier 102 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; 105 106 // XFlushableClipboard 107 108 virtual void SAL_CALL flushClipboard() override; 109 110 // XServiceInfo 111 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; 115 116 /* Get a reference to the used pastboard. 117 */ 118 NSPasteboard* getPasteboard() const; 119 120 /* Notify the current clipboard owner that he is no longer the clipboard owner. 121 */ 122 void fireLostClipboardOwnershipEvent(css::uno::Reference<css::datatransfer::clipboard::XClipboardOwner> const & oldOwner, 123 css::uno::Reference<css::datatransfer::XTransferable> const & oldContent); 124 125 void pasteboardChangedOwner(); 126 127 void provideDataForType(NSPasteboard* sender, const NSString* type); 128 129 void applicationDidBecomeActive(NSNotification* aNotification); 130 131 private: 132 133 /* Notify all registered XClipboardListener that the clipboard content 134 has changed. 135 */ 136 void fireClipboardChangedEvent(); 137 138 private: 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; 148 }; 149 150 #endif // INCLUDED_VCL_OSX_CLIPBOARD_HXX 151 152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 153