[comp.sys.mac.programmer] Blinking cursor in modeless dialog ...

mtoy@xman.SGI.COM (Michael Toy -- The S.G.I. XMAN) (02/24/88)

I can't get the cursor to blink in a dialog box.  All my previous dialog
boxes have been handled by "ModalDialog()" which does all the right things
for me.  Inside Mac tells me that I need to call "IsDialogEvent" and then
"DialogSelect" after a "GetNextEvent" even if "GetNextEvent" returns false
in order for the TextEdit cursor in my modeless dialog box to blink.  I
translated that statement to this code:

    if (GetNextEvent(everyEvent, &anEvent))
	/*
	** This is my event handler, it also calls IsDialogEvent and
	** DialogSelect
	*/
	handle_event(&anEvent);
    else {
#ifdef THISDOESNTWORK
	if (IsDialogEvent(&anEvent))
	    DialogSelect(&anEvent, &theItem, &theDialog);
#else
	/*
	** This also doesn't work, but I tried it because a different
	** interpretation of IM indicates this would be correct.
	*/
	(void) IsDialogEvent(&anEvent)
	DialogSelect(&anEvent, &theItem, &theDialog);
#endif
    }

The above code is from memory so don't tell me that my arguments to
DialogSelect are in the wrong order.  I've already spent a while bashing
my brains against the wall looking for little things like that.
(Well, now that I've mentioned it, doubt fills my brain, "Did you REALLY
make sure ??? :-)
--
Michael Toy, secret identity: the XMAN at Silicon Graphics
						{ames,decwrl,sun}!sgi!mtoy

olson@endor.harvard.edu (Eric K. Olson) (02/25/88)

In a recent article Michael Toy -- The S.G.I. XMAN writes:
>I can't get the cursor to blink in a dialog box.  All my previous dialog
>boxes have been handled by "ModalDialog()" which does all the right things
>for me.  Inside Mac tells me that I need to call "IsDialogEvent" and then
>"DialogSelect" after a "GetNextEvent" even if "GetNextEvent" returns false
>in order for the TextEdit cursor in my modeless dialog box to blink.  I
>translated that statement to this code:
>
>    if (GetNextEvent(everyEvent, &anEvent))
>	/*
>	** This is my event handler, it also calls IsDialogEvent and
>	** DialogSelect
>	*/
>	handle_event(&anEvent);

I use the following code:

void dialTEidle(dialog)
	DialogPtr	dialog;
{
	TEIdle(((DialogRecord *) dialog)->textH);
	}

void dialTEactive(dialog)
	DialogPtr	dialog;
{
	TEActivate(((DialogRecord *) dialog)->textH);
	}

void dialTEdeactive(dialog)
	DialogPtr	dialog;
{
	TEDeactivate(((DialogRecord *) dialog)->textH);
	}

with the following explanation:

Keep in mind that you don't want the cursor to blink just in response
to DialogSelect, since that is called in response to events.  In your
main loop, you should call dialTEIdle.  If the Dialog allows itself
to be deselected, you'll need dialTEActivate and dialTEDeactivate so
that the caret knows when to go away and appear.  Call them in response
to Activate and Deactivate events in the Dialog's window.

Note that this only works because the Dialog Manager shares a single
TextEdit record among all the EditText items in the Dialog (otherwise,
you'ld have to know which item is current, too).  This is documented
in Inside Mac (but seems like something subject to change).  If it
ever does change, this code will break.

I know of no other way to do it; does anyone else?

-Eric
	    "We're writing tomorrow's software yesterday."
Eric K. Olson     olson@endor.harvard.edu     harvard!endor!olson     D0760
   (Name)                (ArpaNet)                 (UseNet)        (AppleLink)