[comp.sys.mac] Apple HyperCard User Group Newsletter

sac@well.UUCP (Steve Cisler) (09/17/87)

By Dave Leffler & Robin Shank

WELCOME...

This is the first issue of  The WindoidQ the newsletter for Apple's
HyperCard User's Group.  We hope the user group and newsletter
will create a forum for information about HyperCard, including
tips and techniques in various accessible formats to make your use
of HyperCard even more valuable, flexible, and fun.

We will bring you articles written by the development team and
will make efforts to take your questions and problems directly to
the source for an answer.

In addition, and most importantly, The Windoid will create a forum
for the open sharing of stackware and information.  

Bill and Dan have shown a remarkable ability to immediately
understand the needs, ideas, and suggestions of HyperCard users.  
The members of the team have thus been able to assist greatly in
shaping HyperCard into what it is today.  The continuing interest in
user input gives users a unique opportunity to help shape
HyperCard's future. 

This newsletter provides an opportunity for  its readers to
contribute to the continued genesis of HyperCard.  With your
assistance we can continue to bring to HyperCard added depth and
functionality.  In the back of every issue will be a form for you to
keep by your Macintosh*.  This form will give you the unique
opportunity to be able to participate in the continued development
of HyperCard.  

If you have a bug, suggestion, or comment fill out the form and
send it to:

AHUG
C/O David Leffler
Apple Computer Inc.
MS 27AQ
10500 N. DeAnza Blvd.
Cupertino, CA  95014

Or  copy the form's format and AppleLink* it to:
HYPERBUG

ASK THE TEAM...

The HyperCard test team has consented to provide us with a series
of tips and techniques based on frequent user questions.  Please
send in your questions and they will try to answer the most
consistently asked.

How can I create a script that will enable me to double-click an
icon button?

Consider creating a button script like the following:

The following handler makes a button that will detect a
double-click on itself.  It waits 30 ticks for the 2nd click then
times out.

Put this handler into a button's script, then add whatever special
things you want your button to do when double-clicked. Adjust the
timeout value if you want it to wait longer (or shorter).   A tick is
1/60th of a second.

on mouseUp
  put the ticks into originalTicks
  repeat until the mouseClick
    if the ticks - originalTicks > 30
	 then exit mouseUp
  end repeat
  -- Put here whatever you want the 
  --button to do when double-clicked.
  -- For example:
  Play "Boing"
end mouseUp

How can I get a word in a field to do something when I click on it?

One way would be to put a transparent button over the text.  If you
want to be able to move the word around inside the field without
having to move the transparent button with it, you can use the
following "sticky button" technique.

 	The following script gets put into the field
On Mousedown
	Set locktext of me to false
	click at the clickloc
	click at the clickloc
	if the selection is "Apple" then
		answer "What kind of Apple:" with
        "Macintosh" or "Apple II"
	else
		put "I don't know that word" into msg
	end if
	set locktext of me to true
End Mousedown

Note: MouseDown, mouseStillDown, and mouseUp messages only get
sent to a field when that field is locked. It is therefore necessary
to lock a field when expecting that field to deal with any of these
messages.

The idea behind sticky buttons is to cause a word to be selected
(highlighted) with a single mouse click. 'The selection' then
becomes a container.

In the above script, we first unlock the field so that we can create
a selection. Next, we want to make Hypercard believe that we have
double clicked a word, when we really have clicked it only once.
This is done in the next two lines of the script. Clicking at the
clickloc forces Hypercard to click twice at the same location
clicked at by the user. A highlighted selection is then created.
Once a word is highlighted, we can use the Hypercard function 'the
selection' to find out what that word is. 

Comparison can be done using multiple IF THEN statements or by
the use of a word-list field. In the above script, we do a very
simple IF THEN ELSE comparison which only looks for the word
APPLE. When found, it puts up a dialog. If any other word is
clicked, a generic message is placed in the message box. Remember
that you do not need to show the message box every time you want
to write into it. Hypercard displays the message box automatically
whenever text is placed inside it.

How can I find out which line of a field a user has clicked in?

It is easy to calculate using information that can be obtained
about a given field. 

First of all, we can find out what size rectangle a field occupies
by using the field property, RECT. Short for rectangle, RECT
returns four numbers in a comma separated list. The numbers
represent the upper-left and lower-right screen coordinates for
that field.

Next, we can find out what the line height of each line of a field is
by using the field property, TEXTHEIGHT. As you might have
guessed, each line of a field can really be expressed as a
multipleof the line height. Unfortunately, we must determine that
multiple using the screen coordinates. Here's a user defined
function that will do just that:

Function Clickline
	return ((item 2 of the 
	clickloc - item 2 of the rect of the
	target) div the textheight of the
	target) + 1
End Clickline
on openField
	put clickline() into msg
	pass openField
end openField

Ignore the openField handler for now, but take a look at the
function. As you may remember, the Hypercard function, THE
TARGET, returns the name and id of the object which last received
a message. Likewise, the Hypercard function THE CLICKLOC returns
the horizontal and vertical screen position of the last mouse click
as two comma separated integers. With that knowledge, let's
dissect the function Clickline() (yes, you need the parentheses).

The function returns an integer which represents the number of
the line of any field clicked in. 

Here's how the function determines the field's line number. First,
it takes the vertical location clicked at by the user (item 2 of the
clickloc) and subtracts the top of the field (item 2 of the rect) to
determine how many pixels are between the top of the field and
the location clicked at. Once this is known, determining the line
number is a matter of dividing those pixels by the TEXTHEIGHT.
This is what the rest of the function does. We add 1 because
Clickline() returns a zero for line 1.

Clickline() is very flexible. In the openfield handler shown above
for example, we use clickline() with a put statement, treating it
just like the number it returns. You can also use it with an IF THEN
statement or any place where you would use the number itself. All
you need do is replace the 'put line' of the openfield handler with
your script.

What about scrolling fields?

An interesting exception arises when using scrolling fields. The
above function does not account for lines that may have scrolled
off of the screen. It looks only at the visible area of the field.
Consider the following function:

Function Clickline
	return (((item 2 of the 
	clickloc - item 2 of the rect of the
	target) div the textheight of the
	target) + 1 + trunc(scroll of the
	target/textheight of the target))
End Clickline

It adds the number of lines that have scrolled off the screen to the
total number of visible lines. The field property SCROLL returns
the number of pixels scrolled off the top of the field. When divided
by the TEXTHEIGHT, this yields the number of lines. Since a full
line may not have scrolled by, it is necessary to truncate the value
using the TRUNC function.

Put both the function definition and the openfield handler in your
home script where they can be used by any field in any stack.

How can I hide buttons from command-option key peek?

When you don't want people peeking at your buttons, it is
necessary to trap the command and option keys. While there are
several ways of doing this, here is one that is simple and works
about 99% of the time.

The basic idea is to take the user to another card when the
command and option keys are both pressed. This can be a "no
peeking" card or a rules card or some other kind of card. When the
user releases both keys, you then return to the card the user was
viewing before trying to peek. Following are the two scripts that
accomplish this. Put the top one in your  stack script and the other
in the "no peeking" card script.

For the stack script:

On Idle
	if the commandkey is down and 
	the optionkey is down then
		push this card
		go card "no peeking"
	end if
end Idle

For the "no peeking" card script:

On Idle
	if the commankey is up and 
	the optionkey is up then
		pop card
	end if
End Idle

POWER USER TIPS

%  Create a button on your Home card with a script that says, 'go to
stack "the stack you want".'  When you click on it, not finding a
stack by that name it will put up SFGetfile asking "Where is the
stack you want?" 

%  To zoom directly to the script of an object, hold down the Shift
key while double clicking on the object, or while choosing Object
"Info...".

%  Do not name a button or a field with a name that begins with a
numeric character.  This causes problems in that  if you ask for a
button "1812" HyperCard looks for the button whose number, not
name, is 1812.

%  In the button or field tools, holding the shift key down when
dragging constrains the movement horizontally or vertically,
making it easy to drag in a straight line.

%  With any tool, Option-Drag in Fatbits allows you to scroll the
screen.

%  To "pre warm" the cards in a stack so that "show all cards" will
really cook through the stack, put an "on openStack" script that
locks the screen, shows all cards, and then unlocks the screen. 
This quickly and invisibly caches all the cards, so that "show card"
scripts will work at optimum speed.

%  If you are running on a Mac II and want to see Visual Effects, be
sure to set the monitor to 2 bit mode.

STACK BUILDING HINTS

Beware of relying entirely on  "Go Back"  buttons for navigation
through your stack.    A good technique is: On openCard  "push
recent card", which remembers where you just came from.  Then
when you do a "pop card" you will always go to that recent
location.  

If you suspect that your pushes and pops are not in sync,  add the
following handlers to your stack script to help you sort them out.

on pop params
	put the params after msg
	pass pop   
end pop

on push params
	put the params after msg
	pass push
end push

TELL HYPERCARD...

Please use the following form to make a difference in the world:

Date:
Name:
MailStop or Address:
Phone:
Versions of:
 a.  HyperCard
 b.  Associated software
 c.  System Software
	1. System
	2. Finder
	3. ImageWriter file
	4. LaserWriter file
	5. Any others
Type of Macintosh:
Peripherals:
Description of problem, suggestions or comments:



You can send this form to:

AHUG
C/O David Leffler
Apple Computer Inc.
MS 27AQ
10500 N. DeAnza Blvd.
Cupertino, CA  95014

Or, copy this format and AppleLink* it to:

HYPERBUG