mGNCS API Reference  v1.2.5
A new control set and a new framework for MiniGUI apps
mtextedit.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 _MGUI_TEXT_EDIT_H
55 #define _MGUI_TEXT_EDIT_H
56 
57 #if defined(_MGNCSCTRL_TEXTEDITOR) || (defined(_MGCTRL_TEXTEDIT) && defined(_MGCTRL_TEXTEDIT_USE_NEW_IMPL))
58 
59 #ifdef __cplusplus
60 extern "C" {
61 #endif
62 
63 /* enable ES_TITLE stle of TEXTEDIT control */
64 #define _MGHAVE_TEXTEDITTITLE 0
65 
66 DECLARE_OBJECT(mTextBuffer)
67 DECLARE_OBJECT(mTextIterator)
68 DECLARE_OBJECT(mTextLayout)
69 DECLARE_OBJECT(mTextLayoutNode)
70 DECLARE_OBJECT(mTextRender)
71 
72 // mTextBuffer
74 typedef struct _TextBufferObserverNode {
75  ITextBufferObserver* observer;
76  struct _TextBufferObserverNode* next;
77 }mTextBufferObserverNode;
78 
79 #define mTextBufferHeader(Clss) \
80  mObjectHeader(Clss) \
81  INTERFACE(ITextBuffer) \
82  char * buffer; \
83  int max_size; \
84  int char_len; \
85  mTextBufferObserverNode* observers;
86 
87 #define mTextBufferClassHeader(Clss, Super) \
88  mObjectClassHeader(Clss, Super) \
89  ITextBufferHeader(ITextBuffer, Clss)
90 
91 //mTextBuffer_construct(const char* str = NULL, const char* str_len = 0)
92 
93 DEFINE_OBJECT(mTextBuffer, mObject)
94 
95 // mTextIterator
97 #define mTextIteratorHeader(Clss) \
98  mObjectHeader(Clss) \
99  INTERFACE(ITextIterator) \
100  mTextBuffer* buffer; \
101  int index;
102 
103 #define mTextIteratorClassHeader(Clss, Super) \
104  mObjectClassHeader(Clss, Super) \
105  ITextIteratorHeader(ITextIterator, Clss)
106 
107 //mTextIterator_construct(mTextBuffer*, int index)
108 
109 DEFINE_OBJECT(mTextIterator, mObject)
110 
111 // mTextLayout
113 #define mTextLayoutHeader(Clss) \
114  mCommBTreeHeader(Clss) \
115  INTERFACE(ITextLayout) \
116  ITextBuffer * text_buffer; \
117  int cursor; \
118  int cursor_x, cursor_y; \
119  int cursor_height; \
120  int text_cursor; \
121  int sel_begin; \
122  int sel_begin_x, sel_begin_y;\
123  int sel_begin_height; \
124  int text_sel_begin; \
125  ITextLayoutContext* context; \
126  PCLIPRGN dirty_area; \
127  int old_height, new_height; //height changed include
128 
129 #define mTextLayoutClassHeader(Clss, Super) \
130  mCommBTreeClassHeader(Clss, Super) \
131  ITextLayoutHeader(ITextLayout, Clss)
132 
133 DEFINE_OBJECT(mTextLayout, mCommBTree)
134 
135 //mTextLayoutNode
136 
137 #define mTextLayoutNodeHeader(Clss) \
138  mCommBTreeNodeHeader(Clss) \
139  int str_count; \
140  int text_count; \
141  int width, height;
142 
143 #define mTextLayoutNodeClassHeader(Clss, Super) \
144  mCommBTreeNodeClassHeader(Clss, Super)
145 
146 DEFINE_OBJECT(mTextLayoutNode,mCommBTreeNode)
147 
148 //mTextRender
150 
151 #define mTextRenderHeader(Clss) \
152  mObjectHeader(Clss) \
153  INTERFACE(ITextRender)
154 
155 #define mTextRenderClassHeader(Clss, Super) \
156  mObjectClassHeader(Clss, Super) \
157  ITextRenderHeader(ITextRender, Clss)
158 
159 DEFINE_OBJECT(mTextRender,mObject)
160 
161 enum {
162  NCS_TXTRDR_TEXT = 0
163 };
164 
165 ITextRender* GetTextRender(int type);
166 
167 /* mTextEditor object*/
168 DECLARE_OBJECT(mTextEditor)
169 
170 
175 #ifndef __MINIGUI_LIB__
176 
180 #define NCSCTRL_TEXTEDITOR NCSCLASSNAME("texteditor")
181 #endif
182 
183 /* define the flag of TextEditor */
184 #define NCS_TEF_REPLACE_MODE 0x010000
185 #define NCS_TEF_HAS_PAINTED 0x020000
186 #define mTextEditor_isReplaceMode(self) \
187  ((self)->flags&NCS_TEF_REPLACE_MODE)
188 #define mTextEditor_hasPainted(self) \
189  ((self)->flags&NCS_TEF_HAS_PAINTED)
190 
191 
192 #ifdef _MGHAVE_TEXTEDITTITLE
193 #define TITLE_HEADER \
194  int title_idx, title_text_idx; \
195  int title_x, title_y, title_last_height; \
196  int title_paracount; \
197  int title_last_para_text_index; \
198  int title_linecount; \
199  int title_last_line_text_index;
200 
201 #define TITLE_CLASS_HEADER(Clss) \
202  void (*setTitle)(Clss*, const char* buff, int len); \
203  int (*getTitle)(Clss*, char* buff, int max);
204 
205 
206 #else
207 #define TITLE_HEADER
208 #define TITLE_CLASS_HEADER(Clss)
209 #endif
210 
211 //mTextEditor_construct(HWND hwnd)
240 #define mTextEditorHeader(Clss) \
241  mWidgetHeader(Clss) \
242  INTERFACE(ITextLayoutContext) \
243  mTextBuffer *textBuffer; \
244  mTextLayout *textLayout; \
245  int visWidth, visHeight;\
246  int offX, offY; \
247  int hardLimit; \
248  unsigned int flags; \
249  int caretWidth; \
250  int caretHeight; \
251  unsigned short scrollBarMode; \
252  unsigned int scrollHStep; \
253  unsigned int scrollVStep; \
254  RECT margins; \
255  int oldOffX, oldOffY; \
256  TITLE_HEADER
257 
258 
344 #define mTextEditorClassHeader(Clss, Super) \
345  mWidgetClassHeader(Clss, Super) \
346  ITextLayoutContextHeader(ITextLayoutContext, Clss) \
347  int (*onChar)(Clss*, int asciiCode, DWORD keyFlags); \
348  BOOL (*onFontChanged)(Clss*); \
349  int (*getInvalidBkgnd)(Clss*, RECT *prc); \
350  int (*onLButtonDBClk)(Clss*, int x, int y, DWORD keyFlags); \
351  void (*onCSizeChanged)(Clss*, int cliWidth, int cliHeight); \
352  void (*onSetFocus)(Clss*, HWND oldActiveWnd, int lParam); \
353  void (*onKillFocus)(Clss*, HWND newActiveWnd, int lParam); \
354  void (*onHScroll)(Clss*, int code, int mouseX); \
355  void (*onVScroll)(Clss*, int code, int mouseY); \
356  \
357  int (*getParaText)(Clss*, int index, int start, int len, char* buffer); \
358  int (*getLineText)(Clss*, int index, int start, int len, char* buffer); \
359  int (*getParaLength)(Clss*, int index, int *startPos); \
360  int (*getParaLengthInMChar)(Clss*, int paraNo, int *startPos); \
361  int (*getLineLength)(Clss*, int lineNo, int *startPos, BOOL bMChar); \
362  int (*getParaNum)(Clss*); \
363  int (*setText)(Clss*, const char* text); \
364  int (*insertText)(Clss*, const char* text, int len); \
365  int (*getText)(Clss*, char* text, int len); \
366  int (*getTextLen)(Clss*); \
367  BOOL (*enableCaret)(Clss*, BOOL enable); \
368  int (*setCaretPosByPara)(Clss*, unsigned int paraIdx, unsigned int offChar, \
369  BOOL isSel); \
370  int (*getCaretPosByPara)(Clss*, int *paraIdx, int *offChar, \
371  int *height, BOOL isSel); \
372  int (*setCaretPosByLine)(Clss*, unsigned int lineIdx, unsigned int offChar, \
373  BOOL isSel); \
374  int (*getCaretPosByLine)(Clss*, int *lineIdx, int *offChar, \
375  int *height, BOOL isSel); \
376  int (*getLineCount)(Clss*); \
377  void (*selectAll)(Clss*); \
378  int (*setSel)(Clss*, unsigned int startParaIdx, unsigned int startOffChar, \
379  unsigned int endParaIdx, unsigned int endOffChar); \
380  int (*getSel)(Clss*, char *buffer, int len); \
381  BOOL (*needLineDecorative)(Clss*); \
382  void (*lineDecorative)(Clss*, int x, int y, int w, int h, \
383  int lineNo, HDC hdc); \
384  TITLE_CLASS_HEADER(Clss)
385 
386 #ifndef __MINIGUI_LIB__
387 
392 #define NCSS_TE_READONLY (1<<NCSS_WIDGET_SHIFT)
393 
398 #define NCSS_TE_UPPERCASE (2<<NCSS_WIDGET_SHIFT)
399 
404 #define NCSS_TE_LOWERCASE (4<<NCSS_WIDGET_SHIFT)
405 
410 #define NCSS_TE_NOHIDESEL (8<<NCSS_WIDGET_SHIFT)
411 
416 #define NCSS_TE_AUTOWRAP (0x10<<NCSS_WIDGET_SHIFT)
417 
422 #define NCSS_TE_BASELINE (0x20<<NCSS_WIDGET_SHIFT)
423 
428 #define NCSS_TE_OWNERBKGND (0x40<<NCSS_WIDGET_SHIFT)
429 
430 /*
431  * \def NCSS_TE_TITLE
432  * \brief make the texteditor has title
433  */
434 #define NCSS_TE_TITLE (0x80<<NCSS_WIDGET_SHIFT)
435 
436 /*
437  * \def NCSS_TE_AUTOVSCROLL
438  * \brief make the texteditor has a auto vert scrollbar
439  *
440  * \note: NCSS_TE_AUTOVSCROLL | WS_VSCROLL == AUTO
441  * !(dwStyle & NCSS_TE_AUTOVSCROLL) && (dwStyle & WS_VSCROLL) == Always
442  * !(dwStyle & (NCSS_TE_AUTOVSCROLL | WS_VSCROLL)) == Nerver
443  */
444 #define NCSS_TE_AUTOVSCROLL (0x100<<NCSS_WIDGET_SHIFT)
445 
446 /*
447  * \def NCSS_TE_AUTOHSCROLL
448  * \brief make the texteditor has the auto horz scrollbar
449  *
450  * \note: NCSS_TE_AUTOHSCROLL | WS_HSCROLL == AUTO
451  * !(dwStyle & NCSS_TE_AUTOHSCROLL) && (dwStyle & WS_HSCROLL) == Always
452  * !(dwStyle & (NCSS_TE_AUTOHSCROLL | WS_HSCROLL)) == Nerver
453  */
454 #define NCSS_TE_AUTOHSCROLL (0x200<<NCSS_WIDGET_SHIFT)
455 
456 #define NCSS_TE_SHIFT (NCSS_WIDGET_SHIFT + 10)
457 
458 #endif
459 
464  enum ncsTEScrollMode
465  {
469  NCS_TEF_SCROLLBAR_NEVER = 0,
470 
474  NCS_TEF_SCROLLBAR_AUTO,
475 
479  NCS_TEF_SCROLLBAR_ALWAYS,
480 };
481 
486 enum mTextEditorProp
487 {
491  NCSP_TE_READONLY = NCSP_WIDGET_MAX + 1,
492 
496  NCSP_TE_SCROLL_MODE,
497 
501  NCSP_TE_SCROLL_HSTEP,
502 
506  NCSP_TE_SCROLL_VSTEP,
507 
511  NCSP_TE_TEXTLIMIT,
512 
516  NCSP_TE_LINECOUNT,
517 
521  NCSP_TE_PARAGRAPHCOUNT,
522 
526  NCSP_TE_MARGINRECT,
527 
531  NCSP_TE_MAX,
532 };
533 #define NCSP_TE_NUMOFPARAGRAPHS NCSP_TE_PARAGRAPHCOUNT
534 
535 #ifndef __MINIGUI_LIB__
536 
540 enum mTextEditorNotify
541 {
545  NCSN_TE_CONTENTCHANGED = NCSN_WIDGET_MAX + 1,
546 
550  NCSN_TE_SETFOCUS,
551 
555  NCSN_TE_KILLFOCUS,
556 
560  NCSN_TE_MAXTEXT,
561 
565  NCSN_TE_CHANGE,
566 
571  NCSN_TE_UPDATE,
572 
576  NCSN_TE_SELCHANGED,
577 
581  NCSN_TE_MAX
582 };
583 
584 typedef struct _mTextEditorRenderer mTextEditorRenderer;
585 #endif
586 
587 
588 DEFINE_OBJECT(mTextEditor, mWidget)
589 
590 #ifdef __MINIGUI_LIB__
591 void TextEditorDrawLinesDecorative(mTextEditor * self, HDC hdc, int x, int y, int w, int h);
592 #define mTextEditor_drawLinesDecorative TextEditorDrawLinesDecorative
593 #else
594 void mTextEditor_drawLinesDecorative(mTextEditor * self, HDC hdc, int x, int y, int w, int h);
595 #endif
596 
598 #ifdef __cplusplus
599 }
600 #endif
601 
602 #endif /*_MGNCSCTRL_TEXTEDITOR*/
603 
604 #endif
605 
606 
define the mWidget members, inherit from mComponent
the Object struct