1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_dtrans.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir //------------------------------------------------------------------------ 32*cdf0e10cSrcweir // includes 33*cdf0e10cSrcweir //------------------------------------------------------------------------ 34*cdf0e10cSrcweir #include <osl/diagnose.h> 35*cdf0e10cSrcweir #include "FetcList.hxx" 36*cdf0e10cSrcweir #include "Fetc.hxx" 37*cdf0e10cSrcweir #include <com/sun/star/datatransfer/XMimeContentTypeFactory.hpp> 38*cdf0e10cSrcweir #include <com/sun/star/datatransfer/XMimeContentType.hpp> 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir #ifndef _DATAFORMATTRANSLATOR_HXX_ 41*cdf0e10cSrcweir #include "DataFmtTransl.hxx" 42*cdf0e10cSrcweir #endif 43*cdf0e10cSrcweir #include "..\misc\ImplHelper.hxx" 44*cdf0e10cSrcweir #include "..\misc\WinClip.hxx" 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir #include <algorithm> 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir #include "MimeAttrib.hxx" 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir //------------------------------------------------------------------------ 51*cdf0e10cSrcweir // namespace directives 52*cdf0e10cSrcweir //------------------------------------------------------------------------ 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir using namespace com::sun::star::uno; 55*cdf0e10cSrcweir using namespace com::sun::star::datatransfer; 56*cdf0e10cSrcweir using namespace com::sun::star::lang; 57*cdf0e10cSrcweir using namespace com::sun::star::container; 58*cdf0e10cSrcweir using namespace rtl; 59*cdf0e10cSrcweir using namespace std; 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir //------------------------------------------------------------------------ 62*cdf0e10cSrcweir // 63*cdf0e10cSrcweir //------------------------------------------------------------------------ 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir LCID CFormatRegistrar::m_TxtLocale = 0; 66*cdf0e10cSrcweir sal_uInt32 CFormatRegistrar::m_TxtCodePage = GetACP( ); 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir //------------------------------------------------------------------------ 69*cdf0e10cSrcweir // 70*cdf0e10cSrcweir //------------------------------------------------------------------------ 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir CFormatEtcContainer::CFormatEtcContainer( ) 73*cdf0e10cSrcweir { 74*cdf0e10cSrcweir m_EnumIterator = m_FormatMap.begin( ); 75*cdf0e10cSrcweir } 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir //------------------------------------------------------------------------ 78*cdf0e10cSrcweir // 79*cdf0e10cSrcweir //------------------------------------------------------------------------ 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir void CFormatEtcContainer::addFormatEtc( const CFormatEtc& fetc ) 82*cdf0e10cSrcweir { 83*cdf0e10cSrcweir m_FormatMap.push_back( CFormatEtc( fetc ) ); 84*cdf0e10cSrcweir } 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir //------------------------------------------------------------------------ 87*cdf0e10cSrcweir // 88*cdf0e10cSrcweir //------------------------------------------------------------------------ 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir void SAL_CALL CFormatEtcContainer::removeFormatEtc( const CFormatEtc& fetc ) 91*cdf0e10cSrcweir { 92*cdf0e10cSrcweir FormatEtcMap_t::iterator iter = 93*cdf0e10cSrcweir find( m_FormatMap.begin(), m_FormatMap.end(), fetc ); 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir if ( iter != m_FormatMap.end( ) ) 96*cdf0e10cSrcweir m_FormatMap.erase( iter ); 97*cdf0e10cSrcweir } 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir //------------------------------------------------------------------------ 100*cdf0e10cSrcweir // 101*cdf0e10cSrcweir //------------------------------------------------------------------------ 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir void SAL_CALL CFormatEtcContainer::removeAllFormatEtc( ) 104*cdf0e10cSrcweir { 105*cdf0e10cSrcweir m_FormatMap.clear( ); 106*cdf0e10cSrcweir } 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir //------------------------------------------------------------------------ 109*cdf0e10cSrcweir // 110*cdf0e10cSrcweir //------------------------------------------------------------------------ 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir sal_Bool CFormatEtcContainer::hasFormatEtc( const CFormatEtc& fetc ) const 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir FormatEtcMap_t::const_iterator iter = 115*cdf0e10cSrcweir find( m_FormatMap.begin(), m_FormatMap.end(), fetc ); 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir return ( iter != m_FormatMap.end( ) ); 118*cdf0e10cSrcweir } 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir //------------------------------------------------------------------------ 121*cdf0e10cSrcweir // 122*cdf0e10cSrcweir //------------------------------------------------------------------------ 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir sal_Bool CFormatEtcContainer::hasElements( ) const 125*cdf0e10cSrcweir { 126*cdf0e10cSrcweir return ( m_FormatMap.size( ) > 0 ); 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir //------------------------------------------------------------------------ 130*cdf0e10cSrcweir // 131*cdf0e10cSrcweir //------------------------------------------------------------------------ 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir void CFormatEtcContainer::beginEnumFormatEtc( ) 134*cdf0e10cSrcweir { 135*cdf0e10cSrcweir m_EnumIterator = m_FormatMap.begin( ); 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir //------------------------------------------------------------------------ 139*cdf0e10cSrcweir // 140*cdf0e10cSrcweir //------------------------------------------------------------------------ 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir sal_uInt32 SAL_CALL CFormatEtcContainer::nextFormatEtc( LPFORMATETC lpFetc, 143*cdf0e10cSrcweir sal_uInt32 aNum ) 144*cdf0e10cSrcweir { 145*cdf0e10cSrcweir OSL_ASSERT( lpFetc ); 146*cdf0e10cSrcweir OSL_ASSERT( !IsBadWritePtr( lpFetc, sizeof( FORMATETC ) * aNum ) ); 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir sal_uInt32 nFetched = 0; 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir if ( m_EnumIterator != m_FormatMap.end( ) ) 151*cdf0e10cSrcweir { 152*cdf0e10cSrcweir for ( sal_uInt32 i = 0; i < aNum; i++, nFetched++, lpFetc++, ++m_EnumIterator ) 153*cdf0e10cSrcweir CopyFormatEtc( lpFetc, *m_EnumIterator ); 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir return nFetched; 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir //------------------------------------------------------------------------ 161*cdf0e10cSrcweir // 162*cdf0e10cSrcweir //------------------------------------------------------------------------ 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir sal_Bool SAL_CALL CFormatEtcContainer::skipFormatEtc( sal_uInt32 aNum ) 165*cdf0e10cSrcweir { 166*cdf0e10cSrcweir FormatEtcMap_t::const_iterator iter_end = m_FormatMap.end( ); 167*cdf0e10cSrcweir for ( sal_uInt32 i = 0; 168*cdf0e10cSrcweir (i < aNum) && (m_EnumIterator != iter_end); 169*cdf0e10cSrcweir i++, ++m_EnumIterator ) 170*cdf0e10cSrcweir ;/* intentionally left empty */ 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir return ( m_EnumIterator != m_FormatMap.end( ) ); 173*cdf0e10cSrcweir } 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir //######################################################################### 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir //------------------------------------------------------------------------ 180*cdf0e10cSrcweir // 181*cdf0e10cSrcweir //------------------------------------------------------------------------ 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir CFormatRegistrar::CFormatRegistrar( const Reference< XMultiServiceFactory >& ServiceManager, 184*cdf0e10cSrcweir const CDataFormatTranslator& aDataFormatTranslator ) : 185*cdf0e10cSrcweir m_DataFormatTranslator( aDataFormatTranslator ), 186*cdf0e10cSrcweir m_bHasSynthesizedLocale( sal_False ), 187*cdf0e10cSrcweir m_SrvMgr( ServiceManager ) 188*cdf0e10cSrcweir { 189*cdf0e10cSrcweir } 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir // ---------------------------------------------------------------------------------------- 192*cdf0e10cSrcweir // this function converts all DataFlavors of the given FlavorList into 193*cdf0e10cSrcweir // an appropriate FORMATETC structure, for some formats like unicodetext, 194*cdf0e10cSrcweir // text and text/html we will offer an accompany format e.g.: 195*cdf0e10cSrcweir // 196*cdf0e10cSrcweir // DataFlavor | Registered Clipformat | Registered accompany clipformat 197*cdf0e10cSrcweir // -------------------------|---------------------------|----------------------------------- 198*cdf0e10cSrcweir // text/plain;charset=ansi | CF_TEXT | CF_UNICODETEXT 199*cdf0e10cSrcweir // | | CF_LOCALE (if charset != GetACP() 200*cdf0e10cSrcweir // | | 201*cdf0e10cSrcweir // text/plain;charset=oem | CF_OEMTEXT | CF_UNICODETEXT 202*cdf0e10cSrcweir // | | CF_LOCALE (if charset != GetOEMCP() 203*cdf0e10cSrcweir // | | 204*cdf0e10cSrcweir // text/plain;charset=utf-16| CF_UNICODETEXT | CF_TEXT 205*cdf0e10cSrcweir // | | 206*cdf0e10cSrcweir // text/html | HTML (Hypertext ...) | HTML Format 207*cdf0e10cSrcweir // | | 208*cdf0e10cSrcweir // 209*cdf0e10cSrcweir // if some tries to register different text formats with different charsets the last 210*cdf0e10cSrcweir // registered wins and the others are ignored 211*cdf0e10cSrcweir // ---------------------------------------------------------------------------------------- 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir void SAL_CALL CFormatRegistrar::RegisterFormats( 214*cdf0e10cSrcweir const Reference< XTransferable >& aXTransferable, CFormatEtcContainer& aFormatEtcContainer ) 215*cdf0e10cSrcweir { 216*cdf0e10cSrcweir Sequence< DataFlavor > aFlavorList = aXTransferable->getTransferDataFlavors( ); 217*cdf0e10cSrcweir sal_Int32 nFlavors = aFlavorList.getLength( ); 218*cdf0e10cSrcweir sal_Bool bUnicodeRegistered = sal_False; 219*cdf0e10cSrcweir DataFlavor aFlavor; 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir for( sal_Int32 i = 0; i < nFlavors; i++ ) 222*cdf0e10cSrcweir { 223*cdf0e10cSrcweir aFlavor = aFlavorList[i]; 224*cdf0e10cSrcweir CFormatEtc fetc = m_DataFormatTranslator.getFormatEtcFromDataFlavor( aFlavor ); 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir // maybe an internal format so we ignore it 227*cdf0e10cSrcweir if ( CF_INVALID == fetc.getClipformat( ) ) 228*cdf0e10cSrcweir continue; 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir if ( !needsToSynthesizeAccompanyFormats( fetc ) ) 231*cdf0e10cSrcweir aFormatEtcContainer.addFormatEtc( fetc ); 232*cdf0e10cSrcweir else 233*cdf0e10cSrcweir { 234*cdf0e10cSrcweir // if we haven't registered any text format up to now 235*cdf0e10cSrcweir if ( m_DataFormatTranslator.isTextFormat( fetc.getClipformat() ) && !bUnicodeRegistered ) 236*cdf0e10cSrcweir { 237*cdf0e10cSrcweir // if the transferable supports unicode text we ignore 238*cdf0e10cSrcweir // any further text format the transferable offers 239*cdf0e10cSrcweir // because we can create it from Unicode text in addition 240*cdf0e10cSrcweir // we register CF_TEXT for non unicode clients 241*cdf0e10cSrcweir if ( m_DataFormatTranslator.isUnicodeTextFormat( fetc.getClipformat() ) ) 242*cdf0e10cSrcweir { 243*cdf0e10cSrcweir aFormatEtcContainer.addFormatEtc( fetc ); // add CF_UNICODE 244*cdf0e10cSrcweir aFormatEtcContainer.addFormatEtc( 245*cdf0e10cSrcweir m_DataFormatTranslator.getFormatEtcForClipformat( CF_TEXT ) ); // add CF_TEXT 246*cdf0e10cSrcweir bUnicodeRegistered = sal_True; 247*cdf0e10cSrcweir } 248*cdf0e10cSrcweir else if ( !hasUnicodeFlavor( aXTransferable ) ) 249*cdf0e10cSrcweir { 250*cdf0e10cSrcweir // we try to investigate the charset and make a valid 251*cdf0e10cSrcweir // windows codepage from this charset the default 252*cdf0e10cSrcweir // return value is the result of GetACP( ) 253*cdf0e10cSrcweir OUString charset = getCharsetFromDataFlavor( aFlavor ); 254*cdf0e10cSrcweir sal_uInt32 txtCP = getWinCPFromMimeCharset( charset ); 255*cdf0e10cSrcweir 256*cdf0e10cSrcweir // we try to get a Locale appropriate for this codepage 257*cdf0e10cSrcweir if ( findLocaleForTextCodePage( ) ) 258*cdf0e10cSrcweir { 259*cdf0e10cSrcweir m_TxtCodePage = txtCP; 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir aFormatEtcContainer.addFormatEtc( 262*cdf0e10cSrcweir m_DataFormatTranslator.getFormatEtcForClipformat( CF_UNICODETEXT ) ); 263*cdf0e10cSrcweir 264*cdf0e10cSrcweir if ( !IsOEMCP( m_TxtCodePage ) ) 265*cdf0e10cSrcweir aFormatEtcContainer.addFormatEtc( 266*cdf0e10cSrcweir m_DataFormatTranslator.getFormatEtcForClipformat( CF_TEXT ) ); 267*cdf0e10cSrcweir else 268*cdf0e10cSrcweir aFormatEtcContainer.addFormatEtc( 269*cdf0e10cSrcweir m_DataFormatTranslator.getFormatEtcForClipformat( CF_OEMTEXT ) ); 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir aFormatEtcContainer.addFormatEtc( 272*cdf0e10cSrcweir m_DataFormatTranslator.getFormatEtcForClipformat( CF_LOCALE ) ); 273*cdf0e10cSrcweir 274*cdf0e10cSrcweir // we save the flavor so it's easier when 275*cdf0e10cSrcweir // queried for it in XTDataObject::GetData(...) 276*cdf0e10cSrcweir m_RegisteredTextFlavor = aFlavor; 277*cdf0e10cSrcweir m_bHasSynthesizedLocale = sal_True; 278*cdf0e10cSrcweir } 279*cdf0e10cSrcweir } 280*cdf0e10cSrcweir } 281*cdf0e10cSrcweir else if ( m_DataFormatTranslator.isTextHtmlFormat( fetc.getClipformat( ) ) ) // Html (Hyper Text...) 282*cdf0e10cSrcweir { 283*cdf0e10cSrcweir // we add text/html ( HTML (HyperText Markup Language) ) 284*cdf0e10cSrcweir aFormatEtcContainer.addFormatEtc( fetc ); 285*cdf0e10cSrcweir 286*cdf0e10cSrcweir // and HTML Format 287*cdf0e10cSrcweir OUString htmlFormat( OUString::createFromAscii( "HTML Format" ) ); 288*cdf0e10cSrcweir aFormatEtcContainer.addFormatEtc( 289*cdf0e10cSrcweir m_DataFormatTranslator.getFormatEtcForClipformatName( htmlFormat ) ); 290*cdf0e10cSrcweir } 291*cdf0e10cSrcweir } 292*cdf0e10cSrcweir } 293*cdf0e10cSrcweir } 294*cdf0e10cSrcweir 295*cdf0e10cSrcweir //------------------------------------------------------------------------ 296*cdf0e10cSrcweir // 297*cdf0e10cSrcweir //------------------------------------------------------------------------ 298*cdf0e10cSrcweir 299*cdf0e10cSrcweir sal_Bool SAL_CALL CFormatRegistrar::hasSynthesizedLocale( ) const 300*cdf0e10cSrcweir { 301*cdf0e10cSrcweir return m_bHasSynthesizedLocale; 302*cdf0e10cSrcweir } 303*cdf0e10cSrcweir 304*cdf0e10cSrcweir //------------------------------------------------------------------------ 305*cdf0e10cSrcweir // 306*cdf0e10cSrcweir //------------------------------------------------------------------------ 307*cdf0e10cSrcweir 308*cdf0e10cSrcweir LCID SAL_CALL CFormatRegistrar::getSynthesizedLocale( ) const 309*cdf0e10cSrcweir { 310*cdf0e10cSrcweir return m_TxtLocale; 311*cdf0e10cSrcweir } 312*cdf0e10cSrcweir 313*cdf0e10cSrcweir //------------------------------------------------------------------------ 314*cdf0e10cSrcweir // 315*cdf0e10cSrcweir //------------------------------------------------------------------------ 316*cdf0e10cSrcweir 317*cdf0e10cSrcweir sal_uInt32 SAL_CALL CFormatRegistrar::getRegisteredTextCodePage( ) const 318*cdf0e10cSrcweir { 319*cdf0e10cSrcweir return m_TxtCodePage; 320*cdf0e10cSrcweir } 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir //------------------------------------------------------------------------ 323*cdf0e10cSrcweir // 324*cdf0e10cSrcweir //------------------------------------------------------------------------ 325*cdf0e10cSrcweir 326*cdf0e10cSrcweir DataFlavor SAL_CALL CFormatRegistrar::getRegisteredTextFlavor( ) const 327*cdf0e10cSrcweir { 328*cdf0e10cSrcweir return m_RegisteredTextFlavor; 329*cdf0e10cSrcweir } 330*cdf0e10cSrcweir 331*cdf0e10cSrcweir //------------------------------------------------------------------------ 332*cdf0e10cSrcweir // 333*cdf0e10cSrcweir //------------------------------------------------------------------------ 334*cdf0e10cSrcweir 335*cdf0e10cSrcweir sal_Bool SAL_CALL CFormatRegistrar::isSynthesizeableFormat( const CFormatEtc& aFormatEtc ) const 336*cdf0e10cSrcweir { 337*cdf0e10cSrcweir return ( m_DataFormatTranslator.isOemOrAnsiTextFormat( aFormatEtc.getClipformat() ) || 338*cdf0e10cSrcweir m_DataFormatTranslator.isUnicodeTextFormat( aFormatEtc.getClipformat() ) || 339*cdf0e10cSrcweir m_DataFormatTranslator.isHTMLFormat( aFormatEtc.getClipformat() ) ); 340*cdf0e10cSrcweir } 341*cdf0e10cSrcweir 342*cdf0e10cSrcweir //------------------------------------------------------------------------ 343*cdf0e10cSrcweir // 344*cdf0e10cSrcweir //------------------------------------------------------------------------ 345*cdf0e10cSrcweir 346*cdf0e10cSrcweir inline 347*cdf0e10cSrcweir sal_Bool SAL_CALL CFormatRegistrar::needsToSynthesizeAccompanyFormats( const CFormatEtc& aFormatEtc ) const 348*cdf0e10cSrcweir { 349*cdf0e10cSrcweir return ( m_DataFormatTranslator.isOemOrAnsiTextFormat( aFormatEtc.getClipformat() ) || 350*cdf0e10cSrcweir m_DataFormatTranslator.isUnicodeTextFormat( aFormatEtc.getClipformat() ) || 351*cdf0e10cSrcweir m_DataFormatTranslator.isTextHtmlFormat( aFormatEtc.getClipformat( ) ) ); 352*cdf0e10cSrcweir } 353*cdf0e10cSrcweir 354*cdf0e10cSrcweir //------------------------------------------------------------------------ 355*cdf0e10cSrcweir // 356*cdf0e10cSrcweir //------------------------------------------------------------------------ 357*cdf0e10cSrcweir 358*cdf0e10cSrcweir OUString SAL_CALL CFormatRegistrar::getCharsetFromDataFlavor( const DataFlavor& aFlavor ) 359*cdf0e10cSrcweir { 360*cdf0e10cSrcweir OUString charset; 361*cdf0e10cSrcweir 362*cdf0e10cSrcweir try 363*cdf0e10cSrcweir { 364*cdf0e10cSrcweir Reference< XMimeContentTypeFactory > xMimeFac( 365*cdf0e10cSrcweir m_SrvMgr->createInstance( OUString::createFromAscii( \ 366*cdf0e10cSrcweir "com.sun.star.datatransfer.MimeContentTypeFactory" ) ), UNO_QUERY ); 367*cdf0e10cSrcweir 368*cdf0e10cSrcweir if( xMimeFac.is( ) ) 369*cdf0e10cSrcweir { 370*cdf0e10cSrcweir Reference< XMimeContentType > xMimeType( xMimeFac->createMimeContentType( aFlavor.MimeType ) ); 371*cdf0e10cSrcweir if ( xMimeType->hasParameter( TEXTPLAIN_PARAM_CHARSET ) ) 372*cdf0e10cSrcweir charset = xMimeType->getParameterValue( TEXTPLAIN_PARAM_CHARSET ); 373*cdf0e10cSrcweir else 374*cdf0e10cSrcweir charset = getMimeCharsetFromWinCP( GetACP( ), PRE_WINDOWS_CODEPAGE ); 375*cdf0e10cSrcweir } 376*cdf0e10cSrcweir } 377*cdf0e10cSrcweir catch(NoSuchElementException&) 378*cdf0e10cSrcweir { 379*cdf0e10cSrcweir OSL_ENSURE( sal_False, "Unexpected" ); 380*cdf0e10cSrcweir } 381*cdf0e10cSrcweir catch(...) 382*cdf0e10cSrcweir { 383*cdf0e10cSrcweir OSL_ENSURE( sal_False, "Invalid data flavor" ); 384*cdf0e10cSrcweir } 385*cdf0e10cSrcweir 386*cdf0e10cSrcweir return charset; 387*cdf0e10cSrcweir } 388*cdf0e10cSrcweir 389*cdf0e10cSrcweir //------------------------------------------------------------------------ 390*cdf0e10cSrcweir // 391*cdf0e10cSrcweir //------------------------------------------------------------------------ 392*cdf0e10cSrcweir 393*cdf0e10cSrcweir sal_Bool SAL_CALL CFormatRegistrar::hasUnicodeFlavor( const Reference< XTransferable >& aXTransferable ) const 394*cdf0e10cSrcweir { 395*cdf0e10cSrcweir CFormatEtc fetc( CF_UNICODETEXT ); 396*cdf0e10cSrcweir 397*cdf0e10cSrcweir DataFlavor aFlavor = 398*cdf0e10cSrcweir m_DataFormatTranslator.getDataFlavorFromFormatEtc( fetc ); 399*cdf0e10cSrcweir 400*cdf0e10cSrcweir return aXTransferable->isDataFlavorSupported( aFlavor ); 401*cdf0e10cSrcweir } 402*cdf0e10cSrcweir 403*cdf0e10cSrcweir //------------------------------------------------------------------------ 404*cdf0e10cSrcweir // 405*cdf0e10cSrcweir //------------------------------------------------------------------------ 406*cdf0e10cSrcweir 407*cdf0e10cSrcweir inline 408*cdf0e10cSrcweir sal_Bool CFormatRegistrar::isEqualCurrentSystemCodePage( sal_uInt32 aCodePage ) const 409*cdf0e10cSrcweir { 410*cdf0e10cSrcweir return ( (aCodePage == GetOEMCP()) || (aCodePage == GetACP()) ); 411*cdf0e10cSrcweir } 412*cdf0e10cSrcweir 413*cdf0e10cSrcweir //------------------------------------------------------------------------ 414*cdf0e10cSrcweir // 415*cdf0e10cSrcweir //------------------------------------------------------------------------ 416*cdf0e10cSrcweir 417*cdf0e10cSrcweir sal_Bool SAL_CALL CFormatRegistrar::findLocaleForTextCodePage( ) 418*cdf0e10cSrcweir { 419*cdf0e10cSrcweir m_TxtLocale = 0; 420*cdf0e10cSrcweir EnumSystemLocalesA( CFormatRegistrar::EnumLocalesProc, LCID_INSTALLED ); 421*cdf0e10cSrcweir return ( IsValidLocale( m_TxtLocale, LCID_INSTALLED ) ) ? sal_True : sal_False; 422*cdf0e10cSrcweir } 423*cdf0e10cSrcweir 424*cdf0e10cSrcweir //------------------------------------------------------------------------ 425*cdf0e10cSrcweir // 426*cdf0e10cSrcweir //------------------------------------------------------------------------ 427*cdf0e10cSrcweir 428*cdf0e10cSrcweir sal_Bool SAL_CALL CFormatRegistrar::isLocaleCodePage( LCID lcid, LCTYPE lctype, sal_uInt32 codepage ) 429*cdf0e10cSrcweir { 430*cdf0e10cSrcweir char buff[6]; 431*cdf0e10cSrcweir sal_uInt32 localeCodePage; 432*cdf0e10cSrcweir 433*cdf0e10cSrcweir OSL_ASSERT( IsValidLocale( lcid, LCID_INSTALLED ) ); 434*cdf0e10cSrcweir 435*cdf0e10cSrcweir // get the ansi codepage of the current locale 436*cdf0e10cSrcweir GetLocaleInfoA( lcid, lctype, buff, sizeof( buff ) ); 437*cdf0e10cSrcweir localeCodePage = atol( buff ); 438*cdf0e10cSrcweir 439*cdf0e10cSrcweir return ( localeCodePage == codepage ); 440*cdf0e10cSrcweir } 441*cdf0e10cSrcweir 442*cdf0e10cSrcweir //------------------------------------------------------------------------ 443*cdf0e10cSrcweir // 444*cdf0e10cSrcweir //------------------------------------------------------------------------ 445*cdf0e10cSrcweir 446*cdf0e10cSrcweir inline 447*cdf0e10cSrcweir sal_Bool SAL_CALL CFormatRegistrar::isLocaleOemCodePage( LCID lcid, sal_uInt32 codepage ) 448*cdf0e10cSrcweir { 449*cdf0e10cSrcweir return isLocaleCodePage( lcid, LOCALE_IDEFAULTCODEPAGE, codepage ); 450*cdf0e10cSrcweir } 451*cdf0e10cSrcweir 452*cdf0e10cSrcweir //------------------------------------------------------------------------ 453*cdf0e10cSrcweir // 454*cdf0e10cSrcweir //------------------------------------------------------------------------ 455*cdf0e10cSrcweir 456*cdf0e10cSrcweir inline 457*cdf0e10cSrcweir sal_Bool SAL_CALL CFormatRegistrar::isLocaleAnsiCodePage( LCID lcid, sal_uInt32 codepage ) 458*cdf0e10cSrcweir { 459*cdf0e10cSrcweir return isLocaleCodePage( lcid, LOCALE_IDEFAULTANSICODEPAGE, codepage ); 460*cdf0e10cSrcweir } 461*cdf0e10cSrcweir 462*cdf0e10cSrcweir //------------------------------------------------------------------------ 463*cdf0e10cSrcweir // 464*cdf0e10cSrcweir //------------------------------------------------------------------------ 465*cdf0e10cSrcweir 466*cdf0e10cSrcweir BOOL CALLBACK CFormatRegistrar::EnumLocalesProc( LPSTR lpLocaleStr ) 467*cdf0e10cSrcweir { 468*cdf0e10cSrcweir // the lpLocaleStr parametere is hexadecimal 469*cdf0e10cSrcweir LCID lcid = strtol( lpLocaleStr, NULL, 16 ); 470*cdf0e10cSrcweir 471*cdf0e10cSrcweir if ( isLocaleAnsiCodePage( lcid, CFormatRegistrar::m_TxtCodePage ) || 472*cdf0e10cSrcweir isLocaleOemCodePage( lcid, CFormatRegistrar::m_TxtCodePage ) ) 473*cdf0e10cSrcweir { 474*cdf0e10cSrcweir CFormatRegistrar::m_TxtLocale = lcid; 475*cdf0e10cSrcweir return sal_False; // stop enumerating 476*cdf0e10cSrcweir } 477*cdf0e10cSrcweir 478*cdf0e10cSrcweir return sal_True; 479*cdf0e10cSrcweir } 480*cdf0e10cSrcweir 481