TweetFollow Us on Twitter

MACINTOSH C
MACINTOSH C: A Hobbyist's Guide To Programming the Mac OS in C
Version 2.3

© 2000 K. J. Bricknell

< Go to Contents

(Chapter 8)

DIALOGS AND ALERTS

A link to the associated demonstration program listing is at the bottom of this page



Introduction

Alerts and alert boxes warn the user whenever an unusual or potentially undesirable situation occurs within your application. An alert box, unlike a dialog box, typically requires only the user's acknowledgment in order for your application to proceed.

Dialog boxes allow the user to provide additional information or to modify settings before your application carries out a command.

Types of Alerts and Alert Boxes

When an alert condition occurs, and depending on the nature of that condition, your application can simply play an alert sound or it can display an alert box. Your application can also base its response on the number of consecutive times the condition occurs, possibly playing an alert sound at first and subsequently displaying an alert box.

The system alert sound is a sound resource stored in the System file. It is played whenever the system software or your application uses the Sound Manager function SysBeep. The alert sound should be used for errors which are minor and immediately obvious, such as attempting to backspace past the left boundary of a text field.

Types of Alert Box

There are two types of alert box: the modal alert box and the movable modal alert box. Both types are shown at Fig 1.

Modal Alert Box

The fixed-position modal alert box places the user in the state, or mode, of being able to work only inside the alert box. The only response the user receives when clicking anywhere outside the alert box is the alert sound, and the user is not be able to bring another application to the front before first dismissing the alert box.

Movable Modal Alert Box

Movable modal alert boxes retain the essentially modal characteristic of their fixed-position counterpart, the main differences being that they allow the user to:

  • Drag the alert box so as to uncover obscured areas of an underlying window.

  • Bring another application to the front by clicking in one of the application's windows or by choosing the application's name from the Application menu.

Historical Note

The movable modal alert box was introduced with OS 8 and the Appearance Manager.

Generally speaking, the movable modal alert box is more appropriate for use in a multi-tasking environment. The modal alert box should be used only where there is justification for denying the user access to other running applications before it is dismissed.

Levels of Alerts

An alert box can display either one of three levels of alert, depending on the nature of the situation the alert box is reporting to the user. The three levels of alert, which are identified by icons supplied automatically by the system, are as follows:

  • Note Alert. The note alert is used to inform users of an occurrence which will not have serious consequences. Usually, a note alert simply offers information. Sometimes, a note alert may ask a simple question and provide, via the push buttons, a choice of responses.

    (Alert boxes)

  • Caution Alert. The caution alert is used to alert the user to an operation which may have undesirable results if it is allowed to continue. As shown at Fig 1, you should provide the user, via the push buttons, with a choice of whether to continue or stop the action.

  • Stop Alert. The stop alert is used to inform the user that a problem or situation is so serious that the action cannot be completed.

Custom Alert Boxes

You can also create custom alert boxes, which might contain your own icons (or, possibly, no icons). Custom alert boxes are typically used for About... boxes.

Types Of Dialogs Boxes

There are three types of dialog box, all of which are illustrated in the examples at Fig 2.

(Dialog boxes)

Modal Dialog Boxes

Fixed-position modal dialog boxes place the user in the state, or mode, of being able to work only inside the dialog box. The only response the user receives when clicking outside the dialog box is the alert sound. This type of dialog box looks like a modal alert box except that it may contain other types of controls in addition to push buttons.

Modal dialog boxes really belong to the era before the Mac OS became a multi-tasking operating system. Accordingly, they should be used only where there is justification for denying the user access to other running applications before they are dismissed.

Movable Modal Dialog Boxes

Movable modal dialog boxes retain the essentially modal characteristic of their fixed-position counterpart, the main differences being that they allow the user to:

  • Drag the dialog box so as to uncover obscured areas of an underlying window.

  • Bring another application to the front by clicking in one of the application's windows or by choosing the application's name from the Application menu.
The absence of close boxes and zoom boxes in the title bar of a movable modal dialog box visually suggests to the user that the dialog box is modal rather than modeless.

Modeless Dialog Boxes

Modeless dialog boxes look and behave very like document windows, except for their interior colour/pattern and the one-pixel frame just inside the window frame. Modeless dialog boxes do not require the user to respond before doing anything else. The user should be able to move the dialog box, activate and deactivate it, and close it like any document window; however, unlike document windows, the modeless dialog box should contain no scroll bars and no size box.

When you display a modeless dialog box, your application must allow the user to perform other operations without first dismissing the dialog.

Because of the difficulty of revoking the last action invoked from a modeless dialog box, it typically does not have a Cancel button, although it may have a Stop button to halt long operations such as searching and printing.

Window Types For Alerts and Dialogs

Fig 3 shows the seven available Appearance-compliant window types for alerts and dialogs and the constants that represent the window definition IDs for those types. Note that modeless dialogs are a special case in that a normal document window type is used.

(Window types)

The window definition ID is derived by multiplying the resource ID of the WDEF by 16 and adding the variation code to the result, as is shown in the following:

WDEF
Resource ID
Variation
Code
Window Definition ID
(Value)
Window Definition ID
(Constant)
65 0 65 * 16 + 0 = 1040 kWindowPlainDialogProc
65 1 65 * 16 + 1 = 1041 kWindowShadowDialogProc
65 2 65 * 16 + 2 = 1042 kWindowModalDialogProc
65 3 65 * 16 + 3 = 1043 kWindowMovableModalDialogProc
65 4 65 * 16 + 4 = 1044 kWindowAlertProc
65 5 65 * 16 + 5 = 1045 kWindowMovableAlertProc
64 0 64 * 16 + 0 = 1024 kWindowDocumentProc

Historical Note

The old pre-Mac OS 8, pre-Appearance Manager window types, and their Appearance-compliant equivalents, are as follows.
Pre-Appearance Appearance-Compliant Description
(None) kWindowAlertProc Modal alert box.
dBoxProc kWindowModalDialogProc Modal dialog box.
plainDBox kWindowPlainDialogProc Modal dialog box.
altDBoxProc kWindowShadowDialogProc Modal dialog box, shadow.
(None) kWindowMovableAlertProc Movable modal alert box.
movableDBoxProc kWindowMovableModalDialogProc Movable modal dialog box.
noGrowDocProc kWindowDocumentProc Document window and modeless dialog box.

Items in Alert and Dialog Boxes

You use item lists, which are resources of type 'DITL', to specify the items to appear in alert boxes and dialog boxes.

Alert boxes should usually contain only informative text and push button controls. Dialog boxes may contain informative or instructional text and controls.

Default Push Buttons

Your application should specify a default push button for every alert and dialog box. The default push button, which is visually identified by the default ring drawn around it, should be the one the user is more likely to click in most circumstances. However, if the most likely choice is at all destructive (for example, erasing a disk or deleting a file), you should consider defining the Cancel button as the default.

Removal of Alert and Dialog Boxes

The Dialog Manager automatically removes and disposes of an alert box when the user clicks its its OK or Cancel push button.

Your application should remove and dispose of a modal dialog box or movable modal dialog box only when the user clicks its OK or Cancel push button.

Your application should not remove a modeless dialog box unless the user clicks its close box or chooses Close from the File menu when the modeless dialog box is the active window. (Typically, a modeless dialog is simply hidden, not disposed of, when the user user clicks the close box or chooses Close.)

Creating Alert Boxes

Alert boxes may be created in one of two ways:

  • Using the functions Alert, NoteAlert, CautionAlert and StopAlert, which take descriptive information about the alert from alert ('ALRT') and extended alert ('alrx') resources. The resource ID of the 'ALRT' and 'alrt' resources must be the same, and is passed in the first parameter of these functions. You specify whether the alert is to be displayed in a modal alert box or a movable modal alert box by setting a particular flag in the 'alrx' resource.

  • Using the function StandardAlert, which optionally takes additional descriptive information about the alert from a standard alert structure (a structure of type AlertStdAlertParamRec). You specify whether the alert is to be a plain, note, caution, or stop alert in the first parameter of the StandardAlert call. You specify whether the alert is to be displayed in a modal alert box or a movable modal alert box by assigning a value to the first field of the standard alert structure.

Historical Note

The extended alert resource, the StandardAlert function, and the standard alert structure were introduced with Mac OS 8 and the Appearance Manager.

Regardless of which method is used to create the alert box, the standard note, caution, and stop icons automatically appear in the upper-left corner of alert boxes displaying, respectively, note, caution and stop alerts. When the Alert function is used, or when a plain alert is created using StandardAlert, no icon is displayed automatically, though you can display your own icon.

'ALRT' and 'alrx' Resources

When creating resources with Resorcerer, it is advisable that you refer to a diagram and description of the structure of the resource and relate that to the various items in the Resorcerer editing windows. Accordingly, the following describes the structure of the resources associated with the creation of alert boxes.

Structure of a Compiled 'ALRT' Resource

Fig 4 shows the structure of a compiled 'ALRT' resource.

('ALRT' resource)

The following describes the fields of the 'ALRT' resource:

Field Description
INITIAL RECTANGLE A rectangle which determines the dimensions of the content region of the alert box's window and, possibly, the position of the rectangle. (The last field of the resource usually specifies a position for the alert.)
ITEM LIST RESOURCE ID The ID of the item list resource that specifies the items, such as press buttons and static text, that are to be displayed in the alert box.
4TH STAGE ALERT INFORMATION Specifies the response when the user repeats the action that invokes the alert four or more consecutive times. (See Alert Stages, below.)
3RD STAGE ALERT INFORMATION Specifies the response when the user repeats the action that invokes the alert three consecutive times. (See Alert Stages, below.)
2ND STAGE ALERT INFORMATION Specifies the response when the user repeats the action that invokes the alert two consecutive times. (See Alert Stages, below.)
1ST STAGE ALERT INFORMATION Specifies the response for the first time the user invokes the action that invokes the alert. (See Alert Stages, below.)
POSITIONING SPECIFICATION Specifies the position of the alert box on the screen. If a positioning constant is not provided, the Dialog Manager places the alert box at the global coordinates you specify for the alert's rectangle. (See Positioning Specification, below.)

Alert Stages

You can define different responses for each of the four alert stages. This is most appropriate for stop alerts, that is, those which signify that an action cannot be completed, especially when that action has a high probability of being accidental. In such circumstances, you might specify that the system alert sound be played the first time the user makes the mistake and, subsequently, that the alert box be displayed as well. Note that every occurrence of the mistake after the fourth is treated as a fourth stage alert.

As will be seen, for each of the four alert stages, you can specify whether the default ring is drawn around the first or second push buttons in the alert, whether the alert box is to be displayed, and whether the system alert sound is to be played one, two, or four times, if at all.

Positioning Specification

The constants for the positioning specification field are as follows:

Constant Value Meaning
kWindowDefaultPosition 0x0000 Use initial location.
kWindowAlertPositionMainScreen 0x300A Alert position on main screen.
kWindowCenterParentWindow 0xA80A Centre on parent window.
kWindowAlertPositionParentWindow 0xB00A Alert position on parent window.
kWindowAlertPositionParentWindowScreen 0x700A Alert position on parent window screen.

Structure of a Compiled 'alrx' Resource

Fig 5 shows the structure of a compiled 'alrx' resource. You use this resource to provide additional features for your alert box, including movable modal behavior, theme-compliant backgrounds and controls, and control embedding hierarchies.

('alrx' resource)

The following describes the main fields of the 'alrx' resource:

Field Description
ALERT FLAGS Constants specifying the alert box's Appearance features. (See Alert Feature Flag Constants, below).
REFERENCE CONSTANT Any value that an application wishes to store here. For example, an application can store a number here that enables it to distinguish between a number of similar alert boxes. Since this information is stored in a window structure within the dialog structure, you can use GetWRefCon to determine this value.
WINDOW TYPE If this Boolean is set to 1 (true), the Dialog Manager specifies an Appearance-compliant window definition ID directly when drawing the alert box window.
TITLE A string representing the title of a movable alert box

Alert Feature Flag Constants

You can set the following bits in the alert flags field of an 'alrx' resource to specify the alert box's Appearance-compliant features:

Constant Bit Meaning
kAlertFlagsUseThemeBackground 0 If this bit is set, the Dialog Manager sets the alert box's background colour or pattern.
kAlertFlagsUseControlHierarchy 1 If this bit is set, the Dialog Manager creates a root control in the alert box and establishes an embedding hierarchy. All alert items automatically become controls once the embedding hierarchy is established.
kAlertFlagsAlertIsMovable 2 If this bit is set, the alert box is movable modal. The Dialog Manager handles movable modal behavior such as dragging the alert box by its title bar or switching out of the application by clicking in another one.
kAlertFlagsUseThemeControls 3 If this bit is set, the Dialog Manager creates Appearance-compliant controls in the alert box. Otherwise, push buttons, checkboxes, and radio buttons will be displayed in their pre-Appearance forms when system-wide Appearance is selected off.

Creating 'ALRT' and 'alrx' Resources Using Resourcer

Creating 'ALRT' Resources

Fig 6 shows an 'ALRT' resource being created with Resorcerer.

(Creating 'ALRT' resources)

Creating 'alrx' Resources

Fig 7 shows an 'alrx' resource being created with Resorcerer. Note that the resource ID of an 'alrx' resource must be the same as the resource ID of the 'ALRT' resource with which it is associated.

(Craeting 'alrx' resources)

The StandardAlert Function

When an alert box is created using the function StandardAlert, the alert box is automatically sized based on the amount of text passed in to it, and push buttons are automatically sized and located. StandardAlert does not provide for alert stages and corresponding alert sounds.

     OSErr  StandardAlert(AlertType inAlertType,
                          StringPtr inError,
                          StringPtr inExplanation,
                          AlertStdAlertParamPtr inAlertParam,
                          SInt16 *outItemHit);

     Returns: A result code.

inAlertType A constant indicating the type of alert box you wish to create (modal or movable modal).
inError A pointer to a Pascal string containing the primary error (label) text you wish to display.
inExplanation A pointer to a Pascal string containing the secondary (narrative) text you wish to display. Secondary text is displayed in the small system font. Pass NULL to indicate no secondary text.
inAlertParam A pointer to a standard alert structure (see below). Pass NULL to specify that you do not wish your alert box to incorporate any of the features that the standard alert structure provides.
outItemHit A pointer to an integer that, on output, will contain a value indicating the item number of the push button that was hit.

Standard Alert Structure

The standard alert structure is as follows:

     struct AlertStdAlertParamRec 

     {
       Boolean         movable;
       Boolean         helpButton;
       ModalFilterUPP  filterProc;
       StringPtr       defaultText;
       StringPtr       cancelText;
       StringPtr       otherText;
       SInt16          defaultButton;
       SInt16          cancelButton;
       UInt16          position;
     };
     typedef struct AlertStdAlertParamRec AlertStdAlertParamRec;
     typedef AlertStdAlertParamRec *AlertStdAlertParamPtr;

Field Descriptions

movable A Boolean value indicating whether or not the alert box is movable.
helpButton A Boolean value indicating whether or not the alert includes a Help button.
filterProc You may specify in this parameter a universal procedure pointer to an application-defined event filter function. If you set this parameter to NULL, the Dialog Manager uses the standard event filter function. (See Event Filter Functions For Modal and Movable Modal Alert and Dialog Boxes, below).
defaultText Text for the push button in the OK push button position. (See Alert Default Text Constants, below). The push button automatically sizes and positions itself in the alert box. To indicate that no push button should be displayed, pass NULL.
cancelText Text for the push button in the Cancel position. (See Alert Default Text Constants, below.) The push button automatically sizes and positions itself in the alert box. To indicate that no push button should be displayed, pass NULL.
otherText Text for the push button in leftmost position. (See Alert Default Text Constants, below.) The push button automatically sizes and positions itself in the alert box. To indicate that no push button should be displayed, pass NULL.
defaultButton Specifies which push button acts as the default push button. (See Alert Button Constants, below.)
cancelButton Specifies which push button acts as the Cancel push button. Can be 0. (See Alert Button Constants, below.)
position The alert box position, as defined by a window positioning specification. (See Positioning Specification, above, but note that, in this structure, the constant kWindowDefaultPosition is equivalent to kWindowAlertPositionParentWindowScreen.)

Alert Default Text Constants

You can use these constants in the defaultText, cancelText, and otherText fields of the standard alert structure to specify the default text for the OK, Cancel, and Don't Save push buttons.

Constant Value Meaning
kAlertDefaultOKText -1 The default text for the default (right) push button is "OK" on an English system. The text will vary depending upon the localisation of the user's system. Use this constant in the defaultText field of the standard alert structure.
kAlertDefaultCancelText -1 The default text for the Cancel (middle) push button is "Cancel" on an English system. The text will vary depending upon the localisation of your system. Use this constant in the cancelText field of the standard alert structure.
kAlertDefaultOtherText -1 The default text for the third (leftmost) push button is "Don't Save" for an English system. The text will vary depending upon the localisation of the user's system. Use this constant in the otherText field of the standard alert structure.

Alert Push Button Constants

You can use these constants in the defaultButton and cancelButton fields in the standard alert structure to specify which push buttons act as the default and Cancel push buttons in the standard alert structure. These constants are also returned in the itemHit parameter of StandardAlert.

Constant Value Meaning
kAlertStdAlertOKButton 1 The OK push button. The default text for this push button is "OK".
kAlertStdAlertCancelButton 2 The Cancel push button (optional). The default text for this push button is "Cancel".
kAlertStdAlertOtherButton 3 A third push button (optional). The default text for this push button is "Don't Save".
kAlertStdAlertHelpButton 4 The Help push button (optional).

Creating Dialog Boxes

Dialog boxes may be created in one of two ways:

  • Using the function GetNewDialog, which takes descriptive information about the dialog from dialog ('DLOG') and extended dialog ('dlgx') resources. The resource ID of the 'DLOG' and 'dlgx' resources must be the same, and is passed in the first parameter of this function.

  • Using NewDialog, NewColorDialog, or NewFeaturesDialog, which take descriptive information passed in the parameters of those functions.

Historical Note

The extended dialog resource and the NewFeaturesDialog function were introduced with OS 8 and the Appearance Manager. NewFeaturesDialog should be used to create Appearance-compliant dialogs. Unlike NewDialog and NewColorDialog, it has a flags parameter containing the same flags you would set in an extended dialog resource.

If NULL is specified as the second parameter in the GetNewDialog call, GetNewDialog itself creates a non-relocatable block for the dialog structure. Passing NULL is appropriate for modal and movable modal dialog boxes because you should dispose of the dialog box, and hence the associated dialog structure, when the user dismisses the dialog. However, in order to avoid heap fragmentation effects, you should ordinarily allocate your own memory for modeless dialog box dialog structures (just as you would for a window structure) and specify the pointer to that memory block in the second parameter of the GetNewDialog call.

Regardless of which method is used to create the dialog, a dialog structure and a window structure will be created, and a pointer to the dialog structure will be returned to the calling function.

The Dialog Structure

The dialog structure created by the GetNewDialog call is defined by the data type DialogRecord:

     struct DialogRecord 
     {
       WindowRecord window;     // Dialog's window record.
       Handle       items;      // Item list resource.
       TEHandle     textH;      // Current editable text item.
       SInt16       editField;  // Editable text item number minus 1.
       SInt16       editOpen;   // (Used internally.)
       SInt16       aDefItem;   // Default push button item number.
     };
     typedef struct DialogRecord DialogRecord;
     typedef DialogRecord *DialogPeek;

Note that the dialog structure includes a window structure field. The Dialog Manager sets the windowKind field of this window structure to kDialogWindowKind.

'DLOG' and 'dlgx' Resources

Structure of a Compiled 'DLOG' Resource

Fig 8 shows the structure of a compiled 'DLOG' resource and how it "feeds" the dialog structure.

('DLOG' resource)

The following describes the main fields of the 'DLOG' resource:

Field Description
RECTANGLE Determines the dialog box's dimensions and, possibly, its position. (The last field of the resource usually specifies a position for the dialog box.)
WINDOW DEFINITION ID The window definition ID. (See Window Types For Alerts and Dialogs, above.)
VISIBILITY If set to the the value of 1, the Dialog Manager displays this dialog box as soon as you call the GetNewDialog function. If set to the value of 0, the Dialog Manager does not display the dialog box until you call ShowWindow.
CLOSE BOX SPECIFICATION This specifies whether to draw a close box. Normally, this is set to the value of 1 only for a modeless dialog box.
REFERENCE CONSTANT Contains any value an application stores here. For example, an application can store a number that represents a dialog box type, or it can store a handle to a record that maintains state information about the dialog box or other window types. An application can use the SetWRefCon function to change this value and GetWRefCon to determine the current value.
ITEM LIST ID The resource ID of the item list resource associated with this dialog box.
WINDOW TITLE A Pascal string displayed in the dialog box's title bar (modeless and movable modal dialog boxes only).
POSITIONING SPECIFICATION Specifies the position of the dialog box on the screen. If a positioning constant is not provided, the Dialog Manager places the dialog box at the global coordinates you specify for the dialog box's rectangle. The same positioning constants as apply in the case of an alert box apply. (See Positioning Specification, above.)

Structure of a Compiled 'dlgx' Resource

Fig 9 shows the structure of a compiled 'dlgx' resource. This resource allows you to provide additional features for your dialog box, including movable modal behavior, theme-compliant backgrounds and controls, and embedding hierarchies.

('dlgx' resource)

The following describes the main field of the 'dlgx' resource:

Field Description
DIALOG FLAGS Constants that specify the dialog box's Appearance features. (See Dialog Feature Flag Constants, below.)

Dialog Feature Flag Constants

You can set the following bits in the dialog flags field of a 'dlgx' resource to specify the dialog box's Appearance-compliant features:

Constant Bit Meaning
kDialogFlagsUseThemeBackground 0 If this bit is set, the Dialog Manager sets the dialog box's background colour or pattern.
kDialogFlagsUseControlHierarchy 1 If this bit is set, the Dialog Manager creates a root control in the dialog box and establishes an embedding hierarchy. Any dialog items automatically become controls once the embedding hierarchy is established.
kDialogFlagsHandleMovableModal 2 If this bit is set, the dialog box is movable modal (in which case you must use kWindowMovableModalDialogProc window definition ID). The Dialog Manager handles movable modal behavior such as dragging the dialog box by its title bar or switching out of the application by clicking in another one.
kDialogFlagsUseThemeControls 3 If this bit is set, the Dialog Manager creates Appearance-compliant controls in the dialog box directly. Otherwise, push buttons, checkboxes, and radio buttons will be displayed in their pre-Appearance forms when system-wide Appearance is selected off.

Creating 'DLOG' and 'dlgx ' Resources Using Resorcerer

Creating 'dlgx' Resources

Fig 10 shows a 'dlgx' resource being created with Resorcerer.

(Creating 'dlgx' resources)

Creating 'DLOG' Resources

Fig 11 shows a 'DLOG' resource being created with Resorcerer.

(Creating 'DLOG' resources)

The NewFeaturesDialog Function

As previously stated, the function NewFeaturesDialog creates a dialog from the information passed in its parameters.

     DialogPtr  NewFeaturesDialog(void *inStorage,
                                  const Rect *inBoundsRect,
                                  ConstStr255Param inTitle,
                                  Boolean inIsVisible,
                                  SInt16 inProcID,
                                  WindowPtr inBehind,
                                  Boolean inGoAwayFlag,
                                  SInt32 inRefCon,
                                  Handle inItemListHandle,
                                  UInt32 inFlags);

     Returns: A pointer to the new dialog box, or NULL if the dialog box 
                 is not created

inStorage A pointer to the memory for the dialog structure. If you set this parameter to NULL, the Dialog Manager automatically allocates a nonrelocatable block in your application heap.
inBoundsRect A pointer to a rectangle, given in global coordinates, that determines the size and position of the dialog box. These coordinates specify the upper-left and lower-right corners of the dialog box.
inTitle A pointer to a text string used for the title of a modeless or movable modal dialog box. You can specify an empty string (not NULL) for a title bar that contains no text.
In C, you specify an empty string by two double quotation marks ("").
inIsVisible A flag that specifies whether the dialog box should be drawn on the screen immediately. If you set this parameter to false, the dialog box is not drawn until your application calls ShowWindow to display it.
inProcID The window definition ID for the type of dialog box. Use the kWindowModalDialogProc constant to specify modal dialog boxes, the kWindowMovableModalDialogProc constant to specify movable modal dialog boxes, and the kWindowDocumentProc constant to specify modeless dialog boxes.
inBehind A pointer to the window behind which the dialog box is to be placed on the desktop. Set this parameter to the window pointer (WindowPtr)-1 to bring the dialog box in front of all other windows.
inGoAwayFlag A Boolean value. If true, specifies that an active modeless dialog box has a close box in its title bar.
inRefCon A value that the Dialog Manager uses to set the refCon field of the dialog box's window structure. Your application may store any value here for any purpose. For example, your application can store a number that represents a dialog box type, or it can store a handle to a structure that maintains state information about the dialog box. You can use the Window Manager function SetWRefCon to change this value and GetWRefCon to determine its current value.
inItemListHandle A handle to an item list resource for the dialog box. You can get the handle by calling GetResource to read the item list resource into memory.
inFlags An unsigned 32-bit mask specifying the dialog box's Appearance-compliant feature flags. (See Dialog Feature Flag Constants, above.)

Although the inItemListHandle parameter specifies an item list ('DITL') resource for the dialog box, the corresponding dialog font table ('dftb') resource (see below) is not automatically accessed. You must explicitly set the dialog box's control font styles individually.

Items for Alert and Dialog Boxes

Preamble - Dialog Manager Primitives

Alert and dialog boxes contain items, such as push buttons, radio buttons, and checkboxes. Prior to the introduction of Mac OS 8 and the Appearance Manager, an actual control could be an item; however, items such as push buttons and radio buttons were not controls as such but rather Dialog Manager primitives.

These primitives may still be specified in item list resources (see below). However, under Appearance, when a root control has been created for the alert or dialog window, thus creating an embedding hierarchy for controls, the Dialog Manager replaces any primitives in the alert or dialog box with their control counterparts (except for the primitive called a user item).

In the era of the Appearance Manager, the situation where all items in an alert or dialog are controls has many advantages. For example, all controls within the alert or dialog can be activated and deactivated by simply activating and deactivating the root control. This includes edit text fields and static text fields. (It was previously not possible to display the old edit text and static text primitives in the dimmed deactivated mode.)

The continued use of the Dialog Manager primitives is not inconsistent with the concept of Appearance-compliant alert and dialog boxes provided that an embedding hierarchy has been established, thus causing the Dialog Manager to replace the primitives with (Appearance-compliant) controls.

The primitives, and their control equivalents, are as follows:

Dialog Manager Primitive Control Equivalent Comment
Button. Press button. -
Radio Button. Radio button. Used in dialog boxes only.
Checkbox. Checkbox. Used in dialog boxes only.
Edit Text. Edit text field. Used in dialog boxes only.
Static Text. Static text field. -
Icon. (An icon whose black and white resource was stored in an 'ICON' resource and whose colour version is stored in a 'cicn' resource with the same ID.) Icon control (no track variant). -
Picture. (Picture stored in a 'PICT' resource.) Picture control (no track variant). -
User Item. (An application-defined item. For example, an application-defined drawing function could be installed in a user item.) - Used in dialog boxes only.

The 'DITL' Resource

You use an item list ('DITL') resource to store information about all the items in an alert or dialog box. The 'DITL' resource ID is specified in the associated 'ALRT' or 'DLOG' resource. 'DITL' resources should be marked as purgeable.

Within a 'DITL' resource for an alert box you can specify static text, button, icon and picture primitives, or their control equivalents. In dialog boxes, any of the primitives, and any control, may be specified.

Items are usually referred to by their position in the item list, that is, by their item number.

Several independent dialog boxes may use the same 'DITL' resource. AppendDITL and ShortenDITL may be used to modify or customise copies of a shared item list resources for use in individual dialog boxes.

Fig 12 shows the structure of a compiled 'DITL' resource and one of its constituent items, in this case a control item.

('DITL' resource)

The following describes the fields of the 'DITL' resource and the control item:

Field Description
ITEM COUNT MINUS 1 This value is one less than the number of items defined in the resource.
FIRST ITEM ... LAST ITEM The format of each item depends on its type.
DISPLAY RECTANGLE Determines the size and location of the item in the alert box or dialog box. The rectangle is specified in coordinates local to the alert box or dialog box. (See Display Rectangles, below.)
ENABLE FLAG Specifies whether the item is enabled or disabled. If this bit is set, the item is enabled and the Dialog Manager reports to your application whenever a mouse-down event occurs inside the item.
ITEM TYPE Specifies the item type.
RESOURCE ID For a control item, this is the resource ID of the 'CNTL' resource.

Display Rectangles

For controls, the item's display rectangle becomes the control's enclosing rectangle. To match a control's enclosing rectangle to its own display rectangle, specify an enclosing rectangle in the 'CNTL' resource identical to the display rectangle specified in the 'DITL' resource.

When an item is a control defined in a control resource, the rectangle added to the update region is the display rectangle defined in the 'CNTL' resource, not the display rectangle specified in the 'DITL' resource.

Resorcerer has a Preferences setting which forces conformity between the display rectangle specified in the 'DITL' resource and the display rectangle specified in the 'CNTL' resource.

Other important aspects of display rectangles are as follows:

  • Edit Text Fields. For an edit text field, the display rectangle becomes the TextEdit destination rectangle and view rectangle (see Chapter 19 - Text and TextEdit). Word wrapping occurs within display rectangles that are large enough to contain multiple lines of text, and the text is clipped if there is more text than will fit in the rectangle.

  • Static Text Fields. For a static text field, the Dialog manager draws the text within the display rectangle just as it draws edit text fields.

  • Icon and Picture Controls. For an icon or picture larger than the display rectangle, the Dialog Manager scales the icon or picture to fit the display rectangle.

  • A click anywhere in the display rectangle is considered a click in that item.

Creating a 'DITL' Resource Using Resorcerer

Fig 13 shows a 'DITL' resource being created with Resorcerer. Two items are being edited (Item 1 and Item 2). Item 1 is a Dialog Manager primitive. Item 2 is a control.

(Creating 'DITL' resources)

Layout Guidelines For Alert and Dialog Boxes

Layout guidelines for items in alert and dialog boxes are contained in the Apple publication Mac OS 8 Human Interface Guidelines. These guidelines show, amongst other things, the required spacing between items.

Default Push buttons

Default Push button in Alert Boxes

The first item in the item list for an alert box created using an 'ALRT' resource should always be the OK push button, because the Dialog Manager will then automatically draw the default ring around that push button. This applies whether the item is a button primitive or a push button control. If a Cancel push button is required, it should be the second item.

Default Push button in Dialog Boxes

You should give every dialog a default push button, except for those which contain edit text fields that accept Return key presses. If you do not provide an event filter function (see Event Filter Functions For Modal and Movable Modal Alert and Dialog Boxes, below) which specifies otherwise, the Dialog Manager treats the first item in the item list resource as the default push button for the purpose of responding to Return and Enter key presses.

The Dialog Manager does not automatically draw the default ring around the default push button in dialog boxes.

Enabling and Disabling Items

You should not necessarily enable all items. For example, you typically disable static text field items and edit text field items because your application does not need to respond to clicks in those items.

Do not confuse a disabled item with a deactivated control. When a control is deactivated, the Control Manager dims it to show that it is deactivated. The Dialog Manager makes no visual distinction between a disabled and enabled item; it simply does not inform your application when the user clicks a disabled item.

Keyboard Focus

Edit text fields and clock controls accept input from the keyboard, and list boxes respond to certain key presses. The Dialog Manager automatically responds to mouse-down events and Tab key-down events intended to shift the keyboard focus between such items, indicating the current target by drawing a keyboard focus frame around that item. For edit text fields, the Dialog Manager also automatically displays the insertion point caret in the current target. For clock controls, the Dialog Manager, in addition to drawing the keyboard focus frame, also moves the keyboard target within the clock by highlighting the individual parts.

The Tab key moves the keyboard focus between such items in a sequence determined by their order in the item list. Accordingly, you should ensure that the item numbers of these items in the 'DITL' resource reflect the sequence in which you require them to be selected by successive Tab key presses.

Manipulating Items

Functions for Manipulating Items

Dialog Manager functions for manipulating items are as follows. Those introduced with Mac OS 8 and the Appearance Manager are shown in light blue.

Function Description
GetDialogItemAsControl Returns the control handle for an item in an embedding hierarchy. Should be used instead of GetDialogItem (see below) when an embedding hierarchy is established.
GetDialogItem Returns the the control handle (or, for application-defined draw functions, the function pointer), item type, and display rectangle of a given item. When an embedding hierarchy is present, you should generally use GetDialogItemAsControl instead of GetDialogItem to get a handle to the control.

When called on a static text field item, GetDialogItem returns a handle to the text, not to the control, and thus may still be used to get a handle to the text of static text fields. (When called on a static text field item, GetDialogItemAsControl returns a handle to the control, not to the text.)

SetDialogItem When an embedding hierarchy does not exist, sets the item type and the display rectangle of an item or, for application-defined items, the draw function of an item.

When an embedding hierarchy exists, you cannot change the type or handle of an item, but application-defined item drawing functions can still be set.

HideDialogItem Hides the given item.
ShowDialogItem Re-displays a hidden item.
GetDialogItemText Returns the text of an edit or static text field item.
SelectDialogItemText Selects the text of an edit text field item. When embedding is on, you should pass in the control handle produced by a call to GetDialogItemAsControl. When embedding is not on, you should pass in the handle produced by a call to GetDialogItem.
FindDialogItem Determines the item number of an item at a particular location in a dialog box.
MoveDialogItem Moves a dialog item to a specified location in a window. Ensures that, if the item is a control, the control rectangle and the dialog item rectangle (maintained by the Dialog Manager) are always the same.
SizeDialogItem Resizes a dialog item to a specified size. If the dialog item is a control, the control rectangle and the dialog item rectangle (maintained by the Dialog Manager) are always the same.
CountDITL Counts items in a dialog box.
AppendDITL Adds items to a dialog box. (See Append Method Constants, below.)
ShortenDITL Removes items from a dialog box.
ParamText Substitutes up to four different text strings in static text field items.
GetAlertStage Returns the stage of the last occurrence of an alert.
ResetAlertStage Resets the stage of the last occurrence of an alert.

Append Method Constants

The AppendDITL and ShortenDITL functions are especially useful where several dialog boxes share the same 'DITL' resource and you want to add or remove items as appropriate for individual dialog boxes. When you call AppendDITL , you specify a new 'DITL' resource to append to the dialog box's existing 'DITL' resource. You also specify where the Dialog Manager should display the new items by using one of the following constants in the AppendDITL call:

Constant Value Description
overlay 0 Overlay existing items. Coordinates of the display rectangle are interpreted as local coordinates within the dialog box.
AppendDITLRight 1 Append at right. Display rectangles are interpreted as relative to the upper-right coordinate of the dialog box.
appendDITLBottom 2 Append at bottom. Display rectangles are interpreted as relative to the lower-left coordinate of the dialog box.

As an alternative to passing these constants, you can pass a negative number to AppendDITL, which appends the items relative to an existing item in the dialog box. The absolute value of this number is interpreted as the item in the dialog box relative to which the new items are to be positioned. For example, -2 would cause the display rectangles of the appended items to be offset from the upper-left corner of item number 2 in the dialog box.

AppendDITL modifies the contents of the dialog box (for instance, by enlarging it). To use the unmodified version of the dialog box at a later time, you should call ReleaseResource to release the memory occupied by the appended item list.

Getting and Setting The Text in EditText Field and Static Text Field Items

Dialog Manager functions for getting text from, and setting the text of, edit text field and static text field items are as follows:

Function Description
GetDialogItemText Gets a copy of the text in static text field and edit text field items. Pass in the handle produced by a call to GetDialogItem, which gets a handle the text in this instance, not to the control.
SetDialogItemText Sets the text string for static text and edit text fields. When embedding is on, you should pass in the control handle produced by a call to GetDialogItemAsControl. If embedding is not on, pass in the handle produced by GetDialogItem.

The function ParamText may also be used to set the text string in a static text field in an alert box or dialog box. A common example is the inclusion of the window title in static text such as "Save changes to the document ... before closing?". In this case, the window's title could be retrieved using GetWTitle and inserted by ParamText at the appropriate text replacement variable (^0, ^1, ^2 or ^3) specified in the static text field item in the 'DITL' resource.

Since there are four text replacement variables, ParamText can supply up to four text strings for a single alert or dialog box.

Setting the Font For Controls in an Alert or Dialog Box - 'dftb' Resources

When an embedding hierarchy is established in a dialog box, you can specify the initial font settings for all controls in an alert or dialog box by creating a dialog font table resource (resource type 'dftb') with the same resource ID as the alert or dialog's 'DITL' resource. When a 'dftb' resource is read in, the control font styles are set, and the resource is marked purgeable.

The 'dftb' resource is the resource-based equivalent of the programmatic method of setting a control's font using the function SetControlFontStyle described at Chapter 7 - Introduction To Controls.

Structure of a Compiled 'dftb' Resource

Fig 14 shows the structure of a compiled 'dftb' resource and of a constituent dialog font table entry.

('dftb' resource)

The following describes the main fields of the 'dftb' resource and the dialog control font entry:

Field Description
NUMBER OF ENTRIES An integer that specifies the number of entries in the resource. Each entry is a dialog control font structure.
FIRST DIALOG CONTROL FONT ENTRY... LASTDIALOG CONTROL FONT ENTRY A series of dialog control font structures, each of which consist of type, dialog font flags, the font ID, font size, font style, text mode, justification, text color, background color, and font name.
TYPE An integer that specifies whether there is font information for the dialog or alert item in the 'DITL'. If you specify a value of 0, there is no font information for the item in the corresponding 'DITL', and no data follows. If you specify a value of 1, there is font information for the item, and the rest of the structure is read. You can cause entries to be skipped by setting this value to 0.
DIALOG FONT FLAGS You can use one or more of these flag constants to specify which other fields in the dialog font table should be used. (See Dialog Font Flag Constants, below.)
FONT ID If the kDialogFontUseFontMask bit is set to 1, then this element will contain an integer indicating the ID of the font family to use. (See Meta Font Constants, below, for more information about the constants that you can specify.) If this bit is set to 0, then the system default font is used.
FONT SIZE If a constant representing the system font, small system font, or small emphasized system font is specified in the Font ID field, this field is ignored. If the kDialogFontUseSizeMask bit is set, this field should contain an integer representing the point size of the text. If the kDialogFontAddSizeMask bit is set, this value will contain the size to add to the current point size of the text.
STYLE If the kDialogFontUseFaceMask bit is set, then this element should contain an integer specifying the text style to describe which styles to apply to the text. You can use one or more of the following style data type mask constants to specify font style:
Bit Value Style
0x00 Normal
0x01 Bold
0x02 Italic
0x04 Underline
0x08 Outline
0x10 Shadow
0x20 Condense
0x40 Extend
TEXT MODE If the kDialogFontUseModeMask bit is set, then this element should contain an integer specifying how characters are drawn. (See Chapter 12 - Drawing With QuickDraw for a discussion of transfer modes.)
JUSTIFICATION If the kDialogFontUseJustMask bit is set, then this element should contain an integer specifying text justification (left, right, centered, or system-justified).
TEXT COLOR If the kDialogUseFontForeColorMask bit is set, then this element should contain a colour to use when drawing the text.
BACKGROUND COLOR If the kDialogFontUseBackColorMask bit is set, then this element should contain a colour to use when drawing the background behind the text. In certain text modes, background colour is ignored.
FONT NAME If the kDialogFontUseFontNameMask bit is set, then this element should contain a Pascal string representing the font name to be used. This overrides the font ID.

Dialog Font Flag Constants

You can set the following bits in the the dialog font flags field of a dialog control font entry to specify the fields in the entry that should be used

Constant Value Meaning
kDialogFontNoFontStyle 0x0000 No font style information is applied.
kDialogFontUseFontMask 0x0001 The font ID specified in the Font ID field of the dialog font table is applied.
kDialogFontUseFaceMask 0x0002 The font style specified in the Style field of the dialog font table is applied.
kDialogFontUseSizeMask 0x0004 The font size specified in the Font Size field of the dialog font table is applied.
kDialogFontUseForeColorMask 0x0008 The text color specified in the Text Color field of the dialog font table is applied. This flag only applies to static text controls.
kDialogFontUseBackColorMask 0x0010 The background color specified in the Background Color field of the dialog font table is applied. This flag only applies to static text controls.
kDialogFontUseModeMask 0x0020 The text mode specified in the Text Mode field of the dialog font table is applied.
kDialogFontUseJustMask 0x0040 The text justification specified in the Justification field of the dialog font table is applied.
kDialogFontUseAllMask 0x00FF All flags in this mask will be set except kDialogFontAddFontSizeMask and kDialogFontUseFontNameMask.
kDialogFontAddFontSizeMask 0x0100 The Dialog Manager will add a specified font size to the existing font size indicated in the Font Size field of the dialog font table resource.
kDialogFontUseFontNameMask 0x0200 The Dialog Manager will use the string in the Font Name field for the font name instead of a font ID.

Meta Font Constants

You can use the following meta font constants in the font ID field of a dialog control font entry to specify to specify the style, size, and font family of a control's font. You should use these meta font constants whenever possible because the system font can change, depending upon the current theme. If none of these constants are specified, the control uses the system font unless a control with a variant that uses the window font has been specified.

Constant Value Meaning In Roman Script System
kControlFontBigSystemFont 0x0001 Use the system font. (For the Roman script system, this is Charcoal 12.)
kControlFontSmallSystemFont 0x0002 Use the small system font. (For the Roman script system, this is Geneva 10.)
kControlFontSmallBoldSystemFont 0x0004 Use the small emphasized system font. (For the Roman script system, this is Geneva 10.)

Another advantage of using these meta font constants is that you can be sure of getting the correct font on a Macintosh using a different script system, such as kanji.

Historical Note

Prior to the introduction of Mac OS 8 and the Appearance Manager, icon colour table ('ictb') resources were used to specify the colour, typface, font style, and font size for items in an alert or dialog box. When an embedding hierarchy is present, the 'ictb' resource is ignored.

Creating a 'dftb' Resource Using Resorcerer

Fig 15 shows a dialog control font entry in a 'dftb' resource being edited with Resorcerer.

(Creating 'dftb' resource)



Go to Part 2
 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Go from lowly lizard to wicked Wyvern in...
Do you like questing, and do you like dragons? If not then boy is this not the announcement for you, as Loongcheer Game has unveiled Quest Dragon: Idle Mobile Game. Yes, it is amazing Square Enix hasn’t sued them for copyright infringement, but... | Read more »
Aether Gazer unveils Chapter 16 of its m...
After a bit of maintenance, Aether Gazer has released Chapter 16 of its main storyline, titled Night Parade of the Beasts. This big update brings a new character, a special outfit, some special limited-time events, and, of course, an engaging... | Read more »
Challenge those pesky wyverns to a dance...
After recently having you do battle against your foes by wildly flailing Hello Kitty and friends at them, GungHo Online has whipped out another surprising collaboration for Puzzle & Dragons. It is now time to beat your opponents by cha-cha... | Read more »
Pack a magnifying glass and practice you...
Somehow it has already been a year since Torchlight: Infinite launched, and XD Games is celebrating by blending in what sounds like a truly fantastic new update. Fans of Cthulhu rejoice, as Whispering Mist brings some horror elements, and tests... | Read more »
Summon your guild and prepare for war in...
Netmarble is making some pretty big moves with their latest update for Seven Knights Idle Adventure, with a bunch of interesting additions. Two new heroes enter the battle, there are events and bosses abound, and perhaps most interesting, a huge... | Read more »
Make the passage of time your plaything...
While some of us are still waiting for a chance to get our hands on Ash Prime - yes, don’t remind me I could currently buy him this month I’m barely hanging on - Digital Extremes has announced its next anticipated Prime Form for Warframe. Starting... | Read more »
If you can find it and fit through the d...
The holy trinity of amazing company names have come together, to release their equally amazing and adorable mobile game, Hamster Inn. Published by HyperBeard Games, and co-developed by Mum Not Proud and Little Sasquatch Studios, it's time to... | Read more »
Amikin Survival opens for pre-orders on...
Join me on the wonderful trip down the inspiration rabbit hole; much as Palworld seemingly “borrowed” many aspects from the hit Pokemon franchise, it is time for the heavily armed animal survival to also spawn some illegitimate children as Helio... | Read more »
PUBG Mobile teams up with global phenome...
Since launching in 2019, SpyxFamily has exploded to damn near catastrophic popularity, so it was only a matter of time before a mobile game snapped up a collaboration. Enter PUBG Mobile. Until May 12th, players will be able to collect a host of... | Read more »
Embark into the frozen tundra of certain...
Chucklefish, developers of hit action-adventure sandbox game Starbound and owner of one of the cutest logos in gaming, has released their roguelike deck-builder Wildfrost. Created alongside developers Gaziter and Deadpan Games, Wildfrost will... | Read more »

Price Scanner via MacPrices.net

13-inch M2 MacBook Airs in stock today at App...
Apple has 13″ M2 MacBook Airs available for only $849 today in their Certified Refurbished store. These are the cheapest M2-powered MacBooks for sale at Apple. Apple’s one-year warranty is included,... Read more
New today at Apple: Series 9 Watches availabl...
Apple is now offering Certified Refurbished Apple Watch Series 9 models on their online store for up to $80 off MSRP, starting at $339. Each Watch includes Apple’s standard one-year warranty, a new... Read more
The latest Apple iPhone deals from wireless c...
We’ve updated our iPhone Price Tracker with the latest carrier deals on Apple’s iPhone 15 family of smartphones as well as previous models including the iPhone 14, 13, 12, 11, and SE. Use our price... Read more
Boost Mobile will sell you an iPhone 11 for $...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering an iPhone 11 for $149.99 when purchased with their $40 Unlimited service plan (12GB of premium data). No trade-in is required... Read more
Free iPhone 15 plus Unlimited service for $60...
Boost Infinite, part of MVNO Boost Mobile using AT&T and T-Mobile’s networks, is offering a free 128GB iPhone 15 for $60 per month including their Unlimited service plan (30GB of premium data).... Read more
$300 off any new iPhone with service at Red P...
Red Pocket Mobile has new Apple iPhones on sale for $300 off MSRP when you switch and open up a new line of service. Red Pocket Mobile is a nationwide MVNO using all the major wireless carrier... Read more
Clearance 13-inch M1 MacBook Airs available a...
Apple has clearance 13″ M1 MacBook Airs, Certified Refurbished, available for $759 for 8-Core CPU/7-Core GPU/256GB models and $929 for 8-Core CPU/8-Core GPU/512GB models. Apple’s one-year warranty is... Read more
Updated Apple MacBook Price Trackers
Our Apple award-winning MacBook Price Trackers are continually updated with the latest information on prices, bundles, and availability for 16″ and 14″ MacBook Pros along with 13″ and 15″ MacBook... Read more
Every model of Apple’s 13-inch M3 MacBook Air...
Best Buy has Apple 13″ MacBook Airs with M3 CPUs in stock and on sale today for $100 off MSRP. Prices start at $999. Their prices are the lowest currently available for new 13″ M3 MacBook Airs among... Read more
Sunday Sale: Apple iPad Magic Keyboards for 1...
Walmart has Apple Magic Keyboards for 12.9″ iPad Pros, in Black, on sale for $150 off MSRP on their online store. Sale price for online orders only, in-store price may vary. Order online and choose... Read more

Jobs Board

Solutions Engineer - *Apple* - SHI (United...
**Job Summary** An Apple Solution Engineer's primary role is tosupport SHI customers in their efforts to select, deploy, and manage Apple operating systems and Read more
DMR Technician - *Apple* /iOS Systems - Haml...
…relevant point-of-need technology self-help aids are available as appropriate. ** Apple Systems Administration** **:** Develops solutions for supporting, deploying, Read more
Omnichannel Associate - *Apple* Blossom Mal...
Omnichannel Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Operations Associate - *Apple* Blossom Mall...
Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.