Path: utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!tut.cis.ohio-state.edu!ucbvax!agate!saturn!ssyx.ucsc.edu!sirkm From: sirkm@ssyx.ucsc.edu (Greg Anderson) Newsgroups: comp.sys.mac.programmer Subject: What's wrong with this ModalDialog filterproc? Message-ID: <10125@saturn.ucsc.edu> Date: 26 Dec 89 16:29:35 GMT Sender: usenet@saturn.ucsc.edu Reply-To: sirkm@ssyx.ucsc.edu (Greg Anderson) Organization: UC Santa Cruz; Division of Social Sciences Lines: 80 I wrote a filterproc for ModalDialog that allows the user to cut, copy and paste to fields in a modal dialog box by pressing command-c, command-x and command-v, respectively. The filterproc works great--cutting and pasting work as expected. However, if the user presses , ModalDialog no longer returns with itemHit = 1. IM I-416 says: "A function result of TRUE tells ModalDialog to return immediately rather than handle the event; in this case, the filterProc function sets itemHit to the item number that ModalDialog should return." I thought that's what I did, but it doesn't work. When the user presses or the filterProc beeps (note the inclusion of a Sysbeep() in the filterProc), but the is added to the active textedit field rather than causing modaldialog to exit with itemHit = 1. I'm using the MPW C. Here's the filterProc: /*---------------------------------------------------------------------- | This filter, when passed to ModalDialog, will allow the user to | cut, copy and paste by pressing command-X, command-C or command-V, | respectively. ----------------------------------------------------------------------*/ pascal int cutPasteFilter( DialogPtr dlog, EventRecord *theEvent, int *itemHit ) { char key; /* * We only wish to filter keyDown events. */ if( theEvent->what == keyDown ) { key = theEvent->message & charCodeMask; /* * Is the command key down? */ if( theEvent->modifiers & cmdKey ) { switch( key ) { case 'x': ZeroScrap(); DlgCut( dlog ); if( TEToScrap() != noErr ) SysBeep(0); break; case 'c': ZeroScrap(); DlgCopy( dlog ); if( TEToScrap() != noErr ) SysBeep(0); break; case 'v': if( TEFromScrap() == noErr ) DlgPaste( dlog ); else SysBeep(0); break; } theEvent->what = nullEvent; return(false); } else if( (key == 13) || (key == 3) ) { SysBeep(0); *itemHit = 1; return(true); } } return(false); } ___\ /___ Greg Anderson ___\ /___ \ \ / / Social Sciences Computing \ \ / / \ /\/\ / University of California, Santa Cruz \ /\/\ / \/ \/ sirkm@ssyx.ucsc.edu \/ \/