home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1995 August / NEBULA.bin / SourceCode / Classes / SampleClasses / ScrollText.h < prev    next >
Encoding:
Text File  |  1992-08-04  |  5.2 KB  |  129 lines

  1. // -------------------------------------------------------------------------------------
  2. // ScrollText.h
  3. // Author: Martin D. Flynn, NeXT Computer, Inc.
  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          1024    // actual size cannot be known
  40.  
  41. // --------------------------------------------------------------------------------
  42. // method name synonyms
  43. #define         setAutoLF               setAutoLineFeed
  44.  
  45. // -------------------------------------------------------------------------------------
  46. // structures used internal to ScrollText
  47.  
  48. /* text attributes */
  49. typedef struct textAttr_s {
  50.     id                  fontId;
  51.     int                 colorMode;      // 0=none, 1=gray, 2=color
  52.     NXColor             color;          // contains only gray if mode=1
  53. } textAttr_t;
  54.  
  55. // scroll text data queue
  56. typedef struct textQueue_s {
  57.     char                *record;
  58.     textAttr_t          attr;
  59.     void                *next;
  60. } textQueue_t;
  61.  
  62. // --------------------------------------------------------------------------------
  63. @interface ScrollText : Object
  64. {
  65.  
  66.     id                  scrollView;
  67.     id                  textView;
  68.     
  69.     textAttr_t          runAttr;                    // newly added text attributes
  70.   
  71.     BOOL                autoLf;                     // auto linefeed mode
  72.   
  73.     mutex_t             queueMutex;                 // text queue mutex
  74.     textQueue_t         *queueData;                 // pointer to front of queue
  75.     textQueue_t         *queueBack;                 // pointer to end of queue
  76.  
  77. }
  78.  
  79. // --------------------------------------------------------------------------------
  80. + newScrollText:anObject;
  81. //  Creates a new ScrollText object to handle text scrolling.  anObject must be
  82. //  a ScrollView object which has a Text content view.  This is compatible
  83. //  with the outlet provided by the text scroll view object in Interface Builder.
  84. //
  85. // --------------------------------------------------------------------------------
  86. - setAutoLineFeed:(BOOL)mode;
  87. //  Sets the autoLineFeed options.  If set to YES, then a newLine will be sent
  88. //  after each string written to the scroll text.  The default is NO. 
  89. //
  90. // --------------------------------------------------------------------------------
  91. - docView;
  92. //  Returns the ScrollView docView.
  93. //
  94. // --------------------------------------------------------------------------------
  95. - scrollView;
  96. //  Returns the ScrollView id.
  97. //
  98. // --------------------------------------------------------------------------------
  99. - setTextAttributeFont:fontId;
  100. - setTextAttributeGray:(float)aGray;
  101. - setTextAttributeColor:(NXColor)aColor;
  102. //  Set RTF font/gray run attributes for newly added text.
  103. //
  104. // --------------------------------------------------------------------------------
  105. - clearScrollText;
  106. //  This clears the contents of the Text ScrollView.  Returns self.
  107. //
  108. // --------------------------------------------------------------------------------
  109. - deleteLinesFrom:(int)fLine to:(int)tLine;
  110. //  This deletes the specified lines from the Text ScrollView. 
  111. //
  112. // --------------------------------------------------------------------------------
  113. - (int)textLines;
  114. //  Returns the current number of lines present in the Text object.
  115. //
  116. // --------------------------------------------------------------------------------
  117. - print:sender;
  118. //  Prints the contents of the ScrollView to the printer.
  119. //
  120. // --------------------------------------------------------------------------------
  121. - (int)textPrintf:(const char*)fmt args:(va_list)args;
  122. - (int)textPrintf:(const char*)fmt, ...;
  123. int textPrintf(id textView, const char *fmt, ...);
  124. //  Appends the specified formated string to the contents of the ScrollView.
  125. //
  126. // --------------------------------------------------------------------------------
  127.  
  128. @end
  129.