Article View: comp.sys.mac
Article #18058Help with modal dialog filterProc needed (med long)
From: Wade S. Blomgren
Date: Wed, 12 Aug 1987 19:35
Date: Wed, 12 Aug 1987 19:35
72 lines
2983 bytes
2983 bytes
I need some help troubleshooting a segment of code. System used: Mac+,
Dataframe20, LightspeedC version 2.01. The object is to present a
dialog box with some static text (disabled) and a single OK button
(enabled), and to use my own filterProc to accept keystrokes and save
them away, and simulate the OK button being hit if a return or an
enter is hit. (See Inside Mac Volume 1, page 415-416). The OK button
is Edit Item #1.
Consider the following snippets of the code. If I call ModalDialog with
a NULL ProcPtr, it behaves as you would expect, ie the OK button is
"hit" if you type return or enter. For this reason I figure the dialog
box's resources are all set up properly. When I use my filterProc as
suggested in IM, and I try to force an exit from the modal dialog when
a return or enter is hit, it just sits there. But it captures my characters
just fine, and when I actually hit the OK button with the mouse, it exits and
the characters are all there. Any returns or enters are just "gone", ie
it gets to the right place in the switch, (confirmed by debugging statements),
but the setting of the itemHit and the return(TRUE) don't abort the modal
dialog. So what is wrong with the filterProc? Any ideas?
Thanks,
Wade Blomgren, UCSD ACS (wade@sdacs.ucsd.edu or ...sdcsvax!sdacs!wade)
-------------------------------------
char data[16]; /* global storage for the characters typed */
int index; /* index into 'data' */
main()
{
/* Inits, etc, then call my testdialog function from the event loop */
}
int testdialog ()
{
int itemhit;
DialogPtr pdialog;
index = 0;
pdialog = GetNewDialog(5,0L,(Ptr) -1);
ModalDialog((ProcPtr) &MyFilter,&itemhit);
DisposDialog(pdialog);
/* look at the results in the data string here, then return */
}
/* the filterProc */
Boolean MyFilter(theDialog,theEvent,theItemHit)
DialogPtr theDialog;
EventRecord *theEvent;
int *theItemHit;
{
char c;
switch (theEvent->what) {
case keyDown:
c = (char) theEvent->message & 0x7f;
switch (c){
case 0x03: /* enter */
case 0x0d: /* return */
*theItemHit=1;
return(TRUE); /* dialog doesn't terminate when this is done - why?*/
break;
default:
data[index++] = c; /* accept all other characters - this works fine */
return(FALSE);
break;
} /* end of the keydown switch */
default:
return(FALSE);
} /* end of the event switch */
} /* end of the filterProc */
Technical Details
Message-ID:
<427@sdacs.ucsd.EDU>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!uunet!husc6!mit-eddie!ll-xn!ames!sdcsvax!sdcc6!sdacs!wadeShow Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!husc6!mit-eddie!ll-xn!ames!sdcsvax!sdcc6!sdacs!wade From: wade@sdacs.ucsd.EDU (Wade S. Blomgren) Newsgroups: comp.sys.mac Subject: Help with modal dialog filterProc needed (med long) Message-ID: <427@sdacs.ucsd.EDU> Date: Wed, 12-Aug-87 15:35:38 EDT Article-I.D.: sdacs.427 Posted: Wed Aug 12 15:35:38 1987 Date-Received: Sat, 15-Aug-87 01:34:03 EDT Organization: UCSD Academic Computing Services Lines: 72