Branch libreoffice-5-0-4
[LibreOffice.git] / vcl / osx / clipboard.hxx
blob1fd71e623bfc0e505e15c1b7b4c60b114eed8731
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/compbase3.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 <boost/utility.hpp>
40 #include <list>
42 #include <premac.h>
43 #import <Cocoa/Cocoa.h>
44 #include <postmac.h>
46 class AquaClipboard;
48 @interface EventListener : NSObject
50 AquaClipboard* pAquaClipboard;
53 // Init the pasteboard change listener with a reference to the OfficeClipboard
54 // instance
55 - (EventListener*)initWithAquaClipboard: (AquaClipboard*) pcb;
57 // Promiss resolver function
58 - (void)pasteboard:(NSPasteboard*)sender provideDataForType:(const NSString *)type;
60 -(void)applicationDidBecomeActive:(NSNotification*)aNotification;
62 -(void)disposing;
63 @end
65 class AquaClipboard : public ::cppu::BaseMutex,
66 public ::cppu::WeakComponentImplHelper3< com::sun::star::datatransfer::clipboard::XSystemClipboard,
67 com::sun::star::datatransfer::clipboard::XFlushableClipboard,
68 com::sun::star::lang::XServiceInfo >,
69 private ::boost::noncopyable
71 public:
72 /* Create a clipboard instance.
74 @param pasteboard
75 If not equal NULL the instance will be instantiated with the provided
76 pasteboard reference and 'bUseSystemClipboard' will be ignored
78 @param bUseSystemClipboard
79 If 'pasteboard' is NULL 'bUseSystemClipboard' determines whether the
80 system clipboard will be created (bUseSystemClipboard == true) or if
81 the DragPasteboard if bUseSystemClipboard == false
83 AquaClipboard(NSPasteboard* pasteboard = NULL,
84 bool bUseSystemClipboard = true);
86 virtual ~AquaClipboard();
88 // XClipboard
90 virtual ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > SAL_CALL getContents()
91 throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
93 virtual void SAL_CALL setContents( const ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable >& xTransferable,
94 const ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::clipboard::XClipboardOwner >& xClipboardOwner )
95 throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
97 virtual OUString SAL_CALL getName()
98 throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
100 // XClipboardEx
102 virtual sal_Int8 SAL_CALL getRenderingCapabilities()
103 throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
105 // XClipboardNotifier
107 virtual void SAL_CALL addClipboardListener( const ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::clipboard::XClipboardListener >& listener )
108 throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
110 virtual void SAL_CALL removeClipboardListener( const ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::clipboard::XClipboardListener >& listener )
111 throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
113 // XFlushableClipboard
115 virtual void SAL_CALL flushClipboard( ) throw( com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
117 // XServiceInfo
119 virtual OUString SAL_CALL getImplementationName()
120 throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
122 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName )
123 throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
125 virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames()
126 throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
128 /* Get a reference to the used pastboard.
130 NSPasteboard* getPasteboard() const;
132 /* Notify the current clipboard owner that he is no longer the clipboard owner.
134 void fireLostClipboardOwnershipEvent(::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::clipboard::XClipboardOwner> oldOwner,
135 ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > oldContent);
137 void pasteboardChangedOwner();
139 void provideDataForType(NSPasteboard* sender, const NSString* type);
141 void applicationDidBecomeActive(NSNotification* aNotification);
143 private:
145 /* Notify all registered XClipboardListener that the clipboard content
146 has changed.
148 void fireClipboardChangedEvent();
150 private:
151 ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XMimeContentTypeFactory > mrXMimeCntFactory;
152 ::std::list< ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::clipboard::XClipboardListener > > mClipboardListeners;
153 ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > mXClipboardContent;
154 com::sun::star::uno::Reference< com::sun::star::datatransfer::clipboard::XClipboardOwner > mXClipboardOwner;
155 DataFlavorMapperPtr_t mpDataFlavorMapper;
156 bool mIsSystemPasteboard;
157 NSPasteboard* mPasteboard;
158 int mPasteboardChangeCount;
159 EventListener* mEventListener;
162 #endif // INCLUDED_VCL_OSX_CLIPBOARD_HXX
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */