Learning Carbon

Book description

Learning Carbon is designed to get you programming right away in Carbon™, one of two APIs (Application Programmer Interfaces) Macintosh® programmers can use to write applications that run native in Mac® OS X. Using Carbon, you don't have to rewrite your Mac OS programs entirely to get them to take advantage of the new features in Mac OS X. Instead, all you have to rewrite is the 10 to 20 percent of the code that can't be translated to OS X. For C programmers, Apple's Carbon is the essential building block for applications on Mac OS X. With Carbon, you can use simple, traditional C interfaces to create world-class applications for a world-class operating system. After orienting you with a detailed tour of a Carbon application, Learning Carbon walks you through the entire process of designing and creating a complete Carbon application called Moon Travel Planner. Along the way, you'll be introduced to two pivotal development tools: Project Builder and Interface Builder. You'll learn key concepts about Carbon and Mac OS X programming, including event management, resource handling, and bundle anatomy. And you'll get direct, hands-on instruction on how to implement essential application tasks, such as managing windows, printing documents, opening and saving files, creating and responding to menu commands, providing user help, and organizing your application for easy localization in multiple countries and languages. After finishing this book, you'll be ready to start writing your own Carbon applications. Written by Apple insiders with access to engineers deeply involved in creating Mac OS X, Learning Carbon brings you information that's not available anywhere else, to get you in on the ground floor of the exciting new Mac OS X application development market.

Publisher resources

Download Example Code

Table of contents

  1. Learning Carbon
    1. Preface
      1. Why Carbon?
      2. Who Might Find This Book Helpful
      3. What You Need
      4. What’s Up Ahead
      5. Side Trips and Terms
      6. Code
      7. The Environment Could Change
      8. How to Contact Us
    2. 1. Introduction to Carbon
      1. Carbon and Mac OS X
      2. What’s in Carbon?
      3. Building Carbon Applications
      4. The Carbon Factory Tour
        1. The Starter Kit
          1. The Toolbox interfaces
          2. Aqua
          3. Behind the curtain
        2. The Expansion Pack
        3. Specialty Interfaces
          1. QuickTime
          2. Color, images, and print production
          3. 3D graphics
          4. HTML
          5. Speech
          6. Text and international services
          7. Internet and networking
          8. Security
          9. Low-level tweaking
        4. Utility Interfaces
        5. Legacy Interfaces
      5. Recap
    3. 2. Specifying a Carbon Application: Moon Travel Planner
      1. The Moon Travel Planner Window
        1. Behavior
        2. Implementation
      2. The Menu Bar
        1. Behavior
        2. Implementation
      3. The About Window
        1. Behavior
        2. Implementation
      4. The Facts for the Traveler Window
        1. Behavior
        2. Implementation
      5. The Itinerary Window
        1. Behavior
        2. Implementation
      6. Recap
    4. 3. Project Builder Projects
      1. A Carbon Application Project
        1. File References
          1. Sources
          2. Resources
          3. External frameworks and libraries
          4. Products
        2. Targets
        3. Main.c: A Skeletal Application
        4. Things May Not Be Where You Think They Are
        5. Application Bundles
        6. Building and Running a Project
        7. Debugging a Project
        8. Onscreen Documentation
      2. Moon Travel Planner: Creating a Project
        1. Building and Running the Skeletal Application
      3. Recap
    5. 4. Interface Builder: Nibs and Windows
      1. A Carbon Nib File
        1. The Default Items in a Nib File
        2. Info Windows
        3. Window Classes
        4. Theme Brush
        5. Controls
        6. Attributes
        7. Receives
      2. Moon Travel Planner: Modifying the Default Window
        1. Open Interface Builder
        2. Revise the Window Title
        3. Set the Window Class, Controls, and Attributes
        4. Set the Window’s Size
        5. Build, Run, and Check the Application
        6. Recap
    6. 5. Interface Builder: Toolsand Controls
      1. Palettes and Layout Tools
        1. The Carbon Palettes Window
          1. Menus palette
          2. Controls palette
          3. Enhanced controls palette
          4. Data views palette
          5. Windows palette
        2. Layout Tools
      2. Moon Travel Planner: Adding Objectsto the Main Window
        1. Open the Nib File
        2. Add an Item from the Enhanced Controls Palette
        3. Add Items from the Controls Palette
        4. Add a PICT Resource
        5. Align Objects with the Layout Tools
        6. Check the Interface
        7. Recap
    7. 6. Carbon Events
      1. Carbon Event Handling
        1. Event Targets
        2. Event Types
        3. Event References
        4. Default Event Handlers
        5. Defining an Event Handler
        6. Installing an Event Handler
      2. MoonTravel Planner: Writing an Event Handler
        1. Identify Events
        2. Write the Main Window Event Handler
          1. The main window event handler
          2. The compute command handler
        3. Install the Main Window Event Handler
          1. Modify the main function
        4. Call the Application Event Loop Function
        5. Recap
    8. 7. Interface Builder: Menus
      1. The Menu Bar
        1. Application Menu
        2. File Menu
        3. Edit Menu
        4. Window Menu
        5. Help Menu
        6. Hierarchical Menus
        7. Contextual Menus
      2. Moon Travel Planner: Modifying the Menu Bar
        1. Disable the Items You Won’t Need
        2. Set Up the Items You Know You’ll Need
          1. Add an About command
          2. Add an Open Itinerary command
          3. Add Commands for Close and Save As
          4. Add Commands for Page Setup and Print
          5. Delete the Help Menu
        3. Add an Application-Specific Menu to the Menu Bar
        4. Add Code to Your Project
          1. Create the menu bar
          2. Handle menu commands
        5. Test the Menus
        6. Recap
    9. 8. Text and Localization
      1. Language-Specific Folders
        1. InfoPlist.strings File
        2. Help Folder
        3. Nib Files
        4. Localizable Strings Files
      2. Moon Travel Planner: Displaying Localized Text
        1. Create a New Window
        2. Add a Text Field
        3. Create Content for the Window
        4. Write a Function to Display the Window
          1. Adding function and global declarations
          2. Creating the window
          3. Writing the show moon facts window function
        5. Modify the Main Window Event Handler
        6. Write a Handler for the Moon Facts Window
          1. Identify events
          2. Write the code for the handler
          3. Install the moon facts window event handler
        7. Make Sure the Text Displays Properly
        8. Recap
    10. 9. Printing
      1. The Carbon Printing Manager
        1. A Sample Printing Session
          1. A look at the print loop
          2. Error handling
        2. Sequence and Scope for Printing Functions
        3. Data Types for Working with Printing Sessions
        4. Functions for Working with Printing Sessions
        5. Where to Go from Here
      2. Moon Travel Planner: Adding Printing to the Moon Facts Window
        1. Define Constants for Working with Printing
        2. Define Data Types for Working with Printing
        3. Define Prototypes for Printing Functions
        4. Write Printing Functions
          1. MTPCreatePrintInfoForWindow
          2. MTPSetupPageFormatForPrinting
          3. MTPPageSetupDoneProc
          4. MTPDoPageSetup
          5. MTPPrintDialogDoneProc
          6. MTPDoPrint
          7. MTPDrawMoonFactsPage
          8. MTPPagesInDoc
          9. MTPPostPrintingErrors
          10. MTPDoPrintLoop
        5. Add a Print Format String to the Localized Strings
        6. Add Printing Code to the Main Function
        7. Adjust Code in the Moon FactsWindow Event Handler
        8. Test the Page Setup and Print Commands
        9. Recap
    11. 10. Property Lists
      1. The Information Property List: Info.plist
        1. Standard Keys
        2. Finder Keys
        3. Viewing and Modifying Property Lists in Project Builder
        4. The About Window
      2. Moon Travel Planner: Modifying and Using Properties
        1. Modify the Property List
        2. Create a New Window
        3. Create the About Window from the nib File
        4. Write a Function to Handle the About Command
        5. Writing an Event Handler for the About Window
          1. Build, run, and test the application
        6. Recap
    12. 11. Files
      1. Managing Files on the Mac
        1. The File Manager
          1. Files
            1. The organization of the file system
            2. The Finder and the file system
            3. The volume format
            4. Identifying a file
            5. File access
            6. File size
          2. The typical tasks of file management
            1. Creating a new file
            2. Opening a file
            3. Reading and writing data
        2. Navigation Services
          1. The programming model
          2. The navigation event handler
          3. Persistence
          4. The Navigation Services dialogs
            1. Standard user interface elements in Navigation Services dialogs
            2. The column view browser
            3. The Where pop-up menu
            4. Open dialog
            5. Save Changes
            6. Save Location
      2. Moon Travel Planner: Handling Files
        1. Create a Window to Display the Itinerary
        2. Define Constants and Variables for Creating Itinerary Files
        3. Write the Itinerary Window Event Handler
        4. Open an Itinerary File
          1. Configure and display an Open dialog
          2. Respond to the user’s action
          3. Retrieve the file to open
          4. Create a new itinerary window
          5. Read the itinerary file
          6. Display the itinerary text
        5. Save the Itinerary
          1. Configure and display a Save dialog
          2. Respond to the user’s action
          3. Create the save file
          4. Write the save data
        6. Close the Itinerary
        7. Handle the Open Command from the Main Window
        8. Build, Run, and Test the Application
      3. Recap
    13. 12. Providing Help
      1. Help on Mac OS X
        1. Help Content for Help Books
          1. Guidelines for creating help content
          2. The mechanics of creating help book content
            1. Anchors
            2. Segments
            3. Descriptions
            4. Keywords
          3. Indexing
        2. Help Tags
          1. How does a help tag work?
          2. Guidelines for writing help tags
      2. Moon Travel Planner: Adding Help
        1. Add the Help Book to the Project
        2. Modify the Application’s Property List
        3. Register the Help Book
        4. Add a Help Tag
        5. Make Sure Help Works Properly
      3. Recap
    14. 13. Desktop Icons
      1. Icon Basics
        1. Types of Icons
          1. Application icons
          2. Document icons
          3. Icons for plug-ins and other support files
        2. Design Tips
        3. Icon Sizes and Masks
        4. Assigning Icons to Applications and Files
          1. Importing icons into Icon Composer
          2. Register the Icon Composer file for the application icon
          3. Adding a Document Type to a Project
            1. Generic file types
            2. Custom file types
      2. Moon Travel Planner: Adding Icons
        1. Import Images to Icon Composer
        2. Add the Icon Files
        3. Register the Application Icon File
        4. Add a Document Type
        5. Make Sure the Icons Display in the Finder
      3. Recap
    15. 14. Beyond Moon Travel: Advanced Topics
      1. Scriptable Applications
        1. How Scripting Works
        2. Making Your Application Scriptable
          1. Design scripting in from the beginning
          2. Identify the objects and commands you will support
          3. Create an ‘aete’ resource that describes your scripting support
          4. Write handlers for the Apple events you support
          5. Install your Apple event handlers
          6. Process incoming Apple events
      2. Threads and Multiprocessing
        1. Multiprocessing Services in a Peanut Shell
      3. Tab Controls
        1. Add a Tab Control to a Window
        2. Add Controls to a User Pane
        3. Write a Handler for the Tab Controls and Panes
      4. Epilogue
    16. A. Additional Resources
      1. Building Your Mac OS X Library
        1. Inside Mac OS X: System Overview
        2. Inside Mac OS X: Aqua Human Interface Guidelines
        3. Inside Carbon: Carbon Porting Guide
        4. Discovering QuickTime
      2. Tapping the Carbon Developer Community
        1. Mac DevCenter
        2. MacTech Magazine
        3. The MacDev-1 Email List
        4. Carbon Development Email List
      3. Keeping Current
      4. Getting Sample Code
      5. Registering Creator Codes
      6. Partnering with Apple
    17. B. Carbon Event Classesand Kinds
    18. C. Parameter Names and Typesfor Common Event Kinds
      1. Apple Events
      2. Control Events
      3. Command Events
      4. Menu Events
      5. Mouse Events
      6. Text Input Events
      7. Window Events
    19. Index
    20. Colophon

Product information

  • Title: Learning Carbon
  • Author(s): Apple Computer Inc
  • Release date: May 2001
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9780596001612