DialogSelect
DialogSelect Process one modeless dialog event
#include <Dialogs.h> Dialog Manager
Boolean DialogSelect( theEvent, whichDlog, itemHit );
EventRecord *theEvent ; event obtained via GetNextEvent
DialogPtr * whichDlog ; receives identity of associated dialog
short *itemHit ; receives identity of selected item
returns Was something selected?
Call DialogSelect to process one event associated with a modeless dialog (use
it after calling IsDialogEvent). It differs from ModalDialog in that it
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
GetNextEvent and checked via IsDialogEvent.
whichDlog is the address of a 32-bit DialogPtr (a.k.a WindowPtr, a.k.a
GrafPtr). Upon return it contains the address of a DialogRecord
identifying the dialog in which theEvent occurred (if the return
value is TRUE).
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.

Notes: DialogSelect should be called directly after GetNextEvent and
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,
as with TEClick.
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.
Unlike ModalDialog, there is no filter function - the code that processes
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).
Note: It is normal to call IsDialogEvent and DialogSelect in your
event loop even when GetNextEvent returns FALSE (no event). This
ensures correct blinking of the caret for editText items.
Example
#include <Dialogs.h>
void EventLoop(void);
short doDlgEvt (EventRecord *theEvent );
void processChanges (DialogPtr whichDlg);
DialogPtr myDlg; /* modeless dialog previously created via GetNewDialog */
void EventLoop() {
EventRecord theEvent;
Boolean evtOccured;
while( TRUE ) {
evtOccured = GetNextEvent( everyEvent, & theEvent);
if (evtOccured) {
if ( IsDialogEvent( & theEvent) ) {
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 doDlgEvt(EventRecord *evp; )
{
DialogPtr whichDlg;
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() */
}
}
if (DialogSelect( evp, & whichDlg, &itemHit ) == FALSE )
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:
GlobalToLocal( &evp->where ); /* userItem is a list */
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 ... */
}