home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / NeXT-Icons / next-icon@gun.com / Apps / ImagePortfolio / apputils.subproj / ScrollText.h < prev    next >
Encoding:
Text File  |  1993-06-03  |  7.4 KB  |  179 lines

  1. // -------------------------------------------------------------------------------------
  2. // ScrollText.h
  3. // Author: Martin D. Flynn
  4. // Description:
  5. // This class provide a full-featured set of utilities to handle printing to a Text
  6. // object within a ScrollView.  This includes the ability to change the text font and 
  7. // color of the text printed to the Text object.  This class will also handle text sent
  8. // to it from any secondary thread.  It will automatically send the data to be printed 
  9. // to the main thread to be printed into the Text object (only if objectThreadPerform
  10. // is compiled with the application).
  11. // -------------------------------------------------------------------------------------
  12. // Permission is granted to freely redistribute this source code, and to use fragments
  13. // of this code in your own applications if you find them to be useful.  This class,
  14. // along with the source code, come with no warranty of any kind, and the user assumes
  15. // all responsibility for its use.
  16. // -------------------------------------------------------------------------------------
  17. // example:
  18. //
  19. //   /* scrollview outlet */
  20. //   - setMyScrollView:anObject
  21. //     {
  22. //     myTextView = [ScrollText newScrollText:anObject];
  23. //     [myTextView setAutoLineFeed:NO]; // default
  24. //     return self;
  25. //     }
  26. //
  27. //   /* display formatted error message */
  28. //   - displayError:(char *)textError
  29. //     {
  30. //     textPrintf(myTextView, "ERROR: %s\n", textError);
  31. //     return self;
  32. //     }
  33. //
  34. // -------------------------------------------------------------------------------------
  35. #import <objc/Object.h>
  36.  
  37. // --------------------------------------------------------------------------------
  38. // formatted text size limit for 'textPrintf'
  39. #define         textStringSIZE          4096    // actual size cannot be known
  40.  
  41. // --------------------------------------------------------------------------------
  42. // method name synonyms
  43. #define         setAutoLF               setAutoLineFeed
  44.  
  45. // --------------------------------------------------------------------------------
  46. // errors passed by 'commandDidComplete:withError:' via 'runCommand:...'
  47. // Note: these codes may be shared by the running command which executes an exit(#)
  48. #define            RUNCMD_STOPPED            -1        // command stopped/aborted
  49. #define            RUNCMD_SUCCESS            0        // executed/completed successfully
  50. #define            RUNCMD_EXEC                255        // cannot execute execl shell
  51.  
  52. // -------------------------------------------------------------------------------------
  53. // structures used internal to ScrollText
  54.  
  55. /* text attributes */
  56. typedef struct textAttr_s {
  57.     id                    fontId;
  58.     int                    colorMode;        // 0=none, 1=gray, 2=color
  59.     NXColor                color;            // contains only gray if mode=1
  60. } textAttr_t;
  61.  
  62. // scroll text data queue
  63. typedef struct textQueue_s {
  64.     char                  *record;
  65.     textAttr_t            attr;
  66.     void                  *next;
  67. } textQueue_t;
  68.  
  69. // -------------------------------------------------------------------------------------
  70. // RunServer support
  71. @protocol RemoteClient        // sent by server to client
  72. - (oneway void)commandOutput:(const char*)buffer len:(int)length;
  73. - (oneway void)commandDidCompleteWithError:(int)errorCode;
  74. @end
  75.  
  76. // --------------------------------------------------------------------------------
  77. @interface ScrollText : Object <RemoteClient>
  78. {
  79.  
  80.     id                    delegate;                    // delegate for RunServer support
  81.  
  82.     id                    scrollView;                    // scroll view object
  83.     id                    textView;                    // text view object
  84.     
  85.     textAttr_t            runAttr;                    // newly added text attributes
  86.   
  87.     BOOL                wasEditable;                // scrollView was editable
  88.     BOOL                autoLf;                        // auto linefeed mode
  89.   
  90.     mutex_t                queueMutex;                    // text queue mutex
  91.     textQueue_t            *queueData;                    // pointer to front of queue
  92.     textQueue_t            *queueBack;                    // pointer to end of queue
  93.  
  94.     int                    cmdChild;                    // command execution
  95.     int                    inputDescriptor;            // input pipe
  96.  
  97. }
  98.  
  99. // --------------------------------------------------------------------------------
  100. + newScrollText:anObject;
  101. //  Creates a new ScrollText object to handle text scrolling.  anObject must be
  102. //  a ScrollView object which has a Text content view.  This is compatible
  103. //  with the outlet provided by the text scroll view object in Interface Builder.
  104. //
  105. // --------------------------------------------------------------------------------
  106. - setDelegate:aDelegate;
  107. //  Currently used for RunServer support.  Returns self.
  108. //
  109. // --------------------------------------------------------------------------------
  110. - setAutoLineFeed:(BOOL)mode;
  111. //  Sets the autoLineFeed options.  If set to YES, then a newLine will be sent
  112. //  after each string written to the scroll text.  The default is NO. 
  113. //
  114. // --------------------------------------------------------------------------------
  115. - docView;
  116. //  Returns the ScrollView docView.
  117. //
  118. // --------------------------------------------------------------------------------
  119. - scrollView;
  120. //  Returns the ScrollView id.
  121. //
  122. // --------------------------------------------------------------------------------
  123. - setTextAttributeFont:fontId;
  124. - setTextAttributeGray:(float)aGray;
  125. - setTextAttributeColor:(NXColor)aColor;
  126. //  Set RTF font/gray run attributes for newly added text.
  127. //
  128. // --------------------------------------------------------------------------------
  129. - setTabStops:(float*)tabArray count:(int)c;
  130. - setTab:(float)tabSize count:(int)c;
  131. //  Set default tabs stops.  'setTabStops:count:' set the default tabs to those
  132. //  specified in the array 'tabArray'. 'setTab:count:' sets the default tabs to 
  133. //  multiples of 'tabSize'.  Both return self.
  134. //
  135. // --------------------------------------------------------------------------------
  136. - clearScrollText;
  137. //  This clears the contents of the Text ScrollView.  Returns self.
  138. //
  139. // --------------------------------------------------------------------------------
  140. - deleteLinesFrom:(int)fLine to:(int)tLine;
  141. //  This deletes the specified lines from the Text ScrollView. 
  142. //
  143. // --------------------------------------------------------------------------------
  144. - (int)textLines;
  145. //  Returns the current number of lines present in the Text object.
  146. //
  147. // --------------------------------------------------------------------------------
  148. - print:sender;
  149. //  Prints the contents of the ScrollView to the printer.
  150. //
  151. // --------------------------------------------------------------------------------
  152. - enscriptPrint:(char*)title option:(char*)option printPanel:(BOOL)prtPnl;
  153. //  Prints the contents of the ScrollView to the printer using unix command enscript.
  154. //
  155. // --------------------------------------------------------------------------------
  156. - (int)textPrint:(const char*)buffer;
  157. - (int)textPrintf:(const char*)fmt args:(va_list)args;
  158. - (int)textPrintf:(const char*)fmt, ...;
  159. int textPrintf(id textView, const char *fmt, ...);
  160. //  Appends the specified formated string to the contents of the ScrollView.
  161. //
  162. // --------------------------------------------------------------------------------
  163. - runCommand:(const char*)command withPath:(const char*)cmdPath;
  164. - runCommand:(const char*)command;
  165. - terminateCommand;
  166. - killCommand;
  167. //  Allows running a command shell and using the scrollable text view to place the
  168. //  output.  The delegate is sent the message commandDidComplete:withError: when
  169. //  the command has completed execution.
  170. //
  171. // --------------------------------------------------------------------------------
  172. - (void)commandOutput:(const char*)buffer len:(int)len;
  173. - (void)commandDidCompleteWithError:(int)errorCode;
  174. //  Provides support for RunServer.
  175. //
  176. // --------------------------------------------------------------------------------
  177.  
  178. @end
  179.