diff --git a/ChangeLog.txt b/ChangeLog.txt index f8ec6e2c46..62852b0621 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -10,6 +10,27 @@ * Change, ! Fix, % Optimization, + Addition, - Removal, ; Comment */ +2016-07-04 19:01 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) + * contrib/gtwvg/wvgcore.c + * contrib/gtwvg/wvgcuig.c + ! use HB_MIN() macro instead of non-standard min() function + ! use casting to double instead of float which may strip significant + bits from 32bit numbers + + * include/hbapicdp.h + + added hb_cdpGetID() macro + * formatting + + * src/rtl/hbjson.c + * modified codepage parameter behavior in JSON encode/decode functions. + Now they can be used for codepage translation. + + * src/rtl/gtwvt/gtwvt.c + * ignore national characters when WM_SYSCHAR message is generated. + It should resolve the problem with Greek keyboard layout reported + by Pete anyhow it's possible that it may create new problems with + some other keyboard layouts so please report them if any. + 2016-06-29 23:02 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * src/rdd/dbfcdx/dbfcdx1.c * src/rdd/dbffpt/dbffpt1.c diff --git a/contrib/gtwvg/wvgcore.c b/contrib/gtwvg/wvgcore.c index f0045b1584..1dfe0b444d 100644 --- a/contrib/gtwvg/wvgcore.c +++ b/contrib/gtwvg/wvgcore.c @@ -215,13 +215,15 @@ HB_BOOL hb_wvt_gtRenderPicture( int x, int y, int wd, int ht, IPicture * iPictur { if( lHeight > lWidth ) { - iWd = min( wd, ( int ) ( ( float ) ht * lWidth / lHeight ) ); - iHt = ( int ) ( ( float ) iWd * lHeight / lWidth ); + iWd = ( int ) ( ( double ) ht * lWidth / lHeight ); + iWd = HB_MIN( iWd, wd ); + iHt = ( int ) ( ( double ) iWd * lHeight / lWidth ); } else { - iHt = min( ht, ( int ) ( ( float ) wd * lHeight / lWidth ) ); - iWd = ( int ) ( ( float ) iHt * lWidth / lHeight ); + iHt = ( int ) ( ( double ) wd * lHeight / lWidth ); + iHt = HB_MIN( iHt, ht ); + iWd = ( int ) ( ( double ) iHt * lWidth / lHeight ); } x += abs( ( iWd - wd ) / 2 ); y += abs( ( iHt - ht ) / 2 ); @@ -545,13 +547,15 @@ HB_BOOL hb_wvt_DrawImage( HDC hdc, int x, int y, int wd, int ht, LPCTSTR lpImage { if( lHeight > lWidth ) { - iWd = min( wd, ( int ) ( ( float ) ht * lWidth / lHeight ) ); - iHt = ( int ) ( ( float ) iWd * lHeight / lWidth ); + iWd = ( int ) ( ( double ) ht * lWidth / lHeight ); + iWd = HB_MIN( iWd, wd ); + iHt = ( int ) ( ( double ) iWd * lHeight / lWidth ); } else { - iHt = min( ht, ( int ) ( ( float ) wd * lHeight / lWidth ) ); - iWd = ( int ) ( ( float ) iHt * lWidth / lHeight ); + iHt = ( int ) ( ( double ) wd * lHeight / lWidth ); + iHt = HB_MIN( iHt, ht ); + iWd = ( int ) ( ( double ) iHt * lWidth / lHeight ); } x += abs( ( iWd - wd ) / 2 ); y += abs( ( iHt - ht ) / 2 ); diff --git a/contrib/gtwvg/wvgcuig.c b/contrib/gtwvg/wvgcuig.c index 9e8a11555f..b62ae609d3 100644 --- a/contrib/gtwvg/wvgcuig.c +++ b/contrib/gtwvg/wvgcuig.c @@ -1533,13 +1533,15 @@ static void hb_wvg_RenderPicture( PHB_GTWVT pWVT, PHB_GOBJS gObj, int iLeft, int { if( lHeight > lWidth ) { - iWd = min( wd, ( int ) ( ( float ) ht * lWidth / lHeight ) ); - iHt = ( int ) ( ( float ) iWd * lHeight / lWidth ); + iWd = ( int ) ( ( double ) ht * lWidth / lHeight ); + iWd = HB_MIN( iWd, wd ); + iHt = ( int ) ( ( double ) iWd * lHeight / lWidth ); } else { - iHt = min( ht, ( int ) ( ( float ) wd * lHeight / lWidth ) ); - iWd = ( int ) ( ( float ) iHt * lWidth / lHeight ); + iHt = ( int ) ( ( double ) wd * lHeight / lWidth ); + iHt = HB_MIN( iHt, ht ); + iWd = ( int ) ( ( double ) iHt * lWidth / lHeight ); } x += abs( ( iWd - wd ) / 2 ); y += abs( ( iHt - ht ) / 2 ); diff --git a/include/hbapicdp.h b/include/hbapicdp.h index 2f278ab48d..70955f4940 100644 --- a/include/hbapicdp.h +++ b/include/hbapicdp.h @@ -402,15 +402,17 @@ extern HB_EXPORT void hb_vmSetCDP( PHB_CODEPAGE pCDP ); #define HB_MAX_CHAR_LEN 8 /* codepage uses simple binary sorting */ -#define HB_CDP_ISBINSORT(cdp) ( ( ( cdp )->type & HB_CDP_TYPE_BINSORT ) != 0 ) +#define HB_CDP_ISBINSORT( cdp ) ( ( ( cdp )->type & HB_CDP_TYPE_BINSORT ) != 0 ) /* codepage uses custom string decoding */ -#define HB_CDP_ISCUSTOM(cdp) ( ( ( cdp )->type & HB_CDP_TYPE_CUSTOM ) != 0 ) +#define HB_CDP_ISCUSTOM( cdp ) ( ( ( cdp )->type & HB_CDP_TYPE_CUSTOM ) != 0 ) /* codepage use character indexes instead of bytes ones */ -#define HB_CDP_ISCHARIDX(cdp) ( ( ( cdp )->type & HB_CDP_TYPE_CHARIDX ) != 0 ) +#define HB_CDP_ISCHARIDX( cdp ) ( ( ( cdp )->type & HB_CDP_TYPE_CHARIDX ) != 0 ) /* Chr(), Asc() and similar functions operates on Unicode values instead of bytes */ -#define HB_CDP_ISCHARUNI(cdp) ( ( ( cdp )->type & HB_CDP_TYPE_CHARUNI ) != 0 ) +#define HB_CDP_ISCHARUNI( cdp ) ( ( ( cdp )->type & HB_CDP_TYPE_CHARUNI ) != 0 ) /* codepage uses UTF-8 encoding */ -#define HB_CDP_ISUTF8(cdp) ( ( ( cdp )->type & HB_CDP_TYPE_UTF8 ) != 0 ) +#define HB_CDP_ISUTF8( cdp ) ( ( ( cdp )->type & HB_CDP_TYPE_UTF8 ) != 0 ) + +#define hb_cdpGetID( cdp ) ( ( cdp )->id ) extern HB_EXPORT HB_BOOL hb_cdpRegisterRaw( PHB_CODEPAGE cdp ); extern HB_EXPORT HB_BOOL hb_cdpRegisterNew( const char * id, diff --git a/src/rtl/gtwvt/gtwvt.c b/src/rtl/gtwvt/gtwvt.c index 343c67e2c4..72689e8151 100644 --- a/src/rtl/gtwvt/gtwvt.c +++ b/src/rtl/gtwvt/gtwvt.c @@ -2607,9 +2607,8 @@ static HB_BOOL hb_gt_wvt_KeyEvent( PHB_GTWVT pWVT, UINT message, WPARAM wParam, ( ( iFlags & HB_KF_ALTGR ) != 0 ) ) /* workaround for AltGR and German keyboard */ iFlags &= ~( HB_KF_CTRL | HB_KF_ALT | HB_KF_ALTGR ); - else - iFlags = hb_gt_wvt_UpdateKeyFlags( iFlags ); case WM_SYSCHAR: + iFlags = hb_gt_wvt_UpdateKeyFlags( iFlags ); if( ! pWVT->IgnoreWM_SYSCHAR ) { iKey = ( int ) wParam; @@ -2621,6 +2620,126 @@ static HB_BOOL hb_gt_wvt_KeyEvent( PHB_GTWVT pWVT, UINT message, WPARAM wParam, } else { + if( message == WM_SYSCHAR && ( iFlags & HB_KF_ALT ) != 0 ) + { + switch( HIWORD( lParam ) & 0xFF ) + { + case 2: + iKey = '1'; + break; + case 3: + iKey = '2'; + break; + case 4: + iKey = '3'; + break; + case 5: + iKey = '4'; + break; + case 6: + iKey = '5'; + break; + case 7: + iKey = '6'; + break; + case 8: + iKey = '7'; + break; + case 9: + iKey = '8'; + break; + case 10: + iKey = '9'; + break; + case 11: + iKey = '0'; + break; + case 13: + iKey = '='; + break; + case 14: + iKey = HB_KX_BS; + break; + case 16: + iKey = 'Q'; + break; + case 17: + iKey = 'W'; + break; + case 18: + iKey = 'E'; + break; + case 19: + iKey = 'R'; + break; + case 20: + iKey = 'T'; + break; + case 21: + iKey = 'Y'; + break; + case 22: + iKey = 'U'; + break; + case 23: + iKey = 'I'; + break; + case 24: + iKey = 'O'; + break; + case 25: + iKey = 'P'; + break; + case 30: + iKey = 'A'; + break; + case 31: + iKey = 'S'; + break; + case 32: + iKey = 'D'; + break; + case 33: + iKey = 'F'; + break; + case 34: + iKey = 'G'; + break; + case 35: + iKey = 'H'; + break; + case 36: + iKey = 'J'; + break; + case 37: + iKey = 'K'; + break; + case 38: + iKey = 'L'; + break; + case 44: + iKey = 'Z'; + break; + case 45: + iKey = 'X'; + break; + case 46: + iKey = 'C'; + break; + case 47: + iKey = 'V'; + break; + case 48: + iKey = 'B'; + break; + case 49: + iKey = 'N'; + break; + case 50: + iKey = 'M'; + break; + } + } #if defined( UNICODE ) if( iKey >= 127 ) iKey = HB_INKEY_NEW_UNICODEF( iKey, iFlags ); @@ -2629,16 +2748,18 @@ static HB_BOOL hb_gt_wvt_KeyEvent( PHB_GTWVT pWVT, UINT message, WPARAM wParam, else iKey = HB_INKEY_NEW_CHARF( iKey, iFlags ); #else - int u = HB_GTSELF_KEYTRANS( pWVT->pGT, iKey ); - if( u ) - iKey = HB_INKEY_NEW_UNICODEF( u, iFlags ); - else if( iKey < 127 && ( iFlags & ( HB_KF_CTRL | HB_KF_ALT ) ) ) - iKey = HB_INKEY_NEW_KEY( iKey, iFlags ); - else { - if( pWVT->CodePage == OEM_CHARSET ) - iKey = hb_gt_wvt_key_ansi_to_oem( iKey ); - iKey = HB_INKEY_NEW_CHARF( iKey, iFlags ); + int u = HB_GTSELF_KEYTRANS( pWVT->pGT, iKey ); + if( u ) + iKey = HB_INKEY_NEW_UNICODEF( u, iFlags ); + else if( iKey < 127 && ( iFlags & ( HB_KF_CTRL | HB_KF_ALT ) ) ) + iKey = HB_INKEY_NEW_KEY( iKey, iFlags ); + else + { + if( pWVT->CodePage == OEM_CHARSET ) + iKey = hb_gt_wvt_key_ansi_to_oem( iKey ); + iKey = HB_INKEY_NEW_CHARF( iKey, iFlags ); + } } #endif } diff --git a/src/rtl/hbjson.c b/src/rtl/hbjson.c index 5b43dda7eb..4ac843fba1 100644 --- a/src/rtl/hbjson.c +++ b/src/rtl/hbjson.c @@ -174,104 +174,69 @@ static void _hb_jsonEncode( PHB_ITEM pValue, PHB_JSON_ENCODE_CTX pCtx, if( HB_IS_STRING( pValue ) ) { - HB_SIZE nPos, nPos2, nLen = hb_itemGetCLen( pValue ); - const char * szString = hb_itemGetCPtr( pValue ); + HB_SIZE nPos, nPos2, nLen; + const char * szString; + void * hString = NULL; char buf[ 8 ]; - _hb_jsonCtxAdd( pCtx, "\"", 1 ); - if( cdp ) { - HB_WCHAR wc; - - nPos = 0; - while( HB_CDPCHAR_GET( cdp, szString, nLen, &nPos, &wc ) ) - { - if( wc >= ' ' && wc < 0x7F && wc != '\\' && wc != '\"' ) - { - buf[ 0 ] = ( char ) wc; - _hb_jsonCtxAdd( pCtx, buf, 1 ); - continue; - } - switch( wc ) - { - case '\\': - _hb_jsonCtxAdd( pCtx, "\\\\", 2 ); - break; - case '\"': - _hb_jsonCtxAdd( pCtx, "\\\"", 2 ); - break; - case '\b': - _hb_jsonCtxAdd( pCtx, "\\b", 2 ); - break; - case '\f': - _hb_jsonCtxAdd( pCtx, "\\f", 2 ); - break; - case '\n': - _hb_jsonCtxAdd( pCtx, "\\n", 2 ); - break; - case '\r': - _hb_jsonCtxAdd( pCtx, "\\r", 2 ); - break; - case '\t': - _hb_jsonCtxAdd( pCtx, "\\t", 2 ); - break; - default: - hb_snprintf( buf, sizeof( buf ), "\\u%04X", wc ); - _hb_jsonCtxAdd( pCtx, buf, 6 ); - break; - } - } + szString = hb_itemGetStr( pValue, cdp, &hString, &nLen ); } else { - nPos = 0; - while( nPos < nLen ) - { - unsigned char uch = szString[ nPos ]; - nPos2 = nPos; - while( uch >= ' ' && uch != '\\' && uch != '\"' ) - uch = szString[ ++nPos2 ]; - if( nPos2 > nPos ) - { - _hb_jsonCtxAdd( pCtx, szString + nPos, nPos2 - nPos ); - if( nPos2 >= nLen ) - break; - nPos = nPos2; - } + szString = hb_itemGetCPtr( pValue ); + nLen = hb_itemGetCLen( pValue ); + } - switch( uch ) - { - case '\\': - _hb_jsonCtxAdd( pCtx, "\\\\", 2 ); - break; - case '\"': - _hb_jsonCtxAdd( pCtx, "\\\"", 2 ); - break; - case '\b': - _hb_jsonCtxAdd( pCtx, "\\b", 2 ); - break; - case '\f': - _hb_jsonCtxAdd( pCtx, "\\f", 2 ); - break; - case '\n': - _hb_jsonCtxAdd( pCtx, "\\n", 2 ); - break; - case '\r': - _hb_jsonCtxAdd( pCtx, "\\r", 2 ); - break; - case '\t': - _hb_jsonCtxAdd( pCtx, "\\t", 2 ); - break; - default: - hb_snprintf( buf, sizeof( buf ), "\\u00%02X", uch ); - _hb_jsonCtxAdd( pCtx, buf, 6 ); - break; - } - nPos++; + _hb_jsonCtxAdd( pCtx, "\"", 1 ); + nPos = 0; + while( nPos < nLen ) + { + unsigned char uch = szString[ nPos ]; + nPos2 = nPos; + while( uch >= ' ' && uch != '\\' && uch != '\"' ) + uch = szString[ ++nPos2 ]; + if( nPos2 > nPos ) + { + _hb_jsonCtxAdd( pCtx, szString + nPos, nPos2 - nPos ); + if( nPos2 >= nLen ) + break; + nPos = nPos2; } + + switch( uch ) + { + case '\\': + _hb_jsonCtxAdd( pCtx, "\\\\", 2 ); + break; + case '\"': + _hb_jsonCtxAdd( pCtx, "\\\"", 2 ); + break; + case '\b': + _hb_jsonCtxAdd( pCtx, "\\b", 2 ); + break; + case '\f': + _hb_jsonCtxAdd( pCtx, "\\f", 2 ); + break; + case '\n': + _hb_jsonCtxAdd( pCtx, "\\n", 2 ); + break; + case '\r': + _hb_jsonCtxAdd( pCtx, "\\r", 2 ); + break; + case '\t': + _hb_jsonCtxAdd( pCtx, "\\t", 2 ); + break; + default: + hb_snprintf( buf, sizeof( buf ), "\\u00%02X", uch ); + _hb_jsonCtxAdd( pCtx, buf, 6 ); + break; + } + nPos++; } _hb_jsonCtxAdd( pCtx, "\"", 1 ); + hb_strfree( hString ); } else if( HB_IS_NUMINT( pValue ) ) { @@ -505,14 +470,8 @@ static const char * _hb_jsonDecode( const char * szSource, PHB_ITEM pValue, PHB_ return NULL; } } - if( cdp ) - szHead += hb_cdpU16ToStr( cdp, HB_CDP_ENDIAN_NATIVE, - &wc, 1, - szHead, szDest + nAlloc - szHead ); - else if( wc <= 0xFF ) - *szHead++ = ( char ) wc; - else - *szHead++ = '?'; + szHead += hb_cdpU16ToStr( cdp ? cdp : hb_vmCDP(), HB_CDP_ENDIAN_NATIVE, + &wc, 1, szHead, szDest + nAlloc - szHead ); break; } default: @@ -529,7 +488,10 @@ static const char * _hb_jsonDecode( const char * szSource, PHB_ITEM pValue, PHB_ return NULL; } } - hb_itemPutCL( pValue, szDest, szHead - szDest ); + if( cdp && hb_vmCDP() != cdp ) + hb_itemPutStrLen( pValue, cdp, szDest, szHead - szDest ); + else + hb_itemPutCL( pValue, szDest, szHead - szDest ); hb_xfree( szDest ); return szSource + 1; } @@ -747,12 +709,12 @@ HB_SIZE hb_jsonDecodeCP( const char * szSource, PHB_ITEM pValue, PHB_CODEPAGE cd HB_SIZE hb_jsonDecode( const char * szSource, PHB_ITEM pValue ) { - return hb_jsonDecodeCP( szSource, pValue, hb_vmCDP() ); + return hb_jsonDecodeCP( szSource, pValue, NULL ); } /* Harbour level API functions */ -static PHB_CODEPAGE _hb_jsonCdpPar( int iParam, HB_BOOL lVmCp ) +static PHB_CODEPAGE _hb_jsonCdpPar( int iParam ) { if( hb_pcount() >= iParam ) { @@ -761,9 +723,6 @@ static PHB_CODEPAGE _hb_jsonCdpPar( int iParam, HB_BOOL lVmCp ) if( szCdp ) return hb_cdpFindExt( szCdp ); } - else if( lVmCp ) - return hb_vmCDP(); - return NULL; } @@ -776,8 +735,7 @@ HB_FUNC( HB_JSONENCODE ) HB_SIZE nLen; char * szRet; - szRet = hb_jsonEncodeCP( pItem, &nLen, hb_parl( 2 ), - _hb_jsonCdpPar( 3, HB_FALSE ) ); + szRet = hb_jsonEncodeCP( pItem, &nLen, hb_parl( 2 ), _hb_jsonCdpPar( 3 ) ); hb_retclen_buffer( szRet, nLen ); } } @@ -785,8 +743,7 @@ HB_FUNC( HB_JSONENCODE ) HB_FUNC( HB_JSONDECODE ) { PHB_ITEM pItem = hb_itemNew( NULL ); - HB_SIZE nSize = hb_jsonDecodeCP( hb_parc( 1 ), pItem, - _hb_jsonCdpPar( 3, HB_TRUE ) ); + HB_SIZE nSize = hb_jsonDecodeCP( hb_parc( 1 ), pItem, _hb_jsonCdpPar( 3 ) ); if( HB_ISBYREF( 2 ) ) {