LibreOffice Module dtrans (master)  1
FetcList.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #ifndef INCLUDED_DTRANS_SOURCE_WIN32_DTOBJ_FETCLIST_HXX
21 #define INCLUDED_DTRANS_SOURCE_WIN32_DTOBJ_FETCLIST_HXX
22 
23 #include <sal/types.h>
24 #include <com/sun/star/datatransfer/XTransferable.hpp>
25 #include <com/sun/star/uno/XComponentContext.hpp>
26 #include "Fetc.hxx"
27 
28 #if !defined WIN32_LEAN_AND_MEAN
29 # define WIN32_LEAN_AND_MEAN
30 #endif
31 #include <windows.h>
32 
33 #include <vector>
34 
35 /*****************************************************************
36  a simple container for FORMATECT structures
37  instances of this class are not thread-safe
38 *****************************************************************/
39 
41 {
42 public:
44 
45  // duplicates not allowed
46  void addFormatEtc( const CFormatEtc& fetc );
47 
48  // removes the specified formatetc
49  void removeFormatEtc( const CFormatEtc& fetc );
50 
51  // removes the formatetc at pos
52  void removeAllFormatEtc( );
53 
54  bool hasFormatEtc( const CFormatEtc& fetc ) const;
55 
56  bool hasElements( ) const;
57 
58  // begin enumeration
59  void beginEnumFormatEtc( );
60 
61  // copies the specified number of formatetc structures starting
62  // at the current enum position
63  // the return value is the number of copied elements; if the
64  // current enum position is at the end the return value is 0
65  sal_uInt32 nextFormatEtc( LPFORMATETC lpFetc, sal_uInt32 aNum = 1 );
66 
67  // skips the specified number of elements in the container
68  bool skipFormatEtc( sal_uInt32 aNum );
69 
70 protected:
71  typedef std::vector< CFormatEtc > FormatEtcMap_t;
72 
73 private:
74  FormatEtcMap_t m_FormatMap;
75  FormatEtcMap_t::iterator m_EnumIterator;
76 };
77 
78 /*****************************************************************
79  a helper class which converts data flavors to clipformats,
80  creates an appropriate formatetc structures and if possible
81  synthesizes clipboard formats if necessary, e.g. if text
82  is provided a locale will also be provided;
83  the class registers the formatetc within a CFormatEtcContainer
84 
85  instances of this class are not thread-safe and multiple
86  instances of this class would use the same static variables
87  that's why this class should not be used by multiple threads,
88  only one thread of a process should use it
89 *****************************************************************/
90 
91 // forward
93 
95 {
96 public:
97  CFormatRegistrar( const css::uno::Reference< css::uno::XComponentContext >& rxContext,
98  const CDataFormatTranslator& aDataFormatTranslator );
99 
100  void RegisterFormats( const css::uno::Reference< css::datatransfer::XTransferable >& aXTransferable,
101  CFormatEtcContainer& aFormatEtcContainer );
102 
103  bool hasSynthesizedLocale( ) const;
104  static LCID getSynthesizedLocale( );
105  static sal_uInt32 getRegisteredTextCodePage( );
106  css::datatransfer::DataFlavor getRegisteredTextFlavor( ) const;
107 
108  static bool isSynthesizeableFormat( const CFormatEtc& aFormatEtc );
109  static bool needsToSynthesizeAccompanyFormats( const CFormatEtc& aFormatEtc );
110 
111 private:
112  OUString getCharsetFromDataFlavor( const css::datatransfer::DataFlavor& aFlavor );
113 
114  bool hasUnicodeFlavor(
115  const css::uno::Reference< css::datatransfer::XTransferable >& aXTransferable ) const;
116 
117  static bool findLocaleForTextCodePage( );
118 
119  static bool isLocaleOemCodePage( LCID lcid, sal_uInt32 codepage );
120  static bool isLocaleAnsiCodePage( LCID lcid, sal_uInt32 codepage );
121  static bool isLocaleCodePage( LCID lcid, LCTYPE lctype, sal_uInt32 codepage );
122 
123  static BOOL CALLBACK EnumLocalesProc( LPSTR lpLocaleStr );
124 
125 private:
128  css::datatransfer::DataFlavor m_RegisteredTextFlavor;
129 
130  const css::uno::Reference< css::uno::XComponentContext > m_xContext;
131 
132  static LCID m_TxtLocale;
133  static sal_uInt32 m_TxtCodePage;
134 
135 private:
138 };
139 
140 #endif
141 
142 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static bool isSynthesizeableFormat(const CFormatEtc &aFormatEtc)
Definition: FetcList.cxx:244
static bool isLocaleOemCodePage(LCID lcid, sal_uInt32 codepage)
Definition: FetcList.cxx:318
static bool isLocaleCodePage(LCID lcid, LCTYPE lctype, sal_uInt32 codepage)
Definition: FetcList.cxx:303
FormatEtcMap_t m_FormatMap
Definition: FetcList.hxx:74
bool hasElements() const
Definition: FetcList.cxx:76
void removeFormatEtc(const CFormatEtc &fetc)
Definition: FetcList.cxx:54
static bool needsToSynthesizeAccompanyFormats(const CFormatEtc &aFormatEtc)
Definition: FetcList.cxx:252
bool hasFormatEtc(const CFormatEtc &fetc) const
Definition: FetcList.cxx:68
static bool findLocaleForTextCodePage()
Definition: FetcList.cxx:296
const CDataFormatTranslator & m_DataFormatTranslator
Definition: FetcList.hxx:126
OUString getCharsetFromDataFlavor(const css::datatransfer::DataFlavor &aFlavor)
Definition: FetcList.cxx:259
const wchar_t *typedef BOOL
void removeAllFormatEtc()
Definition: FetcList.cxx:63
bool m_bHasSynthesizedLocale
Definition: FetcList.hxx:127
void beginEnumFormatEtc()
Definition: FetcList.cxx:81
CFormatRegistrar(const css::uno::Reference< css::uno::XComponentContext > &rxContext, const CDataFormatTranslator &aDataFormatTranslator)
bool hasUnicodeFlavor(const css::uno::Reference< css::datatransfer::XTransferable > &aXTransferable) const
Definition: FetcList.cxx:286
void RegisterFormats(const css::uno::Reference< css::datatransfer::XTransferable > &aXTransferable, CFormatEtcContainer &aFormatEtcContainer)
Definition: FetcList.cxx:143
static bool isLocaleAnsiCodePage(LCID lcid, sal_uInt32 codepage)
Definition: FetcList.cxx:324
FormatEtcMap_t::iterator m_EnumIterator
Definition: FetcList.hxx:75
static LCID getSynthesizedLocale()
Definition: FetcList.cxx:229
bool hasSynthesizedLocale() const
Definition: FetcList.cxx:224
std::vector< CFormatEtc > FormatEtcMap_t
Definition: FetcList.hxx:71
bool skipFormatEtc(sal_uInt32 aNum)
Definition: FetcList.cxx:104
sal_uInt32 nextFormatEtc(LPFORMATETC lpFetc, sal_uInt32 aNum=1)
Definition: FetcList.cxx:86
css::datatransfer::DataFlavor m_RegisteredTextFlavor
Definition: FetcList.hxx:128
css::datatransfer::DataFlavor getRegisteredTextFlavor() const
Definition: FetcList.cxx:239
static LCID m_TxtLocale
Definition: FetcList.hxx:132
const css::uno::Reference< css::uno::XComponentContext > m_xContext
Definition: FetcList.hxx:130
CFormatRegistrar & operator=(const CFormatRegistrar &)
static sal_uInt32 m_TxtCodePage
Definition: FetcList.hxx:133
#define CALLBACK
void addFormatEtc(const CFormatEtc &fetc)
Definition: FetcList.cxx:49
static sal_uInt32 getRegisteredTextCodePage()
Definition: FetcList.cxx:234
static BOOL CALLBACK EnumLocalesProc(LPSTR lpLocaleStr)
Definition: FetcList.cxx:329