1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: aqua_clipboard.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _AQUA_CLIPBOARD_HXX_
32 #define _AQUA_CLIPBOARD_HXX_
34 #include "DataFlavorMapping.hxx"
35 #include <rtl/ustring.hxx>
36 #include <sal/types.h>
37 #include <cppuhelper/compbase4.hxx>
38 #include <com/sun/star/datatransfer/XTransferable.hpp>
39 #include <com/sun/star/datatransfer/clipboard/XClipboardEx.hpp>
40 #include <com/sun/star/datatransfer/clipboard/XClipboardOwner.hpp>
41 #include <com/sun/star/datatransfer/clipboard/XClipboardListener.hpp>
42 #include <com/sun/star/datatransfer/clipboard/XClipboardNotifier.hpp>
43 #include <com/sun/star/datatransfer/XMimeContentTypeFactory.hpp>
44 #include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp>
45 #include <com/sun/star/lang/XServiceInfo.hpp>
46 #include <cppuhelper/basemutex.hxx>
47 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
49 #include <boost/utility.hpp>
53 #import <Cocoa/Cocoa.h>
58 @interface EventListener
: NSObject
60 AquaClipboard
* pAquaClipboard
;
63 // Init the pasteboard change listener with a reference to the OfficeClipboard
65 - (EventListener
*)initWithAquaClipboard
: (AquaClipboard
*) pcb
;
67 // Promiss resolver function
68 - (void)pasteboard
:(NSPasteboard
*)sender provideDataForType
:(NSString
*)type
;
70 -(void)applicationDidBecomeActive
:(NSNotification
*)aNotification
;
76 class AquaClipboard
: public ::cppu::BaseMutex
,
77 public ::cppu::WeakComponentImplHelper4
< com::sun::star::datatransfer::clipboard::XClipboardEx
,
78 com::sun::star::datatransfer::clipboard::XClipboardNotifier
,
79 com::sun::star::datatransfer::clipboard::XFlushableClipboard
,
80 com::sun::star::lang::XServiceInfo
>,
81 private ::boost::noncopyable
84 /* Create a clipboard instance.
87 If not equal NULL the instance will be instantiated with the provided
88 pasteboard reference and 'bUseSystemClipboard' will be ignored
90 @param bUseSystemClipboard
91 If 'pasteboard' is NULL 'bUseSystemClipboard' determines whether the
92 system clipboard will be created (bUseSystemClipboard == true) or if
93 the DragPasteboard if bUseSystemClipboard == false
95 AquaClipboard(const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& context
,
96 NSPasteboard
* pasteboard
= NULL
,
97 bool bUseSystemClipboard
= true);
101 //------------------------------------------------
103 //------------------------------------------------
105 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::datatransfer::XTransferable
> SAL_CALL
getContents()
106 throw( ::com::sun::star::uno::RuntimeException
);
108 virtual void SAL_CALL
setContents( const ::com::sun::star::uno::Reference
< ::com::sun::star::datatransfer::XTransferable
>& xTransferable
,
109 const ::com::sun::star::uno::Reference
< ::com::sun::star::datatransfer::clipboard::XClipboardOwner
>& xClipboardOwner
)
110 throw( ::com::sun::star::uno::RuntimeException
);
112 virtual ::rtl::OUString SAL_CALL
getName()
113 throw( ::com::sun::star::uno::RuntimeException
);
115 //------------------------------------------------
117 //------------------------------------------------
119 virtual sal_Int8 SAL_CALL
getRenderingCapabilities()
120 throw( ::com::sun::star::uno::RuntimeException
);
122 //------------------------------------------------
123 // XClipboardNotifier
124 //------------------------------------------------
126 virtual void SAL_CALL
addClipboardListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::datatransfer::clipboard::XClipboardListener
>& listener
)
127 throw( ::com::sun::star::uno::RuntimeException
);
129 virtual void SAL_CALL
removeClipboardListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::datatransfer::clipboard::XClipboardListener
>& listener
)
130 throw( ::com::sun::star::uno::RuntimeException
);
132 //------------------------------------------------
133 // XFlushableClipboard
134 //------------------------------------------------
136 virtual void SAL_CALL
flushClipboard( ) throw( com::sun::star::uno::RuntimeException
);
138 //------------------------------------------------
140 //------------------------------------------------
142 virtual ::rtl::OUString SAL_CALL
getImplementationName()
143 throw(::com::sun::star::uno::RuntimeException
);
145 virtual sal_Bool SAL_CALL
supportsService( const ::rtl::OUString
& ServiceName
)
146 throw(::com::sun::star::uno::RuntimeException
);
148 virtual ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
getSupportedServiceNames()
149 throw(::com::sun::star::uno::RuntimeException
);
151 /* Get a reference to the used pastboard.
153 NSPasteboard
* getPasteboard() const;
155 /* Notify the current clipboard owner that he is no longer the clipboard owner.
157 void fireLostClipboardOwnershipEvent(::com::sun::star::uno::Reference
< ::com::sun::star::datatransfer::clipboard::XClipboardOwner
> oldOwner
,
158 ::com::sun::star::uno::Reference
< ::com::sun::star::datatransfer::XTransferable
> oldContent
);
160 void pasteboardChangedOwner();
162 void provideDataForType(NSPasteboard
* sender
, NSString
* type
);
164 void applicationDidBecomeActive(NSNotification
* aNotification
);
168 /* Notify all registered XClipboardListener that the clipboard content
171 void fireClipboardChangedEvent();
174 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
> mXComponentContext
;
175 ::com::sun::star::uno::Reference
< ::com::sun::star::datatransfer::XMimeContentTypeFactory
> mrXMimeCntFactory
;
176 ::std::list
< ::com::sun::star::uno::Reference
< ::com::sun::star::datatransfer::clipboard::XClipboardListener
> > mClipboardListeners
;
177 ::com::sun::star::uno::Reference
< ::com::sun::star::datatransfer::XTransferable
> mXClipboardContent
;
178 com::sun::star::uno::Reference
< com::sun::star::datatransfer::clipboard::XClipboardOwner
> mXClipboardOwner
;
179 DataFlavorMapperPtr_t mpDataFlavorMapper
;
180 bool mIsSystemPasteboard
;
181 NSPasteboard
* mPasteboard
;
182 int mPasteboardChangeCount
;
183 EventListener
* mEventListener
;