Laxkit  0.0.7.1
texteditbase-utf8.h
1 //
2 //
3 // The Laxkit, a windowing toolkit
4 // Please consult http://laxkit.sourceforge.net about where to send any
5 // correspondence about this software.
6 //
7 // This library is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU Library General Public
9 // License as published by the Free Software Foundation; either
10 // version 2 of the License, or (at your option) any later version.
11 //
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // Library General Public License for more details.
16 //
17 // You should have received a copy of the GNU Library General Public
18 // License along with this library; if not, write to the Free Software
19 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 //
21 // Copyright (C) 2004-2007 by Tom Lechner
22 //
23 #ifndef _LAX_TEXTEDITBASE_UTF8_H
24 #define _LAX_TEXTEDITBASE_UTF8_H
25 
26 
27 #include <lax/undo.h>
28 #include <fstream>
29 
30 #define LEFT_TAB (1<<0)
31 #define CENTER_TAB (1<<1)
32 #define RIGHT_TAB (1<<2)
33 #define CHAR_TAB (1<<3)
34 #define NUMERIC_TAB (1<<3)
35 
36 #define TEXT_LEFT (1<<0)
37 #define TEXT_CENTER (1<<1)
38 #define TEXT_RIGHT (1<<2)
39 #define TEXT_JUSTIFY (1<<3)
40 #define TEXT_JUSTIFY_RIGHT (1<<2 | 1<<3)
41 #define TEXT_JUSTIFY_CENTER (1<<1 | 1<<3)
42 #define TEXT_FORCEJUSTIFY (1<<4)
43 
44 #define TEXT_WORDWRAP (1<<5)
45 #define TEXT_READONLY (1<<6)
46 
47 #define TEXT_NLONLY (1<<7)
48 #define TEXT_CRLF (1<<9)
49 #define TEXT_LF (1<<7)
50 #define TEXT_CR (1<<8)
51 
52  // write non-chars as cntl char (such as space, '.','\' etc), cntlchar+hex, none
53 #define TEXT_CNTL_BANG (1<<10)
54 #define TEXT_CNTL_HEX (1<<11)
55 #define TEXT_CNTL_NONE (1<<12)
56 
57  // SHOWTABLINE means have a line at top of edit showing the tab stops
58  // TEXT_TABS_STOPS must be set for GetNextTab to be called
59 #define TEXT_TABS_SPACES (1<<13)
60 #define TEXT_TABS_EVEN (1<<14)
61 #define TEXT_TABS_STOPS (1<<15)
62 #define TEXT_TABS_NONE (1<<16)
63 #define TEXT_SHOWTABLINE (1<<17)
64 
65  // put little divits where space/newline/tabs are
66 #define TEXT_SHOW_WHITESPACE (1<<18)
67 
68  // default scrollers is for transient scrollers, special check for ALWAYS must be made in classes
69 #define TEXT_NOSCROLLERS (1<<19)
70 #define TEXT_SCROLLERS (1<<20 | 1<<21)
71 #define TEXT_TRANSIENT_SCROLL (1<<20 | 1<<21)
72 #define TEXT_TRANSIENT_X (1<<20)
73 #define TEXT_TRANSIENT_Y (1<<21)
74 #define TEXT_XSCROLL (1<<20)
75 #define TEXT_YSCROLL (1<<21)
76 #define TEXT_ALWAYS_SCROLLERS (1<<20 | 1<<21 | 1<<22 | 1<<23)
77 #define TEXT_ALWAYS_X (1<<22 | 1<<20)
78 #define TEXT_ALWAYS_Y (1<<23 | 1<<21)
79 
80 #define TEXT_CURS_PAST_NL (1<<24)
81 
82 namespace Laxkit {
83 
84 
85 class TextEditBaseUtf8 : virtual public Undoable
86 {
87  protected:
88  long curline,curpos,selstart,sellen;
89  int cntlmovedist;
90  int tabwidth;
91  char *thetext,*cutbuffer;
92  long textlen,maxtextmem;
93  char newline,newline2;
94  char cntlchar;
95  char modified;
96  long maxtextlen,mintextlen, maxcharswide,mincharswide, maxlines,minlines; // these must be implemented in derived classes
97  unsigned long textstyle;
98  virtual int extendtext(); // overkill?
99  virtual long nextpos(long l);
100  virtual long prevpos(long l);
101  virtual void makevalidpos(long &l);
102 
103  friend class UndoManager;
104  int undomode; //1 for add undos, or 0 for ignore undos
105  UndoManager undomanager;
106  virtual int Undo(UndoData *data); //called by undomanager
107  virtual int Redo(UndoData *data);
108  virtual int AddUndo(int type, const char *str,long len, long start,long end);
109 
110  public:
111  TextEditBaseUtf8(const char *newtext=NULL,unsigned long nstyle=0,unsigned int ncntlchar=0);
112  virtual ~TextEditBaseUtf8();
113  virtual int charwidth(unsigned int usc,int actual=0) { return 1; }
114  virtual int GetTabChar(int atpix);
115  virtual int GetNextTab(int atpix); // redefine for custom tabstops, default is even spacing with tabwidth pixels
116  virtual int GetNextTab(int atpix,int &tabtype); // defaults to LEFT_TAB, calls GetNextTab(atpix)
117 
118  virtual int inschar(unsigned int ucs,char a=1); // a==1 means put curpos after the insert
119  virtual int insstring(const char *blah,int after=0);
120  virtual int delsel();
121  virtual int delchar(int bksp); // bksp=1 del curpos-1, 0 del curpos
122  virtual int replacesel(unsigned int ucs);
123  virtual int replacesel(const char *newt=NULL,int after=0); // after=0, newt=NULL deletes
124  virtual int onlf(long pos=-1);
125  virtual int findword(long pos,long &start, long &end);
126  virtual int isword(long pos=-1);
127  virtual long findlinestart(long pos=-1);
128 
129  virtual int readonly(long pos=-1);
130  virtual int SetText(const char *newtext);
131  //virtual int SetText(std::ifstream &fromfile,long len); // file must be open, len must be accurate
132  virtual const char *GetCText();
133  virtual char *GetText();
134  virtual char *GetSelText();
135  virtual char *CutSelText(); // cuts to char *, not clipboard
136  virtual long GetSelection(long &sels,long &sele);
137  virtual int SetSelection(long newss=-2,long newse=-2); // if e==-1, sets e=textlen,e==-2 sets sels=curpos, curpos+=s
138  virtual long Getnumlines();
139  virtual long Getnlines(long s=-1,long e=-1);
140  virtual long Getcharswide(); // total # chars with letter,nonprint,tabs,etc, not actual width
141  virtual int Getpixwide(long linenum); // return pix wide of line
142  virtual int Modified(int m=1) { modified=m; return m; }
143 
144  virtual int Cut(); // default is for internal cutbuffer
145  virtual int Copy();
146  virtual int Paste();
147  virtual int Undo(); //called by anyone
148  virtual int Redo();
149 
150  virtual long WhichLine(long pos);
151  virtual long GetCurLine() { return 0; }
152  virtual long SetCurLine(long nline) { return 0; }
153  virtual long GetCurpos() { return curpos; }
154  virtual long SetCurpos(long ncurpos); // returns actual new curpos
155  virtual int SetDelimiter(char n1,char n2=0);
156 
157  virtual int Find(const char *str,int fromcurs=1);
158  virtual int Replace(const char *newstr,const char *,int which);
159  virtual int Replace(const char *newstr,int start,int end);
160 };
161 
162 } // namespace Laxkit
163 
164 
165 #endif
166 

Mon Feb 17 2014 11:52:57, Laxkit