Home Page Icon
Home Page
Table of Contents for
Cover
Close
Cover
by Michael Mahoney, Simson Garfinkel
Building Cocoa Applications: A Step by Step Guide
Building Cocoa Applications: A Step-by-Step Guide
Preface
Cocoa and Mac OS X
Mac OS X and Cocoa Components
Object-Oriented Programming
Cocoa Versions
Cocoa, Objective-C, and Java
The Foundation Classes
Drawing with Quartz
Mac OS X and Classic Mode
Organization of This Book
Part I, Cocoa Overview
Part II, Calculator: Building a Simple Application
Part III, MathPaper: A Multiple-Document, Multiprocess Application
Part IV, GraphPaper: A Multithreaded, Mouse-Tracking Application
What You Will Need
Conventions Used in This Book
Comments and Questions
Acknowledgments
I. Cocoa Overview
1. Understanding theAqua Interface
What Makes Mac OS X So Special?
A Quick Look at the Mac OS X User Interface
Basic Principles of the Aqua Interface
The Toolbox, Carbon, and Cocoa
Consistent Aqua
The Mouse and Cursor
Mouse Action Paradigms
Cursors
Window Types and Behavior
Document Windows
Utility Windows
Dialogs
Alerts
Info Dialogs
Multi-View Windows
Windows with Drawers
Main and Key Windows
Window Order
Menus and the Menu Bar
The Dock
Controls
Buttons
Push buttons
Radio buttons and checkboxes
Pop-up Menus, Command Pop-down Menus, and Combination Boxes
Text Fields and Scrolling Lists
Sliders and Scrollers
Color Wells and Image Wells
Disclosure Triangles
Other Controls
The Finder
The Finder Window
The Toolbar
The Menu Structure
Support Windows and Dialogs
Configuring Your Desktop, Step by Step
Working with the Dock
The Finder’s Viewing Options
Finder Preferences
System Preferences
Menu Guidelines and Keyboard Equivalents
Application Menu
File Menu
Edit Menu
Find Submenu
Format and Font Menus
Window Menu
Services Submenu
Working with the Filesystem,Step by Step
Working with Folders
Working with Files
Forcing an Application to Quit
Moving and Copying Files
Moving Without Activating
Getting Information About Files
Filling and Emptying the Trash
Summary
Exercises
References
2. Tools for Developing Cocoa Applications
Developer Tools
Project Builder
Interface Builder
ObjectAlloc
PropertyListEditor
IconComposer and the icns Browser
Utilities
Working with the Terminal
History of the Video Display Terminal
The Mac OS X Terminal Application
Working in a Unix Shell, Step by Step
The Defaults System
Debugging Programs with gdb
Using gdb in Project Builder, Step by Step
Using gdb in a Terminal Window
gdb Commands
User Interface Design
Summary
Exercises
3. Creating a Simple Application with Interface Builder
Getting Started with Interface Builder
Adding Objects to Your Application
Adding a Button Object to Your Window
Giving Your Button a Funky Sound
Inspecting and Changing Your Button’s Attributes
Objects, Messages, and Targets
Objects and Classes
Targets, Actions, and Connections
Summary
Exercise
4. An Objective-C ApplicationWithout Interface Builder
The Tiny.m Program
An Introduction to Objective-C
Objects and Classes
Methods and Messaging
The id Data Type
A Simple Class Example
Creating and Initializing Objects
The @interface Directive
The #import Directive
Destroying Objects
The @implementation Directive
The +alloc Method and the NSObject Root Class
NSString, NSMutableString, and NSLog
autorelease and the NSAutoreleasePool Class
Tiny.m Revisited
Windows, Views, Delegates, and the setup( ) Function
Views
Drawing with Quartz Inside a View Object
Summary
Exercises
References
II. Calculator: Building a Simple Application
5. Building a Project: A Four-Function Calculator
Getting Started: Building the Calculator Project
Building the Calculator’s User Interface
Customizing the Main Window
Adding Controls in a Window
NSMatrix Dragging Options in IB
Building the Calculator’s Controller Class
Designing the Controller Class
Creating the Controller Class
Outlets and Connections
Adding Outlets to an Object
Adding Actions to the Controller
Creating the Controller Class Files
Adding Code to Make the Controller Class Work
Customizing Buttons and Making Connections
Instantiating (Creating an Instance of) the Controller Class
Setting Up Tags and Titles for the Keypad Buttons
Making the Connections
Compiling and Running a Program
Compiling and Running a Program from PB
Compiler Error Messages
The enterDigit: Action Method
Adding the Four Calculator Functions
Adding the Unary Minus Function to the Controller Class
Using IB’s Read Files Commandwith a New Action Method
The Files in a Project
The main.m Program File Generated by PB
Other PB-Generated Files
Summary
Exercises
6. Nibs and Icons
Customizing MainMenu.nib
Changing the Application Menu
Changing the Strings in the About Box
Managing Multiple Nibs
Modifying the Controller Class
Modifying the Main Calculator Nib
Creating the About Box Nib
Adding Icons to Applications
Viewing Icons with the icns Browser Application
Creating Application Icon Files with IconComposer
Changing Calculator’s Application Icon
Making the New Icon Appear in the About Box
Cocoa’s NSImage Class
Summary
Exercises
References
7. Delegation and Resizing
Handling Different Bases
Modifying the Controller Class
Delegation
Should, Will, and Did Delegates
Specifying an Object’s Delegate
Setting Up a Delegate Outlet in the Nib
Adding the Delegate Method to the Controller
Disabling Buttons for BetterMultiradix Input
Accessing NSMatrix Cells with an NSArray Object
Coherence in Object-Oriented Programming
Resizing Windows Programmatically
Modifying the Calculator’s Interface
Modifying the Controller Class
Two Very Important Classes: NSWindow and NSView
The NSWindow Class
The NSView Class
Summary
Exercises
8. Events and Responders
Events and the NSResponder Chain
What Is an Event?
The NSEvent Object
Events and the NSApplication Object
Responders and the NSResponder Chain
Mouse Event Handling
Keyboard Event Handling
An Event-Handling Example Using TextEdit
Action Messages and the NSResponder Chain
Other Kinds of Events
The Event Loop
The Main Event Loop
Catching Keyboard Eventsfor Our Calculator
Subclassing the NSWindow Class
Dictionaries
Implementing the CalcWindow Class
Methods for searching for button titles
Finishing off the CalcWindow class implementation
Changes in the Controller Class
Summary
Exercises
References
9. Darwin and the Window Server
Unix, Mach, and the Mac OS X Environment
Operating Systems
Unix
Mach
The Mach system support environment
Usernames and UIDs
Processes, PIDs, and UIDs
The Window Server and Quartz
The Application Kit and the Window Server
Seeing All the Processes
Summary
Exercises
References
III. MathPaper: A Multiple-Document, Multiprocess Application
10. MathPaper and Cocoa’sDocument-Based Architecture
The MathPaper Application
The Evaluator Back End
lex and yacc
Building the Back End
Cocoa’s Document-Based Architecture
Building MathPaper’s Front End
Setting Up the MathPaper Project
Changing the Names of MathPaper Project Files
The MathDocument Class
The MainMenu.nib File
Customizing the Document-Based Project Information in PB
Setting Up PaperWindow.nib
Testing MathPaper’s Document-Based Architecture
Summary
Exercises
References
11. Tasks, Pipes, and NSTextView
Processes, Pipes, and Resources
Making Evaluator a MathPaper Auxiliary Executable
MathDocument Class Modifications
Creating PaperController, a Subclass of NSWindowController
The NSScrollView and NSTextView Classes
NSTextView Class Basics
PaperController Class Modifications
Creating the NSTextView Delegate
Getting Data from Evaluator
Adding a Method Using a Category
Killing the Evaluator Processes
Giving Proper Titles to MathPaper Windows
Summary
Exercises
12. Rich Text Format and NSText
Rich Text Format
Formatting NSTextView Output
Rich Text Syntax
Using TextEdit to Explore RTF
RTF Control Words and Symbols
Creating an RTF Class
Integrating Our RTF Class into MathPaper
Summary
Exercises
13. Saving, Loading, and Printing
Data Management with NSDocument
Memory to Disk and Back
Rethinking MathDocument and PaperController
Saving to a File
Icons for MathPaper
Synchronizing PaperController with MathDocument
Archiving MathPaper Documents
Writing the Save Methods
Testing the Save Features
Advanced Save Panel Options
Loading from a File
Marking a Document Window as Edited
Adding Printing Capability
Summary
Exercises
14. Drawing with Quartz
Animation in an About Panel
The Quartz Window Server
Buffered, Retained, and Nonretained Windows
Drawing in an NSView with Quartz
Implementing the About Panel in MathPaper
Creating the MathAnimation View
Quartz Graphics Data Types
Setting Colors, Drawing Rectangles, and Drawing Lines
Drawing Text with Quartz
Drawing Images with Quartz
Timers
Adding and Removing Timers
Putting It All Together
Adding an Easter Egg
Summary
Exercises
References
15. Drawing in a Rectangle: More Fun with Cocoa Views
The Advantages of NSView’s drawRect: Method
BlackView: An NSView That Paints Itself Black
A Closer Look at the NSView Class
NSView Coordinate Systems
Moving and Resizing Views
Flipping
The NSView Hierarchy
Opaque and Nonrectangular Views
Controlling Display and Redisplay
Resizing
BarView: An NSView with a Scaled Coordinate System
PolygonView: A Non-Opaque NSView
Changing the PolygonView’s Size
Placing an NSView Inside an NSScrollView
Responding to Events in an NSView
Getting a Mouse-Down Event
Autosizing Multiple Views in a Window
Summary
Exercises
IV. GraphPaper: A Multithreaded, Mouse-Tracking Application
16. GraphPaper: A Multithreaded Application with a Display List
GraphPaper’s Design
The Interface
Connecting to the Back End
Why Use a Display List?
Working with Multiple Threads
Unix Pipes and Evaluator
Threads
Locking with NSLock
Launching Threads with NSThread
Building the GraphPaper Application
Changes to the Evaluator Back End
Building GraphPaper’s Interface
The GraphView Class Interface File
The GraphView Class Implementation File
The initWithFrame: Method
Implementing the Display List
Scaling the GraphView and the drawRect: Method
The Data Stuffer Methods
Stopping a Running Graph
The Graph Displayer
The Segment Class
Testing GraphPaper
Extending the Display List
Adding Axes
Adding Labeling
Using the Label Class
Summary
Exercises
References
17. Color
Colors and Color Objects
Colors from a Programmer’s Point of View
Colors from a User’s Point of View
Programming with Color
Adding Color to GraphPaper
Creating a Preferences Panel
The Controller Class
Creating the Preferences Nib, Panel, and PrefController
PrefController Class Implementation
ColorGraphView
The ColorGraphView Class Implementation
Setting the Colors
Setting the Initial Color
The GraphView, Segment, and Label Classes
Testing GraphPaper’s Color
Summary
Exercises
18. Tracking the Mouse
Tracking the Mouse
Tracking Rectangles
Accepting Mouse-Moved Events
Adding Mouse Tracking to GraphPaper
Changes to the GraphPaper Interface
Changes to the TrackingGraphView Class Files
Summary
Exercises
References
19. Zooming and Saving Graphics Files
Adding a Zoom Button to GraphPaper
The NSScrollView Class Revisited
Changes to MainMenu.nib
Changes to ZoomScrollView
Testing the Zoom Button
Autosizing in GraphPaper
Saving to PDF
Producing PDFs from NSView
Changes to MainMenu.nib
Changes to the Controller Class
Testing the Save Graph Menu Command
Saving to TIFF
Creating an Accessory NSView
Changes to the Controller Class
Testing the PDF and TIFF Save Feature
Summary
Exercises
20. Pasteboards, Services, Modal Sessions, and Drag-and-Drop
Cut, Copy, and Paste with the Pasteboard
Types of Pasteboards
Users and Pasteboards
Providing Data to the Pasteboard
Using the Pasteboard in GraphPaper
Providing Data Through Lazy Evaluation
Implementing the Cut Command
Testing GraphPaper’s Copy and Cut Commands
Services
How Services Work
Creating Your Own Service
Modifications Required for GraphPaper to Implement Services
Creating the Services Advertisement
Modification of GraphView
Changes to Controller
Testing GraphPaper’s Service
Drag-and-Drop
Being a Drag-and-Drop Source
Being a Drag-and-Drop Receiver
Summary
Exercises
21. Preferences and Defaults
Preferences and the Defaults Database System
Accessing the Defaults Database with PropertyListEditor
Accessing the Defaults Database in a Terminal
Defaults Domains
Persistent versus volatile defaults
Standard defaults domains
The NSUserDefaults Class
Adding Defaults to GraphPaper
Registering the Default Values
Reading Values from the Defaults Database
Making the Preferences Panel Work with Defaults
Modifying the Preferences Panel
Changes to the PrefController Class
Testing the Updated Preferences Panel
Setting Up a Multi-View Panel
Tab Views
Loading and Saving the Default Values
Summary
Exercises
A. Cocoa Resources
Apple Resources
Online Documentation
Apple Developer Connection
Sample Code
Worldwide Developers Conference
Registering Creator Codes
Bug Reporting
Third-Party Resources
Mailing Lists
Web Sites
Printed Resources
Index
Colophon
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Next
Next Chapter
Building Cocoa Applications: A Step-by-Step Guide
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset