Important: The information in this document is obsolete and should not be used for new development.
DialogSelect
After determining that an event related to an active modeless dialog box or an active movable modal dialog box has occurred, you can use theDialogSelectfunction to handle most of the events inside the dialog box.
FUNCTION DialogSelect (theEvent: EventRecord; VAR theDialog: DialogPtr; VAR itemHit: Integer): Boolean;
theEvent- An event record returned by an Event Manager function such as
WaitNextEvent.theDialog- A pointer to a dialog record for the dialog box where the event occurred.
itemHit- A number corresponding to the position of an item within the item list resource of the active dialog box.
DESCRIPTION
TheDialogSelectfunction handles most of the events relating to a dialog box. If the event is an activate or update event for a dialog box,DialogSelectactivates or updates it and returnsFALSE. If the event involves an enabled item,DialogSelectreturns a function result ofTRUE. In itsitemHitparameter, it returns the item number of the item selected by the user. In the parametertheDialog, it returns a pointer to
the dialog record for the dialog box where the event occurred. In all other cases, theDialogSelectfunction returnsFALSE. WhenDialogSelectreturnsTRUE, do whatever is appropriate as a response to the event involving that item in that particular dialog box; when it returnsFALSE, do nothing.Generally, only controls should be enabled in a dialog box; therefore your application should normally respond only when
DialogSelectreturnsTRUEafter the user clicks an enabled control, such as the OK button.The
DialogSelectfunction first obtains a pointer to the window containing the event. For update and activate events, the event record contains the window pointer. For other types of events,DialogSelectcalls the Window Manager functionFrontWindow.
The Dialog Manager then makes this window the current graphics port by calling the QuickDraw procedureSetPort. ThenDialogSelectprepares to handle the event by setting up text information if there are any editable text items in the active dialog box.If the event is an update event for a dialog box,
DialogSelectcalls the Window Manager procedureBeginUpdate, the Dialog Manager procedureDrawDialog,
and then the Window Manager procedureEndUpdate. When an item is a control defined in a control ('CNTL') resource, the rectangle added to the update region is the rectangle defined in the control resource, not the display rectangle defined in the item
list resource.The
DialogSelectfunction handles the event as follows:
- In response to an activate or update event for the dialog box,
DialogSelectactivates or updates its window and returnsFALSE.- If a key-down event or an auto-key event occurs and there's an editable text item
in the dialog box,DialogSelectuses TextEdit to handle text entry and editing,
andDialogSelectreturnsTRUE for a function result. In itsitemHit parameter, DialogSelect returnsthe item number.- If a key-down event or an auto-key event occurs and there's no editable text item in the dialog box,
DialogSelectreturnsFALSE.- If the user presses the mouse button while the cursor is in an editable text item,
DialogSelectresponds to the mouse activity as appropriate--that is, either by displaying an insertion point or by selecting text. If the editable text item is disabled,DialogSelectreturnsFALSE. If the editable text item is enabled,DialogSelectreturnsTRUE and in its itemHit parameter returnsthe item number. Normally, editable text items are disabled, and you use theGetDialogItemTextfunction to read the information in the items only after the OK button is clicked.- If the user presses the mouse button while the cursor is in a control,
DialogSelectcalls the Control Manager functionTrackControl. If the user releases the mouse button while the cursor is in an enabled control,DialogSelectreturnsTRUE for a function result and in its itemHit parameter returnsthe 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,
DialogSelectreturnsTRUE for a function result and in its itemHit parameter returnsthe item's number. Generally, only controls should be enabled. If your application creates a complex control--such as one that measures how far a dial is moved--your application must handle mouse events in that item before passing the event toDialogSelect.- If the user presses the mouse button while the cursor is in a disabled item, or if it is in no item, or if any other event occurs,
DialogSelectdoes nothing.- If the event isn't one that
DialogSelectspecifically checks for (if it's a null event, for example), and if there's an editable text item in the dialog box,DialogSelectcalls the TextEdit procedureTEIdleto make the insertion point blink.
SPECIAL CONSIDERATIONS
BecauseDialogSelecthandles only mouse-down events in a dialog box and key-down events in a dialog box's editable text items, you should handle other events
as appropriate before passing them toDialogSelect. Likewise, whenDialogSelectcallsTrackControl, it does not allow you to specify any 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 or a picture or an application-defined item that draws a control-like object in your dialog box. You must then test for and respond to those events yourself.Within dialog boxes, use the procedures
DialogCut,DialogCopy,DialogPaste, andDialogDeleteto support Cut, Copy, Paste, and Clear commands in editable text boxes.The
DialogSelectfunction is unreliable when running in versions of system software earlier than System 7. You shouldn't use this routine if you expect your application to run under earlier versions of system software.SEE ALSO
Listing 6-25 on page 6-79 illustrates the use ofDialogSelectto make the cursor blink in editable text items during null events; Listing 6-29 on page 6-92 illustrates the use ofDialogSelectto handle mouse events in a modeless dialog box; Listing 6-33 on page 6-96 illustrates the use ofDialogSelectto handle key-down events in editable text items; Listing 6-34 on page 6-98 illustrates the use ofDialogSelectto handle activate events in a modeless dialog box.