📄 medit.c
字号:
return newStartPos;
}
static int edtGetDispLen (HWND hWnd,PLINEDATA pLineData)
{
int i, n = 0;
int nOutWidth = edtGetOutWidth (hWnd);
int nTextWidth = 0;
PMLEDITDATA pMLEditData =(PMLEDITDATA) GetWindowAdditionalData2(hWnd);
const char* buffer = pLineData->buffer;
if(buffer[0]==0||pLineData->dataEnd<pMLEditData->dispPos)
return 0;
for (i = pMLEditData->dispPos; i < pLineData->dataEnd; i++)
{
/* 1st:gb:a1-f7,big5:a1-f9 */
if ((BYTE)buffer [i] > 0xA0)
{
i++;
if (i < pLineData->dataEnd)
{
#ifndef USE_BIG5
if ((BYTE)buffer [i] > 0xA0) /* 2nd:gb:a1-fe,big5:40-7e,a1-fe */
#else /* 2nd:gb:a1-fe,big5:40-7e,a1-fe */
if ( ((BYTE)buffer [i] >= 0x40 && (BYTE)buffer[i] <= 0x7e) ||
((BYTE)buffer [i] >= 0xa1 && (BYTE)buffer[i] <= 0xfe))
#endif
{
nTextWidth += GetSysCCharWidth (hWnd);
n += 2;
}
else
i--;
}
else
{
nTextWidth += GetSysCharWidth (hWnd);
n++;
}
}
else
{
nTextWidth += GetSysCharWidth (hWnd);
n++;
}
if (nTextWidth > nOutWidth)
break;
}
return n;
}
static int edtGetOffset (HWND hwnd,const MLEDITDATA* pMLEditData, PLINEDATA pLineData, int x)
{
int i;
int newOff = 0;
int nTextWidth = 0;
const char* buffer = pLineData->buffer;
if(pLineData->dataEnd<pMLEditData->dispPos)
return pLineData->dataEnd;
x -= pMLEditData->leftMargin;
for (i = pMLEditData->dispPos; i < pLineData->dataEnd; i++) {
if ((nTextWidth + (GetSysCharWidth(hwnd) >> 1)) >= x)
break;
/* 1st:gb:a1-f7,big5:a1-f9 */
if ((BYTE)buffer [i] > 0xA0)
{
i++;
if (nTextWidth + GetSysCCharWidth(hwnd)/2 >= x)
break;
if (i < pLineData->dataEnd)
{
#ifndef USE_BIG5
if ((BYTE)buffer [i] > 0xA0) /* 2nd:gb:a1-fe,big5:40-7e,a1-fe */
#else /* 2nd:gb:a1-fe,big5:40-7e,a1-fe */
if ( ((BYTE)buffer [i] >= 0x40 && (BYTE)buffer[i] <= 0x7e) ||
((BYTE)buffer [i] >= 0xa1 && (BYTE)buffer[i] <= 0xfe))
#endif
{
nTextWidth += GetSysCCharWidth (hwnd);
newOff += 2;
}
else
i --;
}
else
{
nTextWidth += GetSysCharWidth (hwnd);
newOff ++;
}
}
else
{
nTextWidth += GetSysCharWidth (hwnd);
newOff ++;
}
}
return newOff;
}
static int edtGetLineNO (HWND hwnd,const MLEDITDATA* pMLEditData, int x)
{
int nline = 0;
if(x>=0)
{
nline = x / GetSysCharHeight(hwnd);
if (nline <= pMLEditData->linesDisp)
return nline;
}
return -1;
}
static BOOL edtIsACCharAtPosition (const char* string, int len, int pos)
{
if (pos > (len - 2))
return FALSE;
/* 1st:gb:a1-f7,big5:a1-f9 2nd:gb:a1-fe,big5:40-7e,a1-fe */
#ifndef USE_BIG5
if ((BYTE)string [pos] > 0xA0 && (BYTE)string [pos + 1] > 0xA0)
return TRUE;
#else
if ((BYTE)string [pos] > 0xA0)
{
if ( ((BYTE)string [pos + 1] >= 0x40 && (BYTE)string [pos + 1] <= 0x7e) ||
((BYTE)string [pos + 1] >= 0xa1 && (BYTE)string [pos + 1] <= 0xfe)) {
/*fprintf(stderr,"true\n");
fflush(stderr);*/
return TRUE;
}
}
#endif
return FALSE;
}
static void str2attr(const char* str,int len)
{
int i=0;
do
{
if (edtIsACCharAtPosition(str,len,i))
{
attr[i]=ATTCHL;
attr[i+1]=ATTCHR;
i+=2;
}
else
{
attr[i]=ATTENG;
i++;
}
}while(i<len);
}
static BOOL edtIsACCharBeforePosition (const char* string,int len, int pos)
{
if (pos < 2)
return FALSE;
/* 1st:gb:a1-f7,big5:a1-f9 2nd:gb:a1-fe,big5:40-7e,a1-fe */
#ifndef USE_BIG5
/* FIXME #ifdef GB2312?*/
if ((BYTE)string [pos - 2] > 0xA0 && (BYTE)string [pos - 1] > 0xA0)
return TRUE;
#else
#if 0
if ((BYTE)string [pos - 2] > 0xA0)
{
if ( ((BYTE)string [pos - 1] >= 0x40 && (BYTE)string[pos - 1] <= 0x7e) ||
((BYTE)string [pos - 1] >= 0xa1 && (BYTE)string[pos - 1] <= 0xfe))
return TRUE;
}
#else
str2attr(string,len);
if (attr[pos-1]==ATTENG) return FALSE;
else return TRUE;
#endif
#endif
return FALSE;
}
static BOOL edtIsACCharFromBegin(const char* string,int len,int pos)
{
int i;
if(pos == 0)
return TRUE;
if(len == 0)
return FALSE;
for(i=0;i<len;)
{
if( edtIsACCharAtPosition(string,len,i) )
i += 2;
else
i++;
if(i==pos)
return TRUE;
}
return FALSE;
}
int GetRETURNPos(char *str)
{
int i;
for(i=0;i<strlen(str);i++)
{
if(str[i]==10)
return i;
}
return -1;
}
void MLEditInitBuffer (PMLEDITDATA pMLEditData,char *spcaption)
{
char *caption=spcaption;
int off1;
int lineNO=0;
PLINEDATA pLineData;
if (!(pMLEditData->head = GdMalloc (sizeof (LINEDATA))))
{
// fprintf (stderr, "EDITLINE: malloc error!\n");
return ;
}
pMLEditData->head->previous = NULL;
pLineData=pMLEditData->head;
while ( (off1 = GetRETURNPos(caption)) != -1)
{
off1 = min(off1, LEN_MLEDIT_BUFFER);
memcpy(pLineData->buffer,caption,off1);
pLineData->buffer[off1] = '\0';
caption+=min(off1,LEN_MLEDIT_BUFFER)+1;
pLineData->lineNO = lineNO;
pMLEditData->dispPos = 0;
pLineData->dataEnd = strlen(pLineData->buffer);
pLineData->next = GdMalloc (sizeof (LINEDATA));
pLineData->next->previous = pLineData;
pLineData = pLineData->next;
lineNO++;
}
off1 = min(strlen(caption),LEN_MLEDIT_BUFFER);
memcpy(pLineData->buffer,caption,off1);
pLineData->buffer[off1] = '\0';
pLineData->lineNO = lineNO++;
pMLEditData->dispPos = 0;
pLineData->dataEnd = strlen(pLineData->buffer);
pLineData->next = NULL;
pMLEditData->lines = lineNO ;
}
PLINEDATA GetLineData(PMLEDITDATA pMLEditData,int lineNO)
{
PLINEDATA pLineData=pMLEditData->head;
while(pLineData)
{
if(pLineData->lineNO==lineNO)
return pLineData;
pLineData = pLineData->next;
}
return NULL;
}
int MLEditCtrlProc (HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
{
DWORD dwStyle;
DWORD dw;
HDC hdc;
PLINEDATA pLineData;
RECT clientRect;
PMLEDITDATA pMLEditData;
dwStyle = GetWindowStyle(hWnd);
switch (message)
{
case WM_CREATE:
{
if (!(pMLEditData = GdMalloc (sizeof (MLEDITDATA))))
{
// fprintf (stderr, "EDIT: malloc error!\n");
return -1;
}
pMLEditData->totalLen = LEN_MLEDIT_BUFFER;
pMLEditData->editPos = 0;
pMLEditData->editLine = 0;
pMLEditData->caretPos = 0;
MLEditInitBuffer(pMLEditData,GetWindowCaption(hWnd));
GetClientRect(hWnd,&clientRect);
pMLEditData->MaxlinesDisp = (clientRect.bottom-clientRect.top)/GetSysCharHeight(hWnd);
pMLEditData->linesDisp = min(pMLEditData->MaxlinesDisp,pMLEditData->lines);
pMLEditData->StartlineDisp = 0;
pMLEditData->EndlineDisp = pMLEditData->StartlineDisp + pMLEditData->linesDisp - 1;
pMLEditData->selStartPos = 0;
pMLEditData->selEndPos = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -