- Change help version to 5.4DEV
[nedit.git] / source / textBuf.h
blob2c0eb9581fc1ebed29bb12cf39c218ba995be8f4
1 /* $Id: textBuf.h,v 1.12 2002/10/14 18:41:07 n8gray Exp $ */
3 #ifndef NEDIT_TEXTBUF_H_INCLUDED
4 #define NEDIT_TEXTBUF_H_INCLUDED
6 #include "rangeset.h"
8 /* Maximum length in characters of a tab or control character expansion
9 of a single buffer character */
10 #define MAX_EXP_CHAR_LEN 20
12 typedef struct {
13 char selected; /* True if the selection is active */
14 char rectangular; /* True if the selection is rectangular */
15 char zeroWidth; /* Width 0 selections aren't "real" selections, but
16 they can be useful when creating rectangular
17 selections from the keyboard. */
18 int start; /* Pos. of start of selection, or if rectangular
19 start of line containing it. */
20 int end; /* Pos. of end of selection, or if rectangular
21 end of line containing it. */
22 int rectStart; /* Indent of left edge of rect. selection */
23 int rectEnd; /* Indent of right edge of rect. selection */
24 } selection;
26 typedef void (*bufModifyCallbackProc)(int pos, int nInserted, int nDeleted,
27 int nRestyled, char *deletedText, void *cbArg);
28 typedef void (*bufPreDeleteCallbackProc)(int pos, int nDeleted, void *cbArg);
30 typedef struct _textBuffer {
31 int length; /* length of the text in the buffer (the length
32 of the buffer itself must be calculated:
33 gapEnd - gapStart + length) */
34 char *buf; /* allocated memory where the text is stored */
35 int gapStart; /* points to the first character of the gap */
36 int gapEnd; /* points to the first char after the gap */
37 selection primary; /* highlighted areas */
38 selection secondary;
39 selection highlight;
40 int tabDist; /* equiv. number of characters in a tab */
41 int useTabs; /* True if buffer routines are allowed to use
42 tabs for padding in rectangular operations */
43 int nModifyProcs; /* number of modify-redisplay procs attached */
44 bufModifyCallbackProc /* procedures to call when buffer is */
45 *modifyProcs; /* modified to redisplay contents */
46 void **cbArgs; /* caller arguments for modifyProcs above */
47 int nPreDeleteProcs; /* number of pre-delete procs attached */
48 bufPreDeleteCallbackProc /* procedure to call before text is deleted */
49 *preDeleteProcs; /* from the buffer; at most one is supported. */
50 void **preDeleteCbArgs; /* caller argument for pre-delete proc above */
51 int cursorPosHint; /* hint for reasonable cursor position after
52 a buffer modification operation */
53 char nullSubsChar; /* NEdit is based on C null-terminated strings,
54 so ascii-nul characters must be substituted
55 with something else. This is the else, but
56 of course, things get quite messy when you
57 use it */
58 RangesetTable *rangesetTable;
59 /* current range sets */
60 } textBuffer;
62 textBuffer *BufCreate(void);
63 textBuffer *BufCreatePreallocated(int requestedSize);
64 void BufFree(textBuffer *buf);
65 char *BufGetAll(textBuffer *buf);
66 void BufSetAll(textBuffer *buf, const char *text);
67 char *BufGetRange(textBuffer *buf, int start, int end);
68 char BufGetCharacter(textBuffer *buf, int pos);
69 char *BufGetTextInRect(textBuffer *buf, int start, int end,
70 int rectStart, int rectEnd);
71 void BufInsert(textBuffer *buf, int pos, const char *text);
72 void BufRemove(textBuffer *buf, int start, int end);
73 void BufReplace(textBuffer *buf, int start, int end, const char *text);
74 void BufCopyFromBuf(textBuffer *fromBuf, textBuffer *toBuf, int fromStart,
75 int fromEnd, int toPos);
76 void BufInsertCol(textBuffer *buf, int column, int startPos, const char *text,
77 int *charsInserted, int *charsDeleted);
78 void BufReplaceRect(textBuffer *buf, int start, int end, int rectStart,
79 int rectEnd, const char *text);
80 void BufRemoveRect(textBuffer *buf, int start, int end, int rectStart,
81 int rectEnd);
82 void BufOverlayRect(textBuffer *buf, int startPos, int rectStart,
83 int rectEnd, const char *text, int *charsInserted, int *charsDeleted);
84 void BufClearRect(textBuffer *buf, int start, int end, int rectStart,
85 int rectEnd);
86 int BufGetTabDistance(textBuffer *buf);
87 void BufSetTabDistance(textBuffer *buf, int tabDist);
88 void BufCheckDisplay(textBuffer *buf, int start, int end);
89 void BufSelect(textBuffer *buf, int start, int end);
90 void BufUnselect(textBuffer *buf);
91 void BufRectSelect(textBuffer *buf, int start, int end, int rectStart,
92 int rectEnd);
93 int BufGetSelectionPos(textBuffer *buf, int *start, int *end,
94 int *isRect, int *rectStart, int *rectEnd);
95 char *BufGetSelectionText(textBuffer *buf);
96 void BufRemoveSelected(textBuffer *buf);
97 void BufReplaceSelected(textBuffer *buf, const char *text);
98 void BufSecondarySelect(textBuffer *buf, int start, int end);
99 void BufSecondaryUnselect(textBuffer *buf);
100 void BufSecRectSelect(textBuffer *buf, int start, int end,
101 int rectStart, int rectEnd);
102 int BufGetSecSelectPos(textBuffer *buf, int *start, int *end,
103 int *isRect, int *rectStart, int *rectEnd);
104 char *BufGetSecSelectText(textBuffer *buf);
105 void BufRemoveSecSelect(textBuffer *buf);
106 void BufReplaceSecSelect(textBuffer *buf, const char *text);
107 void BufHighlight(textBuffer *buf, int start, int end);
108 void BufUnhighlight(textBuffer *buf);
109 void BufRectHighlight(textBuffer *buf, int start, int end,
110 int rectStart, int rectEnd);
111 int BufGetHighlightPos(textBuffer *buf, int *start, int *end,
112 int *isRect, int *rectStart, int *rectEnd);
113 char *BufGetHighlightText(textBuffer *buf);
114 void BufAddModifyCB(textBuffer *buf, bufModifyCallbackProc bufModifiedCB,
115 void *cbArg);
116 void BufRemoveModifyCB(textBuffer *buf, bufModifyCallbackProc bufModifiedCB,
117 void *cbArg);
118 void BufAddPreDeleteCB(textBuffer *buf, bufPreDeleteCallbackProc bufPreDeleteCB,
119 void *cbArg);
120 void BufRemovePreDeleteCB(textBuffer *buf, bufPreDeleteCallbackProc
121 bufPreDeleteCB, void *cbArg);
122 char *BufGetLineText(textBuffer *buf, int pos);
123 int BufStartOfLine(textBuffer *buf, int pos);
124 int BufEndOfLine(textBuffer *buf, int pos);
125 int BufGetExpandedChar(textBuffer *buf, int pos, int indent, char *outStr);
126 int BufExpandCharacter(char c, int indent, char *outStr, int tabDist,
127 char nullSubsChar);
128 int BufCharWidth(char c, int indent, int tabDist, char nullSubsChar);
129 int BufCountDispChars(textBuffer *buf, int lineStartPos, int targetPos);
130 int BufCountForwardDispChars(textBuffer *buf, int lineStartPos, int nChars);
131 int BufCountLines(textBuffer *buf, int startPos, int endPos);
132 int BufCountForwardNLines(textBuffer *buf, int startPos, int nLines);
133 int BufCountBackwardNLines(textBuffer *buf, int startPos, int nLines);
134 int BufSearchForward(textBuffer *buf, int startPos, const char *searchChars,
135 int *foundPos);
136 int BufSearchBackward(textBuffer *buf, int startPos, const char *searchChars,
137 int *foundPos);
138 int BufSubstituteNullChars(char *string, int length, textBuffer *buf);
139 void BufUnsubstituteNullChars(char *string, textBuffer *buf);
140 int BufCmp(textBuffer * buf, int pos, int len, const char *cmpText);
142 #endif /* NEDIT_TEXTBUF_H_INCLUDED */