This is README.rtf in view mode; [Download] [Up]
ImageText By Jayson Adams NeXT Strategic Developer Engineer 24Apr91 Note: ChangeHistory.rtf documents the differences between this version and previous versions. Overview This example demonstrates how to place graphic images in a Text object. It presents a window, into which you can drag files from the Workspace. The window behaves similarly to a Mail Send window, imaging TIFF or EPS files dragged into it, and representing other files by their Workspace icons. You can also type multi-font text into the window. The ªLip Serviceäº command places an image with the ªLipsº icon at the current cursor position. Finally, you can save the RTF data to a file, or read an RTF file created by this example, or by any other application, into the window. The ªOpen RTF as ASCIIº command loads the raw RTF data into the window. Placing ªCellsº in a Text Object Text objects require that graphical objects living inside them implement the following six methods: Ð highlight:(const NXRect *)cellFrame inView:controlView lit:(BOOL)flag Ð drawSelf:(const NXRect *)cellFrame inView:controlView Ð (BOOL)trackMouse:(NXEvent *)theEvent inRect:(const NXRect *)cellFrame ofView:controlView Ð calcCellSize:(NXSize *)theSize Ð readRichText:(NXStream *)stream forView:view Ð writeRichText:(NXStream *)stream forView:view While Cells meet this requirement, you are not restricted to using them or Cell-subclass instances. In fact, the key to writing one of these special objects is to forget you ever heard of Cells Ð if you don't, you will almost certainly get confused. The Cell class is also more heavyweight than what you really need. This example contains a graphic object written ªfrom scratchº (it's an Object subclass) and should give you a pretty good head start on creating your own graphic ªcells.º One more thing: don't try to place views within a Text object. Even though the Release Notes say this is possible, the methods required for doing so simply don't work (as you will discover if you attempt to use them). ªCellsº and RTF Applications wishing to mix text and ªcellsº register ªdirective-classº pairs with the Text class. These pairs inform the Text object that a particular RTF directive corresponds to a particular ªcellº class. When a Text object, while writing its RTF data, encounters a ªcell,º it writes the corresponding directive to the stream, and then sends the writeRichText:forView: method to the ªcell.º The ªcellº must write out all the information it needs to later reconstruct itself. Note that unless you're following the RTF spec. completely, you should probably use a slightly different filename extension than ªrtfº (unlike this example; Edit, for example, uses ªrtfdº for it's special image-containing rtf files). When the Text object reads the RTF data and encounters a registered directive, it instantiates a ªcellº of the proper class and then sends it the readRichText:forView: message. The ªcellº must read all the data it wrote using writeRichText:forView: and use it to restore itself to its original state. Major Classes The major classes within ImageText: GraphicImage Base class which implements the six required messages for graphical objects living in a Text object. Maintains an image which it composites into its control view when asked to draw itself. Saves itself by writing a TIFF representation into the RTF stream. Used for the Lip image and EPS and TIFF files. FileImage Subclass of GraphicImage whose instances represent non-TIFF or EPS files. Writes the file name to the RTF stream rather than image data, and opens the file when double-clicked upon. Controller Performs some initialization, handles icon-entered and icon-exited events, and opens and saves the RTF data. Other Files CopyIcon.psw Contains a pswrap function used to copy bits from a Workspace window into an NXImage lips.tiff Lips icon ImageText.nib Main nib file Info.nib Contains the Info panel IB.proj, Created by Interface Builder Makefile, ImageText.iconheader ImageText_main.m Parting words... If you find the Text object behaving strangely when you place lots of ªcellsº into it, you've probably found a bug in the Text object rather than this code (this example flushed out at least 2 drawing bugs). Good luck! __jayson
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.