Show
Ignore:
Timestamp:
05/17/08 11:34:28 (8 months ago)
Author:
Frank Benoit <benoit@tionex.de>
branch:
default
Message:

Update to SWT 3.4M7

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • dwt/dnd/HTMLTransfer.d

    r212 r213  
    8686    } 
    8787    String string = ( cast(ArrayWrapperString)object ).array; 
    88     int codePage = OS.GetACP(); 
    89     int cchMultiByte = OS.WideCharToMultiByte(codePage, 0, StrToTCHARz(string), -1, null, 0, null, null); 
     88    /* NOTE: CF_HTML uses UTF-8 encoding. */ 
     89    int cchMultiByte = OS.WideCharToMultiByte(OS.CP_UTF8, 0, StrToTCHARz(string), -1, null, 0, null, null); 
    9090    if (cchMultiByte is 0) { 
    9191        transferData.stgmedium = new STGMEDIUM(); 
     
    131131    buffer.append(SUFFIX); 
    132132 
    133     auto wstrz = StrToTCHARz(codePage,buffer.toString); 
    134     cchMultiByte = OS.WideCharToMultiByte(codePage, 0, wstrz, -1, null, 0, null, null); 
     133    auto wstrz = StrToTCHARz(OS.CP_UTF8,buffer.toString); 
     134    cchMultiByte = OS.WideCharToMultiByte(OS.CP_UTF8, 0, wstrz, -1, null, 0, null, null); 
    135135    auto lpMultiByteStr = cast(char*) OS.GlobalAlloc(OS.GMEM_FIXED | OS.GMEM_ZEROINIT, cchMultiByte); 
    136     OS.WideCharToMultiByte(codePage, 0, wstrz, -1, lpMultiByteStr, cchMultiByte, null, null); 
     136    OS.WideCharToMultiByte(OS.CP_UTF8, 0, wstrz, -1, lpMultiByteStr, cchMultiByte, null, null); 
    137137    transferData.stgmedium = new STGMEDIUM(); 
    138138    transferData.stgmedium.tymed = COM.TYMED_HGLOBAL; 
     
    169169        if (lpMultiByteStr is null) return null; 
    170170        try { 
    171             int codePage = OS.GetACP(); 
    172             auto cchWideChar  = OS.MultiByteToWideChar (codePage, OS.MB_PRECOMPOSED, lpMultiByteStr, -1, null, 0); 
     171            /* NOTE: CF_HTML uses UTF-8 encoding. 
     172             * The MSDN documentation for MultiByteToWideChar states that dwFlags must be set to 0 for UTF-8. 
     173             * Otherwise, the function fails with ERROR_INVALID_FLAGS. */ 
     174            auto cchWideChar  = OS.MultiByteToWideChar (OS.CP_UTF8, 0, lpMultiByteStr, -1, null, 0); 
    173175            if (cchWideChar is 0) return null; 
    174176            wchar[] lpWideCharStr = new wchar [cchWideChar - 1]; 
    175             OS.MultiByteToWideChar (codePage, OS.MB_PRECOMPOSED, lpMultiByteStr, -1, lpWideCharStr.ptr, lpWideCharStr.length); 
     177            OS.MultiByteToWideChar (OS.CP_UTF8, 0, lpMultiByteStr, -1, lpWideCharStr.ptr, lpWideCharStr.length); 
    176178            String string = WCHARzToStr(lpWideCharStr.ptr); 
    177179            int fragmentStart = 0, fragmentEnd = 0; 
     
    198200                } 
    199201            } 
    200             if (fragmentEnd <= fragmentStart || fragmentEnd > lpWideCharStr.length) return null; 
    201             /* TO DO: 
    202              * FragmentStart and FragmentEnd are offsets in original byte stream, not 
    203              * the wide char version of the byte stream. 
    204              */ 
    205             String s = string.substring(fragmentStart, fragmentEnd); 
     202            if (fragmentEnd <= fragmentStart || fragmentEnd > OS.strlen(lpMultiByteStr)) return null; 
     203            cchWideChar = OS.MultiByteToWideChar (OS.CP_UTF8, 0, lpMultiByteStr+fragmentStart, fragmentEnd - fragmentStart, lpWideCharStr.ptr, lpWideCharStr.length); 
     204            if (cchWideChar is 0) return null; 
     205            String s = TCHARsToStr( lpWideCharStr[ 0 .. cchWideChar ] ); 
    206206            /* 
    207207             * Firefox includes <!--StartFragment --> in the fragment, so remove it.