home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 June / MacFormat 25.iso / Shareware City / Developers / OutOfPhase1.1 Source / OutOfPhase Folder / Level 1 Extensions 04Jan95 / TextEdit.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-28  |  11.4 KB  |  290 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. /* replace the current selection (if any) with the specified raw data block. */
  182. /* if this fails, some of the data may have been inserted.  this version sets up */
  183. /* the undo information. */
  184. MyBoolean                    TextEditInsertRawDataWithUndo(TextEditRec* Edit, char* RawData,
  185.                                         char* LineFeed);
  186.  
  187.  
  188. /* find the union of two selection ranges */
  189. void                            UnionSelection(SelRec One, SelRec Two, SelRec Three,
  190.                                         SelRec* Start, SelRec* End);
  191.  
  192. /* find the difference (union - intersection) of two selection ranges.  This is */
  193. /* used to avoid redrawing the entire selection range all the time */
  194. void                            DiffSelection(SelRec OneStart, SelRec OneEnd, SelRec TwoStart,
  195.                                         SelRec TwoEnd, SelRec* OutStart, SelRec* OutEnd);
  196.  
  197. /* if the first selection point is after the second then reverse their order */
  198. void                            SortSelection(SelRec* One, SelRec* Two);
  199.  
  200. /* returns True if the first selection point is after the second one */
  201. MyBoolean                    GreaterThan(SelRec* One, SelRec* Two);
  202.  
  203. /* extend the selection using the current mouse-click state (single, double, triple) */
  204. void                            ExtendSelection(TextEditRec* Edit, SelRec* Start, SelRec* End);
  205.  
  206. /* find out if the character is an alphanumeric character.  this is used by */
  207. /* ExtendSelection for figuring out where double-click extends should stop. */
  208. MyBoolean                    AlphaNum(char It);
  209.  
  210. /* append a line of text to the end of the text edit.  This can be used if the */
  211. /* text edit box is being used as an interaction (terminal) window */
  212. /* if NIL is passed in for Data, a blank line will be appended */
  213. MyBoolean                    TextEditAppendLineInteraction(TextEditRec* Edit, char* Data);
  214.  
  215. /* dump the data contained in the text edit to the current position in the */
  216. /* specified file.  returns True if all the data was written successfully */
  217. MyBoolean                    TestEditWriteDataToFile(TextEditRec* Edit,
  218.                                         struct FileType* FileRefNum, char* EOLN);
  219.  
  220.  
  221. /* cut the selected data to the clipboard.  if this fails, some of the data */
  222. /* may have been deleted */
  223. MyBoolean                    TextEditDoMenuCut(TextEditRec* Edit);
  224.  
  225. /* copy the selected data to the clipboard. */
  226. MyBoolean                    TextEditDoMenuCopy(TextEditRec* Edit);
  227.  
  228. /* paste the clipboard in, replacing the current selection if there is one */
  229. /* if this fails, some of the data may have been inserted */
  230. MyBoolean                    TextEditDoMenuPaste(TextEditRec* Edit);
  231.  
  232. /* select the entire data area of the text edit */
  233. void                            TextEditDoMenuSelectAll(TextEditRec* Edit);
  234.  
  235. /* delete the selected area.  This is the same as pressing the delete key */
  236. /* when there is a valid selection.  if this fails, some of the data may */
  237. /* have been deleted */
  238. MyBoolean                    TextEditDoMenuClear(TextEditRec* Edit);
  239.  
  240. /* shift the selection toward the left margin by deleting one tab (or spaces) */
  241. /* from the beginning of the line.  It will not remove non-whitespace characters */
  242. /* if this fails, some of the lines may have been shifted */
  243. MyBoolean                    TextEditShiftSelectionLeftOneTab(TextEditRec* Edit);
  244.  
  245. /* shift selection toward the right margin by inserting a tab at the */
  246. /* beginning of each line.  if this fails, some of the lines may have been shifted. */
  247. MyBoolean                    TextEditShiftSelectionRightOneTab(TextEditRec* Edit);
  248.  
  249. /* convert all tab characters in the text box to the appropriate number of spaces */
  250. /* if this fails, some of the lines may have been converted. */
  251. MyBoolean                    TextEditConvertTabsToSpaces(TextEditRec* Edit);
  252.  
  253. /* show the current selection in the edit window */
  254. void                            TextEditShowSelection(TextEditRec* Edit);
  255.  
  256. /* show the starting edge of the selection. */
  257. void                            TextEditShowSelectionStartEdge(TextEditRec* Edit);
  258.  
  259. /* show the ending edge of the selection. */
  260. void                            TextEditShowSelectionEndEdge(TextEditRec* Edit);
  261.  
  262. /* handle a keypress for inserting or deleting into the text box */
  263. void                            TextEditDoKeyPressed(TextEditRec* Edit, char TheKey,
  264.                                         ModifierFlags Modifiers);
  265.  
  266. /* handle a mouse-down in the text box */
  267. void                            TextEditDoMouseDown(TextEditRec* Edit, OrdType OrigX, OrdType OrigY,
  268.                                         ModifierFlags Modifiers);
  269.  
  270. /* undo the last operation that changed the contained data.  not all operations */
  271. /* can be undone.  Who knows what the state of things will be if this fails. */
  272. MyBoolean                    TextEditDoMenuUndo(TextEditRec* Edit);
  273.  
  274. /* extend the current selection to show balanced parentheses, or beep if */
  275. /* the parentheses are not balanced */
  276. void                            TextEditBalanceParens(TextEditRec* Edit);
  277.  
  278. /* find the specified search string starting at the current selection. */
  279. MyBoolean                    TextEditFindAgain(TextEditRec* Edit, char* SearchString);
  280.  
  281. /* see if the specified location is in the text edit box */
  282. MyBoolean                    TextEditHitTest(TextEditRec* Edit, OrdType X, OrdType Y);
  283.  
  284. /* see if the specified location is in the text edit area of the box (not the */
  285. /* scrollbars).  This is used for deciding whether the mouse should be an Ibeam */
  286. /* or an arrow. */
  287. MyBoolean                    TextEditIBeamTest(TextEditRec* Edit, OrdType X, OrdType Y);
  288.  
  289. #endif
  290.