00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef __TEXT_H
00012 #define __TEXT_H
00013
00014 #include "Lgi.h"
00015
00016
00017 #define TEXTED_WRAP_NONE 0 // no word wrap
00018 #define TEXTED_WRAP_NONREFLOW 1 // insert LF when you hit the end
00019 #define TEXTED_WRAP_REFLOW 2 // dynamically wrap line to editor width
00020
00021
00022 #define TVCP_US_ASCII 0
00023 #define TVCP_ISO_8859_2 1
00024 #define TVCP_WIN_1250 2
00025 #define TVCP_MAX 3
00026
00027
00028
00029
00030 #define TEXTED_USES_CR 0x00000001
00031
00032 #define TAB_SIZE 4
00033
00034 #define IsWhite(c) (strchr(WhiteSpace, c) != 0)
00035 #define IsDelimiter(c) (strchr(Delimiters, c) != 0)
00036 #define IsDigit(c) ((c) >= '0' AND (c) <= '9')
00037 #define IsAlpha(c) (((c) >= 'a' AND (c) <= 'z') OR ((c) >= 'A' AND (c) <= 'Z'))
00038 #define IsText(c) (IsDigit(c) OR IsAlpha(c) OR (c) == '_')
00039
00040 extern char Delimiters[];
00041 extern int StrLen(char *c);
00042 extern int RevStrLen(char *c);
00043
00044
00045 class Document {
00046 protected:
00047 char *File;
00048 GFile F;
00049
00050 bool Open(char *FileName, int Attrib);
00051
00052 public:
00053 Document();
00054 virtual ~Document();
00055
00056 virtual bool Load(char *File) { return FALSE; }
00057 virtual bool Save(char *File) { return FALSE; }
00058 char *GetName() { return File; }
00059 };
00060
00061
00062 class TextDocument;
00063
00064 class GCursor {
00065
00066 friend class TextDocument;
00067
00068 TextDocument *Parent;
00069 int x, y;
00070 int Length;
00071 int Offset;
00072
00073 void GoUpLine();
00074 void GoDownLine();
00075
00076 public:
00077 GCursor();
00078 ~GCursor();
00079
00080 int X() { return x; }
00081 int Y() { return y; }
00082 int LineLength() { return Length; }
00083 int GetOffset() { return Offset; }
00084 operator char*();
00085 char *GetStr();
00086
00087 bool AtEndOfLine();
00088 bool AtBeginningOfLine();
00089
00090 int CursorX(int TabSize);
00091 void SetX(int X);
00092 void SetY(int Y);
00093 void MoveX(int Dx);
00094 void MoveY(int Dy);
00095
00096 bool operator ==(GCursor &c)
00097 {
00098 return (x == c.x) AND
00099 (y == c.y) AND
00100 (Parent == c.Parent);
00101 }
00102
00103 bool operator !=(GCursor &c)
00104 {
00105 return (x != c.x) OR
00106 (y != c.y) OR
00107 (Parent != c.Parent);
00108 }
00109
00110 bool operator <(GCursor &c)
00111 {
00112 return (y < c.y) OR
00113 ((y == c.y) AND (x < c.x));
00114 }
00115
00116 bool operator <=(GCursor &c)
00117 {
00118 return (y < c.y) OR
00119 ((y == c.y) AND (x <= c.x));
00120 }
00121
00122 bool operator >(GCursor &c)
00123 {
00124 return (y > c.y) OR
00125 ((y == c.y) AND (x > c.x));
00126 }
00127
00128 bool operator >=(GCursor &c)
00129 {
00130 return (y > c.y) OR
00131 ((y == c.y) AND (x >= c.x));
00132 }
00133
00134 int operator -(GCursor &c)
00135 {
00136 return (Offset + x) - (c.Offset + c.x);
00137 }
00138 };
00139
00140 class TextLock {
00141
00142 friend class TextDocument;
00143
00144 int StartLine;
00145 int Lines;
00146 char **Line;
00147 ushort **LineW;
00148
00149 public:
00150 TextLock();
00151 ~TextLock();
00152
00153 int Start() { return StartLine; }
00154 char *operator [](int i);
00155 ushort *GetLineW(int i);
00156 };
00157
00158 class UserAction
00159 {
00160 public:
00161 char *Text;
00162 int x, y;
00163 bool Insert;
00164
00165 UserAction();
00166 ~UserAction();
00167 };
00168
00169 #define TEXT_BLOCK 0x4000
00170 #define TEXT_MASK 0x3FFF
00171
00172 class TextDocument : public Document {
00173 public:
00174 friend GCursor;
00175
00176 int Flags;
00177 int LockCount;
00178 bool Dirty;
00179 bool CrLf;
00180 bool Editable;
00181
00182
00183 int IgnoreUndo;
00184 int UndoPos;
00185 List<UserAction> Queue;
00186 void TruncateQueue();
00187 void ApplyAction(UserAction *a, GCursor &c, bool Reverse = false);
00188
00189
00190 int Lines;
00191 int Length;
00192 int Alloc;
00193 char *Data;
00194
00195
00196 bool SetLength(int Len);
00197 int CountLines(char *c, int Len = -1);
00198 char *FindLine(int i);
00199
00200 public:
00201 TextDocument();
00202 virtual ~TextDocument();
00203
00204 bool UseCrLf() { return CrLf; }
00205 void UseCrLf(bool Use) { CrLf = Use; }
00206 bool AcceptEdits() { return Editable; }
00207 void AcceptEdits(bool i) { Editable = i; }
00208
00209
00210 int GetLines() { return Lines; }
00211 int GetLength() { return Length; }
00212
00213
00214 bool Load(char *File);
00215 bool Save(char *File);
00216 bool IsDirty() { return Dirty; }
00217 bool Import(char *s, int size = -1);
00218 bool Export(char *&s, int &size);
00219
00220
00221 bool Lock(TextLock *Lock, int StartLine, int Lines, int CodePage = TVCP_US_ASCII);
00222 void UnLock(TextLock *Lock);
00223 bool MoveLock(TextLock *Lock, int Dy);
00224
00225
00226 bool CursorCreate(GCursor *c, int X, int Y);
00227
00228
00229 bool Insert(GCursor *At, char *Text, int Len = -1);
00230 bool Delete(GCursor *From, int Len, char *Buffer = NULL);
00231
00232
00233 void Undo(GCursor &c);
00234 void Redo(GCursor &c);
00235 void ClearUndoQueue();
00236 bool UndoAvailable(bool Redo = false);
00237 };
00238
00239 #define TVF_SELECTION 0x00000001
00240 #define TVF_DIRTY_CURSOR 0x00000010
00241 #define TVF_DIRTY_TO_EOL 0x00000020
00242 #define TVF_DIRTY_TO_EOP 0x00000040
00243 #define TVF_DIRTY_SELECTION 0x00000080
00244 #define TVF_DIRTY_ALL 0x00000100
00245 #define TVF_DIRTY_MASK (TVF_DIRTY_CURSOR | TVF_DIRTY_TO_EOL | TVF_DIRTY_TO_EOP | TVF_DIRTY_SELECTION | TVF_DIRTY_ALL)
00246 #define TVF_SHIFT 0x00000200
00247 #define TVF_GOTO_START 0x00000400 // of selection
00248 #define TVF_GOTO_END 0x00000800 // of selection
00249 #define TVF_EAT_MOVE 0x00001000 // don't move cursor
00250
00251 class TextView {
00252 protected:
00253
00254 int Flags;
00255 bool IsDirty();
00256 virtual void Dirty(int Type);
00257 void Clean();
00258 ushort *GetCodePageMap(int Page = -1);
00259
00260 char *StatusMsg;
00261 void SetStatus(char *Msg);
00262
00263
00264 char *ClipData;
00265
00266 virtual bool ClipText(char *Str, int Len = -1);
00267 virtual char *ClipText();
00268 virtual bool Cut();
00269 virtual bool Copy();
00270 virtual bool Paste();
00271
00272
00273 TextDocument Doc;
00274 bool OnInsertText(char *Text, int Len = -1);
00275 bool OnDeleteText(GCursor *c, int Len, bool Clip);
00276
00277
00278 int HiddenLines;
00279 int DisplayLines;
00280 GCursor User;
00281 virtual bool UpdateHiddenCheck();
00282 virtual bool OnMoveCursor(int Dx, int Dy = 0, bool NoSelect = FALSE);
00283 virtual void OnSetHidden(int Hidden);
00284 virtual void OnSetCursor(int X, int Y);
00285 virtual bool OnMultiLineTab(bool In) { return FALSE; }
00286
00287
00288 GCursor Start, End;
00289 void OnStartSelection(GCursor *c);
00290 void OnEndSelection();
00291 void OnDeleteSelection(bool Clip);
00292
00293
00294 virtual void AfterInsertText(char *c, int len) {}
00295 virtual void AfterDeleteText() {}
00296
00297
00298 int WrapType;
00299 int CodePage;
00300
00301 public:
00302 TextView();
00303 virtual ~TextView();
00304
00305 virtual bool Open(char *Name);
00306 virtual bool Save(char *Name);
00307 virtual int ProcessKey(GKey &K);
00308 virtual int Paint() { return FALSE; }
00309 virtual int GetWrapType() { return WrapType; }
00310 virtual void SetWrapType(int i) { WrapType = i; }
00311 virtual int GetCodePage() { return CodePage; }
00312 virtual void SetCodePage(int i) { CodePage = i; }
00313
00314 virtual bool ClearDirty(bool Ask);
00315 virtual void OnSave();
00316 virtual void OnGotoLine();
00317 virtual void OnEscape(GKey &K);
00318 virtual void OnEnter(GKey &K);
00319 };
00320
00321 #endif