home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / src / out-of-phase-102-c / OutOfPhase 1.02 Source / OutOfPhase Folder / Level 1 Extensions 29Sep94 / TextEdit.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-23  |  11.1 KB  |  284 lines  |  [TEXT/KAHL]

  1. /* TextEdit.h */
  2.  
  3. #ifndef Included_TextEdit_h
  4. #define Included_TextEdit_h
  5.  
  6. /* TextEdit module depends on */
  7. /* MiscInfo.h */
  8. /* Audit */
  9. /* Debug */
  10. /* Definitions */
  11. /* Memory */
  12. /* Scroll */
  13. /* TextView */
  14. /* EventLoop */
  15. /* Scrap */
  16. /* TextStorage */
  17. /* DataMunging */
  18. /* EventLoop */
  19.  
  20. #include "Screen.h"
  21. #include "EventLoop.h"
  22.  
  23. struct TextEditRec;
  24. typedef struct TextEditRec TextEditRec;
  25.  
  26. /* to avoid dragging Files in */
  27. struct FileType;
  28.  
  29. /* what kind of scrolling should be supported by our text editing object */
  30. typedef enum {eTENoScrollBars = 0, eTEVScrollBar = 1, eTEHScrollBar = 2} TEScrollType;
  31.  
  32. /* for selecting ranges of text */
  33. typedef struct
  34.     {
  35.         long                Line;
  36.         long                Column;
  37.     } SelRec;
  38.  
  39. /* create a new, empty text edit */
  40. TextEditRec*            NewTextEdit(WinType* Window, TEScrollType ScrollStuff,
  41.                                         FontType FontID, FontSizeType FontSize, OrdType X, OrdType Y,
  42.                                         OrdType Width, OrdType Height);
  43.  
  44. /* dispose text edit and all text it contains */
  45. void                            DisposeTextEdit(TextEditRec* Edit);
  46.  
  47.  
  48. /* get location of text edit */
  49. OrdType                        GetTextEditXLoc(TextEditRec* Edit);
  50. OrdType                        GetTextEditYLoc(TextEditRec* Edit);
  51. OrdType                        GetTextEditWidth(TextEditRec* Edit);
  52. OrdType                        GetTextEditHeight(TextEditRec* Edit);
  53.  
  54. /* get font stuff for text edit */
  55. FontType                    GetTextEditFont(TextEditRec* Edit);
  56. FontSizeType            GetTextEditPointSize(TextEditRec* Edit);
  57.  
  58. /* get the number of spaces per tab character */
  59. long                            GetTextEditSpacesPerTab(TextEditRec* Edit);
  60.  
  61. /* get the index of the top line in the window */
  62. long                            GetTextEditTopLine(TextEditRec* Edit);
  63.  
  64. /* get the pixel index of the leftmost text of the text box */
  65. OrdType                        GetTextEditPixelIndent(TextEditRec* Edit);
  66.  
  67. /* returns True if the selection is non-empty, or false if it's an insertion point */
  68. MyBoolean                    TextEditIsThereValidSelection(TextEditRec* Edit);
  69.  
  70. /* get the line number of the start of the selection */
  71. long                            GetTextEditSelectStartLine(TextEditRec* Edit);
  72.  
  73. /* get the line number of the end of the selection */
  74. long                            GetTextEditSelectEndLine(TextEditRec* Edit);
  75.  
  76. /* get the character index of the start of the selection */
  77. long                            GetTextEditSelectStartChar(TextEditRec* Edit);
  78.  
  79. /* get the character index of the character immediately after the end of the */
  80. /* selection.  (if this == start char and startline == endline, then there is no */
  81. /* space between them and therefore there is no selection */
  82. long                            GetTextEditSelectEndCharPlusOne(TextEditRec* Edit);
  83.  
  84. /* find out if selection & scrollbar display is enabled */
  85. MyBoolean                    TextEditIsShowSelectionEnabled(TextEditRec* Edit);
  86.  
  87. /* find out if the data has been modified since the last call to TextEditHasBeenSaved */
  88. MyBoolean                    TextEditDoesItNeedToBeSaved(TextEditRec* Edit);
  89.  
  90. /* get the total number of lines contained in the edit */
  91. long                            GetTextEditNumLines(TextEditRec* Edit);
  92.  
  93. /* find out if auto-indent upon newline is enabled */
  94. MyBoolean                    TextEditIsAutoIndentEnabled(TextEditRec* Edit);
  95.  
  96. /* find out if it is possible to undo the last operation (for enabling menu item) */
  97. MyBoolean                    TextEditCanWeUndo(TextEditRec* Edit);
  98.  
  99.  
  100. /* change the screen location of the text edit box */
  101. void                            SetTextEditPosition(TextEditRec* Edit, OrdType X, OrdType Y,
  102.                                         OrdType Width, OrdType Height);
  103.  
  104. /* change the font being used to display the text */
  105. void                            SetTextEditFontStuff(TextEditRec* Edit, FontType Font,
  106.                                         FontSizeType Size);
  107.  
  108. /* set the number of spaces displayed for a tab */
  109. void                            SetTextEditTabSize(TextEditRec* Edit, long SpacesPerTab);
  110.  
  111. /* change the top line being displayed in the exit box */
  112. void                            SetTextEditTopLine(TextEditRec* Edit, long NewTopLine);
  113.  
  114. /* change the pixel index of the left edge of the text box */
  115. void                            SetTextEditPixelIndent(TextEditRec* Edit, OrdType NewPixelIndent);
  116.  
  117. /* set the selection to a specified range */
  118. void                            SetTextEditSelection(TextEditRec* Edit, long StartLine,
  119.                                         long StartChar, long EndLine, long EndCharPlusOne);
  120.  
  121. /* set the selection to an insertion point at the specified position */
  122. void                            SetTextEditInsertionPoint(TextEditRec* Edit, long Line, long Char);
  123.  
  124. /* enable display of selection and scrollbars */
  125. void                            EnableTextEditSelection(TextEditRec* Edit);
  126.  
  127. /* disable display of selection and scrollbars */
  128. void                            DisableTextEditSelection(TextEditRec* Edit);
  129.  
  130. /* indicate that any data in the text edit has been saved.  After this call, */
  131. /* TextEditDoesItNeedToBeSaved will return False.  It will start returning true */
  132. /* if any subsequent changes are made. */
  133. void                            TextEditHasBeenSaved(TextEditRec* Edit);
  134.  
  135. /* enable or disable auto-indent on carriage return */
  136. void                            SetTextEditAutoIndent(TextEditRec* Edit, MyBoolean AutoIndentFlag);
  137.  
  138.  
  139. /* recalculate the position index of the vertical scrollbar */
  140. void                            TextEditRecalcVerticalScroll(TextEditRec* Edit);
  141.  
  142. /* recalculate the position index of the horizontal scrollbar */
  143. void                            TextEditRecalcHorizontalScroll(TextEditRec* Edit);
  144.  
  145. /* redraw the entire text edit box */
  146. void                            TextEditFullRedraw(TextEditRec* Edit);
  147.  
  148. /* redraw the outline frame of the text edit box */
  149. void                            TextEditRedrawFrame(TextEditRec* Edit);
  150.  
  151. /* update cursor.  This should be called during idle events.  It keeps track of */
  152. /* when the cursor was last blinked and blinks the cursor again if necessary. */
  153. void                            TextEditUpdateCursor(TextEditRec* Edit);
  154.  
  155.  
  156. /* get the specified line of text from the exit */
  157. char*                            GetTextEditLine(TextEditRec* Edit, long LineIndex);
  158.  
  159. /* get a line of text, but first convert all tabs in the line into the */
  160. /* proper number of spaces. */
  161. char*                            GetTextEditSpaceFromTabLine(TextEditRec* Edit, long LineIndex);
  162.  
  163. /* put a new line in the text box.  This overwrites data already on that line */
  164. MyBoolean                    SetTextEditLine(TextEditRec* Edit, long LineIndex, char* LineToCopy);
  165.  
  166. /* use the LineFeed string to create a single block of text containing all */
  167. /* of the lines packed into it */
  168. char*                            TextEditGetRawData(TextEditRec* Edit, char* LineFeed);
  169.  
  170. /* put new data into the text edit.  The RawData is a block with all text lines */
  171. /* packed into it separated by the LineFeed string. */
  172. MyBoolean                    TextEditNewRawData(TextEditRec* Edit, char* RawData, char* LineFeed);
  173.  
  174. /* get a text block containing the selected data */
  175. char*                            TextEditGetSelection(TextEditRec* Edit);
  176.  
  177. /* replace the current selection (if any) with the specified raw data block. */
  178. /* if this fails, some of the data may have been inserted */
  179. MyBoolean                    TextEditInsertRawData(TextEditRec* Edit, char* RawData, char* LineFeed);
  180.  
  181.  
  182. /* find the union of two selection ranges */
  183. void                            UnionSelection(SelRec One, SelRec Two, SelRec Three,
  184.                                         SelRec* Start, SelRec* End);
  185.  
  186. /* find the difference (union - intersection) of two selection ranges.  This is */
  187. /* used to avoid redrawing the entire selection range all the time */
  188. void                            DiffSelection(SelRec OneStart, SelRec OneEnd, SelRec TwoStart,
  189.                                         SelRec TwoEnd, SelRec* OutStart, SelRec* OutEnd);
  190.  
  191. /* if the first selection point is after the second then reverse their order */
  192. void                            SortSelection(SelRec* One, SelRec* Two);
  193.  
  194. /* returns True if the first selection point is after the second one */
  195. MyBoolean                    GreaterThan(SelRec* One, SelRec* Two);
  196.  
  197. /* extend the selection using the current mouse-click state (single, double, triple) */
  198. void                            ExtendSelection(TextEditRec* Edit, SelRec* Start, SelRec* End);
  199.  
  200. /* find out if the character is an alphanumeric character.  this is used by */
  201. /* ExtendSelection for figuring out where double-click extends should stop. */
  202. MyBoolean                    AlphaNum(char It);
  203.  
  204. /* append a line of text to the end of the text edit.  This can be used if the */
  205. /* text edit box is being used as an interaction (terminal) window */
  206. /* if NIL is passed in for Data, a blank line will be appended */
  207. MyBoolean                    TextEditAppendLineInteraction(TextEditRec* Edit, char* Data);
  208.  
  209. /* dump the data contained in the text edit to the current position in the */
  210. /* specified file.  returns True if all the data was written successfully */
  211. MyBoolean                    TestEditWriteDataToFile(TextEditRec* Edit,
  212.                                         struct FileType* FileRefNum, char* EOLN);
  213.  
  214.  
  215. /* cut the selected data to the clipboard.  if this fails, some of the data */
  216. /* may have been deleted */
  217. MyBoolean                    TextEditDoMenuCut(TextEditRec* Edit);
  218.  
  219. /* copy the selected data to the clipboard. */
  220. MyBoolean                    TextEditDoMenuCopy(TextEditRec* Edit);
  221.  
  222. /* paste the clipboard in, replacing the current selection if there is one */
  223. /* if this fails, some of the data may have been inserted */
  224. MyBoolean                    TextEditDoMenuPaste(TextEditRec* Edit);
  225.  
  226. /* select the entire data area of the text edit */
  227. void                            TextEditDoMenuSelectAll(TextEditRec* Edit);
  228.  
  229. /* delete the selected area.  This is the same as pressing the delete key */
  230. /* when there is a valid selection.  if this fails, some of the data may */
  231. /* have been deleted */
  232. MyBoolean                    TextEditDoMenuClear(TextEditRec* Edit);
  233.  
  234. /* shift the selection toward the left margin by deleting one tab (or spaces) */
  235. /* from the beginning of the line.  It will not remove non-whitespace characters */
  236. /* if this fails, some of the lines may have been shifted */
  237. MyBoolean                    TextEditShiftSelectionLeftOneTab(TextEditRec* Edit);
  238.  
  239. /* shift selection toward the right margin by inserting a tab at the */
  240. /* beginning of each line.  if this fails, some of the lines may have been shifted. */
  241. MyBoolean                    TextEditShiftSelectionRightOneTab(TextEditRec* Edit);
  242.  
  243. /* convert all tab characters in the text box to the appropriate number of spaces */
  244. /* if this fails, some of the lines may have been converted. */
  245. MyBoolean                    TextEditConvertTabsToSpaces(TextEditRec* Edit);
  246.  
  247. /* show the current selection in the edit window */
  248. void                            TextEditShowSelection(TextEditRec* Edit);
  249.  
  250. /* show the starting edge of the selection. */
  251. void                            TextEditShowSelectionStartEdge(TextEditRec* Edit);
  252.  
  253. /* show the ending edge of the selection. */
  254. void                            TextEditShowSelectionEndEdge(TextEditRec* Edit);
  255.  
  256. /* handle a keypress for inserting or deleting into the text box */
  257. void                            TextEditDoKeyPressed(TextEditRec* Edit, char TheKey,
  258.                                         ModifierFlags Modifiers);
  259.  
  260. /* handle a mouse-down in the text box */
  261. void                            TextEditDoMouseDown(TextEditRec* Edit, OrdType OrigX, OrdType OrigY,
  262.                                         ModifierFlags Modifiers);
  263.  
  264. /* undo the last operation that changed the contained data.  not all operations */
  265. /* can be undone.  Who knows what the state of things will be if this fails. */
  266. MyBoolean                    TextEditDoMenuUndo(TextEditRec* Edit);
  267.  
  268. /* extend the current selection to show balanced parentheses, or beep if */
  269. /* the parentheses are not balanced */
  270. void                            TextEditBalanceParens(TextEditRec* Edit);
  271.  
  272. /* find the specified search string starting at the current selection. */
  273. MyBoolean                    TextEditFindAgain(TextEditRec* Edit, char* SearchString);
  274.  
  275. /* see if the specified location is in the text edit box */
  276. MyBoolean                    TextEditHitTest(TextEditRec* Edit, OrdType X, OrdType Y);
  277.  
  278. /* see if the specified location is in the text edit area of the box (not the */
  279. /* scrollbars).  This is used for deciding whether the mouse should be an Ibeam */
  280. /* or an arrow. */
  281. MyBoolean                    TextEditIBeamTest(TextEditRec* Edit, OrdType X, OrdType Y);
  282.  
  283. #endif
  284.