42 #ifndef _MGUI_NCSCTRL_EDIT_H 43 #define _MGUI_NCSCTRL_EDIT_H 50 typedef struct strbuffer_s
52 unsigned char *string;
54 unsigned int blocksize;
55 unsigned int buffsize;
60 #define te_alloc malloc 62 #define te_realloc(ptr, size) realloc(ptr, size) 65 static inline void* testr_alloc (StrBuffer *txtbuff,
size_t len,
size_t blocksize)
67 txtbuff->buffsize = (len + 1) + (blocksize - (len + 1)%blocksize);
68 txtbuff->string = (
unsigned char *)te_alloc (txtbuff->buffsize);
69 txtbuff->blocksize = blocksize;
71 return txtbuff->string;
74 static inline void* testr_realloc (StrBuffer *txtbuff,
size_t len)
76 if (len + 1 > (
size_t)txtbuff->buffsize ||
77 len + 1 < (
size_t)(txtbuff->buffsize - txtbuff->blocksize)) {
79 txtbuff->buffsize = (len + 1) + (txtbuff->blocksize -
80 (len + 1)%txtbuff->blocksize);
81 txtbuff->string = (
unsigned char *)te_realloc (txtbuff->string, txtbuff->buffsize);
84 return txtbuff->string;
87 static inline void testr_free (StrBuffer *txtbuff)
90 te_free (txtbuff->string);
94 static inline void testr_setstr (StrBuffer *txtbuff,
const char *newstring,
unsigned int len)
98 if (len < 0 && !newstring)
return;
100 datalen = MIN(len, txtbuff->buffsize-1);
101 memcpy (txtbuff->string, newstring, datalen);
102 txtbuff->string[datalen] =
'\0';
103 txtbuff->txtlen = datalen;
107 static inline StrBuffer* testr_copy (StrBuffer *des, StrBuffer *src)
113 testr_alloc (des, src->txtlen, des->blocksize);
114 testr_setstr (des, (
const char *)src->string, src->txtlen);
119 static inline StrBuffer* testr_dup (StrBuffer *s1)
126 s2 = (StrBuffer *)malloc (
sizeof(s1));
128 testr_alloc (s2, s1->txtlen, s1->blocksize);
129 testr_setstr (s2, (
const char *)s1->string, s1->txtlen);
135 static inline StrBuffer* testr_dup2 (StrBuffer *s2, StrBuffer *s1)
140 testr_alloc (s2, s1->txtlen, s1->blocksize);
141 testr_setstr (s2, (
const char *)s1->string, s1->txtlen);
157 #define NCSCTRL_EDIT NCSCLASSNAME("edit") 159 #ifdef _MGNCS_USE_DBEDIT 160 #define DOUBLE_DC HDC db_dc; 165 typedef struct _mEdit
mEdit;
169 #define mEditHeader(Class) \ 170 mScrollViewHeader(Class) \ 185 typedef struct _TextAttribute
187 struct _TextAttribute* (*clone)(void);
188 void (*destroy)(void);
191 typedef struct _PasteInfo {
196 struct _PasteInfo *next;
199 typedef struct _TextCopyPaste
201 void (*addCopyInfo)(
const char* str,
int len, TextAttribute *atrr,
void *user_info);
202 void (*endCopyInfo)(void);
203 BOOL (*isEmpty)(void);
204 PasteInfo* (*getPasteInfo)(void);
207 typedef struct _UndoRedoInfo
214 struct _UndoRedoInfo * next;
217 typedef struct _TextUndoRedoInfo
219 BOOL (*pushText)(
const char* text,
int start,
int end, TextAttribute *attr,
void *user_data);
220 BOOL (*endPush)(void);
222 UndoRedoInfo* (*getUndoTop)(void);
223 UndoRedoInfo* (*getRedoTop)(void);
225 void (*popUndo)(void);
226 void (*popRedo)(void);
228 BOOL (*isUndoEmpty)(void);
229 BOOL (*isRedoEmpty)(void);
234 #define mEditClassHeader(clsName, parentClass) \ 235 mScrollViewClassHeader(clsName, parentClass) \ 236 int (*onChar)(clsName* self, int asciiCode, DWORD keyFlags); \ 237 int (*setContent)(clsName *self, const char* str, int start, int len); \ 238 void (*replaceText)(clsName *self, const char* str, int start, int len, int replaceStart, int replaceEnd); \ 239 void (*insert)(clsName *self, const char* str, int start, int len, int insertStart); \ 240 void (*append)(clsName *self, const char* str, int start, int len); \ 241 int (*getTextLength)(clsName *self); \ 242 int (*getContent)(clsName *self, char *strBuff, int bufLen, int start, int end); \ 243 int (*setTextAttr)(clsName *self, int start, int end, TextAttribute *attr); \ 244 TextAttribute* (*getTextAttr)(clsName *self, int start, int end, int *pEnd); \ 245 int (*setSel)(clsName *self, int start, int end); \ 246 int (*getSel)(clsName *self, int *pStart, int *pEnd); \ 247 void (*setMargin)(clsName *self, int left, int top, int right, int bottom); \ 248 void (*copy)(clsName *self); \ 249 void (*cut)(clsName *self); \ 250 void (*paste)(clsName *self); \ 251 TextCopyPaste * (*setCopyPaste)(clsName *self, TextCopyPaste* cp); \ 252 void (*undo)(clsName *self); \ 253 void (*redo)(clsName *self); \ 254 TextUndoRedoInfo * (*setUndoRedo)(clsName *self, TextUndoRedoInfo* ur); \ 255 BOOL (*makevisible)(clsName *self, int pos); 374 #define mEditRendererHeader(clsName, parentClass) \ 375 mScrollViewRendererHeader(clsName, parentClass) 383 struct _mEditRenderer
392 #define NCSS_EDIT_LEFT (0x0000L<<NCSS_SCRLV_SHIFT) 398 #define NCSS_EDIT_CENTER (0x0001L<<NCSS_SCRLV_SHIFT) 404 #define NCSS_EDIT_RIGHT (0x0002L<<NCSS_SCRLV_SHIFT) 410 #define NCSS_EDIT_UPPERCASE (0x0004L<<NCSS_SCRLV_SHIFT) 416 #define NCSS_EDIT_LOWERCASE (0x0008L<<NCSS_SCRLV_SHIFT) 422 #define NCSS_EDIT_NOHIDESEL (0x0010L<<NCSS_SCRLV_SHIFT) 428 #define NCSS_EDIT_READONLY (0x0020L<<NCSS_SCRLV_SHIFT) 434 #define NCSS_EDIT_BASELINE (0x0040L<<NCSS_SCRLV_SHIFT) 436 #define NCSS_EDIT_SHIFT (NCSS_SCRLV_SHIFT+8) 477 #ifdef _MGNCS_USE_DBEDIT 478 static inline HDC mEdit_getDC(
mEdit *
self)
481 SelectClipRect(self->db_dc, NULL);
482 SelectFont(self->db_dc, GetWindowFont(self->hwnd));
486 return GetClientDC(self->hwnd);
489 static inline void mEdit_releaseDC(
mEdit *
self, HDC hdc)
491 if (self->db_dc == 0 || self->db_dc != hdc)
495 static inline HDC mEdit_getDC(
mEdit *
self)
497 return GetClientDC(self->hwnd);
500 static inline void mEdit_releaseDC(
mEdit *
self, HDC hdc)
505 #define GETDC(self) mEdit_getDC((mEdit*)self) 506 #define RELEASEDC(self, hdc) mEdit_releaseDC((mEdit*)self, hdc)
the edit struct of edit control, derived from mScrollView.
Edit class's Renderer interface, derived from mScrollViewRenderer.
mEditProp
the Property of edit
the VTable of mEdit, derived from mScrollViewClass.
Get/Set the position of charactor.
MGNCS_EXPORT mEditClass g_stmEditCls
the instance of mEditClass
Get/Set the maximum length of text.