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