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