NeXTSTEP Programming, Step One: Object-Oriented Applications

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

This book is about programming computers running NeXTSTEP. It’s a nononsense, hands-on book that teaches programmers how to write application programs that take full advantage of NeXTSTEP, the operating environment from NeXT Computer Inc. Writing programs for NeXTSTEP is fundamentally different than writing programs for other computers, because NeXTSTEP represents a radical departure from conventional programming environments. One writes NeXTSTEP programs by building systems of related but distinct parts, or objects, and connecting them together to form an integrated whole. Confining different aspects of a program to different pieces makes those pieces easier to design, implement, debug, and reuse. This is what is known as object-oriented programming. NeXTSTEP embodies the principles of object oriented programming from its user interface down to its very core. This greatly simplifies the task of interfacing application programs with the NeXTSTEP operating environment. The downside is that it makes the NeXTSTEP environment very different from the environments to which most programmers are accustomed: there’s a steep curve to climb when learning to program in this easy-to-program environment (sounds strange, but it’s true). We wrote this book out of frustration: at the time, there was no single book that explained step-by-step how to write programs for NeXTSTEP. Instead, a programmer trying to approach the platform was confronted by the NeXT technical documentation and the source-code for several dozen example programs. There was no mention of style, program structure or design considerations. It seemed that there was a black art to writing programs for the black computer, along with a priesthood which promised that newcomers might one day become members — once we paid our dues. With this book, we’ve paid a lot of your dues for you. This book is for anybody who knows how to program in C and wants to do something substantial with NeXTSTEP. Our goal is to get you up-and-running as quickly as possible. This isn’t a textbook or a reference manual — Brad Cox (the inventor of Objective-C) and the technical writing department at NeXT have already written those. This book is instead a jumpingoff point. Consequently, we will occasionally sacrifice depth for breadth and brevity. You won’t learn all of the options of Interface Builder or all the obscure methods that the Text object implements by reading this book. But you'll acquire the conceptual framework necessary to understand NeXT’s excellent documentation, enabling you to discover what you need to know about the Text object and everything else. [Associated diskette image freely available at https://archive.org/details/nextestep-prog-step-one-disk]

Author(s): Simson L. Garfinkel, Michael K. Mahoney
Publisher: Telos - Springer-Verlag
Year: 1993

Language: English
Pages: 631
City: New York
Tags: nextstep;openstep;gnustep

Preface
What is NeXTSTEP?
What You Need
Programming with NeXTSTEP 2.1
Programming with NeXTSTEP 3.0
Additional Programs
The Organization of this Book
Part 1
Part 2
Part 3
Part 4
Part 5
Appendices
Floppy Disk
Conventions Used in this Book
Acknowledgments
Authors’ Biographies
Concise Table of Contents
1
Introduction to the NeXTSTEP Graphical User Interface
What Makes NeXTSTEP So Special?
An Overview of the Graphical User Interface
Basic Principles of the NeXTSTEP User Interface
The Mouse
Mouse Action Paradigms
Cursors
Window Types
Standard Windows
Panels
Menus
Pop-Up Lists
Pull-Down Lists
Miniwindows
Freestanding and Docked Icons
Main and Key Windows
Window Order
1. spring-loaded windows (e.g., pop-up lists, pull-down lists, and menus which pop up at the curs...
Controls
Buttons
Menu Commands
Text Fields
Sliders and Scrollers
Browsers and Selection Lists
Color Wells
The Workspace Manager Application
The File Viewer
The Workspace Menu Structure
Workspace Manager Panels
Configuring Your Workspace, Step by Step
1. Log in to a NeXTSTEP environment. To do this, you must have a username and a password. (If you...
Menu Guidelines and Keyboard Alternatives
Main Menu
Info Submenu
Document (or File) Submenu
Edit Submenu
Find Submenu
Format Submenu
Font Submenu
Windows Submenu
Services Submenu
Working with the File System, Step by Step
1. Log in.
New Features in the NeXTSTEP 3.0 Interface
Workspace Manager 3.0 Menus: New Commands
Workspace Manager 3.0 Panels: New Features
NextApps, NextDeveloper/Apps Folders in NeXTSTEP 3.0
Preferences Application: New Features
Summary
2
NeXTSTEP Development Tools
The Terminal Application
1. Launch the Terminal application (from your dock or /NextApps). A UNIX shell window will likely...
Edit – NeXTSTEP’s Mouse-Based Editor
Using Edit and Librarian, Step by Step
1. Copy the /NextDeveloper/Examples/AppKit/Lines directory (/NextDeveloper/Examples/Lines in 2.1)...
HeaderViewer
Creating Icons
Creating an Icon with IconBuilder in NeXTSTEP 3.0
1. Drag the IconBuilder application file icon into your dock (it’s in the /NextDeveloper/Apps dir...
Creating an Icon with the Icon Application in NeXTSTEP 2.1
1. Drag the Icon application file icon into your dock (it’s in the /NextDeveloper/Demos directory).
Using an Icon to Represent a Directory in the File Viewer
make – The UNIX Program Building Utility
gdb – Debugging Programs
gdb Commands
gdb’s “view” Command
gdb’s “where” Command
gdb’s “print” Command
Using gdb in NeXTSTEP 3.0
User Interface Design
Summary
3
Creating a Simple Application With Interface Builder
Getting Started with Interface Builder
1. Log in and hide the Workspace Manager.
Adding Objects to Your Application
Adding a Button Object to Your Window
Giving Your Button a Funky Sound
1. Click the Sounds suitcase icon in the File window to see the Sounds view. (In NeXTSTEP 2.1, yo...
Giving Your Button an Image
Objects, Messages, and Targets
Objects and Classes
Targets, Actions, and Connections
1. Drag the icons for the TextField and Slider objects (seen at the left of the page) from the Pa...
Congratulations!
4
Creating an Application Without Interface Builder
The Tiny.m Program
Tiny.m: line-by-line
Classes and Objects, Methods and Messages
The Circle Class Example
Creating and Destroying Objects
Class Interface Definitions
The NeXTSTEP Classes Used by Tiny.m
Inheritance
Back to Tiny.m
Windows, Menus, and the demo() Function
Views
Drawing with PostScript Inside a View Object
Responding to Events
An Introduction to Event Handling
Tiny2: A Demonstration of Event Handling
NeXTSTEP Capitalization Conventions
General Rules
Objective-C Class Names
Objective-C Methods
UNIX Variables and Functions
Summary
5
Building a Project: A Four Function Calculator
Getting Started Building the Calculator Project
1. Make sure the Project Builder (PB) and Interface Builder (IB) icons are in your dock and then ...
Building a Project in NeXTSTEP 2.1
1. Make sure the Interface Builder (IB) icon is in your dock and launch IB from your dock.
Building the Calculator’s User Interface
Customizing the Main Window
7. Select “My Window” in IB by clicking in the window’s background.
Adding Controls in a Window
Matrix Dragging Options
Building the Calculator's Controller Class
Designing the Controller Class
Creating the Controller Class
1. Open the Classes view in IB’s File window by clicking the Classes (h) suitcase icon.
Outlets and Connections
Adding Outlets to an Object
Making the Connection
Adding Actions to the Controller
Generating the Controller Class Files
Adding Code to Make the Controller Class Work
Customizing Buttons and Making Connections
Instantiating (Creating an Instance of) the Controller Class
1. Make sure the Classes view is displayed in IB’s File window and then select the Controller class.
Setting Up Titles and Tags for the Keypad Buttons
Making the Connections
Compiling and Running a Program
Compiling and Running a Program from Project Builder
1. Activate PB and click the Builder button at the top of PB’s main window to see the Builder vie...
Compiling and Running a Program in a Terminal Shell Window
Compiler Error Messages
Tags and the enterDigit: Action Method
Adding the Four Calculator Functions
1. Using an editor, insert the following enumerated data type after the #import directive in the ...
Adding Unary Minus to the Controller Class
Using IB’s Parse Command with a New Action Method
1. Using an editor, insert the doUnaryMinus: action method definition in bold below into Controll...
The Files in a Project
The Project Builder-generated Makefile
The PB-generated main() Program File
Other PB-generated Files
Summary
6
Nibs and Icons
Managing Multiple Nibs
Modifying the Controller Class
1. Using an editor, insert the two lines in bold type below into Controller.h and save the file. ...
Modifying the Main Calculator Nib
Creating the Info Panel’s Nib in NeXTSTEP 3.0
Creating the Info Panel’s Nib in NeXTSTEP 2.1
17. Choose IB’s FileÆNew Module command. You will see the New Module panel.
Adding Icons to Your Application
Creating Icons
Changing the Calculator’s Application Icon
1. Back in Project Builder, click the Attributes button to display the attributes of your Calcula...
Changing an Application Icon in NeXTSTEP 2.1
1. Back in IB, click the Attributes/Files button in the Project Inspector so that the word Attrib...
NeXTSTEP Images
Adding Other Images to Your Application
Summary
7
Delegation and Resizing
Handling Different Bases
1. Open your Calculator project in Project Builder (PB) by double- clicking the PB.project file i...
Modifying the Controller Class
Delegation
Did and Will Delegate Methods
Specifying an Object’s Delegate
Setting Up a Delegate Outlet in the Nib
1. Back in IB, Control-drag from the File’s Owner icon to the Controller instance icon inside the...
Adding the Delegate Method
Disabling Buttons for Better Multi-Radix Input
1. Using an editor, replace the 10.0 in the enterDigit: method in Controller.m with radix to get:
Using a List Object to Directly Access Matrix Cells
Coherence in Object-Oriented Programming
Resizing Windows Programmatically
Modifying the Calculator’s Interface
1. Back in IB, click the resize button () in the Calculator window’s title bar and extend the win...
Modifying the Controller Class
The Window and View Classes
The Window Class
The View Class
Strong Typing with Objective-C
Summary
8
Events and Responders
Events and the Responder Chain
What Is An Event?
The NXEvent Data Structure
Events and the Application Object
Responders and the Responder Chain
Mouse Event Handling
Keyboard Event Handling
An Event Handling Example
Action Messages and the Responder Chain
Other Kinds of Events
The Event Loop
The Application Event Loop
Catching Keyboard Events for the Calculator
Subclassing the Window Class
1. Open your Calculator project in Project Builder (PB) by double- clicking the PB.project file i...
Hash Tables
Searching for Button Titles in the Calculator Window
Finishing Off the CalcWindow Class Implementation
Changes in the Controller Class
Summary
9
Mach and the Window Server
The Mach Operating System
The Microprocessor
The Mach Microkernel
The Mach System Support Environment
Usernames and UIDs
Processes, PIDs, and UIDs
Mach-O: The Mach Object File Format
The Window Server and Display PostScript
PostScript
The Application Kit and the Window Server
Seeing All the Processes
10
MathPaper and Multiple Windows
MathPaper
The Structure of MathPaper
The Evaluator Back End
Lex and Yacc
Building the Back End
1. Create a new directory called Evaluator in your home directory.
Building the MathPaper Front End
Setting up the Main Nib
1. Launch Project Builder (PB) from your dock, choose PB’s ProjectÆNew menu command and give your...
Setting Up the paperwindow Nib
Setting Up the paperwindow.nib Connections
Window Delegates
Controlling the MathPaper Application
Controlling a Piece of MathPaper
Testing MathPaper
Summary
11
Spawning Multiple Processes and the Text Object
Spawning Processes with the Process Class
1. Using an editor, create a file called Process.h in your MathPaper directory which contains the...
The ScrollView and Text Classes
Text Class Basics
Changes to the PaperControl Class
Spawning the Subprocesses
Displaying Data Received From the Process
Outlet Setting Methods
Text Delegates and Field Editors
Getting Out of Hand
Summary
12
Text and Rich Text
What Is Rich Text?
Manipulating a Text Object with Explicit Commands
Rich Text Format (RTF)
Exploring Rich Text Commands
Understanding the Rich Text Format
A Rich Text Object
Integrating the Rich Text Object with MathPaper
1. Using an editor, create the RTF.h and RTF.m class files (as specified in the previous section)...
Summary
13
Saving, Loading, and Printing
Saving to a File
File Name Extensions
Adding a Document File Icon and Extension to MathPaper
1. Create an icon for MathPaper document files and save it in your MathPaper directory with the n...
Writing the Save Methods
Testing the Save Features
Loading From a File
1. Insert the new loadCalc: action method declaration below into MathController.h, immediately be...
Exception Handling
Marking a Document Window as Edited
1. Insert the two lines in bold below into the appendtoText:fromPipe: and save: methods in PaperC...
Terminating an Application Properly
Enabling and Disabling Menu Cells
Window Updates
Making MathPaper Update Its Menus
1. Insert the three new outlets and new method declaration in bold below into MathController.h.
Adding Printing Capability
1. Back in IB, select the FirstResponder “class” in the MathPaper.nib Classes view.
Summary
14
Drawing with Display PostScript
Animation in an Info Panel
pswrap: Wrapping PostScript into a C Function
Passing Arguments to pswrap Functions
Wraps that Return a Value
Buffering
A PostScript Wrap for MathPaper
1. Using an editor, type in the wrap below and save it in a file called supershow.psw in your Mat...
Drawing in a View with PostScript
Adding the Animated Info Panel to MathPaper
Adding the Info Panel Menu Cell, Method, and Connection
InfoView’s Animation Code
Testing the Animation
Displaying Pictures in a View
Compositing
The Dissolving Animation
1. Insert the animateDissolve: method below into InfoView.m. Put it above the animateInfo: method...
Display PostScript Timed Entries
Adding a Timed Entry
The Timed Entry Handler
Removing a Timed Entry
Using Timed Entries in Animation
1. Replace the entire contents of the InfoView.h file with the InfoView class interface code below.
Summary
15
Draw Yourself: All About NeXTSTEP Views
The Advantages of View’s drawSelf:: Method
BlackView: A View That Paints Itself Black
1. Launch Project Builder (PB) from your dock, choose PB’s ProjectÆNew menu command and give your...
A Closer Look at the View Class
View Coordinate Systems
Moving and Resizing Views
Flipping
The View Hierarchy
Opaque and Non-Rectangular Views
Displaying Views
Controlling Redisplay
Resizing
BarView: A View with a Scaled Coordinate System
1. Launch PB from your dock, choose PB’s ProjectÆNew menu command and give your new project the n...
PolygonView: A Non-Opaque View
1. Launch PB from your dock, choose PB’s ProjectÆNew menu command and give your new project the n...
Changing the PolygonView’s Size
Placing a View Inside a ScrollView
Responding to Events in a View
Getting a Mouse-Down Event
1. Insert the mouseDown: method declaration below into PolygonView.h.
Autosizing Multiple Views in a Window
1. Back in IB, select the PolygonView instance and type Command-3 to bring up the Size Inspector....
Summary
16
GraphPaper: A Multi-Threaded Application with a Display List
GraphPaper’s Design
The Interface
Connecting to the Back End
Why Use a Display List?
Working with Multiple Threads
The Difficulty of Using Threads
C Threads
Using C Threads
Threads and Objective-C
Building the GraphPaper Application
Changes to the Evaluator Back End
1. Using an editor, insert the six lines in bold below into grammar.y.
Building GraphPaper’s Interface
1. Launch Project Builder (PB) from your dock, choose PB’s ProjectÆNew menu command and give your...
The GraphView Class Interface File
The GraphView Class Implementation File
The Data Stuffer Methods
Stopping a Running Graph
The Data Stuffer Function
Constructing the Graph
The drawSelf:: Method
The clear and awakeFromNib Methods
The Segment Class
The Process Class
Testing GraphPaper
Extending the Display List
Adding Axes
1. Insert the addAxesx1:y1:x2:y2: method declaration below into GraphView.h.
Adding Labeling
1. Create a file called Label.h containing the Label class interface code below.
Using the Label Class
Summary
17
Color
Colors and Color Objects
Colors From a Programmer’s Point of View
Colors From a User’s Point of View
Programming with Colors
Adding Color to GraphPaper
Creating a Preferences Panel
The Controller Class
1. Open your GraphPaper project in Project Builder and the GraphPaper.nib file in Interface Builder.
Creating the Preferences Nib, Panel, and Controller
PrefController Class Implementation
ColorGraphView
Adding Color to GraphPaper
Changes to the GraphView Class
The ColorGraphView Class Implementation
Setting the Colors
Setting the Initial Color
Changes to the Segment and Label Classes
Testing GraphPaper’s Color
Summary
18
View Resizing and Mouse Tracking
More About Resizing
1. Open your GraphPaper project in Project Builder and the GraphPaper.nib file in Interface Builder.
Keeping Your Windows Big Enough
Tracking the Mouse
Tracking Rectangles
The Window Event Mask
Adding Mouse Tracking to GraphPaper
Changes to the GraphPaper Interface
1. Back in IB, Subclass the ColorGraphView class. Rename the new class TrackingGraphView.
Changes to the TrackingGraphView Class Files
Changing the Cursor
Adding a Cursor to the Nib
1. Create a cursor that you like (or use an existing one such as cross.tiff in /NextDeveloper/Exa...
Changes to the TrackingGraphView Class
Summary
19
Zooming and Saving Graphics Files
Adding a Zoom Button To GraphPaper
The ScrollView Class Revisited
Changes to GraphPaper.nib
1. Open your GraphPaper project in Project Builder and the GraphPaper.nib file in Interface Builder.
Changes to ZoomScrollView
Testing the Zoom Button
Bug Fixes
Saving a View as Encapsulated PostScript
Changes to GraphPaper.nib
1. Back in IB, add a menu item to the GraphPaper menu. Change its title to Save Image and give it...
Changes to the Controller Class
Testing the Save Image Menu Command
Saving a View in Tag Image File Format
1. Insert the method declaration below into Controller.h.
Creating an Accessory View
Changes to the Controller Class Implementation
Testing the “EPS or TIFF” Save Feature
Summary
20
The Pasteboard and Services
Cut, Copy, and Paste with the Pasteboard
Providing Data to the Pasteboard
Using the Pasteboard in GraphPaper
1. Insert the four method declarations below into Controller.h.
Providing Data Through Lazy Evaluation
Implementing the Cut Command
Testing GraphPaper’s Copy and Cut Commands
Services
How Services Work
Creating Your Own Service
Adding a Graph Service to GraphPaper
1. Using an editor, create a file called services.txt in your GraphPaper project directory with t...
Testing GraphPaper’s Service
Summary
21
Preferences and Defaults
How Preference Defaults Work
Accessing the Information Stored in the Database
Adding Defaults to GraphPaper
1. Insert the class method declaration below into Controller.h.
Reading Values from the Defaults Database
Making the Preferences Panel Work with Defaults
Modifying the Preference Panel
Changes to PrefController Class
Testing the Updated Preferences Panel
Setting Up a Multi-View Panel
Multi-View Panels
1. Insert the three instance variables and two method declarations in bold below into PrefControl...
Changes to the Interface
Defaults for Initial Values
Summary
Appendix A: Source Code Listings
Calculator Application
CalcWindow.h
CalcWindow.m
Calculator_main.m
Controller.h
Controller.m
MathPaper Application
InfoView.h
InfoView.m
MathController.h
MathController.m
MathPaper_main.m
PaperControl.h
PaperControl.m
Process.h
Process.m
RTF.h
RTF.m
GraphPaper Application
Controller.h
Controller.m
GraphPaper_main.m
GraphView.h
GraphView.m
Label.h
Label.m
PrefController.h
PrefController.m
Process.h
Process.m
Segment.h
Segment.m
TrackingGraphView.h
TrackingGraphView.m
ZoomScrollView.h
ZoomScrollView.m
Appendix B:References
C, Objective-C, and Object-Oriented Programming
UNIX
GNU Tools
PostScript and Display PostScript
Computer Security
Compositing
Data Formats
User Interface Design
Index