korcuska@plato.ils.nwu.edu (Michael Korcuska) (12/12/90)
We need a script which lets us know what line a user clicked on in a field which has several lines of text that wrap. To clarify, we have a field which, according to hypercard, has 3 lines but occupies 4 or 5 physical lines on the screen. How can we find out which of the 3 lines was clicked? Do we need an XFCN which gives us the length of a string in pixels or is there some trick we're missing? E-mail me at korcuska@ils.nwu.edu if this has been overly discussed in this group. thanks Michael
jdevoto@Apple.COM (Jeanne A. E. DeVoto) (12/13/90)
In article <195@anaxagoras.ils.nwu.edu> korcuska@plato (Michael Korcuska) writes: > [ . . ] we have a field which, according to hypercard, has 3 lines >but occupies 4 or 5 physical lines on the screen. How can we find out which >of the 3 lines was clicked? Assuming the field is locked, in HyperCard 1.2.2 or 1.2.5: on mouseDown set the lockText of the target to false click at the clickLoc get word 2 of the selectedLine -- the line number clicked on set the lockText of the target to true -- do something with the line number end mouseDown In HyperCard 2.0: on mouseDown get word 2 of the clickLine -- the number of the line clicked on -- do something with the line number end mouseDown If the field is not locked, generally an idle handler at the card level or higher works best: on idle global lastLineClicked if the selectedLine is lastLineClicked then pass idle -- hasn't changed put the selectedLine into lastLineClicked if the selectedField is "card field 1" then -- do something with the line number -- word 2 of the selectedLine end if end idle -- ========= jeanne a. e. devoto ======================================== jdevoto@apple.com | You may not distribute this article under a jdevoto@well.sf.ca.us | compilation copyright without my permission. ______________________________________________________________________ Apple Computer and I are not authorized | CI$: 72411,165 to speak for each other. |
taylorj@yvax.byu.edu (12/15/90)
Looks like it's again time to post my "definitive" clickRow function (formerly known as clickLine until HyperCard 2.0 stole the name). Unlike most functions floating around, this one handles scrolling and wide margins correctly. Of course, you can strip it down if you know you'll only use it with a certain kind of field. -- Returns the number of the line clicked on in the target field. -- Any wrapped line is counted as separate lines. -- Accounts for scrolling fields and wide margins. -- The fixedLineHeight property of the field must be true. function clickRow put the clickV - the top of the target into lineV if the style of the target = "scrolling" then add the scroll of the target to lineV if the wideMargins of the target then subtract 4 from lineV return lineV div the textHeight of the target + 1 end clickRow An example of its use (in the script of a locked text field): on mouseUp select line clickRow() of me end mouseUp This handler has been largely obviated by the clickLine function of HyperCard 2.0, but it still comes in handy for fields with long lines that wrap, which HyperCard treats as single lines no matter how many "rows" the line takes up. Enjoy! Jim Taylor Microcomputer Support for Curriculum | Brigham Young University | Bitnet: taylorj@byuvax.bitnet 101 HRCB, Provo, UT 84602 | Internet: taylorj@yvax.byu.edu