mtexteditbase.h

00001 /*
00002 ** $Id: mtexteditbase.h 13589 2010-10-29 08:50:13Z wanzheng $
00003 **
00004 ** texteditbase.h: base header for the new text edit module.
00005 **
00006 ** Copyright (C) 2010 Feynman Software.
00007 **
00008 ** Create date: 2010/03/10
00009 */
00010 
00011 #ifndef TEXTEDITBASE_H
00012 #define TEXTEDITBASE_H
00013 
00014 #ifdef __cplusplus
00015 extern "C" {
00016 #endif
00017 
00018 DECLARE_INTERFACE(ITextBufferObserver)
00019 DECLARE_INTERFACE(ITextIterator)
00020 DECLARE_INTERFACE(ITextBuffer)
00021 DECLARE_INTERFACE(ITextRender)
00022 DECLARE_INTERFACE(ITextLayoutContext)
00023 DECLARE_INTERFACE(ITextLayout)
00024 
00025 //define the interface ITextBufferObserver
00026 #define ITextBufferObserverHeader(Interface,ClassImpl)  \
00027         IInterfaceHeader(Interface, ClassImpl)              \
00028         void (*onTextChanged)(ClassImpl*, int changedBegin, int delCount, int insertCount);
00029 
00030 DEFINE_INTERFACE(ITextBufferObserver)
00031 
00032 
00033 
00034 // ITextBuffer
00035 #define ITextBufferHeader(Interface, ClassImpl) \
00036         IInterfaceHeader(Interface, ClassImpl)      \
00037         /*replace */ \
00038         int (*replace)(ClassImpl *self,             \
00039                         int at, int count,                  \
00040                         const char* str,                    \
00041                         int str_count/*=-1*/);              \
00042         int (*getText)(ClassImpl* self,             \
00043                         int at /*=NULL*/,                   \
00044                         char* str_buff,                     \
00045                         int str_count);                     \
00046         int (*getCount)(ClassImpl* self);           \
00047         ITextIterator* (*getAt)(ClassImpl* self,    \
00048                         int charIndex);                     \
00049         BOOL (*addObserver)(ClassImpl*, ITextBufferObserver* observer);     \
00050         BOOL (*removeObserver)(ClassImpl*, ITextBufferObserver* observer);  \
00051         int (*find)(ClassImpl*self, int start, const char* str, int str_count); \
00052         int (*setCase)(ClassImpl *self, int start, int len, BOOL bupper);
00053 
00054 DEFINE_INTERFACE(ITextBuffer)
00055 
00056 
00057 // ITextIterator
00058 #define ITextIteratorHeader(Interface, ClassImpl)           \
00059         IInterfaceHeader(Interface, ClassImpl)                  \
00060         void (*nextChar)(ClassImpl* self);                      \
00061         void (*prevChar)(ClassImpl* self);                      \
00062         /*get current index of charactor*/                      \
00063         int  (*index)(ClassImpl* self);                         \
00064         /*reset the iterator*/                                  \
00065         int  (*reset)(ClassImpl* self, int charIndex);          \
00066         /*is end*/ \
00067         BOOL (*isEnd)(ClassImpl* self);                         \
00068         /*is head*/ \
00069         BOOL (*isHead)(ClassImpl* self);                        \
00070         /*get the charactor as much as more*/                   \
00071         const char* (*getMore)(ClassImpl*,int *pTextLen,        \
00072         int *pVisibleTextLen, BOOL bAutoSkip/*=TRUE*/);     \
00073         /*reference one*/  \
00074         ITextIterator* (*reference)(ClassImpl* self);           \
00075         /*comapre */ \
00076         int (*diff)(ClassImpl*, const ITextIterator* another);  \
00077         /*is in a range*/ \
00078         int (*inRange)(ClassImpl*, const ITextIterator* left,   \
00079             const ITextIterator* right);                    \
00080         /*release me*/ \
00081         void (*releaseIterator)(ClassImpl* self);                       \
00082         /*text Render*/ \
00083         ITextRender* (*getTextRender)(ClassImpl* self);         \
00084         /*getCharType*/ \
00085         int (*getCharType)(ClassImpl* self, int offset);
00086 
00087 enum {
00088         TI_OUTOFRANGE    = -1,
00089         TI_VISIBILE_CHAR = 0,   /*visible char*/
00090         TI_LINERETURN,           /*line return*/
00091     TI_EOF                  /* End OF File */
00092 };
00093 
00094 
00095 DEFINE_INTERFACE(ITextIterator)
00096 
00097 //define the return value of inRange
00098 enum {
00099         TXTITER_RANGE_INVALID    = -1,
00100         TXTITER_RANGE_IN         = 0,   // left  < self  < right
00101         TXTITER_RANGE_LEFTEDGE   ,      // left  == self
00102         TXTITER_RANGE_RIGHTEDGE  ,      // right == self
00103         TXTITER_RANGE_LEFTOUT    ,
00104         TXTITER_RANGE_RIGHTOUT  
00105 };
00106 
00107 
00109 // ITextRender
00110 #define ITextRenderHeader(Interface, ClassImpl)         \
00111         IInterfaceHeader(Interface, ClassImpl)              \
00112         int  (*calc)(ClassImpl* self, HDC hdc,              \
00113             ITextIterator* begin,                       \
00114                         int str_count, int* ptext_count,            \
00115                         const RECT* maxBound, RECT *bounds);        \
00116         int (*draw)(ClassImpl* self, HDC hdc, int x, int y, \
00117             ITextIterator* begin, int str_count);       \
00118         int (*getTextByteLen)(ClassImpl* self, HDC hdc,     \
00119         ITextIterator* it, /*in out*/int *ptext_index); \
00120         int (*getTextCount)(ClassImpl* self, HDC hdc,       \
00121             ITextIterator* it, /*in out*/int* pstr_len);\
00122         int (*getCaretSize)(ClassImpl* self, HDC hdc,       \
00123                         ITextIterator* it, int *pWidth, int *pHeight);
00124 
00125 DEFINE_INTERFACE(ITextRender)
00126 
00127 
00128 
00129 //Interface for ITextLayout
00130 
00131 #define ITextLayoutContextHeader(Interface, ClassImpl)  \
00132         IInterfaceHeader(Interface, ClassImpl)              \
00133         int (*getMetrics)(ClassImpl*,int type);             \
00134         void (*setupDC)(ClassImpl*, HDC hdc);               \
00135         void (*beginSelection)(ClassImpl*,HDC hdc);         \
00136         void (*endSelection)(ClassImpl*, HDC hdc);          \
00137         HDC  (*getDC)(ClassImpl*);                          \
00138     void (*contentPosToDCPos)(ClassImpl*, HDC hdc,      \
00139             int *px, int *py);                          \
00140         void (*releaseDC)(ClassImpl*, HDC hdc);             \
00141     void (*updateCaret)(ClassImpl*);                    \
00142         void (*update)(ClassImpl*, BOOL);
00143 
00144 enum {
00145         TEXTMETRICS_MAXWIDTH,
00146         TEXTMETRICS_MAXHEIGHT,
00147         TEXTMETRICS_LINESPACE,
00148     TEXTMETRICS_DEFLINEHEIGHT
00149 };
00150 
00151 DEFINE_INTERFACE(ITextLayoutContext)
00153 //ITextLayout
00154 typedef void (*CB_LINE_PROC)(mObject* self, int x, int y, int width, int height, int lineNo, void* user_param);
00155 typedef BOOL (*CB_NODE_PROC)(mObject* self, mObject* cur_node, void* user_param);
00156 
00157 #define ITextLayoutHeader(Interface, ClassImpl)         \
00158         ITextBufferObserverHeader(Interface, ClassImpl)     \
00159         /*get the text iterator by pos*/ \
00160         int (*getCharIndex)(ClassImpl*, int *px, int *py,   \
00161         int *plineHeight/*=NULL*/, int *ptext_index);   \
00162         /*get the pos by text iterator */ \
00163         int (*getCharPos)(ClassImpl*, int index, int *px,   \
00164             int *py, int *plineHeight, BOOL bAsText);   \
00165         /*get the size of the text */ \
00166         BOOL (*getTextBoundSize)(ClassImpl* self, int *cx, int *cy);                \
00167         BOOL (*setCursor)(ClassImpl* self, int index, BOOL isSel);                  \
00168         int (*setCursorPos)(ClassImpl* self, int x, int y, BOOL isSel);             \
00169         int (*getCursor)(ClassImpl*, int *px, int *py, int *cursor_h, BOOL isSel);  \
00170         void (*draw)(ClassImpl* self, HDC hdc, int x, int y, int width, int height);\
00171         int (*getLineHeight)(ClassImpl* self, int index);                           \
00172     void (*reset)(ClassImpl *self);                                             \
00173         int (*textCount2Len)(ClassImpl*, int text_index, int text_count, int *plen);\
00174         int (*textLen2Count)(ClassImpl*, int str_index, int str_len, int*text_count,\
00175             int *poutstr_index, int *poutstr_count);                            \
00176     void (*foreachLine)(ClassImpl*, int x, int y, int maxWidth, int maxHeight,  \
00177             CB_LINE_PROC proc, mObject* proc_owner, void* user_param);          \
00178     void (*travelNode)(ClassImpl*, CB_NODE_PROC proc, mObject* proc_owner, void* user_param); \
00179     PLOGFONT (*getReleatedFont)(ClassImpl*, int idx, BOOL isText);              \
00180     int (*getParaByIndex)(ClassImpl* self, int index, int *pcol, BOOL bText);   \
00181     int (*getLineByIndex)(ClassImpl* self, int index, int* pcol, BOOL bText);   \
00182     int (*getIndexByPara)(ClassImpl* self, int paraNo, int col, BOOL* outOfRange, BOOL bText); \
00183     int (*getIndexByLine)(ClassImpl* self, int lineIdx, int col, BOOL* outOfRange, BOOL bText);
00184 
00185 DEFINE_INTERFACE(ITextLayout)
00186 
00187 #ifdef __cplusplus
00188 }
00189 #endif
00190 
00191 #endif
00192 
00193 
00194 
Generated on Fri Jun 10 11:18:06 2011 for New Control Set V1.0.0 API Reference by  doxygen 1.6.3