00001
00019 #ifndef _MGUI_NCSCTRL_EDIT_H
00020 #define _MGUI_NCSCTRL_EDIT_H
00021
00022 #ifdef __cplusplus
00023 extern "C" {
00024 #endif
00025
00026
00027 typedef struct strbuffer_s
00028 {
00029 unsigned char *string;
00030 unsigned int txtlen;
00031 unsigned int blocksize;
00032 unsigned int buffsize;
00033 } StrBuffer;
00034
00035
00036
00037 #define te_alloc malloc
00038 #define te_free free
00039 #define te_realloc(ptr, size, cpysize) realloc(ptr, size)
00040
00041
00042 static inline void* testr_alloc (StrBuffer *txtbuff, size_t len, size_t blocksize)
00043 {
00044 txtbuff->buffsize = (len + 1) + (blocksize - (len + 1)%blocksize);
00045 txtbuff->string = (unsigned char *)te_alloc (txtbuff->buffsize);
00046 txtbuff->blocksize = blocksize;
00047
00048 return txtbuff->string;
00049 }
00050
00051 static inline void* testr_realloc (StrBuffer *txtbuff, size_t len)
00052 {
00053 if (len + 1 > txtbuff->buffsize ||
00054 len + 1 < txtbuff->buffsize - txtbuff->blocksize) {
00055
00056 size_t old_size;
00057 old_size = txtbuff->buffsize;
00058 txtbuff->buffsize = (len + 1) + (txtbuff->blocksize -
00059 (len + 1)%txtbuff->blocksize);
00060 txtbuff->string = (unsigned char *)te_realloc (txtbuff->string, txtbuff->buffsize, old_size);
00061 }
00062
00063 return txtbuff->string;
00064 }
00065
00066 static inline void testr_free (StrBuffer *txtbuff)
00067 {
00068 if (txtbuff) {
00069 te_free (txtbuff->string);
00070 }
00071 }
00072
00073 static inline void testr_setstr (StrBuffer *txtbuff, const char *newstring, unsigned int len)
00074 {
00075 int datalen;
00076
00077 if (len < 0 && !newstring) return;
00078
00079 datalen = MIN(len, txtbuff->buffsize-1);
00080 memcpy (txtbuff->string, newstring, datalen);
00081 txtbuff->string[datalen] = '\0';
00082 txtbuff->txtlen = datalen;
00083 }
00084
00085
00086 static inline StrBuffer* testr_copy (StrBuffer *des, StrBuffer *src)
00087 {
00088 if (!des || !src)
00089 return NULL;
00090
00091 testr_free (des);
00092 testr_alloc (des, src->txtlen, des->blocksize);
00093 testr_setstr (des, (const char *)src->string, src->txtlen);
00094 return des;
00095 }
00096
00097
00098 static inline StrBuffer* testr_dup (StrBuffer *s1)
00099 {
00100 StrBuffer *s2;
00101
00102 if (!s1)
00103 return NULL;
00104
00105 s2 = (StrBuffer *)malloc (sizeof(s1));
00106 if (s2) {
00107 testr_alloc (s2, s1->txtlen, s1->blocksize);
00108 testr_setstr (s2, (const char *)s1->string, s1->txtlen);
00109 }
00110 return s2;
00111 }
00112
00113
00114 static inline StrBuffer* testr_dup2 (StrBuffer *s2, StrBuffer *s1)
00115 {
00116 if (!s1 || !s2)
00117 return NULL;
00118
00119 testr_alloc (s2, s1->txtlen, s1->blocksize);
00120 testr_setstr (s2, (const char *)s1->string, s1->txtlen);
00121 return s2;
00122 }
00123
00124
00125
00126
00132
00133
00134
00135
00136 #define NCSCTRL_EDIT NCSCLASSNAME("edit")
00137
00138 #ifdef _MGNCS_USE_DBEDIT
00139 #define DOUBLE_DC HDC db_dc;
00140 #else
00141 #define DOUBLE_DC
00142 #endif
00143
00144 typedef struct _mEdit mEdit;
00145 typedef struct _mEditClass mEditClass;
00146 typedef struct _mEditRenderer mEditRenderer;
00147
00148 #define mEditHeader(Class) \
00149 mScrollViewHeader(Class) \
00150 DOUBLE_DC
00151
00158 struct _mEdit
00159 {
00160 mEditHeader(mEdit)
00161 };
00162
00163
00164 typedef struct _TextAttribute
00165 {
00166 struct _TextAttribute* (*clone)(void);
00167 void (*destroy)(void);
00168 }TextAttribute;
00169
00170 typedef struct _PasteInfo {
00171 char *str;
00172 int len;
00173 TextAttribute *attr;
00174 void *user_info;
00175 struct _PasteInfo *next;
00176 }PasteInfo;
00177
00178 typedef struct _TextCopyPaste
00179 {
00180 void (*addCopyInfo)(const char* str, int len, TextAttribute *atrr, void *user_info);
00181 void (*endCopyInfo)(void);
00182 BOOL (*isEmpty)(void);
00183 PasteInfo* (*getPasteInfo)(void);
00184 }TextCopyPaste;
00185
00186 typedef struct _UndoRedoInfo
00187 {
00188 char *text;
00189 int start;
00190 int end;
00191 TextAttribute *attr;
00192 void *user_data;
00193 struct _UndoRedoInfo * next;
00194 } UndoRedoInfo;
00195
00196 typedef struct _TextUndoRedoInfo
00197 {
00198 BOOL (*pushText)(const char* text, int start, int end, TextAttribute *attr, void *user_data);
00199 BOOL (*endPush)(void);
00200
00201 UndoRedoInfo* (*getUndoTop)(void);
00202 UndoRedoInfo* (*getRedoTop)(void);
00203
00204 void (*popUndo)(void);
00205 void (*popRedo)(void);
00206
00207 BOOL (*isUndoEmpty)(void);
00208 BOOL (*isRedoEmpty)(void);
00209
00210 void (*empty)(void);
00211 }TextUndoRedoInfo;
00212
00213 #define mEditClassHeader(clsName, parentClass) \
00214 mScrollViewClassHeader(clsName, parentClass) \
00215 int (*onChar)(clsName* self, int asciiCode, DWORD keyFlags); \
00216 int (*setContent)(clsName *self, const char* str, int start, int len); \
00217 void (*replaceText)(clsName *self, const char* str, int start, int len, int replaceStart, int replaceEnd); \
00218 void (*insert)(clsName *self, const char* str, int start, int len, int insertStart); \
00219 void (*append)(clsName *self, const char* str, int start, int len); \
00220 int (*getTextLength)(clsName *self); \
00221 int (*getContent)(clsName *self, char *strBuff, int bufLen, int start, int end); \
00222 int (*setTextAttr)(clsName *self, int start, int end, TextAttribute *attr); \
00223 TextAttribute* (*getTextAttr)(clsName *self, int start, int end, int *pEnd); \
00224 int (*setSel)(clsName *self, int start, int end); \
00225 int (*getSel)(clsName *self, int *pStart, int *pEnd); \
00226 void (*setMargin)(clsName *self, int left, int top, int right, int bottom); \
00227 void (*copy)(clsName *self); \
00228 void (*cut)(clsName *self); \
00229 void (*paste)(clsName *self); \
00230 TextCopyPaste * (*setCopyPaste)(clsName *self, TextCopyPaste* cp); \
00231 void (*undo)(clsName *self); \
00232 void (*redo)(clsName *self); \
00233 TextUndoRedoInfo * (*setUndoRedo)(clsName *self, TextUndoRedoInfo* ur); \
00234 BOOL (*makevisible)(clsName *self, int pos);
00235
00339 struct _mEditClass
00340 {
00341 mEditClassHeader(mEdit, mScrollView)
00342 };
00343
00350 MGNCS_EXPORT extern mEditClass g_stmEditCls;
00351
00352
00353 #define mEditRendererHeader(clsName, parentClass) \
00354 mScrollViewRendererHeader(clsName, parentClass)
00355
00362 struct _mEditRenderer
00363 {
00364 mEditRendererHeader(mEdit, mScrollView)
00365 };
00366
00371 #define NCSS_EDIT_LEFT (0x0000L<<NCSS_SCRLV_SHIFT)
00372
00377 #define NCSS_EDIT_CENTER (0x0001L<<NCSS_SCRLV_SHIFT)
00378
00383 #define NCSS_EDIT_RIGHT (0x0002L<<NCSS_SCRLV_SHIFT)
00384
00389 #define NCSS_EDIT_UPPERCASE (0x0004L<<NCSS_SCRLV_SHIFT)
00390
00395 #define NCSS_EDIT_LOWERCASE (0x0008L<<NCSS_SCRLV_SHIFT)
00396
00401 #define NCSS_EDIT_NOHIDESEL (0x0010L<<NCSS_SCRLV_SHIFT)
00402
00407 #define NCSS_EDIT_READONLY (0x0020L<<NCSS_SCRLV_SHIFT)
00408
00413 #define NCSS_EDIT_BASELINE (0x0040L<<NCSS_SCRLV_SHIFT)
00414
00415 #define NCSS_EDIT_SHIFT (NCSS_SCRLV_SHIFT+8)
00416
00417
00418
00423 enum mEditProp
00424 {
00431 NCSP_EDIT_LIMITTEXT = NCSP_SCRLV_MAX + 1,
00438 NCSP_EDIT_CARETPOS ,
00439 NCSP_EDIT_MAX
00440 };
00441
00442
00444 enum mEditNotify
00445 {
00446 NCSN_EDIT_SETFOCUS = NCSN_ITEMV_SETFOCUS,
00447 NCSN_EDIT_KILLFOCUS = NCSN_ITEMV_KILLFOCUS,
00448 NCSN_EDIT_CHANGE = NCSN_SCRLV_MAX + 1,
00449 NCSN_EDIT_CONTCHANGED,
00450 NCSN_EDIT_UPDATE,
00451 NCSN_EDIT_SELCHANGED,
00452 NCSN_EDIT_MAXTEXT,
00453 NCSN_EDIT_MAX
00454 };
00455
00456 #ifdef _MGNCS_USE_DBEDIT
00457 static inline HDC mEdit_getDC(mEdit *self)
00458 {
00459 if (self->db_dc) {
00460 SelectClipRect(self->db_dc, NULL);
00461 SelectFont(self->db_dc, GetWindowFont(self->hwnd));
00462 return self->db_dc;
00463 }
00464 else
00465 return GetClientDC(self->hwnd);
00466 }
00467
00468 static inline void mEdit_releaseDC(mEdit *self, HDC hdc)
00469 {
00470 if (self->db_dc == 0 || self->db_dc != hdc)
00471 ReleaseDC(hdc);
00472 }
00473 #else
00474 static inline HDC mEdit_getDC(mEdit *self)
00475 {
00476 return GetClientDC(self->hwnd);
00477 }
00478
00479 static inline void mEdit_releaseDC(mEdit *self, HDC hdc)
00480 {
00481 ReleaseDC(hdc);
00482 }
00483 #endif
00484 #define GETDC(self) mEdit_getDC((mEdit*)self)
00485 #define RELEASEDC(self, hdc) mEdit_releaseDC((mEdit*)self, hdc)
00486
00489 #ifdef __cplusplus
00490 }
00491 #endif
00492
00493 #endif
00494
00495