RE: Moving the Cursor
- Posted by Jon Snyder <jongsnyder at hotmail.com> Aug 11, 2002
- 512 views
Dan, Thanks. That's a good idea, but I think that there has to be a better way. The main reason that i didn't want to have different text boxes was to allow the flexibility of using a default area code or just entering 10 digits into the edit box. If you noticed my "addDashes()" routine formated a 7 digit number like this, 123-4567, and a 10 digit number like this, 123-456-7890. If just 7 digits were entered it would use the default area code as the area code. I realize you could do this with multiple edit boxes, but i think that would be more mess than its worth. There had to be some c routine that would be able to move the cursor to the end of an edit box. Would it be that hard just to link to some c routine that would do this? I also thought of the possiblity of just fooling the key handler into thinking that the "End" button was pressed. I don't know how to even start doing something like that. --Jon Snyder Dan Moyer wrote: > Jon, > > Here's an attempt to be helpful; it does *some* of what you want, but > not > exactly always, maybe it could be fixed up, or at least prompt a better > attempt? > > It uses the "3" edit boxes you *didn't* like, backspaces correctly > *some* of > the time to the *end* of the previous number field (& *doesn't* other > times, > moves to *beginning* of previous instead), & moves from the prefix to > the > last part of the number on filling in 3 digits. I didn't put the "-" > between the boxes, nor make the area code move to prefix after filling > in 3 > there. It also uses the "unlink the handler" idea that Don Phillips > suggested, though I had to use a "dummy" procedure to do it right, "0" > didn't work for me. > > You could argue that it doesn't actually force positioning of the > cursor, & > you'd be right. :( This simple problem seems harder (to me) than it > sounds! Maybe there's a simpler solution we're overlooking? > > > Dan Moyer > > > ---------------------------------------------------------------------------- > > ----------- > include Win32Lib.ew > without warning > > ---------------------------------------------------------------------------- > > ---- > constant Window1 = create( Window, "Window1", 0, Default, Default, 400, > 300, > 0 ) > constant Prefix = create( EditText, "", Window1, 52, 56, 30, 28, 0 ) > constant AreaCode = create( EditText, "123", Window1, 15, 56, 30, 28, 0 > ) > global constant NUMBER_EDIT = create( EditText, "", Window1, 92, 56, 60, > 28, > 0 ) > > constant > aStatusBar = create( StatusBar, "", Window1, 0, 25, 20, 20, 0) > > ----------------------------------------------- > setFocus(Prefix) -- didn't seem to work, had to re-do the order of > creation > -- to make 2nd edit box (Prefix) start out with focus, not > sure why > > procedure dummy() -- to unlink handler when changing text in edit boxes > end procedure > > sequence TheNumber -- actually just the last part of the number > sequence ThePrefix > ------------------------------------------------- > > procedure change_prefix() > > ThePrefix = getText(Prefix) > setText(aStatusBar, ThePrefix) > if length(ThePrefix) = 3 then > setFocus(NUMBER_EDIT) > elsif length(ThePrefix) > 3 then > onChange[ Prefix] = routine_id("dummy") -- unlink handler > setText(Prefix, ThePrefix[1..3]) > setFocus(NUMBER_EDIT) > -- following needed 4..length; just 4 by itself gave the ascii? > setText(NUMBER_EDIT, ThePrefix[4..length(ThePrefix)] ) > setFocus(NUMBER_EDIT) > onChange[ Prefix] = routine_id( "change_prefix") -- relink handler > end if > end procedure > onChange[ Prefix] = routine_id( "change_prefix") > > > -- CHECK FOR BACKSPACE KEY IN THE EDIT BOXES > -- IF EDIT BOX EMPTY, MOVE BACK TO PREVIOUS EDIT BOX: > > procedure onKeyDown_NUMBER_EDIT(int keyCode, int shift ) > if keyCode = VK_BACK and length(getText(NUMBER_EDIT)) = 0 then > setFocus(Prefix) > end if > > end procedure > onKeyDown[NUMBER_EDIT] = routine_id("onKeyDown_NUMBER_EDIT") > > procedure onKeyDown_Prefix(int keyCode, int shift ) > if keyCode = VK_BACK and length(getText(Prefix)) = 0 then > setFocus(AreaCode) > end if > > end procedure <snip>