1 /******************************************************************************* 2 * * 3 * textBuf.h -- Nirvana Editor Text Buffer Header File * 4 * * 5 * Copyright 2003 The NEdit Developers * 6 * * 7 * This is free software; you can redistribute it and/or modify it under the * 8 * terms of the GNU General Public License as published by the Free Software * 9 * Foundation; either version 2 of the License, or (at your option) any later * 10 * version. In addition, you may distribute versions of this program linked to * 11 * Motif or Open Motif. See README for details. * 12 * * 13 * This software is distributed in the hope that it will be useful, but WITHOUT * 14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * 15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * 16 * more details. * 17 * * 18 * You should have received a copy of the GNU General Public License along with * 19 * software; if not, write to the Free Software Foundation, Inc., 59 Temple * 20 * Place, Suite 330, Boston, MA 02111-1307 USA * 21 * * 22 * Nirvana Text Editor * 23 * July 31, 2001 * 24 * * 25 *******************************************************************************/ 26 27 #ifndef NEDIT_TEXTBUF_H_INCLUDED 28 #define NEDIT_TEXTBUF_H_INCLUDED 29 30 /* Maximum length in characters of a tab or control character expansion 31 of a single buffer character */ 32 #define MAX_EXP_CHAR_LEN 20 33 34 typedef struct _RangesetTable RangesetTable; 35 36 typedef struct { 37 char selected; /* True if the selection is active */ 38 char rectangular; /* True if the selection is rectangular */ 39 char zeroWidth; /* Width 0 selections aren't "real" selections, but 40 they can be useful when creating rectangular 41 selections from the keyboard. */ 42 int start; /* Pos. of start of selection, or if rectangular 43 start of line containing it. */ 44 int end; /* Pos. of end of selection, or if rectangular 45 end of line containing it. */ 46 int rectStart; /* Indent of left edge of rect. selection */ 47 int rectEnd; /* Indent of right edge of rect. selection */ 48 } selection; 49 50 typedef void (*bufModifyCallbackProc)(int pos, int nInserted, int nDeleted, 51 int nRestyled, const char *deletedText, void *cbArg); 52 typedef void (*bufPreDeleteCallbackProc)(int pos, int nDeleted, void *cbArg); 53 54 typedef struct _textBuffer { 55 int length; /* length of the text in the buffer (the length 56 of the buffer itself must be calculated: 57 gapEnd - gapStart + length) */ 58 char *buf; /* allocated memory where the text is stored */ 59 int gapStart; /* points to the first character of the gap */ 60 int gapEnd; /* points to the first char after the gap */ 61 selection primary; /* highlighted areas */ 62 selection secondary; 63 selection highlight; 64 int tabDist; /* equiv. number of characters in a tab */ 65 int useTabs; /* True if buffer routines are allowed to use 66 tabs for padding in rectangular operations */ 67 int nModifyProcs; /* number of modify-redisplay procs attached */ 68 bufModifyCallbackProc /* procedures to call when buffer is */ 69 *modifyProcs; /* modified to redisplay contents */ 70 void **cbArgs; /* caller arguments for modifyProcs above */ 71 int nPreDeleteProcs; /* number of pre-delete procs attached */ 72 bufPreDeleteCallbackProc /* procedure to call before text is deleted */ 73 *preDeleteProcs; /* from the buffer; at most one is supported. */ 74 void **preDeleteCbArgs; /* caller argument for pre-delete proc above */ 75 int cursorPosHint; /* hint for reasonable cursor position after 76 a buffer modification operation */ 77 char nullSubsChar; /* NEdit is based on C null-terminated strings, 78 so ascii-nul characters must be substituted 79 with something else. This is the else, but 80 of course, things get quite messy when you 81 use it */ 82 RangesetTable *rangesetTable; 83 /* current range sets */ 84 } textBuffer; 85 86 textBuffer *BufCreate(void); 87 textBuffer *BufCreatePreallocated(int requestedSize); 88 void BufFree(textBuffer *buf); 89 char *BufGetAll(textBuffer *buf); 90 const char *BufAsString(textBuffer *buf); 91 void BufSetAll(textBuffer *buf, const char *text); 92 char* BufGetRange(const textBuffer* buf, int start, int end); 93 char BufGetCharacter(const textBuffer* buf, int pos); 94 char *BufGetTextInRect(textBuffer *buf, int start, int end, 95 int rectStart, int rectEnd); 96 void BufInsert(textBuffer *buf, int pos, const char *text); 97 void BufRemove(textBuffer *buf, int start, int end); 98 void BufReplace(textBuffer *buf, int start, int end, const char *text); 99 void BufCopyFromBuf(textBuffer *fromBuf, textBuffer *toBuf, int fromStart, 100 int fromEnd, int toPos); 101 void BufInsertCol(textBuffer *buf, int column, int startPos, const char *text, 102 int *charsInserted, int *charsDeleted); 103 void BufReplaceRect(textBuffer *buf, int start, int end, int rectStart, 104 int rectEnd, const char *text); 105 void BufRemoveRect(textBuffer *buf, int start, int end, int rectStart, 106 int rectEnd); 107 void BufOverlayRect(textBuffer *buf, int startPos, int rectStart, 108 int rectEnd, const char *text, int *charsInserted, int *charsDeleted); 109 void BufClearRect(textBuffer *buf, int start, int end, int rectStart, 110 int rectEnd); 111 int BufGetTabDistance(textBuffer *buf); 112 void BufSetTabDistance(textBuffer *buf, int tabDist); 113 void BufCheckDisplay(textBuffer *buf, int start, int end); 114 void BufSelect(textBuffer *buf, int start, int end); 115 void BufUnselect(textBuffer *buf); 116 void BufRectSelect(textBuffer *buf, int start, int end, int rectStart, 117 int rectEnd); 118 int BufGetSelectionPos(textBuffer *buf, int *start, int *end, 119 int *isRect, int *rectStart, int *rectEnd); 120 int BufGetEmptySelectionPos(textBuffer *buf, int *start, int *end, 121 int *isRect, int *rectStart, int *rectEnd); 122 char *BufGetSelectionText(textBuffer *buf); 123 void BufRemoveSelected(textBuffer *buf); 124 void BufReplaceSelected(textBuffer *buf, const char *text); 125 void BufSecondarySelect(textBuffer *buf, int start, int end); 126 void BufSecondaryUnselect(textBuffer *buf); 127 void BufSecRectSelect(textBuffer *buf, int start, int end, 128 int rectStart, int rectEnd); 129 int BufGetSecSelectPos(textBuffer *buf, int *start, int *end, 130 int *isRect, int *rectStart, int *rectEnd); 131 char *BufGetSecSelectText(textBuffer *buf); 132 void BufRemoveSecSelect(textBuffer *buf); 133 void BufReplaceSecSelect(textBuffer *buf, const char *text); 134 void BufHighlight(textBuffer *buf, int start, int end); 135 void BufUnhighlight(textBuffer *buf); 136 void BufRectHighlight(textBuffer *buf, int start, int end, 137 int rectStart, int rectEnd); 138 int BufGetHighlightPos(textBuffer *buf, int *start, int *end, 139 int *isRect, int *rectStart, int *rectEnd); 140 void BufAddModifyCB(textBuffer *buf, bufModifyCallbackProc bufModifiedCB, 141 void *cbArg); 142 void BufAddHighPriorityModifyCB(textBuffer *buf, bufModifyCallbackProc bufModifiedCB, 143 void *cbArg); 144 void BufRemoveModifyCB(textBuffer *buf, bufModifyCallbackProc bufModifiedCB, 145 void *cbArg); 146 void BufAddPreDeleteCB(textBuffer *buf, bufPreDeleteCallbackProc bufPreDeleteCB, 147 void *cbArg); 148 void BufRemovePreDeleteCB(textBuffer *buf, bufPreDeleteCallbackProc 149 bufPreDeleteCB, void *cbArg); 150 int BufStartOfLine(textBuffer *buf, int pos); 151 int BufEndOfLine(textBuffer *buf, int pos); 152 int BufGetExpandedChar(const textBuffer* buf, int pos, int indent, 153 char* outStr); 154 int BufExpandCharacter(char c, int indent, char *outStr, int tabDist, 155 char nullSubsChar); 156 int BufCharWidth(char c, int indent, int tabDist, char nullSubsChar); 157 int BufCountDispChars(const textBuffer* buf, int lineStartPos, 158 int targetPos); 159 int BufCountForwardDispChars(textBuffer *buf, int lineStartPos, int nChars); 160 int BufCountLines(textBuffer *buf, int startPos, int endPos); 161 int BufCountForwardNLines(const textBuffer* buf, int startPos, 162 unsigned nLines); 163 int BufCountBackwardNLines(textBuffer *buf, int startPos, int nLines); 164 int BufSearchForward(textBuffer *buf, int startPos, const char *searchChars, 165 int *foundPos); 166 int BufSearchBackward(textBuffer *buf, int startPos, const char *searchChars, 167 int *foundPos); 168 int BufSubstituteNullChars(char *string, int length, textBuffer *buf); 169 void BufUnsubstituteNullChars(char *string, textBuffer *buf); 170 int BufCmp(textBuffer * buf, int pos, int len, const char *cmpText); 171 172 #endif /* NEDIT_TEXTBUF_H_INCLUDED */ 173