增加GMULTIEDIT_append2bootm和GMULTIEDIT_append2head
//2007-10-12 gliethttp //修改MultiEdit void _Go2HeadShow(MULTIEDIT_HANDLE hObj, MULTIEDIT_OBJ* pObj) { if (pObj->hText) {//int NumVisLines= _GetNumVisLines(hObj, pObj); int YDist = GUI_GetYDistOfFont(pObj->pFont); //int NumLines = _GetNumLines(hObj, pObj); int the_line;int yPos; /* the_line = pObj->CacheFirstVisibleLine; if(the_line == 0)the_line = NumLines+1; else { the_line -= NumVisLines / 3 + 1; if(the_line < 0)the_line = 0; } */ the_line = 0; yPos = the_line * YDist; _SetCursorXY(hObj, pObj, 0, yPos); _InvalidateTextArea(hObj); } } //_Go2PrevLineShow void _Go2BottomShow(MULTIEDIT_HANDLE hObj, MULTIEDIT_OBJ* pObj) { if (pObj->hText) {//int NumVisLines= _GetNumVisLines(hObj, pObj); int YDist = GUI_GetYDistOfFont(pObj->pFont); int NumLines = _GetNumLines(hObj, pObj); int the_line;int yPos; //the_line = pObj->CacheFirstVisibleLine + NumVisLines + NumVisLines / 3; //if(pObj->CacheLineNumber >= (NumLines-1))the_line = 0; the_line = NumLines+1; yPos = the_line * YDist; _SetCursorXY(hObj, pObj, 0, yPos); _InvalidateTextArea(hObj); } } //向MultiEdit尾部追加文本 int GMULTIEDIT_Append2Bottom(MULTIEDIT_HANDLE hObj,char *text,uint8 flag) {MULTIEDIT_OBJ* pObj; uint32 len = strlen(text); pObj = MULTIEDIT_H2P(hObj); WM_LOCK(); if (_IsCharsAvailable(pObj, len)) { int BytesNeeded; BytesNeeded = len; if (_IsSpaceInBuffer(pObj, BytesNeeded)) { //int CursorOffset; char* pText; pText = (char*) GUI_ALLOC_h2p(pObj->hText); //CursorOffset = pObj->CursorPosByte; //pText += CursorOffset; //memmove(pText + BytesNeeded, pText, strlen(pText) + 1); pText += strlen(pText); memmove(pText,text,len + 1); //GUI_UC_Encode(pText, Char); WM_NotifyParent(hObj, WM_NOTIFICATION_VALUE_CHANGED); //pObj->NumChars += 1; //_InvalidateNumLines(pObj); //_InvalidateTextSizeX(pObj); //_InvalidateTextArea(hObj); _InvalidateNumChars(pObj); _InvalidateNumLines(pObj); _InvalidateTextSizeX(pObj); if(flag)_Go2BottomShow(hObj,pObj); //_ClearCache(pObj); WM_UNLOCK(); return 1; } } WM_UNLOCK(); return 0; } void _Go2Bottom(MULTIEDIT_HANDLE hObj) { _Go2BottomShow(hObj,MULTIEDIT_H2P(hObj)); } void _Go2Head(MULTIEDIT_HANDLE hObj) { _Go2HeadShow(hObj,MULTIEDIT_H2P(hObj)); } //向MultiEdit头部追加文本 GUI_HMEM GUI_ALLOC_ReallocG(GUI_HMEM hOld, int NewSize,int ItemSize) { GUI_HMEM hNew; hNew = GUI_ALLOC_AllocNoInit(NewSize); if (hNew && hOld) { void *pNew, *pOld; int Size, OldSize; OldSize = GUI_ALLOC_GetSize(hOld); Size = (OldSize < NewSize) ? OldSize : NewSize; GUI_LOCK(); pNew = GUI_ALLOC_h2p(hNew); pOld = GUI_ALLOC_h2p(hOld); //2007-10-10 gliethttp //if(OldSize < NewSize) {char *p = (char*)pNew+ItemSize; pNew = p; } memcpy(pNew, pOld, Size); GUI_UNLOCK(); GUI_ALLOC_Free(hOld); } return hNew; } static int _GIncrementBuffer(MULTIEDIT_OBJ* pObj, unsigned AddBytes,uint32 itemsize) { WM_HMEM hNew; int NewSize; NewSize = pObj->BufferSize + AddBytes; hNew = GUI_ALLOC_ReallocG(pObj->hText, NewSize,itemsize); if (hNew) { if (!(pObj->hText)) { char* pText; pText = (char*) GUI_ALLOC_h2p(hNew); *pText = 0; } pObj->BufferSize = NewSize; pObj->hText = hNew; return 1; } return 0; } static int _GIsSpaceInBuffer(MULTIEDIT_OBJ* pObj, int BytesNeeded) { int NumBytes = 0; uint32 itemsize; if (pObj->hText) { NumBytes = strlen((char*)GUI_ALLOC_h2p(pObj->hText)); } itemsize = BytesNeeded; BytesNeeded = (BytesNeeded + NumBytes + 1) - pObj->BufferSize; if (BytesNeeded > 0) { if (!_GIncrementBuffer(pObj, BytesNeeded + MULTIEDIT_REALLOC_SIZE,itemsize)) { return 0; } }//2007-10-12 gliethttp else { return -1; } return 1; } int GMULTIEDIT_Append2Head(MULTIEDIT_HANDLE hObj,char *text,uint8 flag) {MULTIEDIT_OBJ* pObj; uint32 len = strlen(text); int result; pObj = MULTIEDIT_H2P(hObj); WM_LOCK(); if (_IsCharsAvailable(pObj, len)) { int BytesNeeded; BytesNeeded = len; if (result = _GIsSpaceInBuffer(pObj, BytesNeeded)) { //int CursorOffset; char* pText; pText = (char*) GUI_ALLOC_h2p(pObj->hText); //CursorOffset = pObj->CursorPosByte; //pText += CursorOffset; //memmove(pText + BytesNeeded, pText, strlen(pText) + 1); //pText += strlen(pText); //2007-10-12 gliethttp if(result < 0) {uint32 i; uint32 tlen; char *src,*dst; tlen = strlen(pText); src = pText+tlen; dst = src+BytesNeeded; tlen+=1;//'\0'数据 for(i = 0;i < tlen;i++) *dst-- = *src--; } memmove(pText,text,BytesNeeded); //GUI_UC_Encode(pText, Char); WM_NotifyParent(hObj, WM_NOTIFICATION_VALUE_CHANGED); //pObj->NumChars += 1; _InvalidateNumChars(pObj); _InvalidateNumLines(pObj); _InvalidateTextSizeX(pObj); if(flag)_Go2HeadShow(hObj,pObj); //_ClearCache(pObj); WM_UNLOCK(); return 1; } } WM_UNLOCK(); return 0; }
|