1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _DOTRANSFERABLE_HXX_
25 #define _DOTRANSFERABLE_HXX_
26 
27 //------------------------------------------------------------------------
28 // includes
29 //------------------------------------------------------------------------
30 
31 #include <com/sun/star/datatransfer/XTransferable.hpp>
32 
33 #ifndef _CPPUHELPER_IMPLBASE1_HXX_
34 #include <cppuhelper/implbase2.hxx>
35 #endif
36 #include "DataFmtTransl.hxx"
37 #include <com/sun/star/datatransfer/XMimeContentTypeFactory.hpp>
38 #include <com/sun/star/datatransfer/XMimeContentType.hpp>
39 #include <com/sun/star/datatransfer/XSystemTransferable.hpp>
40 
41 #include <systools/win32/comtools.hxx>
42 
43 //------------------------------------------------------------------------
44 // declarations
45 //------------------------------------------------------------------------
46 
47 // forward
48 class CDTransObjFactory;
49 class CFormatEtc;
50 
51 class CDOTransferable : public ::cppu::WeakImplHelper2< ::com::sun::star::datatransfer::XTransferable,
52 						::com::sun::star::datatransfer::XSystemTransferable>
53 {
54 public:
55 	typedef com::sun::star::uno::Sequence< sal_Int8 > ByteSequence_t;
56 
57 	//------------------------------------------------------------------------
58 	// XTransferable
59 	//------------------------------------------------------------------------
60 
61 	virtual ::com::sun::star::uno::Any SAL_CALL getTransferData( const ::com::sun::star::datatransfer::DataFlavor& aFlavor )
62 		throw( ::com::sun::star::datatransfer::UnsupportedFlavorException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException );
63 
64 	virtual ::com::sun::star::uno::Sequence< ::com::sun::star::datatransfer::DataFlavor > SAL_CALL getTransferDataFlavors(  )
65 		throw( ::com::sun::star::uno::RuntimeException );
66 
67 	virtual sal_Bool SAL_CALL isDataFlavorSupported( const ::com::sun::star::datatransfer::DataFlavor& aFlavor )
68 		throw( ::com::sun::star::uno::RuntimeException );
69 	//------------------------------------------------------------------------
70 	// XSystemTransferable
71 	//------------------------------------------------------------------------
72 	virtual ::com::sun::star::uno::Any SAL_CALL getData( const com::sun::star::uno::Sequence<sal_Int8>& aProcessId  ) throw
73 	(::com::sun::star::uno::RuntimeException);
74 
75 
76 private:
77 	// should be created only by CDTransObjFactory
78 	explicit CDOTransferable(
79 		const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& ServiceManager,
80 		IDataObjectPtr rDataObject );
81 
82 	//------------------------------------------------------------------------
83 	// some helper functions
84 	//------------------------------------------------------------------------
85 
86 	void SAL_CALL initFlavorList( );
87 
88 	void SAL_CALL addSupportedFlavor( const com::sun::star::datatransfer::DataFlavor& aFlavor );
89 	com::sun::star::datatransfer::DataFlavor SAL_CALL formatEtcToDataFlavor( const FORMATETC& aFormatEtc );
90 
91 	ByteSequence_t SAL_CALL getClipboardData( CFormatEtc& aFormatEtc );
92 	rtl::OUString  SAL_CALL synthesizeUnicodeText( );
93 
94 	void SAL_CALL clipDataToByteStream( CLIPFORMAT cf, STGMEDIUM stgmedium, ByteSequence_t& aByteSequence );
95 
96 	::com::sun::star::uno::Any SAL_CALL byteStreamToAny( ByteSequence_t& aByteStream, const com::sun::star::uno::Type& aRequestedDataType );
97 	rtl::OUString              SAL_CALL byteStreamToOUString( ByteSequence_t& aByteStream );
98 
99 	LCID SAL_CALL getLocaleFromClipboard( );
100 
101 	sal_Bool SAL_CALL compareDataFlavors( const com::sun::star::datatransfer::DataFlavor& lhs,
102 										  const com::sun::star::datatransfer::DataFlavor& rhs );
103 
104 	sal_Bool SAL_CALL cmpFullMediaType( const com::sun::star::uno::Reference< com::sun::star::datatransfer::XMimeContentType >& xLhs,
105 										const com::sun::star::uno::Reference< com::sun::star::datatransfer::XMimeContentType >& xRhs ) const;
106 
107 	sal_Bool SAL_CALL cmpAllContentTypeParameter( const com::sun::star::uno::Reference< com::sun::star::datatransfer::XMimeContentType >& xLhs,
108 										const com::sun::star::uno::Reference< com::sun::star::datatransfer::XMimeContentType >& xRhs ) const;
109 
110 private:
111 	IDataObjectPtr																			m_rDataObject;
112 	com::sun::star::uno::Sequence< com::sun::star::datatransfer::DataFlavor >				m_FlavorList;
113 	const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >	m_SrvMgr;
114 	CDataFormatTranslator																	m_DataFormatTranslator;
115 	com::sun::star::uno::Reference< com::sun::star::datatransfer::XMimeContentTypeFactory > m_rXMimeCntFactory;
116 	::osl::Mutex																			m_aMutex;
117 	sal_Bool																				m_bUnicodeRegistered;
118 	CLIPFORMAT																				m_TxtFormatOnClipboard;
119 
120 // non supported operations
121 private:
122 	CDOTransferable( const CDOTransferable& );
123 	CDOTransferable& operator=( const CDOTransferable& );
124 
125 	friend class CDTransObjFactory;
126 };
127 
128 #endif
129