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

📄 normal.c

📁 ReactOS是一些高手根据Windows XP的内核编写出的类XP。内核实现机理和API函数调用几乎相同。甚至可以兼容XP的程序。喜欢研究系统内核的人可以看一看。
💻 C
📖 第 1 页 / 共 3 页
字号:
/* ------------- normal.c ------------ */

#include "dflat.h"

#ifdef INCLUDE_MULTI_WINDOWS
static void PaintOverLappers(DFWINDOW wnd);
static void PaintUnderLappers(DFWINDOW wnd);
#endif

static BOOL InsideWindow(DFWINDOW, int, int);
static void TerminateMoveSize(void);
static void SaveBorder(DFRECT);
static void RestoreBorder(DFRECT);
static void GetVideoBuffer(DFWINDOW);
static void PutVideoBuffer(DFWINDOW);
#ifdef INCLUDE_MINIMIZE
static DFRECT PositionIcon(DFWINDOW);
#endif
static void dragborder(DFWINDOW, int, int);
static void sizeborder(DFWINDOW, int, int);
static int px = -1, py = -1;
static int diff;
static struct DfWindow dwnd = {DF_DUMMY, NULL, DfNormalProc,
                                {{-1},{-1},{-1},{-1}}};
static PCHAR_INFO Bsave;
static int Bht, Bwd;
BOOL DfWindowMoving;
BOOL DfWindowSizing;
/* -------- array of class definitions -------- */
DFCLASSDEFS DfClassDefs[] = {
    #undef DfClassDef
    #define DfClassDef(c,b,p,a) {b,p,a},
    #include "classes.h"
};
DFWINDOW HiddenWindow;

/* --------- DFM_CREATE_WINDOW Message ---------- */
static void CreateWindowMsg(DFWINDOW wnd)
{
	DfAppendWindow(wnd);
//	DfClearAttribute(wnd, DF_VSCROLLBAR | DF_HSCROLLBAR);
	if (DfTestAttribute(wnd, DF_SAVESELF) && DfIsVisible(wnd))
		GetVideoBuffer(wnd);
}

/* --------- DFM_SHOW_WINDOW Message ---------- */
static void ShowWindowMsg(DFWINDOW wnd, DF_PARAM p1, DF_PARAM p2)
{
	if (DfGetParent(wnd) == NULL || DfIsVisible(DfGetParent(wnd)))
	{
		DFWINDOW cwnd;

		if (DfTestAttribute(wnd, DF_SAVESELF) && wnd->videosave == NULL)
			GetVideoBuffer(wnd);
		DfSetVisible(wnd);
		DfSendMessage(wnd, DFM_PAINT, 0, TRUE);
		DfSendMessage(wnd, DFM_BORDER, 0, 0);
		/* --- show the children of this window --- */
		cwnd = DfFirstWindow(wnd);
		while (cwnd != NULL)
		{
			if (cwnd->condition != DF_ISCLOSING)
				DfSendMessage(cwnd, DFM_SHOW_WINDOW, p1, p2);
			cwnd = DfNextWindow(cwnd);
		}
	}
}

/* --------- HIDE_WINDOW Message ---------- */
static void HideWindowMsg(DFWINDOW wnd)
{
	if (DfIsVisible(wnd))
	{
		DfClearVisible(wnd);
		/* --- paint what this window covered --- */
		if (DfTestAttribute(wnd, DF_SAVESELF))
			PutVideoBuffer(wnd);
#ifdef INCLUDE_MULTI_WINDOWS
		else
			PaintOverLappers(wnd);
#endif
    }
}

/* --------- DFM_KEYBOARD Message ---------- */
static BOOL KeyboardMsg(DFWINDOW wnd, DF_PARAM p1, DF_PARAM p2)
{
    if (DfWindowMoving || DfWindowSizing)    {
        /* -- move or size a window with keyboard -- */
        int x, y;
        x=DfWindowMoving?DfGetLeft(&dwnd):DfGetRight(&dwnd);
        y=DfWindowMoving?DfGetTop(&dwnd):DfGetBottom(&dwnd);
        switch ((int)p1)    {
            case DF_ESC:
                TerminateMoveSize();
                return TRUE;
            case DF_UP:
                if (y)
                    --y;
                break;
            case DF_DN:
                if (y < DfGetScreenHeight()-1)
                    y++;
                break;
            case DF_FWD:
                if (x < DfGetScreenWidth()-1)
                    x++;
                break;
            case DF_BS:
                if (x)
                    --x;
                break;
            case '\r':
                DfSendMessage(wnd, DFM_BUTTON_RELEASED,x,y);
            default:
                return TRUE;
        }
        /* -- use the mouse functions to move/size - */
        DfSendMessage(wnd, MOUSE_MOVED, x, y);
        return TRUE;
    }

	switch ((int)p1)
	{
		case DF_F1:
			DfSendMessage(wnd, DFM_COMMAND, DF_ID_HELP, 0);
			return TRUE;

		case ' ':
			if ((int)p2 & DF_ALTKEY)
				if (DfTestAttribute(wnd, DF_HASTITLEBAR))
					if (DfTestAttribute(wnd, DF_CONTROLBOX))
						DfBuildSystemMenu(wnd);
			return TRUE;

		case DF_CTRL_F4:
			if (DfTestAttribute(wnd, DF_CONTROLBOX))
			{
				DfSendMessage(wnd, DFM_CLOSE_WINDOW, 0, 0);
				DfSkipApplicationControls();
				return TRUE;
			}
			break;

		default:
			break;
	}

	return FALSE;
}

/* --------- COMMAND Message ---------- */
static void CommandMsg(DFWINDOW wnd, DF_PARAM p1)
{
    switch ((int)p1)    {
        case DF_ID_HELP:
            DfDisplayHelp(wnd,DfClassNames[DfGetClass(wnd)]);
            break;
#ifdef INCLUDE_RESTORE
        case DF_ID_SYSRESTORE:
            DfSendMessage(wnd, DFM_RESTORE, 0, 0);
            break;
#endif
        case DF_ID_SYSMOVE:
            DfSendMessage(wnd, DFM_CAPTURE_MOUSE, TRUE,
                (DF_PARAM) &dwnd);
            DfSendMessage(wnd, DFM_CAPTURE_KEYBOARD, TRUE,
                (DF_PARAM) &dwnd);
            DfWindowMoving = TRUE;
            dragborder(wnd, DfGetLeft(wnd), DfGetTop(wnd));
            break;
        case DF_ID_SYSSIZE:
            DfSendMessage(wnd, DFM_CAPTURE_MOUSE, TRUE,
                (DF_PARAM) &dwnd);
            DfSendMessage(wnd, DFM_CAPTURE_KEYBOARD, TRUE,
                (DF_PARAM) &dwnd);
            DfWindowSizing = TRUE;
            dragborder(wnd, DfGetLeft(wnd), DfGetTop(wnd));
            break;
#ifdef INCLUDE_MINIMIZE
        case DF_ID_SYSMINIMIZE:
            DfSendMessage(wnd, DFM_MINIMIZE, 0, 0);
            break;
#endif
#ifdef INCLUDE_MAXIMIZE
        case DF_ID_SYSMAXIMIZE:
            DfSendMessage(wnd, DFM_MAXIMIZE, 0, 0);
            break;
#endif
        case DF_ID_SYSCLOSE:
            DfSendMessage(wnd, DFM_CLOSE_WINDOW, 0, 0);
			DfSkipApplicationControls();
            break;
        default:
            break;
    }
}

/* --------- DFM_SETFOCUS Message ---------- */
static void SetFocusMsg(DFWINDOW wnd, DF_PARAM p1)
{
	DFRECT rc = {0,0,0,0};

	if (p1 && wnd != NULL && DfInFocus != wnd)
	{
		DFWINDOW this, thispar;
		DFWINDOW that = NULL, thatpar = NULL;

		DFWINDOW cwnd = wnd, fwnd = DfGetParent(wnd);
		/* ---- post focus in ancestors ---- */
		while (fwnd != NULL)
		{
			fwnd->childfocus = cwnd;
			cwnd = fwnd;
			fwnd = DfGetParent(fwnd);
		}
		/* ---- de-post focus in self and children ---- */
		fwnd = wnd;
		while (fwnd != NULL)
		{
			cwnd = fwnd->childfocus;
			fwnd->childfocus = NULL;
			fwnd = cwnd;
		}

		this = wnd;
		that = thatpar = DfInFocus;

		/* ---- find common ancestor of prev focus and this window --- */
		while (thatpar != NULL)
		{
			thispar = wnd;
			while (thispar != NULL)
			{
				if (this == DfCaptureMouse || this == DfCaptureKeyboard)
				{
					/* ---- don't repaint if this window has capture ---- */
					that = thatpar = NULL;
					break;
				}
				if (thispar == thatpar)
				{
					/* ---- don't repaint if DF_SAVESELF window had focus ---- */
					if (this != that && DfTestAttribute(that, DF_SAVESELF))
						that = thatpar = NULL;
					break;
				}
				this = thispar;
				thispar = DfGetParent(thispar);
			}
			if (thispar != NULL)
				break;
			that = thatpar;
			thatpar = DfGetParent(thatpar);
		}
		if (DfInFocus != NULL)
			DfSendMessage(DfInFocus, DFM_SETFOCUS, FALSE, 0);
		DfInFocus = wnd;
		if (that != NULL && DfIsVisible(wnd))
		{
			rc = DfSubRectangle(DfWindowRect(that), DfWindowRect(this));
			if (!DfValidRect(rc))
			{
				if (DfApplicationWindow != NULL)
				{
					DFWINDOW fwnd = DfFirstWindow(DfApplicationWindow);
					while (fwnd != NULL)
					{
						if (!DfIsAncestor(wnd, fwnd))
						{
							rc = DfSubRectangle(DfWindowRect(wnd),DfWindowRect(fwnd));
							if (DfValidRect(rc))
								break;
						}
						fwnd = DfNextWindow(fwnd);
					}
				}
			}
		}
		if (that != NULL && !DfValidRect(rc) && DfIsVisible(wnd))
		{
			DfSendMessage(wnd, DFM_BORDER, 0, 0);
			this = NULL;
		}
		DfReFocus(wnd);
		if (this != NULL)
		DfSendMessage(this, DFM_SHOW_WINDOW, 0, 0);
	}
	else if (!p1 && DfInFocus == wnd)
	{
		/* clearing focus */
		DfInFocus = NULL;
		DfSendMessage(wnd, DFM_BORDER, 0, 0);
	}
}

/* --------- DOUBLE_CLICK Message ---------- */
static void DoubleClickMsg(DFWINDOW wnd, DF_PARAM p1, DF_PARAM p2)
{
    int mx = (int) p1 - DfGetLeft(wnd);
    int my = (int) p2 - DfGetTop(wnd);
    if (!DfWindowSizing && !DfWindowMoving)	{
        if (DfHitControlBox(wnd, mx, my))	{
            DfPostMessage(wnd, DFM_CLOSE_WINDOW, 0, 0);
			DfSkipApplicationControls();
		}
	}
}

/* --------- DFM_LEFT_BUTTON Message ---------- */
static void LeftButtonMsg(DFWINDOW wnd, DF_PARAM p1, DF_PARAM p2)
{
    int mx = (int) p1 - DfGetLeft(wnd);
    int my = (int) p2 - DfGetTop(wnd);
    if (DfWindowSizing || DfWindowMoving)
        return;
    if (DfHitControlBox(wnd, mx, my))    {
        DfBuildSystemMenu(wnd);
        return;
    }
    if (my == 0 && mx > -1 && mx < DfWindowWidth(wnd))  {
        /* ---------- hit the top border -------- */
        if (DfTestAttribute(wnd, DF_MINMAXBOX) &&
                DfTestAttribute(wnd, DF_HASTITLEBAR))  {
            if (mx == DfWindowWidth(wnd)-2)    {
                if (wnd->condition != DF_SRESTORED)
                    /* --- hit the restore box --- */
                    DfSendMessage(wnd, DFM_RESTORE, 0, 0);
#ifdef INCLUDE_MAXIMIZE
                else
                    /* --- hit the maximize box --- */
                    DfSendMessage(wnd, DFM_MAXIMIZE, 0, 0);
#endif
                return;
            }
#ifdef INCLUDE_MINIMIZE
            if (mx == DfWindowWidth(wnd)-3)    {
                /* --- hit the minimize box --- */
                if (wnd->condition != DF_ISMINIMIZED)
                    DfSendMessage(wnd, DFM_MINIMIZE, 0, 0);
                return;
            }
#endif
        }
#ifdef INCLUDE_MAXIMIZE
        if (wnd->condition == DF_ISMAXIMIZED)
            return;
#endif
        if (DfTestAttribute(wnd, DF_MOVEABLE))    {
            DfWindowMoving = TRUE;
            px = mx;
            py = my;
            diff = (int) mx;
            DfSendMessage(wnd, DFM_CAPTURE_MOUSE, TRUE,
                (DF_PARAM) &dwnd);
            dragborder(wnd, DfGetLeft(wnd), DfGetTop(wnd));
        }
        return;
    }
    if (mx == DfWindowWidth(wnd)-1 &&
            my == DfWindowHeight(wnd)-1)    {
        /* ------- hit the resize corner ------- */

⌨️ 快捷键说明

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