Description
This article is from the Mac Programming
FAQ, by Jon Watte h+@austin.metrowerks.com with numerous
contributions by others.
6.3) I'm too back-asswards to use WASTE 1.1. How do I include pictures in text using TextEdit? (Text - Mac Programming)
There's no really easy way (such as a TEAddPict() call), and it will
be a nasty kludge if you do get it working, but if you can live with
that, here's how to do it. I do recommend that you take a look at Q
6.2, above.
Write an algorithm to get the position of a special marker character
[Teach/SimpleText uses option-space] or text attribute that the user
will insert wherever he wants a picture. Pass this position to a
function similar to the one below.
*code*
/*
TEDrawPicture
Draw a picture within TextEdit's text.
input:
pos - the position of the special character in the text where the user
wants a picture.
r - size of picture
output:
r - frame in which picture was drawn
*/
void TEDrawPicture(short pos,PicHandle pic,Rect &r,TEHandle theTE)
{
Point bottomLeft; //I think TT/ST uses topleft
bottomLeft = TEGetPoint(pos, theTE);
r.right = bottomLeft.h + (r.right - r.left);
r.top = bottomLeft.v - (r.bottom - r.top);
r.left = bottomLeft.h;
r.bottom = bottomLeft.v;
DrawPicture(pic, &r);
}
*end*
I'll leave selection and hiliting as an exercise for the reader (don't
ya love it when people say that?).
Thereotically, it should be possible to kludge up TextEdit to the point
where it would treat pictures as if they were actually letters (rather big
letters, but letters just the same). That's what the width and word break
hooks are for, after all. However, this would be a lot of Work, and I've
never seen it done. One is lead to believe that it's less work to create
an improved version of TextEdit from the ground up with picture support.
WASTE 1.1, in fact, does this rather nicely.
 
Continue to:
Share and Enjoy
Bookmark this story so others can enjoy it:
Tags
os, Mac, macintosh, apple, programming, software