Thread View: comp.sys.next.programmer
3 messages
3 total messages
Started by Charles Herrick
Thu, 09 Apr 1992 19:55
-=?=- dumping text into an invisible text object -=?=-
Author: Charles Herrick
Date: Thu, 09 Apr 1992 19:55
Date: Thu, 09 Apr 1992 19:55
48 lines
1876 bytes
1876 bytes
Bubalah's,
I've got some email out on this, but it's driving me crazy so ...
I'd like to shove a selected section from one Text object into another so
I can send the "invisible" target Text object a printPSCode: message and
get the effect of printing selected text. The source Text object lives in
a ScrollView, is straight off IB's palette (i.e. setMonoFont:NO) and is:
docView = [myScrollView docView];
here's code:
BEGIN--CUT HERE--
{
NXSelPt start, end;
int length;
[docView getSel:&start :&end];
length = end.cp - start.cp;
if (length) // something selected, print it
{
id textObject;
NXStream *stream;
NXRect frameRect = {0.0,0.0,1.0,1.0};
// get an NXStream
stream = NXOpenMemory(NULL,0,NX_READWRITE);
// and dump from source Text object
[docView writeRichText:stream from:start.cp to:end.cp];
// get an invisible target Text object. Am I lost here?
textObject = [[[Text alloc]
initFrame:&frameRect]
setMonoFont:NO];
// dump into the text object
[textObject readRichText:stream];
NXClose(stream);
[textObject printPSCode:self];
[textObject free];
}
}
END--CUT HERE--
Now here's what happens ... in Gdb, after the readRichText: message to
textObject, sending [textObject byteLength] replies 1. And indeed a blank
page gets printed. I've noodled around with stream->buf_base, and there is
indeed stuff in the NXStream.
Help??
Chuck Herrick <cnh5730@maraba.tamu.edu>
Re: -=?=- dumping text into an invisible text object -=?=-
Author: simsong Simson L. Garfinkel
Date: Fri, 10 Apr 1992 16:20
Date: Fri, 10 Apr 1992 16:20
14 lines
982 bytes
982 bytes
The problem is that text objects must be on real windows in order to print. Instead of creating a new Text object to do your printing, just put a second text object somewhere else in your window. Make otherText the id of that text object. [window addSubview:otherText] [otherText moveTo:1e30 :1e30]; Now shove the stuff you want into otherText and have it print... -- ................................................................simson
Re: -=?=- dumping text into an invisible text object -=?=-
Author: Charles Herrick
Date: Fri, 10 Apr 1992 18:31
Date: Fri, 10 Apr 1992 18:31
52 lines
2111 bytes
2111 bytes
Charles Herrick writes
> Bubalah's,
> I've got some email out on this, but it's driving me crazy so ...
well, so my good friend and mentor Scott Hess helped me fix my very bogus
code, and here is some code that works. It allows you to print a section
of text that you've selected in a Text object. Happy Hacking :-).
By the way,
docView = [myScrollView docView];
BEGIN--CUT HERE--
- print:sender {
// this works because of Scott Hess, bless him!!
// the MenuCell button with tag == 0 is the "Print All" menu button
if (![[sender selectedCell] tag])
[docView printPSCode:self];
else {
NXSelPt start, end;
int length;
[docView getSel:&start :&end];
length = end.cp - start.cp;
if (length) // something selected, print it {
id invisibleWindow;
static id textObject = nil;
NXStream *stream;
NXRect frameRect;
stream = NXOpenMemory(NULL,0,NX_READWRITE);
[docView writeRichText:stream from:start.cp to:end.cp];
[docView getFrame:&frameRect]; // gotta have a real frameRect
if (!textObject) {
// so it won't complain during lockFocus
invisibleWindow = [[Window alloc] init];
textObject = [[[[Text alloc]
initFrame:&frameRect]
setMonoFont:NO]
setVertResizable:YES];
[[invisibleWindow contentView] addSubview:textObject];
}
else
[textObject setFrame:&frameRect];
NXSeek(stream, 0, NX_FROMSTART); // rewind the stream
[textObject readRichText:stream];
NXClose(stream);
[textObject sizeToFit]; // adjust the frameRect
[textObject printPSCode:self];
}
}
return self;
}
END--CUT HERE--
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