🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.next.programmer
Article #138

Re: "Best" way to append text in a ScrollView

#138
From: Eric P. Scott
Date: Wed, 04 Nov 1992 10:20
51 lines
1861 bytes
"Best" is a judgment call.  I'll offer one approach--extending
the Text class--but I wouldn't go so far as to call it "best."

[This is for 2.x.  No promises for 3.0.]

// The corressponding interface file should #import <appkit/Text.h>

#import <stdarg.h>
#import <streams/streams.h>

@implementation Text(PutSomethingCuteHere)

// Like setText:, but appends.  I recommend messaging
// scrollSelToVisible to the Text object afterwards, or placing
// one before the return.
- appendText:(const char *)aString
{
    int e;

    if ((e=[self textLength])<=0) [self setText:aString];
    else [[self setSel:e:e] replaceSel:aString];
    return self;
}

// For even more fun, we can build a printf: method upon
// appendText:.  Since all parameters after the format
// string are optional as far as Objective-C is concerned,
// delimit them with commas instead of colons.  Extend
// with NXRegisterPrintfProc() for even more flexibility!
- printf:(const char *)format,...
{
    NXStream *s;
    char *streambuf;
    int len, maxlen;
    va_list ap;

    va_start(ap, format);
    s=NXOpenMemory(NULL,0,NX_WRITEONLY);
    NXVPrintf(s, format, ap);
    (void)NXPutc(s, '\0');
    NXFlush(s);
    NXGetMemoryBuffer(s, &streambuf, &len, &maxlen);
    [self appendText:streambuf];
    NXCloseMemory(s, NX_FREEBUFFER);      
    va_end(ap);
}


@end

					-=EPS=-
Technical Details
Message-ID: <1992Nov4.102029.2957@csus.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!sun-barr!decwrl!csus.edu!news
References: <Bx6BM7.DG4@ns1.nodak.edu>

Show Full Headers
Complete Article Headers
Newsgroups: comp.sys.next.programmer
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!sun-barr!decwrl!csus.edu!news
From: eps@futon.SFSU.EDU (Eric P. Scott)
Subject: Re: "Best" way to append text in a ScrollView
Message-ID: <1992Nov4.102029.2957@csus.edu>
Sender: news@csus.edu
Reply-To: eps@cs.sfsu.edu
Organization: San Francisco State University
References: <Bx6BM7.DG4@ns1.nodak.edu>
Date: Wed, 4 Nov 1992 10:20:29 GMT
Lines: 51