`Volume I
`
`•
`
`Addison-Wesley Publishing Company, Inc.
`Reading, Massachusetts Menlo Park, California New York Don Mills, Ontario
`Wokingham, England Amsterdam Bonn Sydney Singapore Tokyo Madrid San Juan
`Paris Seoul Milan Mexico City Taipei
`
`GOOGLE EXHIBIT 1012
`
`Page 1 of 1284
`
`
`
`Copyright © 1985 by Apple Computer, Inc.
`
`All rights reserved. No part of this publication may be reproduced, stored in a
`retrieval system, or transmitted, in any form or by any means, mechanical,
`electronic, photocopying, recording, or otherwise, without prior written
`permission of Apple Computer, Inc. Printed in the United States of America.
`
`© Apple Computer, Inc., 1985
`20525 Mariani Avenue
`Cupertino, CA 95014
`(408) 996-1010
`
`Apple, the Apple logo, LaserWriter, Lisa, Macintosh, the Macintosh logo, and
`Mac Works are registered trademarks of Apple Computer, Inc.
`
`MacDraw, MacPaint, and MacWrite are registered trademarks of Claris
`Corporation.
`
`Simultaneously published in the United States and Canada.
`
`Written by Caroline Rose with Bradley Hacker, Robert Anders, Katie Withey,
`Mark Metzler, Steve Chernicoff, Chris Espinosa, Andy Averill, Brent Davis, and
`Brian Howard, assisted by Sandy Tompkins-Leffler and Louella Pizzuti. Special
`thanks to Cary Clark and Scott Knaster.
`
`This book was produced using the Apple Macintosh computer and the LaserWriter
`printer.
`
`ISBN 0-201-17731-5
`
`Page 2 of 1284
`
`
`
`Inside Macintosh
`Volume I
`
`Page 3 of 1284
`
`
`
`W A R R A N TY I N F O R M A T I ON
`ALL IMPLIED WARRANTIES ON THIS MANUAL, INCLUDING IMPLIED
`WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
`PARTICULAR PURPOSE, ARE LIMITED IN DURATION TO NINETY (90)
`DAYS FROM THE DATE OF THE ORIGINAL RETAIL PURCHASE OF
`THIS PRODUCT.
`
`Even though Apple has reviewed this manual, APPLE MAKES NO WARRANTY OR
`REPRESENTATION, EITHER EXPRESS OR IMPLIED, WITH RESPECT TO
`THIS MANUAL, ITS QUALITY, ACCURACY, MERCHANTABILITY, OR
`FITNESS FOR A PARTICULAR PURPOSE. AS A RESULT, THIS MANUAL
`IS SOLD "AS IS," AND YOU, THE PURCHASER, ARE ASSUMING THE
`ENTIRE RISK AS TO ITS QUALITY AND ACCURACY.
`
`IN NO EVENT WILL APPLE BE LIABLE FOR DIRECT, INDIRECT,
`SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES RESULTING
`FROM ANY DEFECT OR INACCURACY IN THIS MANUAL, even if advised of
`the possibility of such damages.
`
`THE WARRANTY AND REMEDIES SET FORTH ABOVE ARE EXCLUSIVE
`AND IN LIEU OF ALL OTHERS, ORAL OR WRITTEN, EXPRESS OR
`IMPLIED. No Apple dealer, agent, or employee is authorized to make any modification,
`extension, or addition to this warranty.
`
`Some states do not allow the exclusion or limitation of implied warranties or liability for
`incidental or consequential damages, so the above limitation or exclusion may not apply to you.
`This warranty gives you specific legal rights, and you may also have other rights which vary
`from state to state.
`
`Page 4 of 1284
`
`
`
`Contents
`1
`Preface
`About Inside Macintosh
`3
`4
`A Horse of a Different Color
`5
`The Structure of a Typical Chapter
`5
`Conventions
`
`1 A Road M ap
`7
`About This Chapter
`9
`Overview of the Software
`9
`A Simple Example Program
`13
`21 Where to Go From Here
`
`23
`27
`27
`29
`31
`32
`33
`36
`38
`44
`51
`54
`62
`64
`70
`
`71
`73
`73
`75
`78
`81
`
`83
`85
`85
`86
`
`2 T he Macintosh User Interface Guidelines
`About This Chapter
`Introduction
`Types of Applications
`Using Graphics
`Components of the Macintosh System
`The Keyboard
`The Mouse
`Selecting
`Windows
`Commands
`Standard Menus
`Text Editing
`Dialogs and Alerts
`Do's and Don'ts of a Friendly User Interface
`
`3 Macintosh Memory Management: An Introduction
`About This Chapter
`The Stack and the Heap
`Pointers and Handles
`General-Purpose Data Types
`Summary
`
`4 Using Assembly Language
`About This Chapter
`Definition Files
`Pascal Data Types
`
`Page 5 of 1284
`
`
`
`Inside Macintosh
`
`87
`88
`90
`95
`95
`99
`
`101
`103
`103
`105
`107
`110
`112
`113
`127
`128
`132
`
`135
`137
`137
`138
`142
`147
`153
`155
`158
`160
`162
`197
`201
`
`215
`217
`217
`219
`220
`220
`222
`222
`
`The Trap Dispatch Table
`The Trap Mechanism
`Calling Conventions
`Pascal Interface to the Toolbox and Operating System
`Mixing Pascal and Assembly Language
`Summary
`
`5 The Resource Manager
`About This Chapter
`About the Resource Manager
`Overview of Resource Files
`Resource Specification
`Resource References
`Using the Resource Manager
`Resource Manager Routines
`Resources Within Resources
`Format of a Resource File
`Summary of the Resource Manager
`
`6 QuickDraw
`About This Chapter
`About QuickDraw
`The Mathematical Foundation of QuickDraw
`Graphic Entities
`The Drawing Environment: GrafPort
`Coordinates in GrafPorts
`General Discussion of Drawing
`Pictures and Polygons
`Using QuickDraw
`QuickDraw Routines
`Customizing QuickDraw Operations
`Summary of QuickDraw
`
`7 The Font Manager
`About This Chapter
`About the Font Manager
`Font Numbers
`Characters in a Font
`Font Scaling
`Using the Font Manager
`Font Manager Routines
`
`Page 6 of 1284
`
`
`
`Communication Between QuickDraw and the Font Manager
`Format of a Font
`Fonts in a Resource File
`Summary of the Font Manager
`
`Contents
`
`8 The Toolbox Event Manager
`About This Chapter
`About the Toolbox Event Manager
`Event Types
`Priority of Events
`Keyboard Events
`Event Records
`Event Masks
`Using the Toolbox Event Manager
`Toolbox Event Manager Routines
`The Journaling Mechanism
`Summary of the Toolbox Event Manager
`
`224
`227
`234
`236
`
`241
`243
`243
`244
`245
`246
`249
`253
`255
`257
`261
`263
`
`9 The Window Manager
`267
`About This Chapter
`269
`About the Window Manager
`269
`271 Windows and GrafPorts
`271 Window Regions
`272 Windows and Resources
`274 Window Records
`278
`How a Window is Drawn
`279
`Making a Window Active: Activate Events
`280
`Using the Window Manager
`281 Window Manager Routines
`297
`Defining Your Own Windows
`302
`Formats of Resources for Windows
`303
`Summary of the Window Manager
`
`309
`311
`311
`314
`314
`315
`316
`318
`
`10 The Control Manager
`About This Chapter
`About the Control Manager
`Controls and Windows
`Controls and Resources
`Part Codes
`Control Records
`Using the Control Manager
`
`Page 7 of 1284
`
`
`
`Inside Macintosh
`
`319
`328
`332
`334
`
`339
`341
`341
`344
`344
`345
`346
`349
`351
`362
`363
`366
`
`371
`373
`373
`374
`381
`383
`392
`
`397
`399
`399
`401
`402
`403
`407
`409
`410
`411
`423
`425
`429
`
`Control Manager Routines
`Defining Your Own Controls
`Formats of Resources for Controls
`Summary of the Control Manager
`
`11 The Menu Manager
`About This Chapter
`About the Menu Manager
`Menus and Resources
`Menu Records
`Menu Lists
`Creating a Menu in Your Program
`Using the Menu Manager
`Menu Manager Routines
`Defining Your Own Menus
`Formats of Resources for Menus
`Summary of the Menu Manager
`
`12 TextEdit
`About This Chapter
`About TextEdit
`Edit Records
`Using TextEdit
`TextEdit Routines
`Summary of TextEdit
`
`13 The Dialog Manager
`About This Chapter
`About the Dialog Manager
`Dialog and Alert Windows
`Dialogs, Alerts, and Resources
`Item Lists in Memory
`Dialog Records
`Alerts
`Using the Dialog Manager
`Dialog Manager Routines
`Modifying Templates in Memory
`Formats of Resources for Dialogs and Alerts
`Summary of the Dialog Manager
`
`Page 8 of 1284
`
`
`
`Contents
`
`14 The Desk Manager
`435
`About This Chapter
`437
`About the Desk Manager
`437
`Using the Desk Manager
`439
`Desk Manager Routines
`440
`443 Writing Your Own Desk Accessories
`448
`Summary of the Desk Manager
`
`451
`453
`453
`454
`454
`456
`457
`461
`462
`463
`
`465
`467
`467
`476
`477
`
`481
`483
`483
`484
`485
`
`487
`489
`489
`491
`
`493
`495
`495
`501
`503
`
`15 The Scrap Manager
`About This Chapter
`About the Scrap Manager
`Memory and the Desk Scrap
`Desk Scrap Data Types
`Using the Scrap Manager
`Scrap Manager Routines
`Private Scraps
`Format of the Desk Scrap
`Summary of the Scrap Manager
`
`16 Toolbox Utilities
`About This Chapter
`Toolbox Utility Routines
`Formats of Miscellaneous Resources
`Summary of the Toolbox Utilities
`
`17 The Package Manager
`About This Chapter
`About Packages
`Package Manager Routines
`Summary of the Package Manager
`
`18 The Binary-Decimal Conversion Package
`About This Chapter
`Binary-Decimal Conversion Package Routines
`Summary of the Binary-Decimal Conversion Package
`
`19 The International Utilities Package
`About This Chapter
`International Resources
`International String Comparison
`Using the International Utilities Package
`
`Page 9 of 1284
`
`
`
`Inside Macintosh
`
`504
`508
`
`515
`517
`517
`518
`519
`527
`
`International Utilities Package Routines
`Summary of the International Utilities Package
`
`20 The Standard File Package
`About This Chapter
`About the Standard File Package
`Using the Standard File Package
`Standard File Package Routines
`Summary of the Standard File Package
`
`531
`
`Index
`
`Page 10 of 1284
`
`
`
`PREFACE
`
`3
`3
`4
`4
`4
`5
`5
`
`About Inside Macintosh
`The Language
`What's in Each Volume
`Version Numbers
`A Horse of a Different Color
`The Structure of a Typical Chapter
`Conventions
`
`Page 11 of 1284
`
`
`
`1-2
`I-2
`
`Page 12 of 1284
`
`Page 12 of 1284
`
`
`
`Preface
`
`A B O UT
`
`I N S I DE M A C I N T O SH
`
`Inside Macintosh is a three-volume set of manuals that tells you whatyou need to know to write
`software for the Apple® Macintosh™ 128K, 512K, or XL (or a Lisa® running MacWorks™
`XL). Although directed mainly toward programmers writing standard Macintosh applications,
`Inside Macintosh also contains the information needed to write simple utility programs, desk
`accessories, device drivers, or any other Macintosh software. It includes:
`• the user interface guidelines for applications on the Macintosh
`• a complete description of the routines available for your program to call (both those built
`into the Macintosh and others on disk), along with related concepts and background
`information
`• a description of the Macintosh 128K and 512K hardware
`It does not include information about:
`• Programming in general.
`• Getting started as a developer. For this, write to:
`Developer Relations
`Mail Stop 27-S
`Apple Computer, Inc.
`20525 Mariani Avenue
`Cupertino, CA 95014
`• Any specific development system, except where indicated. You'll need to have additional
`documentation for the development system you're using.
`• The Standard Apple Numeric Environment (SANE), which your program can access to
`perform extended-precision floating-point arithmetic and transcendental functions. This
`environment is described in the Apple Numerics Manual.
`You should already be familiar with the basic information that's in Macintosh, the owner's guide,
`and have some experience using a standard Macintosh application (such as MacWrite™).
`
`The Language
`
`The routines you'll need to call are written in assembly language, but (with a few exceptions)
`they're also accessible from high-level languages, such as Pascal on the Lisa Workshop
`development system. Inside Macintosh documents the Lisa Pascal interfaces to the routines and
`the symbolic names defined for assembly-language programmers using the Lisa Workshop; if
`you're using a different development system, its documentation should tell you how to apply the
`information presented here to that system.
`Inside Macintosh is intended to serve the needs of both high-level language and assembly-
`language programmers. Every routine is shown in its Pascal form (if it has one), but assembly-
`language programmers are told how they can access the routines. Information of interest only to
`assembly-language programmers is isolated and labeled so that other programmers can
`conveniendy skip it.
`
`About Inside Macintosh 1-3
`
`Page 13 of 1284
`
`
`
`Inside Macintosh
`
`Familiarity with Lisa Pascal (or a similar high-level language) is recommended for all readers,
`since it's used for most examples. Lisa Pascal is described in the documentation for the Lisa
`Pascal Workshop.
`
`What's in Each Volume
`
`Inside Macintosh consists of three volumes. Volume I begins with the following information of
`general interest:
`• a "road map" to the software and the rest of the documentation
`• the user interface guidelines
`• an introduction to memory management (the least you need to know, with a complete
`discussion following in Volume II)
`• some general information for assembly-language programmers
`It then describes the various parts of the User Interface Toolbox, the software in ROM that
`helps you implement the standard Macintosh user interface in your application. This is followed
`by descriptions of other, RAM-based software that's similar in function to the User Interface
`Toolbox. (The software overview in the Road Map chapter gives further details.)
`Volume II describes the Operating System, the software in ROM that does basic tasks such as
`input and output, memory management, and interrupt handling. As in Volume I, some
`functionally similar RAM-based software is then described.
`Volume III discusses your program's interface with the Finder and then describes the Macintosh
`128K and 512K hardware. A comprehensive summary of all the software is provided, followed
`by some useful appendices and a glossary of all terms defined in Inside Macintosh.
`
`Version Numbers
`
`This edition of Inside Macintosh describes the following versions of the software:
`• version 105 of the ROM in the Macintosh 128K or 512K
`• version 112 of the ROM image installed by MacWorks in the Macintosh XL
`• version 1.1 of the Lisa Pascal interfaces and the assembly-language definitions
`Some of the RAM-based software is read from the file named System (usually kept in the System
`Folder). This manual describes the software in the System file whose creation date is May 2,
`1984.
`
`A H O R SE OF A D I F F E R E NT C O L OR
`
`On an innovative system like the Macintosh, programs don't look quite the way they do on other
`systems. For example, instead of carrying out a sequence of steps in a predetermined order, your
`program is driven primarily by user actions (such as clicking and typing) whose order cannot be
`predicted.
`
`1-4 About Inside Macintosh
`
`Page 14 of 1284
`
`
`
`Preface
`
`You'll probably find that many of your preconceptions about how to write applications don't
`apply here. Because of this, and because of the sheer volume of information in Inside
`Macintosh, it's essential that you read the Road Map chapter. It will help you get oriented and
`figure out where to go next
`
`T HE S T R U C T U RE OF A T Y P I C AL C H A P T ER
`
`Most chapters of Inside Macintosh have the same structure, as described below. Reading through
`this now will save you a lot of time and effort later on. It contains important hints on how to find
`what you're looking for within this vast amount of technical documentation.
`Every chapter begins with a very brief description of its subject and a list of what you should
`already know before reading that chapter. Then there's a section called, for example, "About the
`Window Manager", which gives you more information about the subject, telling you what you
`can do with it in general, elaborating on related user interface guidelines, and introducing
`terminology that will be used in the chapter. This is followed by a series of sections describing
`important related concepts and background information; unless they're noted to be for advanced
`programmers only, you'll have to read them in order to understand how to use the routines
`described later.
`Before the routine descriptions themselves, there's a section called, for example, "Using the
`Window Manager". It introduces you to the routines, telling you how they fit into the general
`flow of an application program and, most important, giving you an idea of which ones you'll
`need to use. Often you'll need only a few routines out of many to do basic operations; by reading
`this section, you can save yourself the trouble of learning routines you'll never use.
`Then, for the details about the routines, read on to the next section. It gives the calling sequence
`for each routine and describes all the parameters, effects, side effects, and so on.
`Following the routine descriptions, there may be some sections that won't be of interest to all
`leaders. Usually these contain information about advanced techniques, or behind the scenes
`details for the curious.
`For review and quick reference, each chapter ends with a summary of the subject matter,
`including the entire Pascal interface and a separate section for assembly-language programmers.
`
`C O N V E N T I O NS
`
`The following notations are used in Inside Macintosh to draw your attention to particular items of
`information:
`
`Note: A note that may be interesting or useful
`
`Warning: A point you need to be cautious about
`
`Assembly-language note: A note of interest to assembly-language programmers only
`
`Conventions 1-5
`
`Page 15 of 1284
`
`
`
`Inside Macintosh
`
`[Not in ROM]
`Routines marked with this notation are not part of the Macintosh ROM. Depending on how
`the interfaces have been set up on the development system you're using, these routines may or
`may not be available. They're available to users of Lisa Pascal; other users should check the
`documentation for their development system for more information. (For related information of
`interest to assembly-language programmers, see chapter 4.)
`
`1-6 Conventions
`
`Page 16 of 1284
`
`
`
`1 A ROAD MAP
`
`9
`9
`9
`12
`13
`21
`
`About This Chapter
`Overview of the Software
`The Toolbox and Other High-Level Software
`The Operating System and Other Low-Level Software
`A Simple Example Program
`Where to Go From Here
`
`Page 17 of 1284
`
`
`
`Inside Macintosh
`Inside Macintosh
`
`1-8
`I-8
`
`Page 18 of 1284
`
`Page 18 of 1284
`
`
`
`A Road Map
`
`A B O UT T H IS C H A P T ER
`
`This chapter introduces you to the "inside" of Macintosh: the Operating System and User
`Interface Toolbox routines that your application program will call. It will help you figure out
`which software you need to learn more about and how to proceed with the rest of the Inside
`Macintosh documentation. To orient you to the software, it presents a simple example program.
`
`O V E R V I EW OF T HE S O F T W A RE
`
`The routines available for use in Macintosh programs are divided according to function, into what
`are in most cases called "managers" of the feature that they support. As shown in Figure 1, most
`are part of either the Operating System or the User Interface Toolbox and are in the Macintosh
`ROM.
`The Operating System is at the lowest level; it does basic tasks such as input and output,
`memory management, and interrupt handling. The User Interface Toolbox is a level above the
`Operating System; it helps you implement the standard Macintosh user interface in your
`application. The Toolbox calls the Operating System to do low-level operations, and you'll also
`call the Operating System directiy yourself.
`RAM-based software is available as well. In most cases this software performs specialized
`operations (such as floating-point arithmetic) that aren't integral to the user interface but may be
`useful to some applications.
`
`The Toolbox and Other High-Level Software
`
`The Macintosh User Interface Toolbox provides a simple means of constructing application
`programs that conform to the standard Macintosh user interface. By offering a common set of
`routines that every application calls to implement the user interface, the Toolbox not only ensures
`familiarity and consistency for the user but also helps reduce the application's code size and
`development time. At the same time, it allows a great deal of flexibility: An application can use
`its own code instead of a Toolbox call wherever appropriate, and can define its own types of
`windows, menus, controls, and desk accessories.
`Figure 2 shows the various parts of the Toolbox in rough order of their relative level. There are
`many interconnections between these parts; the higher ones often call those at the lower levels. A
`brief description of each part is given below, to help you figure out which ones you'll need to
`learn more about. Details are given in the Inside Macintosh chapter on that part of the Toolbox.
`The basic Macintosh terms used below are explained in Macintosh, the owner's guide.
`To keep the data of an application separate from its code, making the data easier to modify and
`easier to share among applications, the Toolbox includes the Resource Manager. The
`Resource Manager lets you, for example, store menus separately from your code so that they Can
`be edited or translated without requiring recompilation of the code. It also allows you to get
`standard data, such as the I-beam pointer for inserting text, from a shared system file. When you
`call other parts of the Toolbox that need access to the data, they call the Resource Manager.
`Although most applications never need to call the Resource Manager directiy, an understanding of
`the concepts behind it is essential because they're basic to so many other operations.
`
`Overview of the Software 1-9
`
`Page 19 of 1284
`
`
`
`Inside Macintosh
`
`A M A C I N T O SH A P P L I C A T I ON P R O G R AM
`
`THE USER INTERFACE TOOLBOX
`(in ROM)
`
`Resource Manager
`QuickDraw
`Font Manager
`Toolbox Event Manager
`Window Manager
`Control Manager
`Menu Manager
`TextEdit
`Dialog Manager
`De3k Manager
`Scrap Manager
`Toolbox Utilities
`Package Manager
`
`THE OPERATING SYSTEM
`THE OPERATING SYSTEM
`THE OPERATING SYSTEM
`(in ROM)
`(in ROM)
`(in ROM)
`
`Memory Manager
`Memory Manager
`Memory Manager
`Segment Loader
`Segment Loader
`Segment Loader
`Operating System Event Manager
`Operating System Event Manager
`Operating System Event Manager
`File Manager
`File Manager
`File Manager
`Device Manager
`Device Manager
`Device Manager
`Disk Driver
`Disk Driver
`Disk Driver
`Sound Driver
`Sound Driver
`Sound Driver
`ROM Serial Driver
`ROM Serial Driver
`ROM Serial Driver
`Vertical Retrace Manager
`Vertical Retrace Manager
`Vertical Retrace Manager
`System Error Handler
`System Error Handler
`System Error Handler
`Operating System Utilities
`Operating System Utilities
`Operating System Utilities
`
`OTHER HIGH-LEVEL SOFTWARE
`(in RAM)
`
`Binary-Decimal Conversion Package
`International UtilitiesPackage
`Standard File Package
`
`OTHER L O W - L E V EL SOFTWARE
`(in RAM)
`
`RAM Serial Driver
`Printing Manager
`Printer Driver
`AppleTalk Manager
`Di3k Initialization Package
`Floating-Point Arithmetic Package
`Transcendental Functions Package
`
`T HE M A C I N T O SH H A R D W A RE
`
`Figure 1. Overview
`
`I-10 Overview of the Software
`
`Page 20 of 1284
`
`
`
`A Road Map
`
`TextEdit
`
`Control Manager
`
`Dialog Manager
`
`Menu Manager
`
`Window Manager
`
`Toolbox Utilities
`
`Toolbox Event Manager
`
`De3k Manager
`
`Scrap Manager
`
`QuickDraw
`
`Package Manager
`
`Font Manager
`
`Resource Manager
`
`Figure 2. Parts of the Toolbox
`
`Graphics are an important part of every Macintosh application. All graphic operations on the
`Macintosh are performed by QuickDraw. To draw something on the screen, you'll often call
`one of the other parts of the Toolbox, but it will in turn call QuickDraw. You'll also call
`QuickDraw directly, usually to draw inside a window, or just to set up constructs like rectangles
`that you'll need when making other Toolbox calls. QuickDraw's underlying concepts, like those
`of the Resource Manager, are important for you to understand.
`Graphics include text as well as pictures. To draw text, QuickDraw calls the Font Manager,
`which does the background work necessary to make a variety of character fonts available in
`various sizes and styles. Unless your application includes a font menu, you need to know only a
`minimal amount about the Font Manager.
`An application decides what to do from moment to moment by examining input from the user in
`the form of mouse and keyboard actions. It learns of such actions by repeatedly calling the
`Toolbox Event Manager (which in turn calls another, lower-level Event Manager in the
`Operating System). The Toolbox Event Manager also reports occurrences within the application
`that may require a response, such as when a window that was overlapped becomes exposed and
`needs to be redrawn.
`All information presented by a standard Macintosh application appears in windows. To create
`windows, activate them, move them, resize them, or close them, you'll call the Window
`Manager. It keeps track of overlapping windows, so you can manipulate windows without
`concern for how they overlap. For example, the Window Manager tells the Toolbox Event
`Manager when to inform your application that a window has to be redrawn. Also, when the user
`presses the mouse button, you call the Window Manager to learn which part of which window it
`was pressed in, or whether it was pressed in the menu bar or a desk accessory.
`Any window may contain controls, such as buttons, check boxes, and scroll bars. You can
`create and manipulate controls with the Control Manager. When you learn from the Window
`Manager that the user pressed the mouse button inside a window containing controls, you call the
`Control Manager to find out which control it was pressed in, if any.
`
`Overview of the Software
`
`I-11
`
`Page 21 of 1284
`
`
`
`Inside Macintosh
`
`A common place for the user to press the mouse button is, of course, in the menu bar. You set
`up menus in the menu bar by calling the Menu Manager. When the user gives a command,
`either from a menu with the mouse or from the keyboard with the Command key, you call the
`Menu Manager to find out which command was given.
`To accept text typed by the user and allow the standard editing capabilities, including cutting and
`pasting text within a document via the Clipboard, your application can call TextEdit. TextEdit
`also handles basic formatting such as word wraparound and justification. You can use it just to
`display text if you like.
`When an application needs more information from the user about a command, it presents a dialog
`box. In case of errors or potentially dangerous situations, it alerts the user with a box containing
`a message or with sound from the Macintosh's speaker (or both). To create and present dialogs
`and alerts, and find out the user's responses to them, you call the Dialog Manager.
`Every Macintosh application should support the use of desk accessories. The user opens desk
`accessories through the Apple menu, which you set up by calling the Menu Manager. When you
`learn that the user has pressed the mouse button in a desk accessory, you pass that information on
`to the accessory by calling the Desk Manager. The Desk Manager also includes routines that
`you must call to ensure that desk accessories work properly.
`As mentioned above, you can use TextEdit to implement the standard text editing capability of
`cutting and pasting via the Clipboard in your application. To allow the use of the Clipboard for
`cutting and pasting text or graphics between your application and another application or a desk
`accessory, you need to call the Scrap Manager.
`Some generally useful operations such as fixed-point arithmetic, string manipulation, and logical
`operations on bits may be performed with the Toolbox Utilities.
`The final part of the Toolbox, the Package Manager, lets you use RAM-based software called
`packages. The Standard File Package will be called by every application whose File menu
`includes the standard commands for saving and opening documents; it presents the standard user
`interface for specifying the document. Two of the Macintosh packages can be seen as extensions
`to the Toolbox Utilities: The Binary-Decimal Conversion Package converts integers to
`decimal strings and vice versa, and the International Utilities Package gives you access to
`country-dependent information such as the formats for numbers, currency, dates, and times.
`
`The Operating System and Other Low-Level Software
`
`The Macintosh Operating System provides the low-level support that applications need in order to
`use the Macintosh hardware. As the Toolbox is your program's interface to the user, the
`Operating System is its interface to the Macintosh.
`The Memory Manager dynamically allocates and releases memory for use by applications and
`by the other parts of the Operating System. Most of the memory that your program uses is in an
`area called the heap; the code of the program itself occupies space in the heap. Memory space in
`the heap must be obtained through the Memory Manager.
`The Segment Loader is the part of the Operating System that loads application code into
`memory to be executed. Your application can be loaded all at once, or you can divide it up into
`dynamically loaded segments to economize on memory usage. The Segment Loader also serves
`as a bridge between the Finder and your application, letting you know whether the application has
`to open or print a document on the desktop when it starts up.
`
`1-12 Overview of the Software
`
`Page 22 of 1284
`
`
`
`A Road Map
`
`Low-level, hardware-related events such as mouse-button presses and keystrokes are reported by
`the Operating System Event Manager. (The Toolbox Event Manager then passes them to the
`application, along with higher-level, software-generated events added at the Toolbox level.) Your
`program will ordinarily deal only with the Toolbox Event Manager and will rarely call the
`Operating System Event Manager directly.
`File I/O is supported by the File Manager, and device I/O by the Device Manager. The task
`of making the various types of devices present the same interface to the application is performed
`by specialized device drivers. The Operating System includes three built-in drivers:
`• The Disk Driver controls data storage and retrieval on 3 1/2-inch disks.
`• The Sound Driver controls sound generation, including music composed of up to four
`simultaneous tones.
`• The Serial Driver reads and writes asynchronous data through the two serial ports,
`providing communication between applications and serial peripheral devices such as a
`modem or printer.
`The above drivers are all in ROM; other drivers are RAM-based. There's a Serial Driver in RAM
`as well as the one in ROM, and there's a Printer Driver in RAM that enables applications to
`print information on any variety of printer via the same interface (called the Printing Manager).
`The AppleTalk Manager is an interface to a pair of RAM drivers that enable programs to send
`and receive information via an AppleTalk network. More RAM drivers can be added
`independently or built on the existing drivers (by calling the routines in those drivers). For
`example, the Printer Driver was built on the Serial Driver, and a music driver could be built on the
`Sound Driver.
`The Macintosh video circuitry generates a vertical retrace interrupt 60 times a second. An
`application can schedule routines to be executed at regular intervals based on this "heartbeat" of
`the system. The Vertical Retrace Manager handles the scheduling and execution of tasks
`during the vertical retrace interrupt.
`If a fatal system error occurs while your application is running, the System Error Handler
`assumes control. The System Error Handler displays a box containing an error message and
`provides a mechanism for the user to start up the system again or resume execution of the
`application.
`The Operating System Utilities perform miscellaneous operations such as getting the date and
`time, finding out the user's preferred speaker volume and other preferences, and doing simple
`string comparison. (More sophisticated string comparison routines are available in the
`International Utilities Package.)
`Finally, there are three Macintosh packages that perform low-level operations: the Disk
`Initialization Package, which the Standard File Package calls to initialize and name disks; the
`Floating-Point Arithmetic Package, which supports extended-precision arithmetic according
`to IEEE Standard 754; and the Transcendental Functions Package, which contains
`trigonometric, logarithmic, exponential, and financial functions, as well as a random number
`generator.
`
`A S I M P LE E X A M P LE P R O G R AM
`
`To illustrate various commonly used parts of the software, this section presents an extremely
`simple example of a Macintosh application program. Though too simple to be practical, this
`
`A Simple Example Program 1-13
`
`Page 23 of 1284
`
`
`
`Inside Macintosh
`
`example shows the overall structure that every application program will have, and it does many of
`the basic things every application will do. By looking it over, you can become more familiar with
`the software and see how your own program code will be structured.
`The example program's source code is shown in Figure 4, which begins at the end of this
`section. A lot of comments are included so that you can see which part of the Toolb