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