Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!snorkelwacker!ira.uka.de!smurf!urlichs From: urlichs@smurf.sub.org (Matthias Urlichs) Newsgroups: comp.sys.mac.programmer Subject: Re: Editable Text Objects in Dialog Boxes Message-ID: Date: 19 Aug 90 23:22:39 GMT References: <1990Aug17.171302.8900@Neon.Stanford.EDU> <4X6NVMD@cs.swarthmore.edu> Organization: University of Karlsruhe, FRG Lines: 89 In comp.sys.mac.programmer, article <4X6NVMD@cs.swarthmore.edu>, jackiw@cs.swarthmore.edu (Nick Jackiw) writes: < commons@Sunburn.Stanford.EDU (Peter Commons) writes: < > 1) Can you limit the length and/or prevent carriage returns? Theoretically I < > could check after every keypress to see if the length is too big or if they < > just hit return (and then delete the last character and redraw), but I was < > hoping for something nicer... < < [...] Thus, if you get a < keydown and the length of your item is at it's maximum, simply convert the < keydown into a nullEvent. You might want to beep, to let them know they've < typed enough, and you'll probably want to let backspace, delete, arrow-left, < arrow-right, arrow-up and arrow-down pass through unscathed, so they can < still edit even if they can't add more. < I think that the first method (deleting any characters after the Nth) is better. - Typing in the middle does what the user would expect. - Supporting Paste, likewise. - It's easier to program -- just check for length in the beginning of the filterproc, before you even look at the event, and if it's too long (by however many characters), shorten and beep. Likewise, if it's empty, replace with default selection but don't beep. (Instead, select the whole replacement so that typing after a backspace still works.) < Likewise, it's trivial for a filter to convert keydown/keyCode=13 (returns) < into nullEvents. Or beeps, or Tabs, or whatever. (When the user does something, something should happen.) < <>2) A month ago some people were saying that to make a password dialog where <>the password was not legible, you change the font to something where all chars <>are undefined??? How do I do this? < < Put up the dialog. DrawDialog. Then switch the font (TextFont) of the < current port to something more interesting---Zapf Chancery or your own < "every-character-a-bullet" font. Alternately, you can try intercepting < and parsing all the keydowns in the way that editText does, store them < yourself in some string, and convert them in your filterProc to bullet-downs < (option-shift-8). This is much more of a hassle than the former method, < however. < Hassle? Not at all. Just take canned code...: (from SingleShare's password handling dialog, managing two passwort fields which should be identical:) Cut/Copy/Paste are not allowed. Neither is autorepeat. This is supposed to be a write-only password, after all. Not changing the dialog's TextFont has the further advantages that (a) you can have other editable fields in it, (b) the whole thing is still legible after Pyro has been messing up the screen. ;-) BTW, the % down there is supposed to be a bullet character. Handling the EditText itself is left as an exercise to the Dialog Manager. :-) ELSE IF (dialogPeek(theDialog)^.editField = inPW1-1) OR (dialogPeek(theDialog)^.editField = inPW2-1) THEN BEGIN selStart := dialogPeek(theDialog)^.textH^^.selStart; selEnd := dialogPeek(theDialog)^.textH^^.selEnd; isPW1 := dialogPeek(theDialog)^.editField = inPW1-1; IF isPW1 THEN PW := thePW1 ELSE PW := thePW2; IF ch = CHR(bs) THEN BEGIN IF selStart = selEnd THEN BEGIN IF selStart > 0 THEN PW := concat(copy(PW,1, selStart - 1), copy(PW, selStart + 1, length(PW) - selStart)); END ELSE PW := concat(copy(PW, 1, selStart), copy(PW, selEnd + 1, length(PW) - selEnd)); END ELSE BEGIN PW := concat(copy(PW, 1, selStart), ch, copy(PW, selEnd + 1, length(PW) - selEnd)); theEvent.message := BitAnd(theEvent.message, -1-charCodeMask) + ord('%'); END; IF isPW1 THEN thePW1 := PW ELSE thePW2 := PW; END; END -- Matthias Urlichs -- urlichs@smurf.sub.org -- urlichs@smurf.ira.uka.de Humboldtstrasse 7 - 7500 Karlsruhe 1 - FRG -- +49+721+621127(Voice)/621227(PEP)