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 
25 #ifndef _FTRANSL_HXX_
26 #define _FTRANSL_HXX_
27 
28 //------------------------------------------------------------------------
29 // includes
30 //------------------------------------------------------------------------
31 
32 #include <rtl/ustring.hxx>
33 #include <sal/types.h>
34 #include <cppuhelper/compbase2.hxx>
35 #include <com/sun/star/lang/XServiceInfo.hpp>
36 #include <com/sun/star/datatransfer/XDataFormatTranslator.hpp>
37 #include <com/sun/star/datatransfer/XMimeContentTypeFactory.hpp>
38 #include "..\misc\WinClip.hxx"
39 
40 #include <vector>
41 
42 #if defined _MSC_VER
43 #pragma warning(push,1)
44 #endif
45 #include <windows.h>
46 #if defined _MSC_VER
47 #pragma warning(pop)
48 #endif
49 
50 //------------------------------------------------------------------------
51 // declarations
52 //------------------------------------------------------------------------
53 
54 struct FormatEntry
55 {
56    FormatEntry();
57 
58    FormatEntry(
59         const char* mime_content_type,
60         const char* human_presentable_name,
61         const char* native_format_name,
62         CLIPFORMAT std_clipboard_format_id,
63         com::sun::star::uno::Type const & cppu_type
64 	);
65 
66 	com::sun::star::datatransfer::DataFlavor aDataFlavor;
67 	rtl::OUString							 aNativeFormatName;
68 	sal_Int32								 aStandardFormatId;
69 };
70 
71 //------------------------------------------------
72 // CDataFormatTranslator
73 //------------------------------------------------
74 
75 class CDataFormatTranslator : public
76 	cppu::WeakImplHelper2< com::sun::star::datatransfer::XDataFormatTranslator, \
77 	com::sun::star::lang::XServiceInfo >
78 {
79 
80 public:
81 	CDataFormatTranslator( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rSrvMgr );
82 
83 	//------------------------------------------------
84 	// XDataFormatTranslator
85 	//------------------------------------------------
86 
87 	virtual ::com::sun::star::uno::Any SAL_CALL getSystemDataTypeFromDataFlavor( const ::com::sun::star::datatransfer::DataFlavor& aDataFlavor )
88 		throw(::com::sun::star::uno::RuntimeException);
89 
90     virtual ::com::sun::star::datatransfer::DataFlavor SAL_CALL getDataFlavorFromSystemDataType( const ::com::sun::star::uno::Any& aSysDataType )
91 		throw(::com::sun::star::uno::RuntimeException);
92 
93 	//------------------------------------------------
94 	// XServiceInfo
95 	//------------------------------------------------
96 
97 	virtual ::rtl::OUString SAL_CALL getImplementationName(	 )
98 		throw(::com::sun::star::uno::RuntimeException);
99 
100 	virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
101 		throw(::com::sun::star::uno::RuntimeException);
102 
103 	virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  )
104 		throw(::com::sun::star::uno::RuntimeException);
105 
106 private:
107 	void SAL_CALL initTranslationTable( );
108 
109 	void SAL_CALL findDataFlavorForStandardFormatId( sal_Int32 aStandardFormatId, com::sun::star::datatransfer::DataFlavor& aDataFlavor ) const;
110 	void SAL_CALL findDataFlavorForNativeFormatName( const rtl::OUString& aNativeFormatName, com::sun::star::datatransfer::DataFlavor& aDataFlavor ) const;
111 	void SAL_CALL findStandardFormatIdForCharset( const rtl::OUString& aCharset, com::sun::star::uno::Any& aAny ) const;
112 	void SAL_CALL setStandardFormatIdForNativeFormatName( const rtl::OUString& aNativeFormatName, com::sun::star::uno::Any& aAny ) const;
113 	void SAL_CALL findStdFormatIdOrNativeFormatNameForFullMediaType(
114 		const com::sun::star::uno::Reference< com::sun::star::datatransfer::XMimeContentTypeFactory >& aRefXMimeFactory,
115 		const rtl::OUString& aFullMediaType, com::sun::star::uno::Any& aAny ) const;
116 
117     sal_Bool isTextPlainMediaType( const rtl::OUString& fullMediaType ) const;
118 
119 	com::sun::star::datatransfer::DataFlavor SAL_CALL mkDataFlv( const rtl::OUString& cnttype, const rtl::OUString& hpname, ::com::sun::star::uno::Type dtype );
120 
121 private:
122 	std::vector< FormatEntry >	m_TranslTable;
123 	const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >	m_SrvMgr;
124 };
125 
126 
127 #endif
128 
129