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

📄 sedit.c

📁 dos 1.0 其中包含quick basic源代码、内存管理himem emm386 发展历史
💻 C
📖 第 1 页 / 共 2 页
字号:
	if (ichSel != ichCursor)
		{
		if (ichSel < ichCursor)
			{
			ichStart = ichSel;
			ichEnd = ichCursor-1;
			}
		else
			{
			ichStart = ichCursor+1;
			ichEnd = ichSel;
			}
		ichEnd = min(ichMac-1, ichEnd);
		cch = ichEnd - ichStart + 1;
		bltbyte((char *) (pwnd->szDialog) + ichStart, sz, cch);
		sz[cch] = '\0';
		}
	else
		*sz = '\0';
	}



PRIVATE DWORD FARPUBLIC			/* WndProcs are PUBLIC */
InternalEditWndProc(pwnd, message, wParam, lParam)
/*
  -- the Edit Window Procedure
*/
REGISTER PWND pwnd;
WORD message, wParam;
DWORD lParam;
	{
	MSP	msp;
	RRC	rrc;
	BOOL	fResetSelection;
	WORD	ichRight;
	BOOL	fOk;	/* for return */

	Assert(!FFocus(pwnd) || pwnd == pwndFocus);

	GetClientRrc(pwnd,&rrc);

	fResetSelection = FALSE;
	ichRight = min(pwnd->ichLeftEb + rrc.rxRight - 1, pwnd->ichMacEb);

	switch(message)
		{
	default:
	/*case WM_ACTIVATE:*/
		return FALSE;
		/*break;*/

	case WM_PAINT:
		if (!pwnd->fNoBracketEb)
			{
			/* put brackets at start and end of edit item */
			/*  NOTE : brackets drawn outside the window !! */
			DrawThisWnd(NULL);
			CharOutAbs(pwnd->arcWindow.axLeft-1,
			    pwnd->arcWindow.ayTop, '[', pwnd->isaEb);
			CharOutAbs(pwnd->arcWindow.axRight,
			    pwnd->arcWindow.ayTop, ']', pwnd->isaEb);
			}
		DisplayEb(pwnd);
		break;

	case WM_LBUTTONDOWN:
		SetFocus(pwnd);
		HiliteEditSel(pwnd, FALSE);
		msp.lParam = lParam;
		if (msp.s.ax < pwnd->arcClipping.axLeft)
			pwnd->ichCursorEb = pwnd->ichLeftEb;
		else if (msp.s.ax > pwnd->arcClipping.axRight)
			pwnd->ichCursorEb = ichRight-1;
		else
			pwnd->ichCursorEb =
			    min(pwnd->ichMacEb, msp.s.rx+pwnd->ichLeftEb);
		pwnd->ichSelEb = pwnd->ichCursorEb;
		SetCapture(pwnd);
		fResetSelection = TRUE;
		break;

	case WM_MOUSEMOVE:
		if (FCaptured(pwnd))
			{
			HiliteEditSel(pwnd, FALSE);
			msp.lParam = lParam;
			if (msp.s.ax < pwnd->arcClipping.axLeft)
				{
				MoveCursorLeft(pwnd);
				SetAlarm(pwnd, ctickRepEdit);
				}
			else if (msp.s.ax >= pwnd->arcClipping.axRight)
				{
				MoveCursorRight(pwnd);
				SetAlarm(pwnd, ctickRepEdit);
				}
			else
				{
				pwnd->ichCursorEb =
				      min((WORD) msp.s.rx + pwnd->ichLeftEb,
				          pwnd->ichMacEb);
				}
			}
		break;

	case WM_ALARM:
		if (FCaptured(pwnd))
			{
			if (axMouse < pwnd->arcClipping.axLeft)
				{
				MoveCursorLeft(pwnd);
				SetAlarm(pwnd, ctickRepEdit);
				}
			else if (axMouse > pwnd->arcClipping.axRight)
				{
				MoveCursorRight(pwnd);
				SetAlarm(pwnd, ctickRepEdit);
				}
			}
		break;

	case WM_LBUTTONUP:
		if (FCaptured(pwnd))
			{
			ReleaseCapture();
			KillAlarm();
			}

		break;

	case WM_KILLFOCUS:
		HiliteEditSel(pwnd, FALSE);
		EnableCursor(pwnd, FALSE);
		SetFFocus(pwnd, FALSE);
		SendMessage(pwnd->pwndParent,WM_DIALOG_KILLFOCUS,pwnd->id,0L);
		if (FChanged(pwnd))
			SendMessage(pwnd->pwndParent, WM_DIALOG, pwnd->id,
			    MAKELONG((PWND) pwnd, EN_CHANGE));
		return TRUE;
		/*break;*/

	case WM_WANTFOCUS:
		return (pwnd->fEnabled); /* don't go to disabled edit item */
		/*break;*/

	case WM_SETFOCUS:
		SetFFocus(pwnd, TRUE);
		SetFChanged(pwnd, FALSE);
		SendMessage(pwnd->pwndParent,WM_DIALOG_SETFOCUS,pwnd->id,0L);
		if (pwnd->fRetainSelEb)
			break;	/* retain old selection */
		/* set selection to all of edit window */
		lParam = MAKELONG(0, ichSelectEnd);
		/* fall through to set selection */

	case EM_SETSEL:
		{
		REGISTER WORD ichLim;

		if ((ichLim = HIWORD(lParam)) == ichSelectEnd)
			{
			/* special case for select till end */
			ichLim = pwnd->ichMacEb;
			}

		AssertSz(LOWORD(lParam) <= ichLim && ichLim <= pwnd->ichMacEb,
		    "invalid Edit selection");

		HiliteEditSel(pwnd, FALSE);
		pwnd->ichCursorEb = ichLim;
		pwnd->ichSelEb = LOWORD(lParam);
		if (ichLim < pwnd->ichLeftEb || ichLim > ichRight)
			{
			/* selection outside visible region */
			WORD cchMac = rrc.rxRight;

			pwnd->ichLeftEb = (ichLim < cchMac) ? 0 :
			    ichLim - cchMac + cchMac / 8;
				/* show end of selection */
			DisplayEb(pwnd);
			}
		} /*EM_SETSEL*/
		break;

	case EM_GETSEL:
		{
		if (pwnd->ichCursorEb > pwnd->ichSelEb)
			return(MAKELONG(pwnd->ichSelEb, pwnd->ichCursorEb));
		else
			return(MAKELONG(pwnd->ichCursorEb, pwnd->ichSelEb));
		break;
		}

	/*
	*  NOTE : for WM_CUT, WM_PASTE and WM_COPY
	*	API specifies "lParam" contains far pointer,
	*	make sure it is in the DDS, then use near pointer
	*/

	case WM_CUT:
		HiliteEditSel(pwnd, FALSE);
		AssertSz(HIWORD(lParam) == HIWORD((char far *) pwnd),
		    "CUT buffer must be in default data segment");
		DeleteSelection(pwnd, (char *) LOWORD(lParam));
		SetFChanged(pwnd, TRUE);
		fResetSelection = TRUE;
		break;

	case WM_PASTE:
		HiliteEditSel(pwnd, FALSE);
		DeleteSelection(pwnd, NULL);
		fResetSelection = TRUE;
		AssertSz(HIWORD(lParam) == HIWORD((char far *) pwnd),
		    "PASTE buffer must be in default data segment");
		PasteSz(pwnd, (char *) LOWORD(lParam));
		SetFChanged(pwnd, TRUE);
		break;

	case WM_COPY:
		HiliteEditSel(pwnd, FALSE);
		AssertSz(HIWORD(lParam) == HIWORD((char far *) pwnd),
		    "COPY buffer must be in default data segment");
		CopySelection(pwnd, (char *) LOWORD(lParam));
		break;

	case WM_INSERT:
		goto insert_char;
		
	case WM_CHAR:
		{
		UndoRepeat(wParam, lParam);

		if (HIWORD(lParam) & KK_MENU)
			return FALSE;	/* ignore ALT keys */

		HiliteEditSel(pwnd, FALSE);
		if (FCaptured(pwnd))
			{
			ReleaseCapture();
			KillAlarm();
			}
		fResetSelection = TRUE;

		if (wParam >= wEditFirst && wParam <= wEditLast)
			{
			if (wParam == chDelete)
				{
				if (pwnd->ichCursorEb != pwnd->ichSelEb)
					DeleteSelection(pwnd, NULL);
				else
					DelChRight(pwnd);
				}
			else
				{
insert_char:
				/* fast case for simple typing */
				SetFChanged(pwnd, TRUE);
				DeleteSelection(pwnd, NULL);
				FAddCh(pwnd, (char) wParam);
				/* reset the selection */
				pwnd->ichSelEb = pwnd->ichCursorEb;
				SetFChanged(pwnd, TRUE);
				}
			}
		else
			{
			/* check for special keys */
			switch(wParam)
				{
			default:
				/* pass character back to Dialog manager */
				fOk = FALSE;
				goto restore_selection;

			case VK_LEFT:
				MoveCursorLeft(pwnd);
				if (HIWORD(lParam) & KK_SHIFT)
					fResetSelection = FALSE;
				break;

			case VK_RIGHT:
				MoveCursorRight(pwnd);
				if (HIWORD(lParam) & KK_SHIFT)
					fResetSelection = FALSE;
				break;

			case LOBYTE(VK_BACK):	/* translated */
				if (pwnd->ichCursorEb != pwnd->ichSelEb)
					DeleteSelection(pwnd, NULL);
				else if ((HIWORD(lParam) & KK_SHIFT) != 0)
					DelChRight(pwnd);
				else
					DelChLeft(pwnd);

				SetFChanged(pwnd, TRUE);
				break;

			case VK_HOME:
				MoveCursorBegin(pwnd);
				if (HIWORD(lParam) & KK_SHIFT)
					fResetSelection = FALSE;
				break;

			case VK_END:
				MoveCursorEnd(pwnd);
				if (HIWORD(lParam) & KK_SHIFT)
					fResetSelection = FALSE;
				}
			}
		} /*WM_CHAR*/
		break;

		}/*switch*/

	if (fResetSelection)
		pwnd->ichSelEb = pwnd->ichCursorEb;

	fOk = TRUE;

restore_selection:
#ifdef LATER
	// cursor should be visible during selections
	if (FFocus(pwnd))
		{
		WORD rx = max(pwnd->ichCursorEb - pwnd->ichLeftEb, 0);
		if (pwnd->ichCursorEb != pwnd->ichSelEb)
			HiliteEditSel(pwnd, TRUE);
		EnableCursor(pwnd, TRUE);
		MoveCursor(pwnd, (RX) rx, 0);
		}
#else
	if (FFocus(pwnd))
		{
		if (pwnd->ichCursorEb != pwnd->ichSelEb)
			{
			EnableCursor(pwnd, FALSE);
			HiliteEditSel(pwnd, TRUE);
			}
		else
			{
			WORD rx = max(pwnd->ichCursorEb - pwnd->ichLeftEb, 0);
			EnableCursor(pwnd, TRUE);
			MoveCursor(pwnd, (RX) rx, 0);
			}
		}
#endif /*!LATER*/

	return((DWORD) fOk);
	}



PUBLIC VOID FARPUBLIC
SetEditText(pwnd, sz, fDrawWindow)
REGISTER PWND pwnd;
char *sz;
BOOL fDrawWindow;
	{
	StartPublic();
	WORD cch;

	stringcpy((char *) pwnd->szDialog, sz, pwnd->cchMaxEb + 1);

	pwnd->ichMacEb = cch = strlen((char *) pwnd->szDialog);
	pwnd->ichLeftEb = 0;
	pwnd->ichCursorEb = 0;
	pwnd->ichSelEb = cch;
	if (fDrawWindow)
		DrawWindow(pwnd);
	StopPublic();
	}

PUBLIC VOID FARPUBLIC
SetEditWidth(pwnd, cch)
REGISTER PWND pwnd;
WORD cch;
	{
	StartPublic();

	pwnd->cchMaxEb = (cch >= 0) ? cch : pwnd->cchDialog;

	StopPublic();
	}

PUBLIC WORD FARPUBLIC
GetEditText(pwnd, sz, cchMac)
REGISTER PWND pwnd;
char *sz;
REGISTER WORD cchMac;
	{
	StartPublic();
	char *szDlg = (char *) pwnd->szDialog;

	if (cchMac > pwnd->ichMacEb + 1)	/* +1 for terminator */
		cchMac = pwnd->ichMacEb + 1;
	stringcpy(sz, szDlg, cchMac);

	StopPublic();
	return(cchMac);
	}



PUBLIC DWORD FARPUBLIC
EditWndProc(pwnd, message, wParam, lParam)
/*
  -- for edit windows
*/
PWND pwnd;
WORD wParam, message;
DWORD lParam;
	{
	StartPublic();

	DWORD lRet = InternalEditWndProc(pwnd, message, wParam, lParam);

	ReturnPublic(lRet, DWORD);
	}

#endif /* EDIT_FULLMGR */

⌨️ 快捷键说明

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