IM: Macintosh Toolbox Essentials - Apple Developer

3y ago
12 Views
2 Downloads
6.16 MB
909 Pages
Last View : 1m ago
Last Download : 3m ago
Upload by : Luis Wallis
Transcription

INSIDE MACINTOSHMacintosh Toolbox Essentials

Apple Computer, Inc. 1992 Apple Computer, Inc.All rights reserved.No part of this publication may bereproduced, stored in a retrieval system,or transmitted, in any form or by anymeans, mechanical, electronic,photocopying, recording, or otherwise,without prior written permission ofApple Computer, Inc. Printed in theUnited States of America.No licenses, express or implied, aregranted with respect to any of thetechnology described in this book.Apple retains all intellectual propertyrights associated with the technologydescribed in this book. This book isintended to assist applicationdevelopers to develop applications onlyfor Apple Macintosh computers.Apple Computer, Inc.1 Infinite LoopCupertino, CA 95014408-996-1010Apple, the Apple logo, APDA,AppleShare, AppleTalk, A/UX,EtherTalk, LaserWriter, Macintosh,MPW, and MultiFinder and aretrademarks of Apple Computer, Inc.,registered in the United States and othercountries.Apple Desktop Bus, Balloon Help,BalloonWriter, Chicago, Finder, Geneva,KanjiTalk, Monaco, New York,QuickDraw, QuickTime, ResEdit,System 7, and TrueType are trademarksof Apple Computer, Inc.Adobe Illustrator and PostScript aretrademarks of Adobe SystemsIncorporated, which may be registeredin certain jurisdictions.AGFA is a trademark of Agfa-Gevaert.FrameMaker is a registered trademarkof Frame Technology Corporation.Helvetica, Palatino, and Times areregistered trademarks of LinotypeCompany.ITC Zapf Dingbats is a registeredtrademark of International TypefaceCorporation.Simultaneously published in the UnitedStates and Canada.LIMITED WARRANTY ON MEDIA ANDREPLACEMENTALL IMPLIED WARRANTIES ON THISMANUAL, INCLUDING IMPLIEDWARRANTIES OF MERCHANTABILITYAND FITNESS FOR A PARTICULARPURPOSE, ARE LIMITED IN DURATIONTO NINETY (90) DAYS FROM THE DATEOF THE ORIGINAL RETAIL PURCHASEOF THIS PRODUCT.Even though Apple has reviewed thismanual, APPLE MAKES NO WARRANTYOR REPRESENTATION, EITHER EXPRESSOR IMPLIED, WITH RESPECT TO THISMANUAL, ITS QUALITY, ACCURACY,MERCHANTABILITY, OR FITNESS FOR APARTICULAR PURPOSE. AS A RESULT,THIS MANUAL IS SOLD “AS IS,” ANDYOU, THE PURCHASER, ARE ASSUMINGTHE ENTIRE RISK AS TO ITS QUALITYAND ACCURACY.IN NO EVENT WILL APPLE BE LIABLEFOR DIRECT, INDIRECT, SPECIAL,INCIDENTAL, OR CONSEQUENTIALDAMAGES RESULTING FROM ANYDEFECT OR INACCURACY IN THISMANUAL, even if advised of the possibilityof such damages.THE WARRANTY AND REMEDIES SETFORTH ABOVE ARE EXCLUSIVE AND INLIEU OF ALL OTHERS, ORAL ORWRITTEN, EXPRESS OR IMPLIED. NoApple dealer, agent, or employee isauthorized to make any modification,extension, or addition to this warranty.Some states do not allow the exclusion orlimitation of implied warranties or liabilityfor incidental or consequential damages, sothe above limitation or exclusion may notapply to you. This warranty gives youspecific legal rights, and you may also haveother rights which vary from state to state.

ContentsFigures, Tables, and ListingsPrefaceAbout This BookxvxxvFormat of a Typical ChapterxxviConventions Used in This BookxxviSpecial FontsxxviiTypes of NotesxxviiEmpty StringsxxviiAssembly-Language InformationxxviiThe Development EnvironmentxxviiiChapter 1Introduction to the Macintosh Toolbox1-1Overview of the Macintosh ert Boxes and Dialog Boxes1-8Icons and Other Interactions With the Finder1-10Resources1-11Help Balloons1-14Copy and Paste1-14Related System Software Features1-14Drawing on the Screen1-14Handling Text1-14Managing Files1-15Allocating Memory and Launching Processes1-15Creating Publishers and Subscribers1-15Communicating With Other Applications1-16Designing Your Application1-16Chapter 2Event Manager2-1Introduction to Events2-4Low-Level Events2-8Operating-System Events2-10High-Level Events2-13Priority of Events2-15Switching Contexts2-15iii

About the Event Manager2-16Using the Event Manager2-17Obtaining Information About Events2-18Processing Events2-21Using the WaitNextEvent Function2-22Writing an Event Loop2-24Setting the Event Mask2-26Handling Events in a Dialog Box2-29Creating a Size Resource2-30Handling Low-Level Events2-32Responding to Mouse Events2-33Responding to Keyboard Events2-38Scanning for a Cancel Event2-46Responding to Update Events2-47Responding to Activate Events2-50Responding to Disk-Inserted Events2-55Responding to Null Events2-57Handling Operating-System Events2-58Responding to Suspend and Resume Events2-60Responding to Mouse-Moved Events2-62Handling High-Level Events2-67Responding to Events From Other Applications2-69Searching for a Specific High-Level Event2-71Determining the Sender of a High-Level Event2-72Sending High-Level Events2-73Requesting Return Receipts2-77Handling Apple Events2-78Event Manager Reference2-78Data Structures2-78The Event Record2-79The Target ID Record2-81The High-Level Event Message Record2-82The Event Queue2-83Event Manager Routines2-84Receiving Events2-84Sending Events2-100Converting Process Serial Numbers and Port Names2-105Reading the Mouse2-108Reading the Keyboard2-110Getting Timing Information2-112Application-Defined Routine2-114Filter Function for Searching the High-Level Event Queue2-114Resource2-115The Size Resource2-115Summary of the Event Manager2-120Pascal Summary2-120Constants2-120iv

Data Types2-122Event Manager Routines2-123Application-Defined Routine2-124C Summary2-125Constants2-125Data Types2-127Event Manager Routines2-128Application-Defined Routine2-129Assembly-Language Summary2-130Data Structures2-130Trap Macros2-130Global Variables2-131Result Codes2-132Chapter 3Menu Manager3-1Introduction to Menus3-5Menu and Menu Bar Definition Routines3-9The Menu Bar3-9Menus3-10Menu Items3-11Groups of Menu Items3-14Keyboard Equivalents for Menu Commands3-16Menus Added Automatically by the Menu Manager3-19The Apple Menu3-20The File Menu3-22The Edit Menu3-24The Font Menu3-26The Size Menu3-27The Help Menu3-29The Keyboard Menu3-32The Application Menu3-33Pop-Up Menus3-33Hierarchical Menus3-38About the Menu Manager3-39How the Menu Manager Maintains Information About Menus3-40How the Menu Manager Maintains Information About an Application’sMenu Bar3-40Using the Menu Manager3-41Creating a Menu3-42Creating a Menu Resource3-43Creating a Menu Bar Resource3-49Setting Up Your Application’s Menu Bar3-50Creating a Hierarchical Menu3-53Creating a Pop-Up Menu3-56v

Changing the Appearance of Items in a Menu3-57Enabling and Disabling Menu Items3-58Changing the Text of an Item3-59Changing the Font Style of Menu Items3-60Changing the Mark of Menu Items3-61Changing the Icon or Script Code of Menu Items3-62Adding Items to a Menu3-64Adding Items to the Help Menu3-67Adding Items to the Apple Menu3-68Adding Fonts to a Menu3-69Handling User Choice of a Menu Command3-70Handling Mouse-Down Events in the Menu Bar3-72Adjusting the Menus of an Application3-73Determining if the User Chose a Keyboard Equivalent3-77Responding When the User Chooses a Menu Item3-78Handling the Apple Menu3-80Handling the Help Menu3-81Handling a Size Menu3-82Accessing Menus From a Dialog Box3-84Writing Your Own Menu Definition Procedure3-87Calculating the Dimensions of a Menu3-89Drawing Menu Items in a Menu3-90Determining Whether the Cursor Is in an Enabled Menu Item3-92Menu Manager Reference3-95Data Structures3-95The Menu Record3-95The Menu List3-97The Menu Color Information Table Record3-98Menu Manager Routines3-102Initializing the Menu Manager3-103Creating Menus3-105Adding Menus to and Removing Menus From the CurrentMenu List3-108Getting a Menu Bar Description From an 'MBAR' Resource3-110Getting and Setting the Menu Bar3-112Drawing the Menu Bar3-113Responding to the User’s Choice of a Menu Command3-114Getting a Handle to a Menu Record3-122Adding and Deleting Menu Items3-124Getting and Setting the Appearance of Menu Items3-130Disposing of Menus3-140Counting the Items in a Menu3-140Highlighting the Menu Bar3-141Recalculating Menu Dimensions3-142Managing Entries in the Menu Color Information Table3-143Application-Defined Routine3-148The Menu Definition Procedure3-148vi

Resources3-151The Menu Resource3-151The Menu Bar Resource3-155The Menu Color Information Table Resource3-155The Menu Definition Procedure Resource3-157Summary of the Menu Manager3-158Pascal Summary3-158Constants3-158Data Types3-158Menu Manager Routines3-159Application-Defined Routine3-162C Summary3-162Constants3-162Data Types3-163Menu Manager Routines3-164Application-Defined Routine3-166Assembly-Language Summary3-167Data Structures3-167Global Variables3-167Result Codes3-167Chapter 4Window Manager4-1Introduction to Windows4-4Active and Inactive Windows4-6Types of Windows4-8Window Regions4-12Dialog Boxes and Alert Boxes4-13Controls4-14Windows on the Desktop4-15About the Window Manager4-16Graphics Ports4-17Window Records4-19Color Windows4-20Events in Windows4-21Using the Window Manager4-22Managing Multiple Windows4-23Creating a Window4-25Defining a Window Resource4-25Creating a Window From a Resource4-27Positioning a Document Window on the DesktopDrawing the Window Contents4-39Updating the Content Region4-40Maintaining the Update Region4-41Handling Events in Windows4-41Handling Mouse Events in Windows4-424-30vii

Handling Keyboard Events in Windows4-47Handling Update Events4-48Handling Activate Events4-50Moving a Window4-53Zooming a Window4-53Resizing a Window4-57Closing a Window4-60Hiding and Showing a Window4-62Window Manager Reference4-64Window Manager Reference4-65Data Structures4-65The Color Window Record4-65The Window Record4-69The Window State Data Record4-70The Window Color Table Record4-71The Auxiliary Window Record4-73The Window List4-74Window Manager Routines4-74Initializing the Window Manager4-74Creating Windows4-75Naming Windows4-85Displaying Windows4-86Retrieving Window Information4-91Moving Windows4-94Resizing Windows4-99Zooming Windows4-101Closing and Deallocating Windows4-103Maintaining the Update Region4-106Setting and Retrieving Other Window CharacteristicsManipulating the Desktop4-112Manipulating Window Color Information4-114Low-Level Routines4-116Application-Defined Routine4-120The Window Definition Function4-120Resources4-124The Window Resource4-124The Window Definition Function Resource4-127The Window Color Table Resource4-127Summary of the Window Manager4-130Pascal Summary4-130Constants4-130Data Types4-132Window Manager Routines4-134Application-Defined Routine4-136C Summary4-137Constants4-137Data Types4-139viii4-109

Window Manager RoutinesApplication-Defined RoutineAssembly-Language SummaryData Types4-144Global Variables4-145Chapter 5Control Manager4-1404-1434-1445-1Introduction to Controls5-4Buttons5-5Checkboxes5-5Radio Buttons5-6Pop-Up Menus5-6Scroll Bars5-7Other Controls5-11Active and Inactive Controls5-11The Control Definition Function5-14About the Control Manager5-14Using the Control Manager5-15Creating and Displaying a Control5-15Creating a Button, Checkbox, or Radio Button5-17Creating Scroll Bars5-21Creating a Pop-Up Menu5-25Updating a Control5-29Responding to Mouse Events in a Control5-30Determining a Mouse-Down Event in a Control5-31Tracking the Cursor in a Control5-35Determining and Changing Control Settings5-37Scrolling Through a Document5-43Scrolling in Response to Events in the Scroll Box5-53Scrolling in Response to Events in Scroll Arrows and Gray AreasDrawing a Scrolled Document Inside a Window5-62Moving and Resizing Scroll Bars5-65Defining Your Own Control Definition Function5-71Control Manager Reference5-72Data Structures5-72Control Manager Reference5-73The Control Record5-73The Auxiliary Control Record5-76The Pop-Up Menu Private Data Record5-77The Control Color Table Record5-77Control Manager Routines5-80Creating Controls5-81Drawing Controls5-85Handling Mouse Events in Controls5-88Changing Control Settings and Display5-93Determining Control Values5-102Removing Controls5-1085-57ix

Application-Defined Routines5-109Defining Your Own Control Definition FunctionDefining Your Own Action Procedures5-115Resources5-117The Control Resource5-118The Control Color Table Resource5-121The Control Definition Function5-123Summary of the Control Manager5-124Pascal Summary5-124Constants5-124Data Types5-126Control Manager Routines5-127Application-Defined Routines5-129C Summary5-129Constants5-129Data Types5-131Control Manager Routines5-132Application-Defined Routines5-134Assembly-Language Summary5-134Data Structures5-134Global Variables5-135Chapter 6Dialog Manager6-1Introduction to Alerts and Dialog Boxes6-6Types of Alerts6-8Types of Dialog Boxes6-9Modal Dialog Boxes6-10Movable Modal Dialog Boxes6-11Modeless Dialog Boxes6-12Items in Alert and Dialog Boxes6-13Events in Alert and Dialog Boxes6-14Alert Boxes, Dialog Boxes, and the Window ManagerAbout the Dialog Manager6-16Using the Dialog Manager6-17Creating Alert Sounds and Alert Boxes6-18Creating Dialog Boxes6-23Providing Items for Alert and Dialog Boxes6-26Item Types6-30Display Rectangles6-32Enabled and Disabled Items6-36Resource IDs for Items6-36Titles for Buttons, Checkboxes, and Radio ButtonsText Strings for Static Text and Editable Text ItemsPop-Up Menus as Items6-42Keyboard Navigation Among Items6-44x5-1096-156-376-40

Manipulating Items6-44Changing Static Text6-46Getting Text From Editable Text Items6-48Adding Items to an Existing Dialog Box6-51Using an Application-Defined Item to Draw the Bold Outlinefor a Default Button6-56Using the Dialog Manager6-61Using the Dialog Manager6-61Displaying Alert and Dialog Boxes6-61Positioning Alert and Dialog Boxes6-62Deactivating Windows Behind Alert and Modal Dialog Boxes6-64Displaying Modeless Dialog Boxes6-66Adjusting Menus for Modal Dialog Boxes6-68Adjusting Menus for Movable Modal and Modeless Dialog Boxes6-73Displaying Multiple Alert and Dialog Boxes6-74Displaying Alert and Dialog Boxes From the Background6-74Including Color in Your Alert and Dialog Boxes6-75Handling Events in Alert and Dialog Boxes6-77Responding to Events in Controls6-78Responding to Events in Editable Text Items6-79Responding to Events in Alert Boxes6-81Responding to Events in Modal Dialog Boxes6-82Writing an Event Filter Function for Alert and ModalDialog Boxes6-86Responding to Mouse Events in Modeless andMovable Modal Dialog Boxes6-89Responding to Keyboard Events in Modeless andMovable Modal Dialog Boxes6-94Responding to Activate and Update Events in Modeless and MovableModal Dialog Boxes6-97Closing Dialog Boxes6-100Dialog Manager Reference6-101Data Structure6-101The Dialog Record6-101Dialog Manager Routines6-102Initializing the Dialog Manager6-103Creating Alerts6-105Creating and Disposing of Dialog Boxes6-113Manipulating Items in Alert and Dialog Boxes6-120Handling Text in Alert and Dialog Boxes6-129Handling Events in Dialog Boxes6-135Application-Defined Routines6-143Resources6-147The Dialog Resource6-148The Alert Resource6-150The Item List Resource6-151The Dialog Color Table Resource6-156The Alert Color Table Resource6-157The Item Color Table Resource6-158xi

Summary of the Dialog Manager6-165Pascal Summary6-165Constants6-165Data Types6-166Dialog Manager Routines6-166Application-Defined Routines6-168C Summary6-168Constants6-168Data Types6-169Dialog Manager Routines6-170Application-Defined Routines6-172Assembly-Language Summary6-172Data Structures6-172Global Variables6-172Chapter 7Finder Interface7-1Introduction to the Finder Interface7-3About the Finder Interface7-6Using the Finder Interface7-6Giving a Signature to Your Application and a Creator and aFile Type to Your Documents7-8Creating Icons for the Finder7-11Creating Customized Document Icons7-17Creating File Reference Resources7-18Creating a Bundle Resource7-20How and When the Finder Launches Your Application7-25Displaying Messages When the Finder Can’t FindYour Application7-27Providing Version Resources7-31Using Finder Information in the Catalog File7-32Supporting Stationery Pads7-34Distributing Fonts, Sounds, and Other Movable Resources7-36Providing Balloon Help for Nondocument Icons7-38Using Aliases7-39Using the System Folder and Its Related Directories7-41The Desktop Database7-45Finder Interface Reference7-46Data Structures7-46File Information Record7-47Extended File Information Record7-49Directory Information Record7-50Extended Directory Information Record7-50Routines7-51Resolving Alias Files7-51Finding Directories7-53xii

Resources7-56The Signature Resource7-57The Icon List Resource7-57The Small Icon List Resource7-58The Large 4-Bit Color Icon Resource7-59The Small 4-Bit Color Icon Resource7-60The Large 8-Bit Color Icon Resource7-61The Small 8-Bit Color Icon Resource7-62The Icon Resource7-63The Color Icon Resource7-64The File Reference Resource7-64The Bundle Resource7-65The Missing-Application Name String7-68The Application-Missing Message String7-68The Version Resource7-69Summary of the Finder Interface7-71Pascal Summary7-71Constants7-71Data Types7-73Routines7-74C Summary7-74Constants7-74Data Types7-76Routines7-77Assembly-Language Summary7-77Data Structures7-77Result Codes7-78GlossaryIndexGL-1IN-1xiii

Figures, Tables, and ListingsChapter 1Introduction to the Macintosh ToolboxFigure 1-1Figure 1-2Figure 1-3Figure 1-4Figure 1-5Chapter 2Event ManagerFigure 2-1Figure 2-2Figure 2-3Figure 2-4Figure 2-5Figure 2-6Figure 2-71-1The SurfWriter application with multiple windows onthe desktop1-3A typical window1-6Common controls1-7An alert box1-8Modal, movable modal, and modeless dialog boxes1-92-1Figure 2-17Sources of events sent to your application2-6Low-level events2-10Operating-system events2-11High-level events2-14The modifiers field of the event record2-20The event mask2-27The message field of the event record for keyboardevents2-40Keyboard translation2-41Virtual key codes for the Apple Keyboard II, ISO layout2-42Virtual key codes for the Apple Extended Keyboard II2-43Responding to an update event for a window2-49Responding to activate events for a window2-52The standard arrow cursor2-63The I-beam, crosshairs, plus sign, and wristwatch cursors2-63The arrow region and the I-beam region2-64Changing the cursor from the I-beam cursor to the arrowcursor2-65Structure of the KeyTranslate function result2-111Listing 2-1Listing 2-2Listing 2-3Listing 2-4Listing 2-5Listing 2-6Listing 2-7Listing 2-8Using the WaitNextEvent function2-23An event loop2-24Processing events2-26The Rez input for a sample 'SIZE' resourceHandling mouse-down events2-34Handling key-down and auto-key events2-44Handling key-down events2-44Scanning for a Command-period event2-46Figure 2-8Figure 2-9Figure 2-10Figure 2-11Figure 2-12Figure 2-13Figure 2-14Figure 2-15Figure 2-162-31xv

Listing 2-9Listing 2-10Listing 2-11Listing 2-12Listing 2-13Listing 2-14Listing 2-15Listing 2-16Listing 2-17Listing 2-18Listing 2-19Chapter 3Menu ManagerFigure 3-1Figure 3-2Figure 3-3Figure 3-4Figure 3-5Figure 3-6Figure 3-7Figure 3-8Figure 3-9Figure 3-10Figure 3-11Figure 3-12Figure 3-13Figure 3-14Figure 3-15Figure 3-16Figure 3-17Figure 3-18Figure 3-19Figure 3-20Figure 3-21Figure 3-22Figure 3-23Figure 3-24Figure 3-25Figure 3-26Figure 3-27Figure 3-28Figure 3-29Figure 3-30Figure 3-31Figure 3-32xviResponding to update events2-50Responding to activate events2-53Responding to disk-inserted events2-56Handling null events2-57Responding to operating-system events2-59Responding to suspend and resume events2-61Changing the cursor2-65Accepting a high-level event2-70Posting a high-level event by application signature2-74Using the PPCBrowser function to post a high-level eventA Rez template for a 'SIZE' resource2-1162-763-1A pull-down menu, a submenu, and a pop-up menu3-6The SurfWriter application’s menu bar with the Editmenu displayed3-7The menu bar of the SurfWriter application3-10The SurfWriter application’s menu bar localized for anotherscript system3-10Two menus with various characteristics3-13Menu items in a mutually exclusive group3-14Menu items in an accumulating group3-15Use of a checkmark and dash in an accumulating group3-15The Apple menu for the SurfWriter application3-21Choosing the

Overview of the Macintosh Toolbox 1-4 Events 1-5 Menus 1-6 Windows 1-6 Controls 1-7 Alert Boxes and Dialog Boxes 1-8 Icons and Other Interactions With the Finder 1-10 Resources 1-11 Help Balloons 1-14 Copy and Paste 1-14 Related System Software Features 1-14 Drawing on the Screen 1-14 Handling Text 1-14 Managing Files 1-15

Related Documents:

Macintosh Developer Note Number 3 covers the Macintosh Color Classic , the Macintosh LC III, the Macintosh PowerBook 165c, the Macintosh Centris 610 and 650, and the Macintosh Quadra 800. APDA is Apple’s worldwide source for over three hundred development tools, technical resources, training products, and information for anyone

Model-Based Calibration Toolbox 13, 21, 23, 24, 27 500 600 Control System Design and Analysis Control System Toolbox 200 200 System Identification Toolbox 200 200 Fuzzy Logic Toolbox 200 200 Robust Control Toolbox 4 200 200 Model Predictive Control Toolbox 4 200 23200 Aerospace Toolbox 200 200 Signal Processing and Communications

for Apple Macintosh computers. Every effort has been made to ensure that the information in this manual is accurate. Apple is not responsible for printing or clerical errors. Apple Computer, Inc. 20525 Mariani Avenue Cupertino, CA 95014 408-996-1010 Apple, the Apple logo, APDA, HyperCard, LaserWriter, Macint

(collectively the "Apple Software") are licensed, not sold, to you by Apple Inc. ("Apple") for use only under the terms of this License, and Apple reserves all rights not expressly granted to you. You own the media on which the Apple Software is recorded but Apple and/or Apple's licensor(s) retain ownership of the Apple Software itself.

Apple Seed (tune: Twinkle, Twinkle) I'm a little apple seed, Peeking through, Please help me, I'll help you. Dig me a hole, And hide me away, And I'll be an apple tree, Some fine day. Found an Apple [tune: "My Darling Clementine"] Found an apple, found an apple. Found an apple on a tree. I was napping, jus

Essentials of Knowledge Management,Bryan Bergeron Essentials of Patents,Andy Gibbs and Bob DeMatteis Essentials of Payroll Management and Accounting,Steven M.Bragg Essentials of Shared Services,Bryan Bergeron Essentials of Supply Chain Management,Michael Hugos Essentials of Trademarks and Unfair Competition,

Berkeley Madonna is available for both Macintosh and Windows platforms. While these versions are mostly identical, there are some differences which are noted throughout this guide with the notation [Macintosh] or [Windows]. System Requirements Macintosh: Power Macintosh or compatible computer1 with a PowerPC processor and least

British Association of Social Workers (2014) The Code of Ethics for Social Work. Birmingham: BASW First published: January 2012 Updated: October 2014 Typographically reset: 2018 . 3 The Code is binding on all social workers who are BASW members in all roles, sectors and settings in the UK. Social workers have a responsibility to promote and work to the Code of Ethics in carrying out their .