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