Mercurial > projects > dwt2
diff org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/internal/win32/OS.d @ 120:536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
===D2===
* added [Try]Immutable/Const/Shared templates to work with differenses in D1/D2 instead of version statements
used these templates to work with strict type storage rules of dmd-2.053
* com.ibm.icu now also compilable with D2, but not tested yet
* small fixes
Snippet288 - shared data is in TLS
===Phobos===
* fixed critical bugs in Phobos implemention
completely incorrect segfault prone fromStringz (Linux's port ruthless killer)
terrible, incorrect StringBuffer realization (StyledText killer)
* fixed small bugs as well
Snippet72 - misprint in the snippet
* implemented missed functionality for Phobos
ByteArrayOutputStream implemented (image loading available)
formatting correctly works for all DWT's cases
As a result, folowing snippets now works with Phobos (Snippet### - what is fixed):
Snippet24, 42, 111, 115, 130, 235, 276 - bad string formatting
Snippet48, 282 - crash on image loading
Snippet163, 189, 211, 213, 217, 218, 222 - crash on copy/cut in StyledText
Snippet244 - hang-up
===Tango===
* few changes for the latest Tango trunc-r5661
* few small performance improvments
===General===
* implMissing-s for only one version changed to implMissingInTango/InPhobos
* incorrect calls to Format in toString-s fixed
* fixed loading \uXXXX characters in ResourceBundle
* added good UTF-8 support for StyledText, TextLayout (Win32) and friends
UTF functions revised and tested. It is now in java.nonstandard.*Utf modules
StyledText and TextLayout (Win32) modules revised for UTF-8 support
* removed small diferences in most identical files in *.swt.* folders
*.swt.internal.image, *.swt.events and *.swt.custom are identical in Win32/Linux32
now 179 of 576 (~31%) files in *.swt.* folders are fully identical
* Win32: snippets now have right subsystem, pretty icons and native system style controls
* small fixes in snippets
Snippet44 - it's not Snippet44
Snippet212 - functions work with different images and offsets arrays
Win32: Snippet282 - crash on close if the button has an image
Snippet293 - setGrayed is commented
and others
Win32: As a result, folowing snippets now works
Snippet68 - color doesn't change
Snippet163, 189, 211, 213, 217, 218, 222 - UTF-8 issues (see above)
Snippet193 - no tabel headers
author | Denis Shelomovskij <verylonglogin.reg@gmail.com> |
---|---|
date | Sat, 09 Jul 2011 15:50:20 +0300 |
parents | 9f4c18c268b2 |
children |
line wrap: on
line diff
--- a/org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/internal/win32/OS.d Sun Apr 17 17:58:36 2011 +0200 +++ b/org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/internal/win32/OS.d Sat Jul 09 15:50:20 2011 +0300 @@ -21,15 +21,17 @@ import java.nonstandard.SharedLib; version(Tango){ -static import tango.sys.Common; + static import tango.sys.Common; -static import tango.stdc.stdlib; -static import tango.stdc.string; -import tango.sys.win32.CodePage : CodePage; -private import tango.stdc.stringz; - - + static import tango.stdc.stdlib; + static import tango.stdc.string; //for strlen + import tango.sys.win32.CodePage : CodePage; + private import tango.stdc.stringz; } else { // Phobos + static import core.stdc.string; //for strlen + static import std.windows.charset; //for toMBSz + static import std.c.windows.windows; //for GetLastError + static import std.windows.syserror; //for sysErrorString } alias org.eclipse.swt.internal.win32.WINAPI DWTWINAPI; @@ -387,7 +389,8 @@ char[2000] buf; getDwtLogger.error( __FILE__, __LINE__, "{}: {}", msg, CodePage.from( winMsg, buf ) ); } else { // Phobos - implMissing( __FILE__, __LINE__ ); + auto err = std.c.windows.windows.GetLastError(); + getDwtLogger.error( __FILE__, __LINE__, "{}: {}", msg, std.windows.syserror.sysErrorString(err) ); } } TCHAR[] buffer = new TCHAR[ MAX_PATH ]; @@ -3578,8 +3581,7 @@ version(Tango){ return tango.stdc.string.strlen( cast(char*)ptr ); } else { // Phobos - implMissing( __FILE__, __LINE__ ); - return 0; + return core.stdc.string.strlen( cast(char*)ptr ); } } @@ -3593,7 +3595,7 @@ //----------------------------------------------------------------------------- // convert UTF-8 to MBCS alias StrToMBCS StrToMBCSs; -public CHAR[] StrToMBCS(CString sc, uint codepage = 0) { +public CHAR[] StrToMBCS(in char[] sc, uint codepage = 0) { CHAR[] ret = cast(CHAR[]) sc; try{ foreach (char c; sc){ @@ -3616,8 +3618,7 @@ } // convert UTF-8 to MBCSz -public char* StrToMBCSz(CString sc) { - char* ret = null; +public TryConst!(char)* StrToMBCSz(in char[] sc) { version(Tango){ try{ if( CodePage.isAscii( sc )){ @@ -3628,19 +3629,18 @@ return toStringz( tango.sys.win32.CodePage.CodePage.into( sc, dst )); }catch(Exception e){ // do nothing - ret = ""; + return "".ptr; } } else { // Phobos - implMissing( __FILE__, __LINE__ ); + return std.windows.charset.toMBSz(sc); } - return ret; } -public String16 StrToWCHARs(uint codepage , CString sc, bool terminated = false ) { +public String16 StrToWCHARs(uint codepage , in char[] sc, bool terminated = false ) { return StrToWCHARs( sc, terminated ); } -public String16 StrToWCHARs(CString sc, bool terminated = false ) { +public String16 StrToWCHARs(in char[] sc, bool terminated = false ) { String16 ret; try{ ret = toWCharArray(sc); @@ -3654,19 +3654,19 @@ return ret; } -public LPCWSTR StrToWCHARz( uint codepage, CString sc, uint* length = null ) { +public LPCWSTR StrToWCHARz( uint codepage, in char[] sc, uint* length = null ) { return StrToWCHARz( sc, length ); } -public LPCWSTR StrToWCHARz(CString sc, uint* length = null ) { +public LPCWSTR StrToWCHARz(in char[] sc, uint* length = null ) { return StrToWCHARs(sc, true ).ptr; } -public CString MBCSsToStr(CHAR[] string, uint codepage = 0){ +public String MBCSsToStr(in CHAR[] string, uint codepage = 0){ return MBCSzToStr( string.ptr, string.length, codepage); } -public CString MBCSzToStr(PCHAR pString, int _length = -1, uint codepage = 0) { +public String MBCSzToStr(in PCHAR pString, int _length = -1, uint codepage = 0) { // null terminated string pointer if(_length == -1){ _length = 0; @@ -3678,19 +3678,19 @@ return null; String16 wcs = _mbcszToWs(pString, _length, codepage); - String result; - try{ - result = String_valueOf(wcs); - }catch(Exception e){ + + try { + return String_valueOf(wcs); + } catch { + return null; } - return result; } -public String WCHARsToStr(CString16 string){ +public String WCHARsToStr(in WCHAR[] string){ return WCHARzToStr(string.ptr, string.length); } -public String WCHARzToStr(LPCWSTR pString, int _length = -1) +public String WCHARzToStr(in LPCWSTR pString, int _length = -1) { if( pString is null ){ return null; @@ -3706,13 +3706,11 @@ // convert wchar* to UTF-8 auto wcs = pString[0.._length]; - String result; - try{ - result = String_valueOf(wcs); - }catch(Exception e){ - // do nothing + try { + return String_valueOf(wcs); + } catch { + return null; } - return result; } /** @@ -3726,7 +3724,7 @@ { // BSTR is aliased to wchar* // Note : Free the "bstr" memory if freeTheString is true, default false -static char[] BSTRToStr(/*BSTR*/ inout wchar* bstr, bool freeTheString = false){ +static char[] BSTRToStr(/*BSTR*/ ref wchar* bstr, bool freeTheString = false){ if(bstr is null) return null; int size = (SysStringByteLen(bstr) + 1)/wchar.sizeof; char[] result = WCHARzToStr(bstr, size); @@ -3740,7 +3738,7 @@ } // end of OLE_COM -public static String16 _mbcszToWs(PCHAR pMBCS, int len, uint codepage = 0) +public static String16 _mbcszToWs(in PCHAR pMBCS, int len, uint codepage = 0) { wchar[] wbuf; // Convert MBCS to unicode @@ -3759,26 +3757,6 @@ return _length; } -/** - * There is a bug in Phobos std.string.toupper() to lower() with - std.string.toupper() and std.string.tolower() give a wrong result when deal with a mixture of upper/lower English and Chinese characters. e.g. -char[] a = "AbCd中文eFgH"; -char[] b = std.string.toupper(a); -char[] c = std.string.tolower(a); -The length of a is 11, but the length of b,c is 18 now. - * - */ -public String tolower(char[] string) { - LPCTSTR ps = StrToTCHARz(string); - LPCTSTR ps2 = OS.CharLower(cast(LPTSTR)ps); - return TCHARzToStr(ps2); -} -public String toupper(char[] string) { - LPCTSTR ps = StrToTCHARz(string); - LPCTSTR ps2 = OS.CharUpper(cast(LPTSTR)ps); - return TCHARzToStr(ps2); -} - version(ANSI){ alias StrToMBCS StrToTCHARs; alias StrToMBCSz StrToTCHARz;