This is ScrollText.h in view mode; [Download] [Up]
// ------------------------------------------------------------------------------------- // ScrollText.h // Author: Martin D. Flynn // Description: // This class provide a full-featured set of utilities to handle printing to a Text // object within a ScrollView. This includes the ability to change the text font and // color of the text printed to the Text object. This class will also handle text sent // to it from any secondary thread. It will automatically send the data to be printed // to the main thread to be printed into the Text object (only if objectThreadPerform // is compiled with the application). // ------------------------------------------------------------------------------------- // Permission is granted to freely redistribute this source code, and to use fragments // of this code in your own applications if you find them to be useful. This class, // along with the source code, come with no warranty of any kind, and the user assumes // all responsibility for its use. // ------------------------------------------------------------------------------------- // example: // // /* scrollview outlet */ // - setMyScrollView:anObject // { // myTextView = [ScrollText newScrollText:anObject]; // [myTextView setAutoLineFeed:NO]; // default // return self; // } // // /* display formatted error message */ // - displayError:(char *)textError // { // textPrintf(myTextView, "ERROR: %s\n", textError); // return self; // } // // ------------------------------------------------------------------------------------- #import <objc/Object.h> // -------------------------------------------------------------------------------- // formatted text size limit for 'textPrintf' #define textStringSIZE 4096 // actual size cannot be known // -------------------------------------------------------------------------------- // method name synonyms #define setAutoLF setAutoLineFeed // -------------------------------------------------------------------------------- // errors passed by 'commandDidComplete:withError:' via 'runCommand:...' // Note: these codes may be shared by the running command which executes an exit(#) #define RUNCMD_STOPPED -1 // command stopped/aborted #define RUNCMD_SUCCESS 0 // executed/completed successfully #define RUNCMD_EXEC 255 // cannot execute execl shell // ------------------------------------------------------------------------------------- // structures used internal to ScrollText /* text attributes */ typedef struct textAttr_s { id fontId; int colorMode; // 0=none, 1=gray, 2=color NXColor color; // contains only gray if mode=1 } textAttr_t; // scroll text data queue typedef struct textQueue_s { char *record; textAttr_t attr; void *next; } textQueue_t; // ------------------------------------------------------------------------------------- // RunServer support @protocol RemoteClient // sent by server to client - (oneway void)commandOutput:(const char*)buffer len:(int)length; - (oneway void)commandDidCompleteWithError:(int)errorCode; @end // -------------------------------------------------------------------------------- @interface ScrollText : Object <RemoteClient> { id delegate; // delegate for RunServer support id scrollView; // scroll view object id textView; // text view object textAttr_t runAttr; // newly added text attributes BOOL wasEditable; // scrollView was editable BOOL autoLf; // auto linefeed mode mutex_t queueMutex; // text queue mutex textQueue_t *queueData; // pointer to front of queue textQueue_t *queueBack; // pointer to end of queue int cmdChild; // command execution int inputDescriptor; // input pipe } // -------------------------------------------------------------------------------- + newScrollText:anObject; // Creates a new ScrollText object to handle text scrolling. anObject must be // a ScrollView object which has a Text content view. This is compatible // with the outlet provided by the text scroll view object in Interface Builder. // // -------------------------------------------------------------------------------- - setDelegate:aDelegate; // Currently used for RunServer support. Returns self. // // -------------------------------------------------------------------------------- - setAutoLineFeed:(BOOL)mode; // Sets the autoLineFeed options. If set to YES, then a newLine will be sent // after each string written to the scroll text. The default is NO. // // -------------------------------------------------------------------------------- - docView; // Returns the ScrollView docView. // // -------------------------------------------------------------------------------- - scrollView; // Returns the ScrollView id. // // -------------------------------------------------------------------------------- - setTextAttributeFont:fontId; - setTextAttributeGray:(float)aGray; - setTextAttributeColor:(NXColor)aColor; // Set RTF font/gray run attributes for newly added text. // // -------------------------------------------------------------------------------- - setTabStops:(float*)tabArray count:(int)c; - setTab:(float)tabSize count:(int)c; // Set default tabs stops. 'setTabStops:count:' set the default tabs to those // specified in the array 'tabArray'. 'setTab:count:' sets the default tabs to // multiples of 'tabSize'. Both return self. // // -------------------------------------------------------------------------------- - clearScrollText; // This clears the contents of the Text ScrollView. Returns self. // // -------------------------------------------------------------------------------- - deleteLinesFrom:(int)fLine to:(int)tLine; // This deletes the specified lines from the Text ScrollView. // // -------------------------------------------------------------------------------- - (int)textLines; // Returns the current number of lines present in the Text object. // // -------------------------------------------------------------------------------- - print:sender; // Prints the contents of the ScrollView to the printer. // // -------------------------------------------------------------------------------- - enscriptPrint:(char*)title option:(char*)option printPanel:(BOOL)prtPnl; // Prints the contents of the ScrollView to the printer using unix command enscript. // // -------------------------------------------------------------------------------- - (int)textPrint:(const char*)buffer; - (int)textPrintf:(const char*)fmt args:(va_list)args; - (int)textPrintf:(const char*)fmt, ...; int textPrintf(id textView, const char *fmt, ...); // Appends the specified formated string to the contents of the ScrollView. // // -------------------------------------------------------------------------------- - runCommand:(const char*)command withPath:(const char*)cmdPath; - runCommand:(const char*)command; - terminateCommand; - killCommand; // Allows running a command shell and using the scrollable text view to place the // output. The delegate is sent the message commandDidComplete:withError: when // the command has completed execution. // // -------------------------------------------------------------------------------- - (void)commandOutput:(const char*)buffer len:(int)len; - (void)commandDidCompleteWithError:(int)errorCode; // Provides support for RunServer. // // -------------------------------------------------------------------------------- @end
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.