diff options
Diffstat (limited to 'dtrans')
-rw-r--r-- | dtrans/source/win32/dtobj/FetcList.cxx | 14 | ||||
-rw-r--r-- | dtrans/source/win32/misc/ImplHelper.cxx | 97 | ||||
-rw-r--r-- | dtrans/source/win32/misc/ImplHelper.hxx | 69 |
3 files changed, 115 insertions, 65 deletions
diff --git a/dtrans/source/win32/dtobj/FetcList.cxx b/dtrans/source/win32/dtobj/FetcList.cxx index c88551dd8519..9deaf947b032 100644 --- a/dtrans/source/win32/dtobj/FetcList.cxx +++ b/dtrans/source/win32/dtobj/FetcList.cxx @@ -2,9 +2,9 @@ * * $RCSfile: FetcList.cxx,v $ * - * $Revision: 1.5 $ + * $Revision: 1.6 $ * - * last change: $Author: tra $ $Date: 2001-03-06 12:25:42 $ + * last change: $Author: tra $ $Date: 2001-03-09 08:47:21 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -395,7 +395,7 @@ void SAL_CALL CFormatRegistrar::synthesizeAndRegisterAccompanyFormats( { OUString charset = getCharsetFromDataFlavor( aFlavor ); if ( charset.getLength( ) ) - m_TxtCodePage = getWinCodePageFromMimeCharset( charset ); + m_TxtCodePage = getWinCPFromMimeCharset( charset ); else m_TxtCodePage = GetACP( ); @@ -444,13 +444,15 @@ OUString SAL_CALL CFormatRegistrar::getCharsetFromDataFlavor( const DataFlavor& if( xMimeFac.is( ) ) { Reference< XMimeContentType > xMimeType( xMimeFac->createMimeContentType( aFlavor.MimeType ) ); - charset = xMimeType->getParameterValue( TEXTPLAIN_PARAM_CHARSET ); + if ( xMimeType->hasParameter( TEXTPLAIN_PARAM_CHARSET ) ) + charset = xMimeType->getParameterValue( TEXTPLAIN_PARAM_CHARSET ); + else + charset = getMimeCharsetFromWinCP( GetACP( ), PRE_WINDOWS_CODEPAGE ); } } catch(NoSuchElementException&) { - OSL_ENSURE( sal_False, "Text data flavor without charset not allowed" ); - charset = OUString::createFromAscii( "windows-1252" ); + OSL_ENSURE( sal_False, "Unexpected" ); } catch(...) { diff --git a/dtrans/source/win32/misc/ImplHelper.cxx b/dtrans/source/win32/misc/ImplHelper.cxx index 9f8bc8f10a69..ee8a427eb651 100644 --- a/dtrans/source/win32/misc/ImplHelper.cxx +++ b/dtrans/source/win32/misc/ImplHelper.cxx @@ -2,9 +2,9 @@ * * $RCSfile: ImplHelper.cxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: tra $ $Date: 2001-03-02 12:44:41 $ + * last change: $Author: tra $ $Date: 2001-03-09 08:48:25 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -101,47 +101,75 @@ using ::rtl::OUString; using ::rtl::OString; //------------------------------------------------------------------------ -// converts a codepage into its string representation +// returns a windows codepage appropriate to the +// given mime charset parameter value //------------------------------------------------------------------------ -OUString SAL_CALL CodePageToString( sal_Int32 codepage ) +sal_uInt32 SAL_CALL getWinCPFromMimeCharset( const OUString& charset ) { - OSL_ASSERT( IsValidCodePage( codepage ) ); + OString osCharset( charset.getStr( ), charset.getLength( ), CP_ACP ); - sal_Unicode cpStr[6]; - _itow( codepage, cpStr, 10 ); - return OUString( cpStr, wcslen( cpStr ) ); + rtl_TextEncoding textEnc = + rtl_getTextEncodingFromMimeCharset( osCharset.getStr( ) ); + + return rtl_getBestPCCodePageFromTextEncoding( textEnc ); } -//------------------------------------------------------------------------ -// convert a mime charset into a windows codepage -//------------------------------------------------------------------------ +//-------------------------------------------------- +// returns a windows codepage appropriate to the +// given locale and locale type +//-------------------------------------------------- -sal_Int32 SAL_CALL getWinCodePageFromMimeCharset( const OUString& charset ) +OUString SAL_CALL getWinCPFromLocaleId( LCID lcid, LCTYPE lctype ) { - OString osCharset( charset.getStr( ), charset.getLength( ), CP_ACP ); + OSL_ASSERT( IsValidLocale( lcid, LCID_SUPPORTED ) ); - rtl_TextEncoding textEnc = rtl_getTextEncodingFromMimeCharset( osCharset.getStr( ) ); - return rtl_getBestPCCodePageFromTextEncoding( textEnc ); + // we use the GetLocaleInfoA because don't want to provide + // a unicode wrapper function for Win9x in sal/systools + char buff[6]; + GetLocaleInfoA( lcid, lctype, buff, sizeof( buff ) ); + rtl_TextEncoding tenc = rtl_getTextEncodingFromPCCodePage( CP_ACP ); + + return OUString( buff, rtl_str_getLength( buff ), tenc ); +} + +//-------------------------------------------------- +// returns a mime charset parameter value appropriate +// to the given codepage, optional a prefix can be +// given, e.g. "windows-" or "cp" +//-------------------------------------------------- + +OUString SAL_CALL getMimeCharsetFromWinCP( sal_uInt32 cp, const OUString& aPrefix ) +{ + return aPrefix + cptostr( cp ); +} + +//-------------------------------------------------- +// returns a mime charset parameter value appropriate +// to the given locale id and locale type, optional a +// prefix can be given, e.g. "windows-" or "cp" +//-------------------------------------------------- + +OUString SAL_CALL getMimeCharsetFromLocaleId( LCID lcid, LCTYPE lctype, const OUString& aPrefix ) +{ + OUString charset = getWinCPFromLocaleId( lcid, lctype ); + return aPrefix + charset; } //------------------------------------------------------------------------ // IsOEMCP //------------------------------------------------------------------------ -sal_Bool SAL_CALL IsOEMCP( UINT codepage ) +sal_Bool SAL_CALL IsOEMCP( sal_uInt32 codepage ) { - UINT arrOEMCP[] = { 437, 708, 709, - 710, 720, 737, - 775, 850, 852, - 855, 857, 860, - 861, 862, 863, - 864, 865, 866, - 869, 874, 932, - 936, 949, 950, - 1361 }; - - for ( sal_Int8 i = 0; i < ( sizeof( arrOEMCP )/sizeof( UINT ) ); ++i ) + OSL_ASSERT( IsValidCodePage( codepage ) ); + + sal_uInt32 arrOEMCP[] = { 437, 708, 709, 710, 720, 737, + 775, 850, 852, 855, 857, 860, + 861, 862, 863, 864, 865, 866, + 869, 874, 932, 936, 949, 950, 1361 }; + + for ( sal_Int8 i = 0; i < ( sizeof( arrOEMCP )/sizeof( sal_uInt32 ) ); ++i ) if ( arrOEMCP[i] == codepage ) return sal_True; @@ -149,21 +177,18 @@ sal_Bool SAL_CALL IsOEMCP( UINT codepage ) } //------------------------------------------------------------------------ -// a '==' operator for DataFlavors -// we compare only MimeType and DataType +// converts a codepage into its string representation //------------------------------------------------------------------------ -sal_Bool SAL_CALL operator==( const DataFlavor& lhs, const DataFlavor& rhs ) +OUString SAL_CALL cptostr( sal_uInt32 codepage ) { -#pragma message( "******************************************" ) -#pragma message( "**************** fix this ****************" ) -#pragma message( "******************************************" ) + OSL_ASSERT( IsValidCodePage( codepage ) ); - return ( ( lhs.MimeType == rhs.MimeType ) && - ( lhs.DataType == rhs.DataType ) ); + sal_Unicode cpStr[6]; + _itow( codepage, cpStr, 10 ); + return OUString( cpStr, wcslen( cpStr ) ); } - //------------------------------------------------------------------------- // OleStdDeleteTargetDevice() // diff --git a/dtrans/source/win32/misc/ImplHelper.hxx b/dtrans/source/win32/misc/ImplHelper.hxx index 3db412af15b3..f3226eaed2ee 100644 --- a/dtrans/source/win32/misc/ImplHelper.hxx +++ b/dtrans/source/win32/misc/ImplHelper.hxx @@ -2,9 +2,9 @@ * * $RCSfile: ImplHelper.hxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: tra $ $Date: 2001-03-02 12:44:33 $ + * last change: $Author: tra $ $Date: 2001-03-09 08:48:25 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -77,21 +77,10 @@ #include <windows.h> - -//------------------------------------------------------------------------ -// const -//------------------------------------------------------------------------ - -//const sal_Bool SET_HUMANPRESENTABLE_NAME = sal_True; - //------------------------------------------------------------------------ // deklarations //------------------------------------------------------------------------ -#ifdef __cplusplus -extern "C" { -#endif - // target device and formatetc helper void SAL_CALL DeleteTargetDevice(DVTARGETDEVICE* ptd); sal_Bool SAL_CALL CopyFormatEtc(LPFORMATETC petcDest, LPFORMATETC petcSrc); @@ -99,18 +88,52 @@ sal_Int32 SAL_CALL CompareFormatEtc( const FORMATETC* pFetcLeft, const FORMATETC sal_Bool SAL_CALL CompareTargetDevice(DVTARGETDEVICE* ptdLeft, DVTARGETDEVICE* ptdRight); DVTARGETDEVICE* SAL_CALL CopyTargetDevice(DVTARGETDEVICE* ptdSrc); -#ifdef __cplusplus -} -#endif - // some codepage helper functions -sal_Int32 SAL_CALL getWinCodePageFromMimeCharset( const rtl::OUString& charset ); -UINT SAL_CALL GetWinCPFromMime( const rtl::OUString& mimeType ); -sal_Bool SAL_CALL IsOEMCP( UINT codepage ); -rtl::OUString SAL_CALL CodePageToString( sal_Int32 codepage ); +//-------------------------------------------------- +// returns a windows codepage appropriate to the +// given mime charset parameter value +//-------------------------------------------------- + +sal_uInt32 SAL_CALL getWinCPFromMimeCharset( + const rtl::OUString& charset ); + +//-------------------------------------------------- +// returns a windows codepage appropriate to the +// given locale and locale type +//-------------------------------------------------- + +rtl::OUString SAL_CALL getWinCPFromLocaleId( + LCID lcid, LCTYPE lctype ); + +//-------------------------------------------------- +// returns a mime charset parameter value appropriate +// to the given codepage, optional a prefix can be +// given, e.g. "windows-" or "cp" +//-------------------------------------------------- + +rtl::OUString SAL_CALL getMimeCharsetFromWinCP( + sal_uInt32 cp, const rtl::OUString& aPrefix ); + +//-------------------------------------------------- +// returns a mime charset parameter value appropriate +// to the given locale id and locale type, optional a +// prefix can be given, e.g. "windows-" or "cp" +//-------------------------------------------------- + +rtl::OUString SAL_CALL getMimeCharsetFromLocaleId( + LCID lcid, LCTYPE lctype, const rtl::OUString& aPrefix ); + +//----------------------------------------------------- +// returns true, if a given codepage is an oem codepage +//----------------------------------------------------- + +sal_Bool SAL_CALL IsOEMCP( sal_uInt32 codepage ); + +//-------------------------------------------------- +// converts a codepage into a string representation +//-------------------------------------------------- -sal_Bool SAL_CALL operator==( const ::com::sun::star::datatransfer::DataFlavor& lhs, - const ::com::sun::star::datatransfer::DataFlavor& rhs ); +rtl::OUString SAL_CALL cptostr( sal_uInt32 codepage ); #endif
\ No newline at end of file |