tj@cs.ucla.edu (Tom Johnson) (07/07/90)
I am trying to implement a password dialog box--something along the lines of that used by AppleShare. The dialog box has two text edit items, one for the user name, and one for the password--I would like to hide the password from the observer (replace it with apples or bullets). I suppose that what I have to do is create a filter proc for the dialog, intercept, KeyDown and AutoKey events, stuff the value into a buffer, and replace the theEvent->message with the character of my choice. My big question is: How do I know when the user is entering text into the Password text edit item (as opposed to the UserName item)? The event record gives me no indication of which item is selected (or does it?), the itemHit variable doesn't tell me, and I don't where to find out. Any ideas? Surely somebody else out there has done this already and can offer me some tips, ideas, or source code. Thanks- Tom -- Tom Johnson UCLA Computer Science Department 3413 Boelter Hall, Los Angeles CA 90024 (213)825-6952 Internet: tj@cs.ucla.edu
jackiw@cs.swarthmore.edu (Nick Jackiw) (07/08/90)
tj@cs.ucla.edu (Tom Johnson) writes: > My big question is: How do I know when the user is entering text into > the Password text edit item (as opposed to the UserName item)? The event > record gives me no indication of which item is selected (or does it?), > the itemHit variable doesn't tell me, and I don't where to find out. There's a field in the DialogRecord called editField, which according to I-408 "is one less than the item number of the current editText item, or -1 if there's no editText item in the dialog." So use this and bob's your uncle. Do beware of tabs, though. ModalDialog interprets these separately, as keys to switch from the current editText item to the next. This switching probably happens after your filterProc and before your itemHit. Make sure you ignore tabs, or handle them appropriately. > Tom Johnson UCLA Computer Science Department -- -----Nicholas Jackiw [jackiw@cs.swarthmore.edu|jackiw@swarthmr.bitnet]----- "Here is how I built this artificial mine. I snatched a female louse from the hair of humanity. I was seen to lie with her on three successive nights, and then I flung her into the pit." _Maldoror_, Canto II
hawley@adobe.COM (Steve Hawley) (07/09/90)
In article <PXAMQ65@xavier.swarthmore.edu> jackiw@cs.swarthmore.edu (Nick Jackiw) writes: >tj@cs.ucla.edu (Tom Johnson) writes: >> My big question is: How do I know when the user is entering text into >> the Password text edit item (as opposed to the UserName item)? The event >> record gives me no indication of which item is selected (or does it?), >> the itemHit variable doesn't tell me, and I don't where to find out. Don't sweat so much. Try this instead: Create a font with NO entries except the "undefined" character. Make the "undefined" character be a bullet or apple or a picture of Ulrich Zwingli or whatever you want. Use this font for the password TextEdit field. Magically, any and all characters typed will be this one character. Share and enjoy. Steve Hawley hawley@adobe.com -- "A blow on the head is... ...worth two in the bush." -Basil Fawlty
dave@cmi.com (David Halonen) (07/11/90)
A very simple solution: Get the text string, rip of the last character typed in, store it, replace with a character of your choice, replace the original string with modified, wait for next char. Sample code follows: do { len = *displayStr; ModalDialog( nil, &itemHit); GetIText( itemHdl, &displayStr ); newLen = *displayStr; if( newLen != len ) { if( newLen > len ) {/*user added a char*/ sprintf( (char *) answer, "%s%c", answer, displayStr[ newLen ] ); displayStr[ newLen ] = (char) 0xA5;/*convert char to '%'*/ } else {/*user deleted a char*/ *displayStr = newLen; *(answer + len - 1) = (char) 0x00;/*adjust end of 'C' string*/ } SetIText( itemHdl, displayStr ); } } while ( (itemHit != okButton) & (itemHit != cancelButton) ); if ( itemHit == okButton ) { CtoPstr( (char *) answer );/*sprintf turns it into a C string*/ if( EqualString( &answer, paPassword, false, false ) ) valid = true; } Ugly, but it works. David Halonen, Center for Machine Intelligence, Electronic Data Systems Ann Arbor, MI (313) 995-0900 AppleLink: N0548 Internet: dave@cmi.com