1 #ifndef __KOST_TEXTEDITOR_H
2 #define __KOST_TEXTEDITOR_H
10 #include <sys/types.h>
13 #include "linkedlist.h"
16 #include "kkstrtext.h"
17 #include "conscommon.h"
18 #include "abstractui.h"
20 #define TEXTEDITOR_NOFILES -2
21 #define TEXTEDITOR_ABORTED -1
22 #define TEXTEDITOR_OK 0
24 __KTOOL_BEGIN_NAMESPACE
33 } hl_kind
; // kinds of text to highlight
42 // text highlight entry
49 bool operator == (const hl_kind
&kind
) const;
50 bool operator != (const hl_kind
&kind
) const;
51 bool operator < (const hlight
&ah
) const;
59 int x1
, y1
, x2
, y2
, color
;
65 linkedlist
*lines
, *blocks
, *highlines
, *undo
;
67 int sx
, sy
, x
, y
, ncolorscheme
;
68 bool modified
, markmode
, markreverse
, showmarked
;
73 vector
<int> difcolors
;
75 string synt_quote
, synt_qescape
;
77 int ncolor
, qcolor
, blockcolor
;
88 class texteditor
: public abstractuicontrol
{
91 vector
<colorscheme
> colorschemes
;
94 int fn
/* file number */, fcount
/* files count */;
95 bool undolog
, show
, prevshift
;
100 static void textblockfree(void *p
);
101 static void editfilefree(void *p
);
102 static void undorecordfree(void *p
);
103 static void highlinefree(void *p
);
105 static int findint(void *p1
, void *p2
);
106 static int findhl(void *p1
, void *p2
);
107 static int findhighline(void *p1
, void *p2
);
108 static int sorthl(void *p1
, void *p2
);
110 bool fix_x(bool tab
);
111 void sethlcolor(int n
);
112 void draw(int fromline
);
113 void draw_print(char *buf
, int bcolor
, int distance
);
115 int addwindow(char *id
);
117 void scancomments(bool visible
);
119 void modification(tundoaction action
, const string
&data
,
120 bool connected
= false, int curx
= -1, int cury
= -1);
123 const char currentchar();
125 int count_clrcodes(char *cp
, int pos
);
126 int hl_comment(char *cp
, char *txt
, int color
);
127 int hl_comment(char *cp
, int st
, int pend
, int color
);
128 void showline(int ln
, int startx
, int distance
, int extrax
= 0);
131 void edmove(int k
, int options
= 2);
132 void eddel(bool usetabs
= true);
133 void edenter(bool countspaces
= true);
136 void eddelbegofline();
137 void eddelendofline();
138 void edtransposechar();
140 void eddelwordemacs();
144 void shiftmarkedblock(int delta
);
147 bool active
, wrap
, insertmode
, modified
, smarttab
;
149 int (*otherkeys
)(texteditor
&caller
, int k
);
150 void (*idle
)(texteditor
&caller
);
153 virtual ~texteditor();
155 int load(const string buf
, const string id
);
156 int load(FILE *f
, const string id
);
157 int load(ifstream
&f
, const string id
);
158 // loads a file from char* or FILE opening
159 // a new editor window
161 char *save(const char *linebreak
);
162 int save(FILE *f
, const char *linebreak
);
163 int save(ofstream
&f
, const string linebreak
);
164 // saves a file to char* or FILE
167 // closes current file
170 // returns the amount of windows opened
173 // returns current editor window number
176 char *getfid(int fnn
);
177 // returns id of a file
179 void setfid(char *id
);
180 void setfid(int fnn
, char *id
);
181 // sets an id of file
186 void setcolorscheme(int nscheme
);
187 void setcolorscheme(int fn
, int nscheme
);
188 // set color scheme for current file
196 void copymark(FILE *f
);
197 void copymark(char *p
, int maxlen
);
199 void insert(FILE *f
);
200 void insert(const string buf
);
205 void addblock(int x1
, int y1
, int x2
, int y2
, int color
);
208 void setcoords(int nx1
, int ny1
, int nx2
, int ny2
);
209 int addscheme(int nc
, int bc
, int fbold
, ...);
210 // nc = normal text color
212 // fbold = use bold colors
213 // ... = numbers of pairs in different attribute,
214 // the last one MUST BE 0 !
215 void addhighlight(int nscheme
, string text
, int color
, hl_kind kind
);
216 void addcolordif(int nscheme
, int pairno
);
219 virtual void redraw();
223 bool find(const char *needle
, const char *options
, int *col
, int *line
);
225 void setpos(int col
, int line
);
226 void getpos(int *col
, int *line
);
228 char *getline(int ln
);
229 void putline(int ln
, const char *newline
);
231 void highlight(int line
, int color
);
232 void highlight(int fn
, int line
, int color
);
234 void unlight(int line
);
235 void unlight(int fn
, int line
);
238 void clearlight(int fn
);
239 // lines highlighting
241 void shiftident(int x1
, int y1
, int x2
, int y2
, int delta
);
242 void shiftident(int delta
);
245 __KTOOL_END_NAMESPACE
247 #ifdef __KTOOL_USE_NAMESPACES
249 using ktool::editfile
;
250 using ktool::texteditor
;
252 using ktool::hl_kind
;
253 using ktool::h_alone
;
255 using ktool::h_symbol
;
256 using ktool::h_block
;
257 using ktool::h_quotes
;
258 using ktool::h_comment
;