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

📄 edit.c

📁 深圳市微逻辑电子有限公司 巨果&#8226 Kingmos&reg 系统核心
💻 C
📖 第 1 页 / 共 5 页
字号:
		// allocate success

		// allocate memory to edit buffer
		// allocate length is INITIALEDITSIAE

		if (lpPDAEditProperty!=NULL)
		{  // 存在创建属性
			// get the text limit
			if (lpPDAEditProperty->cLimited!=0) // 有编辑文本限制
				lpEditItem->cbEditLimitLen=lpPDAEditProperty->cLimited;
			else // 没有设定文本限制
				lpEditItem->cbEditLimitLen=INITIALEDITSIZE;

			// get the edit title text
			if (lpPDAEditProperty->lpTitle!=NULL) // 有标题
				lpEditItem->cbTitleLen=strlen(lpPDAEditProperty->lpTitle); // 得到标题长度
			else // 没有标题文本,设定当前长度为0
				lpEditItem->cbTitleLen=0;
		}
		else
		{ // 没有创建属性,设置默认参数
			lpEditItem->cbEditLimitLen=INITIALEDITSIZE;
			lpEditItem->cbTitleLen=0;
		}

		lpEditItem->cbEditBufferLen=lpEditItem->cbEditLimitLen+1; // 得到缓存大小

		lpEditItem->cbControlBufferLen=lpEditItem->cbEditBufferLen+lpEditItem->cbTitleLen; // 得到控制缓存大小,包含标题
		// allocate memory
		lpEditItem->lpPDAControlBuffer=(LPTSTR)malloc(lpEditItem->cbControlBufferLen); // 得到控制缓存

		if (lpEditItem->lpPDAControlBuffer==NULL)
		{  // allocate failare then free struct EDITITEM and return FALSe
			lpEditItem->cbEditBufferLen=0;
			lpEditItem->cbControlBufferLen=0;
			free(lpEditItem); // 释放空间
//			SendNotificationMsg(hWnd,EN_ERRSPACE);
		    return -1;
		}

		lpEditItem->lpPDASaveEditBuffer=(LPTSTR)malloc(lpEditItem->cbEditBufferLen);  // 分配备份缓存
		if (lpEditItem->lpPDASaveEditBuffer==NULL)
		{  // allocate failare then free struct EDITITEM and return FALSe
		  lpEditItem->cbEditBufferLen=0;
		  lpEditItem->cbControlBufferLen=0;
		  free(lpEditItem->lpPDAControlBuffer);
		  free(lpEditItem);
//		  SendNotificationMsg(hWnd,EN_ERRSPACE);
		  return -1;
		}

		lpEditItem->lpPDAEditBuffer=lpEditItem->lpPDAControlBuffer+lpEditItem->cbTitleLen;  // 分配编辑缓存
		
		// clear struct EDITITEM
//		Clear(lpEditItem);
    ClearEditItemStruct(lpEditItem);  // 清除编辑条目结构

		// read control title text
		if (lpEditItem->cbTitleLen)
		  memcpy(lpEditItem->lpPDAControlBuffer,lpPDAEditProperty->lpTitle, lpEditItem->cbTitleLen );		// Read Text Success 

		// read Window text
		if (lpcs->lpszName!=NULL)
		{  // 有编辑文本
			lpEditItem->cbEditLen=strlen(lpcs->lpszName); // 得到编辑文本的大小
			//  the window text can put the default buffer ???
			if (lpEditItem->cbEditLen>lpEditItem->cbEditLimitLen)
			{ // 文本长度大于文本限制
				lpEditItem->cbEditLen=0;
				SaveEditText(lpEditItem->lpPDASaveEditBuffer,(LPCTSTR)"",(int)(lpEditItem->cbEditLen+1)); // 设置文本为空
			}
			if (dwStyle&ES_PASSWORD)
			{  // 当前是密码显示
				dwStyle&=~ES_MULTILINE;  // 密码只能是单行编辑
				SetWindowLong(hWnd,GWL_STYLE,dwStyle); // 重新设置风格
				// read Window text
				FillPassWordChar(lpEditItem->lpPDAEditBuffer,lpEditItem->cbEditLen,lpEditItem->chPassWordWord); // 用密码字符填充编辑文本
			}
			else
			{
				GetEditText(lpEditItem->lpPDAEditBuffer,lpcs->lpszName,(int)(lpEditItem->cbEditLen+1)); // +1 is read end code 'null' // 得到编辑文本
			}
			SaveEditText(lpEditItem->lpPDASaveEditBuffer,lpcs->lpszName,(int)(lpEditItem->cbEditLen+1));// 保存当前编辑文本
		}
		else
		{ // 没有编辑文本,
			lpEditItem->cbEditLen=0;
			SaveEditText(lpEditItem->lpPDASaveEditBuffer,(LPCTSTR)"",(int)(lpEditItem->cbEditLen+1)); // 设定编辑文本为空
		}
		// Read Text Success

		// get edit format 
		lpEditItem->lpFormat=NULL;  // 设置编辑格式为空
    if (dwStyle&ES_FORMAT)
		{  // 当前编辑为格式编辑
			if (lpPDAEditProperty != NULL && lpPDAEditProperty->lpFormat!=NULL)
			{ // 存在格式编辑
				dwStyle&=~ES_MULTILINE; // 格式编辑只能是当行编辑
				SetWindowLong(hWnd,GWL_STYLE,dwStyle); // 重设风格
				nFormatLen=strlen(lpPDAEditProperty->lpFormat)+1; // 得到格式编辑串的长度
				if (nFormatLen)
				{ 
					lpEditItem->lpFormat=(LPTSTR)malloc(nFormatLen); // 分配格式编辑串缓存
					if (lpEditItem->lpFormat) // 分配成功
						memcpy(lpEditItem->lpFormat,lpPDAEditProperty->lpFormat, nFormatLen );		// Read Text Success 
					else
						SendNotificationMsg(hWnd,EN_ERRSPACE); // 错误
				}
			}
			else
			{ // 不存在格式编辑
				dwStyle&=~ES_FORMAT; // 取消格式编辑
				SetWindowLong(hWnd,GWL_STYLE,dwStyle);
			}
		}
    lpEditItem->dwStyle=dwStyle;  // 得到编辑风格
		lpEditItem->nTotalLine=-1;
		lpEditItem->bNeedCalcTotalLine = TRUE;

/*		
		lpEditItem->cl_NormalText = CL_BLACK;
		lpEditItem->cl_NormalBkColor = CL_WHITE;

		lpEditItem->cl_InvertText = CL_WHITE;
		lpEditItem->cl_InvertBkColor = CL_BLACK;

		lpEditItem->cl_DisableText = CL_LIGHTGRAY;
		lpEditItem->cl_DisableBkColor = CL_WHITE;
*/
		// 设定当前文本的颜色
		lpEditItem->cl_NormalText = GetSysColor(COLOR_WINDOWTEXT);
		lpEditItem->cl_NormalBkColor = GetSysColor(COLOR_WINDOW);

		lpEditItem->cl_InvertText = GetSysColor(COLOR_HIGHLIGHTTEXT);
		lpEditItem->cl_InvertBkColor = GetSysColor(COLOR_HIGHLIGHT);

		lpEditItem->cl_DisableText = GetSysColor(COLOR_GRAYTEXT);
		lpEditItem->cl_DisableBkColor = GetSysColor(COLOR_WINDOW);

		lpEditItem->cl_ReadOnly = lpEditItem->cl_NormalText;
		lpEditItem->cl_ReadOnlyBk = lpEditItem->cl_NormalBkColor;

		lpEditItem->cl_Title = lpEditItem->cl_NormalText;
		lpEditItem->cl_TitleBk = lpEditItem->cl_NormalBkColor;

		// set Initial State to Edit Control
		SetWindowLong(hWnd,0,(LONG)lpEditItem);

		SetPDAEditScrollPage(hWnd);  // 设定滚动条
		lpEditItem->iStartPos=0; // 设定开始位置
		GetClientRect(hWnd,&lpEditItem->rect); // 得到客户去区
		SetWindowRect(hWnd,lpEditItem,FALSE); // 设置窗口大小
		SetPDAEditVScrollPos(hWnd,lpEditItem->nDisplayLine);// 设定垂直滚动条的位置
		SetPDAEditHScrollPos(hWnd,(int)((lpEditItem->nDisplayx)/HSCROLLWIDTH)); // 设定水平滚动条的位置

		// !!! Add By Jami chen in 2003.08.08
		// set default  Caret position 
		SetCaretToStart(hWnd,lpEditItem);  // Add By Jami chen in 2005.01.28
		SetPDACaretPosition(hWnd,lpEditItem,0,0);  // 设定光标位置
		// !!! Add End By Jami  chen in 2003.08.08

//		RETAILMSG(1,(TEXT("Leave InitialPDAEdit ...\r\n")));
		// initial success ,return TRUE
		return 0;
}
// **************************************************
// 声明:static LRESULT DoSetFocus(HWND hWnd,WPARAM wParam,LPARAM lParam)
// 参数:
// 	IN hWnd -- 窗口句柄
// 	IN wParam -- 保留
// 	IN lParam -- 保留
// 返回值:无
// 功能描述:设置焦点,处理WM_SETFOCUS消息。
// 引用: 
// *************************************************
static LRESULT DoSetFocus(HWND hWnd,WPARAM wParam,LPARAM lParam)
{
//	DWORD dwStyle;
    LPEDITITEM lpEditItem;

		  lpEditItem=(LPEDITITEM)GetWindowLong(hWnd,0);  // 得到编辑条目结构指针
      if(lpEditItem==NULL) return FALSE;


	  CreatePDACaret(hWnd,lpEditItem);  // 创建光标
//			dwStyle=GetWindowLong(hWnd,GWL_STYLE);
//			if (dwStyle&ES_MULTIITEMEDIT)
//			{
//				hParentWnd=GetParent(hWnd);
	  SendNotificationMsg( hWnd,EN_SETFOCUS); // 发送通知消息
//			}
      SetPDACaret(hWnd);  // 设置光标位置
      // show caret
      ShowPDACaret(hWnd); // 显示光标
      wParam++;
      lParam++;
			return 0;
}

// **************************************************
// 声明:static LRESULT DoKillFocus(HWND hWnd,WPARAM wParam,LPARAM lParam)
// 参数:
// 	IN hWnd -- 窗口句柄
// 	IN wParam -- 保留
// 	IN lParam -- 保留
// 返回值:无
// 功能描述:杀死焦点,处理WM_KILLFOCUS消息。
// 引用: 
// **************************************************
static LRESULT DoKillFocus(HWND hWnd,WPARAM wParam,LPARAM lParam)
{
    LPEDITITEM lpEditItem;

		  lpEditItem=(LPEDITITEM)GetWindowLong(hWnd,0);// 得到编辑条目结构指针
      if(lpEditItem==NULL) return FALSE;

// !!! Modified By jami chen in 2005.01.12 
//      ClearInvert(hWnd,lpEditItem,TRUE); // 清除选择
// !!! to  By Jami chen in 2005.01.12
	  if (!(lpEditItem->dwStyle & ES_NOHIDESEL ))
	  {
	      ClearInvert(hWnd,lpEditItem,TRUE); // 清除选择
	  }
// !!! Modified  End
	    DeletePDACaret(hWnd); // 删除光标
	    SendNotificationMsg(hWnd,EN_KILLFOCUS);  // 发送通知消息
      wParam++;
      lParam++;
    	return 0;
}
/*****************************************************************/
/*****************************************************************/
// **************************************************
// 声明:static LRESULT DoSize(HWND hWnd,WPARAM wParam,LPARAM lParam)
// 参数:
// 	IN hWnd -- 窗口句柄
// 	IN wParam -- 保留
// 	IN lParam -- 保留
// 返回值:无
// 功能描述:改变窗口大小,处理WM_SIZE消息。
// 引用: 
// **************************************************
static LRESULT DoSize(HWND hWnd,WPARAM wParam,LPARAM lParam)
{
  LPEDITITEM lpEditItem;
  RECT rectNew;
  int nShowPos,nShowLine;
  LPTSTR lpShowAddress;
  DWORD dwStyle;

		lpEditItem=(LPEDITITEM)GetWindowLong(hWnd,0);// 得到编辑条目结构指针
		if(lpEditItem==NULL) return FALSE;
		GetClientRect(hWnd,&rectNew); // 得到客户区域
		lpEditItem->rect.right=rectNew.right; // 设置新的大小
		lpEditItem->rect.bottom=rectNew.bottom; // 设置新的大小

		// !!! Add By Jami chen in 2004.08.21
/*		if (nTotalLine<=nPageLine)
		{ // not a page ,so not need scroll
			nMinPos=0;
			nMaxPos=nPageLine-1;//-nWindowLine+1;
			Edit_SetScrollRange(hWnd,SB_VERT,nMinPos,nMaxPos,TRUE);
			EnableScrollBar(hWnd,SB_VERT,ESB_DISABLE_BOTH);
		}
*/

		SetPDAEditScrollPage(hWnd);
		SetPDAEditVScrollRange(hWnd,lpEditItem->nTotalLine);  // 设置垂直滚动条的范围
		SetPDAEditVScrollPos(hWnd,lpEditItem->nDisplayLine);
		SetPDAEditHScrollPos(hWnd,(int)((lpEditItem->nDisplayx)/HSCROLLWIDTH));

		dwStyle = GetWindowLong(hWnd,GWL_STYLE);
		lpShowAddress=lpEditItem->lpCaretPosition;
		GetCoordinate(hWnd,lpEditItem,lpShowAddress,&nShowPos,&nShowLine,dwStyle&ES_MULTILINE);
		lpEditItem->nCaretx=nShowPos-lpEditItem->nDisplayx;
		lpEditItem->nCaretLine=nShowLine-lpEditItem->nDisplayLine;
		AdjustCaretInEditItem(hWnd,lpEditItem);  // 调整光标位置
		SetPDACaret(hWnd);
		InvalidateRect(hWnd,NULL,TRUE);
		// !!! Add End By Jami chen in 2004.08.21
		return 0;
}

#ifdef DITHERING_DEAL  // 抖动处理
static int old_x = -1,old_y = -1;
#endif

// **************************************************
// 声明:static LRESULT DoLButtonDown(HWND hWnd,WPARAM wParam,LPARAM lParam)
// 参数:
// 	IN hWnd -- 窗口句柄
// 	IN wParam -- 保留
// 	IN lParam -- MAKELPARAM(x,y),当前鼠标的位置
// 返回值:无
// 功能描述:处理WM_LBUTTONDOWN消息。
// 引用: 
// **************************************************
static LRESULT DoLButtonDown(HWND hWnd,WPARAM wParam,LPARAM lParam)
{
	int xPos,yPos;
  LPEDITITEM lpEditItem;

		  lpEditItem=(LPEDITITEM)GetWindowLong(hWnd,0);// 得到编辑条目结构指针
      if(lpEditItem==NULL) return FALSE;


			// Get LButton down Position
			xPos=(int)(short)LOWORD(lParam);
			yPos=(int)(short)HIWORD(lParam);

#ifdef DITHERING_DEAL  // 抖动处理
			old_x = xPos;
			old_y = yPos;
#endif

			// set Caret position to LButton Down Position
			SetPDACaretPosition(hWnd,lpEditItem,xPos,yPos);  // 设置光标位置

			//  is or not get facus???
			if (GetFocus()!=hWnd)  // 得到焦点窗口是否在当前窗口
			{  // if not active then get focus
				SetFocus(hWnd); // 设置焦点窗口
			}

			// Clear Invert and redraw
			ClearInvert(hWnd,lpEditItem,TRUE);  // 清除选择
			//// set caret position
			//SetPDACaret(hWnd);

			// Capture the mouse
			if (GetCapture()!=hWnd)
				SetCapture(hWnd);

			// set Invert Area
			SetInvertArea(hWnd,lpEditItem);

      if (AdjustCaretInEditItem(hWnd,lpEditItem)==TRUE)  // 调整光标位置
			{
				// Redraw the window
//				DrawPDAEditControl(hWnd,hdc);
				InvalidateRect(hWnd,NULL,TRUE); // 需要重绘窗口
			}

			// set caret position
			SetPDACaret(hWnd);  // 设置光标

      // show caret
      ShowPDACaret(hWnd);  // 显示光标
      wParam++;
    return 0;
}
// **************************************************
// 声明:static LRESULT DoMouseMove(HWND hWnd,WPARAM wParam,LPARAM lParam)
// 参数:
// 	IN hWnd -- 窗口句柄
// 	IN wParam -- 保留
// 	IN lParam -- MAKELPARAM(x,y),当前鼠标的位置
// 返回值:无
// 功能描述:处理WM_MOUSEMOVE消息。
// 引用: 
// **************************************************
static LRESULT DoMouseMove(HWND hWnd,WPARAM wParam,LPARAM lParam)
{
	int xPos,yPos;
  LPEDITITEM lpEditItem;


	// if the mouse be capture by this window
	if (GetCapture()==hWnd)
	{  

			// Get LButton down Position
			xPos=(int)(short)LOWORD(lParam);
			yPos=(int)(short)HIWORD(lParam);

#ifdef DITHERING_DEAL  // 抖动处理
			if (((old_x - xPos) > -3 && (old_x - xPos) < 3) && 
				((old_y - yPos) > -3 && (old_y - yPos) < 3))
			{

⌨️ 快捷键说明

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