oGet:bGotFocus Problem

Post Reply
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

oGet:bGotFocus Problem

Post 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
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: oGet:bGotFocus Problem

Post 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
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: oGet:bGotFocus Problem

Post 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
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post 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
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post 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
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post 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
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post 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
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post by James Bott »

Enrico,

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

James
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post by James Bott »

Enrico,

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

Thanks,
James
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post 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
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post 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
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post by Enrico Maria Giordano »

James Bott wrote:Thanks for your time, Enrico.
It's my great pleasure.

EMG
Post Reply