[comp.sys.mac.hypercard] selecting from a scrollable field

abdenour@mist.cs.orst.edu (Abdennour A. MOUSSAOUI) (03/13/90)

Another question.
I have a list of numbers let us say from 1-1000. if I place them
in a scrollable field (one number per line), is it possible
write a script so that when a user click on a number then I will know
on which one he click on?
The reason for this is that I have a stack that has 1000 cards.
so I wantto create a table of content card so that a user can jump to
any card he likes without scanning one by one.
also I don't want the user to have to type a number in a field or
have to pull the the go menu and use find or message command.
This is why I want to have a scrollable list of numbers that a user
can select from to jump to the appropriate card.

any help or suggestions?
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /\   !    ~~~~Hayaa Ala-falaah  
Abdennour Moussaoui              || _~_~_      Allahu Akbar Allahu Akbar  
Oregon State University          ||(_____)     Laa Illaha Ila Allah~~~~
email=abdenour@mist.cs.orst.edu  |||_|_|_|  

ALE101@psuvm.psu.edu (Allen Edmiston) (03/13/90)

In article <16815@orstcs.CS.ORST.EDU>, abdenour@mist.cs.orst.edu (Abdennour A.
MOUSSAOUI) says:
>I have a list of numbers let us say from 1-1000. if I place them
>in a scrollable field (one number per line), is it possible
>write a script so that when a user click on a number then I will know
>on which one he click on?

though i really dont have an answer for this, i just wanted to suggest looking
at the apple q&a stack along with the tech note stack, you could probably get
alot of useful information from fiddling with them.


                                                   Allen Edmiston

ako@cs.hut.fi (Arto Kojo) (03/14/90)

>From: abdenour@mist.cs.orst.edu (Abdennour A. MOUSSAOUI)
>I have a list of numbers let us say from 1-1000. if I place them
>in a scrollable field (one number per line), is it possible
>write a script so that when a user click on a number then I will know
>on which one he click on?

I've included a (SuperCard) field script that does the thing you want
and highlights the selected line with SC graphic item. Standard highlight
("select line lineN of card field 1") wasn't good enough for me.

However, I've got a further problem:

How to detect line wrapping in field (if any line wraps, the script gets mixed)
or prevent lines from wrapping in SuperCard scrolling fields ????


----clip clap----

on mouseUp
  put the mouseV into clickY
  put the short name of me && "hilite" into grcName
  set the cursor to 4
  
  put 2 into marginal --normal sized margins
  if the wideMargins of me is true then add (the textSize of me div 3)
	to marginal
  subtract marginal from clickY
  put (clickY - the top of me + the scroll of me) div the textHeight of me + 1
	into lineN
  if lineN < 1 then put 1 into lineN
  if lineN > the number of lines in me then put the number of lines in me
	into lineN
  
  put the top of me + marginal + (lineN - 1) * the textHeight of me -
	the scroll of me + (the height of card graphic grcName div 2)
	into newY
  put the left of me + 2 + (the width of card graphic grcName div 2)
	into newX
  set the loc of card graphic grcName to newX,newY
  show card graphic grcName
end mouseUp



--
:::: Arto Kojo :::::::::::::::::::::: Helsinki University of Technology ::::
::   TKK/TKO-lab/Y227                 ako@hutcs.hut.fi                    ::
::   02150 ESPOO FINLAND              s29808u@puukko.hut.fi               ::
:::: tel: +358-0-4513236 :::::::::::: akojo@otax.tky.hut.fi ::::::::::::::::

tomj@oakhill.UUCP (Tom Johnson) (03/14/90)

In article <AKO.90Mar14111614@hutcs.hut.FI> ako@cs.hut.fi (Arto Kojo) writes:
>
>From: abdenour@mist.cs.orst.edu (Abdennour A. MOUSSAOUI)
>I have a list of numbers let us say from 1-1000. if I place them
>in a scrollable field (one number per line), is it possible
>write a script so that when a user click on a number then I will know
>on which one he click on?

Put the following script (or a reasonable facimile thereof) in a **LOCKED**
scrollable field and it will return the contents of the selection line within
the field.  Note that this MUST run under HC 1.2 or later.

on mouseUp
  put the mouseV into m
  put item 2 of the rect of me into t
  put the scroll of me into s
  put the textHeight of me into th
  put (round((m-t+s)/th + 0.5)) into l
  if l > (number of lines in me) then
    beep
    put "" into chosenNumber
  else
    put line l of me into chosenNumber
  end if
end mouseUp

You can also add double-click detection by inserting the following as
the first two lines of the handler:
  wait 7 ticks
  if the mouseClick then put TRUE into dc else put FALSE into dc

Then, later in the script:
  if dc=TRUE then
    <do your double-click thing here>
  endif

Hope this helps.

Tom Johnson   tomj@oakhill.UUCP

aland@chaos.cs.brandeis.edu (Alan D Danziger) (03/15/90)

In article <16815@orstcs.CS.ORST.EDU>, abdenour@mist.cs.orst.edu
(Abdennour A.
MOUSSAOUI) says:
>I have a list of numbers let us say from 1-1000. if I place them
>in a scrollable field (one number per line), is it possible
>write a script so that when a user click on a number then I will know
>on which one he click on?

Yes...  You can get the line that was clicked on...

    I don't have the exact 'method' handy, but send me mail if you
want me to look it up for you...
-- 

	-=Alan=-
	aland@chaos.cs.brandeis.edu

dave@lsuc.on.ca (David Sherman|LSUC|Toronto) (03/15/90)

abdenour@mist.CS.ORST.EDU (Abdennour A. MOUSSAOUI) writes:
>I have a list of numbers let us say from 1-1000. if I place them
>in a scrollable field (one number per line), is it possible
>write a script so that when a user click on a number then I will know
>on which one he click on?

The below is what I use.  As well as being simple, it avoids the
problems of some of the other posted solutions when the line is
long enough to wrap around to a second line on the field.

Make sure the field is locked.

on mouseUp
  set the lockText of me to false -- to allow selecting
  click at the clickLoc
  click at the clickLoc
  -- now the word clicked on is selected
  set the lockText of me to true -- so the user can't muck around
  select the selectedLine -- optional, to highlight the whole line clicked on
  put word 2 of the selectedLine into lineNumber
  go card (line lineNumber of me) -- or whatever
end mouseUp

If what you have is a list of card numbers or card names, "go card"
will work fine.  Otherwise, just get line lineNumber of me and do
whatever you want with It (pun intended).

If you find this useful, please let me know.

David Sherman
Toronto
-- 
Moderator, mail.yiddish
{ uunet!attcan  att  utzoo }!lsuc!dave          dave@lsuc.on.ca

gdavis@primate.wisc.edu (Gary Davis) (03/16/90)

From article <1990Mar15.052929.5942@lsuc.on.ca>, by dave@lsuc.on.ca (David Sherman|LSUC|Toronto):
- abdenour@mist.CS.ORST.EDU (Abdennour A. MOUSSAOUI) writes:
--I have a list of numbers let us say from 1-1000. if I place them
--in a scrollable field (one number per line), is it possible
--write a script so that when a user click on a number then I will know
--on which one he click on?
- 
- The below is what I use.  As well as being simple, it avoids the
- problems of some of the other posted solutions when the line is
- long enough to wrap around to a second line on the field.
- 
- Make sure the field is locked.
- 
- on mouseUp
-   set the lockText of me to false -- to allow selecting
-   click at the clickLoc
-   click at the clickLoc
-   -- now the word clicked on is selected
-   set the lockText of me to true -- so the user can't muck around
-   select the selectedLine -- optional, to highlight the whole line clicked on
-   put word 2 of the selectedLine into lineNumber
-   go card (line lineNumber of me) -- or whatever
- end mouseUp

This solution works well when you have the possibility of wrapped
lines, but it is noticeably slower than calculating the line
clicked from the click point as others have suggested. If you have
a scrolling list of just numbers from 1 to 1000 then you
presumably don't need to worry about wrapped lines.

To get the contents of the selected line you can also just say 

value of the selectedLine

instead of

line (word 2 of the selectedLine) of me

Gary Davis

taylorj@yvax.byu.edu (03/16/90)

Yes, yes, I know lots of people posted their favorite script for selecting text
from a field, but they all suffered from bloated code or wouldn't work in all
cases.  Below is the "canonical" clickLine function that handles regular
fields, scrolling fields, and fields with wide margins:

  function clickLine
    put the clickV - the top of the target into lineV
    if the style of the target is "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 clickLine

You would use this in a locked field with a script something like

  on mouseUp
    select line clickLine() of me
  end mouseUp

or

  on mouseUp
    go to card clickLine()
    -- where cards are numbered to correspond to lines in the field
  end mouseUp


By the way, the "the"s in the script above make it run FASTER, not slower as
you might expect.


Jim Taylor
Microcomputer Support for Curriculum   |
Brigham Young University               |   Bitnet: taylorj@byuvax.bitnet
101 HRCB, Provo, UT  84602             |   Internet: taylorj@yvax.byu.edu