00001
00002
00003
00004
00005 #ifndef __GTEXTVIEW4_H
00006 #define __GTEXTVIEW4_H
00007
00008 #include "GDocView.h"
00009 #include "GUndo.h"
00010
00011
00012
00013
00014 #define TEXTED_USES_CR 0x00000001
00015 #define TAB_SIZE 4
00016 #define DEBUG_TIMES_MSG 8000 // a=0 b=(char*)Str
00017
00018 #define M_TEXTVIEW_DEBUG_TEXT (M_USER+0x3421)
00019
00020 extern char Delimiters[];
00021
00022 class GTextView4;
00023
00024 class GTextStyle
00025 {
00026 friend class GUrl;
00027
00028 protected:
00029 void RefreshLayout(int Start, int Len);
00030
00031 public:
00032 enum StyleDecor
00033 {
00034 DecorNone,
00035 DecorSquiggle,
00036 };
00037
00039 GTextView4 *View;
00044 int Owner;
00046 int Start;
00048 int Len;
00050 GFont *Font;
00052 COLOUR c;
00054 StyleDecor Style;
00056 COLOUR DecorColour;
00057
00059 char *Data;
00060
00061 GTextStyle(int owner)
00062 {
00063 Owner = owner;
00064 View = 0;
00065 c = 0;
00066 Font = 0;
00067 Start = -1;
00068 Len = 0;
00069 Style = DecorNone;
00070 DecorColour = 0;
00071 Data = 0;
00072 }
00073
00074 virtual bool OnMouseClick(GMouse *m) { return false; }
00075 virtual bool OnMenu(GSubMenu *m) { return false; }
00076 virtual void OnMenuClick(int i) {}
00077 virtual TCHAR *GetCursor() { return 0; }
00078
00080 bool Overlap(GTextStyle *s)
00081 {
00082 if (s->Start + s->Len < Start ||
00083 s->Start > Start + Len)
00084 return false;
00085
00086 return true;
00087 }
00088 };
00089
00091 class
00092 #ifdef MAC
00093 LgiClass
00094 #endif
00095 GTextView4 :
00096 public GDocView,
00097 public ResObject
00098 {
00099 friend class GTextStyle;
00100 friend class GUrl;
00101 friend class GTextView4Undo;
00102 friend bool Text_FindCallback(GFindReplaceCommon *Dlg, bool Replace, void *User);
00103
00104 protected:
00105
00106 enum GTextViewSeek
00107 {
00108 PrevLine,
00109 NextLine,
00110 StartLine,
00111 EndLine
00112 };
00113
00114 class GTextLine
00115 {
00116 public:
00117 int Start;
00118 int Len;
00119 GRect r;
00120 COLOUR Col;
00121
00122 GTextLine()
00123 {
00124 Col = 0x80000000;
00125 }
00126 virtual ~GTextLine() {}
00127 bool Overlap(int i)
00128 {
00129 return i>=Start AND i<=Start+Len;
00130 }
00131 };
00132
00133 class GTextView4Private *d;
00134 friend class GTextView4Private;
00135
00136
00137 bool Dirty;
00138 bool CanScrollX;
00139
00140
00141 GFont *Font;
00142 GFont *FixedFont;
00143 GFont *Underline;
00144 int LineY;
00145 int SelStart, SelEnd;
00146 int DocOffset;
00147 int MaxX;
00148 bool Blink;
00149 int ScrollX;
00150 GRect CursorPos;
00151
00152 List<GTextLine> Line;
00153 List<GTextStyle> Style;
00154
00155
00156 char *TextCache;
00157
00158
00159 char16 *Text;
00160 int Cursor;
00161 int Size;
00162 int Alloc;
00163
00164
00165 bool UndoOn;
00166 GUndo UndoQue;
00167
00168
00169 GTextLine *GetLine(int Offset, int *Index = 0);
00170 int SeekLine(int Start, GTextViewSeek Where);
00171 int TextWidth(GFont *f, char16 *s, int Len, int x, int Origin);
00172 int ScrollYLine();
00173 int ScrollYPixel();
00174 int MatchText(char16 *Text, bool MatchWord, bool MatchCase, bool SelectionOnly);
00175
00176
00177 bool InsertStyle(GTextStyle *s);
00178 GTextStyle *GetNextStyle(int Where = -1);
00179 GTextStyle *HitStyle(int i);
00180 int GetColumn();
00181
00182
00183 virtual void PourText(int Start, int Length);
00184 virtual void PourStyle(int Start, int Length);
00185 virtual void OnFontChange();
00186 virtual char16 *MapText(char16 *Str, int Len, bool RtlTrailingSpace = false);
00187
00188 #ifdef _DEBUG
00189
00190 int _PourTime;
00191 int _StyleTime;
00192 int _PaintTime;
00193 #endif
00194
00195 public:
00196
00197 GTextView4( int Id,
00198 int x,
00199 int y,
00200 int cx,
00201 int cy,
00202 GFontType *FontInfo = 0);
00203 ~GTextView4();
00204
00205 const char *GetClass() { return "GTextView4"; }
00206
00207
00208 char *Name();
00209 bool Name(const char *s);
00210 char16 *NameW();
00211 bool NameW(const char16 *s);
00212 int64 Value();
00213 void Value(int64 i);
00214 const char *GetMimeType() { return "text/plain"; }
00215 int GetSize() { return Size; }
00216
00217 struct EditInfo
00218 {
00219 int At;
00220 int Len;
00221 char16 *Txt;
00222
00223 int End() { return At + Len; }
00224 };
00225
00226 virtual bool Insert(GArray<EditInfo> &Edits);
00227 bool Insert(int At, char16 *Data, int Len);
00228 virtual bool Delete(GArray<EditInfo> &Edits);
00229 bool Delete(int At, int Len);
00230 int HitText(int x, int y);
00231 void DeleteSelection(char16 **Cut = 0);
00232
00233
00234 GFont *GetFont();
00235 void SetFont(GFont *f, bool OwnIt = false);
00236 void SetFixedWidthFont(bool i);
00237
00238
00239 void SetTabSize(uint8 i);
00240 void SetBorder(int b);
00241 void SetReadOnly(bool i);
00242
00244 void SetWrapType(uint8 i);
00245
00246
00247 GRect &GetMargin();
00248 void SetMargin(GRect &r);
00249
00250
00251 void SetCursor(int i, bool Select, bool ForceFullUpdate = false);
00252 int IndexAt(int x, int y);
00253 bool IsDirty() { return Dirty; }
00254 void IsDirty(bool d) { Dirty = d; }
00255 bool HasSelection();
00256 void UnSelectAll();
00257 void SelectWord(int From);
00258 void SelectAll();
00259 int GetCursor(bool Cursor = true);
00260 void PositionAt(int &x, int &y, int Index = -1);
00261 int GetLines();
00262 void GetTextExtent(int &x, int &y);
00263 char *GetSelection();
00264
00265
00266 bool Open(char *Name, char *Cs = 0);
00267 bool Save(char *Name, char *Cs = 0);
00268
00269
00270 bool Cut();
00271 bool Copy();
00272 bool Paste();
00273
00274
00275 void Undo();
00276 void Redo();
00277 bool GetUndoOn() { return UndoOn; }
00278 void SetUndoOn(bool b) { UndoOn = b; }
00279
00280
00281 virtual bool DoGoto();
00282 virtual bool DoCase(bool Upper);
00283 virtual bool DoFind();
00284 virtual bool DoFindNext();
00285 virtual bool DoReplace();
00286
00287
00288 bool ClearDirty(bool Ask, char *FileName = 0);
00289 void UpdateScrollBars(bool Reset = false);
00290 void GotoLine(int Line);
00291 GDocFindReplaceParams *CreateFindReplaceParams();
00292 void SetFindReplaceParams(GDocFindReplaceParams *Params);
00293
00294
00295 bool OnFind(char16 *Find, bool MatchWord, bool MatchCase, bool SelectionOnly);
00296 bool OnReplace(char16 *Find, char16 *Replace, bool All, bool MatchWord, bool MatchCase, bool SelectionOnly);
00297 bool OnMultiLineTab(bool In);
00298 void OnSetHidden(int Hidden);
00299 void OnPosChange();
00300 void OnCreate();
00301 void OnEscape(GKey &K);
00302 void OnMouseWheel(double Lines);
00303
00304
00305 void OnFocus(bool f);
00306 void OnMouseClick(GMouse &m);
00307 void OnMouseMove(GMouse &m);
00308 bool OnKey(GKey &k);
00309 void OnPaint(GSurface *pDC);
00310 int OnEvent(GMessage *Msg);
00311 int OnNotify(GViewI *Ctrl, int Flags);
00312 void OnPulse();
00313 int OnHitTest(int x, int y);
00314
00315
00316 virtual void OnEnter(GKey &k);
00317 virtual void OnUrl(char *Url);
00318 };
00319
00320 #endif