54 #ifndef _MGUI_NCSCTRL_EDIT_H
55 #define _MGUI_NCSCTRL_EDIT_H
62 typedef struct strbuffer_s
64 unsigned char *string;
66 unsigned int blocksize;
67 unsigned int buffsize;
72 #define te_alloc malloc
74 #define te_realloc(ptr, size) realloc(ptr, size)
77 static inline void* testr_alloc (StrBuffer *txtbuff,
size_t len,
size_t blocksize)
79 txtbuff->buffsize = (len + 1) + (blocksize - (len + 1)%blocksize);
80 txtbuff->string = (
unsigned char *)te_alloc (txtbuff->buffsize);
81 txtbuff->blocksize = blocksize;
83 return txtbuff->string;
86 static inline void* testr_realloc (StrBuffer *txtbuff,
size_t len)
88 if (len + 1 > (
size_t)txtbuff->buffsize ||
89 len + 1 < (
size_t)(txtbuff->buffsize - txtbuff->blocksize)) {
91 txtbuff->buffsize = (len + 1) + (txtbuff->blocksize -
92 (len + 1)%txtbuff->blocksize);
93 txtbuff->string = (
unsigned char *)te_realloc (txtbuff->string, txtbuff->buffsize);
96 return txtbuff->string;
99 static inline void testr_free (StrBuffer *txtbuff)
102 te_free (txtbuff->string);
106 static inline void testr_setstr (StrBuffer *txtbuff,
const char *newstring,
unsigned int len)
110 if (len < 0 && !newstring)
return;
112 datalen = MIN(len, txtbuff->buffsize-1);
113 memcpy (txtbuff->string, newstring, datalen);
114 txtbuff->string[datalen] =
'\0';
115 txtbuff->txtlen = datalen;
119 static inline StrBuffer* testr_copy (StrBuffer *des, StrBuffer *src)
125 testr_alloc (des, src->txtlen, des->blocksize);
126 testr_setstr (des, (
const char *)src->string, src->txtlen);
131 static inline StrBuffer* testr_dup (StrBuffer *s1)
138 s2 = (StrBuffer *)malloc (
sizeof(s1));
140 testr_alloc (s2, s1->txtlen, s1->blocksize);
141 testr_setstr (s2, (
const char *)s1->string, s1->txtlen);
147 static inline StrBuffer* testr_dup2 (StrBuffer *s2, StrBuffer *s1)
152 testr_alloc (s2, s1->txtlen, s1->blocksize);
153 testr_setstr (s2, (
const char *)s1->string, s1->txtlen);
169 #define NCSCTRL_EDIT NCSCLASSNAME("edit")
171 #ifdef _MGNCS_USE_DBEDIT
172 #define DOUBLE_DC HDC db_dc;
177 typedef struct _mEdit
mEdit;
181 #define mEditHeader(Class) \
182 mScrollViewHeader(Class) \
197 typedef struct _TextAttribute
199 struct _TextAttribute* (*clone)(void);
200 void (*destroy)(void);
203 typedef struct _PasteInfo {
208 struct _PasteInfo *next;
211 typedef struct _TextCopyPaste
213 void (*addCopyInfo)(
const char* str,
int len, TextAttribute *atrr,
void *user_info);
214 void (*endCopyInfo)(void);
215 BOOL (*isEmpty)(void);
216 PasteInfo* (*getPasteInfo)(void);
219 typedef struct _UndoRedoInfo
226 struct _UndoRedoInfo * next;
229 typedef struct _TextUndoRedoInfo
231 BOOL (*pushText)(
const char* text,
int start,
int end, TextAttribute *attr,
void *user_data);
232 BOOL (*endPush)(void);
234 UndoRedoInfo* (*getUndoTop)(void);
235 UndoRedoInfo* (*getRedoTop)(void);
237 void (*popUndo)(void);
238 void (*popRedo)(void);
240 BOOL (*isUndoEmpty)(void);
241 BOOL (*isRedoEmpty)(void);
246 #define mEditClassHeader(clsName, parentClass) \
247 mScrollViewClassHeader(clsName, parentClass) \
248 int (*onChar)(clsName* self, int asciiCode, DWORD keyFlags); \
249 int (*setContent)(clsName *self, const char* str, int start, int len); \
250 void (*replaceText)(clsName *self, const char* str, int start, int len, int replaceStart, int replaceEnd); \
251 void (*insert)(clsName *self, const char* str, int start, int len, int insertStart); \
252 void (*append)(clsName *self, const char* str, int start, int len); \
253 int (*getTextLength)(clsName *self); \
254 int (*getContent)(clsName *self, char *strBuff, int bufLen, int start, int end); \
255 int (*setTextAttr)(clsName *self, int start, int end, TextAttribute *attr); \
256 TextAttribute* (*getTextAttr)(clsName *self, int start, int end, int *pEnd); \
257 int (*setSel)(clsName *self, int start, int end); \
258 int (*getSel)(clsName *self, int *pStart, int *pEnd); \
259 void (*setMargin)(clsName *self, int left, int top, int right, int bottom); \
260 void (*copy)(clsName *self); \
261 void (*cut)(clsName *self); \
262 void (*paste)(clsName *self); \
263 TextCopyPaste * (*setCopyPaste)(clsName *self, TextCopyPaste* cp); \
264 void (*undo)(clsName *self); \
265 void (*redo)(clsName *self); \
266 TextUndoRedoInfo * (*setUndoRedo)(clsName *self, TextUndoRedoInfo* ur); \
267 BOOL (*makevisible)(clsName *self, int pos);
386 #define mEditRendererHeader(clsName, parentClass) \
387 mScrollViewRendererHeader(clsName, parentClass)
395 struct _mEditRenderer
404 #define NCSS_EDIT_LEFT (0x0000L<<NCSS_SCRLV_SHIFT)
410 #define NCSS_EDIT_CENTER (0x0001L<<NCSS_SCRLV_SHIFT)
416 #define NCSS_EDIT_RIGHT (0x0002L<<NCSS_SCRLV_SHIFT)
422 #define NCSS_EDIT_UPPERCASE (0x0004L<<NCSS_SCRLV_SHIFT)
428 #define NCSS_EDIT_LOWERCASE (0x0008L<<NCSS_SCRLV_SHIFT)
434 #define NCSS_EDIT_NOHIDESEL (0x0010L<<NCSS_SCRLV_SHIFT)
440 #define NCSS_EDIT_READONLY (0x0020L<<NCSS_SCRLV_SHIFT)
446 #define NCSS_EDIT_BASELINE (0x0040L<<NCSS_SCRLV_SHIFT)
448 #define NCSS_EDIT_SHIFT (NCSS_SCRLV_SHIFT+8)
489 #ifdef _MGNCS_USE_DBEDIT
490 static inline HDC mEdit_getDC(
mEdit *
self)
493 SelectClipRect(self->db_dc, NULL);
494 SelectFont(self->db_dc, GetWindowFont(self->hwnd));
498 return GetClientDC(self->hwnd);
501 static inline void mEdit_releaseDC(
mEdit *
self, HDC hdc)
503 if (self->db_dc == 0 || self->db_dc != hdc)
507 static inline HDC mEdit_getDC(
mEdit *
self)
509 return GetClientDC(self->hwnd);
512 static inline void mEdit_releaseDC(
mEdit *
self, HDC hdc)
517 #define GETDC(self) mEdit_getDC((mEdit*)self)
518 #define RELEASEDC(self, hdc) mEdit_releaseDC((mEdit*)self, hdc)