1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #include <sal/types.h>
23 #include <com/sun/star/datatransfer/XTransferable.hpp>
24 #include <com/sun/star/uno/XComponentContext.hpp>
27 #if !defined WIN32_LEAN_AND_MEAN
28 # define WIN32_LEAN_AND_MEAN
34 /*****************************************************************
35 a simple container for FORMATECT structures
36 instances of this class are not thread-safe
37 *****************************************************************/
39 class CFormatEtcContainer
42 CFormatEtcContainer( );
44 // duplicates not allowed
45 void addFormatEtc( const CFormatEtc
& fetc
);
47 // removes the specified formatetc
48 void removeFormatEtc( const CFormatEtc
& fetc
);
50 // removes the formatetc at pos
51 void removeAllFormatEtc( );
53 bool hasFormatEtc( const CFormatEtc
& fetc
) const;
55 bool hasElements( ) const;
58 void beginEnumFormatEtc( );
60 // copies the specified number of formatetc structures starting
61 // at the current enum position
62 // the return value is the number of copied elements; if the
63 // current enum position is at the end the return value is 0
64 sal_uInt32
nextFormatEtc( LPFORMATETC lpFetc
, sal_uInt32 aNum
= 1 );
66 // skips the specified number of elements in the container
67 bool skipFormatEtc( sal_uInt32 aNum
);
70 typedef std::vector
< CFormatEtc
> FormatEtcMap_t
;
73 FormatEtcMap_t m_FormatMap
;
74 FormatEtcMap_t::iterator m_EnumIterator
;
77 /*****************************************************************
78 a helper class which converts data flavors to clipformats,
79 creates an appropriate formatetc structures and if possible
80 synthesizes clipboard formats if necessary, e.g. if text
81 is provided a locale will also be provided;
82 the class registers the formatetc within a CFormatEtcContainer
84 instances of this class are not thread-safe and multiple
85 instances of this class would use the same static variables
86 that's why this class should not be used by multiple threads,
87 only one thread of a process should use it
88 *****************************************************************/
91 class CDataFormatTranslator
;
93 class CFormatRegistrar
96 CFormatRegistrar( const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
97 const CDataFormatTranslator
& aDataFormatTranslator
);
99 void RegisterFormats( const css::uno::Reference
< css::datatransfer::XTransferable
>& aXTransferable
,
100 CFormatEtcContainer
& aFormatEtcContainer
);
102 bool hasSynthesizedLocale( ) const;
103 static LCID
getSynthesizedLocale( );
104 static sal_uInt32
getRegisteredTextCodePage( );
105 css::datatransfer::DataFlavor
getRegisteredTextFlavor( ) const;
107 static bool isSynthesizeableFormat( const CFormatEtc
& aFormatEtc
);
108 static bool needsToSynthesizeAccompanyFormats( const CFormatEtc
& aFormatEtc
);
111 OUString
getCharsetFromDataFlavor( const css::datatransfer::DataFlavor
& aFlavor
);
113 bool hasUnicodeFlavor(
114 const css::uno::Reference
< css::datatransfer::XTransferable
>& aXTransferable
) const;
116 static bool findLocaleForTextCodePage( );
118 static bool isLocaleOemCodePage( LCID lcid
, sal_uInt32 codepage
);
119 static bool isLocaleAnsiCodePage( LCID lcid
, sal_uInt32 codepage
);
120 static bool isLocaleCodePage( LCID lcid
, LCTYPE lctype
, sal_uInt32 codepage
);
122 static BOOL CALLBACK
EnumLocalesProc( LPSTR lpLocaleStr
);
125 const CDataFormatTranslator
& m_DataFormatTranslator
;
126 bool m_bHasSynthesizedLocale
;
127 css::datatransfer::DataFlavor m_RegisteredTextFlavor
;
129 const css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
131 static LCID m_TxtLocale
;
132 static sal_uInt32 m_TxtCodePage
;
135 CFormatRegistrar( const CFormatRegistrar
& );
136 CFormatRegistrar
& operator=( const CFormatRegistrar
& );
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */