Important: The information in this document is obsolete and should not be used for new development.
ModalDialog
To handle events when you display a modal dialog box, use theModalDialogprocedure.
PROCEDURE ModalDialog (filterProc: ModalFilterProcPtr; VAR itemHit: Integer);
filterProc- A pointer to an event filter function.
itemHit- A number representing the position of the selected item in the item list resource for the active modal dialog box.
DESCRIPTION
Call theModalDialogprocedure immediately after displaying a modal dialog box. TheModalDialogprocedure assumes that a modal dialog box is displayed as the current port, andModalDialogrepeatedly handles events inside that port until an event involving an enabled dialog box item--such as a click in a radio button, for example--occurs. If the event is a mouse-down event outside the content region of the dialog box,ModalDialogemits the system alert sound and gets the next event. After receiving an event involving an enabled item,ModalDialogreturns its item number in theitemHitparameter. Your application should then do whatever is appropriate in response to an event in that item. Your application should continue callingModalDialoguntil the user selects the OK or Cancel button.For events inside the dialog box,
ModalDialogpasses the event to the event filter function pointed to in thefilterProcparameter before handling the event. When the event filter returnsFALSE,ModalDialoghandles the event. If the event filter function handles the event, the event filter function returnsTRUE, andModalDialogperforms no more event handling.If you set the
filterProcparameter toNIL, the standard event filter function is executed. The standard event filter function returnsTRUEand causesModalDialogto return item number 1, which is the number of the default button, when the user presses the Return key or the Enter key. However, your application should provide a simple event filter function that
You can use the same event filter function in most or all of your alert and modal
- returns
TRUEand the item number for the default button if the user presses the Return or Enter key- returns
TRUEand the item number for the Cancel button if the user presses the Esc key or the Command-period key combination- updates your windows in response to update events (this allows background applications to receive update events) and return
FALSE- returns
FALSEfor all events that your event filter function doesn't handle
dialog boxes.You can also use the event filter function specified in the
filterProcparameter to test for and respond to keyboard equivalents and more complex events--for instance, the user dragging the cursor within an application-defined item.To handle events,
ModalDialogcalls theIsDialogEventfunction. If the result ofIsDialogEventisTRUE, thenModalDialogcalls theDialogSelectfunction to handle the event. Unless the event filter function returnsTRUE,ModalDialoghandles the event as follows:
- In response to an activate or update event for the dialog box,
ModalDialogactivates or updates its window.- If the user presses the mouse button while the cursor is in an editable text item,
ModalDialogresponds to the mouse activity as appropriate--that is, either by displaying an insertion point or by selecting text. If a key-down event occurs and there's an editable text item,ModalDialoguses TextEdit to handle text entry and editing automatically. If the editable text item is enabled,ModalDialogreturns its item number after it receives either the mouse-down or key-down event. Normally, editable text items are disabled, and you use theGetDialogItemTextprocedure to read the information in the items only after the user clicks the OK button.- If the user presses the mouse button while the cursor is in a control,
ModalDialogcalls the Control Manager functionTrackControl. If the user releases the mouse button while the cursor is in an enabled control,ModalDialogreturns the control's item number. Your application should respond appropriately--for example, by performing a command after the user clicks the OK button.- If the user presses the mouse button while the cursor is in any other enabled item in the dialog box,
ModalDialogreturns the item's number, and your application should respond appropriately. Generally, only controls should be enabled. If your application creates a control more complex than a button, radio button, or checkbox, your application must handle events inside that item with your event filter function.- If the user presses the mouse button while the cursor is in a disabled item or in no item, or if any other event occurs,
ModalDialogdoes nothing.
SPECIAL CONSIDERATIONS
Do not useModalDialogfor movable modal dialog boxes (that is, those created with themovableDBoxProcwindow definition ID) or for modeless dialog boxes (that is, those created with thenoGrowDocProcwindow definition ID). If you want the Dialog Manager to assist you in handling events for movable modal and modeless dialog boxes, use theIsDialogEventandDialogSelectfunctions instead.The
ModalDialogprocedure calls the Event Manager functionGetNextEventwith a mask that excludes disk-inserted events. To receive disk-inserted events, your event filter function can call the Event Manager procedureSetSystemEventMask.When
ModalDialogcallsTrackControl, it does not allow you to specify the action procedure necessary for anything more complex than a button, radio button, or checkbox. If you need a more complex control (for example, one that measures how long the user holds down the mouse button or how far the user has moved an indicator), you can create your own control, a picture, or an application-defined item that draws a control- like object in your dialog box. You must then provide an event filter function that appropriately handles events in that item.SEE ALSO
Listing 6-26 on page 6-83 illustrates the use ofModalDialog. "Responding to Events in Editable Text Items" beginning on page 6-79 describes howModalDialoguses TextEdit to handle text entry and editing in editable text items. TheIsDialogEventandDialogSelectfunctions (which your application may use instead ofModalDialogfor modeless and movable modal dialog boxes) are described on page 6-131 and page 6-132, respectively. See the description ofMyEventFilteron page 6-138 for information about the event filter function your application should specify in thefilterProcparameter.The
GetNextEventandSetSystemEventMaskroutines are described in the chapter "Event Manager" in this book. See that chapter as well for a discussion of disk-inserted events. See "Responding to Events in Controls" on page 6-78 for a description of how your application should respond to events inside of controls; theTrackControlfunction is fully described in the chapter "Control Manager" in this book. Also see that chapter for information about creating your own nonstandard controls. TextEdit is described in the chapter "TextEdit" of Inside Macintosh: Text.