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 _FETCLIST_HXX_
30 #define _FETCLIST_HXX_
31 
32 //------------------------------------------------------------------------
33 // includes
34 //------------------------------------------------------------------------
35 
36 #include <sal/types.h>
37 #include <cppuhelper/servicefactory.hxx>
38 #include <com/sun/star/datatransfer/XTransferable.hpp>
39 #include "Fetc.hxx"
40 
41 #if defined _MSC_VER
42 #pragma warning(push,1)
43 #endif
44 #include <windows.h>
45 #if defined _MSC_VER
46 #pragma warning(pop)
47 #endif
48 #include <vector>
49 
50 /*****************************************************************
51 	a simple container for FORMATECT structures
52 	instances of this class are not thread-safe
53 *****************************************************************/
54 
55 class CFormatEtcContainer
56 {
57 public:
58 	CFormatEtcContainer( );
59 
60 	// duplicates not allowed
61 	void SAL_CALL addFormatEtc( const CFormatEtc& fetc );
62 
63 	// removes the specified formatetc
64 	void SAL_CALL removeFormatEtc( const CFormatEtc& fetc );
65 
66 	// removes the formatetc at pos
67 	void SAL_CALL removeAllFormatEtc( );
68 
69 	sal_Bool SAL_CALL hasFormatEtc( const CFormatEtc& fetc ) const;
70 
71 	sal_Bool SAL_CALL hasElements( ) const;
72 
73 	// begin enumeration
74 	void SAL_CALL beginEnumFormatEtc( );
75 
76 	// copies the specified number of formatetc structures starting
77 	// at the current enum position
78 	// the return value is the number of copied elements; if the
79 	// current enum position is at the end the return value is 0
80 	sal_uInt32 SAL_CALL nextFormatEtc( LPFORMATETC lpFetc, sal_uInt32 aNum = 1 );
81 
82 	// skips the specified number of elements in the container
83 	sal_Bool SAL_CALL skipFormatEtc( sal_uInt32 aNum );
84 
85 protected:
86 	typedef std::vector< CFormatEtc > FormatEtcMap_t;
87 
88 private:
89 	FormatEtcMap_t           m_FormatMap;
90 	FormatEtcMap_t::iterator m_EnumIterator;
91 };
92 
93 /*****************************************************************
94 	a helper class which converts data flavors to clipformats,
95 	creates an appropriate formatetc structures and if possible
96 	synthesizes clipboard formats if necessary, e.g. if text
97 	is provided a locale will also be provided;
98 	the class registers the formatetc within a CFormatEtcContainer
99 
100 	instances of this class are not thread-safe and multiple
101 	instances of this class would use the same static variables
102 	that's why this class should not be used by multiple threads,
103 	only one thread of a process should use it
104 *****************************************************************/
105 
106 // forward
107 class CDataFormatTranslator;
108 
109 class CFormatRegistrar
110 {
111 public:
112 	CFormatRegistrar( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& ServiceManager,
113 					  const CDataFormatTranslator& aDataFormatTranslator );
114 
115 	void SAL_CALL RegisterFormats( const com::sun::star::uno::Reference< com::sun::star::datatransfer::XTransferable >& aXTransferable,
116 								   CFormatEtcContainer& aFormatEtcContainer );
117 
118 	sal_Bool   SAL_CALL hasSynthesizedLocale( ) const;
119 	LCID       SAL_CALL getSynthesizedLocale( ) const;
120 	sal_uInt32 SAL_CALL getRegisteredTextCodePage( ) const;
121 	com::sun::star::datatransfer::DataFlavor SAL_CALL getRegisteredTextFlavor( ) const;
122 
123 	sal_Bool  SAL_CALL isSynthesizeableFormat( const CFormatEtc& aFormatEtc ) const;
124 	sal_Bool  SAL_CALL needsToSynthesizeAccompanyFormats( const CFormatEtc& aFormatEtc ) const;
125 
126 private:
127 	sal_Bool      SAL_CALL isEqualCurrentSystemCodePage( sal_uInt32 aCodePage ) const;
128 	rtl::OUString SAL_CALL getCharsetFromDataFlavor( const com::sun::star::datatransfer::DataFlavor& aFlavor );
129 
130 	sal_Bool SAL_CALL hasUnicodeFlavor(
131 		const com::sun::star::uno::Reference< com::sun::star::datatransfer::XTransferable >& aXTransferable ) const;
132 
133 	sal_Bool SAL_CALL findLocaleForTextCodePage( );
134 
135 	static sal_Bool SAL_CALL isLocaleOemCodePage( LCID lcid, sal_uInt32 codepage );
136 	static sal_Bool SAL_CALL isLocaleAnsiCodePage( LCID lcid, sal_uInt32 codepage );
137 	static sal_Bool SAL_CALL isLocaleCodePage( LCID lcid, LCTYPE lctype, sal_uInt32 codepage );
138 
139 	static BOOL CALLBACK EnumLocalesProc( LPSTR lpLocaleStr );
140 
141 private:
142 	const CDataFormatTranslator&			 m_DataFormatTranslator;
143 	sal_Bool								 m_bHasSynthesizedLocale;
144 	com::sun::star::datatransfer::DataFlavor m_RegisteredTextFlavor;
145 
146 	const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >	m_SrvMgr;
147 
148 	static LCID       m_TxtLocale;
149 	static sal_uInt32 m_TxtCodePage;
150 
151 private:
152 	CFormatRegistrar( const CFormatRegistrar& );
153 	CFormatRegistrar& operator=( const CFormatRegistrar& );
154 };
155 
156 #endif
157