normal.c
来自「这是一个开放源代码的与WINNT/WIN2K/WIN2003兼容的操作系统」· C语言 代码 · 共 1,086 行 · 第 1/3 页
C
1,086 行
#ifdef INCLUDE_MINIMIZE
if (wnd->condition == ISMINIMIZED)
return;
#endif
if (!TestAttribute(wnd, SIZEABLE))
return;
#ifdef INCLUDE_MAXIMIZE
if (wnd->condition == ISMAXIMIZED) {
if (GetParent(wnd) == NULL)
return;
if (TestAttribute(GetParent(wnd),HASBORDER))
return;
/* ----- resizing a maximized window over a
borderless parent ----- */
wnd = GetParent(wnd);
}
#endif
WindowSizing = TRUE;
DfSendMessage(wnd, CAPTURE_MOUSE,
TRUE, (PARAM) &dwnd);
dragborder(wnd, GetLeft(wnd), GetTop(wnd));
}
}
/* --------- MOUSE_MOVED Message ---------- */
static BOOL MouseMovedMsg(DFWINDOW wnd, PARAM p1, PARAM p2)
{
if (WindowMoving) {
int leftmost = 0, topmost = 0,
bottommost = DfGetScreenHeight()-2,
rightmost = DfGetScreenWidth()-2;
int x = (int) p1 - diff;
int y = (int) p2;
if (GetParent(wnd) != NULL &&
!TestAttribute(wnd, NOCLIP)) {
DFWINDOW wnd1 = GetParent(wnd);
topmost = GetClientTop(wnd1);
leftmost = GetClientLeft(wnd1);
bottommost = GetClientBottom(wnd1);
rightmost = GetClientRight(wnd1);
}
if (x < leftmost || x > rightmost ||
y < topmost || y > bottommost) {
x = max(x, leftmost);
x = min(x, rightmost);
y = max(y, topmost);
y = min(y, bottommost);
}
if (x != px || y != py) {
px = x;
py = y;
dragborder(wnd, x, y);
}
return TRUE;
}
if (WindowSizing) {
sizeborder(wnd, (int) p1, (int) p2);
return TRUE;
}
return FALSE;
}
#ifdef INCLUDE_MAXIMIZE
/* --------- MAXIMIZE Message ---------- */
static void MaximizeMsg(DFWINDOW wnd)
{
DFRECT rc = {0, 0, 0, 0};
DFRECT holdrc;
holdrc = wnd->RestoredRC;
rc.rt = DfGetScreenWidth()-1;
rc.bt = DfGetScreenHeight()-1;
if (GetParent(wnd))
rc = ClientRect(GetParent(wnd));
wnd->oldcondition = wnd->condition;
wnd->condition = ISMAXIMIZED;
DfSendMessage(wnd, DFM_HIDE_WINDOW, 0, 0);
DfSendMessage(wnd, MOVE,
RectLeft(rc), RectTop(rc));
DfSendMessage(wnd, DFM_SIZE,
RectRight(rc), RectBottom(rc));
if (wnd->restored_attrib == 0)
wnd->restored_attrib = wnd->attrib;
ClearAttribute(wnd, SHADOW);
DfSendMessage(wnd, SHOW_WINDOW, 0, 0);
wnd->RestoredRC = holdrc;
}
#endif
#ifdef INCLUDE_MINIMIZE
/* --------- MINIMIZE Message ---------- */
static void MinimizeMsg(DFWINDOW wnd)
{
DFRECT rc;
DFRECT holdrc;
holdrc = wnd->RestoredRC;
rc = PositionIcon(wnd);
wnd->oldcondition = wnd->condition;
wnd->condition = ISMINIMIZED;
DfSendMessage(wnd, DFM_HIDE_WINDOW, 0, 0);
DfSendMessage(wnd, MOVE,
RectLeft(rc), RectTop(rc));
DfSendMessage(wnd, DFM_SIZE,
RectRight(rc), RectBottom(rc));
if (wnd == inFocus)
SetNextFocus();
if (wnd->restored_attrib == 0)
wnd->restored_attrib = wnd->attrib;
ClearAttribute(wnd,
SHADOW | SIZEABLE | HASMENUBAR |
VSCROLLBAR | HSCROLLBAR);
DfSendMessage(wnd, SHOW_WINDOW, 0, 0);
wnd->RestoredRC = holdrc;
}
#endif
#ifdef INCLUDE_RESTORE
/* --------- RESTORE Message ---------- */
static void RestoreMsg(DFWINDOW wnd)
{
DFRECT holdrc;
holdrc = wnd->RestoredRC;
wnd->oldcondition = wnd->condition;
wnd->condition = ISRESTORED;
DfSendMessage(wnd, DFM_HIDE_WINDOW, 0, 0);
wnd->attrib = wnd->restored_attrib;
wnd->restored_attrib = 0;
DfSendMessage(wnd, MOVE, wnd->RestoredRC.lf,
wnd->RestoredRC.tp);
wnd->RestoredRC = holdrc;
DfSendMessage(wnd, DFM_SIZE, wnd->RestoredRC.rt,
wnd->RestoredRC.bt);
if (wnd != inFocus)
DfSendMessage(wnd, SETFOCUS, TRUE, 0);
else
DfSendMessage(wnd, SHOW_WINDOW, 0, 0);
}
#endif
/* --------- MOVE Message ---------- */
static void MoveMsg(DFWINDOW wnd, PARAM p1, PARAM p2)
{
DFWINDOW cwnd;
BOOL wasVisible = isVisible(wnd);
int xdif = (int) p1 - wnd->rc.lf;
int ydif = (int) p2 - wnd->rc.tp;
if (xdif == 0 && ydif == 0)
return;
if (wasVisible)
DfSendMessage(wnd, DFM_HIDE_WINDOW, 0, 0);
wnd->rc.lf = (int) p1;
wnd->rc.tp = (int) p2;
wnd->rc.rt = GetLeft(wnd)+WindowWidth(wnd)-1;
wnd->rc.bt = GetTop(wnd)+WindowHeight(wnd)-1;
if (wnd->condition == ISRESTORED)
wnd->RestoredRC = wnd->rc;
cwnd = FirstWindow(wnd);
while (cwnd != NULL) {
DfSendMessage(cwnd, MOVE, cwnd->rc.lf+xdif, cwnd->rc.tp+ydif);
cwnd = NextWindow(cwnd);
}
if (wasVisible)
DfSendMessage(wnd, SHOW_WINDOW, 0, 0);
}
/* --------- SIZE Message ---------- */
static void SizeMsg(DFWINDOW wnd, PARAM p1, PARAM p2)
{
BOOL wasVisible = isVisible(wnd);
DFWINDOW cwnd;
DFRECT rc;
int xdif = (int) p1 - wnd->rc.rt;
int ydif = (int) p2 - wnd->rc.bt;
if (xdif == 0 && ydif == 0)
return;
if (wasVisible)
DfSendMessage(wnd, DFM_HIDE_WINDOW, 0, 0);
wnd->rc.rt = (int) p1;
wnd->rc.bt = (int) p2;
wnd->ht = GetBottom(wnd)-GetTop(wnd)+1;
wnd->wd = GetRight(wnd)-GetLeft(wnd)+1;
if (wnd->condition == ISRESTORED)
wnd->RestoredRC = WindowRect(wnd);
#ifdef INCLUDE_MAXIMIZE
rc = ClientRect(wnd);
cwnd = FirstWindow(wnd);
while (cwnd != NULL) {
if (cwnd->condition == ISMAXIMIZED)
DfSendMessage(cwnd, DFM_SIZE, RectRight(rc), RectBottom(rc));
cwnd = NextWindow(cwnd);
}
#endif
if (wasVisible)
DfSendMessage(wnd, SHOW_WINDOW, 0, 0);
}
/* --------- CLOSE_WINDOW Message ---------- */
static void CloseWindowMsg(DFWINDOW wnd)
{
DFWINDOW cwnd;
wnd->condition = ISCLOSING;
if (wnd->PrevMouse != NULL)
DfSendMessage(wnd, RELEASE_MOUSE, 0, 0);
if (wnd->PrevKeyboard != NULL)
DfSendMessage(wnd, RELEASE_KEYBOARD, 0, 0);
/* ----------- hide this window ------------ */
DfSendMessage(wnd, DFM_HIDE_WINDOW, 0, 0);
/* --- close the children of this window --- */
cwnd = LastWindow(wnd);
while (cwnd != NULL) {
if (inFocus == cwnd)
inFocus = wnd;
DfSendMessage(cwnd,CLOSE_WINDOW,0,0);
cwnd = LastWindow(wnd);
}
/* --- change focus if this window had it -- */
if (wnd == inFocus)
SetPrevFocus();
/* -- free memory allocated to this window - */
if (wnd->title != NULL)
free(wnd->title);
if (wnd->videosave != NULL)
free(wnd->videosave);
/* -- remove window from parent's list of children -- */
RemoveWindow(wnd);
if (wnd == inFocus)
inFocus = NULL;
free(wnd);
}
/* ---- Window-processing module for NORMAL window class ---- */
int NormalProc(DFWINDOW wnd, DFMESSAGE msg, PARAM p1, PARAM p2)
{
switch (msg) {
case CREATE_WINDOW:
CreateWindowMsg(wnd);
break;
case SHOW_WINDOW:
ShowWindowMsg(wnd, p1, p2);
break;
case DFM_HIDE_WINDOW:
HideWindowMsg(wnd);
break;
case DISPLAY_HELP:
DisplayHelp(wnd, (char *)p1);
break;
case INSIDE_WINDOW:
return InsideWindow(wnd, (int) p1, (int) p2);
case KEYBOARD:
if (KeyboardMsg(wnd, p1, p2))
return TRUE;
/* ------- fall through ------- */
case ADDSTATUS:
case SHIFT_CHANGED:
if (GetParent(wnd) != NULL)
DfPostMessage(GetParent(wnd), msg, p1, p2);
break;
case PAINT:
if (isVisible(wnd))
ClearWindow(wnd, (DFRECT *)p1, ' ');
break;
case BORDER:
if (isVisible(wnd))
{
if (TestAttribute(wnd, HASBORDER))
RepaintBorder(wnd, (DFRECT *)p1);
else if (TestAttribute(wnd, HASTITLEBAR))
DisplayTitle(wnd, (DFRECT *)p1);
}
break;
case DFM_COMMAND:
CommandMsg(wnd, p1);
break;
case SETFOCUS:
SetFocusMsg(wnd, p1);
break;
case DFM_DOUBLE_CLICK:
DoubleClickMsg(wnd, p1, p2);
break;
case LEFT_BUTTON:
LeftButtonMsg(wnd, p1, p2);
break;
case MOUSE_MOVED:
if (MouseMovedMsg(wnd, p1, p2))
return TRUE;
break;
case DFM_BUTTON_RELEASED:
if (WindowMoving || WindowSizing)
{
if (WindowMoving)
DfPostMessage(wnd,MOVE,dwnd.rc.lf,dwnd.rc.tp);
else
DfPostMessage(wnd, DFM_SIZE,dwnd.rc.rt,dwnd.rc.bt);
TerminateMoveSize();
}
break;
#ifdef INCLUDE_MAXIMIZE
case MAXIMIZE:
if (wnd->condition != ISMAXIMIZED)
MaximizeMsg(wnd);
break;
#endif
#ifdef INCLUDE_MINIMIZE
case MINIMIZE:
if (wnd->condition != ISMINIMIZED)
MinimizeMsg(wnd);
break;
#endif
#ifdef INCLUDE_RESTORE
case RESTORE:
if (wnd->condition != ISRESTORED) {
#ifdef INCLUDE_MAXIMIZE
if (wnd->oldcondition == ISMAXIMIZED)
DfSendMessage(wnd, MAXIMIZE, 0, 0);
else
#endif
RestoreMsg(wnd);
}
break;
#endif
case MOVE:
MoveMsg(wnd, p1, p2);
break;
case DFM_SIZE: {
SizeMsg(wnd, p1, p2);
break;
}
case CLOSE_WINDOW:
CloseWindowMsg(wnd);
break;
default:
break;
}
return TRUE;
}
#ifdef INCLUDE_MINIMIZE
/* ---- compute lower right icon space in a rectangle ---- */
static DFRECT LowerRight(DFRECT prc)
{
DFRECT rc;
RectLeft(rc) = RectRight(prc) - ICONWIDTH;
RectTop(rc) = RectBottom(prc) - ICONHEIGHT;
RectRight(rc) = RectLeft(rc)+ICONWIDTH-1;
RectBottom(rc) = RectTop(rc)+ICONHEIGHT-1;
return rc;
}
/* ----- compute a position for a minimized window icon ---- */
static DFRECT PositionIcon(DFWINDOW wnd)
{
DFWINDOW pwnd = GetParent(wnd);
DFRECT rc;
RectLeft(rc) = DfGetScreenWidth()-ICONWIDTH;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?