1fbcf0fe9SAndrew Rist /**************************************************************
2*9f86329eSmseidel  *
3fbcf0fe9SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4fbcf0fe9SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5fbcf0fe9SAndrew Rist  * distributed with this work for additional information
6fbcf0fe9SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7fbcf0fe9SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8fbcf0fe9SAndrew Rist  * "License"); you may not use this file except in compliance
9fbcf0fe9SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*9f86329eSmseidel  *
11fbcf0fe9SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*9f86329eSmseidel  *
13fbcf0fe9SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14fbcf0fe9SAndrew Rist  * software distributed under the License is distributed on an
15fbcf0fe9SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16fbcf0fe9SAndrew Rist  * KIND, either express or implied.  See the License for the
17fbcf0fe9SAndrew Rist  * specific language governing permissions and limitations
18fbcf0fe9SAndrew Rist  * under the License.
19*9f86329eSmseidel  *
20fbcf0fe9SAndrew Rist  *************************************************************/
21fbcf0fe9SAndrew Rist 
22fbcf0fe9SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _FETCLIST_HXX_
25cdf0e10cSrcweir #define _FETCLIST_HXX_
26cdf0e10cSrcweir 
27cdf0e10cSrcweir //------------------------------------------------------------------------
28cdf0e10cSrcweir // includes
29cdf0e10cSrcweir //------------------------------------------------------------------------
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <sal/types.h>
32cdf0e10cSrcweir #include <cppuhelper/servicefactory.hxx>
33cdf0e10cSrcweir #include <com/sun/star/datatransfer/XTransferable.hpp>
34cdf0e10cSrcweir #include "Fetc.hxx"
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #if defined _MSC_VER
37cdf0e10cSrcweir #pragma warning(push,1)
38cdf0e10cSrcweir #endif
39cdf0e10cSrcweir #include <windows.h>
40cdf0e10cSrcweir #if defined _MSC_VER
41cdf0e10cSrcweir #pragma warning(pop)
42cdf0e10cSrcweir #endif
43cdf0e10cSrcweir #include <vector>
44cdf0e10cSrcweir 
45cdf0e10cSrcweir /*****************************************************************
46*9f86329eSmseidel 	a simple container for FORMATETC structures
47*9f86329eSmseidel 	instances of this class are not thread-safe
48cdf0e10cSrcweir *****************************************************************/
49cdf0e10cSrcweir 
50cdf0e10cSrcweir class CFormatEtcContainer
51cdf0e10cSrcweir {
52cdf0e10cSrcweir public:
53cdf0e10cSrcweir 	CFormatEtcContainer( );
54cdf0e10cSrcweir 
55cdf0e10cSrcweir 	// duplicates not allowed
56cdf0e10cSrcweir 	void SAL_CALL addFormatEtc( const CFormatEtc& fetc );
57*9f86329eSmseidel 
58*9f86329eSmseidel 	// removes the specified formatetc
59cdf0e10cSrcweir 	void SAL_CALL removeFormatEtc( const CFormatEtc& fetc );
60*9f86329eSmseidel 
61cdf0e10cSrcweir 	// removes the formatetc at pos
62cdf0e10cSrcweir 	void SAL_CALL removeAllFormatEtc( );
63cdf0e10cSrcweir 
64cdf0e10cSrcweir 	sal_Bool SAL_CALL hasFormatEtc( const CFormatEtc& fetc ) const;
65*9f86329eSmseidel 
66cdf0e10cSrcweir 	sal_Bool SAL_CALL hasElements( ) const;
67*9f86329eSmseidel 
68cdf0e10cSrcweir 	// begin enumeration
69cdf0e10cSrcweir 	void SAL_CALL beginEnumFormatEtc( );
70*9f86329eSmseidel 
71cdf0e10cSrcweir 	// copies the specified number of formatetc structures starting
72cdf0e10cSrcweir 	// at the current enum position
73*9f86329eSmseidel 	// the return value is the number of copied elements; if the
74cdf0e10cSrcweir 	// current enum position is at the end the return value is 0
75cdf0e10cSrcweir 	sal_uInt32 SAL_CALL nextFormatEtc( LPFORMATETC lpFetc, sal_uInt32 aNum = 1 );
76cdf0e10cSrcweir 
77cdf0e10cSrcweir 	// skips the specified number of elements in the container
78cdf0e10cSrcweir 	sal_Bool SAL_CALL skipFormatEtc( sal_uInt32 aNum );
79cdf0e10cSrcweir 
80cdf0e10cSrcweir protected:
81cdf0e10cSrcweir 	typedef std::vector< CFormatEtc > FormatEtcMap_t;
82cdf0e10cSrcweir 
83*9f86329eSmseidel private:
84cdf0e10cSrcweir 	FormatEtcMap_t           m_FormatMap;
85cdf0e10cSrcweir 	FormatEtcMap_t::iterator m_EnumIterator;
86cdf0e10cSrcweir };
87cdf0e10cSrcweir 
88cdf0e10cSrcweir /*****************************************************************
89cdf0e10cSrcweir 	a helper class which converts data flavors to clipformats,
90cdf0e10cSrcweir 	creates an appropriate formatetc structures and if possible
91cdf0e10cSrcweir 	synthesizes clipboard formats if necessary, e.g. if text
92*9f86329eSmseidel 	is provided a locale will also be provided;
93cdf0e10cSrcweir 	the class registers the formatetc within a CFormatEtcContainer
94cdf0e10cSrcweir 
95*9f86329eSmseidel 	instances of this class are not thread-safe and multiple
96cdf0e10cSrcweir 	instances of this class would use the same static variables
97cdf0e10cSrcweir 	that's why this class should not be used by multiple threads,
98cdf0e10cSrcweir 	only one thread of a process should use it
99cdf0e10cSrcweir *****************************************************************/
100cdf0e10cSrcweir 
101cdf0e10cSrcweir // forward
102cdf0e10cSrcweir class CDataFormatTranslator;
103cdf0e10cSrcweir 
104cdf0e10cSrcweir class CFormatRegistrar
105cdf0e10cSrcweir {
106cdf0e10cSrcweir public:
107cdf0e10cSrcweir 	CFormatRegistrar( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& ServiceManager,
108*9f86329eSmseidel 					  const CDataFormatTranslator& aDataFormatTranslator );
109*9f86329eSmseidel 
110cdf0e10cSrcweir 	void SAL_CALL RegisterFormats( const com::sun::star::uno::Reference< com::sun::star::datatransfer::XTransferable >& aXTransferable,
111cdf0e10cSrcweir 								   CFormatEtcContainer& aFormatEtcContainer );
112*9f86329eSmseidel 
113cdf0e10cSrcweir 	sal_Bool   SAL_CALL hasSynthesizedLocale( ) const;
114cdf0e10cSrcweir 	LCID       SAL_CALL getSynthesizedLocale( ) const;
115cdf0e10cSrcweir 	sal_uInt32 SAL_CALL getRegisteredTextCodePage( ) const;
116cdf0e10cSrcweir 	com::sun::star::datatransfer::DataFlavor SAL_CALL getRegisteredTextFlavor( ) const;
117*9f86329eSmseidel 
118cdf0e10cSrcweir 	sal_Bool  SAL_CALL isSynthesizeableFormat( const CFormatEtc& aFormatEtc ) const;
119cdf0e10cSrcweir 	sal_Bool  SAL_CALL needsToSynthesizeAccompanyFormats( const CFormatEtc& aFormatEtc ) const;
120cdf0e10cSrcweir 
121*9f86329eSmseidel private:
122cdf0e10cSrcweir 	sal_Bool      SAL_CALL isEqualCurrentSystemCodePage( sal_uInt32 aCodePage ) const;
123cdf0e10cSrcweir 	rtl::OUString SAL_CALL getCharsetFromDataFlavor( const com::sun::star::datatransfer::DataFlavor& aFlavor );
124*9f86329eSmseidel 
125*9f86329eSmseidel 	sal_Bool SAL_CALL hasUnicodeFlavor(
126cdf0e10cSrcweir 		const com::sun::star::uno::Reference< com::sun::star::datatransfer::XTransferable >& aXTransferable ) const;
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 	sal_Bool SAL_CALL findLocaleForTextCodePage( );
129cdf0e10cSrcweir 
130cdf0e10cSrcweir 	static sal_Bool SAL_CALL isLocaleOemCodePage( LCID lcid, sal_uInt32 codepage );
131cdf0e10cSrcweir 	static sal_Bool SAL_CALL isLocaleAnsiCodePage( LCID lcid, sal_uInt32 codepage );
132cdf0e10cSrcweir 	static sal_Bool SAL_CALL isLocaleCodePage( LCID lcid, LCTYPE lctype, sal_uInt32 codepage );
133cdf0e10cSrcweir 
134cdf0e10cSrcweir 	static BOOL CALLBACK EnumLocalesProc( LPSTR lpLocaleStr );
135*9f86329eSmseidel 
136*9f86329eSmseidel private:
137cdf0e10cSrcweir 	const CDataFormatTranslator&			 m_DataFormatTranslator;
138cdf0e10cSrcweir 	sal_Bool								 m_bHasSynthesizedLocale;
139cdf0e10cSrcweir 	com::sun::star::datatransfer::DataFlavor m_RegisteredTextFlavor;
140cdf0e10cSrcweir 
141cdf0e10cSrcweir 	const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >	m_SrvMgr;
142*9f86329eSmseidel 
143cdf0e10cSrcweir 	static LCID       m_TxtLocale;
144cdf0e10cSrcweir 	static sal_uInt32 m_TxtCodePage;
145*9f86329eSmseidel 
146cdf0e10cSrcweir private:
147cdf0e10cSrcweir 	CFormatRegistrar( const CFormatRegistrar& );
148cdf0e10cSrcweir 	CFormatRegistrar& operator=( const CFormatRegistrar& );
149cdf0e10cSrcweir };
150cdf0e10cSrcweir 
151cdf0e10cSrcweir #endif
152