Mercurial > projects > dwt-win
comparison dwt/dnd/HTMLTransfer.d @ 213:36f5cb12e1a2
Update to SWT 3.4M7
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 17 May 2008 17:34:28 +0200 |
parents | ab60f3309436 |
children | e2affbeb686d |
comparison
equal
deleted
inserted
replaced
212:ab60f3309436 | 213:36f5cb12e1a2 |
---|---|
83 public void javaToNative (Object object, TransferData transferData){ | 83 public void javaToNative (Object object, TransferData transferData){ |
84 if (!checkHTML(object) || !isSupportedType(transferData)) { | 84 if (!checkHTML(object) || !isSupportedType(transferData)) { |
85 DND.error(DND.ERROR_INVALID_DATA); | 85 DND.error(DND.ERROR_INVALID_DATA); |
86 } | 86 } |
87 String string = ( cast(ArrayWrapperString)object ).array; | 87 String string = ( cast(ArrayWrapperString)object ).array; |
88 int codePage = OS.GetACP(); | 88 /* NOTE: CF_HTML uses UTF-8 encoding. */ |
89 int cchMultiByte = OS.WideCharToMultiByte(codePage, 0, StrToTCHARz(string), -1, null, 0, null, null); | 89 int cchMultiByte = OS.WideCharToMultiByte(OS.CP_UTF8, 0, StrToTCHARz(string), -1, null, 0, null, null); |
90 if (cchMultiByte is 0) { | 90 if (cchMultiByte is 0) { |
91 transferData.stgmedium = new STGMEDIUM(); | 91 transferData.stgmedium = new STGMEDIUM(); |
92 transferData.result = COM.DV_E_STGMEDIUM; | 92 transferData.result = COM.DV_E_STGMEDIUM; |
93 return; | 93 return; |
94 } | 94 } |
128 | 128 |
129 buffer.append(PREFIX); | 129 buffer.append(PREFIX); |
130 buffer.append(string); | 130 buffer.append(string); |
131 buffer.append(SUFFIX); | 131 buffer.append(SUFFIX); |
132 | 132 |
133 auto wstrz = StrToTCHARz(codePage,buffer.toString); | 133 auto wstrz = StrToTCHARz(OS.CP_UTF8,buffer.toString); |
134 cchMultiByte = OS.WideCharToMultiByte(codePage, 0, wstrz, -1, null, 0, null, null); | 134 cchMultiByte = OS.WideCharToMultiByte(OS.CP_UTF8, 0, wstrz, -1, null, 0, null, null); |
135 auto lpMultiByteStr = cast(char*) OS.GlobalAlloc(OS.GMEM_FIXED | OS.GMEM_ZEROINIT, cchMultiByte); | 135 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); |
137 transferData.stgmedium = new STGMEDIUM(); | 137 transferData.stgmedium = new STGMEDIUM(); |
138 transferData.stgmedium.tymed = COM.TYMED_HGLOBAL; | 138 transferData.stgmedium.tymed = COM.TYMED_HGLOBAL; |
139 transferData.stgmedium.unionField = lpMultiByteStr; | 139 transferData.stgmedium.unionField = lpMultiByteStr; |
140 transferData.stgmedium.pUnkForRelease = null; | 140 transferData.stgmedium.pUnkForRelease = null; |
141 transferData.result = COM.S_OK; | 141 transferData.result = COM.S_OK; |
166 | 166 |
167 try { | 167 try { |
168 auto lpMultiByteStr = cast(char*) OS.GlobalLock(hMem); | 168 auto lpMultiByteStr = cast(char*) OS.GlobalLock(hMem); |
169 if (lpMultiByteStr is null) return null; | 169 if (lpMultiByteStr is null) return null; |
170 try { | 170 try { |
171 int codePage = OS.GetACP(); | 171 /* NOTE: CF_HTML uses UTF-8 encoding. |
172 auto cchWideChar = OS.MultiByteToWideChar (codePage, OS.MB_PRECOMPOSED, lpMultiByteStr, -1, null, 0); | 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); | |
173 if (cchWideChar is 0) return null; | 175 if (cchWideChar is 0) return null; |
174 wchar[] lpWideCharStr = new wchar [cchWideChar - 1]; | 176 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); |
176 String string = WCHARzToStr(lpWideCharStr.ptr); | 178 String string = WCHARzToStr(lpWideCharStr.ptr); |
177 int fragmentStart = 0, fragmentEnd = 0; | 179 int fragmentStart = 0, fragmentEnd = 0; |
178 int start = string.indexOf(StartFragment) + StartFragment.length; | 180 int start = string.indexOf(StartFragment) + StartFragment.length; |
179 int end = start + 1; | 181 int end = start + 1; |
180 while (end < string.length) { | 182 while (end < string.length) { |
195 end++; | 197 end++; |
196 } catch (NumberFormatException e) { | 198 } catch (NumberFormatException e) { |
197 break; | 199 break; |
198 } | 200 } |
199 } | 201 } |
200 if (fragmentEnd <= fragmentStart || fragmentEnd > lpWideCharStr.length) return null; | 202 if (fragmentEnd <= fragmentStart || fragmentEnd > OS.strlen(lpMultiByteStr)) return null; |
201 /* TO DO: | 203 cchWideChar = OS.MultiByteToWideChar (OS.CP_UTF8, 0, lpMultiByteStr+fragmentStart, fragmentEnd - fragmentStart, lpWideCharStr.ptr, lpWideCharStr.length); |
202 * FragmentStart and FragmentEnd are offsets in original byte stream, not | 204 if (cchWideChar is 0) return null; |
203 * the wide char version of the byte stream. | 205 String s = TCHARsToStr( lpWideCharStr[ 0 .. cchWideChar ] ); |
204 */ | |
205 String s = string.substring(fragmentStart, fragmentEnd); | |
206 /* | 206 /* |
207 * Firefox includes <!--StartFragment --> in the fragment, so remove it. | 207 * Firefox includes <!--StartFragment --> in the fragment, so remove it. |
208 */ | 208 */ |
209 String foxStart = "<!--StartFragment -->\r\n"; //$NON-NLS-1$ | 209 String foxStart = "<!--StartFragment -->\r\n"; //$NON-NLS-1$ |
210 int prefix = s.indexOf(foxStart); | 210 int prefix = s.indexOf(foxStart); |