📄 edit.c
字号:
return 0;
}
old_x = xPos;
old_y = yPos;
#endif
lpEditItem=(LPEDITITEM)GetWindowLong(hWnd,0); // 得到编辑条目结构指针
if(lpEditItem==NULL) return FALSE;
// set Caret position to LButton Down Position
// !!! Modified By jami chen in 2004.10.18
// SetPDACaretPosition(hWnd,lpEditItem,xPos,yPos);
if (SetPDACaretPosition(hWnd,lpEditItem,xPos,yPos) == FALSE)
{
// 光标位置没有发生改变
return 0;
}
// !!! Modified End
// the caret coordinate position is or not in the
// client rect ???
// if not in the client rect ,then adjust and return TRUE
if (AdjustCaretInEditItem(hWnd,lpEditItem)==TRUE)
{
// set caret position
SetPDACaret(hWnd);
// Set Invert Area
SetInvertArea(hWnd,lpEditItem);
// get hdc
// DrawPDAEditControl(hWnd);
InvalidateRect(hWnd,NULL,TRUE);
}
else
{
// set caret position
SetPDACaret(hWnd);
// set invert area
SetInvertArea(hWnd,lpEditItem);
// redraw the changed area
DisplayInvertChange(hWnd,lpEditItem);
}
}
wParam++;
return 0;
}
// **************************************************
// 声明:static void DoLButtonUp(HWND hWnd,WPARAM wParam,LPARAM lParam)
// 参数:
// IN hWnd -- 窗口句柄
// IN wParam -- 保留
// IN lParam -- MAKELPARAM(x,y),当前鼠标的位置
// 返回值:无
// 功能描述:处理WM_LBUTTONUP消息。
// 引用:
// **************************************************
static void DoLButtonUp(HWND hWnd,WPARAM wParam,LPARAM lParam)
{
// Release capture
SetCapture(NULL);
wParam++;
lParam++;
}
// **************************************************
// 声明:static void DoProcessChar(HWND hWnd,WPARAM wParam,LPARAM lParam)
// 参数:
// IN hWnd -- 窗口句柄
// IN wParam -- 保留
// IN lParam -- 保留
// 返回值:无
// 功能描述:字符输入,处理WM_CHAR消息。
// 引用:
// **************************************************
static void DoProcessChar(HWND hWnd,WPARAM wParam,LPARAM lParam)
{
TCHAR chCharCode;
LPEDITITEM lpEditItem;
DWORD dwStyle;
BOOL bResult;
DWORD dwShowFlag = PE_SHOWTEXTEND;
LPTSTR lpShowAddress;
int nShowLine,nShowPos;
HDC hdc;
int xPos,nLine;
int bDeleteResult;
BOOL bDeleteInvert = FALSE;
// get window style
dwStyle=GetWindowLong(hWnd,GWL_STYLE);
if (dwStyle&ES_READONLY) return;
// get struct EDITITEM data
lpEditItem=(LPEDITITEM)GetWindowLong(hWnd,0);
if (lpEditItem==NULL) return;
// get will be redrawed start address
lpShowAddress=lpEditItem->lpCaretPosition;
// get input char code
chCharCode=(TCHAR)wParam;
if (chCharCode==ENTERCODE)
{ // the input char is enter code
if (PickCharacter(0x00,chCharCode,dwStyle)==FALSE) return;
//Delete Invert Area
if (DeleteInvert(hWnd,lpEditItem))
{
SetCaretCoordinate(hWnd,lpEditItem); // 设置光标的坐标
AdjustCaretInEditItem(hWnd,lpEditItem); // 调整光标位置
bDeleteInvert=TRUE;
}
// insert enter code
bResult=InsertChar(hWnd,lpEditItem,0x0d,0x0a);
// will redraw to the end of the text from the caret position
dwShowFlag=PE_SHOWTEXTEND;
}
else if(chCharCode==BACKSPACE)
{ // the input char is Backspace
//Delete Invert Area
if (DeleteInvert(hWnd,lpEditItem))
{
// AdjustCaretInEditItem(hWnd,lpEditItem);
bDeleteInvert=TRUE;
bResult=TRUE;
}
else
{
// Do backspace operation
bDeleteResult=BackSpaceChar(hWnd,lpEditItem);
if (bDeleteResult==0)
{ // the operation failare
bResult=FALSE;
}
else
{ // the operation success
if (bDeleteResult==1) // normal operation
dwShowFlag=PE_SHOWLINEEND;
else // delete the enter code
dwShowFlag=PE_SHOWTEXTEND;
bResult=TRUE;
}
}
// set redraw start addresss
lpShowAddress=lpEditItem->lpCaretPosition;
}
else
{ // the input char is normal char
// if (chCharCode<0)
if (chCharCode<0 || chCharCode > 0x7F)
{ // the input char
if (lpEditItem->HalfByte==FALSE)
{ // the input char is chinese high byte
lpEditItem->HiByte=chCharCode;
lpEditItem->HalfByte=TRUE;
return ;
}
else
{ // the input char is chinese low byte
lpEditItem->LoByte=chCharCode;
if (PickCharacter(lpEditItem->HiByte,lpEditItem->LoByte,dwStyle)==FALSE) return;
//Delete Invert Area
if (DeleteInvert(hWnd,lpEditItem))
{
SetCaretCoordinate(hWnd,lpEditItem); // 设定光标的坐标
AdjustCaretInEditItem(hWnd,lpEditItem); // 调整光标的位置
bDeleteInvert=TRUE;
}
// Insert chinese word
bResult=InsertChar(hWnd,lpEditItem,lpEditItem->HiByte,lpEditItem->LoByte);
// clear chinese high and low byte
lpEditItem->HiByte=0;
lpEditItem->LoByte=0;
lpEditItem->HalfByte=FALSE;
// must redraw to the end of the line from the caret position
dwShowFlag=PE_SHOWLINEEND;
}
}
else
{ // 当前字符是ASCII
lpEditItem->HalfByte=FALSE; // 不需要等待半个字符
if (PickCharacter(0,chCharCode,dwStyle)==FALSE) return; // 当前字符不需要
if (dwStyle&ES_UPPERCASE) // 要求大写
chCharCode=toupper(chCharCode); // 转化为大写
if (dwStyle&ES_LOWERCASE) // 要求小写
chCharCode=tolower(chCharCode); // 转化为小写
//Delete Invert Area
if (DeleteInvert(hWnd,lpEditItem))
{
SetCaretCoordinate(hWnd,lpEditItem); // 设定光标坐标
AdjustCaretInEditItem(hWnd,lpEditItem); // 调整光标位置
bDeleteInvert=TRUE;
}
// the input char is english char or symbol char
bResult=InsertChar(hWnd,lpEditItem,0x00,chCharCode);
// must redraw to the end of the line from the caret position
dwShowFlag=PE_SHOWLINEEND;
}
}
// get caret coordinate
GetCoordinate(hWnd,lpEditItem,lpEditItem->lpCaretPosition,&xPos,&nLine,dwStyle&ES_MULTILINE);
lpEditItem->nCaretx=xPos-lpEditItem->nDisplayx; // 设定光标的位置
lpEditItem->nCaretLine=nLine-lpEditItem->nDisplayLine;
if (bResult)
{ // the insert operation success ,must the redraw the window
// add code : if Caret out of the client area then must
// Reset Display Position
if (AdjustCaretInEditItem(hWnd,lpEditItem)==TRUE)
{// 要求全部显示
lpShowAddress=NULL;
nShowPos=0;
nShowLine=0;
dwShowFlag=PE_SHOWCLIENT;
}
else
{
// get redraw start coordinate
GetCoordinate(hWnd,lpEditItem,lpShowAddress,&xPos,&nLine,dwStyle&ES_MULTILINE); // 得到光标位置
nShowPos=xPos; // 从光标开始显示
nShowLine=nLine;
}
if (bDeleteInvert==TRUE)
{ // 要求全部显示
lpShowAddress=NULL;
nShowPos=0;
nShowLine=0;
dwShowFlag=PE_SHOWCLIENT;
}
SendNotificationMsg(hWnd,EN_CHANGE);
// redraw the window
hdc=GetDC(hWnd);
DrawPDAEditSpecialText(hWnd,hdc,lpEditItem,lpShowAddress,nShowPos,nShowLine,0,dwShowFlag); // 显示要显示的部分
ReleaseDC(hWnd,hdc);
// reset thw caret
}
SetPDACaret(hWnd); // 设定光标
lParam++;
}
// **************************************************
// 声明:static BOOL PickCharacter(CHAR HiByte,CHAR LoByte,DWORD dwStyle)
// 参数:
// IN HiByte -- 高字节
// IN LoByte -- 低字节
// IN dwStyle -- 编辑区风格
// 返回值:需要字符,返回TRUE,否则返回FALSE。
// 功能描述:选择字符是否符合当前类型的编辑区。
// 引用:
// **************************************************
// delete By Jami chen in 2004.06.12
/*static BOOL PickCharacter(CHAR HiByte,CHAR LoByte,DWORD dwStyle)
{
if (dwStyle&ES_NUMBER)
{ // the edit control is number ,then Only Receive 0--9
if (HiByte!=0) return FALSE;
if (LoByte>'9'||LoByte<'0') return FALSE;
}
if ((dwStyle&ES_MULTILINE)==0)
{ // if this is single line then not receive the entercode
if (LoByte==ENTERCODE&&HiByte==0) return FALSE;
}
if (HiByte==0&&LoByte<0x20)
{// not receive the character of not display
if (LoByte!=ENTERCODE) return FALSE;
}
return TRUE;
}
*/
// **************************************************
// 声明:static void DoKeyDown(HWND hWnd,WPARAM wParam,LPARAM lParam)
// 参数:
// IN hWnd -- 窗口句柄
// IN wParam -- 虚键值
// IN lParam -- 保留
// 返回值:无
// 功能描述:处理WM_KEYDOWN消息。
// 引用:
// **************************************************
static void DoKeyDown(HWND hWnd,WPARAM wParam,LPARAM lParam)
{
int nVirtKey ;
int nPageLine,nScrollLine,iHorzPos = MOTIONLESS;
nVirtKey = (int) wParam; // virtual-key code
nPageLine=GetPageLine(hWnd); // 得到一页的编辑行数
nScrollLine=0;
switch(nVirtKey)
{
case VK_PRIOR:// page up
nScrollLine=0-nPageLine;
break;
case VK_NEXT:// page down
nScrollLine=nPageLine;
break;
case VK_END:// to the text end
iHorzPos=MOVETOEND;
break;
case VK_HOME:// to the text start
iHorzPos=MOVETOHOME;
break;
case VK_LEFT:// to the left Char
iHorzPos=MOVETOLEFT;
break;
case VK_UP:// to the up line
nScrollLine=-1;
break;
case VK_RIGHT:// to the right Char
iHorzPos=MOVETORIGHT;
break;
case VK_DOWN:// to the line down
nScrollLine=1;
break;
case VK_DELETE: // delete char
DoDeleteChar(hWnd);
return;
default :
return;
};
if (nScrollLine==0)
{
if (iHorzPos!=MOTIONLESS)
{
LPEDITITEM lpEditItem;
// get struct EDITITEM data
lpEditItem=(LPEDITITEM)GetWindowLong(hWnd,0);
if (lpEditItem==NULL)
return;
HorzMoveCaret(hWnd,lpEditItem,iHorzPos); // 水平移动光标
}
// return;
}
ScrollCaretInPDAEdit(hWnd,nScrollLine); // 滚动光标
lParam++;
}
// **************************************************
// 声明:int GetTextHeight(HWND hWnd)
// 参数:
// IN hWnd -- 窗口句柄
// 返回值:返回编辑文本高度。
// 功能描述:达到编辑文本高度。
// 引用:
// **************************************************
int GetTextHeight(HWND hWnd)
{
HDC hdc;
TEXTMETRIC TextMetric;
int nTextHeight;
DWORD dwStyle;
hdc=GetDC(hWnd);
// get current text property
GetTextMetrics(hdc,&TextMetric);
ReleaseDC(hWnd,hdc);
nTextHeight=(int)TextMetric.tmHeight;
dwStyle=GetWindowLong(hWnd,GWL_STYLE);
// add a dot line height , 1 dot
if (dwStyle&ES_LINESEPARATE)
nTextHeight+=1;
return nTextHeight;
}
// **************************************************
// 声明:static void DoGetCaretPosition(HWND hWnd,WPARAM wParam,LPARAM lParam)
// 参数:
// IN hWnd -- 窗口句柄
// OUT wParam -- LPINT 指向INT的指针,存放光标所在的行。
// OUT lParam -- LPINT 指向INT的指针,存放光标所在的X坐标。
// 返回值:无
// 功能描述:得到当前光标的位置,处理EM_GETCARETPOS消息。
// 引用:
// **************************************************
static void DoGetCaretPosition(HWND hWnd,WPARAM wParam,LPARAM lParam)
{
int *lpnLine,*lpxPos;
LPEDITITEM lpEditItem;
#ifdef _MAPPOINTER
wParam = (WPARAM)MapPtrToProcess( (LPVOID)wParam, GetCallerProcess() ); // 映射指针
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -