Cut/Copy/Paste feature in Get

1,221 views
Skip to first unread message

Jayadev U

unread,
Mar 1, 2014, 11:16:39 AM3/1/14
to harbou...@googlegroups.com

Hi,

 

 

Using Harbour 3.0 +MingW on XP/Win8.1

 

I am porting a xHarbour application to Harbour.  My users make extensive use of cut/copy/paste feature in gets (which is the default behavior in xHarbour).  To give similar functionality, I copied the tgetlist.prg over to the source folder, and made the following modifications in it.

 

   #ifdef HB_EXT_INKEY

 

      case K_CTRL_C

         oGet:Assign()

         hb_gtInfo( GTI_CLIPBOARDDATA, CStr( oGet:VarGet() ) )

         exit

 

      case K_CTRL_X

         oGet:Assign()

         hb_gtInfo( GTI_CLIPBOARDDATA, CStr( oGet:VarGet() ) )

         oGet:DelEnd()

         exit

 

      case K_CTRL_V

         cToPaste := hb_gtInfo( GTI_CLIPBOARDDATA )

         nLen := len( cToPaste )

         for nI := 1 to nLen

            oGet:Insert( cToPaste[ nI ] )

         next nI

         exit

   #endif

 

In my .hbp file I have /d HB_EXT_INKEY, but when executing the program none of the above cases are triggered.  The inkey() value returns 3 (Ctrl-C) whereas it should return 515 (Ctrl-C), see definition in xhbinkey.ch

 

I have tried including xHbInkey.ch as also defining the Keys with #define directive in tgetlist.prg but no change.

 

Will I have to compile the HB30 sources again with some flag to enable this feature ?

 

Kindly help.

 

Warm regards,

 

Jayadev

 

Klas Engwall

unread,
Mar 1, 2014, 2:18:15 PM3/1/14
to harbou...@googlegroups.com
Hi Jayadev,

> Using Harbour 3.0 +MingW on XP/Win8.1

[...]

> In my .hbp file I have /d HB_EXT_INKEY, but when executing the program
> none of the above cases are triggered. The inkey() value returns 3
> (Ctrl-C) whereas it should return 515 (Ctrl-C), see definition in
> xhbinkey.ch

Are you mixing different Harbour versions again? xhbinkey.ch did not
exist in HB30. It was not added until:

2013-04-26 14:31 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl)
+ contrib/xhb/xhbinkey.ch

I don't think you can do what you are trying to do in HB30. I think you
will have to stick with the 3 and check instead if <Ctrl> is pressed to
distinguish between <Ctrl><C> and <PgDn>.

Regards,
Klas

José Quintas

unread,
Mar 1, 2014, 3:04:01 PM3/1/14
to harbou...@googlegroups.com
I like the idea to copy to clipboard the get, better than nothing.
Need test in 3.0, I use this code in Harbour 3.2 + gtwvg:

- mouse wheel
- left mouse button as ESC
- past text from clipboard
- copy to clipboard current get content (added now)
** do not change getsys

#include "hbgtinfo.ch"
#include "inkey.ch"

   hb_gtInfo( HB_GTI_INKEYFILTER, { | nKey |
      LOCAL nBits, lIsKeyCtrl
      SWITCH nKey
      CASE K_MWBACKWARD
         RETURN K_DOWN
      CASE K_MWFORWARD
         RETURN K_UP
      CASE K_RBUTTONDOWN
         RETURN K_ESC
      CASE K_RDBLCLK
         RETURN K_ESC
      CASE K_CTRL_V
         nBits := hb_GtInfo( HB_GTI_KBDSHIFTS )
         lIsKeyCtrl := ( nBits == hb_BitOr( nBits, HB_GTI_KBD_CTRL ) )
         IF lIsKeyCtrl
            hb_GtInfo( HB_GTI_CLIPBOARDPASTE )
            RETURN 0
         ENDIF
      CASE K_CTRL_C
         nBits := hb_gtInfo( HB_GTI_KBDSHIFTS )
         lIsKeyCtrl := ( nBits == hb_BitOr( nBits, HB_GTI_KBD_CTRL ) )
         IF lIsKeyCtrl
             MsgExclamation( "Copado para área de transferência" )
            IF GetActive() != NIL
               hb_gtInfo( HB_GTI_CLIPBOARDDATA, Transform( GetActive():VarGet(), "" ) )
               RETURN 0
            ENDIF
         ENDIF
      ENDSWITCH
      RETURN nKey
       } )

José M. C. Quintas
--
--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: http://groups.google.com/group/harbour-users
 
---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Klas Engwall

unread,
Mar 1, 2014, 4:07:35 PM3/1/14
to harbou...@googlegroups.com
Hi José,

> I like the idea to copy to clipboard the get, better than nothing.
> Need test in 3.0, I use this code in Harbour 3.2 + gtwvg:

[...]

> CASE K_CTRL_C
> nBits := hb_gtInfo( HB_GTI_KBDSHIFTS )
> lIsKeyCtrl := ( nBits == hb_BitOr( nBits, HB_GTI_KBD_CTRL ) )
> IF lIsKeyCtrl
> MsgExclamation( "Copado para área de transferência" )
> IF GetActive() != NIL
> hb_gtInfo( HB_GTI_CLIPBOARDDATA,
> Transform( GetActive():VarGet(), "" ) )
> RETURN 0
> ENDIF
> ENDIF

Yes, we talked about that a long time ago :-)

A slight improvement would be to move the bit checking to the top of the
method. That way it is only done once, and not in every case where the
<Ctrl> key matters. And it reduces the risk that an extremely fast
typist releases the <Ctrl> key before hb_gtInfo(HB_GTI_KBDSHIFTS) is called.

Regards,
Klas

José Quintas

unread,
Mar 1, 2014, 5:01:21 PM3/1/14
to harbou...@googlegroups.com
Hi

Em 01/03/2014 18:07, Klas Engwall escreveu:
> Yes, we talked about that a long time ago :-)
>
> A slight improvement would be to move the bit checking to the top of
> the method. That way it is only done once, and not in every case where
> the <Ctrl> key matters. And it reduces the risk that an extremely fast
> typist releases the <Ctrl> key before hb_gtInfo(HB_GTI_KBDSHIFTS) is
> called.
>
> Regards,
> Klas
>

Yes, I use it since that time.
After that, I know about HB_GTI_INKEYFILTER and move code to it.
Only now I add a second key that need check ctrl-key.

My question about your suggestion is:
Change reduces the code, but will check ctrl-key always.
Is ok check ctrl-key allways for any key? or better check only when needed?
(Depends on how Harbour make this check)

José M. C. Quintas

Klas Engwall

unread,
Mar 1, 2014, 7:24:13 PM3/1/14
to harbou...@googlegroups.com
Hi José,

> My question about your suggestion is:
> Change reduces the code, but will check ctrl-key always.
> Is ok check ctrl-key allways for any key? or better check only when needed?
> (Depends on how Harbour make this check)

There is of course a little cost involved when checking it for every
keystroke. But for me it is more important to check it early. In both
cases we are talking about a few milliseconds more or less. A compromise
might be to just get the bits at the top and analyze them as needed, for
each case. We might want to check other shift keys in the future, and
the same <nBits> variable can be used for those cases too.

Regards,
Klas

Jayadev U

unread,
Mar 1, 2014, 8:48:47 PM3/1/14
to harbou...@googlegroups.com
Hi Klas,

>>Are you mixing different Harbour versions again? xhbinkey.ch did not exist
in HB30.

No, I am not mixing versions again. I am just using xhbinkey.ch only for
the #defines of <ctrl-c> etc. In fact there is nothing other than inkey
definitions in that file.

>>I don't think you can do what you are trying to do in HB30. I think you
will have to stick with the 3 and check >>instead if <Ctrl> is pressed to
distinguish between <Ctrl><C> and <PgDn>.

CAN THIS BE DONE WITH THE LATEST NIGHTLY BUILD, IF SO HOW ?


Thanks for all you help.

Warm regards,

Jayadev

Jayadev U

unread,
Mar 1, 2014, 8:50:10 PM3/1/14
to harbou...@googlegroups.com

Hi José,

 

Many thanks for your prompt reply.  I shall test and see.

 

Warm regards,

 

Jayadev

 

 

From: harbou...@googlegroups.com [mailto:harbou...@googlegroups.com] On Behalf Of José Quintas
Sent: Sunday, March 2, 2014 1:34 AM
To: harbou...@googlegroups.com
Subject: Re: [harbour-users] Cut/Copy/Paste feature in Get

 

I like the idea to copy to clipboard the get, better than nothing.

Jayadev U

unread,
Mar 1, 2014, 10:49:41 PM3/1/14
to harbou...@googlegroups.com

Hi José,

 

Your codes works perfectly. I have made the following modification to add Cut feature (ctrl-x).  It may be of use to you.

 

         CASE K_CTRL_X

            nBits := hb_gtInfo( HB_GTI_KBDSHIFTS )

            lIsKeyCtrl := ( nBits == hb_BitOr( nBits, HB_GTI_KBD_CTRL ) )

            IF lIsKeyCtrl

               IF GetActive() != NIL

                  hb_gtInfo( HB_GTI_CLIPBOARDDATA, Transform( GetActive():VarGet(), "" ) )

                  GetActive():DelEnd()

                  RETURN 0

               ENDIF

            ENDIF

 

Thanks for helping me.

 

Warm regards,

 

Jayadev

 

 

 

 

From: harbou...@googlegroups.com [mailto:harbou...@googlegroups.com] On Behalf Of José Quintas
Sent: Sunday, March 2, 2014 1:34 AM
To: harbou...@googlegroups.com
Subject: Re: [harbour-users] Cut/Copy/Paste feature in Get

 

I like the idea to copy to clipboard the get, better than nothing.

Klas Engwall

unread,
Mar 2, 2014, 12:32:22 PM3/2/14
to harbou...@googlegroups.com
Hi Jayadev,

>>> Are you mixing different Harbour versions again? xhbinkey.ch did not exist
> in HB30.
>
> No, I am not mixing versions again. I am just using xhbinkey.ch only for
> the #defines of <ctrl-c> etc. In fact there is nothing other than inkey
> definitions in that file.

Yes, you are mixing versions. There was no support for any extended key
codes in HB30. xhbinkey.ch was added in HB32 less than a year ago. You
can #include it in your HB30 code but it adds absolutely nothing of
value. It also requires the xhb_inkey() function and a few other things,
and those did not exist until April 2013 either.

>>> I don't think you can do what you are trying to do in HB30. I think you
> will have to stick with the 3 and check >>instead if <Ctrl> is pressed to
> distinguish between <Ctrl><C> and <PgDn>.
>
> CAN THIS BE DONE WITH THE LATEST NIGHTLY BUILD, IF SO HOW ?

I noticed in a later post that you have already tried the
HB_GTI_KBDSHIFTS bit-checking code José posted. That works with both
HB30 and HB32. As I mentioned in another post last night, I would
suggest to move the nBits:=hb_gtInfo(HB_GTI_KBDSHIFTS) line to the top
of the method as a "semi useful" guard against the <Ctrl> key already
being released at the time of the function call. It is not fool proof in
any way (you have to remember that key codes are buffered in the
keyboard buffer while the HB_GTI_KBDSHIFTS test is a snapshot of the
state of the shift keys at the moment of the function call) but it
should be slightly better to check early than to check late anyway.

Regards,
Klas

rafa thefull

unread,
Mar 3, 2014, 4:54:42 AM3/3/14
to harbou...@googlegroups.com
This has a big problem
The debugger always stops at that line does not work.

Regards.

Jayadev U

unread,
Mar 3, 2014, 5:27:34 AM3/3/14
to harbou...@googlegroups.com
Hi Rafa,

I was about to write the email and I saw your mail. Yes, the debugger stops
working and you have to comment out the lines for it to work ? Any
workaround José ?

-----Original Message-----
From: harbou...@googlegroups.com [mailto:harbou...@googlegroups.com]
On Behalf Of rafa thefull
Sent: Monday, March 3, 2014 3:25 PM
To: harbou...@googlegroups.com
Subject: Re: [harbour-users] Cut/Copy/Paste feature in Get

Jayadev U

unread,
Mar 3, 2014, 5:35:14 AM3/3/14
to harbou...@googlegroups.com
Hi Klas,

>>Yes, you are mixing versions. There was no support for any extended key
codes in HB30. xhbinkey.ch was added in HB32 >>less than a year ago. You can
#include it in your HB30 code but it adds absolutely nothing of value. It
also requires >>the xhb_inkey() function and a few other things, and those
did not exist until April 2013 either.

No, no, I am not mixing versions, I simply copied the code in <Ctrl-c> and
others into the OLD tgetlist.prg (from HB30 source code) and linked it to my
program.

>>I noticed in a later post that you have already tried the HB_GTI_KBDSHIFTS
bit-checking code José posted. That works >>with both
>>HB30 and HB32. As I mentioned in another post last night, I would suggest
to move the >>nBits:=hb_gtInfo(HB_GTI_KBDSHIFTS) line to the top of the
method as a "semi useful" guard against the <Ctrl> key >>already being
released at the time of the function call. It is not fool proof in any way
(you have to remember that >>key codes are buffered in the keyboard buffer
while the HB_GTI_KBDSHIFTS test is a snapshot of the state of the shift
>>keys at the moment of the function call) but it should be slightly better
to check early than to check late anyway.

Ok.

Please see my other post today, we cannot debug the program once the above
code is introduced into the program.

Kindly let me know, if I can make it work in Hb32 (using the option within
tgetlist.prg), if so what is the procedure ?, this will help me easily debug
the programs and at the same time not disturb the rest of the program.

Warm regards,

Jayadev


-----Original Message-----
From: harbou...@googlegroups.com [mailto:harbou...@googlegroups.com]
On Behalf Of Klas Engwall
Sent: Sunday, March 2, 2014 11:02 PM
To: harbou...@googlegroups.com
Subject: Re: [harbour-users] Cut/Copy/Paste feature in Get

Hi Jayadev,

>>> Are you mixing different Harbour versions again? xhbinkey.ch did not
>>> exist
> in HB30.
>
> No, I am not mixing versions again. I am just using xhbinkey.ch only
> for the #defines of <ctrl-c> etc. In fact there is nothing other than
> inkey definitions in that file.


>>> I don't think you can do what you are trying to do in HB30. I think
>>> you
> will have to stick with the 3 and check >>instead if <Ctrl> is pressed
> to distinguish between <Ctrl><C> and <PgDn>.
>
> CAN THIS BE DONE WITH THE LATEST NIGHTLY BUILD, IF SO HOW ?

I noticed in a later post that you have already tried the HB_GTI_KBDSHIFTS
bit-checking code José posted. That works with both
HB30 and HB32. As I mentioned in another post last night, I would suggest to
move the nBits:=hb_gtInfo(HB_GTI_KBDSHIFTS) line to the top of the method as
a "semi useful" guard against the <Ctrl> key already being released at the
time of the function call. It is not fool proof in any way (you have to
remember that key codes are buffered in the keyboard buffer while the
HB_GTI_KBDSHIFTS test is a snapshot of the state of the shift keys at the
moment of the function call) but it should be slightly better to check early
than to check late anyway.

Regards,
Klas

José Quintas

unread,
Mar 3, 2014, 7:09:30 AM3/3/14
to harbou...@googlegroups.com
In Clipper, debug uses only code compiled with /b
In Harbour all code is debugged.
I don't know if this can be changed

Note:
When I began to use classes, debug crashes
After I began to use multithread
After I began to use inkeyfilter
No option to debug source code now, only add some routines to check
situations.

José M. C. Quintas

Jayadev U

unread,
Mar 3, 2014, 7:52:25 AM3/3/14
to harbou...@googlegroups.com
Hi José,

It does not matter, when I have to debug, I comment out your code and in the
final exe your code is added. Having the best of both the world :-)

I however feel, that there must be some way in which it can be activated
within the tgetlist.prg. In Hb32, it provides for <ctrl-c> etc in
tgetlist.prg. How to compile with the extended keys in Hb32 ?, I don't
know.

Thank you for your code once again.

Warm regards,

Jayadev

rafa thefull

unread,
Mar 3, 2014, 8:00:17 AM3/3/14
to harbou...@googlegroups.com
Hi

I put ;-)

#ifndef __DEBUG__
CODE INKEY
#endif

But, i send problem the list develop of Harbour.

Regards

José Quintas

unread,
Mar 3, 2014, 10:15:29 AM3/3/14
to harbou...@googlegroups.com
Hi

Em 03/03/2014 09:52, Jayadev U escreveu:
> Hi José,
>
> I however feel, that there must be some way in which it can be activated
> within the tgetlist.prg. In Hb32, it provides for <ctrl-c> etc in
> tgetlist.prg. How to compile with the extended keys in Hb32 ?, I don't
> know.
>
> Thank you for your code once again.
>
> Warm regards,
>
> Jayadev
>
>

If not use inkeyfilter, then can include same code in tgetlist, or getsys.

For extended codes:

SET( _SET_EVENTMASK, <option> )

From inkey.ch

#define INKEY_MOVE 1
#define INKEY_LDOWN 2
#define INKEY_LUP 4
#define INKEY_RDOWN 8
#define INKEY_RUP 16
#define INKEY_MMIDDLE 32 /* Harbour extension middle button
mask */
#define INKEY_MWHEEL 64 /* Harbour extension mouse wheel mask */
#define INKEY_KEYBOARD 128
#define INKEY_ALL 255

#define HB_INKEY_RAW 256 /* Harbour extension */
#define HB_INKEY_GTEVENT 1024 /* Harbour extension */
#define HB_INKEY_EXT 2048 /* Harbour extension */

#define HB_INKEY_ALL ( INKEY_ALL + HB_INKEY_GTEVENT )

José M. C. Quintas

Jayadev

unread,
Mar 4, 2014, 3:36:50 AM3/4/14
to harbou...@googlegroups.com
Hi José,

Many thanks.  I shall check with Hb32.

Warm regards,

Jayadev

 

José Quintas

unread,
Mar 4, 2014, 3:30:17 PM3/4/14
to harbou...@googlegroups.com
You can compile only module you want to debug.

Detail is:
In Clipper you delete obj and recompile using -b
In Harbour you need delete obj and c file, or if not possible, edit PRG
to force recompile using -b.

my application in normal use:

hbmk2 jpa.hbp

to debug only p0010.prg after above compile:

del d:\temp\p0010.*
hbmk2 jpa.hbp -b

Note:
in hbp I use: -inc -workdir=d:\temp
then all .obj (.o) and .c are in d:\temp
Because previous compile, and -inc, only p0010 will be compiled using -b.

José M. C. Quintas


Em 03/03/2014 07:27, Jayadev U escreveu:

Qatan

unread,
Mar 5, 2014, 6:05:38 AM3/5/14
to harbou...@googlegroups.com
Hello,

>...
>del d:\temp\p0010.*
>hbmk2 jpa.hbp -b
>
>Note:
>in hbp I use: -inc -workdir=d:\temp
>then all .obj (.o) and .c are in d:\temp
>Because previous compile, and -inc, only p0010 will be compiled using -b.

I could simply do this:

hbmk2 jpa.hbp -b -rebuild

The above will rebuild all the modules with DEBUG info in them.

Usually there is no need to define -workdir
I just let hbmk2 deal with it automatically.

And if I want to rebuild only one PRG than you should have the option -inc
(inside the .HBP)
Then I simple open it and save that specific PRG to force hbmk2 to rebuild
it:

hbmk2 jpa.hbp -b

The above will rebuild only one (or more) modules with DEBUG info in them
(all the ones you saved).
I hope it give you more ideas and options to rebuild, etc...

Regards,

Qatan


Rafa Carmona

unread,
Mar 7, 2014, 12:34:22 PM3/7/14
to harbou...@googlegroups.com
Hi José 
How can we simulate the Menu Mark and Copy the application from directly Harbour? 

The idea is to press CTRL + Mouse moved to the COPY without having to go to the Windows Menu


--
--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.

Web: http://groups.google.com/group/harbour-users

--- You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.



--
Saludos
Rafa Carmona

José Quintas

unread,
Mar 12, 2014, 6:44:07 AM3/12/14
to harbou...@googlegroups.com
Hi

Em 07/03/2014 14:34, Rafa Carmona escreveu:
> Hi José
> How can we simulate the Menu Mark and Copy the application from
> directly Harbour?
>
> The idea is to press CTRL + Mouse moved to the COPY without having to
> go to the Windows Menu
>
> --
> Saludos
> Rafa Carmona
>

I do not try it, but I think willl be needed 3 routines:
- memoedit mark/copy
- getsys mark/copy of a single get
- screen mark/copy for console - this already exists in gtwvg

José M. C. Quintas


Reply all
Reply to author
Forward
0 new messages