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

📄 editbase.c

📁 深圳市微逻辑电子有限公司 巨果&#8226 Kingmos&reg 系统核心
💻 C
📖 第 1 页 / 共 5 页
字号:
			// Get caret x-coordinate form window origin
			lpEditItem->nCaretx=nCaretPosition-lpEditItem->nDisplayx;
		}
		return TRUE;
}
/**************************************************
声明: LPTSTR GetLinePosition(HWND hWnd,LPEDITITEM lpEditItem,LPTSTR lpLineStart,int xPos,BOOL bIsMultiLine,int * lpRealPos)
参数:
	IN hWnd -- 窗口句柄
	IN lpEdititem -- 编辑条目结构指针
	IN lpLineStart -- 指定行的起始地址
	IN xPos -- 要调整的原始坐标
	IN bIsMultiLine -- 是否是多行编辑区
	OUT lpRealPos -- 调整后的实际位置
返回值:返回指定坐标的字符指针位置
功能描述:得到指定点在指定行中的实际位置。
引用: 
************************************************/
 LPTSTR GetLinePosition(HWND hWnd,LPEDITITEM lpEditItem,LPTSTR lpLineStart,int xPos,BOOL bIsMultiLine,int * lpRealPos)
{
  int lpCharWidthBuffer[128];
//   LPEDITITEM lpEditItem;
  int ChineseCharWidth;
  int nAddWidth=0;
  int CurCharWidth,nWindowWidth;
  LPSTR lpCurChar,lpPreChar;
  DWORD dwStyle;
  FORMATANALYSIS FmtAnalysis;
  int nFMTItem;
  SIZE Size;

		// get struct EDITITEM data
//		lpEditItem=(LPEDITITEM)GetWindowLong(hWnd,0);
//    if (lpEditItem==NULL) return NULL;
		// get window width
    nWindowWidth=GetWindowWidth(hWnd,lpEditItem);
		// Get Edit Control Style
//		dwStyle=GetWindowLong(hWnd,GWL_STYLE);
    dwStyle=lpEditItem->dwStyle;
		// get Char Width for ASCII Code
    GetPDACharWidth(hWnd,lpCharWidthBuffer,&ChineseCharWidth);

		nAddWidth=GetxStartOfLine(hWnd,lpEditItem,lpLineStart);
		// Get the line Start Address
		lpCurChar=lpLineStart;
		lpPreChar=lpLineStart;
    if (dwStyle&ES_FORMAT)
    {  // 当前条目是格式化条目
      FormatEdit(hWnd,lpEditItem,&FmtAnalysis);  // 格式化编辑区
      nFMTItem=GetFmtItem(&FmtAnalysis,lpCurChar)-1;; // 得到格式化条目
    }
		while(TRUE)
		{
      if (dwStyle&ES_FORMAT)
      { // the current edit is a format edit
          if (lpCurChar==lpEditItem->lpPDAEditBuffer)
          {  // is must calculate the size of the format title
            Size=GetSize(hWnd,FmtAnalysis.lpTitle,
                                    FmtAnalysis.cTitleLen);
            CurCharWidth=(int)Size.cx;
            nAddWidth+=CurCharWidth;
          }
      }
			// to the text end?
			if (*lpCurChar==0x00) 
			{
				// This Line Must include Last Code 
				lpPreChar=lpCurChar;
				break;
			}
			// Is or not Multiple Line edit Control
			if (bIsMultiLine)
			{   // is or not enter code ?
				if (*lpCurChar==0x0d&&*(lpCurChar+1)==0x0a) 
				{
					lpPreChar=lpCurChar; 
					break;
				}
			}
			// Get Current Character Width
//			if (*lpCurChar<0)
			if (*lpCurChar<0 || *lpCurChar>0x7F)
			{  // current Character is a chinese
				CurCharWidth=ChineseCharWidth;
				// to next character
				lpPreChar=lpCurChar;
				lpCurChar+=2;
			}
			else
			{  // current character is english or sambol
          if ((dwStyle&ES_FORMAT)&&(*lpCurChar==FMTSEPARATE))
          { // the current edit is a format edit and the current character is system separate char
            Size=GetSize(hWnd,(FmtAnalysis.arrayFmtItem[nFMTItem]).lpTileText,
                                    (FmtAnalysis.arrayFmtItem[nFMTItem]).cTileTextLen);
            CurCharWidth=(int)Size.cx;
						// to next item
            nFMTItem++;
						if (nFMTItem>=FORMATITEMMAXNUM)
							nFMTItem=FORMATITEMMAXNUM-1;
          }
          else
			      CurCharWidth=lpCharWidthBuffer[*lpCurChar];
				//to next character
				lpPreChar=lpCurChar;
				lpCurChar++;
			}
			// Is or not Special Position
			if (nAddWidth+CurCharWidth>xPos) break;

			if ((dwStyle&ES_AUTONEWLINE)&&bIsMultiLine)
			{
				// Is or not to the edge the window
				if (nAddWidth+CurCharWidth>nWindowWidth) break;
			}
			// add current character width
			nAddWidth+=CurCharWidth;

		}
		// return Current character Position

    if (lpRealPos)
		  *lpRealPos=nAddWidth;
		// return needed width
		return lpPreChar;
}
/**************************************************
声明: int GetxStartOfLine(HWND hWnd,LPEDITITEM lpEditItem,LPCTSTR lpLineAddress)
参数:
	IN hWnd -- 窗口句柄
	IN lpEdititem -- 编辑条目结构指针
	IN lpLineAddress -- 指定行的指针
返回值:返回指定行的起始坐标
功能描述:得到指定行的起始坐标。
引用: 
************************************************/
 int GetxStartOfLine(HWND hWnd,LPEDITITEM lpEditItem,LPCTSTR lpLineAddress)
{
	DWORD dwStyle;
	int nWindowWidth,nLineWidth;
	int xStart;

			dwStyle=lpEditItem->dwStyle;
			if (!((dwStyle&ES_CENTER)||(dwStyle&ES_RIGHT)))
			{ // this edit is left-aligns
				return 0;
			}
			nWindowWidth=GetWindowWidth(hWnd,lpEditItem); // 得到窗口宽度
		    GetLineLength(hWnd,lpEditItem,(LPCTSTR)lpLineAddress,(int *)&nLineWidth); // 得到当前行的字符宽度
	        xStart=0; 
			if (dwStyle&ES_CENTER)
			{
				xStart=(nWindowWidth-nLineWidth)/2; // 将字符显示在中间
			}
			if (dwStyle&ES_RIGHT)
			{
				xStart=nWindowWidth-nLineWidth; // 将字符显示在右边
			}
			return xStart;
}
/**************************************************
声明: LPTSTR GetLineAddress(HWND hWnd,LPEDITITEM lpEditItem,int nLine)
参数:
	IN hWnd -- 窗口句柄
	IN lpEdititem -- 编辑条目结构指针
	IN nLine -- 指定行索引
返回值:返回指定行的地址
功能描述:得到指定行的地址。
引用: 
************************************************/
 LPTSTR GetLineAddress(HWND hWnd,LPEDITITEM lpEditItem,int nLine)
{
//    LPEDITITEM lpEditItem;
	DWORD dwStyle;
	LPTSTR lpCurChar,lpLineAddress;
	int nAddLen;
	int nCurLine;
  int lpCharWidthBuffer[128];
  int ChineseCharWidth,nCurCharWidth,nWindowWidth;
  int nCurCharPos=0;
  FORMATANALYSIS FmtAnalysis;
  int nFMTItem;
  SIZE Size;


		// Get struct EDITITEM data
//		lpEditItem=(LPEDITITEM)GetWindowLong(hWnd,0);
//    if (lpEditItem==NULL) return NULL;
    // Get Char Width
    GetPDACharWidth(hWnd,lpCharWidthBuffer,&ChineseCharWidth);
    // Get Window Width
	// {modified by chen jian ming 2000-08-30
    //nWindowWidth=lpEditItem->rect.right-lpEditItem->rect.left;
	// } to {
	nWindowWidth=GetWindowWidth(hWnd,lpEditItem);
	// end} 2000-08-30
			// Get Edit Control Style
		dwStyle=lpEditItem->dwStyle;

		if (!(dwStyle&ES_MULTILINE))
		{  // the edit control is single line edit
			//if (nLine==0) 
				return lpEditItem->lpPDAControlBuffer;
			//else 
			//	return NULL;
		}
		// initialize variable
		lpCurChar=lpLineAddress=lpEditItem->lpPDAControlBuffer;
		nAddLen=0;
		nCurLine=0;

    if (dwStyle&ES_FORMAT)
    { // The current Edit is a format edit
      FormatEdit(hWnd,lpEditItem,&FmtAnalysis);
      nFMTItem=0;
    }
		while(TRUE)
		{
			// the current line is need line , then exit circle 
			if (nCurLine==nLine)
				break;
			if (*lpCurChar==0x00||nAddLen==(lpEditItem->cbEditLen+lpEditItem->cbTitleLen))
			{  // this is to end edit buffer
				// exit circle
        if (dwStyle&ES_FORMAT)
        {  // must calculate the last item's tile text
            Size=GetSize(hWnd,(FmtAnalysis.arrayFmtItem[nFMTItem]).lpTileText,
                                    (FmtAnalysis.arrayFmtItem[nFMTItem]).cTileTextLen);
            nCurCharWidth=Size.cx;  // 得到字符宽度
        	  if (dwStyle&ES_AUTONEWLINE)
	          {	// 自动换行
		          if (nCurCharPos+nCurCharWidth>nWindowWidth)
              { // 需要换行
                lpLineAddress=lpCurChar;
                nCurCharPos=0;
              }
            }
        }
				break;
			}
      if (dwStyle&ES_FORMAT)
      { // Current edit is a format edit 
          if (lpCurChar==lpEditItem->lpPDAEditBuffer)
          {  // the start of the edit , mist calculate the format title first
            Size=GetSize(hWnd,FmtAnalysis.lpTitle,
                                    FmtAnalysis.cTitleLen);
            nCurCharWidth=Size.cx;
      		  if (nCurCharPos+nCurCharWidth>nWindowWidth)
            {  // 需要换行
      			   nCurLine++;
               nCurCharPos=nCurCharWidth;
               continue; 
            }
            nCurCharPos+=nCurCharWidth;
          }
      }
//			if (*lpCurChar<0)
			if (*lpCurChar<0 || *lpCurChar>0x7F)
			{  // the current character is chinese
        nCurCharWidth=ChineseCharWidth;
			}
			else
			{  // the current character is english or symbol
        if ((dwStyle&ES_FORMAT)&&(*lpCurChar==FMTSEPARATE))
        {  // the current character is system separate code
            Size=GetSize(hWnd,(FmtAnalysis.arrayFmtItem[nFMTItem]).lpTileText,
                                    (FmtAnalysis.arrayFmtItem[nFMTItem]).cTileTextLen);
            nCurCharWidth=Size.cx;
						// to next item 
            nFMTItem++;
						if (nFMTItem>=FORMATITEMMAXNUM)
							nFMTItem=FORMATITEMMAXNUM-1;
        }
        else
        { // get current character width
            nCurCharWidth=lpCharWidthBuffer[*lpCurChar];
        }
			}
			if (*lpCurChar==0x0d&&*(lpCurChar+1)==0x0a)
			{  // this code is enter code , must display this line and to next line
				// to next char
				lpCurChar+=2;
				nAddLen+=2;
				lpLineAddress=lpCurChar;
				nCurLine++;
        nCurCharPos=0;
				// to next circle
				continue;
			}

			if (dwStyle&ES_AUTONEWLINE)
			{	 // current edit may auto newline
					if (nCurCharPos+nCurCharWidth>nWindowWidth)
					{ // to next line
						nCurLine++;
						lpLineAddress=lpCurChar;
						nCurCharPos=0;
					}
			}
			// to next char
      nCurCharPos+=nCurCharWidth;
//			if (*lpCurChar<0)
			if (*lpCurChar<0 || *lpCurChar>0x7F)
			{  // the current character is chinese
				lpCurChar+=2;
				nAddLen+=2;
			}
			else
			{  // the current character is english or symbol
				lpCurChar++;
				nAddLen++;
			}
		}
		// return current line start address
		return lpLineAddress;		
}
/**************************************************
声明: int GetTotalLine(HWND hWnd,LPEDITITEM lpEditItem)
参数:
	IN hWnd -- 窗口句柄
	IN lpEdititem -- 编辑条目结构指针
返回值:返回编辑条目的总行数
功能描述:得到编辑条目的总行数。
引用: 
************************************************/
 int GetTotalLine(HWND hWnd,LPEDITITEM lpEditItem)
{
//    LPEDITITEM lpEditItem;
	DWORD dwStyle;
	LPTSTR lpCurChar;
	int nAddLen;
	int nTotalLine;
  int lpCharWidthBuffer[128];
  int ChineseCharWidth;
  int nCurCharWidth,nWindowWidth;
  int nCurCharPos=0,nCurCharLen;
  FORMATANALYSIS FmtAnalysis;
  int nFMTItem;
  SIZE Size;

	if (lpEditItem->bNeedCalcTotalLine == FALSE)
		return lpEditItem->nTotalLine;
	
	lpEditItem->bNeedCalcTotalLine = FALSE;
  // Get Char Width
    GetPDACharWidth(hWnd,lpCharWidthBuffer,&ChineseCharWidth);
    // Get Window Width
	// {modified by chen jian ming 2000-08-30
//    nWindowWidth=lpEditItem->rect.right-lpEditItem->rect.left;
	//} to {
	nWindowWidth=GetWindowWidth(hWnd,lpEditItem);
	// end} 2000-08-30
		// Get struct EDITITEM data
//		lpEditItem=(LPEDITITEM)GetWindowLong(hWnd,0);
//    if (lpEditItem==NULL) return 0;
		// Get Edit Control Style
		dwStyle=lpEditItem->dwStyle;
		// get edit text length
		lpEditItem->cbEditLen=strlen(lpEditItem->lpPDAEditBuffer);

		if (!(dwStyle&ES_MULTILINE))
		{  // the edit control is single line edit , Only 1 line
			return 1;
		}
		// initialize variable
//		lpCurChar=lpEditItem->lpPDAEditBuffer;
		lpCurChar=lpEditItem->lpPDAControlBuffer;
		nAddLen=0;
		nTotalLine=1;

    if (dwStyle&ES_FORMAT)
    { // 是格式化条目
      FormatEdit(hWnd,lpEditItem,&FmtAnalysis);  // 格式化编辑区
      nFMTItem=0;
      Size=GetSize(hWnd,FmtAnalysis.lpTitle,FmtAnalysis.cTitleLen); // 得到条目尺寸
      nCurCharWidth=(int)Size.cx;  // 当前字符宽度为条目宽度
      nCurCharPos=nCurCharWidth;
    }

		while(TRUE)
		{
			if (*lpCurChar==0x00||nAddLen==(lpEditItem->cbEditLen+lpEditItem->cbTitleLen))
			{  // this is to end edit buffer
        if (dwStyle&ES_FORMAT)
        {  // 当前为格式化条目
          Size=GetSize(hWnd,(FmtAnalysis.arrayFmtItem[nFMTItem]).lpTileText,
                                  (FmtAnalysis.arrayFmtItem[nFMTItem]).cTileTextLen);
          nCurCharWidth=(int)Size.cx;
			    if (dwStyle&ES_AUTONEWLINE)
			    {  // 可以自动换行

⌨️ 快捷键说明

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