mGNCS API Reference  v1.2.0
A new control set and a new framework for MiniGUI apps
mtexteditbase.h
Go to the documentation of this file.
1 
42 #ifndef TEXTEDITBASE_H
43 #define TEXTEDITBASE_H
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
49 DECLARE_INTERFACE(ITextBufferObserver)
50 DECLARE_INTERFACE(ITextIterator)
51 DECLARE_INTERFACE(ITextBuffer)
52 DECLARE_INTERFACE(ITextRender)
53 DECLARE_INTERFACE(ITextLayoutContext)
54 DECLARE_INTERFACE(ITextLayout)
55 
56 //define the interface ITextBufferObserver
57 #define ITextBufferObserverHeader(Interface,ClassImpl) \
58  IInterfaceHeader(Interface, ClassImpl) \
59  void (*onTextChanged)(ClassImpl*, int changedBegin, int delCount, int insertCount);
60 
61 DEFINE_INTERFACE(ITextBufferObserver)
62 
63 
64 // ITextBuffer
66 #define ITextBufferHeader(Interface, ClassImpl) \
67  IInterfaceHeader(Interface, ClassImpl) \
68  /*replace */ \
69  int (*replace)(ClassImpl *self, \
70  int at, int count, \
71  const char* str, \
72  int str_count/*=-1*/); \
73  int (*getText)(ClassImpl* self, \
74  int at /*=NULL*/, \
75  char* str_buff, \
76  int str_count); \
77  int (*getCount)(ClassImpl* self); \
78  ITextIterator* (*getAt)(ClassImpl* self, \
79  int charIndex); \
80  BOOL (*addObserver)(ClassImpl*, ITextBufferObserver* observer); \
81  BOOL (*removeObserver)(ClassImpl*, ITextBufferObserver* observer); \
82  int (*find)(ClassImpl*self, int start, const char* str, int str_count); \
83  int (*setCase)(ClassImpl *self, int start, int len, BOOL bupper);
84 
85 DEFINE_INTERFACE(ITextBuffer)
86 
87 // ITextIterator
89 #define ITextIteratorHeader(Interface, ClassImpl) \
90  IInterfaceHeader(Interface, ClassImpl) \
91  void (*nextChar)(ClassImpl* self); \
92  void (*prevChar)(ClassImpl* self); \
93  /*get current index of charactor*/ \
94  int (*index)(ClassImpl* self); \
95  /*reset the iterator*/ \
96  int (*reset)(ClassImpl* self, int charIndex); \
97  /*is end*/ \
98  BOOL (*isEnd)(ClassImpl* self); \
99  /*is head*/ \
100  BOOL (*isHead)(ClassImpl* self); \
101  /*get the charactor as much as more*/ \
102  const char* (*getMore)(ClassImpl*,int *pTextLen, \
103  int *pVisibleTextLen, BOOL bAutoSkip/*=TRUE*/); \
104  /*reference one*/ \
105  ITextIterator* (*reference)(ClassImpl* self); \
106  /*comapre */ \
107  int (*diff)(ClassImpl*, const ITextIterator* another); \
108  /*is in a range*/ \
109  int (*inRange)(ClassImpl*, const ITextIterator* left, \
110  const ITextIterator* right); \
111  /*release me*/ \
112  void (*releaseIterator)(ClassImpl* self); \
113  /*text Render*/ \
114  ITextRender* (*getTextRender)(ClassImpl* self); \
115  /*getCharType*/ \
116  int (*getCharType)(ClassImpl* self, int offset);
117 
118 enum {
119  TI_OUTOFRANGE = -1,
120  TI_VISIBILE_CHAR = 0, /*visible char*/
121  TI_LINERETURN, /*line return*/
122  TI_EOF /* End OF File */
123 };
124 
125 
126 DEFINE_INTERFACE(ITextIterator)
127 
128 //define the return value of inRange
129 enum {
130  TXTITER_RANGE_INVALID = -1,
131  TXTITER_RANGE_IN = 0, // left < self < right
132  TXTITER_RANGE_LEFTEDGE , // left == self
133  TXTITER_RANGE_RIGHTEDGE , // right == self
134  TXTITER_RANGE_LEFTOUT ,
135  TXTITER_RANGE_RIGHTOUT
136 };
137 
138 
140 // ITextRender
141 #define ITextRenderHeader(Interface, ClassImpl) \
142  IInterfaceHeader(Interface, ClassImpl) \
143  int (*calc)(ClassImpl* self, HDC hdc, \
144  ITextIterator* begin, \
145  int str_count, int* ptext_count, \
146  const RECT* maxBound, RECT *bounds); \
147  int (*draw)(ClassImpl* self, HDC hdc, int x, int y, \
148  ITextIterator* begin, int str_count); \
149  int (*getTextByteLen)(ClassImpl* self, HDC hdc, \
150  ITextIterator* it, /*in out*/int *ptext_index); \
151  int (*getTextCount)(ClassImpl* self, HDC hdc, \
152  ITextIterator* it, /*in out*/int* pstr_len);\
153  int (*getCaretSize)(ClassImpl* self, HDC hdc, \
154  ITextIterator* it, int *pWidth, int *pHeight);
155 
156 DEFINE_INTERFACE(ITextRender)
157 
158 
159 //Interface for ITextLayout
161 
162 #define ITextLayoutContextHeader(Interface, ClassImpl) \
163  IInterfaceHeader(Interface, ClassImpl) \
164  int (*getMetrics)(ClassImpl*,int type); \
165  void (*setupDC)(ClassImpl*, HDC hdc); \
166  void (*beginSelection)(ClassImpl*,HDC hdc); \
167  void (*endSelection)(ClassImpl*, HDC hdc); \
168  HDC (*getDC)(ClassImpl*); \
169  void (*contentPosToDCPos)(ClassImpl*, HDC hdc, \
170  int *px, int *py); \
171  void (*releaseDC)(ClassImpl*, HDC hdc); \
172  void (*updateCaret)(ClassImpl*); \
173  void (*update)(ClassImpl*, BOOL);
174 
175 enum {
176  TEXTMETRICS_MAXWIDTH,
177  TEXTMETRICS_MAXHEIGHT,
178  TEXTMETRICS_LINESPACE,
179  TEXTMETRICS_DEFLINEHEIGHT
180 };
181 
182 DEFINE_INTERFACE(ITextLayoutContext)
184 //ITextLayout
185 typedef void (*CB_LINE_PROC)(mObject* self, int x, int y, int width, int height, int lineNo, void* user_param);
186 typedef BOOL (*CB_NODE_PROC)(mObject* self, mObject* cur_node, void* user_param);
187 
188 #define ITextLayoutHeader(Interface, ClassImpl) \
189  ITextBufferObserverHeader(Interface, ClassImpl) \
190  /*get the text iterator by pos*/ \
191  int (*getCharIndex)(ClassImpl*, int *px, int *py, \
192  int *plineHeight/*=NULL*/, int *ptext_index); \
193  /*get the pos by text iterator */ \
194  int (*getCharPos)(ClassImpl*, int index, int *px, \
195  int *py, int *plineHeight, BOOL bAsText); \
196  /*get the size of the text */ \
197  BOOL (*getTextBoundSize)(ClassImpl* self, int *cx, int *cy); \
198  BOOL (*setCursor)(ClassImpl* self, int index, BOOL isSel); \
199  int (*setCursorPos)(ClassImpl* self, int x, int y, BOOL isSel); \
200  int (*getCursor)(ClassImpl*, int *px, int *py, int *cursor_h, BOOL isSel); \
201  void (*draw)(ClassImpl* self, HDC hdc, int x, int y, int width, int height);\
202  int (*getLineHeight)(ClassImpl* self, int index); \
203  void (*reset)(ClassImpl *self); \
204  int (*textCount2Len)(ClassImpl*, int text_index, int text_count, int *plen);\
205  int (*textLen2Count)(ClassImpl*, int str_index, int str_len, int*text_count,\
206  int *poutstr_index, int *poutstr_count); \
207  void (*foreachLine)(ClassImpl*, int x, int y, int maxWidth, int maxHeight, \
208  CB_LINE_PROC proc, mObject* proc_owner, void* user_param); \
209  void (*travelNode)(ClassImpl*, CB_NODE_PROC proc, mObject* proc_owner, void* user_param); \
210  PLOGFONT (*getReleatedFont)(ClassImpl*, int idx, BOOL isText); \
211  int (*getParaByIndex)(ClassImpl* self, int index, int *pcol, BOOL bText); \
212  int (*getLineByIndex)(ClassImpl* self, int index, int* pcol, BOOL bText); \
213  int (*getIndexByPara)(ClassImpl* self, int paraNo, int col, BOOL* outOfRange, BOOL bText); \
214  int (*getIndexByLine)(ClassImpl* self, int lineIdx, int col, BOOL* outOfRange, BOOL bText);
215 
216 DEFINE_INTERFACE(ITextLayout)
217 
218 #ifdef __cplusplus
219 }
220 #endif
221 
222 #endif
223 
224 
225 
the Object struct