← Macintosh C Programming Primer, Volume II: Mastering the Toolbox Using THINK C

Macintosh C Programming Primer, Volume II: Mastering the Toolbox Using THINK C

From the originals

13 scans

Machine-transcribed text and image descriptions. Check the linked original for uncertain words or fine print.

These are transcribed pages from the documents, not the full publications. Open the original for the remaining pages.

Image 1

Macintosh C Programming Primer

Addison-Wesley DAVE MARK Macintosh® C Programming Primer Volume II Mastering the Toolbox Using THINK C®

A book cover with a blue header bar bearing the Addison-Wesley logo and author name, a large black serif title with the word Primer spelled in colorful cut-out letter tiles (pink P, orange r, blue i, purple M, orange e, green R), and a blue-scribbled shape at the lower left behind the subtitle text.

Reading notes: The blue shape at lower left partially overlaps the word THINK in the subtitle, so 'THINK' is partly obscured and read from context. The 'Volume II' line is in blue while the subtitle below is black; reading order follows top-to-bottom layout. The 'Primer' letter tiles are stylized and partly overlap each other; letters were read as P, r, i, M, e, R.

Printed product names
Macintosh · THINK C
Languages
English
PDF page 1

Macintosh C Programming Primer

Addison-Wesley DAVE MARK Macintosh® C Programming Primer Volume II Mastering the Toolbox Using THINK C®

Book cover with a blue top band showing the Addison-Wesley logo and author name, large black title letters with the word Primer set in multicolored tilted paper-like blocks (pink, yellow, blue, purple, orange, green), and a blue diagonal shape in the lower left behind the subtitle.

Reading notes: Subtitle text 'Mastering the Toolbox Using THINK C' is partly overlapped by the blue shape in the lower left; the letters 'THINK C' are legible but the overlap reduces clarity. Reading order of the title lines is inferred from layout.

Printed product names
Macintosh C Programming Primer · THINK C
Languages
English
PDF page 2

Macintosh®C Programming Primer

Macintosh®C Programming Primer Volume II Mastering the Toolbox Using THINK C® Dave Mark • ...... Addison-Wesley Publishing Company, Inc. Reading, Massachusett,s Menlo Park, California New York Don Mills, Ontario Wokingham, England Amsterdam Bonn Sidney Singapore Tokyo Madrid San Juan Paris Seoul Milan Mexico City Taipei

Reading notes: Possible OCR error: 'Massachusett,s' appears with a stray comma. Line-break and reading order of publisher city list is uncertain.

Printed product names
Macintosh®C · THINK C®
Languages
English
PDF page 3

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 Addison-Wesley was aware of a trademark claim, the designations have been printed in initial capital letters or all capital letters. Under the copyright laws, this book may not be copied, photo- copied, reproduced, translated, modified, or reduced to any electronic medium or machine-readable form, in whole or in part, without the prior written consent of the publisher. Library of Congress Cataloging-in-Publication Data (Revised for vol. 2) Mark, Dave. Macintosh programming primer. Includes index. Bibliography: p. Vol. 2 has title: Macintosh C programming primer. Contents: [1] Inside the toolbox using THINK's Lightspeed C - v. 2. Mastering the toolbox using THINKC. 1. Macintosh (Computer)- Programming. 2. C (Computer program language). I. Reed, Cartwright. II. Title. III. Title: Macintosh C programming primer. QA76.8.M3M368 1989 005.265 88-34992 ISBN 0-201-15662-8 ISBN 0-201-57016-5 Copyright© 1990 by Dave Mark All rights reserved. Printed in the United States of America. Published simultaneously in Canada. ISBN 0-201-57016-5 4 5 6 7 8 9 10 - MW - 94939291 Fourth printing, November 1991

Reading notes: Printed catalog numbers and ISBN digits may be garbled by extraction spacing Some product designations split across lines in the front matter

Printed product names
Lightspeed C · Macintosh
Printed dates
1989 · 1990 · November 1991 · 88-34992
Languages
English
PDF page 4

To Deneen and my father, both of whom reached milestones this year.

A mostly blank white page with two lines of italic serif text centered on the left-middle area and a thin vertical gold line running down the right side.

Reading notes: Reading order is top-to-bottom as printed; no headline is present.

Languages
English
PDF page 5

Contents Foreword by Scott Knaster ix Preface xi Acknowledgments xm 1 Welcome Back 1 Volume I in Review 3 Volume II Topics 5 Chapter 2-Toolbox Techniques 5 Chapter 3- Code Resources 6 Chapter 4- Color QuickDraw 8 Chapter 5- TextEdit 11 Chapter 6- 0bject Programming 12 Appendix A- Glossary of Terms 13 Appendix B- Source Code Listing 13 How to Use This Book 14 Ready, Set . . . 15 2 Toolbox Techniques 17 All About Pointers 19 Pointers Are Never Relocatable 22 The Macintosh Memory Layout 22 The System Space 23 The Application Space 23 v

Reading notes: Table of contents layout and page numbers may not reflect original reading order

Languages
English
PDF page 6

Macintosh Programming Primer

vi Macintosh Programming Primer The Stack 25 The Application Heap 27 Handles, At Last! 29 Careful With That Handle, Eugene! When To Use Handles 34 Miscellaneous Tips and Techniques 34 MoreMasters( ) and MoveHHI( ) 35 Purgeable Blocks 35 Keeping Your Applications 32-bit Clean Piggybacking Data on Your Windows Calling Them, So They Can Call You In Review 39 3 Code Resources 41 Specialized Code 43 The Common Thread 44 Chapter Programs 45 AFI, the Application Font INIT 46 AFI Resources 48 Creating the AFI Project 53 32 35 36 38 Walking Through the AFI Source Code 56 The AFI cdev 60 AFI cdev Resources 61 The cdev Source Code 67 Checking Out the AFI cdev 73 Walking Through the cdev Source Code 74 Writing Your Own MDEF 82 The MDEF Project and Source Code 83 Building Your MDEF 87 Building the MDEF Tester 88 Walking Through the PICT MDEF Source Code 100 Dialog Filter Procedures 106 Creating the DLOG Resources 107 Walking Through the DLOG Source Code 115 In Review 121 4 Color QuickDraw 123 The Evolution of QuickDraw 125 Color QuickDraw and Indexed Devices 126 The CGrafPort and the CWindowPtr 128 What Machine Is the Program Running On? 129 Keeping Track of Graphic Devices 131 The Pixel Image 132

Languages
English
PDF page 7

Contents vii The First Program: Colorlnfo 133 Colorlnfo Resources 133 Setting Up the Project 135 Running Colorlnfo 140 Walking Through the Colorlnfo Source Code 141 The Palette Manager 149 Using the Palette Manager 150 Palette 152 Palette Resources 152 Setting Up the Project 152 Running Palette 159 Walking Through the Palette Source Code 159 Using the Arithmetic Color Modes 167 ColorTutor: Hands-on Color 167 ColorTutor Resources 169 Setting Up the Project 170 Running ColorTutor 184 Walking Through the ColorTutor Source Code 185 Working with Off-screen Drawing Environments 202 GWorld 203 GWorld Resources 203 Setting Up the Project 203 Running GWorld 208 Walking Through the GWorld Source Code 208 In Review 215 5 TextEdit 217 Exploring TextEdit 219 Using TextEdit 221 TextEdit Record 221 TextEdit Routines 224 Scrolling Text in TextEdit 227 Resizing the DestRect 228 TextEdit's Private Scrap 230 FormEdit 230 FormEdit Resources 232 The Code 242 Running FormEdit 270 Walking Through the FormEdit Source Code 271 In Review 311

Reading notes: Source appears to be a table of contents with OCR artifacts (e.g., 'Colorlnfo' likely 'ColorInfo', 'Setting Up' spacing). Reading order of fragmentary headings may be uncertain.

Languages
English
PDF page 8

viii Macintosh Programming Primer 6 Object Programming 313 About Object Programming 315 The Shaper Applicaticm 316 An Object View of Shaper 316 An Example 317 Instance Variables and Methods 318 Creating Some Shape Objects 319 Object References 320 Shape's Methods 322 Adding Subclasses to Shaper 323 CreateSquare ( ) versus CreateShape ( 324 A Second Shape Subclass 324 Object Classes Exist on Levels 326 More about Methods 327 The THINK Class Library 329 TCL Organization 330 The Visual Hierarchy 330 The Chain of Command 333 The Switchboard and the Bartender 335 Building an Application with the TCL 335 Art Class 336 TinyEdit 337 The Starter Application 338 MyStarter 340 Creating a Folder for MyStarter 341 Changing CStarterDoc.c 342 Replacing CStarterPane.c 344 Replacing CStarterPane.h 34 7 Creating CDragPane.c 34 7 Creating CDragPane.h 350 Creating CMouse.c 351 Creating CMouse.h 354 Checking Your Work 355 Walking Through the MyStarter Source Code 357 The CMouse Object Class 366 In Review 371 Appendix A Glossary 373 Appendix B Code Listing 395 Index 497

Reading notes: Table-of-contents style text with OCR-like spacing artifacts such as 'Applicaticm' and split words like 'CreateShape (' and '34 7' Primary heading not explicitly printed in the supplied copy

Languages
English
PDF page 9

Foreword Scott Knaster Back in 1984, just after the end of the Pleistocene Era, it was actually possible for one person to know just about everything there was to know technically about a Macintosh. There was, after all, just one model, the venerable but not venerated Macintosh 128K. In fact, calling the Macintosh 128K the first member of a product line was pretty much wishful thinking; after all, they didn't say "World War I" until the sequel came out. But I digress (or just think of it as hypertext). For all its 64K of ROM, several hundred routines, and many storage options (you could connect an external 3-t inch disk drive, or not), the Macintosh programmer's world was well-defined, and by today's standards, it was graspable- you could get your head around it, as they used to say here in California. Things around here are a little bit different now, of course. Chances are your Macintosh knows how to talk to one or two across the room, and if you're really cool, probably a few hundred more located somewhere between here and Indonesia. There are now well over a thousand routines defined in the many versions of the ROMs that Apple's genius engineers have cranked out over the past few years in between cans of Jolt cola and occasional minutes of sleep. It's a rich and complex world for programmers of all stripes, both pro- fessional and hobby varieties. ix

Reading notes: Phrase 'Pleistocene Era' is a figurative reference rather than a dated date; 'Indonesia' and 'California' are place references only. Inline text contains a hyphenated line break 'pro-fessional' that may be a typesetting artifact.

Printed product names
Macintosh 128K · Macintosh · Jolt
Printed dates
1984
Languages
English
PDF page 10

Macintosh Programming Primer

x Macintosh Programming Primer And that, at last, is where this book comes in. Not too long ago, I was wondering (electronically) aloud why no one had written a practical, up-to-date book about programming the Macintosh in C, currently the most popular language among Macintosh programming gurus. The answer, of course, was that there was a book like that. Hiding behind the innocent guise of a primer was just such a volume, with friendly presentation, thoroughness, and fun. That was Volume I of the Macintosh Programming Primer, predecessor of this book. (Digression again: as you probably know, the folks who invented the Macintosh planned on programmers using Pascal or assembly language. At that time, C was for UNIX hackers and employees of huge telephone companies . Pretty soon, though, the clamor for C started, and the rest is history. If you have practical reasons for avoiding C, such as the need for features available in another language, you probably have no reason to switch. To those of you who resist C for religious reasons, I'll point out that Pascal and C really aren't so different. It's a little like those two guys with black and white faces on Star Trek; they hated each other, but nobody else could tell them apart. Language religion wars don't really help anyone, but writing great software does.) Anyway, Dave Mark sees all the neat new stuff in the Macintosh world as his playground, and he invites us to play, too. In this wonderful volume, we get to go exploring with Dave as he takes us on a tour of many of the things that our new and improved Macintoshes can do. Some of my favorite discussions include the ones about cdevs, object programming, and the world of living color with Color QuickDraw, but they're all entertaining. By choosing THINK C as the learning tool, we can all easily sing along with Dave as we go. This book is full of fun and good learning. With the vast landscape of Macintosh programming as your goal and Dave Mark as your friend, you'll soon feel the awe and mystery of commanding your Macintosh to do great things. Scott Knaster

Reading notes: The source contains a foreword-style passage with an apparent inline digression; reading order is continuous but intentionally interjected.

Printed product names
THINK C · Color QuickDraw · Pascal · C · Star Trek · UNIX · Macintosh
Languages
English
PDF page 11

Preface From the sounds of it, Macintosh Programming Primer, Volume I was well received. Cartwright Reed and I got lots of letters, phone calls, and AppleLinks, and all were much appreciated. People also sent us personal letters relating their own programming experiences. We even got Christmas cards! We also received a bunch of letters from people with suggestions for Volume II of the Primer. These letters were the primary factor in determining the table of contents for this book. Color QuickDraw, Object Programming, and TextEdit all made the cut-you asked for it, you got it! I am very interested in hearing from you. Feel free to send me your comments on Volume II, good or bad. I'd also love to see examples of your work. Has anyone built an application that's on the market, or being regularly used? Keep in touch. As always, send all letters, comments, and cards (especially baseball cards-I love those!) to: Mac Primer Comments 2534 North Jefferson Street Arlington, VA 22207 One more thing. Please join me and millions of others in the cam- paign to save our planet's natural resources. Recycling, conservation of water and gasoline, and reduced consumption of non-biodegradable products are vital to that goal. I believe that together we can make a difference. D.M. Arlington, VA xi

Reading notes: Several words are split by hyphenation or line breaks, such as 'cam-paign' and 'non-biodegradable', which may affect reading order.

Printed product names
Macintosh Programming Primer, Volume I · Color QuickDraw · TextEdit
Languages
English