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

📄 editbase.c

📁 深圳市微逻辑电子有限公司 巨果&#8226 Kingmos&reg 系统核心
💻 C
📖 第 1 页 / 共 5 页
字号:
			else
			{  // current character is english or sambol
          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];
          }
			}
			// Is or not Multiple Line edit Control
			if (bIsMultiLine)
			{   // is or not enter code ?
				if (*lpCurChar==0x0d&&*(lpCurChar+1)==0x0a)
				{
					// To Next Line
					nCurLine++;
//					nAddWidth=0;
					nAddWidth=GetxStartOfLine(hWnd,lpEditItem,lpCurChar);
					lpCurChar+=2;
					continue;
				}
			  if (dwStyle&ES_AUTONEWLINE)
			  {  // 可以自动换行
				  if (nAddWidth+nCurCharWidth>nWindowWidth)
				    {
								  // To Next Line
								  nCurLine++;
  //								nAddWidth=0;
								  nAddWidth=GetxStartOfLine(hWnd,lpEditItem,lpCurChar);
  //					  continue;
				    }
			  }
			}
			// Get Current Character Width
//			if (*lpCurChar<0)
			if (*lpCurChar<0 || *lpCurChar>0x80)
			{ // to next character
				lpCurChar+=2;
			}
			else
			{ //to next character
				lpCurChar++;
			}
			// add current character width
			nAddWidth+=nCurCharWidth;

		}
		// return Current character Position
		if (lpxPos)
			*lpxPos=nAddWidth;
		if (lpnLine)
			*lpnLine=nCurLine;
		return ;
}
/**************************************************
声明:BOOL PickCharacter(CHAR HiByte,CHAR LoByte,DWORD dwStyle)
参数:
	IN HiByte -- 高字节
	IN LoByte -- 低字节
	IN dwStyle -- 编辑区风格
返回值:需要字符,返回TRUE,否则返回FALSE。
功能描述:选择字符是否符合当前类型的编辑区。
引用: 
************************************************/
 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;
}
/**************************************************
声明: BOOL InsertChar(HWND hWnd,LPEDITITEM lpEditItem,CHAR HiByte,CHAR LoByte)
参数:
	IN hWnd -- 窗口句柄
	IN lpEdititem -- 编辑条目结构指针
	IN HiByte -- 高字节
	IN LoByte -- 低字节
返回值:成功返回TRUE,否则返回FALSE
功能描述:插入字符。
引用: 
************************************************/
 BOOL InsertChar(HWND hWnd,LPEDITITEM lpEditItem,CHAR HiByte,CHAR LoByte)
{
  int nTextLen,nRemainLen;
  int nMoveLen;
//	LPEDITITEM lpEditItem;
	DWORD dwStyle;
  BOOL bReturnCode=TRUE;
  FORMATANALYSIS FmtAnalysis;


	// get struct EDITITEM data
//	lpEditItem=(LPEDITITEM)GetWindowLong(hWnd,0);
//  if (lpEditItem==NULL) return FALSE;
//  dwStyle=GetWindowLong(hWnd,GWL_STYLE);
    dwStyle=lpEditItem->dwStyle;


  if (dwStyle&ES_PASSWORD)
  { // the style is password
		  GetEditText(lpEditItem->lpPDAEditBuffer,lpEditItem->lpPDASaveEditBuffer,(int)(lpEditItem->cbEditLen+1)); // +1 is read end code 'null'
//		GetWindowText(hWnd,lpEditItem->lpPDAEditBuffer,lpEditItem->cbEditLen+1); // +1 is read end code 'null'
  }
  // Get the legnth of the text 
	nTextLen=strlen(lpEditItem->lpPDAEditBuffer);
	// get the length from the caret position to the end (include the end code)
	nMoveLen=strlen(lpEditItem->lpCaretPosition)+1;
	// get the remain length of the window
  if (dwStyle&ES_FORMAT)
  { // the style is format style
    FormatEdit(hWnd,lpEditItem,&FmtAnalysis);
    nRemainLen=CanInsertToFmtItem(&FmtAnalysis,HiByte,LoByte);
  }
  else
  {
	  nRemainLen=lpEditItem->cbEditLimitLen-nTextLen;
  }
	if (HiByte==0)
	{ // this is a english or symbol
		if (nRemainLen<1)
		{ // the remain length is not enough to place the insert char
//			MessageBeep(0xFFFFFFFFL);
			bReturnCode=FALSE;
			SendNotificationMsg( hWnd,EN_MAXTEXT);
		}
    else
    {
		  //place the insert char
		  memmove(lpEditItem->lpCaretPosition+1,lpEditItem->lpCaretPosition,nMoveLen);
		  *(lpEditItem->lpCaretPosition)=LoByte;
		  // move the caret position
		  lpEditItem->lpCaretPosition++;
//      nRemainLen--;
			lpEditItem->fModified=TRUE;
			lpEditItem->cbEditLen=strlen(lpEditItem->lpPDAEditBuffer);
			SaveEditText(lpEditItem->lpPDASaveEditBuffer,lpEditItem->lpPDAEditBuffer,(int)(lpEditItem->cbEditLen+1));
			lpEditItem->bNeedCalcTotalLine = TRUE;
// !!! Add By Jami chen in 2005.04.05
			SetWindowRect(hWnd,lpEditItem,TRUE);
// !!! Add End
//			SendNotificationMsg(hWnd,EN_CHANGE);
    }

	}
	else
	{ // the insert char is chinese
		if (nRemainLen<2)
		{ // the remain length is not enough to place the insert char
//			MessageBeep(0xFFFFFFFF);
			bReturnCode=FALSE;
			SendNotificationMsg( hWnd,EN_MAXTEXT);
		}
		else
		{
			  // place the insert char
			  memmove(lpEditItem->lpCaretPosition+2,lpEditItem->lpCaretPosition,nMoveLen);
			  *(lpEditItem->lpCaretPosition)=HiByte;
			  *(lpEditItem->lpCaretPosition+1)=LoByte;
			  //move caret position
			  lpEditItem->lpCaretPosition+=2;
		//    nRemainLen-=2;
			  lpEditItem->fModified=TRUE;
			  lpEditItem->cbEditLen=strlen(lpEditItem->lpPDAEditBuffer);
			  SaveEditText(lpEditItem->lpPDASaveEditBuffer,lpEditItem->lpPDAEditBuffer,(int)(lpEditItem->cbEditLen+1));
			  lpEditItem->bNeedCalcTotalLine = TRUE;
// !!! Add By Jami chen in 2005.04.05
			  SetWindowRect(hWnd,lpEditItem,TRUE);
// !!! Add End
//			  SendNotificationMsg(hWnd,EN_CHANGE);
		}
	}

//  SetWindowText(hWnd,lpEditItem->lpPDAEditBuffer);
//	lpEditItem->cbEditLen=strlen(lpEditItem->lpPDAEditBuffer);
//	SaveEditText(lpEditItem->lpPDASaveEditBuffer,lpEditItem->lpPDAEditBuffer,(int)(lpEditItem->cbEditLen+1));
  if (dwStyle&ES_PASSWORD)
  {
		// read Window text
    FillPassWordChar(lpEditItem->lpPDAEditBuffer,lpEditItem->cbEditLen,lpEditItem->chPassWordWord);
  }
  if (nRemainLen==0)
  {
    if (dwStyle&ES_FORMAT)
    { //Is format?
      while(*lpEditItem->lpCaretPosition!=0)
      { // jump the next format item
        if (*lpEditItem->lpCaretPosition==FMTSEPARATE)
        {
          lpEditItem->lpCaretPosition++;
//          lpPDAEditState->lpCaretPosition=lpCurChar;
	          return bReturnCode;
        }
        lpEditItem->lpCaretPosition++;
      }
    }
    if (dwStyle&ES_MULTIITEMEDIT)
      SetCaretToNextItem(hWnd,lpEditItem);
//    JumpToNextItem(hWnd,lpEditItem);
  }
	// insert success
	return bReturnCode;
}

/**************************************************
声明:void ClearLine(HWND hWnd,HDC hdc,LPEDITITEM lpEditItem,int xPos,int yPos)
参数:
	IN hWnd -- 窗口句柄
	IN hdc -- 设备句柄
	IN lpEdititem -- 编辑条目结构指针
	IN xPos -- x坐标
	IN yPos -- y坐标
返回值:无
功能描述:清除行指定坐标以后的区域。
引用: 
************************************************/
void ClearLine(HWND hWnd,HDC hdc,LPEDITITEM lpEditItem,int xPos,int yPos)
{
   RECT ClearRect;
//   HDC hdc;
   int nTextHeight;
	 int nWindowWidth;
	 HBRUSH hBrush;

	 //  get line height
	 nTextHeight=GetTextHeight(hWnd);
	 // get window width
	 nWindowWidth=(int)(lpEditItem->rect.right-lpEditItem->rect.left);

	// calculate clear rect
	ClearRect.left=xPos;
	ClearRect.top=yPos;
	ClearRect.right=nWindowWidth;
	ClearRect.bottom =ClearRect.top+nTextHeight;
	// clear ClearRect
//	hdc=GetDC(hWnd);
//	FillRect(hdc,&ClearRect,GetStockObject(WHITE_BRUSH));
	hBrush = GetBkBrush(hWnd,lpEditItem);
	FillRect(hdc,&ClearRect,hBrush);
	DeleteObject(hBrush);
//	ReleaseDC(hWnd,hdc);
}
/**************************************************
声明: void ClearTextEnd(HWND hWnd,HDC hdc,LPEDITITEM lpEditItem,int xPos,int yPos)
参数:
	IN hWnd -- 窗口句柄
	IN hdc -- 设备句柄
	IN lpEdititem -- 编辑条目结构指针
	IN xPos -- x坐标
	IN yPos -- y坐标
返回值:无
功能描述:清除指定坐标以后的所有区域。
引用: 
************************************************/
 void ClearTextEnd(HWND hWnd,HDC hdc,LPEDITITEM lpEditItem,int xPos,int yPos)
{
   RECT ClearRect;
//   HDC hdc;
   int nTextHeight;
   HBRUSH hBrush;


//	RETAILMSG(1,(TEXT("Enter ClearTextEnd ...\r\n")));
	nTextHeight=GetTextHeight(hWnd);

//	hdc=GetDC(hWnd);
	// Get Client Rect
//	GetClientRect(hWnd,&ClientRect);
	// Clear appoint line
	ClearRect.left=xPos;
	ClearRect.top=yPos;
	ClearRect.right=lpEditItem->rect.right;

	ClearRect.bottom =ClearRect.top+nTextHeight;
//	FillRect(hdc,&ClearRect,GetStockObject(WHITE_BRUSH));
	hBrush = GetBkBrush(hWnd,lpEditItem);
	FillRect(hdc,&ClearRect,hBrush);
	// clear next line to the window end

	ClearRect.left=0;
	ClearRect.top=ClearRect.bottom;
	ClearRect.right=lpEditItem->rect.right;
//	ClearRect.bottom =lpEditItem->rect.bottom;
    ClearRect.bottom=lpEditItem->rect.bottom+lpEditItem->iStartPos;

    if (ClearRect.bottom>ClearRect.top)
	{
//	   FillRect(hdc,&ClearRect,GetStockObject(WHITE_BRUSH));
	   FillRect(hdc,&ClearRect,hBrush);
	}

	DeleteObject(hBrush);

#ifdef LINE_BANK
	// 在空白的地方绘制横线
	{
		DWORD dwStyle;

		dwStyle = GetWindowLong(hWnd,GWL_STYLE);
		if (dwStyle&ES_LINESEPARATE)
		{
			int nCurLine,nBottomLine;
			int nWindowHeight;

				nWindowHeight=GetWindowHeight(hWnd);

				nCurLine = (yPos - lpEditItem->iStartPos ) / nTextHeight + lpEditItem->nDisplayLine;
				nBottomLine = nWindowHeight / nTextHeight + lpEditItem->nDisplayLine;

				for (;nCurLine < nBottomLine; nCurLine++)
				{
					DrawLineSeparate(hWnd,hdc,lpEditItem,(int)(nCurLine-lpEditItem->nDisplayLine));
				}
		}
	}
#endif
//	ReleaseDC(hWnd,hdc);
//	RETAILMSG(1,(TEXT("Leave ClearTextEnd ...\r\n")));
}

/**************************************************
声明: void ClearTextHead(HWND hWnd,HDC hdc,LPEDITITEM lpEditItem,int xPos,int yPos)
参数:
	IN hWnd -- 窗口句柄
	IN hdc -- 设备句柄
	IN lpEdititem -- 编辑条目结构指针
	IN xPos -- x坐标
	IN yPos -- y坐标
返回值:无
功能描述:清除指定点以前当前行的区域。
引用: 
************************************************/
 void ClearTextHead(HWND hWnd,HDC hdc,LPEDITITEM lpEditItem,int xPos,int yPos)
{
   RECT ClearRect;
//   HDC hdc;
   int nTextHeight;
   HBRUSH hBrush;

   nTextHeight=GetTextHeight(hWnd);

	// Clear appoint line
	ClearRect.left=lpEditItem->rect.left;
	ClearRect.top=yPos;
	ClearRect.right= xPos;

	ClearRect.bottom =ClearRect.top+nTextHeight;
//	FillRect(hdc,&ClearRect,GetStockObject(WHITE_BRUSH));
	hBrush = GetBkBrush(hWnd,lpEditItem);
	FillRect(hdc,&ClearRect,hBrush);
	DeleteObject(hBrush);
	// clear next line to the window end
}
/**************************************************
声明: void DisplayInvertChange(HWND hWnd,LPEDITITEM lpEditItem)
参数:
	IN hWnd -- 窗口句柄
	IN lpEdititem -- 编辑条目结构指针
返回值:无
功能描述:显示选择区域改变的文本。
引用: 
************************************************/
 void DisplayInvertChange(HWND hWnd,LPEDITITEM lpEditItem)
{
    LPTSTR lpShowAddress;
//	LPEDITITEM lpEditItem;
	int nShowPos,nShowLine;
	int sizeLen;
	HDC hdc;
	DWORD dwStyle;

⌨️ 快捷键说明

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