MACINTOSH C CARBON: A Hobbyist's Guide To Programming the Macintosh in C
Version 1.0
© 2001 K. J. Bricknell
CHAPTER 14
MORE ON CONTROLS

Introduction
Chapter 7 - Introduction to Controls introduced the subject of controls and addressed the basic controls (push buttons, checkboxes, radio buttons, scroll bars, and pop-up menu buttons), primary group boxes (text title variant) and user panes. This chapter revisits group boxes and user panes and addresses the many remaining controls.
The controls addressed in this chapter are as follows:
Bevel button |
Image well |
Tab |
Edit text |
Slider |
Group boxes |
Clock |
Progress and relevance bar |
Little arrows |
Disclosure triangle |
Picture |
Icon |
Window header |
Placard |
Static text field |
Separator line |
Pop-up arrow |
Radio group |
Chasing arrows |
User pane |
Scrolling text box |
Disclosure button |
Edit Unicode text |
Round button |
|
The data browser control is not addressed in this book. The one remaining control (the list box) is addressed at Chapter 22.
The progress bar will be described in this chapter and the indeterminate variant demonstrated in the associated demonstration program. However, because the use of the determinate variant is ordinarily associated with the matter of scanning for a Command-period event, the demonstration of that particular variant has been held over to the demonstration program associated with Chapter 25.
Preamble - Review of Control Basics
Recall from Chapter 7 that:
- Control definition functions (CDEFs) determine the appearance and behaviour of controls.
- Two new features introduced with Mac OS 8 were embedding and latency. Embedding hierarchies have implications for drawing order and hit testing.
- Another feature introduced with Mac OS 8 was read and write access to the various attributes of a control. Each piece of information that a particular CDEF allows access to is referenced by a control data tag. Control data tag constants are passed in the inTagName parameter of the getter and setter functions SetControlData and GetControlData.
- FindControl is used to determine whether a mouse-down event occurred in a control and, if so, which control. FindControl returns a control part code identifying the part of the control in which the mouse-down occurred. kControlNoPart (0) is returned if the mouse-down occurred where no enabled control exists. TrackControl or HandleControlClick are used to handle user interaction with a control as long as the user holds the mouse button down. These two functions return kControlNoPart if the cursor is outside the control or control part when the mouse button is released or the relevant control part code if the user releases the mouse button while the cursor is still inside the control or control part.
- The font for any control can be set independently of the system or window font.
- The pop-up menu button differs from the other basic controls in that the control's initial, minimum, and maximum values do not actually represent initial, minimum and maximum values as such. For example, the minimum value field of the 'CNTL' resource for a pop-up button is used to specify the resource ID of the 'MENU' resource utilised by the control.
The use of the initial, minimum, and maximum fields for purposes other than control values as such also applies to most of the controls addressed in this chapter.
More on Embedding
As stated at Chapter 8, if the kDialogFlagsUseControlHierarchy feature bit is set in a dialog's 'dlgx' resource, the Dialog Manager creates a root control in the dialog box and establishes an embedding hierarchy.
The Dialog Manager uses AutoEmbedControl to position dialog items in an embedding hierarchy based on both visual containment and the order of the items in the item list. As items are added to a dialog box during creation, controls that already exist in the window will be containers for new controls if they both visually contain the control and are themselves embedder controls. For this reason, you should place the largest embedder controls at the beginning of the item list. As an example, the Dialog Manager will automatically embed radio buttons in a group box if, firstly, the radio buttons visually "fit" inside the group box and, secondly, the group box precedes the radio buttons in the item list.

Control Descriptions

Bevel Buttons
A bevel button is a rectangular control with a bevelled edge that can include text, an icon, a picture, or a combination of text and an icon or picture. Bevel buttons can be made to behave in a number of different ways: they can behave like push buttons; in sets, they can behave like radio buttons or checkboxes; if a menu is attached, they behave like pop-up menu buttons. Typical bevel buttons are shown at Fig 1.
Note that, on Mac OS X, bevel button have square corners by default but can be made rounded using the function SetControlData with the kControlBevelButtonKindTag tag (see Other Control Data Tag Constants, below).
Note also that, while three bevel sizes are available on Mac OS 8/9, only one bevel size is available on Mac OS X.
Variants and Control Definition IDs
The bevel button CDEF resource ID is 2. The six available variants and their control definition IDs are as follows:
Variant |
Var Code |
Control Definition ID |
With small (2 pixel wide) bevel. (Pop-up menu, if any, below.) |
0 |
32 |
kControlBevelButtonSmallBevelProc |
With medium (3 pixel wide) bevel. (Pop-up menu, if any, below.) |
1 |
33 |
kControlBevelButtonNormalBevelProc |
With large (4 pixel wide) bevel. (Pop-up menu, if any, below.) |
2 |
34 |
kControlBevelButtonLargeBevelProc |
With small (2 pixel wide) bevel. Pop-up menu on right. |
4 |
36 |
KControlBevelButtonSmallBevelProc + kControlBevelButtonMenuOnRight |
With medium (3 pixel wide) bevel. Pop-up menu, if any, on right. |
5 |
37 |
KControlBevelButtonNormalBevelProc + kControlBevelButtonMenuOnRight |
With large (4 pixel wide) bevel. Pop-up menu, if any, on right. |
6 |
38 |
KControlBevelButtonLargeBevelProc + kControlBevelButtonMenuOnRight |
Note that, while three bevel sizes are available on Mac OS 8/9, bevel button will always be displayed with one bevel size on Mac OS X regardless of which of the first three variants is used.
For bevel buttons containing text, if the constant kControlUsesOwningWindowsFontVariant is added to the variation code, the text will appear in the window's font.
Control Values
The following lists the initial, minimum, and maximum value settings for bevel buttons:
Control Value |
Content |
Initial |
If you wish to attach a menu, the menu ID. If no menu, 0. |
Minimum |
High byte specifies behaviour (see Bevel Button Behaviour Constants, and Bevel Button Menu Constants, below). Low byte specifies content type (see Bevel Button and Image Well Content Type Constants, below). |
Maximum |
Resource ID of bevel button's content if resource-based. |
Note that bevel buttons have two values: the value of the bevel button and, if a menu has been attached, the value of the menu.
Bevel Button Behaviour Constants
The following bevel button behaviour constants apply to the high byte of a bevel button's minimum value:
Constant |
Value |
Description |
| kControlBehaviorPushbutton |
0 |
Button pops up after being clicked. This constant is used when push button behaviour is required. |
| kControlBehaviorToggles |
0x0100 |
Button toggles state automatically when clicked. This constant is used when checkbox or radio button behaviour is required. |
| kControlBehaviorSticky |
0x0200 |
When clicked, button stays down until application sets control's value to 0. This behaviour is useful in tool palettes. |
| kControlBehaviorOffsetContents |
0x8000 |
Button contents are offset (one pixel down and to the right) when button is clicked. (Some users consider that this behaviour gives a bevel button a more realistic "feel".) |
Bevel Button Behaviour Constants (Menus)
The following bevel button behaviour constants (menus) apply to the high byte of a bevel button's minimum value:
Constant |
Value |
Description |
| kControlBehaviorSingleValueMenu |
0 |
Menu contains commands, not choices, and should not be marked with a checkmark. Overrides the kControlBehaviorMultiValueMenu bit. |
| kControlBehaviorMultiValueMenu |
0x4000 |
Menus are multi-valued. The user can toggle entries in the button's menu and have multiple items checked. The button does not maintain the menu value as it normally would. When this bit is set, the menu value accessed using GetControlData with the kControlBevelButtonMenuValueTag will return the value of the last menu item chosen. |
Button and Image Well Content Type Constants
The following button and image well content type constants apply to the low byte of a bevel button's minimum value:
Constant |
Value |
Description |
| kControlContentTextOnly |
0 |
Content type is text only. |
| kControlContentIconSuiteRes |
1 |
Content type is an icon suite resource ID. |
| kControlContentCIconRes |
2 |
Content type is a colour icon resource ID. |
| kControlContentPictRes |
3 |
Content type is a picture resource ID. |
| kControlContentIconSuiteHandle |
129 |
Content type is an icon suite handle. |
| kControlContentCIconHandle |
130 |
Content type is a colour icon handle. |
| kControlContentPictHandle |
131 |
Content type is a picture handle. |
| kControlContentIconRef |
132 |
Content type is an icon reference. |
You can also use these constants in the contentType field of the bevel button and image well content structure (see below). You can then pass a pointer to this structure in the inBuffer parameter of GetControlData and SetControlData to get and set the resource ID (for resource-based content), handle (for handle-based content), or reference (for reference-based content) of a colour icon, icon suite, picture, or icon reference in a bevel button.
 |
Note that resource-based content is owned by the control, while handle-based content is owned by you. The control definition function will not dispose of handle-based content. If you replace handle-based content with resource-based content on the ßy, you must dispose of the handle properly to avoid a memory leak. |
Control Data Tag Constant - Content Type
The control data tag constant relevant to content type in bevel buttons is as follows:
Control Data Tag Constant |
Meaning and Data Type Returned or Set |
| kControlBevelButtonContentTag |
Gets or sets a bevel button's content type for drawing. (See Bevel Button and Image Well Content Type Constants, above. See also The Bevel Button and Image Well Structure, below.) Data type returned or set: ControlButtonContentInfo structure |
Bevel Button Alignment and Placement Constants, and Associated Control Data Tag Constants
By calling SetControlData with certain control data tag constants, and with certain constants passed in the inData parameter, you can specify the alignment of icons, pictures, and text in a bevel button, and you can specify the placement of text in relation to an icon or picture. By calling GetControlData with these constants you can also ascertain alignment and placement.
Bevel Button Graphic Alignment Constants
The following constants are used to specify the alignment of icon suites, colour icons, and pictures:
Constant |
Value |
Description |
| kControlBevelButtonAlignSysDirection |
-1 |
Graphic is aligned according to the system default script direction (only left or right). |
| kControlBevelButtonAlignCenter |
0 |
Graphic is aligned centre. |
| kControlBevelButtonAlignLeft |
1 |
Graphic is aligned left. |
| kControlBevelButtonAlignRight |
2 |
Graphic is aligned right. |
| kControlBevelButtonAlignTop |
3 |
Graphic is aligned top. |
| kControlBevelButtonAlignBottom |
4 |
Graphic is aligned bottom. |
| kControlBevelButtonAlignTopLeft |
5 |
Graphic is aligned top left. |
| kControlBevelButtonAlignBottomLeft |
6 |
Graphic is aligned bottom left. |
| kControlBevelButtonAlignTopRight |
7 |
Graphic is aligned top right. |
| kControlBevelButtonAlignBottomRight |
8 |
Graphic is aligned bottom right. |
Bevel Button Text Alignment Constants
The following constants are used to specify the alignment of text:
Constant |
Value |
Description |
| kControlBevelButtonAlignTextSysDirection |
0 |
Text is aligned according to the current script direction (left or right). |
| kControlBevelButtonAlignTextCenter |
1 |
Text is aligned centre. |
| kControlBevelButtonAlignTextFlushRight |
-1 |
Text is aligned flush right. |
| kControlBevelButtonAlignTextFlushLeft |
-2 |
Text is aligned flush left. |
Bevel Button Text Placement Constants
The following constants are used to specify the placement of text in relation to an icon suite, colour icon, or picture:
Constant |
Value |
Description |
| kControlBevelButtonPlaceSysDirection |
-1 |
Text is placed according to the system default script direction. |
| kControlBevelButtonPlaceNormally |
0 |
Text is centred. |
| kControlBevelButtonPlaceToRightOfGraphic |
1 |
Text is placed to the right of the graphic. |
| kControlBevelButtonPlaceToLeftOfGraphic |
2 |
Text is placed to the left of the graphic. |
| kControlBevelButtonPlaceBelowGraphic |
3 |
Text is placed below the graphic. |
| kControlBevelButtonPlaceAboveGraphic |
4 |
Text is placed above the graphic. |
Control Data Tag Constants - Alignment and Placement
The control data tag constants relevant to the alignment and placement of graphics and text in bevel buttons are as follows:
Control Data Tag Constant |
Meaning and Data Type Returned or Set |
| kControlBevelButtonTextAlignTag |
Gets or sets the alignment of text. (See Bevel Button Text Alignment Constants, above.) Data type returned or set: ControlButtonTextAlignment |
| kControlBevelButtonGraphicAlignTag |
Gets or sets the alignment of graphics in relation to any text the button may contain. (See Bevel Button Graphic Alignment Constants.) Data type returned or set: ControlButtonGraphicAlignment |
| kControlBevelButtonTextPlaceTag |
Gets or sets the placement of text. (See Bevel Button Text Placement Constants, above.) Data type returned or set: ControlButtonTextPlacement |
| kControlBevelButtonTextOffsetTag |
Gets or sets the number of pixels that text is offset from the button's left or right edge. This is used with left, right, or system justification, but it is ignored when the text is centre aligned. Data type returned or set: SInt16 |
| kControlBevelButtonGraphicOffsetTag |
Gets or sets the horizontal and vertical amounts that a graphic element is offset from the button's edges. This value is ignored when the graphic is specified to be centred on the button. Data type returned or set: Point |
The Button Content Info Structure
As previously stated, you can use bevel button and image well content type constants in the contentType field of the button content info structure and you can then pass a pointer to this structure in the inBuffer parameter of GetControlData and SetControlData. The button content info structure is as follows:
struct ControlButtonContentInfo
{
ControlContentType contentType;
union {
SInt16 resID;
CIconHandle cIconHandle;
Handle iconSuite;
IconRef iconRef;
PicHandle picture;
Handle ICONHandle;
} u;
};
typedef struct ControlButtonContentInfo ControlButtonContentInfo;
typedef ControlButtonContentInfo *ControlButtonContentInfoPtr;
typedef ControlButtonContentInfo ControlImageContentInfo;
typedef ControlButtonContentInfo *ControlImageContentInfoPtr;
Field Descriptions
| contentType |
Specifies the content type (see Bevel Button and Image Well Content Type Constants, above.) and determines which of the following fields are used. |
| resID |
If the content type specified in the contentType field is kControlContentIconSuiteRes, kControlContentCIconRes, or kControlContentPictRes, this field should contain the resource ID of a picture, colour icon, or icon suite resource. |
| cIconHandle |
If the content type specified in the contentType field is kControlContentCIconHandle, this field should contain a handle to a colour icon. |
| iconSuite |
If the content type specified in the contentType field is kControlContentIconSuiteHandle, this field should contain a handle to an icon suite. |
| iconRef |
If the content type specified in the contentType field is kControlContentIconRef, this field should contain an icon reference. |
| picture |
If the content type specified in the contentType field is kControlContentPictHandle, this field should contain a handle to a picture. |
Other Control Data Tag Constants
The remaining control data tag constants relevant to bevel buttons are as follows:
Control Data Tag Constant |
Meaning and Data Type Returned or Set |
| kControlBevelButtonCenterPopUpGlyphTag |
Gets or sets the position of the pop-up arrow when a pop-up menu is attached. Data type returned or set: Boolean. If true, glyph is vertically centred on the right; if false, glyph is on the bottom right. |
| kControlBevelButtonTransformTag |
Gets or sets a transform that is added to the standard transform. See the Icons section at Chapter 13.) Data type returned or set: IconTransformType |
| kControlBevelButtonMenuValueTag |
Gets the menu value. (See "Bevel Button Menu Constants, above.) Data type returned or set: SInt16 |
| kControlBevelButtonMenuRefTag |
Gets the menu reference. Data type returned or set: MenuRef |
| kControlBevelButtonLastMenuTag |
Gets the menu ID of the last menu selected in the submenu or main menu. Data type returned or set: Boolean |
| kControlBevelButtonMenuDelayTag |
Gets or sets the delay (in number of ticks) before the menu is displayed. Data type returned or set: SInt32 |
| kControlBevelButtonScaleIconTag |
Gets or sets whether, when the proper icon size is unavailable, the icon should be scaled. For use only with icon suites or the IconRef data type. Data type returned or set: Boolean. If true, indicates that if an icon of the ideal size is not available a larger or smaller icon should be scaled. If false, no scaling should occur; instead, a smaller icon should be drawn or a larger icon clipped. |
| kControlBevelButtonOwnedMenuRefTag |
Sets the menu reference. (The control will dispose.) Data type set: MenuRef |
| kControlBevelButtonKindTag |
Data type set: ThemeButtonKind (kThemeSmallBevelButton, kThemeMediumBevelButton, kThemeLargeBevelButton, kThemeRoundedBevelButton). |
With regard to the kControlBevelButtonMenuDelayTag constant, setting a delay before the menu is displayed in a bevel button with sticky behaviour is useful for providing option sets in tool palettes. You can set up the bevel button so that:
- If the user clicks it once, it simply turns on the function represented by the button.
- If the user presses it for longer than the user-set double-click time, it displays a pop-up menu which offers further options for that function.
Helper Functions
The following helper functions may be used in lieu of SetControlData and GetControlData with the relevant control data tags:
GetBevelButtonMenuValue
SetBevelButtonMenuValue
GetBevelButtonMenuHandle
GetBevelButtonContentInfo
SetBevelButtonContentInfo
SetBevelButtonTransform
SetBevelButtonGraphicAlignment
SetBevelButtonTextAlignment
SetBevelButtonTextPlacement
Control Part Codes
The following control part codes are relevant to bevel buttons:
Constant |
Value |
Description |
| kControlNoPart |
0 |
For bevel buttons with a menu attached, this part code indicates that either the mouse was released outside the bevel button and menu or that the button was disabled. |
| kControlMenuPart |
2 |
For bevel buttons with a menu attached, this part code indicates that the event occurred in a menu item of the bevel button. |
| kControlButtonPart |
10 |
For bevel buttons with a menu attached, this part code indicates that the event occurred in the button but not in the attached menu. |
Bevel Button States
Bevel buttons can exist in five active states and two disabled states. The active states are off, pressed (was off), on, pressed (was on), and mixed. The mixed state is used, where appropriate, when the bevel button is behaving as a checkbox or radio button. Disabled bevel buttons can be shown as off or on.
Programmatic Creation
Bevel button controls may be created programmatically using the function CreateBevelButtonControl:
OSStatus CreateBevelButtonControl(WindowRef window,const Rect *boundsRect,
CFStringRef title,ControlBevelThickness thickness,
ControlBevelButtonBehavior behavior,
ControlButtonContentInfoPtr info,SInt16 menuID,
ControlBevelButtonMenuBehavior menuBehavior,
ControlBevelButtonMenuPlacement menuPlacement,
ControlRef *outControl);
Relevant constants are:
Parameter |
Constants |
| thickness |
kControlBevelButtonSmallBevel
kControlBevelButtonNormalBevel
kControlBevelButtonLargeBevel |
| behavior |
See Bevel Button Behaviour Constants, above. |
| info.contentType |
See Button and Image Well Content Type Constants, above |
| menuBehavior |
See Bevel Button Behaviour Constants (Menus), above. |
| menuPlacement |
kControlBevelButtonMenuOnBottom
kControlBevelButtonMenuOnRight
|

Image Wells
Image wells can be used to display icons or pictures. They are controlled in much the same way as bevel buttons, but with fewer options and states. They should not be used in place of push buttons or bevel buttons. Typical image wells are shown at Fig 2.
Variants and Control Definition IDs
The image well CDEF resource ID is 11. The one available variant and its control definition IDs is as follows:
Variant |
Var Code |
Control Definition ID |
Image well. |
0 |
176 |
kControlImageWellProc |
Image well with autotracking. |
1 |
177 |
kControlImageWellAutoTrackProc |
Control Values
Control Value |
Content |
Initial |
Resource ID of image well's content ('cicn', 'PICT' or icon suite). |
Minimum |
Content type. (See Bevel Button and Image Well Content Type Constants, above.) After the image well is created, reset to 0. |
Maximum |
Ignored. Reset to 2 after creation. |
Bevel Button and Image Well Content Type Constants and The Button Content Info Structure
The bevel button and image well content type constants (see Bevel Buttons, above) apply to an image well's minimum value.
You can also use these constants in the contentType field of the button content info structure (see Bevel Buttons, above). You can then pass a pointer to this structure in the inBuffer parameter of GetControlData and SetControlData to get and set the resource ID (for resource-based content) or handle (for handle-based content) of a colour icon, icon suite, or picture in an image well.
Control Data Tag Constant |
Meaning and Data Type Returned or Set |
| kControlImageWellContentTag |
Gets or sets the content. (See The Button Content Info Structure, above.) Data type returned or set: ControlButtonContentInfo structure |
| kControlImageWellTransformTag |
Gets or sets a transform that is added to the standard transform. (See the Icons section at Chapter 13.) Data type returned or set: IconTransformType |
Helper Functions
The following helper functions may be used in lieu of SetControlData and GetControlData with the relevant control data tag constants:
GetImageWellContentInfo
SetImageWellContentInfo
SetImageWellTransform
Control Part Codes
Constant |
Value |
Description |
| kControlImageWellPart |
26 |
Event occurred in an image well. |
Programmatic Creation
Image well controls may be created programmatically using the function CreateImageWellControl:
OSStatus CreateImageWellControl(WindowRef window,const Rect *boundsRect,
const ControlButtonContentInfo *info,
ControlRef *outControl);
Relevant constants are:
Parameter |
Constants |
| info.contentType |
See Button and Image Well Content Type Constants, above. |

Tab Control (Embedding Control)
The tab control is an embedding control which provides a means of presenting information on multiple "pages". The user selects the desired "page" by clicking the appropriate tab.
A typical tab control is shown at Fig 3.
The content area of a tab is known as a pane. Controls which are embedded within an individual pane should only affect the settings displayed in that pane. Controls whose effect is intended to be global (that is, their setting are intended to affect all the panes in a set of tabs) should be located outside the tab control.
The tab information ('tab#') resource may be used to provide the tab names and icon suite IDs.
Variants and Control Definition IDs
The tab control CDEF resource ID is 8. The eight available variants and their control definition ID are follows:
Variant |
Var Code |
Control Definition ID |
Large tab control, tabs at top. |
0 |
128 |
kControlTabLargeProc |
Small tab control, tabs at top. |
1 |
129 |
kControlTabSmallProc |
Large tab control, tabs at bottom. |
2 |
130 |
kControlTabLargeProc |
Small tab control, tabs at bottom. |
3 |
131 |
kControlTabSmallProc |
Large tab control, tabs at right. |
4 |
132 |
kControlTabLargeProc |
Small tab control, tabs at right. |
5 |
133 |
kControlTabSmallProc |
Large tab control, tabs at left. |
6 |
134 |
kControlTabLargeProc |
Small tab control, tabs at left. |
7 |
135 |
kControlTabSmallProc |
Control Values
Control Value |
Content |
Initial |
Resource ID of the 'tab#' resource you are using to hold tab information. Reset to the minimum setting after creation. A value of 0 indicates not to read a 'tab#' resource. (See The Tab Information Structure, below.) |
Minimum |
Ignored. Reset to 1 after creation. |
Maximum |
Ignored. Reset to the number of individual tabs in the tab control after creation. |
Control Data Tag Constants
Control Data Tag Constant |
Meaning and Data Type Returned or Set |
| kControlTabContentRectTag |
Gets the content rectangle. Data type returned or set: Rect |
| kControlTabEnabledFlagTag |
Enables or disables a single tab. Data type returned or set: Boolean; if true, enabled; if false, disabled. |
| kControlTabFontStyleTag |
Gets or sets the font and font style. Data type returned or set: ControlFontStyleRec |
| kControlTabInfoTag |
Gets or sets information for a tab in a tab control. (See The Tab Information Structure, below.) Data type returned or set: ControlTabInfoRec |
Helper Functions
The following helper functions may be used in lieu of SetControlData and GetControlData with the relevant control data tags:
GetTabContentRect
SetTabEnabled
The Tab Information Structure
If you are not creating a tab control with a 'tab#' resource, you can call SetControlMaximum to set the number of tabs in a tab control and then call SetControlData with the kControlTabInfoTag to set the information for an individual tab in a tab control. The tab information structure passed in the SetControlData call should be one of the following:
struct ControlTabInfoRec
{
SInt16 version; // Set to 0.
SInt16 iconSuiteID; // Set to 0 for no icon.
Str255 name; // Title for tab label.
};
typedef struct ControlTabInfoRec ControlTabInfoRec;
struct ControlTabInfoRecV1
{
SInt16 version; // Set to kControlTabInfoVersionOne.
SInt16 iconSuiteID; // Set to 0 for no icon.
CFStringRef name; // Title for tab label. (Should always be released)
};
typedef struct ControlTabInfoRecV1 ControlTabInfoRecV1;
An alternative tab information structure takes a CFString object in the name parameter:
struct ControlTabInfoRecV1
{
SInt16 version;
SInt16 iconSuiteID;
CFstringRef name;
};
typedef struct ControlTabInfoRecV1 ControlTabInfoRecV1;
If this variant is used, kControlTabInfoVersionOne should be assigned to the version field.
The Tab Information Resource
You can use a tab information resource to specify the icon suite ID and name of each tab in a tab control. A tab information resource is a resource of type 'tab#'. All tab information resources must have resource ID numbers greater than 127. The Control Manager uses the information you specify to provide additional information to the corresponding tab control. Fig 4 shows the structure of a compiled 'tab#' resource.
The following describes the fields of a compiled 'tab#' resource and one of its tab information entries:
Field |
Description |
VERSION NUMBER |
Version of the resource. |
NUMBER OF ENTRIES |
The number of tab information entries in the resource. |
ICON SUITE ID |
Icon suite resource ID. |
TAB NAME |
The tab name. |
Programmatic Creation
Tab controls may be created programmatically using the function CreateTabsControl:
OSStatus CreateTabsControl(WindowRef window,const Rect *boundsRect,ControlTabSize size,
ControlTabDirection direction,UInt16 numTabs,
const ControlTabEntry *tabArray,
ControlRef *outControl);
Relevant constants are:
Parameter |
Constants |
| size |
kControlTabSizeLarge
kControlTabSizeSmall |
| direction |
kControlTabDirectionNorth
kControlTabDirectionSouth
kControlTabDirectionEast
kControlTabDirectionWest
|
The tabArray parameter of takes a pointer to an array of tab entry structures:
struct ControlTabEntry
{
ControlButtonContentInfo *icon;
CFStringRef name;
Boolean enabled;
};
typedef struct ControlTabEntry ControlTabEntry;

Edit Text
Edit text controls are rectangular areas in which the user enters text. Edit text controls supports keyboard focus, and a password entry variant is available. Fig 5 shows a typical edit text control.
Edit text controls can have an application-defined key filter function attached to filter key strokes or modify them on return.
Variants and Control Definition IDs
The edit text control CDEF resource ID is 17. The three available variants and their control definition IDs are as follows:
Variant |
Var Code |
Control Definition ID |
Edit text control. |
0 |
272 |
kControlEditTextProc |
Edit text control for passwords. This control is supported by the Script Manager. Password text can be accessed via the kEditTextPasswordTag constant. (See Control Data Tag Constants, below.) |
2 |
274 |
kControlEditTextPasswordProc |
Edit text control for inline input. This control supports 2-byte script systems. |
4 |
276 |
kControlEditTextInlineInputProc |
Control Values
Control Value |
Content |
Initial |
Reserved. Set to 0. |
Minimum |
Reserved. Set to 0. |
Maximum |
Reserved. Set to 0. |
Control Data Tag Constants
Control Data Tag Constant |
Meaning and Data Type Returned or Set |
| kControlEditTextTextTag |
Gets or sets text. Data type returned or set: character buffer |
| kControlEditTextTEHandleTag |
Gets a handle to the text edit structure. Data type returned or set: TEHandle |
| kControlEditTextSelectionTag |
Gets or sets the selection. Data type returned or set: ControlEditTextSelectionRec structure. (See The Edit Text Selection Structure, below.) |
| kControlEditTextPasswordTag |
Gets clear password text, that is, the text of the actual password typed, not the bullet text. Data type returned or set: character buffer |
| kControlKeyFilterTag |
Gets or sets a key filter function. Data type returned or set: ControlKeyFilterUPP |
| kControlEditTextStyleTag |
Gets or sets the font style. Data type returned or set: ControlFontStyleRec |
| KControlEditTextLockedTag |
Gets or sets whether the text is currently editable. Data type returned or set: Boolean. If true, text is locked. If false, text is editable |
| kControlEditTextValidationProcTag |
Gets or sets a universal procedure pointer to a callback function which can be used to validate editable text after an operation that changes the text, such as a cut or paste. Data type returned or set: ControlEditTextValidationUPP |
| kControlEditTextCFStringTag |
Gets or sets text. (Mac OS X only.) Data type returned or set: CFStringRef |
Control Part Codes
Constant |
Value |
Description |
| kControlEditTextPart |
5 |
Event occurred in an edit text control. |
The Edit Text Selection Structure
You can pass a pointer to the edit text selection structure to GetControlData and SetControlData to access and set the current selection range in an edit text control. An edit text selection structure is of type ControlEditTextSelectionRec:
struct ControlEditTextSelectionRec
{
SInt16 selStart;
SInt16 selEnd;
};
typedef struct ControlEditTextSelectionRec ControlEditTextSelectionRec;
typedef ControlEditTextSelectionRec *ControlEditTextSelectionPtr;
Field Descriptions
| selStart |
Beginning of the edit text selection. |
| selEnd |
End of the edit text selection. |
Programmatic Creation
Edit text controls may be created programmatically using the function CreateEditTextControl:
OSStatus CreateEditTextControl(WindowRef window,const Rect *boundsRect,CFStringRef text,
Boolean isPassword,Boolean useInlineInput,
const ControlFontStyleRec *style,ControlRef *outControl);

Sliders
A slider control consists of a slider bar and an indicator. The user can drag the indicator to set a new value within the range represented by the slider bar.
Sliders can be oriented horizontally or vertically, and the indicator can point in any direction. The indicator can also be nondirectional if required. Typical sliders are shown at Fig 6.
A slider can, optionally, display tick marks, and you can specify the number of tick marks required. If you specify tick marks, you should ensure that they are labelled.
A live feedback variant is available. This variant continually updates the value of the control as the indicator is dragged, as opposed to the standard behaviour of updating the value only when the mouse button is released.
Variants and Control Definition IDs
The slider CDEF resource ID is 3. The ten available variants and their control definition IDs are as follows:
Variant |
Var Code |
Control Definition ID |
Slider. If the slider is horizontal, the indicator points down, and if the slider is vertical, the indicator points right. |
0 |
48 |
kControlSliderProc |
Slider with live feedback. The value of the control is updated automatically by the Control Manager before your action function is called. If no application-defined action function is supplied, the slider draws ghosted image of the indicator as the user moves it. |
1 |
49 |
kControlSliderProc + kControlSliderLiveFeedback |
Slider with tick marks. The control rectangle must be large enough to include the tick marks. |
2 |
50 |
kControlSliderProc + kControlSliderHasTickMarks |
Slider with live feedback and tick marks. |
3 |
51 |
kControlSliderProc + kControlSliderLiveFeedback + kControlSliderHasTickMarks |
Slider with indicator reversed. . If the slider is horizontal, the indicator points up, and if the slider is vertical, the indicator points left. |
4 |
52 |
kControlSliderProc + kControlSliderReverseDirection |
Slider with live feedback and indicator reversed. |
5 |
53 |
kControlSliderProc+ kControlSliderLiveFeedback + kControlSliderReverseDirection |
Slider with tick marks and indicator reversed. |
6 |
54 |
kControlSliderProc + kControlSliderHasTickMarks + kControlSliderReverseDirection |
Slider with live feedback, tick marks and indicator reversed. |
7 |
55 |
kControlSliderProc + kControlSliderLiveFeedback + kControlSliderHasTickMarks + kControlSliderReverseDirection |
Slider with a rectangular, non-directional indicator. |
8 |
56 |
kControlSliderProc + kControlSliderNonDirectional |
Slider with live feedback and a rectangular, non-directional indicator. |
9 |
57 |
kControlSliderProc + kControlSliderLiveFeedback + kControlSliderNonDirectional |
Control Values
Control Value |
Content |
Initial |
Appropriate value between -32768 and 32768. For the tick mark variant, the number of ticks required. Reset to the minimum setting after creation. |
Minimum |
-32768 to 32768. |
Maximum |
-32768 to 32768. When the maximum setting is equal to the minimum setting, the slider is inactive. |
Control Part Codes
Constant |
Value |
Description |
| kControlIndicatorPart |
129 |
Event occurred in the indicator. |
Programmatic Creation
Slider controls may be created programmatically using the function CreateSliderControl:
OSStatus CreateSliderControl(WindowRef window,const Rect *boundsRect,SInt32 value,
SInt32 minimum,SInt32 maximum,
ControlSliderOrientation orientation,UInt16 numTickMarks,
Boolean liveTracking,ControlActionUPP liveTrackingProc,
ControlRef *outControl);
Relevant constants are:
Parameter |
Constants |
| orientation |
kControlSliderPointsDownOrRight
kControlSliderPointsUpOrLeft
kControlSliderDoesNotPoint |

Group Boxes (Embedding Control)
Group boxes are embedding controls used to group a number of related items. They may be either primary or secondary.
A group box can be untitled or it can have a text title, a pop-up menu title, or a checkbox title. Group boxes with a pop-up menu title are useful for displaying a variety of related settings in a limited space. Group boxes with a checkbox title are useful for indicating that a group of settings may be deactivated by the user.
Secondary group boxes are generally used for grouping subsidiary information.
Typical group boxes are shown at Fig 7.
Variants and Control Definition IDs
The group box CDEF resource ID is 10. The six available variants and their control definition IDs are as follows:
Variant |
Var Code |
Control Definition ID |
Primary group box, text title. |
0 |
160 |
kControlGroupBoxTextTitleProc |
Primary group box, checkbox title. |
1 |
161 |
kControlGroupBoxCheckBoxProc |
Primary group box, pop-up button title. |
2 |
162 |
kControlGroupBoxPopupButtonProc |
Secondary group box, text title. |
4 |
164 |
kControlGroupBoxSecondaryTextTitleProc |
Secondary group box, checkbox title. |
5 |
165 |
kControlGroupBoxSecondaryCheckBoxProc |
Secondary group box, pop-up button title. |
6 |
166 |
kControlGroupBoxSecondaryPopupButtonProc |
Control Values
Control Value |
Content |
Initial |
Ignored if group box has text title. If the group box has a checkbox or pop-up button title, same value as the checkbox or pop-up button. |
Minimum |
Ignored if group box has text title. If the group box has a checkbox or pop-up button title, same minimum setting as the checkbox or pop-up button.
|
Maximum |
Ignored if group box has text title. If the group box has a checkbox or pop-up button title, same maximum setting as the checkbox or pop-up button. |
Control Data Tag Constant
Control Data Tag Constant |
Meaning and Data Type Returned or Set |
| kControlGroupBoxMenuHandleTag |
Gets the menu handle of a group box. Data type returned or set: MenuHandle |
| kControlGroupBoxFontStyleTag |
Gets or sets the font style. Data type returned or set: ControlFontStyleRec |
| kControlGroupBoxTitleRectTag |
Gets the rectangle containing the group box title (and any associated control, such as a checkbox). Data type returned or set: Rect |
Control Part Codes
Constant |
Value |
Description |
| kControlNoPart |
0 |
Returned if the group box title is a text title. If the group box title is a checkbox title or a pop-up menu button title, the user tracked completely out of the control. |
| kControlButtonPart |
10 |
The group box title is a checkbox title and the check box was hit. The group box title is a pop-up menu button and the mouse button was released over the button. |
| kControlMenuPart |
2 |
The group box title is a pop-up menu button and the mouse button was released in the menu. |
Programmatic Creation
Group box controls may be created programmatically using the functions CreateGroupBoxControl, CreateCheckGroupBoxControl, and CreatePopupGroupBoxControl:
OSStatus CreateGroupBoxControl(WindowRef window,const Rect *boundsRect,
CFStringRef title,Boolean primary,
ControlRef *outControl);
OSStatus CreateCheckGroupBoxControl(WindowRef window,const Rect *boundsRect,
CFStringRef title,SInt32 initialValue,
Boolean primary,Boolean autoToggle,
ControlRef *outControl);
OSStatus CreatePopupGroupBoxControl(WindowRef window,const Rect *boundsRect,
CFStringRef title,Boolean primary,SInt16 menuID,
Boolean variableWidth,SInt16 titleWidth,
SInt16 titleJustification,Style titleStyle,
ControlRef *outControl);

Clock
Clock controls are a combination of an edit text control and little arrows (see below) which display date or time. The displayed date and time may be changed using the little arrows or by typing in the edit text control. Fig 8 shows a clock control displaying a date.
The clock control supports keyboard navigation and keyboard focus. If the control is made inactive, the user will be unable to change the displayed date or time values; however the correct date and time will continue to be displayed.
Variants and Control Definition IDs
The clock control CDEF resource ID is 15. The four available variants and their control definition ID are follows:
Variant |
Var Code |
Control Definition ID |
Clock control displaying hour/minutes. |
0 |
240 |
kControlClockTimeProc |
Clock control displaying hours/minutes/seconds. |
1 |
241 |
kControlClockTimeSecondsProc |
Clock control displaying date/month/year. |
2 |
242 |
kControlClockDateProc |
Clock control displaying month/year. |
3 |
243 |
kControlClockMonthYearProc |
Control Values
Control Value |
Content |
Initial |
One or more of the clock value flags. (See Clock Value Flag Constants, below.) Reset to 0 after creation. |
Minimum |
Reserved. Set to 0. |
Maximum |
Reserved. Set to 0. |
Clock Value Flag Constants
Constant |
Value |
Description |
| kControlClockNoFlags |
0 |
Indicates that clock is editable but does not display the current "live" time. |
| kControlClockIsDisplayOnly |
1 |
When only this bit is set, the clock is not editable. When this bit and the kControlClockIsLive bit is set, the clock automatically updates on idle (clock will have the current time). |
| kControlClockIsLive |
2 |
When only this bit is set, the clock automatically updates on idle and any changes to the clock affect the system clock. When this bit and the kControlClockIsDisplayOnly bit is set, the clock automatically updates on idle (clock will have the current time), but is not editable. |
Control Data Tag Constant
Control Data Tag Constant |
Meaning and Data Type Returned or Set |
| kControlClockLongDateTag |
Gets or sets the clock control's time or date. Data type returned or set: LongDateRec structure. |
| kControlClockFontStyleTag |
Gets or sets the font style. Data type returned or set: ControlFontStyleRec |
| kControlClockAnimatingTag |
Starts and stops clock animation. Use only if a call to GetControlFeatures reveals that the control's kControlIdlesWithTimer flag is set. Data type returned or set: Boolean |
Control Part Codes
Constant |
Value |
Description |
| kControlClockPart |
8 |
Event occurred in a clock control. |
| kControlClockHourDayPart |
9 |
Event occurred in the part that contains the hour. |
| kControlClockMinuteMonthPart |
10 |
Event occurred in the part that contains the minute or the month. |
| kControlClockSecondYearPart |
11 |
Event occurred in the part that contains the second or the year. |
| kControlClockAMPMPart |
12 |
Event occurred in the part that contains the AM/PM information. |
Programmatic Creation
Clock controls may be created programmatically using the function CreateClockControl:
OSStatus CreateClockControl(WindowRef window,const Rect *boundsRect,
ControlClockType clockType,ControlClockFlags clockFlags,
ControlRef *outControl);
Relevant constants are:
Parameter |
Constants |
| clockType |
kControlClockTypeHourMinute
kControlClockTypeHourMinuteSecond
kControlClockTypeMonthDayYear
kControlClockTypeMonthYear |
| clockFlags |
See Clock Value Flag Constants, above. |

Progress and Relevance Bars
Progress bars are used to indicate capacity or the current status of a lengthy operation. Two types of progress bars can be used: an indeterminate progress bar, which shows that an operation is occurring |