oGet:bGotFocus Problem

oGet:bGotFocus Problem

Postby James Bott » Fri Jul 07, 2006 10:26 pm

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  Expand view
#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
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: oGet:bGotFocus Problem

Postby Enrico Maria Giordano » Sat Jul 08, 2006 7:05 am

Code: Select all  Expand view
#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: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: oGet:bGotFocus Problem

Postby Enrico Maria Giordano » Sat Jul 08, 2006 7:17 am

Alternative (maybe better):

Code: Select all  Expand view
#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
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby James Bott » Sat Jul 08, 2006 7:20 am

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: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby James Bott » Sat Jul 08, 2006 7:26 am

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

Postby Enrico Maria Giordano » Sat Jul 08, 2006 8:40 am

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

Postby James Bott » Sat Jul 08, 2006 9:02 am

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: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby James Bott » Sat Jul 08, 2006 9:06 am

Enrico,

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

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

Postby Enrico Maria Giordano » Sat Jul 08, 2006 9:41 am

I'm using latest FWH with latest xHarbour or latest Harbour.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Enrico Maria Giordano » Sat Jul 08, 2006 9:45 am

Do you want my EXE to test it there?

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby James Bott » Sat Jul 08, 2006 5:34 pm

Enrico,

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

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

Postby James Bott » Sat Jul 08, 2006 8:15 pm

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

Postby Enrico Maria Giordano » Sat Jul 08, 2006 9:51 pm

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: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Enrico Maria Giordano » Sat Jul 08, 2006 9:52 pm

James Bott wrote:Thanks for your time, Enrico.


It's my great pleasure.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 55 guests