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