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

📄 dialbox.c

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

#include "dflat.h"

static int inFocusCommand(DF_DBOX *);
static void dbShortcutKeys(DF_DBOX *, int);
static int ControlProc(DFWINDOW, DFMESSAGE, DF_PARAM, DF_PARAM);
static void FirstFocus(DF_DBOX *db);
static void NextFocus(DF_DBOX *db);
static void PrevFocus(DF_DBOX *db);
static DF_CTLWINDOW *AssociatedControl(DF_DBOX *, enum DfCommands);

static BOOL SysMenuOpen;

static DF_DBOX **dbs = NULL;
static int dbct = 0;

/* --- clear all heap allocations to control text fields --- */
void DfClearDialogBoxes(void)
{
	int i;

	for (i = 0; i < dbct; i++)
	{
		DF_CTLWINDOW *ct = (*(dbs+i))->ctl;

		while (ct->class)
		{
			if ((ct->class == DF_EDITBOX ||
			     ct->class == DF_COMBOBOX) &&
			    ct->itext != NULL)
			{
				free(ct->itext);
			}
			ct++;
		}
	}

	if (dbs != NULL)
	{
		free(dbs);
		dbs = NULL;
	}
	dbct = 0;
}


/* -------- DFM_CREATE_WINDOW Message --------- */
static int CreateWindowMsg(DFWINDOW wnd, DF_PARAM p1, DF_PARAM p2)
{
    DF_DBOX *db = wnd->extension;
    DF_CTLWINDOW *ct = db->ctl;
    DFWINDOW cwnd;
    int rtn, i;
    /* ---- build a table of processed dialog boxes ---- */
    for (i = 0; i < dbct; i++)
        if (db == dbs[i])
            break;
    if (i == dbct)    {
        dbs = DfRealloc(dbs, sizeof(DF_DBOX *) * (dbct+1));
        *(dbs + dbct++) = db;
    }
    rtn = DfBaseWndProc(DF_DIALOG, wnd, DFM_CREATE_WINDOW, p1, p2);
    ct = db->ctl;
    while (ct->class)    {
        int attrib = 0;
        if (DfTestAttribute(wnd, DF_NOCLIP))
            attrib |= DF_NOCLIP;
        if (wnd->Modal)
            attrib |= DF_SAVESELF;
        ct->setting = ct->isetting;
        if (ct->class == DF_EDITBOX && ct->dwnd.h > 1)
            attrib |= (DF_MULTILINE | DF_HASBORDER);
        else if ((ct->class == DF_LISTBOX || ct->class == DF_TEXTBOX) &&
				ct->dwnd.h > 2)
            attrib |= DF_HASBORDER;
        cwnd = DfDfCreateWindow(ct->class,
                        ct->dwnd.title,
                        ct->dwnd.x+DfGetClientLeft(wnd),
                        ct->dwnd.y+DfGetClientTop(wnd),
                        ct->dwnd.h,
                        ct->dwnd.w,
                        ct,
                        wnd,
                        ControlProc,
                        attrib);
        if ((ct->class == DF_EDITBOX ||
                ct->class == DF_COMBOBOX) &&
                    ct->itext != NULL)
            DfSendMessage(cwnd, DFM_SETTEXT, (DF_PARAM) ct->itext, 0);
        ct++;
    }
    return rtn;
}

/* -------- DFM_LEFT_BUTTON Message --------- */
static BOOL LeftButtonMsg(DFWINDOW wnd, DF_PARAM p1, DF_PARAM p2)
{
    DF_DBOX *db = wnd->extension;
    DF_CTLWINDOW *ct = db->ctl;
    if (DfWindowSizing || DfWindowMoving)
        return TRUE;
    if (DfHitControlBox(wnd, p1-DfGetLeft(wnd), p2-DfGetTop(wnd))) {
        DfPostMessage(wnd, DFM_KEYBOARD, ' ', DF_ALTKEY);
        return TRUE;
    }
    while (ct->class)    {
        DFWINDOW cwnd = ct->wnd;
        if (ct->class == DF_COMBOBOX)    {
            if (p2 == DfGetTop(cwnd))    {
                if (p1 == DfGetRight(cwnd)+1)    {
                    DfSendMessage(cwnd, DFM_LEFT_BUTTON, p1, p2);
                    return TRUE;
                }
            }
            if (DfGetClass(DfInFocus) == DF_LISTBOX)
                DfSendMessage(wnd, DFM_SETFOCUS, TRUE, 0);
        }
        else if (ct->class == DF_SPINBUTTON)    {
            if (p2 == DfGetTop(cwnd))    {
                if (p1 == DfGetRight(cwnd)+1 ||
                        p1 == DfGetRight(cwnd)+2)    {
                    DfSendMessage(cwnd, DFM_LEFT_BUTTON, p1, p2);
                    return TRUE;
                }
            }
        }
        ct++;
    }
    return FALSE;
}

/* -------- DFM_KEYBOARD Message --------- */
static BOOL KeyboardMsg(DFWINDOW wnd, DF_PARAM p1, DF_PARAM p2)
{
    DF_DBOX *db = wnd->extension;
    DF_CTLWINDOW *ct;

    if (DfWindowMoving || DfWindowSizing)
        return FALSE;
    switch ((int)p1)    {
        case DF_F1:
            ct = DfGetControl(DfInFocus);
            if (ct != NULL)
                if (DfDisplayHelp(wnd, ct->help))
                    return TRUE;
            break;
        case DF_SHIFT_HT:
        case DF_BS:
        case DF_UP:
            PrevFocus(db);
            break;
        case DF_ALT_F6:
        case '\t':
        case DF_FWD:
        case DF_DN:
            NextFocus(db);
            break;
        case ' ':
            if (((int)p2 & DF_ALTKEY) &&
                    DfTestAttribute(wnd, DF_CONTROLBOX))    {
                SysMenuOpen = TRUE;
                DfBuildSystemMenu(wnd);
            }
            break;
        case DF_CTRL_F4:
        case DF_ESC:
            DfSendMessage(wnd, DFM_COMMAND, DF_ID_CANCEL, 0);
            break;
        default:
            /* ------ search all the shortcut keys ----- */
            dbShortcutKeys(db, (int) p1);
            break;
    }
    return wnd->Modal;
}

/* -------- COMMAND Message --------- */
static BOOL CommandMsg(DFWINDOW wnd, DF_PARAM p1, DF_PARAM p2)
{
    DF_DBOX *db = wnd->extension;
    switch ((int) p1)    {
        case DF_ID_OK:
        case DF_ID_CANCEL:
            if ((int)p2 != 0)
                return TRUE;
            wnd->ReturnCode = (int) p1;
            if (wnd->Modal)
                DfPostMessage(wnd, DFM_ENDDIALOG, 0, 0);
            else
                DfSendMessage(wnd, DFM_CLOSE_WINDOW, TRUE, 0);
            return TRUE;
        case DF_ID_HELP:
            if ((int)p2 != 0)
                return TRUE;
            return DfDisplayHelp(wnd, db->HelpName);
        default:
            break;
    }
    return FALSE;
}

/* ----- window-processing module, DF_DIALOG window class ----- */
int DfDialogProc(DFWINDOW wnd, DFMESSAGE msg, DF_PARAM p1, DF_PARAM p2)
{
	int rtn;
    DF_DBOX *db = wnd->extension;

    switch (msg)    {
        case DFM_CREATE_WINDOW:
            return CreateWindowMsg(wnd, p1, p2);
        case DFM_SHIFT_CHANGED:
            if (wnd->Modal)
                return TRUE;
            break;
        case DFM_LEFT_BUTTON:
            if (LeftButtonMsg(wnd, p1, p2))
                return TRUE;
            break;
        case DFM_KEYBOARD:
            if (KeyboardMsg(wnd, p1, p2))
                return TRUE;
            break;
        case DFM_CLOSE_POPDOWN:
            SysMenuOpen = FALSE;
            break;
        case DFM_LB_SELECTION:
        case DFM_LB_CHOOSE:
            if (SysMenuOpen)
                return TRUE;
            DfSendMessage(wnd, DFM_COMMAND, inFocusCommand(db), msg);
            break;
        case DFM_COMMAND:
            if (CommandMsg(wnd, p1, p2))
                return TRUE;
            break;
        case DFM_PAINT:
            p2 = TRUE;
            break;
		case DFM_MOVE:
		case DFM_DFM_SIZE:
			rtn = DfBaseWndProc(DF_DIALOG, wnd, msg, p1, p2);
			if (wnd->dfocus != NULL)
				DfSendMessage(wnd->dfocus, DFM_SETFOCUS, TRUE, 0);
			return rtn;

		case DFM_CLOSE_WINDOW:
			if (!p1)
			{
                DfSendMessage(wnd, DFM_COMMAND, DF_ID_CANCEL, 0);
                return TRUE;
            }
            break;

        default:
            break;
    }
    return DfBaseWndProc(DF_DIALOG, wnd, msg, p1, p2);
}

/* ------- create and execute a dialog box ---------- */
BOOL DfDialogBox(DFWINDOW wnd, DF_DBOX *db, BOOL Modal,
  int (*wndproc)(struct DfWindow *, enum DfMessages, DF_PARAM, DF_PARAM))
{
    BOOL rtn;
    int x = db->dwnd.x, y = db->dwnd.y;
    DFWINDOW DialogWnd;

    if (!Modal && wnd != NULL)
    {
        x += DfGetLeft(wnd);
        y += DfGetTop(wnd);
    }
    DialogWnd = DfDfCreateWindow(DF_DIALOG,
                        db->dwnd.title,
                        x, y,
                        db->dwnd.h,
                        db->dwnd.w,
                        db,
                        wnd,
                        wndproc,
                        Modal ? DF_SAVESELF : 0);
    DialogWnd->Modal = Modal;
    FirstFocus(db);
    DfPostMessage(DialogWnd, DFM_INITIATE_DIALOG, 0, 0);
    if (Modal)
    {
        DfSendMessage(DialogWnd, DFM_CAPTURE_MOUSE, 0, 0);
        DfSendMessage(DialogWnd, DFM_CAPTURE_KEYBOARD, 0, 0);
        while (DfDispatchMessage ())
            ;
        rtn = DialogWnd->ReturnCode == DF_ID_OK;
        DfSendMessage(DialogWnd, DFM_RELEASE_MOUSE, 0, 0);
        DfSendMessage(DialogWnd, DFM_RELEASE_KEYBOARD, 0, 0);
        DfSendMessage(DialogWnd, DFM_CLOSE_WINDOW, TRUE, 0);
        return rtn;
    }
    return FALSE;
}

/* ----- return command code of in-focus control window ---- */
static int inFocusCommand(DF_DBOX *db)
{
    DF_CTLWINDOW *ct = db->ctl;
    while (ct->class)    {
        if (ct->wnd == DfInFocus)
            return ct->command;
        ct++;
    }
    return -1;
}

/* -------- find a specified control structure ------- */
DF_CTLWINDOW *DfFindCommand(DF_DBOX *db, enum DfCommands cmd, int class)
{
    DF_CTLWINDOW *ct = db->ctl;
    while (ct->class)
    {
        if (ct->class == class)
            if (cmd == ct->command)
                return ct;
        ct++;
    }
    return NULL;
}

/* ---- return the window handle of a specified command ---- */
DFWINDOW DfControlWindow(DF_DBOX *db, enum DfCommands cmd)
{
    DF_CTLWINDOW *ct = db->ctl;
    while (ct->class)
    {
        if (ct->class != DF_TEXT && cmd == ct->command)
            return ct->wnd;
        ct++;
    }
    return NULL;
}

/* --- return a pointer to the control structure that matches a window --- */
DF_CTLWINDOW *WindowControl(DF_DBOX *db, DFWINDOW wnd)
{
    DF_CTLWINDOW *ct = db->ctl;
    while (ct->class)
    {
        if (ct->wnd == wnd)
            return ct;
        ct++;
    }
    return NULL;
}

/* ---- set a control DF_ON or DF_OFF ----- */
void DfControlSetting(DF_DBOX *db, enum DfCommands cmd,
                                int class, int setting)
{
    DF_CTLWINDOW *ct = DfFindCommand(db, cmd, class);
    if (ct != NULL)	{
        ct->isetting = setting;
		if (ct->wnd != NULL)
			ct->setting = setting;
	}
}

/* ---- return pointer to the text of a control window ---- */
char *DfGetDlgTextString(DF_DBOX *db,enum DfCommands cmd,DFCLASS class)
{
    DF_CTLWINDOW *ct = DfFindCommand(db, cmd, class);
    if (ct != NULL)
        return ct->itext;
    else
        return NULL;
}

/* ------- set the text of a control specification ------ */
void DfSetDlgTextString(DF_DBOX *db, enum DfCommands cmd,
                                    char *text, DFCLASS class)
{
    DF_CTLWINDOW *ct = DfFindCommand(db, cmd, class);
    if (ct != NULL)    {
        ct->itext = DfRealloc(ct->itext, strlen(text)+1);
        strcpy(ct->itext, text);
    }
}

/* ------- set the text of a control window ------ */
void DfPutItemText(DFWINDOW wnd, enum DfCommands cmd, char *text)
{
    DF_CTLWINDOW *ct = DfFindCommand(wnd->extension, cmd, DF_EDITBOX);

    if (ct == NULL)
        ct = DfFindCommand(wnd->extension, cmd, DF_TEXTBOX);
    if (ct == NULL)
        ct = DfFindCommand(wnd->extension, cmd, DF_COMBOBOX);
    if (ct == NULL)
        ct = DfFindCommand(wnd->extension, cmd, DF_LISTBOX);
    if (ct == NULL)

⌨️ 快捷键说明

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