Mercurial > projects > dwt2
comparison 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 |
comparison
equal
deleted
inserted
replaced
119:d00e8db0a568 | 120:536e43f63c81 |
---|---|
19 import org.eclipse.swt.internal.Library; | 19 import org.eclipse.swt.internal.Library; |
20 import java.lang.all; | 20 import java.lang.all; |
21 import java.nonstandard.SharedLib; | 21 import java.nonstandard.SharedLib; |
22 | 22 |
23 version(Tango){ | 23 version(Tango){ |
24 static import tango.sys.Common; | 24 static import tango.sys.Common; |
25 | 25 |
26 static import tango.stdc.stdlib; | 26 static import tango.stdc.stdlib; |
27 static import tango.stdc.string; | 27 static import tango.stdc.string; //for strlen |
28 import tango.sys.win32.CodePage : CodePage; | 28 import tango.sys.win32.CodePage : CodePage; |
29 private import tango.stdc.stringz; | 29 private import tango.stdc.stringz; |
30 | |
31 | |
32 } else { // Phobos | 30 } else { // Phobos |
31 static import core.stdc.string; //for strlen | |
32 static import std.windows.charset; //for toMBSz | |
33 static import std.c.windows.windows; //for GetLastError | |
34 static import std.windows.syserror; //for sysErrorString | |
33 } | 35 } |
34 | 36 |
35 alias org.eclipse.swt.internal.win32.WINAPI DWTWINAPI; | 37 alias org.eclipse.swt.internal.win32.WINAPI DWTWINAPI; |
36 | 38 |
37 void trace(int line ){ | 39 void trace(int line ){ |
385 version(Tango){ | 387 version(Tango){ |
386 char[] winMsg = tango.sys.Common.SysError.lastMsg(); | 388 char[] winMsg = tango.sys.Common.SysError.lastMsg(); |
387 char[2000] buf; | 389 char[2000] buf; |
388 getDwtLogger.error( __FILE__, __LINE__, "{}: {}", msg, CodePage.from( winMsg, buf ) ); | 390 getDwtLogger.error( __FILE__, __LINE__, "{}: {}", msg, CodePage.from( winMsg, buf ) ); |
389 } else { // Phobos | 391 } else { // Phobos |
390 implMissing( __FILE__, __LINE__ ); | 392 auto err = std.c.windows.windows.GetLastError(); |
393 getDwtLogger.error( __FILE__, __LINE__, "{}: {}", msg, std.windows.syserror.sysErrorString(err) ); | |
391 } | 394 } |
392 } | 395 } |
393 TCHAR[] buffer = new TCHAR[ MAX_PATH ]; | 396 TCHAR[] buffer = new TCHAR[ MAX_PATH ]; |
394 buffer[] = 0; | 397 buffer[] = 0; |
395 HANDLE hModule = OS.GetLibraryHandle (); | 398 HANDLE hModule = OS.GetLibraryHandle (); |
3576 } | 3579 } |
3577 static int strlen( PCHAR ptr ){ | 3580 static int strlen( PCHAR ptr ){ |
3578 version(Tango){ | 3581 version(Tango){ |
3579 return tango.stdc.string.strlen( cast(char*)ptr ); | 3582 return tango.stdc.string.strlen( cast(char*)ptr ); |
3580 } else { // Phobos | 3583 } else { // Phobos |
3581 implMissing( __FILE__, __LINE__ ); | 3584 return core.stdc.string.strlen( cast(char*)ptr ); |
3582 return 0; | |
3583 } | 3585 } |
3584 } | 3586 } |
3585 | 3587 |
3586 static void POINTSTOPOINT( ref POINT pt, int pts) { | 3588 static void POINTSTOPOINT( ref POINT pt, int pts) { |
3587 pt.x = cast(SHORT) LOWORD(pts); | 3589 pt.x = cast(SHORT) LOWORD(pts); |
3591 alias DWTWINAPI.GetScrollBarInfo GetScrollBarInfo; | 3593 alias DWTWINAPI.GetScrollBarInfo GetScrollBarInfo; |
3592 } // END of OS | 3594 } // END of OS |
3593 //----------------------------------------------------------------------------- | 3595 //----------------------------------------------------------------------------- |
3594 // convert UTF-8 to MBCS | 3596 // convert UTF-8 to MBCS |
3595 alias StrToMBCS StrToMBCSs; | 3597 alias StrToMBCS StrToMBCSs; |
3596 public CHAR[] StrToMBCS(CString sc, uint codepage = 0) { | 3598 public CHAR[] StrToMBCS(in char[] sc, uint codepage = 0) { |
3597 CHAR[] ret = cast(CHAR[]) sc; | 3599 CHAR[] ret = cast(CHAR[]) sc; |
3598 try{ | 3600 try{ |
3599 foreach (char c; sc){ | 3601 foreach (char c; sc){ |
3600 if (c >= 0x80) | 3602 if (c >= 0x80) |
3601 { | 3603 { |
3614 } | 3616 } |
3615 return ret; | 3617 return ret; |
3616 } | 3618 } |
3617 | 3619 |
3618 // convert UTF-8 to MBCSz | 3620 // convert UTF-8 to MBCSz |
3619 public char* StrToMBCSz(CString sc) { | 3621 public TryConst!(char)* StrToMBCSz(in char[] sc) { |
3620 char* ret = null; | |
3621 version(Tango){ | 3622 version(Tango){ |
3622 try{ | 3623 try{ |
3623 if( CodePage.isAscii( sc )){ | 3624 if( CodePage.isAscii( sc )){ |
3624 return .toStringz( sc ); | 3625 return .toStringz( sc ); |
3625 } | 3626 } |
3626 char[] dst; | 3627 char[] dst; |
3627 dst.length = sc.length; | 3628 dst.length = sc.length; |
3628 return toStringz( tango.sys.win32.CodePage.CodePage.into( sc, dst )); | 3629 return toStringz( tango.sys.win32.CodePage.CodePage.into( sc, dst )); |
3629 }catch(Exception e){ | 3630 }catch(Exception e){ |
3630 // do nothing | 3631 // do nothing |
3631 ret = ""; | 3632 return "".ptr; |
3632 } | 3633 } |
3633 | 3634 |
3634 } else { // Phobos | 3635 } else { // Phobos |
3635 implMissing( __FILE__, __LINE__ ); | 3636 return std.windows.charset.toMBSz(sc); |
3636 } | 3637 } |
3637 return ret; | 3638 } |
3638 } | 3639 |
3639 | 3640 public String16 StrToWCHARs(uint codepage , in char[] sc, bool terminated = false ) { |
3640 public String16 StrToWCHARs(uint codepage , CString sc, bool terminated = false ) { | |
3641 return StrToWCHARs( sc, terminated ); | 3641 return StrToWCHARs( sc, terminated ); |
3642 } | 3642 } |
3643 public String16 StrToWCHARs(CString sc, bool terminated = false ) { | 3643 public String16 StrToWCHARs(in char[] sc, bool terminated = false ) { |
3644 String16 ret; | 3644 String16 ret; |
3645 try{ | 3645 try{ |
3646 ret = toWCharArray(sc); | 3646 ret = toWCharArray(sc); |
3647 }catch(Exception e){ | 3647 }catch(Exception e){ |
3648 // do nothing | 3648 // do nothing |
3652 ret ~= "\0"; | 3652 ret ~= "\0"; |
3653 } | 3653 } |
3654 return ret; | 3654 return ret; |
3655 } | 3655 } |
3656 | 3656 |
3657 public LPCWSTR StrToWCHARz( uint codepage, CString sc, uint* length = null ) { | 3657 public LPCWSTR StrToWCHARz( uint codepage, in char[] sc, uint* length = null ) { |
3658 return StrToWCHARz( sc, length ); | 3658 return StrToWCHARz( sc, length ); |
3659 } | 3659 } |
3660 | 3660 |
3661 public LPCWSTR StrToWCHARz(CString sc, uint* length = null ) { | 3661 public LPCWSTR StrToWCHARz(in char[] sc, uint* length = null ) { |
3662 return StrToWCHARs(sc, true ).ptr; | 3662 return StrToWCHARs(sc, true ).ptr; |
3663 } | 3663 } |
3664 | 3664 |
3665 public CString MBCSsToStr(CHAR[] string, uint codepage = 0){ | 3665 public String MBCSsToStr(in CHAR[] string, uint codepage = 0){ |
3666 return MBCSzToStr( string.ptr, string.length, codepage); | 3666 return MBCSzToStr( string.ptr, string.length, codepage); |
3667 } | 3667 } |
3668 | 3668 |
3669 public CString MBCSzToStr(PCHAR pString, int _length = -1, uint codepage = 0) { | 3669 public String MBCSzToStr(in PCHAR pString, int _length = -1, uint codepage = 0) { |
3670 // null terminated string pointer | 3670 // null terminated string pointer |
3671 if(_length == -1){ | 3671 if(_length == -1){ |
3672 _length = 0; | 3672 _length = 0; |
3673 while(*(pString + _length)) | 3673 while(*(pString + _length)) |
3674 ++_length; | 3674 ++_length; |
3676 // convert MBCS to UTF-8 | 3676 // convert MBCS to UTF-8 |
3677 if(_length == 0) | 3677 if(_length == 0) |
3678 return null; | 3678 return null; |
3679 | 3679 |
3680 String16 wcs = _mbcszToWs(pString, _length, codepage); | 3680 String16 wcs = _mbcszToWs(pString, _length, codepage); |
3681 String result; | 3681 |
3682 try{ | 3682 try { |
3683 result = String_valueOf(wcs); | 3683 return String_valueOf(wcs); |
3684 }catch(Exception e){ | 3684 } catch { |
3685 return null; | |
3685 } | 3686 } |
3686 return result; | 3687 } |
3687 } | 3688 |
3688 | 3689 public String WCHARsToStr(in WCHAR[] string){ |
3689 public String WCHARsToStr(CString16 string){ | |
3690 return WCHARzToStr(string.ptr, string.length); | 3690 return WCHARzToStr(string.ptr, string.length); |
3691 } | 3691 } |
3692 | 3692 |
3693 public String WCHARzToStr(LPCWSTR pString, int _length = -1) | 3693 public String WCHARzToStr(in LPCWSTR pString, int _length = -1) |
3694 { | 3694 { |
3695 if( pString is null ){ | 3695 if( pString is null ){ |
3696 return null; | 3696 return null; |
3697 } | 3697 } |
3698 // null terminated string pointer | 3698 // null terminated string pointer |
3704 if(_length == 0) | 3704 if(_length == 0) |
3705 return null; | 3705 return null; |
3706 // convert wchar* to UTF-8 | 3706 // convert wchar* to UTF-8 |
3707 auto wcs = pString[0.._length]; | 3707 auto wcs = pString[0.._length]; |
3708 | 3708 |
3709 String result; | 3709 try { |
3710 try{ | 3710 return String_valueOf(wcs); |
3711 result = String_valueOf(wcs); | 3711 } catch { |
3712 }catch(Exception e){ | 3712 return null; |
3713 // do nothing | |
3714 } | 3713 } |
3715 return result; | |
3716 } | 3714 } |
3717 | 3715 |
3718 /** | 3716 /** |
3719 * <Shawn> difference between WCHARzToStr(pwstr, -1) : | 3717 * <Shawn> difference between WCHARzToStr(pwstr, -1) : |
3720 * BSTRToStr() internally call WCHARzToStr(pwstr, length) with length set, | 3718 * BSTRToStr() internally call WCHARzToStr(pwstr, length) with length set, |
3724 | 3722 |
3725 version(OLE_COM) | 3723 version(OLE_COM) |
3726 { | 3724 { |
3727 // BSTR is aliased to wchar* | 3725 // BSTR is aliased to wchar* |
3728 // Note : Free the "bstr" memory if freeTheString is true, default false | 3726 // Note : Free the "bstr" memory if freeTheString is true, default false |
3729 static char[] BSTRToStr(/*BSTR*/ inout wchar* bstr, bool freeTheString = false){ | 3727 static char[] BSTRToStr(/*BSTR*/ ref wchar* bstr, bool freeTheString = false){ |
3730 if(bstr is null) return null; | 3728 if(bstr is null) return null; |
3731 int size = (SysStringByteLen(bstr) + 1)/wchar.sizeof; | 3729 int size = (SysStringByteLen(bstr) + 1)/wchar.sizeof; |
3732 char[] result = WCHARzToStr(bstr, size); | 3730 char[] result = WCHARzToStr(bstr, size); |
3733 if(freeTheString) { | 3731 if(freeTheString) { |
3734 // free the string and set ptr to null | 3732 // free the string and set ptr to null |
3738 return result; | 3736 return result; |
3739 } | 3737 } |
3740 } // end of OLE_COM | 3738 } // end of OLE_COM |
3741 | 3739 |
3742 | 3740 |
3743 public static String16 _mbcszToWs(PCHAR pMBCS, int len, uint codepage = 0) | 3741 public static String16 _mbcszToWs(in PCHAR pMBCS, int len, uint codepage = 0) |
3744 { | 3742 { |
3745 wchar[] wbuf; | 3743 wchar[] wbuf; |
3746 // Convert MBCS to unicode | 3744 // Convert MBCS to unicode |
3747 wbuf.length = OS.MultiByteToWideChar(codepage, 0, pMBCS, len, null, 0); | 3745 wbuf.length = OS.MultiByteToWideChar(codepage, 0, pMBCS, len, null, 0); |
3748 int n = OS.MultiByteToWideChar(codepage, 0, pMBCS, len, wbuf.ptr, wbuf.length); | 3746 int n = OS.MultiByteToWideChar(codepage, 0, pMBCS, len, wbuf.ptr, wbuf.length); |
3755 int _length = 0; | 3753 int _length = 0; |
3756 while(*(pString + _length)) | 3754 while(*(pString + _length)) |
3757 ++_length; | 3755 ++_length; |
3758 | 3756 |
3759 return _length; | 3757 return _length; |
3760 } | |
3761 | |
3762 /** | |
3763 * There is a bug in Phobos std.string.toupper() to lower() with | |
3764 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. | |
3765 char[] a = "AbCd中文eFgH"; | |
3766 char[] b = std.string.toupper(a); | |
3767 char[] c = std.string.tolower(a); | |
3768 The length of a is 11, but the length of b,c is 18 now. | |
3769 * | |
3770 */ | |
3771 public String tolower(char[] string) { | |
3772 LPCTSTR ps = StrToTCHARz(string); | |
3773 LPCTSTR ps2 = OS.CharLower(cast(LPTSTR)ps); | |
3774 return TCHARzToStr(ps2); | |
3775 } | |
3776 public String toupper(char[] string) { | |
3777 LPCTSTR ps = StrToTCHARz(string); | |
3778 LPCTSTR ps2 = OS.CharUpper(cast(LPTSTR)ps); | |
3779 return TCHARzToStr(ps2); | |
3780 } | 3758 } |
3781 | 3759 |
3782 version(ANSI){ | 3760 version(ANSI){ |
3783 alias StrToMBCS StrToTCHARs; | 3761 alias StrToMBCS StrToTCHARs; |
3784 alias StrToMBCSz StrToTCHARz; | 3762 alias StrToMBCSz StrToTCHARz; |