diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 8fbe06651c..64a54d9110 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,18 @@ The license applies to all entries newer than 2009-04-28. */ +2012-04-24 08:43 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) + * harbour/src/rtl/inkey.c + * modified HB_KEYPUT() and HB_KEYINS() to convert strings + into key codes instead of passing them directly to keyboard + buffer like in __KEYBOARD() function. + + * harbour/include/hbgtcore.h + * harbour/src/rtl/hbgtcore.c + * modified hb_inkeySetText() (PRG __KEYBOARD() function) to translate + passed string into unicode values + This modification affects also HB_GTI_CLIPBOARDPASTE + 2012-04-24 07:18 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * harbour/include/hbgtcore.h ! fixed typo in HB_GTSELF_KEYTRANS() macro. diff --git a/harbour/include/hbgtcore.h b/harbour/include/hbgtcore.h index 1c4dc5dcbe..e12cf6ca89 100644 --- a/harbour/include/hbgtcore.h +++ b/harbour/include/hbgtcore.h @@ -337,7 +337,7 @@ typedef struct _HB_GT_BASE int inkeyTail; int iLastPut; int inkeyLast; - HB_BYTE * StrBuffer; + HB_WCHAR * StrBuffer; HB_SIZE StrBufferSize; HB_SIZE StrBufferPos; diff --git a/harbour/src/rtl/hbgtcore.c b/harbour/src/rtl/hbgtcore.c index 6fa5a4df35..7b0f8d2127 100644 --- a/harbour/src/rtl/hbgtcore.c +++ b/harbour/src/rtl/hbgtcore.c @@ -2743,6 +2743,12 @@ static HB_BOOL hb_gt_def_InkeyNextCheck( PHB_GT pGT, int iEventMask, int * iKey if( pGT->StrBuffer ) { *iKey = pGT->StrBuffer[ pGT->StrBufferPos ]; + if( *iKey >= 128 ) + { + *iKey = HB_INKEY_NEW_UNICODE( *iKey ); + if( ( iEventMask & HB_INKEY_EXT ) == 0 ) + *iKey = hb_inkeyKeyStd( *iKey ); + } } else if( pGT->inkeyHead != pGT->inkeyTail ) { @@ -2922,16 +2928,20 @@ static void hb_gt_def_InkeySetText( PHB_GT pGT, const char * szText, HB_SIZE nLe if( szText && nLen ) { - pGT->StrBuffer = ( HB_BYTE * ) hb_xgrab( nLen ); - memcpy( pGT->StrBuffer, szText, nLen ); - pGT->StrBufferSize = nLen; - pGT->StrBufferPos = 0; - do + PHB_CODEPAGE cdp = hb_vmCDP(); + HB_SIZE nIndex = 0; + HB_WCHAR wc; + + pGT->StrBufferSize = pGT->StrBufferPos = 0; + pGT->StrBuffer = ( HB_WCHAR * ) hb_xgrab( nLen * sizeof( HB_WCHAR ) ); + while( HB_CDPCHAR_GET( cdp, szText, nLen, &nIndex, &wc ) ) + pGT->StrBuffer[ pGT->StrBufferSize++ ] = wc == ';' ? HB_CHAR_CR : wc; + + if( pGT->StrBufferSize == 0 ) { - if( pGT->StrBuffer[ --nLen ] == ';' ) - pGT->StrBuffer[ nLen ] = HB_CHAR_CR; + hb_xfree( pGT->StrBuffer ); + pGT->StrBuffer = NULL; } - while( nLen ); } } diff --git a/harbour/src/rtl/inkey.c b/harbour/src/rtl/inkey.c index fa3b4ed4a3..2c88a0406f 100644 --- a/harbour/src/rtl/inkey.c +++ b/harbour/src/rtl/inkey.c @@ -65,12 +65,47 @@ */ #include "hbapigt.h" +#include "hbgtcore.h" #include "hbapiitm.h" #include "hbapicdp.h" #include "hbset.h" #include "hbstack.h" #include "hbvm.h" +static void hb_inkeySetTextKeys( const char * pszText, HB_SIZE nSize, HB_BOOL fInsert ) +{ + PHB_CODEPAGE cdp = hb_vmCDP(); + HB_SIZE nIndex = 0; + HB_WCHAR wc; + + if( fInsert ) + { + HB_WCHAR buffer[ 32 ], * keys; + HB_SIZE n = 0; + + keys = nSize <= HB_SIZEOFARRAY( buffer ) ? buffer : + ( HB_WCHAR * ) hb_xgrab( nSize * sizeof( HB_WCHAR ) ); + while( HB_CDPCHAR_GET( cdp, pszText, nSize, &nIndex, &wc ) ) + keys[ n++ ] = wc; + + while( n-- ) + { + int iKey = keys[ n ] >= 128 ? HB_INKEY_NEW_UNICODE( keys[ n ] ) : keys[ n ]; + hb_inkeyIns( iKey ); + } + if( nSize > HB_SIZEOFARRAY( buffer ) ) + hb_xfree( keys ); + } + else + { + while( HB_CDPCHAR_GET( cdp, pszText, nSize, &nIndex, &wc ) ) + { + int iKey = wc >= 128 ? HB_INKEY_NEW_UNICODE( wc ) : wc; + hb_inkeyPut( iKey ); + } + } +} + HB_FUNC( INKEY ) { int iPCount = hb_pcount(); @@ -101,7 +136,7 @@ HB_FUNC( HB_KEYPUT ) } else if( HB_ISCHAR( 1 ) ) { - hb_inkeySetText( hb_parc( 1 ), hb_parclen( 1 ) ); + hb_inkeySetTextKeys( hb_parc( 1 ), hb_parclen( 1 ), HB_FALSE ); } else if( HB_ISARRAY( 1 ) ) { @@ -119,7 +154,8 @@ HB_FUNC( HB_KEYPUT ) } else if( type & HB_IT_STRING ) { - hb_inkeySetText( hb_arrayGetCPtr( pArray, nIndex ), hb_arrayGetCLen( pArray, nIndex ) ); + hb_inkeySetTextKeys( hb_arrayGetCPtr( pArray, nIndex ), + hb_arrayGetCLen( pArray, nIndex ), HB_FALSE ); } } } @@ -133,7 +169,7 @@ HB_FUNC( HB_KEYINS ) } else if( HB_ISCHAR( 1 ) ) { - hb_inkeySetText( hb_parc( 1 ), hb_parclen( 1 ) ); + hb_inkeySetTextKeys( hb_parc( 1 ), hb_parclen( 1 ), HB_TRUE ); } else if( HB_ISARRAY( 1 ) ) { @@ -151,7 +187,8 @@ HB_FUNC( HB_KEYINS ) } else if( type & HB_IT_STRING ) { - hb_inkeySetText( hb_arrayGetCPtr( pArray, nIndex ), hb_arrayGetCLen( pArray, nIndex ) ); + hb_inkeySetTextKeys( hb_arrayGetCPtr( pArray, nIndex ), + hb_arrayGetCLen( pArray, nIndex ), HB_TRUE ); } } }