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

📄 normal.c

📁 ReactOS是一些高手根据Windows XP的内核编写出的类XP。内核实现机理和API函数调用几乎相同。甚至可以兼容XP的程序。喜欢研究系统内核的人可以看一看。
💻 C
📖 第 1 页 / 共 3 页
字号:
    DfRectTop(rc) = DfGetScreenHeight()-DF_ICONHEIGHT;
    DfRectRight(rc) = DfGetScreenWidth()-1;
    DfRectBottom(rc) = DfGetScreenHeight()-1;
    if (pwnd != NULL)    {
        DFRECT prc = DfWindowRect(pwnd);
		DFWINDOW cwnd = DfFirstWindow(pwnd);
        rc = LowerRight(prc);
        /* - search for icon available location - */
		while (cwnd != NULL)	{
            if (cwnd->condition == DF_ISMINIMIZED)    {
                DFRECT rc1;
                rc1 = DfWindowRect(cwnd);
                if (DfRectLeft(rc1) == DfRectLeft(rc) &&
                        DfRectTop(rc1) == DfRectTop(rc))    {
                    DfRectLeft(rc) -= DF_ICONWIDTH;
                    DfRectRight(rc) -= DF_ICONWIDTH;
                    if (DfRectLeft(rc) < DfRectLeft(prc)+1)   {
                        DfRectLeft(rc) =
                            DfRectRight(prc)-DF_ICONWIDTH;
                        DfRectRight(rc) =
                            DfRectLeft(rc)+DF_ICONWIDTH-1;
                        DfRectTop(rc) -= DF_ICONHEIGHT;
                        DfRectBottom(rc) -= DF_ICONHEIGHT;
                        if (DfRectTop(rc) < DfRectTop(prc)+1)
                            return LowerRight(prc);
                    }
                    break;
                }
            }
			cwnd = DfNextWindow(cwnd);
        }
    }
    return rc;
}
#endif
/* ----- terminate the move or size operation ----- */
static void TerminateMoveSize(void)
{
    px = py = -1;
    diff = 0;
    DfSendMessage(&dwnd, DFM_RELEASE_MOUSE, TRUE, 0);
    DfSendMessage(&dwnd, DFM_RELEASE_KEYBOARD, TRUE, 0);
    RestoreBorder(dwnd.rc);
    DfWindowMoving = DfWindowSizing = FALSE;
}
/* ---- build a dummy window border for moving or sizing --- */
static void dragborder(DFWINDOW wnd, int x, int y)
{
    RestoreBorder(dwnd.rc);
    /* ------- build the dummy window -------- */
    dwnd.rc.lf = x;
    dwnd.rc.tp = y;
    dwnd.rc.rt = dwnd.rc.lf+DfWindowWidth(wnd)-1;
    dwnd.rc.bt = dwnd.rc.tp+DfWindowHeight(wnd)-1;
    dwnd.ht = DfWindowHeight(wnd);
    dwnd.wd = DfWindowWidth(wnd);
    dwnd.parent = DfGetParent(wnd);
    dwnd.attrib = DF_VISIBLE | DF_HASBORDER | DF_NOCLIP;
    DfInitWindowColors(&dwnd);
    SaveBorder(dwnd.rc);
    DfRepaintBorder(&dwnd, NULL);
}
/* ---- write the dummy window border for sizing ---- */
static void sizeborder(DFWINDOW wnd, int rt, int bt)
{
    int leftmost = DfGetLeft(wnd)+10;
    int topmost = DfGetTop(wnd)+3;
    int bottommost = DfGetScreenHeight()-1;
    int rightmost  = DfGetScreenWidth()-1;
    if (DfGetParent(wnd))    {
        bottommost = min(bottommost,
            DfGetClientBottom(DfGetParent(wnd)));
        rightmost  = min(rightmost,
            DfGetClientRight(DfGetParent(wnd)));
    }
    rt = min(rt, rightmost);
    bt = min(bt, bottommost);
    rt = max(rt, leftmost);
    bt = max(bt, topmost);

    if (rt != px || bt != py)
        RestoreBorder(dwnd.rc);

    /* ------- change the dummy window -------- */
    dwnd.ht = bt-dwnd.rc.tp+1;
    dwnd.wd = rt-dwnd.rc.lf+1;
    dwnd.rc.rt = rt;
    dwnd.rc.bt = bt;
    if (rt != px || bt != py)    {
        px = rt;
        py = bt;
        SaveBorder(dwnd.rc);
        DfRepaintBorder(&dwnd, NULL);
    }
}
#ifdef INCLUDE_MULTI_WINDOWS
/* ----- adjust a rectangle to include the shadow ----- */
static DFRECT adjShadow(DFWINDOW wnd)
{
    DFRECT rc;
    rc = wnd->rc;
    if (DfTestAttribute(wnd, DF_SHADOW))    {
        if (DfRectRight(rc) < DfGetScreenWidth()-1)
            DfRectRight(rc)++;
        if (DfRectBottom(rc) < DfGetScreenHeight()-1)
            DfRectBottom(rc)++;
    }
    return rc;
}
/* --- repaint a rectangular subsection of a window --- */
static void PaintOverLap(DFWINDOW wnd, DFRECT rc)
{
    if (DfIsVisible(wnd))    {
        int isBorder, isTitle, isData;
        isBorder = isTitle = FALSE;
        isData = TRUE;
        if (DfTestAttribute(wnd, DF_HASBORDER))    {
            isBorder =  DfRectLeft(rc) == 0 &&
                        DfRectTop(rc) < DfWindowHeight(wnd);
            isBorder |= DfRectLeft(rc) < DfWindowWidth(wnd) &&
                        DfRectRight(rc) >= DfWindowWidth(wnd)-1 &&
                        DfRectTop(rc) < DfWindowHeight(wnd);
            isBorder |= DfRectTop(rc) == 0 &&
                        DfRectLeft(rc) < DfWindowWidth(wnd);
            isBorder |= DfRectTop(rc) < DfWindowHeight(wnd) &&
                        DfRectBottom(rc) >= DfWindowHeight(wnd)-1 &&
                        DfRectLeft(rc) < DfWindowWidth(wnd);
        }
        else if (DfTestAttribute(wnd, DF_HASTITLEBAR))
            isTitle = DfRectTop(rc) == 0 &&
                      DfRectRight(rc) > 0 &&
                      DfRectLeft(rc)<DfWindowWidth(wnd)-DfBorderAdj(wnd);

        if (DfRectLeft(rc) >= DfWindowWidth(wnd)-DfBorderAdj(wnd))
            isData = FALSE;
        if (DfRectTop(rc) >= DfWindowHeight(wnd)-DfBottomBorderAdj(wnd))
            isData = FALSE;
        if (DfTestAttribute(wnd, DF_HASBORDER))    {
            if (DfRectRight(rc) == 0)
                isData = FALSE;
            if (DfRectBottom(rc) == 0)
                isData = FALSE;
        }
        if (DfTestAttribute(wnd, DF_SHADOW))
            isBorder |= DfRectRight(rc) == DfWindowWidth(wnd) ||
                        DfRectBottom(rc) == DfWindowHeight(wnd);
        if (isData)
            DfSendMessage(wnd, DFM_PAINT, (DF_PARAM) &rc, TRUE);
        if (isBorder)
            DfSendMessage(wnd, DFM_BORDER, (DF_PARAM) &rc, 0);
        else if (isTitle)
            DfDisplayTitle(wnd, &rc);
    }
}
/* ------ paint the part of a window that is overlapped
            by another window that is being hidden ------- */
static void PaintOver(DFWINDOW wnd)
{
    DFRECT wrc, rc;
    wrc = adjShadow(HiddenWindow);
    rc = adjShadow(wnd);
    rc = DfSubRectangle(rc, wrc);
    if (DfValidRect(rc))
        PaintOverLap(wnd, DfRelativeWindowRect(wnd, rc));
}
/* --- paint the overlapped parts of all children --- */
static void PaintOverChildren(DFWINDOW pwnd)
{
    DFWINDOW cwnd = DfFirstWindow(pwnd);
    while (cwnd != NULL)    {
        if (cwnd != HiddenWindow)    {
            PaintOver(cwnd);
            PaintOverChildren(cwnd);
        }
        cwnd = DfNextWindow(cwnd);
    }
}
/* -- recursive overlapping paint of parents -- */
static void PaintOverParents(DFWINDOW wnd)
{
    DFWINDOW pwnd = DfGetParent(wnd);
    if (pwnd != NULL)    {
        PaintOverParents(pwnd);
        PaintOver(pwnd);
        PaintOverChildren(pwnd);
    }
}
/* - paint the parts of all windows that a window is over - */
static void PaintOverLappers(DFWINDOW wnd)
{
    HiddenWindow = wnd;
    PaintOverParents(wnd);
}
/* --- paint those parts of a window that are overlapped --- */
static void PaintUnderLappers(DFWINDOW wnd)
{
    DFWINDOW hwnd = DfNextWindow(wnd);
    while (hwnd != NULL)    {
        /* ------- test only at document window level ------ */
        DFWINDOW pwnd = DfGetParent(hwnd);
/*        if (pwnd == NULL || DfGetClass(pwnd) == DF_APPLICATION)  */  {
            /* ---- don't bother testing self ----- */
            if (DfIsVisible(hwnd) && hwnd != wnd)    {
                /* --- see if other window is descendent --- */
                while (pwnd != NULL)    {
                    if (pwnd == wnd)
                        break;
                    pwnd = DfGetParent(pwnd);
                }
                /* ----- don't test descendent overlaps ----- */
                if (pwnd == NULL)    {
                    /* -- see if other window is ancestor --- */
                    pwnd = DfGetParent(wnd);
                    while (pwnd != NULL)    {
                        if (pwnd == hwnd)
                            break;
                        pwnd = DfGetParent(pwnd);
                    }
                    /* --- don't test ancestor overlaps --- */
                    if (pwnd == NULL)    {
                        HiddenWindow = DfGetAncestor(hwnd);
                        DfClearVisible(HiddenWindow);
                        PaintOver(wnd);
                        DfSetVisible(HiddenWindow);
                    }
                }
            }
        }
        hwnd = DfNextWindow(hwnd);
    }
    /* --------- repaint all children of this window
        the same way ----------- */
    hwnd = DfFirstWindow(wnd);
    while (hwnd != NULL)    {
        PaintUnderLappers(hwnd);
        hwnd = DfNextWindow(hwnd);
    }
}
#endif /* #ifdef INCLUDE_MULTI_WINDOWS */

/* --- save video area to be used by dummy window border --- */
static void SaveBorder(DFRECT rc)
{
	Bht = DfRectBottom(rc) - DfRectTop(rc) + 1;
	Bwd = DfRectRight(rc) - DfRectLeft(rc) + 1;
	Bsave = DfRealloc(Bsave, Bht * Bwd * sizeof(CHAR_INFO));

	DfGetVideo(rc,Bsave);
}
/* ---- restore video area used by dummy window border ---- */
static void RestoreBorder(DFRECT rc)
{
	if (Bsave != NULL)
	{
		DfStoreVideo(rc, Bsave);
		free(Bsave);
		Bsave = NULL;
	}
}
/* ----- test if screen coordinates are in a window ---- */
static BOOL InsideWindow(DFWINDOW wnd, int x, int y)
{
    DFRECT rc;
    rc = DfWindowRect(wnd);
    if (!DfTestAttribute(wnd, DF_NOCLIP))
    {
        DFWINDOW pwnd = DfGetParent(wnd);
        while (pwnd != NULL)
		{
            rc = DfSubRectangle(rc, DfClientRect(pwnd));
            pwnd = DfGetParent(pwnd);
        }
    }
    return DfInsideRect(x, y, rc);
}

BOOL DfIsDerivedFrom(DFWINDOW wnd, DFCLASS class)
{
    DFCLASS tclass = DfGetClass(wnd);
    while (tclass != -1)    {
        if (tclass == class)
            return TRUE;
        tclass = (DfClassDefs[tclass].base);
    }
    return FALSE;
}

/* -- find the oldest document window ancestor of a window -- */
DFWINDOW DfGetAncestor(DFWINDOW wnd)
{
    if (wnd != NULL)    {
        while (DfGetParent(wnd) != NULL)    {
            if (DfGetClass(DfGetParent(wnd)) == DF_APPLICATION)
                break;
            wnd = DfGetParent(wnd);
        }
    }
    return wnd;
}

BOOL DfIsVisible(DFWINDOW wnd)
{
    while (wnd != NULL)    {
        if (isHidden(wnd))
            return FALSE;
        wnd = DfGetParent(wnd);
    }
    return TRUE;
}

/* -- adjust a window's rectangle to clip it to its parent - */
static DFRECT ClipRect(DFWINDOW wnd)
{
    DFRECT rc;
    rc = DfWindowRect(wnd);
    if (DfTestAttribute(wnd, DF_SHADOW))    {
        DfRectBottom(rc)++;
        DfRectRight(rc)++;
    }
	return DfClipRectangle(wnd, rc);
}

/* -- get the video memory that is to be used by a window -- */
static void GetVideoBuffer(DFWINDOW wnd)
{
    DFRECT rc;
    int ht;
    int wd;

    rc = ClipRect(wnd);
    ht = DfRectBottom(rc) - DfRectTop(rc) + 1;
    wd = DfRectRight(rc) - DfRectLeft(rc) + 1;
    wnd->videosave = DfRealloc(wnd->videosave, (ht * wd * sizeof(CHAR_INFO)));
    DfGetVideo(rc, wnd->videosave);
}

/* -- put the video memory that is used by a window -- */
static void PutVideoBuffer(DFWINDOW wnd)
{
	if (wnd->videosave != NULL)
	{
		DFRECT rc;
		rc = ClipRect(wnd);
		DfStoreVideo(rc, wnd->videosave);
		free(wnd->videosave);
		wnd->videosave = NULL;
	}
}

/* ------- return TRUE if awnd is an ancestor of wnd ------- */
BOOL DfIsAncestor(DFWINDOW wnd, DFWINDOW awnd)
{
	while (wnd != NULL)	{
		if (wnd == awnd)
			return TRUE;
		wnd = DfGetParent(wnd);
	}
	return FALSE;
}

/* EOF */

⌨️ 快捷键说明

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