Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

PATHDocumentation > Mac OS 8 and 9 > Human Interface Toolbox > Control Manager >

Mac OS 8 Control Manager Reference


Handling Keyboard Focus

A control with keyboard focus receives keyboard events. The Dialog Manager tests to see which control has keyboard focus when a keyboard event is processed and sends the event to that control. If no control has keyboard focus, the keyboard event is discarded. Currently, the list box, clock, and editable text controls are the only standard system controls that support keyboard focus. A control retains keyboard focus if it is hidden or deactivated.

A focus ring is drawn around the control with keyboard focus. When creating your own controls, allow space for the focus ring. For more details on designing with focus rings, see Mac OS 8 Human Interface Guidelines .

Keyboard focus is only available if an embedding hierarchy has been established in the focusable control's window. The default focusing order is based on the order in which controls are added to the window. For more details on embedding hierarchies, see Embedding Controls .

The following Control Manager functions for handling keyboard focus are new with Appearance Manager 1.0:


SetKeyboardFocus

Sets the current keyboard focus to a specified control part for a window.

pascal OSErr SetKeyboardFocus (
                     WindowPtr inWindow,
                     ControlHandle inControl,
                     ControlFocusPart inPart);
inWindow
A pointer to the window containing the control that is to receive keyboard focus.
inControl
A handle to the control that is to receive keyboard focus.
inPart
A part code specifying the part of a control to receive keyboard focus. To clear a control's keyboard focus, pass kControlFocusNoPart. See Handling Keyboard Focus .
function result
A result code; see Result Codes .

DISCUSSION

The SetKeyboardFocus function sets the keyboard focus to a specified control part. The control to receive keyboard focus can be deactivated or invisible. This permits you to set the focus for an item in a dialog box before the dialog box is displayed.


VERSION NOTES

Available with Appearance Manager 1.0 and later.


SEE ALSO

GetKeyboardFocus .

Handling Keyboard Focus .


GetKeyboardFocus

Obtains a handle to the control with the current keyboard focus for a specified window.

pascal OSErr GetKeyboardFocus (
                     WindowPtr inWindow,
                     ControlHandle* outControl);
inWindow
A pointer to the window for which to obtain keyboard focus.
outControl
Pass a pointer to a ControlHandle value. On return, the ControlHandle value is set to a handle to the control that currently has keyboard focus. Produces nil if no control has focus.
function result
A result code; see Result Codes .

DISCUSSION

The GetKeyboardFocus function returns the handle of the control with current keyboard focus within a specified window.


VERSION NOTES

Available with Appearance Manager 1.0 and later.


SEE ALSO

SetKeyboardFocus .

Handling Keyboard Focus .


AdvanceKeyboardFocus

Advances the keyboard focus to the next focusable control in a window.

pascal OSErr AdvanceKeyboardFocus (WindowPtr inWindow);
inWindow
A pointer to the window for which to advance keyboard focus.
function result
A result code; see Result Codes .

DISCUSSION

The AdvanceKeyboardFocus function skips over deactivated and hidden controls until it finds the next focusable control in the window. If it does not find a focusable item, it simply returns.

When AdvanceKeyboardFocus is called, the Control Manager calls your control definition function and passes kControlMsgFocus in its message parameter and kControlFocusNextPart in its param parameter. In response to this message, your control definition function should change keyboard focus to its next part, the entire control, or remove keyboard focus from the control, depending upon the circumstances. see Handling Keyboard Focus for a discussion of possible responses to this message.


VERSION NOTES

Available with Appearance Manager 1.0 and later.


SEE ALSO

ReverseKeyboardFocus .

Handling Keyboard Focus .


ReverseKeyboardFocus

Returns keyboard focus to the prior focusable control in a window.

pascal OSErr ReverseKeyboardFocus (WindowPtr inWindow);
inWindow
A pointer to the window for which to reverse keyboard focus.
function result
A result code; see Result Codes .

DISCUSSION

The ReverseKeyboardFocus function reverses the progression of keyboard focus, skipping over deactivated and hidden controls until it finds the previous control to receive keyboard focus in the window.

When ReverseKeyboardFocus is called, the Control Manager calls your control definition function and passes kControlMsgFocus in its message parameter and kControlFocusPrevPart in its param parameter. In response to this message, your control definition function should change keyboard focus to its previous part, the entire control, or remove keyboard focus from the control, depending upon the circumstances. see Handling Keyboard Focus for a discussion of possible responses to this message.


VERSION NOTES

Available with Appearance Manager 1.0 and later.


SEE ALSO

AdvanceKeyboardFocus .

Handling Keyboard Focus .


ClearKeyboardFocus

Removes the keyboard focus for the currently focused control in a window.

pascal OSErr ClearKeyboardFocus (WindowPtr inWindow);
inWindow
A pointer to the window in which to clear keyboard focus.
function result
A result code; see Result Codes .

DISCUSSION

When the ClearKeyboardFocus function is called, the Control Manager calls your control definition function and passes kControlMsgFocus in its message parameter and kControlFocusNoPart in its param parameter. see Handling Keyboard Focus for a discussion of possible responses to this message.


VERSION NOTES

Available with Appearance Manager 1.0 and later.


SEE ALSO

Handling Keyboard Focus .


\xA9 1998 Apple Computer, Inc. – (Last Updated 19 Nov 98)