🚀 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 Todd Enders Wed, 04 Nov 1992 04:10
"Best" way to append text in a ScrollView
#132
Author: Todd Enders
Date: Wed, 04 Nov 1992 04:10
18 lines
1244 bytes
     This has probably been asked a lot, but humour me...

     I'm trying to put some text into a ScrollView, in the following fashion:

     [text_out setText:"foo!\n"];
     ...
     ** now I want to append some more text **

     The $64 question is what is the "best" way to do this?  I can't really
see a way short of sucking the existing text into a string and strcat()-ing
the new text on the end.  I fooled around with setSel::, but the new text
always overwrites the old.  I'm sure there's an easy/elegant way to do this, 
but I haven't seen it in any of the examples.  *HELP*!!!

Todd     enders@bolshoi.uucp     NeXTMail Welcome!!!
         uunet!bolshoi!enders
         enders@bolshoi.cc.misu.nodak.edu
Re: "Best" way to append text in a ScrollView
#138
Author: 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=-
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