Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

GTextView.h

00001 #ifndef __GTEXTVIEW_H
00002 #define __GTEXTVIEW_H
00003 
00004 // Word wrap
00005 #define TEXTED_WRAP_NONE            0   // no word wrap
00006 #define TEXTED_WRAP_REFLOW          1   // dynamically wrap line to editor width
00007 
00008 // Notify flags
00009 #define GTVN_DOC_CHANGED            0x0001
00010 #define GTVN_CURSOR_CHANGED         0x0002
00011 #define GTVN_CODEPAGE_CHANGED       0x0004
00012 
00013 // Util macros
00014 #define IsWhiteSpace(c)             (strchr(GTextView::WhiteSpace, c) != 0)
00015 #define IsDelimiter(c)              (strchr(GTextView::Delimiters, c) != 0)
00016 #define IsDigit(c)                  ((c) >= '0' AND (c) <= '9')
00017 #define IsAlpha(c)                  (((c) >= 'a' AND (c) <= 'z') OR ((c) >= 'A' AND (c) <= 'Z'))
00018 #define IsText(c)                   (IsDigit(c) OR IsAlpha(c) OR (c) == '_')
00019 #define IsWordBoundry(c)            (strchr(GTextView::WhiteSpace, c) OR strchr(GTextView::Delimiters, c))
00020 #define UrlChar(c)                  (strchr(GTextView::UrlDelim, (c)) OR AlphaOrDigit((c)))
00021 #define EmailChar(c)                (strchr("._-:", (c)) OR AlphaOrDigit((c)))
00022 
00023 extern char16 *ConvertToCrLf(char16 *Text);
00024 
00025 // Callback API for menu
00026 class GTextViewMenu
00027 {
00028 public:
00029     virtual bool AppendItems(GSubMenu *Menu, int Base = 1000) = 0;
00030     virtual bool OnMenu(class GTextView *View, int Id) = 0;
00031 };
00032 
00033 // TextView class
00034 class GTextView : public GLayout
00035 {
00036 public:
00037     // Static
00038     static char *WhiteSpace;
00039     static char *Delimiters;
00040     static char *UrlDelim;
00041     static bool AlphaOrDigit(char c);
00042 
00044     // Properties
00045     #define _TvMenuProp(Type, Name)                     \
00046     protected:                                          \
00047         Type Name;                                      \
00048     public:                                             \
00049         virtual void Set##Name(Type i) { Name=i; }      \
00050         virtual Type Get##Name() { return Name; }
00051 
00052     _TvMenuProp(uint16, WrapAtCol)
00053     _TvMenuProp(bool, UrlDetect)
00054     _TvMenuProp(bool, ReadOnly)
00055     _TvMenuProp(uint8, WrapType)
00056     _TvMenuProp(uint8, TabSize)
00057     _TvMenuProp(bool, CrLf)
00058     _TvMenuProp(bool, AutoIndent)
00059     _TvMenuProp(COLOUR, BackColour)
00060     #undef _TvMenuProp
00061 
00063     // Object
00064     GTextView()
00065     {
00066         WrapAtCol = 0;
00067         UrlDetect = true;
00068         ReadOnly = false;
00069         WrapType = TEXTED_WRAP_REFLOW;
00070         CrLf = false;
00071         AutoIndent = true;
00072         BackColour = Rgb24(255, 255, 255);
00073     }
00074 
00076     // File
00077     virtual bool Open(char *Name, char *Cs = 0) { return false; }
00078     virtual bool Save(char *Name, char *Cs = 0) { return false; }
00079 
00081     // Find/Replace
00082     virtual bool DoFind() { return false; }
00083     virtual bool DoReplace() { return false; }
00084 
00086     // Callback API
00087     virtual GTextViewMenu *GetMenuCallback() { return 0; }
00088     virtual void SetMenuCallback(GTextViewMenu *c) {}
00089     
00091     // State / Selection
00092     
00093     // Set the cursor position, to select an area, move the cursor with Select=false
00094     // then set the other end of the region with Select=true.
00095     virtual void SetCursor(int i, bool Select, bool ForceFullUpdate = false) {}
00096 
00097     // Cursor=false means the other end of the selection if any. The cursor is alwasy
00098     // at one end of the selection.
00099     virtual int GetCursor(bool Cursor = true) { return 0; }
00100 
00101     // Selection access
00102     virtual bool HasSelection() { return false; }
00103     virtual void UnSelectAll() {}
00104     virtual void SelectWord(int From) {}
00105     virtual void SelectAll() {}
00106     virtual char *GetSelection() { return 0; }
00107 
00108     // Returns the character index at the x,y location
00109     virtual int IndexAt(int x, int y) { return 0; }
00110 
00111     // Index=-1 returns the x,y of the cursor, Index >=0 returns the specified x,y
00112     virtual void PositionAt(int &x, int &y, int Index = -1) { }
00113 
00114     virtual bool IsDirty() { return false; }
00115     virtual int GetLines() { return 0; }
00116     virtual void GetTextExtent(int &x, int &y) {}
00117 
00119     // Clipboard IO
00120     virtual bool Cut() { return false; }
00121     virtual bool Copy() { return false; }
00122     virtual bool Paste() { return false; }
00123 
00125     // Virtual events
00126     virtual void OnEscape(GKey &K) {}
00127     virtual void OnEnter(GKey &k) {}
00128     virtual void OnUrl(char *Url) {}
00129 };
00130 
00131 #endif

Generated on Wed Oct 26 14:46:50 2005 for Lgi by  doxygen 1.4.1