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