1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _AQUA_CLIPBOARD_HXX_
29 #define _AQUA_CLIPBOARD_HXX_
30 
31 #include "DataFlavorMapping.hxx"
32 #include <rtl/ustring.hxx>
33 #include <sal/types.h>
34 #include <cppuhelper/compbase4.hxx>
35 #include <com/sun/star/datatransfer/XTransferable.hpp>
36 #include <com/sun/star/datatransfer/clipboard/XClipboardEx.hpp>
37 #include <com/sun/star/datatransfer/clipboard/XClipboardOwner.hpp>
38 #include <com/sun/star/datatransfer/clipboard/XClipboardListener.hpp>
39 #include <com/sun/star/datatransfer/clipboard/XClipboardNotifier.hpp>
40 #include <com/sun/star/datatransfer/XMimeContentTypeFactory.hpp>
41 #include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp>
42 #include <com/sun/star/lang/XServiceInfo.hpp>
43 #include <cppuhelper/basemutex.hxx>
44 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
45 
46 #include <boost/utility.hpp>
47 #include <list>
48 
49 #include <premac.h>
50 #import <Cocoa/Cocoa.h>
51 #include <postmac.h>
52 
53 class AquaClipboard;
54 
55 @interface EventListener : NSObject
56 {
57      AquaClipboard* pAquaClipboard;
58 }
59 
60 // Init the pasteboard change listener with a reference to the OfficeClipboard
61 // instance
62 - (EventListener*)initWithAquaClipboard: (AquaClipboard*) pcb;
63 
64 // Promiss resolver function
65 - (void)pasteboard:(NSPasteboard*)sender provideDataForType:(NSString *)type;
66 
67 -(void)applicationDidBecomeActive:(NSNotification*)aNotification;
68 
69 -(void)disposing;
70 @end
71 
72 
73 class AquaClipboard : public ::cppu::BaseMutex,
74 					  public ::cppu::WeakComponentImplHelper4< com::sun::star::datatransfer::clipboard::XClipboardEx,
75 															   com::sun::star::datatransfer::clipboard::XClipboardNotifier,
76 															   com::sun::star::datatransfer::clipboard::XFlushableClipboard,
77 															   com::sun::star::lang::XServiceInfo >,
78 					  private ::boost::noncopyable
79 {
80 public:
81   /* Create a clipboard instance.
82 
83 	 @param pasteboard
84 	 If not equal NULL the instance will be instantiated with the provided
85 	 pasteboard reference and 'bUseSystemClipboard' will be ignored
86 
87 	 @param bUseSystemClipboard
88 	 If 'pasteboard' is NULL 'bUseSystemClipboard' determines whether the
89 	 system clipboard will be created (bUseSystemClipboard == true) or if
90 	 the DragPasteboard if bUseSystemClipboard == false
91    */
92   AquaClipboard(NSPasteboard* pasteboard = NULL,
93 				bool bUseSystemClipboard = true);
94 
95   ~AquaClipboard();
96 
97   //------------------------------------------------
98   // XClipboard
99   //------------------------------------------------
100 
101   virtual ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > SAL_CALL getContents()
102 	throw( ::com::sun::star::uno::RuntimeException );
103 
104   virtual void SAL_CALL setContents( const ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable >& xTransferable,
105 									 const ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::clipboard::XClipboardOwner >& xClipboardOwner )
106 	throw( ::com::sun::star::uno::RuntimeException );
107 
108   virtual ::rtl::OUString SAL_CALL getName()
109 	throw( ::com::sun::star::uno::RuntimeException );
110 
111   //------------------------------------------------
112   // XClipboardEx
113   //------------------------------------------------
114 
115   virtual sal_Int8 SAL_CALL getRenderingCapabilities()
116 	throw( ::com::sun::star::uno::RuntimeException );
117 
118   //------------------------------------------------
119   // XClipboardNotifier
120   //------------------------------------------------
121 
122   virtual void SAL_CALL addClipboardListener( const ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::clipboard::XClipboardListener >& listener )
123 	throw( ::com::sun::star::uno::RuntimeException );
124 
125   virtual void SAL_CALL removeClipboardListener( const ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::clipboard::XClipboardListener >& listener )
126 	throw( ::com::sun::star::uno::RuntimeException );
127 
128   //------------------------------------------------
129   // XFlushableClipboard
130   //------------------------------------------------
131 
132   virtual void SAL_CALL flushClipboard( ) throw( com::sun::star::uno::RuntimeException );
133 
134   //------------------------------------------------
135   // XServiceInfo
136   //------------------------------------------------
137 
138   virtual ::rtl::OUString SAL_CALL getImplementationName()
139 	throw(::com::sun::star::uno::RuntimeException);
140 
141   virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
142 	throw(::com::sun::star::uno::RuntimeException);
143 
144   virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()
145 	throw(::com::sun::star::uno::RuntimeException);
146 
147   /* Get a reference to the used pastboard.
148    */
149   NSPasteboard* getPasteboard() const;
150 
151   /* Notify the current clipboard owner that he is no longer the clipboard owner.
152    */
153   void fireLostClipboardOwnershipEvent(::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::clipboard::XClipboardOwner> oldOwner,
154 									   ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > oldContent);
155 
156   void pasteboardChangedOwner();
157 
158   void provideDataForType(NSPasteboard* sender, NSString* type);
159 
160   void applicationDidBecomeActive(NSNotification* aNotification);
161 
162 private:
163 
164   /* Notify all registered XClipboardListener that the clipboard content
165 	 has changed.
166   */
167   void fireClipboardChangedEvent();
168 
169 private:
170   ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XMimeContentTypeFactory > mrXMimeCntFactory;
171   ::std::list< ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::clipboard::XClipboardListener > > mClipboardListeners;
172   ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > mXClipboardContent;
173   com::sun::star::uno::Reference< com::sun::star::datatransfer::clipboard::XClipboardOwner > mXClipboardOwner;
174   DataFlavorMapperPtr_t mpDataFlavorMapper;
175   bool mIsSystemPasteboard;
176   NSPasteboard* mPasteboard;
177   int mPasteboardChangeCount;
178   EventListener* mEventListener;
179 };
180 
181 #endif
182