🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.sys.next.programmer
2 messages
2 total messages Started by Scott Hess Sun, 02 Aug 1992 17:47
Handling custom RTF directives in Text.
#403
Author: Scott Hess
Date: Sun, 02 Aug 1992 17:47
61 lines
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>
Re: Handling custom RTF directives in Text.
#441
Author: Michael Mellinger
Date: Tue, 04 Aug 1992 17:30
74 lines
4214 bytes
In article <SCOTT.92Aug2124752@nic.gac.edu> scott@nic.gac.edu (Scott Hess)  
writes:
 
> 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.

Hmmm.  I didn't realize that someone else was having this same problem.
I've spent the past few days trying to figure this out, but I've had no  
luck.

My guess is that the word attachment is already registered under some  
other class.  If you try to register a word twice, the second time it is  
ignored.  For example, after this code is executed, the word GraphicImage  
will still be registered with the GraphicImage class.

  [Text registerDirective:"GraphicImage" forClass:[GraphicImage class]];
  [Text registerDirective:"GraphicImage" forClass:[FooImage class]];

So, I figure that the word attachment might already be registered.  If we  
knew the class name, it might be possible to substitute in the proper  
object.
 
> 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.

The attachment directives in Mail contain the file position where the  
attachment belongs.  You can edit your mail documents and move the  
attachment statements around and the attachments will appear in the same  
place.  If you change the character position that is appended to the end,  
then the attachment will move in your message.  I was considering just  
extracting the attachments separately by parsing the rtf myself then  
inserting the attachments in their proper locations.

> 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?".


Personally, I wouldn't use the word attachment unless I was planning on  
being able to read NeXT Mail documents.  I think that it is the only thing  
that currently uses this keyword.  RTFD uses the word NeXTGraphic,  
followed by the character position.  One multimedia text standard would be  
best, so applications can cut and paste among themselves.  Under 3.0 there  
is some sort of filter to allow Edit documents with attachments(apps,  
sounds, tiffs) etc. to be copied into mail.  Under 2.0, attachments were  
copied as filenames from Edit to Mail.

Anyway, the moral of the story is that standards are nice.  Btw, does NeXT  
document their RTFD "standard" in 3.0?
 
> [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 ...]

I'll probably need -textWillFinishReadingRichText to scan for attachments,  
if I don't find out the proper hack, so I'll let you know.

-Mike
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads