1 /* $Id: textBuf.h,v 1.9 2002/07/11 21:18:11 slobasso Exp $ */
3 #ifndef NEDIT_TEXTBUF_H_INCLUDED
4 #define NEDIT_TEXTBUF_H_INCLUDED
6 /* Maximum length in characters of a tab or control character expansion
7 of a single buffer character */
8 #define MAX_EXP_CHAR_LEN 20
19 typedef void (*bufModifyCallbackProc
)(int pos
, int nInserted
, int nDeleted
,
20 int nRestyled
, char *deletedText
, void *cbArg
);
21 typedef void (*bufPreDeleteCallbackProc
)(int pos
, int nDeleted
, void *cbArg
);
23 typedef struct _textBuffer
{
24 int length
; /* length of the text in the buffer (the length
25 of the buffer itself must be calculated:
26 gapEnd - gapStart + length) */
27 char *buf
; /* allocated memory where the text is stored */
28 int gapStart
; /* points to the first character of the gap */
29 int gapEnd
; /* points to the first char after the gap */
30 selection primary
; /* highlighted areas */
33 int tabDist
; /* equiv. number of characters in a tab */
34 int useTabs
; /* True if buffer routines are allowed to use
35 tabs for padding in rectangular operations */
36 int nModifyProcs
; /* number of modify-redisplay procs attached */
37 bufModifyCallbackProc
/* procedures to call when buffer is */
38 *modifyProcs
; /* modified to redisplay contents */
39 void **cbArgs
; /* caller arguments for modifyProcs above */
40 int nPreDeleteProcs
; /* number of pre-delete procs attached */
41 bufPreDeleteCallbackProc
/* procedure to call before text is deleted */
42 *preDeleteProcs
; /* from the buffer; at most one is supported. */
43 void **preDeleteCbArgs
; /* caller argument for pre-delete proc above */
44 int cursorPosHint
; /* hint for reasonable cursor position after
45 a buffer modification operation */
46 char nullSubsChar
; /* NEdit is based on C null-terminated strings,
47 so ascii-nul characters must be substituted
48 with something else. This is the else, but
49 of course, things get quite messy when you
53 textBuffer
*BufCreate(void);
54 textBuffer
*BufCreatePreallocated(int requestedSize
);
55 void BufFree(textBuffer
*buf
);
56 char *BufGetAll(textBuffer
*buf
);
57 void BufSetAll(textBuffer
*buf
, const char *text
);
58 char *BufGetRange(textBuffer
*buf
, int start
, int end
);
59 char BufGetCharacter(textBuffer
*buf
, int pos
);
60 char *BufGetTextInRect(textBuffer
*buf
, int start
, int end
,
61 int rectStart
, int rectEnd
);
62 void BufInsert(textBuffer
*buf
, int pos
, const char *text
);
63 void BufRemove(textBuffer
*buf
, int start
, int end
);
64 void BufReplace(textBuffer
*buf
, int start
, int end
, const char *text
);
65 void BufCopyFromBuf(textBuffer
*fromBuf
, textBuffer
*toBuf
, int fromStart
,
66 int fromEnd
, int toPos
);
67 void BufInsertCol(textBuffer
*buf
, int column
, int startPos
, const char *text
,
68 int *charsInserted
, int *charsDeleted
);
69 void BufReplaceRect(textBuffer
*buf
, int start
, int end
, int rectStart
,
70 int rectEnd
, const char *text
);
71 void BufRemoveRect(textBuffer
*buf
, int start
, int end
, int rectStart
,
73 void BufOverlayRect(textBuffer
*buf
, int startPos
, int rectStart
,
74 int rectEnd
, const char *text
, int *charsInserted
, int *charsDeleted
);
75 void BufClearRect(textBuffer
*buf
, int start
, int end
, int rectStart
,
77 int BufGetTabDistance(textBuffer
*buf
);
78 void BufSetTabDistance(textBuffer
*buf
, int tabDist
);
79 void BufSelect(textBuffer
*buf
, int start
, int end
);
80 void BufUnselect(textBuffer
*buf
);
81 void BufRectSelect(textBuffer
*buf
, int start
, int end
, int rectStart
,
83 int BufGetSelectionPos(textBuffer
*buf
, int *start
, int *end
,
84 int *isRect
, int *rectStart
, int *rectEnd
);
85 char *BufGetSelectionText(textBuffer
*buf
);
86 void BufRemoveSelected(textBuffer
*buf
);
87 void BufReplaceSelected(textBuffer
*buf
, const char *text
);
88 void BufSecondarySelect(textBuffer
*buf
, int start
, int end
);
89 void BufSecondaryUnselect(textBuffer
*buf
);
90 void BufSecRectSelect(textBuffer
*buf
, int start
, int end
,
91 int rectStart
, int rectEnd
);
92 int BufGetSecSelectPos(textBuffer
*buf
, int *start
, int *end
,
93 int *isRect
, int *rectStart
, int *rectEnd
);
94 char *BufGetSecSelectText(textBuffer
*buf
);
95 void BufRemoveSecSelect(textBuffer
*buf
);
96 void BufReplaceSecSelect(textBuffer
*buf
, const char *text
);
97 void BufHighlight(textBuffer
*buf
, int start
, int end
);
98 void BufUnhighlight(textBuffer
*buf
);
99 void BufRectHighlight(textBuffer
*buf
, int start
, int end
,
100 int rectStart
, int rectEnd
);
101 int BufGetHighlightPos(textBuffer
*buf
, int *start
, int *end
,
102 int *isRect
, int *rectStart
, int *rectEnd
);
103 char *BufGetHighlightText(textBuffer
*buf
);
104 void BufAddModifyCB(textBuffer
*buf
, bufModifyCallbackProc bufModifiedCB
,
106 void BufRemoveModifyCB(textBuffer
*buf
, bufModifyCallbackProc bufModifiedCB
,
108 void BufAddPreDeleteCB(textBuffer
*buf
, bufPreDeleteCallbackProc bufPreDeleteCB
,
110 void BufRemovePreDeleteCB(textBuffer
*buf
, bufPreDeleteCallbackProc
111 bufPreDeleteCB
, void *cbArg
);
112 char *BufGetLineText(textBuffer
*buf
, int pos
);
113 int BufStartOfLine(textBuffer
*buf
, int pos
);
114 int BufEndOfLine(textBuffer
*buf
, int pos
);
115 int BufGetExpandedChar(textBuffer
*buf
, int pos
, int indent
, char *outStr
);
116 int BufExpandCharacter(char c
, int indent
, char *outStr
, int tabDist
,
118 int BufCharWidth(char c
, int indent
, int tabDist
, char nullSubsChar
);
119 int BufCountDispChars(textBuffer
*buf
, int lineStartPos
, int targetPos
);
120 int BufCountForwardDispChars(textBuffer
*buf
, int lineStartPos
, int nChars
);
121 int BufCountLines(textBuffer
*buf
, int startPos
, int endPos
);
122 int BufCountForwardNLines(textBuffer
*buf
, int startPos
, int nLines
);
123 int BufCountBackwardNLines(textBuffer
*buf
, int startPos
, int nLines
);
124 int BufSearchForward(textBuffer
*buf
, int startPos
, const char *searchChars
,
126 int BufSearchBackward(textBuffer
*buf
, int startPos
, const char *searchChars
,
128 int BufSubstituteNullChars(char *string
, int length
, textBuffer
*buf
);
129 void BufUnsubstituteNullChars(char *string
, textBuffer
*buf
);
131 #endif /* NEDIT_TEXTBUF_H_INCLUDED */