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