DialogSelect
DialogPtr * whichDlog ; receives identity of associated dialog short *itemHit ; receives identity of selected item
returns Was something selected?
returns control after every event, not just events related to an enabled item.
theEvent is the address of a 16-byte EventRecord that must contain an event related to a modeless dialog. It is normally a value obtained via
whichDlog is the address of a 32-bit DialogPtr (a.k.a WindowPtr, a.k.a identifying the dialog in which theEvent occurred (if the return
itemHit is the address of a 16-bit integer. Upon return, it contains the
identity of an item affected by theEvent (if the return value is
Returns: a Boolean; it indicates whether or not the event needs processing. It is one of:
FALSE (0) No processing is needed; the user clicked on a disabled item or no item at all. Or the event was an activate or update event and
DialogSelect handled it for you. The values of whichDlog and itemHit are un defined.
TRUE (1) Further processing is needed; the user clicked on an enabled item or typed a character (and an editText item exists). The
values of whichDlog and itemHit identify the dialog and item to
process.
IsDialogEvent report the occurance of a dialog event. It handles the preliminary processing of the event. It:
• processes update and activate events entirely and returns FALSE. • returns FALSE for clicks on disabled dialog items and clicks where no item exists.
• tracks enabled controls. If the control is selected (i.e., the mouse button
is released while inside the control), it returns TRUE. • activates and highlights any selection made in any enabled editText item,
• handles a keystroke by storing it into the current editText item (if any).
Note: it treats command-shifted keys as normal keystrokes. • calls TEIdle to maintain correct blinking of the insertion-point caret. When this call returns FALSE, you are done. You can continue with the event loop.
If it returns TRUE, it is up to you to determine what to do. For instance, an appropriate action when the user clicks a radio button is to turn on that
button and turn off all other such buttons (see SetCtlValue; see ModalDialog for an example of code). This would generate update events causing the controls to be redisplayed with the correct appearance.
dialog events is responsible for subsequent handling of all events. You may
need to check the nature of the event and do some processing before (or in
lieu of) calling DialogSelect in order to handle such events as command-shifted keystrokes (i.e., to implement cut-and-paste).
ensures correct blinking of the caret for editText items.
Example
#include <Dialogs.h>
void EventLoop(void);
DialogPtr myDlg; /* modeless dialog previously created via GetNewDialog */ void EventLoop() {
if (evtOccured) {
doDlgEvt( &theEvent );
continue;
}
switch ( theEvent.what ) {
case keyDown:
doKeyEvt( &theEvent ); /* handle other events */
/* ... process non-dialog events ... */
} /* end of switch */
} /* end of if */
} /* end of while */
}
{
short itemHit;
char theKey;
if ( evp->what == keyDown ) {
if ( evp->modifiers & cmdKey ) { /*command key pressed */
theKey = evp->message & charCodeMask;
if ( (theKey == 'C') || (theKey == 'c') ) {
/* ...do command-C via DlgCopy... */ }
/*.. check for and process other command-shifted keys if needed ... */
return(0);
/* don't let unwanted command-keys into DialogSelect() */
}
}
return(0); /* no extra work needed , just return */
if ( whichDlg == myDlg ) { /* process the interaction */
switch ( itemHit ) {
case ok:
processChanges( whichDlg ); /* user said to "DO IT" */
break;
case cancel:
break;
case LISTITEM:
if ( LClick( evp->where, evp->modifiers, theList ) ) { /*... process double click on the list ... */
}
break;
/* ... do whatever extra handling is needed for dialog items ... */
} /* end of switch */
}
/* ... process other dialogs that might be open ... */
}