[comp.sys.mac.hypercard] Q: replacing the selection on a button click ?

wilde@boulder.Colorado.EDU (Nick Wilde) (01/06/91)

First of all, I'm but a novice "hyper-hacker", so if this is a FAQ or
a "so-simple-everybody-knows-the-answer-but-this-turkey question" I 
apologize. So send me the answer and I'll shut up. My question:

I have this field, ya see. The user clicks on said field, sets the
insertion point, maybe selects some text. Now,  said user goes over
and clicks one of several buttons. Depending upon which button is
pushed, I want to replace whatever was selected in the field with
some text. The problem is as soon as the user clicks on the button,
"the selection" goes away, and I have no idea where to put the 
text.... 

Is there someway around this ?  Maybe someway to save the selection
on a closeField or mouseLeave msg ? Is there some way to get a 
"description" of the selection, vs the selection itself ? Why is the
sky blue ? Do toilets really flush in the opposite direction due
to coriolis force in the southern hemisphere ? Does anybody care ?

Thanx for listening...

-Nick, the novice hyper-hacker 

ralph@world.std.com (Ralph Lombreglia) (01/06/91)

From article #2842:
>The problem is as soon as the user clicks on the button,
>"the selection" goes away...

Buttons which "hilite" when clicked will kill text selection in
HyperCard.  It's something many people thought might be corrected in
v.2.0, but it wasn't.  Set the "autohilite" of the buttons in question
to false; they won't give you any visual feedback when you click on
them, but they won't kill your text selections, either.  You could
give a little feedback to the user by setting the cursor to "watch"
(the wristwatch), which is especially effective on slower Macintoshes.

>Why is the sky blue?

Because.

Ralph Lombreglia
Internet: ralph@world.std.com   MCI Mail: rlombreglia   Bix: rlombreglia

jdevoto@Apple.COM (Jeanne A. E. DeVoto) (01/06/91)

In article <1991Jan5.232644.29647@csn.org> wilde@boulder.Colorado.EDU
(Nick Wilde) writes:
>I have this field, ya see. The user clicks on said field, sets the
>insertion point, maybe selects some text. Now,  said user goes over
>and clicks one of several buttons. Depending upon which button is
>pushed, I want to replace whatever was selected in the field with
>some text. The problem is as soon as the user clicks on the button,
>"the selection" goes away, and I have no idea where to put the 
>text.... 

Let me guess: the button's autohilite property is turned on.
When a button is hilited, the text selection is lost. You can get around
the problem by turning off autohiliting, of course, but this solution
is unappealing: for one thing, it removes an important element of user
feedback.

>                                       Is there some way to get a 
>"description" of the selection, vs the selection itself ? Why is the
>sky blue ? Do toilets really flush in the opposite direction due
>to coriolis force in the southern hemisphere ? Does anybody care ?

The function you're looking for is "the selectedChunk". This function
returns a chunk expression such as "char 5 to 14 of card field ID 5".
The basic strategy is to store the selectedChunk and then re-select it
after your handler is finished. Add some code to fake auto-hiliting
and you get something like:

  on mouseDown
    put the selectedChunk into mySelection
    repeat until the mouse is up -- autohilite
      if the mouseLoc is within the rect of the target then
        set the hilite of the target to true
      else
        set the hilite of the target to false
      end if
    end repeat
    if the mouseLoc is within the rect of the target then
      -- do button stuff
    end if
    set the hilite of the target to false
    select mySelection
  end mouseDown

Because the atmosphere preferentially scatters red light.

Depends on whether the inflow faucets are angled or not.

I do! ;-)
-- 
========= 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.                     |