Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!uw-beaver!blake!Tomobiki-Cho!mrc From: mrc@Tomobiki-Cho.acs.washington.edu (Mark Crispin) Newsgroups: comp.sys.next Subject: Re: writing to a ScrollView Message-ID: <1074@blake.acs.washington.edu> Date: 6 Mar 89 19:42:02 GMT References: <9235@orstcs.CS.ORST.EDU> Sender: news@blake.acs.washington.edu Organization: Mendou Zaibatsu, Tomobiki-Cho, Butsumetsu-Shi Lines: 62 Here's the method I have to do what you want. It isn't very pretty, but it does the job. I'd be happy to get any word on a better way to do this. As a general comment, sometimes there is *too much* documentation on the NeXT, and simple answers to simple questions get obscured. telemetryView is an instance variable that is set by an outlet connected to the Scrolling TextView inside my window. The scrolling is a bit strange. By default, the contentView will stay at the top of the docView. What I did was take the docView's rectangle and set its origin to its height. This creates a rectangle that is immediately below the docView; I then scroll to make that rectangle visible. It can't, of course, but it scrolls as close as it can (to the bottom). The other strange thing about the scrolling is that it scrolls before the text is output. That's because, in the application it lives, that there's a [mumble telemetry:"\n"]; method call after any strings it outputs. So, the scrolling goes before so it doesn't scroll to a blank line. A more reasonable thing may be to scroll at the end, and make the callers output the \n before a new string instead of after. I wanted line breaking at the end of the physical line, ignoring word boundaries. If breaking at the nearest convenient word boundary is what you want, remove the invocations to setNoWrap and setCharWrap:. I used replaceSel: as an "append string to text" method, taking advantage of the fact that no text can be selected in this window so by default it'll just dump where the cursor is...at the end. /* Send a string to the telemetry window * Accepts: string * * This is not a very pretty function. I hope someone can tell me a better * way to do do this. */ - telemetry:(char *)string { NXRect rect; /* get the current bounds of this view */ [telemetryView getBounds:&rect]; /* make a rectangle of the bottommost line */ rect.origin.y = rect.size.height; /* make sure that line can be seen */ [telemetryView scrollRectToVisible:&rect]; [telemetryView setNoWrap]; /* kill all wrapping */ /* wrap by characters */ [telemetryView setCharWrap:YES]; /* blat the string */ [telemetryView replaceSel:string]; return self; } -------- Mark Crispin / P.O. Box 2652 / Seattle, WA 98111-2652 / (206) 842-2385 mrc@Tomobiki-Cho.CAC.Washington.EDU / MRC@WSMR-SIMTEL20.Army.Mil 250cc Rebel pilot -- I just wind it up and it goes! kisha no kisha ga kisha de kisha-shita...tabesaserarenakerebanaranakattarashii