The simplest Cocoa application, even one without a line of code added to it, includes a wealth of features you get “for free.” You do not have to program these features yourself. You can see this when you test an interface in Interface Builder.
Application and Window Behavior
Controls and Text
Menu Commands
Document Management
File Management
Communicating with Other Applications
Custom Drawing and Animation
Internationalization
Editing Support
Printing
Help
Plug-in Architecture
In the Interface Builder test mode, Currency Converter behaves almost like any other application on the screen. Click elsewhere on the screen, and Currency Converter is deactivated, becoming totally or partially obscured by the windows of other applications.
If you closed your application, run it again. Once the Currency Converter window is open, move it around by its title bar. Here are some other tests you can do:
Open the Edit menu. Its items appear and then disappear when you release the mouse button, as with any application menu.
Click the miniaturize button. Click the window’s icon in the Dock to get the application back.
Click the close button; the Currency Converter window disappears.
If you hadn’t configured the Currency Converter window in Interface Builder to remove the resize box, you could resize it now. You could also have set the autoresizing attributes of the window and its views so that the window’s elements would resize proportionally to the resized window or would retain their initial size (see Interface Builder Help for details on autoresizing).
The buttons and text fields of Currency Converter come with many built-in behaviors. Notice that the Convert button pulsates (as is the default for buttons associated with the Return key). Click the Convert button. Notice how the button is highlighted for a moment.
If you had buttons of a different style, they would also respond in characteristic ways to mouse clicks.
Now click in one of the text fields. See how the insertion point blinks in place. Type some text and select it. Use the commands in the Edit menu to copy it and paste it in the other text field.
Do you recall the nextKeyView connections you made between the Currency Converter text fields? Insert the cursor in a text field, press the Tab key and watch the cursor jump from field to field.
Interface Builder gives every new application a default menu that includes the application, File, Edit, Window, and Help menus. Some of these menus, such as Edit, contain ready-made sets of commands. For example, with the Services submenu (whose items are added by other applications at runtime) you can communicate with other Mac OS X applications. You can manage your application’s windows with the Window menu.
Currency Converter needs only a few commands: the Quit and Hide commands and the Edit menu’s Copy, Cut, and Paste commands. You can delete the unwanted commands if you wish. However, you could also add new ones and get “free” behavior. An application designed in Interface Builder can acquire extra functionality with the simple addition of a menu or menu command, without the need for compilation. For example:
The Font submenu adds behavior for applying fonts to text in text view objects, like the one in the text view object in the Text palette. Your application gets the Font window and a font manager “for free.” Text elements in your application can use this functionality right out of the box. See Font Panel for more information.
The Text submenu allows you to align text anywhere text is editable and to display a ruler in the NSText object for tabbing, indentation, and alignment.
Thanks to the PDF graphics core of Mac OS X, many objects that display text or images can print their contents as PDF documents.
Many applications create and manage repeatable, semi-autonomous objects called documents. Documents contain discrete sets of information and support the entry and maintenance of that information. A word-processing document is a typical example. The application coordinates with the user and communicates with its documents to create, open, save, close, and otherwise manage them. You could also save your Currency Converters as documents, with a little extra code.
See Document-Based Applications Overview in Cocoa Design Guidelines Documentation for more information.
An application can use the Open dialog, which is created and managed by the Application Kit framework, to help the user locate files in the file system and open them. It can also use the Save dialog to save information in files. Cocoa also provides classes for managing files in the file system (creating, comparing, copying, moving, and so forth) and for managing user defaults.
Cocoa gives an application several ways to exchange information with other applications:
Pasteboards. Pasteboards are a global facility for sharing information among applications. Applications can use the pasteboards to hold data that the user has cut or copied and may paste into another application. Each application can have multiple pasteboards accepting multiple data types.
Services. Any application can access the services provided by another application, based on the type of selected data (such as text). An application can also provide services to other applications such as encryption, language translation, or record fetching.
Drag and drop. If your application implements the proper protocol, users can drag objects to and from the interfaces of other applications.
Cocoa lets you create your own custom views that draw their own content and respond to user actions. To assist you in this, Cocoa provides objects and functions for drawing, such as the NSBezierPath class.
Cocoa provides API and tool support for internationalizing the strings, images, sounds, and nib files that are part of an application. Internationalization allows you to easily localize your application to multiple languages and locales without significant overhead.
You can get several panels (and associated functionality) when you add certain menus to your application’s menu bar in Interface Builder. These “add-ons” include the Font window (and font management), the color picker (and color management), the text ruler, and the tabbing and indentation capabilities the Text menu brings with it.
Formatter classes enable your application to format numbers, dates, and other types of field values. Support for validating the contents of fields is also available.
With just a simple Interface Builder procedure, Cocoa automates simple printing of views that contain text or graphics. When a user executes the Print command, an appropriate dialog helps to configure the print process. The output is WYSIWYG (what you see is what you get).
Several Application Kit classes give you greater control over the printing of documents and forms, including features such as pagination and page orientation.
You can very easily create context-sensitive help—known as “help tags”—for your application using the Interface Builder inspector. After you’ve entered the help tag text for the user interface elements in your application, a small window containing concise information on the element appears when the user places the pointer over these elements.
You can design your application so that users can incorporate new modules later on. For example, a drawing program could have a tools palette: pencil, brush, eraser, and so on. You could create a new tool and have users install it. When the application is next started, this tool appears in the palette.
Last updated: 2007-10-31