My favorites | Sign in
Project Home Downloads Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
class TextCtrl : public Ctrl, protected TextArrayOps {
public:
virtual void SetData(const Value& v);
virtual Value GetData() const;
virtual void CancelMode();
virtual String GetSelectionData(const String& fmt) const;
virtual void MiddleDown(Point p, dword flags);

public:
struct UndoRec {
int serial;
int pos;
int size;
String text;
bool typing;
};

struct UndoData {
int undoserial;
BiArray<UndoRec> undo;
BiArray<UndoRec> redo;

void Clear() { undo.Clear(); redo.Clear(); }
};

enum {
INK_NORMAL,
INK_DISABLED,
INK_SELECTED,
PAPER_NORMAL,
PAPER_READONLY,
PAPER_SELECTED,
COLOR_COUNT,
};

protected:
virtual void DirtyFrom(int line);
virtual void SelectionChanged();
virtual void ClearLines();
virtual void InsertLines(int line, int count);
virtual void RemoveLines(int line, int count);
virtual void PreInsert(int pos, const WString& text);
virtual void PostInsert(int pos, const WString& text);
virtual void PreRemove(int pos, int size);
virtual void PostRemove(int pos, int size);
virtual void SetSb();
virtual void PlaceCaret(int newcursor, bool sel = false);
virtual void InvalidateLine(int i);

struct Ln : Moveable<Ln> {
int len;
String text;

int GetLength() const { return len; }
operator WString() const { return FromUtf8(text); }

Ln(const WString& wtext) { text = ToUtf8(wtext); len = wtext.GetLength(); }
Ln() { len = 0; }
};

Vector<Ln> line;
int total;
int cline, cpos;
int cursor, anchor;
int undoserial;
bool incundoserial;
int undosteps;
BiArray<UndoRec> undo;
BiArray<UndoRec> redo;
int dirty;
int undo_op;
byte charset;

bool selclick;
Point dropcaret;
bool isdrag;

Color color[COLOR_COUNT];

bool processtab, processenter;
bool nobg;

void IncDirty();
void DecDirty();
int Insert0(int pos, const WString& txt);
void Remove0(int pos, int size);
int InsertU(int pos, const WString& txt, bool typing = false);
void RemoveU(int pos, int size);
void Undodo();
int Insert(int pos, const WString& txt, bool typing);
void DoPaste() { Paste(); }
void DoRemoveSelection() { RemoveSelection(); }
void RefreshLines(int l1, int l2);

public:
virtual void RefreshLine(int i);

Callback1<Bar&> WhenBar;
Callback WhenState;
Callback WhenSel;

void CachePos(int pos);

enum { CHARSET_UTF8_BOM = 250 };

void Load(Stream& s, byte charset = CHARSET_DEFAULT);
void Save(Stream& s, byte charset = CHARSET_DEFAULT, bool crlf = false) const;

int GetInvalidCharPos(byte charset = CHARSET_DEFAULT) const;
bool CheckCharset(byte charset = CHARSET_DEFAULT) const { return GetInvalidCharPos(charset) < 0; }

void Set(const WString& s);
void Set(const String& s, byte charset = CHARSET_DEFAULT);
String Get(byte charset = CHARSET_DEFAULT) const;
String Get(int pos, int size, byte charset = CHARSET_DEFAULT) const;
WString GetW(int pos, int size) const;
WString GetW() const { return GetW(0, GetLength()); }

void ClearDirty();
bool IsDirty() const { return dirty; }

void Clear();

int GetLinePos(int& pos) const;
int GetPos(int line, int column) const;
int GetPos(int line) const { return GetPos(line, 0); }
int GetLine(int pos) const { return GetLinePos(pos); }

const String& GetUtf8Line(int i) const { return line[i].text; }
WString GetWLine(int i) const { return FromUtf8(line[i].text); }
String GetEncodedLine(int i, byte charset = CHARSET_DEFAULT) const;
int GetLineLength(int i) const { return line[i].GetLength(); }

int GetLineCount() const { return line.GetCount(); }
int GetChar(int pos) const;
int operator[](int pos) const { return GetChar(pos); }
int GetLength() const { return total; }

int GetCursor() const { return cursor; }
int GetCursorLine() { return GetLine(GetCursor()); }

void SetSelection(int anchor = 0, int cursor = INT_MAX);
bool IsSelection() const { return anchor >= 0; }
bool GetSelection(int& l, int& h) const;
String GetSelection(byte charset = CHARSET_DEFAULT) const;
WString GetSelectionW() const;
void ClearSelection();
bool RemoveSelection();
void SetCursor(int cursor) { PlaceCaret(cursor); }
int Paste(const WString& text);

int Insert(int pos, const WString& txt) { return Insert(pos, txt, false); }
int Insert(int pos, const String& txt, byte charset = CHARSET_DEFAULT);
int Insert(int pos, const char *txt) { return Insert(pos, WString(txt)); }
void Remove(int pos, int size);

void NextUndo();
void Undo();
void Redo();
bool IsUndo() const { return undo.GetCount(); }
bool IsRedo() const { return redo.GetCount(); }
void ClearUndo() { undo.Clear(); redo.Clear(); }
bool IsUndoOp() const { return undo_op; }
UndoData PickUndoData();
void SetPickUndoData(pick_ UndoData& data);

void Cut();
void Copy();
void Paste();
void SelectAll();

void StdBar(Bar& menu);

void SetCharset(byte cs) { charset = ResolveCharset(cs); }
byte GetCharset() const { return charset; }

void SetColor(int i, Color c) { color[i] = c; Refresh(); }
Color GetColor(int i) const { return color[i]; }

TextCtrl& UndoSteps(int n) { undosteps = n; Undodo(); return *this; }
int GetUndoSteps() const { return undosteps; }
TextCtrl& ProcessTab(bool b = true) { processtab = b; return *this; }
TextCtrl& NoProcessTab() { return ProcessTab(false); }
TextCtrl& ProcessEnter(bool b = true) { processenter = b; return *this; }
TextCtrl& NoProcessEnter() { return ProcessEnter(false); }
TextCtrl& NoBackground(bool b = true) { nobg = b; Transparent(); Refresh(); return *this; }
bool IsNoBackground() const { return nobg; }
bool IsProcessTab() const { return processtab; }
bool IsProcessEnter() const { return processenter; }

typedef TextCtrl CLASSNAME;

TextCtrl();
virtual ~TextCtrl();
};

class LineEdit : public TextCtrl {
public:
virtual bool Key(dword key, int count);
virtual void Paint(Draw& w);
virtual void LeftDown(Point p, dword flags);
virtual void RightDown(Point p, dword flags);
virtual void LeftRepeat(Point p, dword keyflags);
virtual void LeftDouble(Point p, dword keyflags);
virtual void LeftTriple(Point p, dword keyflags);
virtual void LeftUp(Point p, dword flags);
virtual void LeftDrag(Point p, dword flags);
virtual void MouseMove(Point p, dword flags);
virtual void MouseWheel(Point, int zdelta, dword);
virtual Image CursorImage(Point, dword);
virtual void DragAndDrop(Point p, PasteClip& d);
virtual void DragRepeat(Point p);
virtual void DragLeave();
virtual void Layout();
virtual void RefreshLine(int i);

protected:
virtual void SetSb();
virtual void PlaceCaret(int newcursor, bool sel = false);

public:
struct Highlight : Moveable<Highlight> {
Color paper;
Color ink;
Font font;
wchar chr;

bool operator==(const Highlight& h) const
{ return paper == h.paper && ink == h.ink && font == h.font; }
};

struct EditPos : Moveable<EditPos> {
int sby;
int cursor;

void Serialize(Stream& s);
void Clear() { sby = 0; cursor = 0; }
EditPos() { Clear(); }
};

protected:
virtual void HighlightLine(int line, Vector<Highlight>& h, int pos);
virtual void NewScrollPos();

ScrollBars sb;
int gcolumn;
int mpos;


Font font;
CharFilter filter;
int tabsize;
int bordercolumn;
Color bordercolor;
bool nohbar;
bool showtabs;
bool cutline;
bool overwrite;
Scroller scroller;
Point caretpos;
bool showspaces;

void Paint0(Draw& w);

void AlignChar();

void MovePage(int dir, bool sel);

void PlaceCaret0(Point p);
int PlaceCaretNoG(int newcursor, bool sel = false);

void Scroll();
void SetHBar();
Rect DropCaret();
void RefreshDropCaret();

struct RefreshDraw;

public:
Size GetFontSize() const;
int GetGPos(int ln, int cl) const;
int GetMousePos(Point p) const;
Point GetColumnLine(int pos) const;
int GetColumnLinePos(Point pos) const { return GetGPos(pos.y, pos.x); }
Point GetIndexLine(int pos) const;
int GetIndexLinePos(Point pos) const;

void ScrollUp() { sb.LineUp(); }
void ScrollDown() { sb.LineDown(); }

Rect GetLineScreenRect(int line) const;

void TopCursor(int lines = 0);
void CenterCursor();

void MoveUpDown(int n, bool sel = false);

void MoveLeft(bool sel = false);
void MoveRight(bool sel = false);
void MoveUp(bool sel = false);
void MoveDown(bool sel = false);
void MovePageUp(bool sel = false);
void MovePageDown(bool sel = false);
void MoveHome(bool sel = false);
void MoveEnd(bool sel = false);
void MoveTextBegin(bool sel = false);
void MoveTextEnd(bool sel = false);

bool InsertChar(dword key, int count = 1, bool canoverwrite = false);
void DeleteChar();
void Backspace();
void DeleteLine();
void CutLine();

Point GetScrollPos() const { return sb; }
Size GetPageSize() { return sb.GetPage(); }
void SetScrollPos(Point p) { sb.Set(p); }

EditPos GetEditPos() const;
void SetEditPos(const EditPos& pos);
void SetEditPosSb(const LineEdit::EditPos& pos);

void ScrollIntoCursor();

Point GetCaretPoint() const { return caretpos; }

void Clear();

void OverWriteMode(bool o = true) { overwrite = o; PlaceCaret(cursor, false); }
bool IsOverWriteMode() const { return overwrite; }

void RefreshChars(bool (*predicate)(int c));

LineEdit& TabSize(int n);
int GetTabSize() const { return tabsize; }
LineEdit& BorderColumn(int col, Color c = SColorFace());
LineEdit& SetFont(Font f);
Font GetFont() const { return font; }
LineEdit& NoHorzScrollbar(bool b = true) { nohbar = b; ScrollIntoCursor(); return *this; }
bool IsNoHorzScrollbar() const { return nohbar; }
LineEdit& ShowTabs(bool st = true) { showtabs = st; Refresh(); return *this; }
bool IsShowTabs() const { return showtabs; }
LineEdit& ShowSpaces(bool ss = true) { showspaces = ss; Refresh(); return *this; }
bool IsShowSpacess() const { return showspaces; }
LineEdit& WithCutLine(bool b) { cutline = b; return *this; }
LineEdit& NoCutLine() { return WithCutLine(false); }
bool IsWithCutLine() const { return cutline; }
LineEdit& SetFilter(int (*f)(int c)) { filter = f; return *this; }

LineEdit& SetScrollBarStyle(const ScrollBar::Style& s) { sb.SetStyle(s); return *this; }

typedef LineEdit CLASSNAME;

LineEdit();
virtual ~LineEdit();
};

class DocEdit : public TextCtrl {
public:
virtual void Paint(Draw& w);
virtual void Layout();
virtual bool Key(dword key, int count);
virtual void LeftDown(Point p, dword flags);
virtual void LeftDouble(Point p, dword keyflags);
virtual void LeftTriple(Point p, dword keyflags);
virtual void LeftUp(Point p, dword flags);
virtual void RightDown(Point p, dword w);
virtual void MouseMove(Point p, dword flags);
virtual void MouseWheel(Point p, int zdelta, dword keyflags);
virtual Image CursorImage(Point p, dword keyflags);
virtual void GotFocus();
virtual void LostFocus();
virtual void RefreshLine(int i);
virtual void SetSb();

virtual void DragAndDrop(Point p, PasteClip& d);
virtual void DragRepeat(Point p);
virtual void DragLeave();
virtual void LeftDrag(Point p, dword flags);

protected:
virtual void ClearLines();
virtual void InsertLines(int line, int count);
virtual void RemoveLines(int line, int count);
virtual void PlaceCaret(int pos, bool select = false);
virtual void InvalidateLine(int i);

struct Para : Moveable<Para> {
int cx, cy;

Para() { cx = -1; }
};

Vector<Para> para;
Font font;
int after;
CharFilter filter;
ScrollBar sb;
int cx;
bool updownleave, eofline;

struct Fmt {
FontInfo fi;
int len;
Buffer<wchar> text;
Buffer<int> width;
Vector<int> line;
int LineEnd(int i) {
return i < line.GetCount() - 1 ? line[i + 1] : len;
}
};
Fmt Format(const WString& text) const;

void Invalidate();
int GetHeight(int i);
void Scroll();
void PlaceCaret(bool scroll);
int GetY(int parai);
int GetCursorPos(Point p);
Point GetCaret(int pos);
void VertMove(int delta, bool select, bool scs);
void HomeEnd(int x, bool select);
void RefreshStyle();
Rect DropCaret();
void RefreshDropCaret();
int GetMousePos(Point p);

public:
DocEdit& After(int a) { after = a; RefreshStyle(); return *this; }
DocEdit& SetFont(Font f) { font = f; RefreshStyle(); return *this; }
DocEdit& SetFilter(int (*f)(int c)) { filter = f; return *this; }
DocEdit& AutoHideSb(bool b = true) { sb.AutoHide(b); return *this; }
bool IsAutoHideSb() const { return sb.IsAutoHide(); }
DocEdit& UpDownLeave(bool u = true) { updownleave = u; return *this; }
DocEdit& NoUpDownLeave() { return UpDownLeave(false); }
bool IsUpDownLeave() const { return updownleave; }
DocEdit& SetScrollBarStyle(const ScrollBar::Style& s) { sb.SetStyle(s); return *this; }
DocEdit& EofLine(bool b = true) { eofline = b; return *this; }
DocEdit& NoEofLine() { return EofLine(false); }
bool IsEofLine() const { return eofline; }

typedef DocEdit CLASSNAME;

DocEdit();
virtual ~DocEdit();
};

Change log

r4169 by cxl on Nov 13, 2011   Diff
CtrlLib, ide: Support for UTF8-BOM
encoding (RM #129)
Go to: 
Project members, sign in to write a code review

Older revisions

r3351 by cxl on Apr 17, 2011   Diff
CtrlLib: LineEdit::ShowSpaces
r3332 by cxl on Apr 10, 2011   Diff
.Various changes
r2325 by cxl on Apr 18, 2010   Diff
CtrlLib: EditField ReadOnly Ctrl+C
fix, DocEdit: NoEofLine, Display:
Background fix
All revisions of this file

File info

Size: 14765 bytes, 446 lines

File properties

svn:eol-style
native
Powered by Google Project Hosting