9.2. Connecting Carbon Interfaces
Every control in a Carbon nib file can have a unique key that identifies the control within your application. This key is called a ControlID and is composed of the following bits of information:
struct ControlID { OSType signature; SInt32 id; };
The signature field is an OSType that identifies the owner of the control; in an application, this is normally the application's creator code. The id field is simply a signed number. Each of your controls will have a unique id number. Traditionally these numbers start at 128 and increase in value.
Action controls, such as buttons or text fields, have an associated command that takes place when the control is changed or used. Control commands are identified by 32-bit identifiers, which resemble OSType codes. Carbon handles some actions automatically, such as quit for quitting an application.
Together these ControlID and command values function like Cocoa outlets and actions, except you must manage the controls manually. Cocoa will automatically set your outlet instance variables when your nib is loaded, and will simply call your Objective-C method actions at the appropriate times. In Carbon programming, you must find the control yourself using its ControlID if you want to work with the control (such as ask it for its value). Also, you must manually register callback functions to receive events from the operating system, and interpret the events yourself.
In this example you build a Carbon version of the ...
Get Beginning Mac OS® X Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.