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

📄 window.c

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

#include "dflat.h"

DFWINDOW DfInFocus = NULL;

int DfForeground, DfBackground;   /* current video colors */

static void TopLine(DFWINDOW, int, DFRECT);

/* --------- create a window ------------ */
DFWINDOW DfDfCreateWindow(
    DFCLASS class,              /* class of this window       */
    char *ttl,                /* title or NULL              */
    int left, int top,        /* upper left coordinates     */
    int height, int width,    /* dimensions                 */
    void *extension,          /* pointer to additional data */
    DFWINDOW parent,            /* parent of this window      */
    int (*wndproc)(struct DfWindow *,enum DfMessages,DF_PARAM,DF_PARAM),
    int attrib)               /* window attribute           */
{
    DFWINDOW wnd = DfCalloc(1, sizeof(struct DfWindow));
    if (wnd != NULL)    {
        int base;
        /* ----- height, width = -1: fill the screen ------- */
        if (height == -1)
            height = DfScreenHeight;
        if (width == -1)
            width = DfScreenWidth;
        /* ----- coordinates -1, -1 = center the window ---- */
        if (left == -1)
            wnd->rc.lf = (DfScreenWidth-width)/2;
        else
            wnd->rc.lf = left;
        if (top == -1)
            wnd->rc.tp = (DfScreenHeight-height)/2;
        else
            wnd->rc.tp = top;
        wnd->attrib = attrib;
        if (ttl != NULL)
            DfAddAttribute(wnd, DF_HASTITLEBAR);
        if (wndproc == NULL)
            wnd->wndproc = DfClassDefs[class].wndproc;
        else
            wnd->wndproc = wndproc;
        /* ---- derive attributes of base classes ---- */
        base = class;
        while (base != -1)    {
            DfAddAttribute(wnd, DfClassDefs[base].attrib);
            base = DfClassDefs[base].base;
        }
        if (parent)
		{
			if (!DfTestAttribute(wnd, DF_NOCLIP))
			{
            	/* -- keep upper left DfWithin borders of parent - */
            	wnd->rc.lf = max(wnd->rc.lf,DfGetClientLeft(parent));
            	wnd->rc.tp = max(wnd->rc.tp,DfGetClientTop(parent));
        	}
		}
		else
			parent = DfApplicationWindow;

        wnd->class = class;
        wnd->extension = extension;
        wnd->rc.rt = DfGetLeft(wnd)+width-1;
        wnd->rc.bt = DfGetTop(wnd)+height-1;
        wnd->ht = height;
        wnd->wd = width;
        if (ttl != NULL)
            DfInsertTitle(wnd, ttl);
        wnd->parent = parent;
        wnd->oldcondition = wnd->condition = DF_SRESTORED;
        wnd->RestoredRC = wnd->rc;
		DfInitWindowColors(wnd);
        DfSendMessage(wnd, DFM_CREATE_WINDOW, 0, 0);
        if (DfIsVisible(wnd))
            DfSendMessage(wnd, DFM_SHOW_WINDOW, 0, 0);
    }
    return wnd;
}

/* -------- add a title to a window --------- */
void DfAddTitle(DFWINDOW wnd, char *ttl)
{
	DfInsertTitle(wnd, ttl);
	DfSendMessage(wnd, DFM_BORDER, 0, 0);
}

/* ----- insert a title into a window ---------- */
void DfInsertTitle(DFWINDOW wnd, char *ttl)
{
	wnd->title=DfRealloc(wnd->title,strlen(ttl)+1);
	strcpy(wnd->title, ttl);
}

static char line[300];

/* ------ write a line to video window client area ------ */
void DfWriteLine(DFWINDOW wnd, char *str, int x, int y, BOOL pad)
{
    char *cp;
    int len;
    int dif;
	char wline[200];

	memset(wline, 0, 200);
    len = DfLineLength(str);
    dif = strlen(str) - len;
    strncpy(wline, str, DfClientWidth(wnd) + dif);
    if (pad)    {
        cp = wline+strlen(wline);
        while (len++ < DfClientWidth(wnd)-x)
            *cp++ = ' ';
    }
    DfWPuts(wnd, wline, x, y);
}

DFRECT DfAdjustRectangle(DFWINDOW wnd, DFRECT rc)
{
    /* -------- adjust the rectangle ------- */
    if (DfTestAttribute(wnd, DF_HASBORDER))    {
        if (DfRectLeft(rc) == 0)
            --rc.rt;
        else if (DfRectLeft(rc) < DfRectRight(rc) &&
                DfRectLeft(rc) < DfWindowWidth(wnd)+1)
            --rc.lf;
    }
    if (DfTestAttribute(wnd, DF_HASBORDER | DF_HASTITLEBAR))    {
        if (DfRectTop(rc) == 0)
            --rc.bt;
        else if (DfRectTop(rc) < DfRectBottom(rc) &&
                DfRectTop(rc) < DfWindowHeight(wnd)+1)
            --rc.tp;
    }
    DfRectRight(rc) = max(DfRectLeft(rc),
                        min(DfRectRight(rc),DfWindowWidth(wnd)));
    DfRectBottom(rc) = max(DfRectTop(rc),
                        min(DfRectBottom(rc),DfWindowHeight(wnd)));
    return rc;
}

/* -------- display a window's title --------- */
void DfDisplayTitle(DFWINDOW wnd, DFRECT *rcc)
{
	if (DfGetTitle(wnd) != NULL)
	{
		int tlen = min((int)strlen(DfGetTitle(wnd)), (int)DfWindowWidth(wnd)-2);
		int tend = DfWindowWidth(wnd)-3-DfBorderAdj(wnd);
		DFRECT rc;

		if (rcc == NULL)
			rc = DfRelativeWindowRect(wnd, DfWindowRect(wnd));
		else
			rc = *rcc;
		rc = DfAdjustRectangle(wnd, rc);

		if (DfSendMessage(wnd, DFM_TITLE, (DF_PARAM) rcc, 0))
		{
			if (wnd == DfInFocus)
			{
				DfForeground = DfCfg.clr[DF_TITLEBAR] [DF_HILITE_COLOR] [DF_FG];
				DfBackground = DfCfg.clr[DF_TITLEBAR] [DF_HILITE_COLOR] [DF_BG];
			}
			else
			{
				DfForeground = DfCfg.clr[DF_TITLEBAR] [DF_STD_COLOR] [DF_FG];
				DfBackground = DfCfg.clr[DF_TITLEBAR] [DF_STD_COLOR] [DF_BG];
			}
			memset(line,' ',DfWindowWidth(wnd));
#ifdef INCLUDE_MINIMIZE
			if (wnd->condition != DF_ISMINIMIZED)
#endif
			strncpy (line + ((DfWindowWidth(wnd)-2 - tlen) / 2),
			         wnd->title, tlen);
			if (DfTestAttribute(wnd, DF_CONTROLBOX))
				line[2-DfBorderAdj(wnd)] = DF_CONTROLBOXCHAR;
			if (DfTestAttribute(wnd, DF_MINMAXBOX))
			{
				switch (wnd->condition)
				{
					case DF_SRESTORED:
#ifdef INCLUDE_MAXIMIZE
						line[tend+1] = DF_MAXPOINTER;
#endif
#ifdef INCLUDE_MINIMIZE
						line[tend]   = DF_MINPOINTER;
#endif
						break;
#ifdef INCLUDE_MINIMIZE
					case DF_ISMINIMIZED:
						line[tend+1] = DF_MAXPOINTER;
						break;
#endif
#ifdef INCLUDE_MAXIMIZE
					case DF_ISMAXIMIZED:
#ifdef INCLUDE_MINIMIZE
						line[tend]   = DF_MINPOINTER;
#endif
#ifdef INCLUDE_RESTORE
						line[tend+1] = DF_RESTOREPOINTER;
#endif
						break;
#endif
					default:
						break;
				}
			}
			line[DfRectRight(rc)+1] = line[tend+3] = '\0';
			if (wnd != DfInFocus)
				DfClipString++;
			DfWriteLine(wnd, line+DfRectLeft(rc),
                       	DfRectLeft(rc)+DfBorderAdj(wnd),
                       	0,
                       	FALSE);
			DfClipString = 0;
		}
	}
}

/* --- display right border shadow character of a window --- */
static void shadow_char(DFWINDOW wnd, int y)
{
    int fg = DfForeground;
    int bg = DfBackground;
    int x = DfWindowWidth(wnd);
    char c = DfVideoChar(DfGetLeft(wnd)+x, DfGetTop(wnd)+y);

    if (DfTestAttribute(wnd, DF_SHADOW) == 0)
        return;
    DfForeground = DARKGRAY;
    DfBackground = BLACK;
    DfWPutch(wnd, c, x, y);
    DfForeground = fg;
    DfBackground = bg;
}

/* --- display the bottom border shadow line for a window -- */
static void shadowline(DFWINDOW wnd, DFRECT rc)
{
    int i;
    int y = DfGetBottom(wnd)+1;
    int fg = DfForeground;
    int bg = DfBackground;

    if ((DfTestAttribute(wnd, DF_SHADOW)) == 0)
        return;
    for (i = 0; i < DfWindowWidth(wnd)+1; i++)
        line[i] = DfVideoChar(DfGetLeft(wnd)+i, y);
    line[i] = '\0';
    DfForeground = DARKGRAY;
    DfBackground = BLACK;
    line[DfRectRight(rc)+1] = '\0';
    if (DfRectLeft(rc) == 0)
        rc.lf++;
	DfClipString++;
    DfWPuts(wnd, line+DfRectLeft(rc), DfRectLeft(rc),
        DfWindowHeight(wnd));
	--DfClipString;
    DfForeground = fg;
    DfBackground = bg;

⌨️ 快捷键说明

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