⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 editbase.c

📁 深圳市微逻辑电子有限公司 巨果&#8226 Kingmos&reg 系统核心
💻 C
📖 第 1 页 / 共 5 页
字号:
			      if (nCurCharPos+nCurCharWidth>nWindowWidth)
			      { // 要求换行 
				    nTotalLine++;
				    nCurCharPos=0;
			      }
			    }
        }
				// exit circle
				break;
			}
//			if (*lpCurChar<0)
			if (*lpCurChar<0 || *lpCurChar>0x7F)
			{  // the current character is chinese
        nCurCharWidth=ChineseCharWidth;
        nCurCharLen=2;
			}
			else
			{  // the current character is english or symbol
        if ((dwStyle&ES_FORMAT)&&(*lpCurChar==FMTSEPARATE))
        {  // 格式化条目分隔符
          Size=GetSize(hWnd,(FmtAnalysis.arrayFmtItem[nFMTItem]).lpTileText,
                                  (FmtAnalysis.arrayFmtItem[nFMTItem]).cTileTextLen);
          nCurCharWidth=(int)Size.cx;
          nFMTItem++; // 下一个条目
					if (nFMTItem>=FORMATITEMMAXNUM)
						nFMTItem=FORMATITEMMAXNUM-1;
        }
        else
          nCurCharWidth=lpCharWidthBuffer[*lpCurChar];  // 得到当前字符的宽度
        nCurCharLen=1;
			}
			if (*lpCurChar==0x0d&&*(lpCurChar+1)==0x0a)
			{  // this code is enter code , to next line
				// to next char
				lpCurChar+=2;
				nAddLen+=2;
				nTotalLine++;
        nCurCharPos=0;
				// to next circle
				continue;
			}
			if (dwStyle&ES_AUTONEWLINE)
			{  // 可以自动换行
			  if (nCurCharPos+nCurCharWidth>nWindowWidth)
			  {  // 要求换行 
				nTotalLine++;
				nCurCharPos=0;
			  }
			}
			// to next char
			lpCurChar+=nCurCharLen;
			nAddLen+=nCurCharLen;
      nCurCharPos+=nCurCharWidth;
		}
		// return Total line 
//    Print(10,430,nTotalLine);
		return nTotalLine;		
}
/**************************************************
声明: void SetInvertArea(HWND hWnd,LPEDITITEM lpEditItem)
参数:
	IN hWnd -- 窗口句柄
	IN lpEdititem -- 编辑条目结构指针
返回值:无
功能描述:设置编辑去的选择区域。
引用: 
************************************************/
 void SetInvertArea(HWND hWnd,LPEDITITEM lpEditItem)
{
//   LPEDITITEM lpEditItem;

		// Get struct EDITITEM data
//		lpEditItem=(LPEDITITEM)GetWindowLong(hWnd,0);
//    if (lpEditItem==NULL) return;
		// save old Invert area
		lpEditItem->lpOldInvertStart=lpEditItem->lpInvertStart;
		lpEditItem->lpOldInvertEnd=lpEditItem->lpInvertEnd;

		// The Invert Initial point is or not exist
		if (lpEditItem->lpInvertInitial==NULL)
		{ // Is not exist ,then set Invert area to the caret position
			lpEditItem->lpInvertStart=lpEditItem->lpInvertEnd=lpEditItem->lpCaretPosition;
			lpEditItem->lpInvertInitial=lpEditItem->lpCaretPosition;
		}
		else
		{ // Is exist , then set new area
			if (lpEditItem->lpCaretPosition>lpEditItem->lpInvertInitial)
			{ // if caret position is behind the initial point
				// the Invert start in the initial point and the end in the caret position
				lpEditItem->lpInvertStart=lpEditItem->lpInvertInitial;
				lpEditItem->lpInvertEnd=lpEditItem->lpCaretPosition;
			}
			else
			{  // the Invert start in the caret position and the end in the initial point
				lpEditItem->lpInvertEnd=lpEditItem->lpInvertInitial;
				lpEditItem->lpInvertStart=lpEditItem->lpCaretPosition;
			}
		}
}
/**************************************************
声明:void SetPDAEditColor(HWND hWnd,HDC hdc,int nColorStyle)
参数:
	IN hWnd -- 窗口句柄
	IN hdc -- 设备句柄
	IN nColorStyle -- 颜色类型
返回值:无
功能描述:设置设备颜色。
引用: 
************************************************/
void SetPDAEditColor(HWND hWnd,HDC hdc,int nColorStyle)
{
	COLORREF cl_Color;
	CTLCOLORSTRUCT CtlColor;


		CtlColor.fMask = 0xffffffff;
		SendMessage(hWnd,WM_GETCTLCOLOR,0,(LPARAM)&CtlColor);
		if (nColorStyle==NORMALCOLOR)
		{ // Set normal color
			// set Text Color same with normal window
//			SetTextColor(hdc,CL_BLACK);
//			cl_Color = SendMessage(hWnd,EM_GETCOLOR,NORMALTEXTCOLOR,0);
			cl_Color = CtlColor.cl_Text;
			SetTextColor(hdc,cl_Color);
			// set Text background Color same with normal window
//			SetBkColor(hdc,CL_WHITE);
//			cl_Color = SendMessage(hWnd,EM_GETCOLOR,NORMALTEXTBKCOLOR,0);
			cl_Color = CtlColor.cl_TextBk;
			SetBkColor(hdc,cl_Color);
		}
		if (nColorStyle==INVERTCOLOR)
		{ // set invert color
			// set Text Color same with Invert Text
//			SetTextColor(hdc,CL_WHITE);
//			cl_Color = SendMessage(hWnd,EM_GETCOLOR,NORMALINVERTCOLOR,0);
			cl_Color = CtlColor.cl_Selection;
			SetTextColor(hdc,cl_Color);
			// set Text background Color same with Invert text background
//			SetBkColor(hdc,CL_BLACK);
//			cl_Color = SendMessage(hWnd,EM_GETCOLOR,NORMALINVERTBKCOLOR,0);
			cl_Color = CtlColor.cl_SelectionBk;
			SetBkColor(hdc,cl_Color);
		}
		if (nColorStyle==DISABLECOLOR)
		{ // set invert color
			cl_Color = CtlColor.cl_Disable;
			SetTextColor(hdc,cl_Color);

			cl_Color = CtlColor.cl_DisableBk;
			SetBkColor(hdc,cl_Color);
		}
		if (nColorStyle==TITLECOLOR)
		{ // set invert color
			// set Text Color same with Invert Text
			cl_Color = CtlColor.cl_Title;
			SetTextColor(hdc,cl_Color);

			cl_Color = CtlColor.cl_TitleBk;
			SetBkColor(hdc,cl_Color);
		}
		if (nColorStyle==READONLYCOLOR)
		{ // set invert color
			// set Text Color same with Invert Text
			cl_Color = CtlColor.cl_ReadOnly;
			SetTextColor(hdc,cl_Color);

			cl_Color = CtlColor.cl_ReadOnlyBk;
			SetBkColor(hdc,cl_Color);
		}
}
/**************************************************
声明: void DrawPDAEditSpecialText(HWND hWnd,HDC hdc,LPEDITITEM lpEditItem,LPTSTR lpShowAddress,
							   int nShowPos,int nShowLine,int nShowWordLen,DWORD dwFlag)

参数:
	IN hWnd : Handle of the window
	IN hdc  : handle of the device context
	IN lpEditItem : the pointer of the struct EDITITEM
	IN lpShowAddress : It is will be Showed Start Address ,if dwFlag is PE_SHOWCLIENT ,this parameter is ignore     
	IN nShowPos      : This is will be showed Start Position
	IN nShowLine     : This is will be showed start Line
	IN nShowWordLen  : This is will be showed word number,if dwFlag is PE_SHOWSPECIALLEN ,this parameter is valid,
	                other is ignore
	IN dwFlag        : you need Draw style
	    PE_SHOWCLIENT  : draw the whole text
 	   PE_SHOWLINEEND : draw the lpShowAddress from the appoint position to the end of the line
  	  PE_SHOWTEXTEND : draw the lpShowAddress from the appoint position to the end of the TEXT
   	 PE_SHOWSPECIALLEN: draw the lpShowAddress from the appoint position used the appoint len
返回值:无
功能描述:绘制指定文本。
引用: 
************************************************/
 void DrawPDAEditSpecialText(HWND hWnd,HDC hdc,LPEDITITEM lpEditItem,LPTSTR lpShowAddress,
							   int nShowPos,int nShowLine,int nShowWordLen,DWORD dwFlag)
{
	int lpCharWidthBuffer[128];
	int ChineseCharWidth;
	DWORD dwStyle;
	LPTSTR lpCurChar,lpLineAddress;
	int x,y;
	int nAddLen,nShowLen;
	int nCurLine;
	int nCurCharPos,nCurShowPos;
	int nTextHeight;
	int nWindowWidth,nCurCharWidth,nCurCharLen,nWindowHeight;
  int nFMTItem;
  FORMATANALYSIS FmtAnalysis;
  RECT rcClientRect;

		// Send Notification message EN_UPDATE to parent window
		SendNotificationMsg( hWnd,EN_UPDATE);
		// get Line Height
		nTextHeight=GetTextHeight(hWnd);
		// get window width
    nWindowWidth=GetWindowWidth(hWnd,lpEditItem);
	if (dwFlag==PE_SHOWALL)
		nWindowHeight=0x7fff;  // can show untile the end
	else
		nWindowHeight=GetWindowHeight(hWnd);
		// get Char Width for ASCII Code and chinese Code
    GetPDACharWidth(hWnd,lpCharWidthBuffer,&ChineseCharWidth);

//    RETAILMSG(1,( "!!!!!Chinese CHAR Width  = %d\r\n",ChineseCharWidth));

		// Get Edit Control Style
//		dwStyle=GetWindowLong(hWnd,GWL_STYLE);
    dwStyle=lpEditItem->dwStyle;

		// initial variable
		if (dwFlag==PE_SHOWCLIENT||dwFlag==PE_SHOWALL)
		{ // begin from the top of the window
	  	nCurLine=lpEditItem->nDisplayLine;
      lpCurChar=lpLineAddress=GetLineAddress(hWnd,lpEditItem,nCurLine);
		}
		else
		{  // begin from the special address
			if (lpShowAddress==NULL) return;
		  nCurLine=nShowLine;
			lpCurChar=lpLineAddress=lpShowAddress;
		}
//		nClearPos=(int)(nShowPos-lpEditItem->nDisplayx);
//		RETAILMSG(1,("Draw %s \r\n",lpCurChar));

		if ((dwStyle&ES_CENTER)||(dwStyle&ES_RIGHT))
		{ // 对齐方式为中间对齐或右边对齐
			lpCurChar=lpLineAddress=GetLineAddress(hWnd,lpEditItem,nCurLine); // 得到行起始位置
			nShowPos=GetxStartOfLine(hWnd,lpEditItem,lpCurChar); // 得到开始显示位置
			dwFlag=PE_SHOWTEXTEND; // 显示到文本结束
			x=nShowPos-lpEditItem->nDisplayx; // 得到开始显示位置
			y=(nCurLine-lpEditItem->nDisplayLine)*nTextHeight+lpEditItem->iStartPos;
			ClearTextHead(hWnd,hdc,lpEditItem,x,y); // 清除文本前面空白
		}
		// Set Normal Color
		// the initial position in the invert area ,then must set the invert color
		if (lpEditItem->dwStyle&WS_DISABLED)
		{  // 当前为DISABLE
			SetPDAEditColor(hWnd,hdc,DISABLECOLOR);
		}
		else
		{
			if (lpCurChar>=lpEditItem->lpInvertStart&&lpCurChar<lpEditItem->lpInvertEnd)
			{  // 在选择范围内
				SetPDAEditColor(hWnd,hdc,INVERTCOLOR);
			}
			else if (lpCurChar<lpEditItem->lpPDAEditBuffer)
			{ // 是标题
				SetPDAEditColor(hWnd,hdc,TITLECOLOR);
			}
			else if (lpEditItem->dwStyle&ES_READONLY)
			{ // 是只读
				SetPDAEditColor(hWnd,hdc,READONLYCOLOR);
			}
			else
			{  // 一般文本
				SetPDAEditColor(hWnd,hdc,NORMALCOLOR);
			}

		}

		nAddLen=nShowLen=0;
		nCurCharPos=nShowPos;
		nCurShowPos=nShowPos;

		GetClientRect(hWnd,&rcClientRect);
		//  first hide the caret
		HidePDACaret(hWnd);
		// Clear Rewrite Area : ClearRect
/*
		switch (dwFlag)
		{
			case PE_SHOWCLIENT:
				// Clear the whole client area
				ClearTextEnd(hWnd,hdc,0,0);
				break;
			case PE_SHOWLINEEND:
				// clear the appoint line
//				ClearLine(hWnd,(nShowPos-lpEditItem->nDisplayx),(nShowLine-lpEditItem->nDisplayLine));
//				break;
			case PE_SHOWTEXTEND:
				// clear the appoint line to the end
				ClearTextEnd(hWnd,hdc,nClearPos,(int)(nShowLine-lpEditItem->nDisplayLine));
//				ClearTextEnd(hWnd,0,0);
        break;
		}
*/
    if (dwStyle&ES_FORMAT)
    {  // 是格式化条目
      FormatEdit(hWnd,lpEditItem,&FmtAnalysis);
      nFMTItem=GetFmtItem(&FmtAnalysis,lpCurChar)-1;;
    }

    while(TRUE)
		{
// Add By Jami chen in 2003.06.30
			if (lpCurChar == lpEditItem->lpPDAEditBuffer)
			{
					// display Invert area text
					x=nCurShowPos-lpEditItem->nDisplayx;
					y=(nCurLine-lpEditItem->nDisplayLine)*nTextHeight+lpEditItem->iStartPos;
					// display this line
					if (y>=0&&y<nWindowHeight)
					{
//						RETAILMSG(1,("TextOut0 (%d,%d) %s -- %d\r\n",x,y,lpLineAddress,nShowLen));						
						TextOut(hdc,x,y,lpLineAddress,nShowLen);
					}

					// set Next Display Area : Invert Area
					lpLineAddress=lpCurChar;
					nShowLen=0;
					nCurShowPos=nCurCharPos;

					// restore normal area color
					if (!(lpEditItem->dwStyle&WS_DISABLED))
					{
// !!! modified by jami chen in 2004.7.12
//						SetPDAEditColor(hWnd,hdc,NORMALCOLOR);
						if (lpEditItem->dwStyle&ES_READONLY)
						{ // 是只读
							SetPDAEditColor(hWnd,hdc,READONLYCOLOR);
						}
						else
						{  // 一般文本
							SetPDAEditColor(hWnd,hdc,NORMALCOLOR);
						}
// !!! modified End by jami chen in 2004.7.12
					}
			}
// !!! Add End By Jami chen in  2003.06.30
			if (dwFlag==PE_SHOWSPECIALLEN&&nAddLen>=nShowWordLen)
			{  // is or not display need draw length
				x=nCurShowPos-lpEditItem->nDisplayx;
				y=(nCurLine-lpEditItem->nDisplayLine)*nTextHeight+lpEditItem->iStartPos;
				if (y>=0&&y<nWindowHeight)
				{
//					RETAILMSG(1,("TextOut1 (%d,%d) %s -- %d\r\n",x,y,lpLineAddress,nShowLen));						
					TextOut(hdc,x,y,lpLineAddress,nShowLen);
				}
				if (dwStyle&ES_LINESEPARATE)
					DrawLineSeparate(hWnd,hdc,lpEditItem,(int)(nCurLine-lpEditItem->nDisplayLine));
				// exit circle
				break;
			}
			if (*lpCurChar==0x00||nAddLen==(lpEditItem->cbEditLen+lpEditItem->cbTitleLen))
			{  // this is to end edit text
				x=nCurShowPos-lpEditItem->nDisplayx;
				y=(nCurLine-lpEditItem->nDisplayLine)*nTextHeight+lpEditItem->iStartPos;
				if (y>=0&&y<nWindowHeight)
		        {
//					   RETAILMSG(1,("TextOut2 (%d,%d) %s -- %d\r\n",x,y,lpLineAddress,nShowLen));						
					   TextOut(hdc,x,y,lpLineAddress,nShowLen);
					   if (dwStyle&ES_FORMAT)
						{ // display the last item tile
							ShowFormatText(hWnd,hdc,lpEditItem,
                                   (FmtAnalysis.arrayFmtItem[nFMTItem]).lpTileText,
                                   (FmtAnalysis.arrayFmtItem[nFMTItem]).cTileTextLen,
                                   &nCurCharPos,
                                   &nCurLine);
						}

//           ClearLine(hWnd,hdc,lpEditItem,(nCurCharPos-lpEditItem->nDisplayx),nCurLine);
				        ClearTextEnd(hWnd,hdc,lpEditItem,(int)(nCurCharPos-lpEditItem->nDisplayx),y);

#ifndef LINE_BANK
						if (dwStyle&ES_LINESEPARATE)
							DrawLineSeparate(hWnd,hdc,lpEditItem,(int)(nCurLine-lpEditItem->nDisplayLine));
#endif
				}
				// exit circle
				break;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -