building cocoa applications - a step-by-step guide (2002)

727 460 0
building cocoa applications - a step-by-step guide (2002)

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Building Cocoa Applications: A Step-by-Step Guide By Simson Garfinkel, Michael Mahoney Publisher: O'Reilly Pub Date: May 2002 ISBN: 0-596-00235-1 Pages: 648 Copyright Dedication Preface Cocoa and Mac OS X Organization of This Book What You Will Need Conventions Used in This Book Comments and Questions Acknowledgments Part I: Cocoa Overview Chapter 1. Understanding theAqua Interface Section 1.1. What Makes Mac OS X So Special? Section 1.2. A Quick Look at the Mac OS X User Interface Section 1.3. Basic Principles of the Aqua Interface Section 1.4. The Mouse and Cursor Section 1.5. Window Types and Behavior Section 1.6. Menus and the Menu Bar Section 1.7. The Dock Section 1.8. Controls Section 1.9. The Finder Section 1.10. Configuring Your Desktop, Step by Step Section 1.11. Menu Guidelines and Keyboard Equivalents Section 1.12. Working with the Filesystem,Step by Step Section 1.13. Summary Section 1.14. Exercises Section 1.15. References Chapter 2. Tools for Developing Cocoa Applications Section 2.1. Developer Tools Section 2.2. Utilities Section 2.3. Working with the Terminal Section 2.4. Debugging Programs with gdb Section 2.5. User Interface Design Section 2.6. Summary Section 2.7. Exercises Chapter 3. Creating a Simple Application with Interface Builder Section 3.1. Getting Started with Interface Builder Section 3.2. Adding Objects to Your Application Section 3.3. Objects, Messages, and Targets Section 3.4. Summary Section 3.5. Exercise Chapter 4. An Objective-C ApplicationWithout Interface Builder Section 4.1. The Tiny.m Program Section 4.2. An Introduction to Objective-C Section 4.3. Tiny.m Revisited Section 4.4. Summary Section 4.5. Exercises Section 4.6. References Part II: Calculator: Building a Simple Application Chapter 5. Building a Project: A Four-Function Calculator Section 5.1. Getting Started: Building the Calculator Project Section 5.2. Building the Calculator's User Interface Section 5.3. Building the Calculator's Controller Class Section 5.4. Customizing Buttons and Making Connections Section 5.5. Compiling and Running a Program Section 5.6. Compiler Error Messages Section 5.7. The enterDigit: Action Method Section 5.8. Adding the Four Calculator Functions Section 5.9. Adding the Unary Minus Function to the Controller Class Section 5.10. The Files in a Project Section 5.11. Summary Section 5.12. Exercises Chapter 6. Nibs and Icons Section 6.1. Customizing MainMenu.nib Section 6.2. Managing Multiple Nibs Section 6.3. Adding Icons to Applications Section 6.4. Changing Calculator's Application Icon Section 6.5. Cocoa's NSImage Class Section 6.6. Summary Section 6.7. Exercises Section 6.8. References Chapter 7. Delegation and Resizing Section 7.1. Handling Different Bases Section 7.2. Delegation Section 7.3. Disabling Buttons for BetterMultiradix Input Section 7.4. Resizing Windows Programmatically Section 7.5. Two Very Important Classes: NSWindow and NSView Section 7.6. Summary Section 7.7. Exercises Chapter 8. Events and Responders Section 8.1. Events and the NSResponder Chain Section 8.2. Events and the NSApplication Object Section 8.3. The Event Loop Section 8.4. Catching Keyboard Eventsfor Our Calculator Section 8.5. Summary Section 8.6. Exercises Section 8.7. References Chapter 9. Darwin and the Window Server Section 9.1. Unix, Mach, and the Mac OS X Environment Section 9.2. The Window Server and Quartz Section 9.3. Seeing All the Processes Section 9.4. Summary Section 9.5. Exercises Section 9.6. References Part III: MathPaper: A Multiple-Document, Multiprocess Application Chapter 10. MathPaper and Cocoa'sDocument-Based Architecture Section 10.1. The MathPaper Application Section 10.2. The Evaluator Back End Section 10.3. Cocoa's Document-Based Architecture Section 10.4. Building MathPaper's Front End Section 10.5. Summary Section 10.6. Exercises Section 10.7. References Chapter 11. Tasks, Pipes, and NSTextView Section 11.1. Processes, Pipes, and Resources Section 11.2. Making Evaluator a MathPaper Auxiliary Executable Section 11.3. MathDocument Class Modifications Section 11.4. Creating PaperController, a Subclass of NSWindowController Section 11.5. The NSScrollView and NSTextView Classes Section 11.6. PaperController Class Modifications Section 11.7. Summary Section 11.8. Exercises Chapter 12. Rich Text Format and NSText Section 12.1. Rich Text Format Section 12.2. Creating an RTF Class Section 12.3. Integrating Our RTF Class into MathPaper Section 12.4. Summary Section 12.5. Exercises Chapter 13. Saving, Loading, and Printing Section 13.1. Data Management with NSDocument Section 13.2. Saving to a File Section 13.3. Loading from a File Section 13.4. Marking a Document Window as Edited Section 13.5. Adding Printing Capability Section 13.6. Summary Section 13.7. Exercises Chapter 14. Drawing with Quartz Section 14.1. Animation in an About Panel Section 14.2. The Quartz Window Server Section 14.3. Implementing the About Panel in MathPaper Section 14.4. Quartz Graphics Data Types Section 14.5. Timers Section 14.6. Putting It All Together Section 14.7. Summary Section 14.8. Exercises Section 14.9. References Chapter 15. Drawing in a Rectangle: More Fun with Cocoa Views Section 15.1. The Advantages of NSView's drawRect: Method Section 15.2. BlackView: An NSView That Paints Itself Black Section 15.3. A Closer Look at the NSView Class Section 15.4. BarView: An NSView with a Scaled Coordinate System Section 15.5. PolygonView: A Non-Opaque NSView Section 15.6. Responding to Events in an NSView Section 15.7. Autosizing Multiple Views in a Window Section 15.8. Summary Section 15.9. Exercises Part IV: GraphPaper: A Multithreaded, Mouse-Tracking Application Chapter 16. GraphPaper: A Multithreaded Application with a Display List Section 16.1. GraphPaper's Design Section 16.2. Working with Multiple Threads Section 16.3. Building the GraphPaper Application Section 16.4. Extending the Display List Section 16.5. Summary Section 16.6. Exercises Section 16.7. References Chapter 17. Color Section 17.1. Colors and Color Objects Section 17.2. Adding Color to GraphPaper Section 17.3. Summary Section 17.4. Exercises Chapter 18. Tracking the Mouse Section 18.1. Tracking the Mouse Section 18.2. Adding Mouse Tracking to GraphPaper Section 18.3. Summary Section 18.4. Exercises Section 18.5. References Chapter 19. Zooming and Saving Graphics Files Section 19.1. Adding a Zoom Button to GraphPaper Section 19.2. Saving to PDF Section 19.3. Saving to TIFF Section 19.4. Creating an Accessory NSView Section 19.5. Summary Section 19.6. Exercises Chapter 20. Pasteboards, Services, Modal Sessions, and Drag-and-Drop Section 20.1. Cut, Copy, and Paste with the Pasteboard Section 20.2. Using the Pasteboard in GraphPaper Section 20.3. Services Section 20.4. Creating Your Own Service Section 20.5. Drag-and-Drop Section 20.6. Summary Section 20.7. Exercises Chapter 21. Preferences and Defaults Section 21.1. Preferences and the Defaults Database System Section 21.2. Adding Defaults to GraphPaper Section 21.3. Making the Preferences Panel Work with Defaults Section 21.4. Setting Up a Multi-View Panel Section 21.5. Summary Section 21.6. Exercises Appendix A. Cocoa Resources Section A.1. Apple Resources Section A.2. Third-Party Resources Colophon Book: Building Cocoa Applications: A Step-by-Step Guide Copyright © 2002 O'Reilly & Associates, Inc. All rights reserved. Printed in the United States of America. Published by O'Reilly & Associates, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O'Reilly & Associates books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://safari.oreilly. com). For more information contact our corporate/institutional sales department: 800-998- 9938 or corporate@oreilly.com. Nutshell Handbook, the Nutshell Handbook logo, and the O'Reilly logo are registered trademarks of O'Reilly & Associates, Inc. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and O'Reilly & Associates, Inc. was aware of a trademark claim, the designations have been printed in caps or initial caps. The association between the image of a Mastiff and building Cocoa applications is a trademark of O'Reilly & Associates, Inc. Apple Computer, Inc. boldly combined open source technologies with its own programming efforts to create Mac OS X, one of the most versatile and stable operating systems now available. In the same spirit, Apple has joined forces with O'Reilly & Associates, Inc. to bring you an indispensable collection of technical publications. The ADC logo indicates that the book has been technically reviewed by Apple engineers and is recommended by the Apple Developer Connection. Apple, the Apple logo, AppleScript, AppleTalk, AppleWorks, Cocoa, Finder, Mac, Macintosh, MPW, QuickDraw, QuickTime, and Sherlock are trademarks of Apple Computer, Inc., registered in the United States and other countries. Aqua, Carbon, and Quartz are trademarks of Apple Computer, Inc. While every precaution has been taken in the preparation of this book, the publisher and the author assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein. Book: Building Cocoa Applications: A Step-by-Step Guide Dedication For the kids: Nina, Timmy, Sonia, Jared, and Draken Book: Building Cocoa Applications: A Step-by-Step Guide Preface Welcome! Building Cocoa Applications describes how to write Objective-C programs for computers running the Mac OS X operating system, using the object-oriented Cocoa application framework. The book covers a wide range of technologies: ● The Aqua graphical user interface, Cocoa developer tools, object-oriented concepts, and the Objective-C language ● Cocoa programming and graphics concepts: nibs, icons, delegation, resizing, events, responders, tasks, pipes, color, Rich Text, the mouse, zoom buttons, pasteboards, modal sessions, and drag-and-drop ● The Cocoa environment: Darwin and the Window Server, the document-based architecture, the Quartz drawing system, Cocoa's preferences and defaults systems, and facilities for saving, loading, and printing Building Cocoa Applications is a no-nonsense, hands-on book that's intended for serious developers. It's filled with extended examples illustrating complete applications written in Objective-C. As you proceed through the book, you'll take a step-by-step approach to building a series of applications of increasing complexity, adding features as you go. Although we do not assume prior knowledge of the Macintosh or any other window-based operating environment, we do assume some familiarity with programming in general and the ANSI C language in particular. Our primary goal is to get you up and running as quickly as possible. If you carefully read this book from cover to cover and diligently build the sample applications along with us, we're confident that you'll soon be writing your own sophisticated Cocoa graphics applications. While this book is fast moving, we start by laying a solid foundation. Part I of the book explains how to use Aqua, the Mac OS X graphical user interface (GUI), and describes the Cocoa developer tools you'll use to build applications. It also introduces two simple but complete Cocoa applications - one built with Cocoa's Interface Builder tool and one built without it. Parts II, III, and IV are organized by application: we'll build three major, highly useful graphics applications and, in doing so, teach you how to build your own applications with Cocoa. The applications we will build are: Calculator (Part II) A simple, four-function calculation application that's similar to the calculator that comes with Mac OS X MathPaper (Part III) An application that is similar to a word processor but that solves equations you supply GraphPaper (Part IV) A more complex, multithreading application that graphs a formula in two dimensions The first chapter in each of these three parts introduces the application and builds its most basic functionality. Each subsequent chapter adds a new layer of functionality. For example, Chapter 6 shows how to add an icon to the Calculator application so it will display nicely in the Finder, Chapter 12 enhances MathPaper so it displays Rich Text, and Chapter 19 adds zoom buttons to GraphPaper. We'll also build numerous additional simple applications throughout the book to demonstrate specific features of Cocoa and Mac OS X. You can build all of these applications right along with us - we provide simple but complete instructions on how to do whatever is necessary. Code for all of the applications we'll build is provided on the O'Reilly web site (see Section P.5, later in this Preface). [...]... Objective-C language in which Cocoa is written, and Cocoa programming itself q q q q Chapter 1 Chapter 2 Chapter 3 Chapter 4 Book: Building Cocoa Applications: A Step-by-Step Guide Section: Part I: Cocoa Overview Chapter 1 Understanding theAqua Interface The Mac OS X graphical user interface (GUI) is called Aqua Aqua's advanced use of color, animation, and transparency and its plethora of powerful user-oriented... your programs automatically get the Aqua look and feel Although every application is different, Cocoa makes it easier for all applications to work in similar ways, which in turn makes it easier for people to learn new applications Cocoa also makes it easier for applications to work with each other Because of Cocoa' s object-oriented nature, Cocoa applications can easily provide services and special functions... performance considerations: Cocoa- based programs run faster if they are written in Objective-C than if they are written in Java One significant advantage of Java over Objective-C is the large number of third-party class libraries that are now available for Java If you need to use one of these libraries, you can benefit from using Java for some or all of your Cocoa applications In particular, Apple's... Framework now supports only the Java-based application programming interface (API) One of the primary differences between Java and Objective-C is memory management: Java has automatic garbage collection, whereas Objective-C has a reference-count-based memory-management system The Objective-C system is cruder, but it gives programmers greater control and generally produces applications that run faster...Book: Building Cocoa Applications: A Step-by-Step Guide Section: Preface Cocoa and Mac OS X Cocoa is an object-oriented development environment that runs in the Mac OS X environment Cocoa software has previously been bundled with the Mac OS X user system on a separate developer CD-ROM, but newer systems come with a package that users can install - the package name is Developer.mpkg, and it's found in /Applications/ ... and Cocoa programming itself Chapter 1, contains an overview of Aqua features and behaviors that programmers should understand so that they can build applications that look and feel like Mac OS X applications In particular, programmers writing new Mac OS X applications should follow Aqua's stringent interface guidelines so as not to confuse users Chapter 1 also contains a tutorial on how to become a. .. and Java Although the Cocoa Foundation and the Application Kit are written in Objective-C, Cocoa programs can be written in either Objective-C or Java This freedom comes from the fact that Java and Objective-C have very similar models of object-oriented programming, which has allowed Apple to create a "Java bridge" that allows Java objects to invoke Objective-C methods and vice versa Java can even be... graphically IB allows easy access to Cocoa' s Application Kit , a set of more than 120 powerful classes that define and create objects for use by your applications We'll discuss these powerful tools in the next chapter Book: Building Cocoa Applications: A Step-by-Step Guide Section: Chapter 1 Understanding theAqua Interface 1.2 A Quick Look at the Mac OS X User Interface Let's take a look at the main... an easy-to-use, object-oriented programming language that is well suited to writing [2] GUIs The Cocoa environment provides consistency and ease of programming that are unparalleled among the other programming environments available today 1.3.2 Consistent Aqua Aqua's consistency means that windows in different applications have the same appearance and functionality; for example, mouseclicks and drags... detailed information on programming Cocoa applications in Java, see the upcoming O'Reilly book Cocoa and Java (And for those interested in writing Perl applications for this new platform, watch for Programming Cocoa Applications with Perl, also coming soon from O'Reilly.) The Foundation Classes Many of the Cocoa class libraries are actually implemented with the Apple Foundation library The Foundation . kids: Nina, Timmy, Sonia, Jared, and Draken Book: Building Cocoa Applications: A Step-by-Step Guide Preface Welcome! Building Cocoa Applications describes how to write Objective-C programs for. the Java-based application programming interface (API). One of the primary differences between Java and Objective-C is memory management: Java has automatic garbage collection, whereas Objective-C. every application is different, Cocoa makes it easier for all applications to work in similar ways, which in turn makes it easier for people to learn new applications. Cocoa also makes it easier

Ngày đăng: 26/10/2014, 20:14

Từ khóa liên quan

Mục lục

  • Building Cocoa Applications: A Step-by-Step Guide

  • Copyright

  • Dedication

  • Preface

    • Cocoa and Mac OS X

    • Organization of This Book

    • What You Will Need

    • Conventions Used in This Book

    • Comments and Questions

    • Acknowledgments

    • Part I: Cocoa Overview

      • Chapter 1. Understanding theAqua Interface

        • 1.1 What Makes Mac OS X So Special?

        • 1.2 A Quick Look at the Mac OS X User Interface

        • 1.3 Basic Principles of the Aqua Interface

        • 1.4 The Mouse and Cursor

        • 1.5 Window Types and Behavior

        • 1.6 Menus and the Menu Bar

        • 1.7 The Dock

        • 1.8 Controls

        • 1.9 The Finder

        • 1.10 Configuring Your Desktop, Step by Step

        • 1.11 Menu Guidelines and Keyboard Equivalents

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan