Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucsd!ames!ncar!boulder!tramp!hartkopf
From: hartkopf@tramp.Colorado.EDU (Jeff Hartkopf)
Newsgroups: comp.sys.apple
Subject: IIGS filter procedure for dialog box
Message-ID: <12232@boulder.Colorado.EDU>
Date: 29 Sep 89 22:04:13 GMT
Sender: news@boulder.Colorado.EDU
Reply-To: hartkopf@tramp.Colorado.EDU (Jeff Hartkopf)
Organization: University of Colorado, Boulder
Lines: 55

I'm having problems figuring out how to use a filter procedure
for a dialog box (I'm using ORCA/C).  I need to pass a filter to
the ModalDialog() call so it will filter out certain keypresses:
in the dialog I have a line edit which I want to *only* to accept
hexadecimal digits (0-9, A-F, a-f), and ignore any other keypresses
(unless the keypress is RETURN, in which case I want the dialog to
handle that normally, by selecting the default button).  So I
figured I'd just tell the filter to check if the event is a keypress;
if so, if it's an invalid character (anything but RETURN and hex
characters), return TRUE (the filter handled the keypress, i.e., did
nothing), otherwise return FALSE (let the dialog manager handle the
keypress in the standard way).  The main problem is, when I call
ModalDialog(), it keeps calling my filter procedure repeatedly, never
drawing any of the controls in the dialog box.  Another question is,
once I get that part working, if the event's what field is keyDownEvt,
is the message field the character pressed?  Here's what I tried:


pascal word FILTER(GrafPortPtr dlog, EventRecord *evtptr, int *itemHit)
{
    #define c evtptr->message
    #define RETURN 13

    if (evtptr->what == keyDownEvt)
        if (c != RETURN && (c < '0' || (c > '9' && c < 'A') ||
                    (c > 'F' && c< 'a') || c > 'f'))  /* invalid */
            return (TRUE);  /* just ignore them */
    return (FALSE);

    #undef RETURN 13
    #undef c
}


/* later... */
...

int itemHit;
...

/* OK and CNCL are 2 buttons */
while ((itemHit = (int) ModalDialog((WordProcPtr) FILTER+0x80000000))
        != OK && itemHit != CNCL)
{
/* stuff */
}


Any suggestions would be greatly appreciated.


Jeff Hartkopf

Internet:
hartkopf@tramp.Colorado.EDU