Path: utzoo!mnetor!uunet!husc6!bloom-beacon!mit-eddie!ll-xn!ames!amdahl!apple!dwb
From: dwb@Apple.COM (David W. Berry)
Newsgroups: comp.sys.mac.programmer
Subject: Re: MultiFinder switch bug with custom WDEFs
Message-ID: <9442@apple.Apple.Com>
Date: 9 May 88 21:47:05 GMT
References: <242@uvabick.UUCP> <8700@apple.Apple.Com> <2887@midas.TEK.COM> <9332@apple.Apple.Com> <2770@polya.STANFORD.EDU>
Reply-To: dwb@apple.UUCP (David W. Berry)
Organization: Apple Computer Inc, Cupertino, CA
Lines: 65
Keywords: MultiFinder doesn't allow switching when it thinks it sees a dBoxProc

In article <2770@polya.STANFORD.EDU> kaufman@polya.stanford.edu (Marc T. Kaufman) writes:
>One of the main reasons for using modal dialogs where modeless dialogs
>would do, is the availability of the Dialog Manager for handling most of
>the buttons, switches, and events.  If a dialog is modeless, you cannot
>use IsDialogEvent, NewDialog, GetNewDialog, or the ModalDialog event filter.
	Umm... beg to disagree, but, of the four things you mentioned,
only one of them (ModalDialog) isn't *supposed* to be used with modeless
dialogs, and ModalDialog isn't supposed to be used with modeless dialogs
because it specifically makes a dialog modal (kinda like the name suggests).
IsDialogEvent is primarily useful with modeless dialogs:
	Inside Macintosh I, pg. 416:  "If your application includes
any modeless dialog boxes, you'll pass events to IsDialogEvent to
learn whether need to be handled as part of a dialog, and then usually
call DialogSelect if so."  DialogSelect handles things like tab moving
to the next field, caret blinking, etc.  What is left for the programmer
to handle are things like:
	Buttons, CheckBoxes, RadioButtons - none of which are handled
		automatically by the system for modal dialogs either.
	Return, Cmd-., Enter - which are handled by ModalDialog, but
		which are pretty simple to deal with anyway.
	NewDialog and GetNewDialog are used to create dialogs, possibly
from resources, no matter what they are to be used for.

	Making a dialog modeless is really a lot easier than people
seem to think.  Basically, you put the following code into your event
loop:

	if(IsDialogEvent(&myEvent))
	{
		if(DialogSelect(&myEvent, &whichDialog, &whichItem))
		{
			if(whichDialog == dialog1)
				DoDialog1(&myEvent, whichItem);
			else if (whichDialog == dialog2)
				DoDialog2(&myEvent, whichItem);
		}
	}
	else
	{
		HandleEvent(&myEvent);
	}

	which corresponds to the part of the modal dialog which looks
like:
	do
	{
		ModalDialog(NULL, &whichItem);
		DoDialog1(whichItem);
	} while(not terminated);

	The only change necessary to DoDialog? is to add at the top
something like:

	if((myEvent->what == keyDown) || (myEvent->what == autoKey))
	{
		key = message & charCodeMask;
		if((key == 0x0d) || (key = 0x03))
			TerminateDialog();
		if((key == '.') && (myEvent->modifiers & cmdKey))
			CancelDialog();
	}

	Pretty easy, huh?
>
>Marc Kaufman (kaufman@polya.stanford.edu)