Up
Authors
- Scott Christley (
scottc@net-community.com)
-
- Richard Frith-Macdonald (
richard@brainstorm.co.uk)
-
Date: Generated at 2025-12-03
The abstract control class
Copyright: (C) 1996 Free Software Foundation, Inc.
- Declared in:
- AppKit/NSControl.h
Availability: OpenStep
NSControl is an abstract class that defines the
common interface and behavior for user interface
controls. It provides the basic functionality for
controls that use NSCell objects to display content
and handle user interaction. NSControl manages the
relationship between the control and its cell,
handles target-action messaging, and provides methods
for value management and display. Key features include: -
Cell-based architecture for content display and
editing - Target-action mechanism for user
interaction - Value management with type
conversion methods - Text formatting and editing
support - Mouse tracking and event handling -
Integration with field editor for text input
NSControl is subclassed by concrete controls like
NSButton, NSTextField, NSSlider, and others that
implement specific user interface elements.
TODO Description
NSControl declares 3 Instance Variables
+ (Class)
cellClass;
Availability: OpenStep
Returns the default cell class used by this control
class. Returns: The
Class object
representing the default cell type
Returns the cell Class used by
NSControl. Used by subclasses.
See Also:
+setCellClass:
+ (void)
setCellClass: (Class)factoryId;
Availability: OpenStep
Sets the default cell class for this control class.
factoryId: The
Class object to
use as the default cell class
Sets the cell Class used by
NSControl to factoryId. Used by
subclasses.
See Also:
+setCellClass:
- (BOOL)
abortEditing;
Availability: OpenStep
Aborts current editing session and discards changes.
Returns:
YES if editing was
successfully aborted,
NO
otherwise
Sends an
[NSCell -endEditing:]
message to the current object used to edit the
NSControl. Returns NO if the the
currentEditor does not exists,
YES otherwise.
- (SEL)
action;
Availability: OpenStep
Returns the action selector sent to the target.
Returns: The
SEL representing the
action method
Returns the NSControl's cell action method.
See Also:
-setAction:
[NSCell -action]
- (
NSTextAlignment)
alignment;
Availability: OpenStep
Returns the text alignment used by the control.
Returns: The NSTextAlignment value indicating text
alignment
Returns the alignment of the text in the
NSControl's cell. Returns
NSNaturalTextAlignment if the cell
does not exists. See
NSTextAlignment
for more informations.
See Also:
-setAlignment:
[NSCell -alignment]
- (
NSAttributedString*)
attributedStringValue;
Availability: MacOS-X 10.0.0
Returns the control's value as an attributed
string. Returns: The NSAttributedString
representation of the control's value
- (
NSWritingDirection)
baseWritingDirection;
Availability: MacOS-X 10.4.0
Returns the base writing direction for the
control's text. Returns: The NSWritingDirection
indicating text direction
- (void)
calcSize;
Availability: OpenStep
Calculates the optimal size for the control.
Recalculates the internal size by sending
[NSCell -calcDrawInfo:]
to the cell.
- (id)
cell;
Availability: OpenStep
Returns the cell object used by this control.
Returns: The NSCell object managing the control's
content and behavior
Returns the NSControl's cell.
See Also:
-setCell:
- (
NSText*)
currentEditor;
Availability: OpenStep
Returns the current field editor being used for
text editing. Returns: The NSText object serving as
the field editor, or
nil if none
Returns the NSText object used when editing the
NSControl.
- (double)
doubleValue;
Availability: OpenStep
- (void)
drawCell: (
NSCell*)aCell;
Availability: OpenStep
- (void)
drawCellInside: (
NSCell*)aCell;
Availability: OpenStep
- (float)
floatValue;
Availability: OpenStep
- (
NSFont*)
font;
Availability: OpenStep
Returns the font used by the control. Returns: The
NSFont object used for displaying text
Returns the font of the text in the NSControl's
cell. Returns nil if the cell does not
exists.
See Also:
-setFont:
[NSCell -font]
- (id)
formatter;
Availability: MacOS-X 10.0.0
Returns the formatter used by the control's cell.
Returns: The NSFormatter object used for
formatting, or nil if none
- (BOOL)
ignoresMultiClick;
Availability: OpenStep
Returns whether the control ignores multiple
clicks. Returns:
YES if multi-clicks
are ignored,
NO otherwise
Returns wheter multiple clicks are ignored.
See Also:
-setIgnoresMultiClick:
-mouseDown:
- (int)
intValue;
Availability: OpenStep
- (
NSInteger)
integerValue;
Availability: MacOS-X 10.5.0
- (BOOL)
isContinuous;
Availability: OpenStep
Returns whether the control sends actions
continuously. Returns:
YES if
continuous action sending is enabled,
NO otherwise
Returns whether the NSControl's cell can
continuously sends its action message.
See Also:
-setContinuous:
[NSCell -isContinuous]
- (BOOL)
isEnabled;
Availability: OpenStep
Returns whether the control is enabled for user
interaction. Returns:
YES if the
control is enabled,
NO if disabled
Returns whether the selected cell of the
NSControl is enabled.
See Also:
-setEnabled:
[NSCell -isEnabled]
- (void)
mouseDown: (
NSEvent*)theEvent;
Availability: OpenStep
Handles mouse down events in the control. theEvent:
The mouse event to process
- (id)
objectValue;
Availability: OpenStep
Returns the control's value as an object. Returns:
The object representation of the control's value
- (void)
performClick: (id)sender;
Availability: OpenStep
Simulates a mouse click on the control. sender:
The object requesting the click simulation
Simulates a single mouse click on the control.
This method calls the cell's method
performClickWithFrame:inView:.
Take note that sender is not used.
- (BOOL)
refusesFirstResponder;
Availability: MacOS-X 10.0.0
Returns whether the control refuses to become first
responder. Returns: YES if the
control refuses first responder status,
NO otherwise
- (void)
selectCell: (
NSCell*)aCell;
Availability: OpenStep
Selects the specified cell for interaction. aCell:
The NSCell object to select
Sets the aCell's state to NSOnState and marks self
for display if it is the NSControl's cell.
- (id)
selectedCell;
Availability: OpenStep
Returns the currently selected cell. Returns: The
NSCell object that is currently selected, or
nil if none
Returns the NSControl's selected cell.
- (
NSInteger)
selectedTag;
Availability: OpenStep
Returns the tag of the currently selected cell.
Returns: The tag value of the selected cell, or -1
if none selected
Returns the tag of the NSControl's selected cell
(if exists). -1 otherwise.
See Also:
[NSCell -tag]
- (BOOL)
sendAction: (SEL)theAction
to: (id)theTarget;
Availability: OpenStep
Sends the specified action to the specified target.
theAction: The action selector to send
theTarget: The target object to receive the
action Returns:
YES if the action was
successfully sent,
NO otherwise
Asks the NSApplication to send an action
theAction with theTarget as
target to NSControl. Returns NO if
theAction is nil or if
NSApplication can not send the action.
See Also:
[NSApplication -sendAction:to:from:]
- (
NSInteger)
sendActionOn: (
NSInteger)mask;
Availability: OpenStep
Sets the events that trigger action sending. mask: A
bitmask of event types that should trigger action
sending Returns: The previous event mask
value
- (void)
setAction: (SEL)aSelector;
Availability: OpenStep
Sets the action selector sent to the target.
aSelector: The
SEL representing
the action method
Sets the NSControl's cell action method.
See Also:
-action
[NSCell -setAction:]
- (void)
setAlignment: (
NSTextAlignment)mode;
Availability: OpenStep
Sets the text alignment used by the control. mode: The
NSTextAlignment value to use for text
alignment
Sets the alignment of the text in the NSControl's
cell to mode. This method abort the
editing and marks self for display if the cell is
an NSActionCell. See
NSTextAlignment
for more informations.
See Also:
-alignment
[NSCell -setAlignment:]
-abortEditing
- (void)
setAttributedStringValue: (
NSAttributedString*)attribStr;
Availability: MacOS-X 10.0.0
Sets the control's value as an attributed string.
attribStr: The NSAttributedString value to set
- (void)
setBaseWritingDirection: (
NSWritingDirection)direction;
Availability: MacOS-X 10.4.0
Sets the base writing direction for the
control's text. direction: The NSWritingDirection
to use for text layout
- (void)
setCell: (
NSCell*)aCell;
Availability: OpenStep
Sets the cell object for this control. aCell: The
NSCell object to use for managing content and
behavior
Sets the NSControl's cell to aCell,
Raises an NSInvalidArgumentException exception if
aCell is not nil and if it
is not a cell class.
See Also: -cell
- (void)
setContinuous: (BOOL)flag;
Availability: OpenStep
Sets whether the control sends actions continuously.
flag:
YES to enable continuous action
sending,
NO to disable
Sets whether the NSControl's cell can continuously
sends its action message.
See Also:
-isContinuous
[NSCell -setContinuous:]
- (void)
setDoubleValue: (double)aDouble;
Availability: OpenStep
- (void)
setEnabled: (BOOL)flag;
Availability: OpenStep
Sets whether the control is enabled for user
interaction. flag:
YES to enable
the control,
NO to disable it
Sets whether the NSControl's selected cell is
enabled. If flag is NO,
this method abort the editing. This method marks
self for display.
See Also:
-isEnabled
[NSCell -setEnabled:]
- (void)
setFloatValue: (float)aFloat;
Availability: OpenStep
- (void)
setFloatingPointFormat: (BOOL)autoRange
left: (
NSUInteger)leftDigits
right: (
NSUInteger)rightDigits;
Availability: OpenStep
Sets the floating point number format for the control.
autoRange: YES to automatically
determine range, NO for fixed format
leftDigits: Number of digits to display to the
left of decimal point rightDigits: Number of digits to
display to the right of decimal point
- (void)
setFont: (
NSFont*)fontObject;
Availability: OpenStep
Sets the font used by the control. fontObject: The
NSFont object to use for displaying text
Sets the font of the text in the NSControl's cell
and the editor object (if exists) to
fontObject.
See Also: -font
[NSCell -setFont:]
-currentEditor
- (void)
setFormatter: (
NSFormatter*)newFormatter;
Availability: MacOS-X 10.0.0
Sets the formatter for the control's cell.
newFormatter: The NSFormatter object to use
for formatting values
- (void)
setIgnoresMultiClick: (BOOL)flag;
Availability: OpenStep
Sets whether the control ignores multiple clicks.
flag:
YES to ignore multi-clicks,
NO to process them
Sets wheter multiple clicks are ignored.
See Also:
-ignoresMultiClick
-mouseDown:
- (void)
setIntValue: (int)anInt;
Availability: OpenStep
- (void)
setIntegerValue: (
NSInteger)anInt;
Availability: MacOS-X 10.5.0
- (void)
setNeedsDisplay;
Availability: OpenStep
Marks the control as needing display refresh.
Marks self for display.
- (void)
setObjectValue: (id)anObject;
Availability: OpenStep
Sets the control's value as an object. anObject: The
object value to set
- (void)
setRefusesFirstResponder: (BOOL)flag;
Availability: MacOS-X 10.0.0
Sets whether the control refuses to become first
responder. flag: YES to refuse
first responder status, NO to accept it
- (void)
setStringValue: (
NSString*)aString;
Availability: OpenStep
- (void)
setTag: (
NSInteger)anInt;
Availability: OpenStep
Sets the tag value for the control. anInt: The integer
tag value to assign
Assigning a Tag
- (void)
setTarget: (id)anObject;
Availability: OpenStep
Sets the target object for action messages. anObject:
The object that should receive action messages
Sets the target object of the NSControl's cell to
anObject.
See Also:
-target
[NSCell -setTarget:]
- (
NSSize)
sizeThatFits: (
NSSize)size;
Availability: MacOS-X 10.10.0
Returns the optimal size for the control
within the given constraints. size: The maximum
size constraints Returns: The optimal
size for the control
- (void)
sizeToFit;
Availability: OpenStep
Resizes the control to fit its content optimally.
Resizes the NSControl to fits the NSControl's
cell size.
See Also:
[NSCell -cellSize]
- (
NSString*)
stringValue;
Availability: OpenStep
- (
NSInteger)
tag;
Availability: OpenStep
Returns the tag value assigned to the control.
Returns: The integer tag value, or -1 if none
assigned
Returns the NSControl tag
See Also:
-setTag:
- (void)
takeDoubleValueFrom: (id)sender;
Availability: OpenStep
Sets the control's value from the
double value of the
sender. sender: The object whose
double value should be used
Sets the NSControl's selected cell to the sender's
double value.
See Also:
[NSCell -takeDoubleValueFrom:]
-takeFloatValueFrom:
takeIntValueFrom: takeStringValueFrom:
- (void)
takeFloatValueFrom: (id)sender;
Availability: OpenStep
- (void)
takeIntValueFrom: (id)sender;
Availability: OpenStep
- (void)
takeIntegerValueFrom: (id)sender;
Availability: MacOS-X 10.5.0
- (void)
takeObjectValueFrom: (id)sender;
Availability: OpenStep
Sets the control's value from the object value of the
sender. sender: The object whose object
value should be used
- (void)
takeStringValueFrom: (id)sender;
Availability: OpenStep
- (id)
target;
Availability: OpenStep
Returns the target object for action messages.
Returns: The object that receives action messages
Returns the target object of the NSControl's
cell.
See Also:
-setTarget:
[NSCell -target]
- (void)
updateCell: (
NSCell*)aCell;
Availability: OpenStep
Updates the specified cell's display. aCell: The
NSCell object to update
Marks self for display.
- (void)
updateCellInside: (
NSCell*)aCell;
Availability: OpenStep
Updates the interior display of the specified cell.
aCell: The NSCell object whose interior should be
updated
Marks self for display.
- (void)
validateEditing;
Availability: OpenStep
Validates the current editing session and commits
changes.
Instance Variables for NSControl Class
@protected id
_cell;
Availability: OpenStep
Warning the underscore at the start of the
name of this instance variable indicates that, even
though it is not technically private, it is
intended for internal use within the package, and
you should not use the variable in other code.
@protected BOOL
_ignoresMultiClick;
Availability: OpenStep
Warning the underscore at the start of the
name of this instance variable indicates that, even
though it is not technically private, it is
intended for internal use within the package, and
you should not use the variable in other code.
@protected NSInteger
_tag;
Availability: OpenStep
Warning the underscore at the start of the
name of this instance variable indicates that, even
though it is not technically private, it is
intended for internal use within the package, and
you should not use the variable in other code.
- Declared in:
- AppKit/NSControl.h
Availability: OpenStep
This category provides methods that objects can
implement to receive notifications about text
editing events in NSControl objects.
- (void)
controlTextDidBeginEditing: (
NSNotification*)aNotification;
Availability: OpenStep
Called when text editing begins in a control.
aNotification: Notification containing the
NSControl object
- (void)
controlTextDidChange: (
NSNotification*)aNotification;
Availability: OpenStep
Called when text changes during editing in a
control. aNotification: Notification containing
the NSControl object
- (void)
controlTextDidEndEditing: (
NSNotification*)aNotification;
Availability: OpenStep
Called when text editing ends in a control.
aNotification: Notification containing the
NSControl object
- Declared in:
- AppKit/NSControl.h
Availability: OpenStep
Description forthcoming.
- (BOOL)
control: (
NSControl*)control
didFailToFormatString: (
NSString*)string
errorDescription: (
NSString*)error;
Availability: OpenStep
Notifies when string formatting fails
for the control. control: The NSControl
object where formatting failed string: The
string that failed to format error:
Description of the formatting error
Returns: YES if the error
was handled, NO otherwise
- (void)
control: (
NSControl*)control
didFailToValidatePartialString: (
NSString*)string
errorDescription: (
NSString*)error;
Availability: OpenStep
Notifies when partial string validation
fails. control: The NSControl object where
validation failed string: The partial
string that failed validation error:
Description of the validation error
- (BOOL)
control: (
NSControl*)control
isValidObject: (id)object;
Availability: OpenStep
Validates an object value for the
control. control: The NSControl
object requesting validation object: The
object value to validate Returns:
YES if the object is valid,
NO otherwise
- (BOOL)
control: (
NSControl*)control
textShouldBeginEditing: (
NSText*)fieldEditor;
Availability: OpenStep
Determines whether text editing should begin in
the control. control: The NSControl object
requesting to begin editing fieldEditor: The
NSText object that will serve as the field editor
Returns: YES to allow editing to
begin, NO to prevent it
- (BOOL)
control: (
NSControl*)control
textShouldEndEditing: (
NSText*)fieldEditor;
Availability: OpenStep
Determines whether text editing should end in
the control. control: The NSControl object
requesting to end editing fieldEditor: The
NSText object serving as the field editor Returns:
YES to allow editing to end,
NO to continue editing
- (
NSArray*)
control: (
NSControl*)control
textView: (
NSTextView*)textView
completions: (
NSArray*)words
forPartialWordRange: (
NSRange)charRange
indexOfSelectedItem: (int*)index;
Availability: MacOS-X 10.0.0
Provides completions for partial word input during
text editing. control: The NSControl object requesting
completions textView: The NSTextView object
handling the editing words: Array of potential
completion words charRange: The
character range of the partial word index:
Pointer to store the index of the
preferred completion Returns: Array of completion
strings to display
- (BOOL)
control: (
NSControl*)control
textView: (
NSTextView*)textView
doCommandBySelector: (SEL)command;
Availability: MacOS-X 10.0.0
Handles command selector execution
during text editing. control: The NSControl object
where the command occurred textView: The
NSTextView object handling the editing command:
The selector representing the command to
execute Returns: YES if the
command was handled, NO to
use default handling
- Declared in:
- AppKit/NSControl.h
- Conforms to:
- NSObject
Availability: OpenStep
This protocol defines methods that delegates can
implement to control and respond to text editing
operations in NSControl objects. It provides
fine-grained control over validation,
formatting, and editing behavior.
Up