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/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>
43 #import <Cocoa/Cocoa.h>
48 @interface EventListener
: NSObject
50 AquaClipboard
* pAquaClipboard
;
53 // Init the pasteboard change listener with a reference to the OfficeClipboard
55 - (EventListener
*)initWithAquaClipboard
: (AquaClipboard
*) pcb
;
57 // Promiss resolver function
58 - (void)pasteboard
:(NSPasteboard
*)sender provideDataForType
:(const NSString
*)type
;
60 -(void)applicationDidBecomeActive
:(NSNotification
*)aNotification
;
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
72 /* Create a clipboard instance.
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();
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
;
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
;
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
);
145 /* Notify all registered XClipboardListener that the clipboard content
148 void fireClipboardChangedEvent();
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: */