Article View: comp.sys.next.programmer
Article #403Handling custom RTF directives in Text.
From: Scott Hess
Date: Sun, 02 Aug 1992 17:47
Date: Sun, 02 Aug 1992 17:47
61 lines
3515 bytes
3515 bytes
In article <SCOTT.92Jul30040409@nic.gac.edu>, scott@nic.gac.edu (Scott Hess) writes: >I've been attempting to get some stuff done using custom RTF >directives in Text, specifically an \attachment directive (like >what Mail uses for attachments). I've got a special Cell type that >can hold a filename, and will image the file's icon and everything >- just as we expect. I've registered the Cell subclass' class >using Text's +registerDirective:forClass:. And, the saga continues ... First off, it appears that the \attachment directive is somehow special cased. I can't say exactly how, or why, because nobody has replied to my posting (well, nobody has replied with any answers or even hints). But, if I name my directive \attach, or anything but \attachment, things work out fine. Perhaps \attachment is a Microsoft pre-defined directive. In any case, I managed to figure out a way that I can cause my program to output the \attachment directive _exactly_ like Mail does, though. It gets a bit hairy, here. When I put the Cell that displays the file's icon into the Text object, I cause the NXRun associated with that Cell to have the rFlags.subclassWantsRTF flag set to YES. This, in turn, causes my Text delegate to be called with -textWillWriteRichText:*. At the point where -textWillWriteRichText:* is called, the Text has already written "\attachment ", so I then call the NXRun's info element (which is the Cell to be written) and ask it to write what it needs to write, namely the pathname. Now, my problem is retrieving the data from a stream. The delegate method -textWillReadRichText:* is called when Text comes across an \attachment directive in the input. It is simple enough for me to then read the pathname from the stream, _but_, there's no apparent method by which I can create a Cell and place it in the Text! If I use Text's -replaceSelWithCell:, it places the Cell wherever the selection was before the Paste was initiated without regard to which point in the stream we are reading from. This means that all of the Cells are pasted first, followed by any text. Now, this I can probably fix using an _extremely_ hacked solution - I can record the positions and filename for each Cell, and then insert them after the Paste. But this is _ugly_. Is there any way I can say "Put this Cell at the point we are in our reading of the NXStream?". [BTW, I just implemented the above. My, oh my, it _is_ disgusting. Works, though. One problem - why don't my Text delegate methods -textWillStartReadingRichText: and -textWillFinishReadingRichText: get called before and after RTF is read? I ended up putting the functionality in a Text subclass, but I'd still be interested in knowing ...] Thanks, -- scott hess <shess@ssesco.com> <Who's now in a programming Berserker-frenzy> 12901 Upton Avenue South, #326 Burnsville, MN 55337 (612) 895-1208 Anytime! <I want to become so famous that people buy tapes of me reading source code>
Technical Details
Message-ID:
<SCOTT.92Aug2124752@nic.gac.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!europa.asd.contel.com!darwin.sura.net!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!doug.cae.wisc.edu!umn.edu!noc.msc.net!gacvx2.gac.edu!gacvax2!scottShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!europa.asd.contel.com!darwin.sura.net!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!doug.cae.wisc.edu!umn.edu!noc.msc.net!gacvx2.gac.edu!gacvax2!scott From: scott@nic.gac.edu (Scott Hess) Newsgroups: comp.sys.next.programmer Subject: Handling custom RTF directives in Text. Message-ID: <SCOTT.92Aug2124752@nic.gac.edu> Date: 2 Aug 92 17:47:52 GMT Distribution: world Organization: Gustavus Adolphus College Lines: 61 Nntp-Posting-Host: nic.gac.edu