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

📄 medit.c

📁 在ecos 下mingui 的移植开发
💻 C
📖 第 1 页 / 共 5 页
字号:
	RECT rc;	int i;	PMLEDITDATA pMLEditData;		pMLEditData =(PMLEDITDATA) GetWindowAdditionalData2(hWnd);	GetClientRect (hWnd, &rc);	i = ((rc.right - rc.left - pMLEditData->rightMargin - pMLEditData->leftMargin) / GetSysCharWidth ());	return i;}int GetMaxLen (HWND hWnd, PMLEDITDATA pMLEditData){	int i;	PLINEDATA pLineData = pMLEditData->head;		i = 0;	while (pLineData)	{		edtGetLineInfo (hWnd, pLineData);		if (pMLEditData->sz.cx > i) 			i = pMLEditData->sz.cx;		pLineData = pLineData->next;	}	return i;}static int  edtGetNewvPos (HWND hWnd, PLINEDATA pLineData , int pos){	int i = 0;	int dist = MAX_IMPOSSIBLE;	int newdist = 0;		PMLEDITDATA pMLEditData =(PMLEDITDATA) GetWindowAdditionalData2(hWnd);	//fprintf (stderr, "<===== In edtGetNewvPos =====>\n");	edtGetLineInfo (hWnd, pLineData);	if (pos < 0)		return -1;	if (pos > pMLEditData->sz.cx)		return -2;	for (i=0; i<pMLEditData->fit_chars + 1; i++) {		newdist = pos - pMLEditData->dx_chars[i];		if (newdist > 0 && newdist < dist) {			dist = newdist;		}else {				return i;		}	}	return 0;}static void edtSetScrollInfo (HWND hWnd, PMLEDITDATA pMLEditData, BOOL fRedraw){	SCROLLINFO 	si;	PLINEDATA 	pLineData;	RECT 		rc;	int 		viLn;	int 		viCol;	// Vscroll	GetClientRect (hWnd, &rc);	viLn = (rc.bottom - pMLEditData->topMargin - pMLEditData->bottomMargin) / GetSysCharHeight ();	viCol = GetMaxCol (hWnd);		si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;	si.nMax = pMLEditData->lines - 1;	si.nMin = 0;	si.nPage = min (pMLEditData->EndlineDisp - pMLEditData->StartlineDisp + 1, viLn);		si.nPos = pMLEditData->StartlineDisp;		if (si.nMax < viLn) {		si.nMax = 100;		si.nMin = 0;		si.nPage = 10;		si.nPos = 0;		SetScrollInfo (hWnd, SB_VERT, &si, fRedraw);		EnableScrollBar (hWnd, SB_VERT, FALSE);	} else {		SetScrollInfo (hWnd, SB_VERT, &si, fRedraw);		EnableScrollBar (hWnd, SB_VERT, TRUE);	}		// Hscroll	pLineData = GetLineData(pMLEditData, pMLEditData->editLine);	si.nMax = GetMaxLen(hWnd, pMLEditData) - 1;	si.nMin = 0;	si.nPage = edtGetOutWidth (hWnd);	edtGetLineInfo (hWnd, pLineData);	si.nPos = pMLEditData->dx_chars[pMLEditData->vdispPos];				if (si.nMax < viCol) {		si.nMax = 100;		si.nMin = 0;		si.nPage = 10;		si.nPos = 0;		SetScrollInfo (hWnd, SB_HORZ, &si, fRedraw);		EnableScrollBar (hWnd, SB_HORZ, FALSE);	} else {		SetScrollInfo (hWnd, SB_HORZ, &si, fRedraw);		EnableScrollBar (hWnd, SB_HORZ, TRUE);	}}BOOL edtGetCaretValid (HWND hWnd, int lineNO, int olddispPos, int newOff){	PLINEDATA temp;	PMLEDITDATA pMLEditData =(PMLEDITDATA) GetWindowAdditionalData2(hWnd);			temp = GetLineData (pMLEditData, lineNO);	edtGetLineInfo (hWnd, temp);	if( olddispPos > pMLEditData->sz.cx ) 	{		pMLEditData->veditPos = pMLEditData->fit_chars;       	pMLEditData->vdispPos = edtGetStartDispPosAtEnd (hWnd, temp);		return TRUE;	}					else 	{		pMLEditData->veditPos = edtGetNewvPos (hWnd, temp, newOff);		if (pMLEditData->veditPos == -2)			pMLEditData->veditPos = pMLEditData->fit_chars;		pMLEditData->vdispPos = edtGetNewvPos (hWnd, temp, olddispPos);		if (olddispPos != pMLEditData->dx_chars[pMLEditData->vdispPos])			return TRUE;	}	return FALSE;}void edtSetCaretPos (HWND hWnd){	PMLEDITDATA pMLEditData =(PMLEDITDATA) GetWindowAdditionalData2(hWnd);    SetCaretPos (hWnd, 				pMLEditData->dx_chars[pMLEditData->veditPos] 					- pMLEditData->dx_chars[pMLEditData->vdispPos]                    + pMLEditData->leftMargin, 				(pMLEditData->editLine-pMLEditData->StartlineDisp) * GetSysCharHeight() //Mneeded	                + pMLEditData->topMargin);	ShowCaret (hWnd);}// added by leon to optimize displayint MLEditCtrlProc (HWND hWnd, int message, WPARAM wParam, LPARAM lParam){       DWORD       dwStyle;    HDC         hdc;	PLINEDATA  pLineData;	RECT		clientRect;    PMLEDITDATA pMLEditData;    dwStyle     = GetWindowStyle(hWnd);    switch (message)    {        case MSG_CREATE:		{            if (!(pMLEditData = malloc (sizeof (MLEDITDATA)))) {                //fprintf (stderr, "EDIT: malloc error!\n");                return -1;            }            if (!CreateCaret (hWnd, NULL, 1, GetSysCharHeight ()))            {                //fprintf (stderr, "EDIT: Create Caret error!\n");                free (pMLEditData);                return -1;            }            pMLEditData->status         = 0;            pMLEditData->totalLen       = LEN_MLEDIT_BUFFER;            pMLEditData->editPos        = 0;            pMLEditData->editLine       = 0;            pMLEditData->caretPos       = 0;			MLEditInitBuffer (pMLEditData, GetWindowCaption(hWnd));				GetClientRect(hWnd,&clientRect);            			pMLEditData->MaxlinesDisp   = (clientRect.bottom-clientRect.top)/GetSysCharHeight();			pMLEditData->linesDisp		= min(pMLEditData->MaxlinesDisp,pMLEditData->lines);			pMLEditData->StartlineDisp  = 0;			pMLEditData->EndlineDisp    = pMLEditData->StartlineDisp + pMLEditData->linesDisp - 1;            pMLEditData->selStartPos    = 0;            pMLEditData->selEndPos      = 0;            pMLEditData->passwdChar     = '*';            pMLEditData->leftMargin     = MARGIN_MEDIT_LEFT;            pMLEditData->topMargin      = MARGIN_MEDIT_TOP;            pMLEditData->rightMargin    = MARGIN_MEDIT_RIGHT;            pMLEditData->bottomMargin   = MARGIN_MEDIT_BOTTOM;            pMLEditData->hardLimit      = -1;                        // undo information            pMLEditData->lastOp         = MEDIT_OP_NONE;            pMLEditData->lastPos        = 0;            pMLEditData->affectedLen    = 0;            pMLEditData->undoBufferLen  = LEN_MLEDIT_UNDOBUFFER;            pMLEditData->undoBuffer [0] = '\0';			pMLEditData->pos_chars = (int*)malloc(LEN_MLEDIT_BUFFER*sizeof(int));			pMLEditData->dx_chars = (int*)malloc(LEN_MLEDIT_BUFFER*sizeof(int));			/*			fprintf (stderr, "pos_chars = %p\n",pMLEditData->pos_chars);			fprintf (stderr, "dx_chars = %p\n",pMLEditData->dx_chars);			*/						memset (pMLEditData->pos_chars, 0, LEN_MLEDIT_BUFFER*sizeof(int));			memset (pMLEditData->dx_chars , 0, LEN_MLEDIT_BUFFER*sizeof(int));			pMLEditData->fit_chars = 0;			pMLEditData->vdispPos = 0;			pMLEditData->veditPos = 0;			pMLEditData->logfont = NULL;						SetWindowAdditionalData2(hWnd,(DWORD)pMLEditData);			SetWindowAdditionalData(hWnd,(DWORD)0);						// added by leon for scrollbars			edtSetScrollInfo (hWnd, pMLEditData, TRUE);        	// added by leon for scrollbars						break;		}        case MSG_DESTROY:        {			pMLEditData =(PMLEDITDATA) GetWindowAdditionalData2(hWnd);		    DestroyCaret (hWnd);			MLEditEmptyBuffer(pMLEditData);			free (pMLEditData->pos_chars);			free (pMLEditData->dx_chars);			pMLEditData->pos_chars = NULL;			pMLEditData->dx_chars = NULL;            free(pMLEditData); 			//fprintf (stderr, "<--- In medit : After free --->\n");		}        break;                case MSG_SIZECHANGED:        break;        case MSG_SETFONT:        {            PLOGFONT old;			pMLEditData =(PMLEDITDATA) GetWindowAdditionalData2(hWnd);            old = pMLEditData->logfont;            pMLEditData->logfont = (PLOGFONT)lParam;            pMLEditData->vdispPos = 0;            pMLEditData->veditPos = 0;            edtSetCaretPos (hWnd);            edtSetScrollInfo (hWnd, pMLEditData, TRUE);            InvalidateRect (hWnd, NULL, TRUE);            return (int)old;        }        break;                case MSG_GETFONT:			pMLEditData =(PMLEDITDATA) GetWindowAdditionalData2(hWnd);            return (int)pMLEditData->logfont;        break;                case MSG_SETCURSOR:            if (dwStyle & WS_DISABLED) {                SetCursor (GetSystemCursor (IDC_ARROW));                return 0;            }        break;        case MSG_KILLFOCUS:		{			pMLEditData = (PMLEDITDATA) GetWindowAdditionalData2 (hWnd);            pMLEditData->status &= ~EST_FOCUSED;            HideCaret (hWnd);			NotifyParent (hWnd, GetDlgCtrlID(hWnd), EN_KILLFOCUS);		}        break;                case MSG_SETFOCUS:		{			pMLEditData = (PMLEDITDATA) GetWindowAdditionalData2 (hWnd);            if (pMLEditData->status & EST_FOCUSED)                return 0;                        pMLEditData->status |= EST_FOCUSED;            // only implemented for ES_LEFT align format.			edtSetCaretPos (hWnd);			/*            SetCaretPos (hWnd,                 pMLEditData->caretPos * GetSysCharWidth ()                     + pMLEditData->leftMargin,                 pMLEditData->topMargin);                            ShowCaret (hWnd);			*/            ActiveCaret (hWnd);			NotifyParent (hWnd, GetDlgCtrlID(hWnd), EN_SETFOCUS);		}        break;                case MSG_ENABLE:            if ( (!(dwStyle & WS_DISABLED) && !wParam)                    || ((dwStyle & WS_DISABLED) && wParam) ) {                if (wParam)					ExcludeWindowStyle(hWnd,WS_DISABLED);                else					IncludeWindowStyle(hWnd,WS_DISABLED);                InvalidateRect (hWnd, NULL, FALSE);            }        return 0;        case MSG_NCPAINT:            if (wParam)                hdc = wParam;            else                hdc = GetDC (hWnd);            if (lParam)                ClipRectIntersect (hdc, (RECT*)lParam);			            if (dwStyle & WS_BORDER)			{				RECT rc;				GetWindowRect(hWnd,&rc);                Draw3DDownFrame (hdc, 0, 0,                                       rc.right - rc.left - 1,                                       rc.bottom - rc.top - 1,                                      PIXEL_invalid);			}            if (!wParam)                ReleaseDC (hdc);        if ((dwStyle & WS_VSCROLL ) || (dwStyle & WS_HSCROLL )) break;        return 0;        case MSG_PAINT:        {            int     i;            char*   dispBuffer;            RECT    rect;                        pMLEditData =(PMLEDITDATA) GetWindowAdditionalData2(hWnd);            hdc = BeginPaint (hWnd);            if (pMLEditData->logfont)                SelectFont (hdc, pMLEditData->logfont);            GetClientRect (hWnd, &rect);                if (dwStyle & WS_DISABLED)            {                SetBrushColor (hdc, PIXEL_lightgray);                FillBox (hdc, 0, 0, rect.right, rect.bottom);                SetBkColor (hdc, PIXEL_lightgray);            }            else {                SetBrushColor (hdc, PIXEL_lightwhite);                FillBox (hdc, 0, 0, rect.right, rect.bottom);                SetBkColor (hdc, PIXEL_lightwhite);            }            SetTextColor (hdc, PIXEL_black);			//fprintf (stderr, "Paint   dispPos = %d\n", pMLEditData->dispPos);			for(i = pMLEditData->StartlineDisp; i <= pMLEditData->EndlineDisp; i++)			{				pLineData= GetLineData(pMLEditData,i);            	edtGetLineInfo (hWnd, pLineData);         	    if (pMLEditData->fit_chars == 0 && pMLEditData->EndlineDisp >= pMLEditData->lines) {                	continue;           		 }#ifdef _DEBUG       	    	if (pMLEditData->dispPos > pLineData->dataEnd) {        	       // fprintf (stderr, "ASSERT failure: %s.\n", "Edit Paint");				}#endif                            dispBuffer = alloca (LEN_MLEDIT_BUFFER+1);				//edtGetLineInfo (hWnd, pLineData);                if (dwStyle & ES_PASSWORD)                    memset (dispBuffer, '*', pLineData->dataEnd);				    memcpy (dispBuffer,                    	    pLineData->buffer,// +pMLEditData->dispPos,						pLineData->dataEnd);// - pMLEditData->dispPos);               		dispBuffer[pLineData->dataEnd] = '\0';            // only implemented ES_LEFT align format for single line edit.                rect.left = pMLEditData->leftMargin;                rect.top = pMLEditData->topMargin ;                rect.right = pMLEditData->rightMargin;                rect.bottom = pMLEditData->bottomMargin;//				printf("lineNO=%d,lines=%d,editLine=%d\n",pLineData->lineNO,pMLEditData->lines,//						pMLEditData->editLine);//				printf("--dispBuffer=%s--\n",dispBuffer);                ClipRectIntersect (hdc, &rect);				/*

⌨️ 快捷键说明

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