keith@apple.UUCP (Keith Rollin) (10/19/87)
WINDOID Issue #1 Editor: David Leffler Welcome... This is the first issue of The HyperCard Windoid - 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, 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 20520 Mariani Ave., Cupertino, CA 95014 Or copy the 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. Question: How can I create a script that will enable me to double-click an icon button? Answer: Consider creating a button script like the following. The following handler for 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 next whatever you want the button to do when double-clicked. -- For example: Play "Boing" end mouseUp Question: How can get a word in a field to do something when I click on it? Answer: 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 (highlighte 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. Question: How can I find out which line of a field a user has clicked in? Answer: Using information that can obtained about a given field, it is easy to calculate. First of all, we can find out what size rectangle a field occupies by using 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 usi the field property, TEXTHEIGHT. As you might have guessed, each line of field can really be expressed as a multiple of 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 yo 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 a field clicked in. Here's how the function determines the field's line number. First, it takes 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 examp 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 funct 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 scri where they can be used by any field in any stack. One final note: a "line" to HyperCard is a string of text separated by a carriage return. Therefore "the number of lines in field "myfield" " will return the number of carriage returns in the field, regardless of how the text may have wrapped in the field. Question: How can I hide buttons from command-option key peek? Answer: 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 opti 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, or going to its "info" window. Do not name a button or a field with a numeric character. This is because if you ask for a button "1812" HyperCard looks for the button whose number is 1812. In the button or field tools, holding the shift key down when dragging either will give you an automatic straight edge. You can easily drag buttons or fields in a straight line, either horizontally or vertically. Option-Drag in Fatbits allows you to grab and move 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 cashes all the cards, and show card scripts will work at optimum speed. If you are running on a MacII and want to see Visual Effects, be sure to set the monitor to 2 bit mode. Stack Design Issues Beware of relying on "Go Back" buttons for navigation in your stack. Push and Pop are where it's at. If the user strays just a little from the "predicted" course of navigation, the Back buttons just take him/her on a confusing little trip down memory lane. A good technique: On opencard "push recent card", which pushes 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 sinc, (happens before harminica convergences) add the following scripts to that stack script to help you sort out your pops.: on pop params put the params after msg pass pop end pop on push params put the params after msg pass push end push The form: Please use the following form to make a difference in the world: Date: Name: 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: AHUG C/O David Leffler Apple Computer Inc. MS 27AQ 20525 Mariani Ave., Cupertino, CA 95014 Or copy the format and AppleLink it to: HYPERBUG$ -- Keith Rollin amdahl\ Sales Technical Support pyramid!sun !apple!keith Apple Computer decwrl/ Disclaimer: I read this board for fun, not profit. Anything I say is from the result of reading magazines, hacking, and soaking my head in acid.