diff --git a/ChangeLog.txt b/ChangeLog.txt index 8a62fa42ab..f120627f2b 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -10,6 +10,33 @@ * Change, ! Fix, % Optimization, + Addition, - Removal, ; Comment */ +2013-04-26 14:31 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) + + contrib/xhb/xhbinkey.ch + + contrib/xhb/xhbkey.c + * contrib/xhb/xhb.hbp + * contrib/xhb/xhb.hbx + + added support for xHarbour compatible extended Inkey() key codes + This functionality works with GTs which can operate on Harbour + extended key codes which are translated at runtime to xHarbour + extended keys (HB_EXT_INKEY). + + added new PRG function: + xhb_Inkey( [ ] [ , ] ) -> + which works like Inkey() but returns xHarbour extended key codes. + + added new PRG function: + xhb_KeyTrans( ) -> + which translates Harbour extended key code to xHarbour one. + + * include/hbapigt.h + * src/rtl/inkeyapi.c + + added new C function: + int hb_inkeyKeyVal( int iKey ); + It extract key/character code from Harbour extended key code + + * include/harbour.hbx + * src/rtl/inkey.c + + added new PRG function: + hb_keyVal( ) -> | + 2013-04-26 12:07 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * contrib/xhb/xhb.hbc * contrib/xhb/xhb.hbp diff --git a/contrib/xhb/xhb.hbp b/contrib/xhb/xhb.hbp index 7db5342b11..2118d95ca6 100644 --- a/contrib/xhb/xhb.hbp +++ b/contrib/xhb/xhb.hbp @@ -55,6 +55,7 @@ xhbi18n.c xhbinet.c xhbini.c xhbis.c +xhbkey.c xhbmsgs.c xhbmtc.c xhbmvinf.c diff --git a/contrib/xhb/xhb.hbx b/contrib/xhb/xhb.hbx index 903f680743..d92554d2b4 100644 --- a/contrib/xhb/xhb.hbx +++ b/contrib/xhb/xhb.hbx @@ -447,6 +447,8 @@ DYNAMIC xhb_HashError DYNAMIC xhb_Inc DYNAMIC xhb_Include DYNAMIC xhb_Index +DYNAMIC xhb_Inkey +DYNAMIC xhb_KeyTrans DYNAMIC xhb_Less DYNAMIC xhb_LessEq DYNAMIC xhb_Lib diff --git a/contrib/xhb/xhbinkey.ch b/contrib/xhb/xhbinkey.ch new file mode 100644 index 0000000000..cd33bda31c --- /dev/null +++ b/contrib/xhb/xhbinkey.ch @@ -0,0 +1,98 @@ +/* + * Harbour Project source code: + * xHarbour compatible extended Inkey() key codes + * + * Copyright 2013 Przemyslaw Czerpak + * www - http://harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +#ifndef XHB_INKEY_CH_ +#define XHB_INKEY_CH_ + +/* New control keys that do not overlap with other codes */ + +#define XHB_K_CTRL_A 513 /* Ctrl-A */ +#define XHB_K_CTRL_B 514 /* Ctrl-B */ +#define XHB_K_CTRL_C 515 /* Ctrl-C */ +#define XHB_K_CTRL_D 516 /* Ctrl-D */ +#define XHB_K_CTRL_E 517 /* Ctrl-E */ +#define XHB_K_CTRL_F 518 /* Ctrl-F */ +#define XHB_K_CTRL_G 519 /* Ctrl-G */ +#define XHB_K_CTRL_H 520 /* Ctrl-H */ +#define XHB_K_CTRL_I 521 /* Ctrl-I */ +#define XHB_K_CTRL_J 522 /* Ctrl-J */ +#define XHB_K_CTRL_K 523 /* Ctrl-K */ +#define XHB_K_CTRL_L 524 /* Ctrl-L */ +#define XHB_K_CTRL_M 525 /* Ctrl-M */ +#define XHB_K_CTRL_N 526 /* Ctrl-N */ +#define XHB_K_CTRL_O 527 /* Ctrl-O */ +#define XHB_K_CTRL_P 528 /* Ctrl-P */ +#define XHB_K_CTRL_Q 529 /* Ctrl-Q */ +#define XHB_K_CTRL_R 530 /* Ctrl-R */ +#define XHB_K_CTRL_S 531 /* Ctrl-S */ +#define XHB_K_CTRL_T 532 /* Ctrl-T */ +#define XHB_K_CTRL_U 533 /* Ctrl-U */ +#define XHB_K_CTRL_V 534 /* Ctrl-V */ +#define XHB_K_CTRL_W 535 /* Ctrl-W */ +#define XHB_K_CTRL_X 536 /* Ctrl-X */ +#define XHB_K_CTRL_Y 537 /* Ctrl-Y */ +#define XHB_K_CTRL_Z 538 /* Ctrl-Z */ + +/* extended shift key codes, none in Clipper */ + +#define XHB_K_SH_LEFT 424 /* Shift-Left */ +#define XHB_K_SH_UP 425 /* Shift-Up */ +#define XHB_K_SH_RIGHT 426 /* Shift-Right */ +#define XHB_K_SH_DOWN 427 /* Shift-Down */ + +#define XHB_K_SH_INS 428 /* Shift-Ins */ +#define XHB_K_SH_DEL 429 /* Shift-Del */ +#define XHB_K_SH_HOME 430 /* Shift-Home */ +#define XHB_K_SH_END 431 /* Shift-End */ +#define XHB_K_SH_PGUP 432 /* Shift-PgUp */ +#define XHB_K_SH_PGDN 433 /* Shift-PgDn */ + +#define XHB_K_SH_RETURN 434 /* Shift-Enter */ +#define XHB_K_SH_ENTER 434 /* Shift-Enter */ + +#endif /* XHB_INKEY_CH_ */ diff --git a/contrib/xhb/xhbkey.c b/contrib/xhb/xhbkey.c new file mode 100644 index 0000000000..03ed5afbb3 --- /dev/null +++ b/contrib/xhb/xhbkey.c @@ -0,0 +1,123 @@ +/* + * Harbour Project source code: + * xHarbour compatible extended Inkey() key codes + * + * Copyright 2013 Przemyslaw Czerpak + * www - http://harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +#include "hbgtcore.h" +#include "hbset.h" +#include "xhbinkey.ch" + +static int hb_inkeyKeyXHB( int iKey ) +{ + HB_TRACE( HB_TR_DEBUG, ( "hb_inkeyKeyXHB(%d)", iKey ) ); + + if( HB_INKEY_ISEXT( iKey ) ) + { + int iFlags = HB_INKEY_FLAGS( iKey ), + iValue = HB_INKEY_VALUE( iKey ); + + if( HB_INKEY_ISKEY( iKey ) ) + { + if( ( iFlags & ( HB_KF_SHIFT | HB_KF_CTRL | HB_KF_ALT ) ) == HB_KF_SHIFT && + iValue >= 0 && iValue < 32 ) + { + switch( iValue ) + { + case HB_KX_LEFT: + return XHB_K_SH_LEFT; + case HB_KX_UP: + return XHB_K_SH_UP; + case HB_KX_RIGHT: + return XHB_K_SH_RIGHT; + case HB_KX_DOWN: + return XHB_K_SH_DOWN; + case HB_KX_INS: + return XHB_K_SH_INS; + case HB_KX_DEL: + return XHB_K_SH_DEL; + case HB_KX_HOME: + return XHB_K_SH_HOME; + case HB_KX_END: + return XHB_K_SH_END; + case HB_KX_PGUP: + return XHB_K_SH_PGUP; + case HB_KX_PGDN: + return XHB_K_SH_PGDN; + case HB_KX_ENTER: + return XHB_K_SH_ENTER; + } + } + } + if( HB_INKEY_ISKEY( iKey ) || + HB_INKEY_ISCHAR( iKey ) || + HB_INKEY_ISUNICODE( iKey ) ) + { + if( ( iFlags & ( HB_KF_CTRL | HB_KF_ALT ) ) == HB_KF_CTRL ) + { + if( iValue >= 'A' && iValue <= 'Z' ) + return 512 + ( iValue - 'A' ) + 1; + else if( iValue >= 'a' && iValue <= 'z' ) + return 512 + ( iValue - 'a' ) + 1; + } + } + } + return hb_inkeyKeyStd( iKey ); +} + +HB_FUNC( XHB_KEYTRANS ) +{ + hb_retni( hb_inkeyKeyXHB( hb_parni( 1 ) ) ); +} + +HB_FUNC( XHB_INKEY ) +{ + int iPCount = hb_pcount(), iKey; + + iKey = hb_inkey( iPCount == 1 || ( iPCount > 1 && HB_ISNUM( 1 ) ), hb_parnd( 1 ), + hb_parnidef( 2, hb_setGetEventMask() ) | HB_INKEY_EXT ); + + hb_retni( hb_inkeyKeyXHB( iKey ) ); +} diff --git a/include/harbour.hbx b/include/harbour.hbx index 90f83ee32f..d0720ecda5 100644 --- a/include/harbour.hbx +++ b/include/harbour.hbx @@ -639,6 +639,7 @@ DYNAMIC hb_keyNext DYNAMIC hb_keyPut DYNAMIC hb_keySetLast DYNAMIC hb_keyStd +DYNAMIC hb_keyVal DYNAMIC hb_langErrMsg DYNAMIC hb_langMessage DYNAMIC hb_langName diff --git a/include/hbapigt.h b/include/hbapigt.h index 68bde5cb40..6f9dc21551 100644 --- a/include/hbapigt.h +++ b/include/hbapigt.h @@ -314,7 +314,8 @@ extern HB_EXPORT void hb_inkeyExit( void ); /* reset inkey pool extern HB_EXPORT HB_SIZE hb_inkeyKeyString( int iKey, char * buffer, HB_SIZE nSize ); /* convert key value to string */ extern HB_EXPORT int hb_inkeyKeyStd( int iKey ); /* convert Harbour extended key code to cl*pper inkey code */ -extern HB_EXPORT int hb_inkeyKeyMod( int iKey ); /* extract keyboard modifiers from Harbour extended key code */ +extern HB_EXPORT int hb_inkeyKeyMod( int iKey ); /* extract keyboard modifiers HB_KF_* from Harbour extended key code */ +extern HB_EXPORT int hb_inkeyKeyVal( int iKey ); /* extract key/character code from Harbour extended key code */ HB_EXTERN_END diff --git a/src/rtl/inkey.c b/src/rtl/inkey.c index 69606b78e4..5c2978643b 100644 --- a/src/rtl/inkey.c +++ b/src/rtl/inkey.c @@ -262,3 +262,8 @@ HB_FUNC( HB_KEYMOD ) { hb_retni( hb_inkeyKeyMod( hb_parni( 1 ) ) ); } + +HB_FUNC( HB_KEYVAL ) +{ + hb_retni( hb_inkeyKeyVal( hb_parni( 1 ) ) ); +} diff --git a/src/rtl/inkeyapi.c b/src/rtl/inkeyapi.c index 3ce3b75e05..9496267cc5 100644 --- a/src/rtl/inkeyapi.c +++ b/src/rtl/inkeyapi.c @@ -485,3 +485,15 @@ int hb_inkeyKeyMod( int iKey ) return iFlags; } + +int hb_inkeyKeyVal( int iKey ) +{ + int iValue = 0; + + HB_TRACE( HB_TR_DEBUG, ( "hb_inkeyKeyVal(%d)", iKey ) ); + + if( HB_INKEY_ISEXT( iKey ) && ! HB_INKEY_ISMOUSEPOS( iKey ) ) + iValue = HB_INKEY_VALUE( iKey ); + + return iValue; +}