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