Contents

NSBeginAlertSheet

Creates and runs an alert sheet.

Declaration

extern void NSBeginAlertSheet(NSString *title, NSString *defaultButton, NSString *alternateButton, NSString *otherButton, NSWindow *docWindow, id modalDelegate, SEL didEndSelector, SEL didDismissSelector, void *contextInfo, NSString *msgFormat, ...);

Discussion

Creates and runs an alert sheet on docWindow, with the title of title, the text of msg, and buttons with titles of defaultButton, alternateButton, and otherButton.

The buttons are laid out on the lower-right corner of the sheet, with defaultButton on the right, alternateButton on the left, and otherButton in the middle. If title is nil or an empty string, a default localized title is used (“Alert” in English). If defaultButton is nil or an empty string, a default localized button title (“OK” in English) is used. For the remaining buttons, this function creates them only if their corresponding button title is non-nil.

A Command-D key equivalent for the “Don’t Save” button is provided, if one is found. The button titles are searched for the localized value for “Don’t Save.” If a match is found, that button is assigned a Command-D key equivalent, provided it is not the default button.

If you create a modal panel using runModal(for:) or beginSheet(_:modalFor:modalDelegate:didEnd:contextInfo:), you can assign the key equivalent yourself, using keyEquivalent and keyEquivalentModifierMask.

The msg argument is the message that’s displayed in the panel. It can use printf-style formatting characters; any necessary arguments should be listed at the end of the function’s argument list (after the msg argument). For more information on formatting characters, see the man page for printf.

When the modal session is ended, and before the sheet is dismissed, the didEndSelector is invoked on the modalDelegate. passing contextInfo. After the sheet is dismissed, the didDismissSelector is invoked on the modalDelegate, passing contextInfo. Typically, you will want to implement the didEndSelector but you may pass NULL for the didDismissSelector. The two selectors should be defined as follows:

sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void  *)contextInfo;
sheetDidDismiss:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void  *)contextInfo;

where sheet is the alert sheet, returnCode specifies which button the user pressed, and contextInfo is the same contextInfo passed into NSBeginAlertSheet. returnCode can be one of the following:

See Also

Functions