Page 1 of 1

oGet:bGotFocus Problem

Posted: Fri Jul 07, 2006 10:26 pm
by James Bott
I am trying to change the behavior of a GET using bGotFocus. I want the cursor to be in the 1 postion when the GET is entered and to clear the contents of the GET if the user starts typing in the first postion. The code below works when you tab or shift-tab into the GET but not if you click into the GET. Strangely, you do hear the tone() when clicking into the GET so the codeblock is getting eval'd, but there must be other code that is getting called after the codeblock which then moves the cursor back to the click position. I have been working on this for hours with no luck.

Using May 2006 FWH.

Any ideas on a solution?

James
-------------------------

Code: Select all

#include "fivewin.ch"

function main()
   local oDlg, oGet, cName:= "Microsoft           ", oGet2, cAddress:=space(22), oBtn

   define dialog oDlg

   @ 1,1 get oGet var cName of oDlg 

   oGet:bGotFocus:= {||  oGet:gohome(), oGet:oGet:clear:=.t., tone(300,1) }

   @ 2,1 get oGet2 var cAddress of oDlg update

   activate dialog oDlg

return nil

Re: oGet:bGotFocus Problem

Posted: Sat Jul 08, 2006 7:05 am
by Enrico Maria Giordano

Code: Select all

#include "fivewin.ch" 

function main() 
   local oDlg, oGet, cName:= "Microsoft           ", oGet2, cAddress:=space(22), oBtn 

   define dialog oDlg 

   @ 1,1 get oGet var cName of oDlg 

//   oGet:bGotFocus:= {||  oGet:gohome(), oGet:oGet:clear:=.t., tone(300,1), sysrefresh() } 
   oGet:bGotFocus := { || oGet:PostMsg( WM_KEYDOWN, VK_HOME ) }

   @ 2,1 get oGet2 var cAddress of oDlg update 

   activate dialog oDlg 

return nil
EMG

Re: oGet:bGotFocus Problem

Posted: Sat Jul 08, 2006 7:17 am
by Enrico Maria Giordano
Alternative (maybe better):

Code: Select all

#include "fivewin.ch" 

#define EM_SETSEL 177


function main() 
   local oDlg, oGet, cName:= "Microsoft           ", oGet2, cAddress:=space(22), oBtn 

   define dialog oDlg 

   @ 1,1 get oGet var cName of oDlg 

//   oGet:bGotFocus:= {||  oGet:gohome(), oGet:oGet:clear:=.t., tone(300,1), sysrefresh() } 
//   oGet:bGotFocus := { || oGet:PostMsg( WM_KEYDOWN, VK_HOME ) }
   oGet:bGotFocus := { || oGet:PostMsg( EM_SETSEL, Len( RTrim( cName ) ), 0 ) }

   @ 2,1 get oGet2 var cAddress of oDlg update 

   activate dialog oDlg 

return nil
EMG

Posted: Sat Jul 08, 2006 7:20 am
by James Bott
Enrico,

> oGet:bGotFocus := { || oGet:PostMsg( WM_KEYDOWN, VK_HOME ) }

I already tried that. First it only has an effect when tabbing or shift-tabbing into the Get. What it does is select the text from position 1 to the current postion without changing the position. I need it to go to position 1 without selecting any text.

Also, your proposed solution does nothing when you click into the GET.

James

Posted: Sat Jul 08, 2006 7:26 am
by James Bott
Enrico,

>oGet:bGotFocus := { || oGet:PostMsg( EM_SETSEL, Len( RTrim( cName ) ), 0 ) }

This one selects all the text from 1 to the current cursor position. Still not what I need.

James

Posted: Sat Jul 08, 2006 8:40 am
by Enrico Maria Giordano
James Bott wrote:Enrico,

> oGet:bGotFocus := { || oGet:PostMsg( WM_KEYDOWN, VK_HOME ) }

I already tried that. First it only has an effect when tabbing or shift-tabbing into the Get. What it does is select the text from position 1 to the current postion without changing the position. I need it to go to position 1 without selecting any text.

Also, your proposed solution does nothing when you click into the GET.

James
What it does here is the following:

1. I click on the second GET.

2. Then I click on the first GET (not on the first position).

3. The caret is now on the first position of the first GET.

Is it what you need?

EMG

Posted: Sat Jul 08, 2006 9:02 am
by James Bott
Enrico,
What it does here is the following:

1. I click on the second GET.

2. Then I click on the first GET (not on the first position).

3. The caret is now on the first position of the first GET.

Is it what you need?
Yes, that is what I need but not what I am getting here. When I do exactly what you describe above, the text is highlighted from position 1 to the place where I clicked, and the cursor is flashing at the place where I clicked. I have double checked the code and it is the same as yours.

I am using FWH, May 2006 and the Harbour that came with it. Are you using xHarbour? Maybe that is the difference.

James

Posted: Sat Jul 08, 2006 9:06 am
by James Bott
Enrico,

I also see exactly the same behavior that I get with Harbour with Clipper.

James

Posted: Sat Jul 08, 2006 9:41 am
by Enrico Maria Giordano
I'm using latest FWH with latest xHarbour or latest Harbour.

EMG

Posted: Sat Jul 08, 2006 9:45 am
by Enrico Maria Giordano
Do you want my EXE to test it there?

EMG

Posted: Sat Jul 08, 2006 5:34 pm
by James Bott
Enrico,

Yes, please send me both the PRG and the EXE.

Thanks,
James

Posted: Sat Jul 08, 2006 8:15 pm
by James Bott
After evaluating my situation again, I have figured out that what I really needed was to just clear the GET whenever it was clicked into. I have been able to do this with this code:

oGet:bGotFocus := { || oGet:varPut(space(len(oGet:varGet()))), oGet:refresh() }

The reason I needed this is that the GET is an incremental search field for a listbox, so you really can't allow editing, typeover, etc. I want the field cleared when entered so the user doesn't have to backspace or deleted all the previous data to start a new search. It works OK now.

I am still at a loss as to why Enrico and I are seeing different results with his code. One of use must be linking in something different.

Thanks for your time, Enrico.

James

Posted: Sat Jul 08, 2006 9:51 pm
by Enrico Maria Giordano
James Bott wrote:Enrico,

Yes, please send me both the PRG and the EXE.

Thanks,
James
Sent.

Let me know.

EMG

Posted: Sat Jul 08, 2006 9:52 pm
by Enrico Maria Giordano
James Bott wrote:Thanks for your time, Enrico.
It's my great pleasure.

EMG