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;
00068 COLOUR c;
00070 StyleDecor Decor;
00072 COLOUR DecorColour;
00073
00075 char *Data;
00076
00077 GStyle(int owner)
00078 {
00079 Owner = owner;
00080 View = 0;
00081 c = 0;
00082 Font = 0;
00083 Start = -1;
00084 Len = 0;
00085 Decor = DecorNone;
00086 DecorColour = 0;
00087 Data = 0;
00088 }
00089
00090 virtual bool OnMouseClick(GMouse *m) { return false; }
00091 virtual bool OnMenu(GSubMenu *m) { return false; }
00092 virtual void OnMenuClick(int i) {}
00093 virtual TCHAR *GetCursor() { return 0; }
00094
00096 bool Overlap(GStyle *s)
00097 {
00098 if (s->Start + s->Len < Start ||
00099 s->Start > Start + Len)
00100 return false;
00101
00102 return true;
00103 }
00104 };
00105
00106 friend class GTextView3::GStyle;
00107
00108 protected:
00109
00110 enum GTextViewSeek
00111 {
00112 PrevLine,
00113 NextLine,
00114 StartLine,
00115 EndLine
00116 };
00117
00118 class GTextLine
00119 {
00120 public:
00121 int Start;
00122 int Len;
00123 GRect r;
00124 COLOUR Col;
00125
00126 GTextLine()
00127 {
00128 Col = 0x80000000;
00129 }
00130 virtual ~GTextLine() {}
00131 bool Overlap(int i)
00132 {
00133 return i>=Start AND i<=Start+Len;
00134 }
00135 };
00136
00137 class GTextView3Private *d;
00138 friend class GTextView3Private;
00139
00140
00141 bool Dirty;
00142 bool CanScrollX;
00143
00144
00145 GFont *Font;
00146 GFont *FixedFont;
00147 GFont *Underline;
00148 int LineY;
00149 int SelStart, SelEnd;
00150 int DocOffset;
00151 int MaxX;
00152 bool Blink;
00153 int ScrollX;
00154 GRect CursorPos;
00155
00156 List<GTextLine> Line;
00157 List<GStyle> Style;
00158
00159
00160 char *TextCache;
00161
00162
00163 char16 *Text;
00164 int Cursor;
00165 int Size;
00166 int Alloc;
00167
00168
00169 bool UndoOn;
00170 GUndo UndoQue;
00171
00172
00173 GTextLine *GetLine(int Offset, int *Index = 0);
00174 int SeekLine(int Start, GTextViewSeek Where);
00175 int TextWidth(GFont *f, char16 *s, int Len, int x, int Origin);
00176 int ScrollYLine();
00177 int ScrollYPixel();
00178 int MatchText(char16 *Text, bool MatchWord, bool MatchCase, bool SelectionOnly);
00179
00180
00181 bool InsertStyle(GStyle *s);
00182 GStyle *GetNextStyle(int Where = -1);
00183 GStyle *HitStyle(int i);
00184 int GetColumn();
00185
00186
00187 virtual void PourText(int Start, int Length);
00188 virtual void PourStyle(int Start, int Length);
00189 virtual void OnFontChange();
00190 virtual char16 *MapText(char16 *Str, int Len, bool RtlTrailingSpace = false);
00191
00192 #ifdef _DEBUG
00193
00194 int _PourTime;
00195 int _StyleTime;
00196 int _PaintTime;
00197 #endif
00198
00199 public:
00200
00201 GTextView3( int Id,
00202 int x,
00203 int y,
00204 int cx,
00205 int cy,
00206 GFontType *FontInfo = 0);
00207 ~GTextView3();
00208
00209 char *GetClass() { return "GTextView3"; }
00210
00211
00212 char *Name();
00213 bool Name(char *s);
00214 char16 *NameW();
00215 bool NameW(char16 *s);
00216 int64 Value();
00217 void Value(int64 i);
00218 char *GetMimeType() { return "text/plain"; }
00219 int GetSize() { return Size; }
00220
00221 int HitText(int x, int y);
00222 void DeleteSelection(char16 **Cut = 0);
00223
00224
00225 GFont *GetFont();
00226 void SetFont(GFont *f, bool OwnIt = false);
00227 void SetFixedWidthFont(bool i);
00228
00229
00230 void SetTabSize(uint8 i);
00231 void SetBorder(int b);
00232 void SetReadOnly(bool i);
00233
00235 void SetWrapType(uint8 i);
00236
00237
00238 GRect &GetMargin();
00239 void SetMargin(GRect &r);
00240
00241
00242 void SetCursor(int i, bool Select, bool ForceFullUpdate = false);
00243 int IndexAt(int x, int y);
00244 bool IsDirty() { return Dirty; }
00245 void IsDirty(bool d) { Dirty = d; }
00246 bool HasSelection();
00247 void UnSelectAll();
00248 void SelectWord(int From);
00249 void SelectAll();
00250 int GetCursor(bool Cursor = true);
00251 void PositionAt(int &x, int &y, int Index = -1);
00252 int GetLines();
00253 void GetTextExtent(int &x, int &y);
00254 char *GetSelection();
00255
00256
00257 bool Open(char *Name, char *Cs = 0);
00258 bool Save(char *Name, char *Cs = 0);
00259
00260
00261 bool Cut();
00262 bool Copy();
00263 bool Paste();
00264
00265
00266 void Undo();
00267 void Redo();
00268 bool GetUndoOn() { return UndoOn; }
00269 void SetUndoOn(bool b) { UndoOn = b; }
00270
00271
00272 virtual bool DoGoto();
00273 virtual bool DoCase(bool Upper);
00274 virtual bool DoFind();
00275 virtual bool DoFindNext();
00276 virtual bool DoReplace();
00277
00278
00279 bool ClearDirty(bool Ask, char *FileName = 0);
00280 void UpdateScrollBars(bool Reset = false);
00281 void GotoLine(int Line);
00282 GDocFindReplaceParams *CreateFindReplaceParams();
00283 void SetFindReplaceParams(GDocFindReplaceParams *Params);
00284
00285
00286 bool OnFind(char16 *Find, bool MatchWord, bool MatchCase, bool SelectionOnly);
00287 bool OnReplace(char16 *Find, char16 *Replace, bool All, bool MatchWord, bool MatchCase, bool SelectionOnly);
00288 bool OnMultiLineTab(bool In);
00289 void OnSetHidden(int Hidden);
00290 void OnPosChange();
00291 void OnCreate();
00292 void OnEscape(GKey &K);
00293 void OnMouseWheel(double Lines);
00294
00295
00296 void OnFocus(bool f);
00297 void OnMouseClick(GMouse &m);
00298 void OnMouseMove(GMouse &m);
00299 bool OnKey(GKey &k);
00300 void OnPaint(GSurface *pDC);
00301 int OnEvent(GMessage *Msg);
00302 int OnNotify(GViewI *Ctrl, int Flags);
00303 void OnPulse();
00304 int OnHitTest(int x, int y);
00305 bool OnLayout(GViewLayoutInfo &Inf);
00306 int WillAccept(List<char> &Formats, GdcPt2 Pt, int KeyState);
00307 int OnDrop(char *Format, GVariant *Data, GdcPt2 Pt, int KeyState);
00308
00309
00310 virtual bool Insert(int At, char16 *Data, int Len);
00311 virtual bool Delete(int At, int Len);
00312 virtual void OnEnter(GKey &k);
00313 virtual void OnUrl(char *Url);
00314 };
00315
00316 #endif