1. RE: getFocus & setFocus
- Posted by Ron Austin <ronaustin at alltel.net> Dec 13, 2003
- 675 views
Ron Austin wrote: > > > We have a program that has a main window, a listview window, a menu bar, > > a tool bar, 7 Tool tips, 7 labels and 7 EditText controls Data[1] thru > Data[7]. We want to change focus to the next EditText control when we > hit the Enter key or down arrow and change to the previous EditText > control when we hit the up arrow key. After shuffling the controls around a little, I now have my 7 EditText controls giving me 14,12,11,10,9,8,7. This is better. If it wouldn't skip 13 I could deal with it. I could deal with it anyway by making some sort of cross referrence table; 14=1, 12=2, etc, but I don't think I should have to. How can I fix this? > > This is working ok, so far. We set pos=1 to begin with and then add or > subtract from it, being carefull not to go over 7 or under 1. > > The problem comes in if someone uses the mouse to change the focus to > another control. We tried using getFocus() but instead of returning a > nunmber from 1 to 7, it returns 7,5,4,19,34,33,32 > These controls were created one after the other. Why don't it assign an > > id in assending sequential order? >
2. RE: getFocus & setFocus
- Posted by "Elliott S. de Andrade" <quantum_analyst at hotmail.com> Dec 13, 2003
- 609 views
I doubt you need a cross-reference table or anything. I'll assume that Data[1] through Data[7] contain the Win32lib ID's of the EditText controls. If all you want to do is find out which one is in focus, use focusControl = find(getFocus(), Data) if focusControl = 0 then -- focus is on a menu item or something.... -- you shouldn't change focus here, probably.... else -- index of Data for the focused control is in focusControl pos = focusControl -- change focus if you need to... -- or do any other work end if >From: Ron Austin <ronaustin at alltel.net> >Reply-To: EUforum at topica.com >To: EUforum at topica.com >Subject: RE: getFocus & setFocus >Date: Sat, 13 Dec 2003 16:52:49 +0000 > > >Ron Austin wrote: > > > > > > We have a program that has a main window, a listview window, a menu bar, > > > > a tool bar, 7 Tool tips, 7 labels and 7 EditText controls Data[1] thru > > Data[7]. We want to change focus to the next EditText control when we > > hit the Enter key or down arrow and change to the previous EditText > > control when we hit the up arrow key. > >After shuffling the controls around a little, I now have my 7 EditText >controls giving me 14,12,11,10,9,8,7. This is better. If it wouldn't >skip 13 I could deal with it. I could deal with it anyway by making >some sort of cross referrence table; 14=1, 12=2, etc, but I don't think >I should have to. How can I fix this? > > > > This is working ok, so far. We set pos=1 to begin with and then add or > > subtract from it, being carefull not to go over 7 or under 1. > > > > The problem comes in if someone uses the mouse to change the focus to > > another control. We tried using getFocus() but instead of returning a > > nunmber from 1 to 7, it returns 7,5,4,19,34,33,32 > > These controls were created one after the other. Why don't it assign an > > > > id in assending sequential order? > > >
3. RE: getFocus & setFocus
- Posted by Ron Austin <ronaustin at alltel.net> Dec 13, 2003
- 641 views
Derek Parnell wrote: > > > ----- Original Message ----- > From: "Ron Austin" <ronaustin at alltel.net> > To: <EUforum at topica.com> > Subject: getFocus & setFocus > > > > We have a program that has a main window, a listview window, a menu bar, > > > > a tool bar, 7 Tool tips, 7 labels and 7 EditText controls Data[1] thru > > Data[7]. We want to change focus to the next EditText control when we > > hit the Enter key or down arrow and change to the previous EditText > > control when we hit the up arrow key. > > > > This is working ok, so far. We set pos=1 to begin with and then add or > > subtract from it, being carefull not to go over 7 or under 1. > > > > The problem comes in if someone uses the mouse to change the focus to > > another control. We tried using getFocus() but instead of returning a > > nunmber from 1 to 7, it returns 7,5,4,19,34,33,32 > > These controls were created one after the other. Why don't it assign an > > > > id in assending sequential order? > > Well, there are some very good reasons why control ids are not numbered > in the same order that they are created. The main reasons are that some > controls are created implicitly rather than you explictly by the coder, > and when control's are destroyed, win32lib re-uses the id number and > other variables for efficiency, and blocks of id numbers and associated > variables are created at a time - also for efficiency reasons. > > One way to easily do what you are attempting is to place the seven > control ids into their own sequence and cycle through that sequence. > > For example... > > sequence Edits > Edits = {Edit1, Edit2, Edit3, Edit4, Edit5, Edit6, Edit7} > integer CurrentEdit > CurrentEdit = 1 > . . . > -- Up > if CurrentEdit > 1 then > CurrentEdit -= 1 > setFocus(Edits[CurrentEdit]) > end if > . . . > -- Down > if CurrentEdit < 7 then > CurrentEdit += 1 > setFocus(Edits[CurrentEdit]) > end if > . . . > -- User Changes Focus > procedure Focus_Edits(integer self, integer event, sequence parms) > CurrentEdit = find(self, Edits) > end procedure > setHandler(Edits, w32HGotFocus, routine_id("Focus_Edits")) > > > -- > Derek > > > Thanks Elliot and Derek. I tried Elliot's solution first and it works > just like I want it to. Sure is nice to have knowledgeable people reply > so I can get several solutions. Two more problems have popped up. First, is there a way to keep the bell from beeping when the enter key is hit? It makes you think there is an error when there is not. Second, when using arrows to go up and down through the controls, when it hits a combo box it starts scrolling through the list instead of continuing up or down. I understand why it's doing this and doubt if there is a solution, but it never hurts to ask. Thanks again for the help