Fixed bug #1734670: when logging off of MSN it did not hide the contacts
[centerim.git] / kkconsui / include / texteditor.h
blob403eaa7a20e66f6facca7124dff80b3a234c1cec
1 #ifndef __KOST_TEXTEDITOR_H
2 #define __KOST_TEXTEDITOR_H
4 #include <string>
5 #include <vector>
6 #include <list>
7 #include <fstream>
8 #include <algorithm>
9 #include <unistd.h>
10 #include <sys/types.h>
11 #include <sys/stat.h>
13 #include "linkedlist.h"
14 #include "conf.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
26 typedef enum {
27 h_alone,
28 h_eol,
29 h_symbol,
30 h_block,
31 h_quotes,
32 h_comment
33 } hl_kind; // kinds of text to highlight
35 typedef enum {
36 udelchar,
37 udelblock,
38 uinschar,
39 uinsblock
40 } tundoaction;
42 // text highlight entry
44 struct hlight {
45 hl_kind kind;
46 int color;
47 string text;
49 bool operator == (const hl_kind &kind) const;
50 bool operator != (const hl_kind &kind) const;
51 bool operator < (const hlight &ah) const;
54 struct highline {
55 int line, color;
58 struct textblock {
59 int x1, y1, x2, y2, color;
62 struct editfile {
63 char *id;
65 linkedlist *lines, *blocks, *highlines, *undo;
66 textblock *markblock;
67 int sx, sy, x, y, ncolorscheme;
68 bool modified, markmode, markreverse, showmarked;
71 struct colorscheme {
72 vector<hlight> hl;
73 vector<int> difcolors;
75 string synt_quote, synt_qescape;
77 int ncolor, qcolor, blockcolor;
78 bool bold;
81 struct undorecord {
82 tundoaction action;
83 bool prevconnected;
84 int x, y;
85 string data;
88 class texteditor: public abstractuicontrol {
89 protected:
90 linkedlist *files;
91 vector<colorscheme> colorschemes;
93 int outx, abscol;
94 int fn /* file number */, fcount /* files count */;
95 bool undolog, show, prevshift;
97 editfile *curfile;
98 colorscheme colors;
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);
122 bool endofline();
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);
130 void marktext();
131 void edmove(int k, int options = 2);
132 void eddel(bool usetabs = true);
133 void edenter(bool countspaces = true);
134 void edbackspace();
135 void eddelline();
136 void eddelbegofline();
137 void eddelendofline();
138 void edtransposechar();
139 void eddelword();
140 void eddelwordemacs();
142 void inschar(int k);
144 void shiftmarkedblock(int delta);
146 public:
147 bool active, wrap, insertmode, modified, smarttab;
149 int (*otherkeys)(texteditor &caller, int k);
150 void (*idle)(texteditor &caller);
152 texteditor();
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
166 void close();
167 // closes current file
169 int getfcount();
170 // returns the amount of windows opened
172 int getfnum();
173 // returns current editor window number
175 char *getfid();
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
183 void setfnum(int n);
184 // sets active file
186 void setcolorscheme(int nscheme);
187 void setcolorscheme(int fn, int nscheme);
188 // set color scheme for current file
190 void startmark();
191 void endmark();
192 void switchmark();
193 bool ismark();
195 void clearmark();
196 void copymark(FILE *f);
197 void copymark(char *p, int maxlen);
199 void insert(FILE *f);
200 void insert(const string buf);
202 void delmark();
203 void undo();
205 void addblock(int x1, int y1, int x2, int y2, int color);
206 // adds a block
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
211 // bc = block 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);
218 int open();
219 virtual void redraw();
220 void draw();
221 void updatecursor();
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);
237 void clearlight();
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;
254 using ktool::h_eol;
255 using ktool::h_symbol;
256 using ktool::h_block;
257 using ktool::h_quotes;
258 using ktool::h_comment;
260 #endif
262 #endif