📄 normal.c
字号:
#ifdef INCLUDE_MINIMIZE
if (wnd->condition == DF_ISMINIMIZED)
return;
#endif
if (!DfTestAttribute(wnd, DF_SIZEABLE))
return;
#ifdef INCLUDE_MAXIMIZE
if (wnd->condition == DF_ISMAXIMIZED) {
if (DfGetParent(wnd) == NULL)
return;
if (DfTestAttribute(DfGetParent(wnd),DF_HASBORDER))
return;
/* ----- resizing a maximized window over a
borderless parent ----- */
wnd = DfGetParent(wnd);
}
#endif
DfWindowSizing = TRUE;
DfSendMessage(wnd, DFM_CAPTURE_MOUSE,
TRUE, (DF_PARAM) &dwnd);
dragborder(wnd, DfGetLeft(wnd), DfGetTop(wnd));
}
}
/* --------- MOUSE_MOVED Message ---------- */
static BOOL MouseMovedMsg(DFWINDOW wnd, DF_PARAM p1, DF_PARAM p2)
{
if (DfWindowMoving) {
int leftmost = 0, topmost = 0,
bottommost = DfGetScreenHeight()-2,
rightmost = DfGetScreenWidth()-2;
int x = (int) p1 - diff;
int y = (int) p2;
if (DfGetParent(wnd) != NULL &&
!DfTestAttribute(wnd, DF_NOCLIP)) {
DFWINDOW wnd1 = DfGetParent(wnd);
topmost = DfGetClientTop(wnd1);
leftmost = DfGetClientLeft(wnd1);
bottommost = DfGetClientBottom(wnd1);
rightmost = DfGetClientRight(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 (DfWindowSizing) {
sizeborder(wnd, (int) p1, (int) p2);
return TRUE;
}
return FALSE;
}
#ifdef INCLUDE_MAXIMIZE
/* --------- DFM_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 (DfGetParent(wnd))
rc = DfClientRect(DfGetParent(wnd));
wnd->oldcondition = wnd->condition;
wnd->condition = DF_ISMAXIMIZED;
DfSendMessage(wnd, DFM_HIDE_WINDOW, 0, 0);
DfSendMessage(wnd, DFM_MOVE,
DfRectLeft(rc), DfRectTop(rc));
DfSendMessage(wnd, DFM_DFM_SIZE,
DfRectRight(rc), DfRectBottom(rc));
if (wnd->restored_attrib == 0)
wnd->restored_attrib = wnd->attrib;
DfClearAttribute(wnd, DF_SHADOW);
DfSendMessage(wnd, DFM_SHOW_WINDOW, 0, 0);
wnd->RestoredRC = holdrc;
}
#endif
#ifdef INCLUDE_MINIMIZE
/* --------- DFM_MINIMIZE Message ---------- */
static void MinimizeMsg(DFWINDOW wnd)
{
DFRECT rc;
DFRECT holdrc;
holdrc = wnd->RestoredRC;
rc = PositionIcon(wnd);
wnd->oldcondition = wnd->condition;
wnd->condition = DF_ISMINIMIZED;
DfSendMessage(wnd, DFM_HIDE_WINDOW, 0, 0);
DfSendMessage(wnd, DFM_MOVE,
DfRectLeft(rc), DfRectTop(rc));
DfSendMessage(wnd, DFM_DFM_SIZE,
DfRectRight(rc), DfRectBottom(rc));
if (wnd == DfInFocus)
DfSetNextFocus();
if (wnd->restored_attrib == 0)
wnd->restored_attrib = wnd->attrib;
DfClearAttribute(wnd,
DF_SHADOW | DF_SIZEABLE | DF_HASMENUBAR |
DF_VSCROLLBAR | DF_HSCROLLBAR);
DfSendMessage(wnd, DFM_SHOW_WINDOW, 0, 0);
wnd->RestoredRC = holdrc;
}
#endif
#ifdef INCLUDE_RESTORE
/* --------- DFM_RESTORE Message ---------- */
static void RestoreMsg(DFWINDOW wnd)
{
DFRECT holdrc;
holdrc = wnd->RestoredRC;
wnd->oldcondition = wnd->condition;
wnd->condition = DF_SRESTORED;
DfSendMessage(wnd, DFM_HIDE_WINDOW, 0, 0);
wnd->attrib = wnd->restored_attrib;
wnd->restored_attrib = 0;
DfSendMessage(wnd, DFM_MOVE, wnd->RestoredRC.lf,
wnd->RestoredRC.tp);
wnd->RestoredRC = holdrc;
DfSendMessage(wnd, DFM_DFM_SIZE, wnd->RestoredRC.rt,
wnd->RestoredRC.bt);
if (wnd != DfInFocus)
DfSendMessage(wnd, DFM_SETFOCUS, TRUE, 0);
else
DfSendMessage(wnd, DFM_SHOW_WINDOW, 0, 0);
}
#endif
/* --------- DFM_MOVE Message ---------- */
static void MoveMsg(DFWINDOW wnd, DF_PARAM p1, DF_PARAM p2)
{
DFWINDOW cwnd;
BOOL wasVisible = DfIsVisible(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 = DfGetLeft(wnd)+DfWindowWidth(wnd)-1;
wnd->rc.bt = DfGetTop(wnd)+DfWindowHeight(wnd)-1;
if (wnd->condition == DF_SRESTORED)
wnd->RestoredRC = wnd->rc;
cwnd = DfFirstWindow(wnd);
while (cwnd != NULL) {
DfSendMessage(cwnd, DFM_MOVE, cwnd->rc.lf+xdif, cwnd->rc.tp+ydif);
cwnd = DfNextWindow(cwnd);
}
if (wasVisible)
DfSendMessage(wnd, DFM_SHOW_WINDOW, 0, 0);
}
/* --------- SIZE Message ---------- */
static void SizeMsg(DFWINDOW wnd, DF_PARAM p1, DF_PARAM p2)
{
BOOL wasVisible = DfIsVisible(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 = DfGetBottom(wnd)-DfGetTop(wnd)+1;
wnd->wd = DfGetRight(wnd)-DfGetLeft(wnd)+1;
if (wnd->condition == DF_SRESTORED)
wnd->RestoredRC = DfWindowRect(wnd);
#ifdef INCLUDE_MAXIMIZE
rc = DfClientRect(wnd);
cwnd = DfFirstWindow(wnd);
while (cwnd != NULL) {
if (cwnd->condition == DF_ISMAXIMIZED)
DfSendMessage(cwnd, DFM_DFM_SIZE, DfRectRight(rc), DfRectBottom(rc));
cwnd = DfNextWindow(cwnd);
}
#endif
if (wasVisible)
DfSendMessage(wnd, DFM_SHOW_WINDOW, 0, 0);
}
/* --------- DFM_CLOSE_WINDOW Message ---------- */
static void CloseWindowMsg(DFWINDOW wnd)
{
DFWINDOW cwnd;
wnd->condition = DF_ISCLOSING;
if (wnd->PrevMouse != NULL)
DfSendMessage(wnd, DFM_RELEASE_MOUSE, 0, 0);
if (wnd->PrevKeyboard != NULL)
DfSendMessage(wnd, DFM_RELEASE_KEYBOARD, 0, 0);
/* ----------- hide this window ------------ */
DfSendMessage(wnd, DFM_HIDE_WINDOW, 0, 0);
/* --- close the children of this window --- */
cwnd = DfLastWindow(wnd);
while (cwnd != NULL) {
if (DfInFocus == cwnd)
DfInFocus = wnd;
DfSendMessage(cwnd,DFM_CLOSE_WINDOW,0,0);
cwnd = DfLastWindow(wnd);
}
/* --- change focus if this window had it -- */
if (wnd == DfInFocus)
DfSetPrevFocus();
/* -- 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 -- */
DfRemoveWindow(wnd);
if (wnd == DfInFocus)
DfInFocus = NULL;
free(wnd);
}
/* ---- Window-processing module for DF_NORMAL window class ---- */
int DfNormalProc(DFWINDOW wnd, DFMESSAGE msg, DF_PARAM p1, DF_PARAM p2)
{
switch (msg) {
case DFM_CREATE_WINDOW:
CreateWindowMsg(wnd);
break;
case DFM_SHOW_WINDOW:
ShowWindowMsg(wnd, p1, p2);
break;
case DFM_HIDE_WINDOW:
HideWindowMsg(wnd);
break;
case DFM_DISPLAY_HELP:
DfDisplayHelp(wnd, (char *)p1);
break;
case DFM_INSIDE_WINDOW:
return InsideWindow(wnd, (int) p1, (int) p2);
case DFM_KEYBOARD:
if (KeyboardMsg(wnd, p1, p2))
return TRUE;
/* ------- fall through ------- */
case DFM_ADDSTATUS:
case DFM_SHIFT_CHANGED:
if (DfGetParent(wnd) != NULL)
DfPostMessage(DfGetParent(wnd), msg, p1, p2);
break;
case DFM_PAINT:
if (DfIsVisible(wnd))
DfClearWindow(wnd, (DFRECT *)p1, ' ');
break;
case DFM_BORDER:
if (DfIsVisible(wnd))
{
if (DfTestAttribute(wnd, DF_HASBORDER))
DfRepaintBorder(wnd, (DFRECT *)p1);
else if (DfTestAttribute(wnd, DF_HASTITLEBAR))
DfDisplayTitle(wnd, (DFRECT *)p1);
}
break;
case DFM_COMMAND:
CommandMsg(wnd, p1);
break;
case DFM_SETFOCUS:
SetFocusMsg(wnd, p1);
break;
case DFM_DOUBLE_CLICK:
DoubleClickMsg(wnd, p1, p2);
break;
case DFM_LEFT_BUTTON:
LeftButtonMsg(wnd, p1, p2);
break;
case MOUSE_MOVED:
if (MouseMovedMsg(wnd, p1, p2))
return TRUE;
break;
case DFM_BUTTON_RELEASED:
if (DfWindowMoving || DfWindowSizing)
{
if (DfWindowMoving)
DfPostMessage(wnd,DFM_MOVE,dwnd.rc.lf,dwnd.rc.tp);
else
DfPostMessage(wnd, DFM_DFM_SIZE,dwnd.rc.rt,dwnd.rc.bt);
TerminateMoveSize();
}
break;
#ifdef INCLUDE_MAXIMIZE
case DFM_MAXIMIZE:
if (wnd->condition != DF_ISMAXIMIZED)
MaximizeMsg(wnd);
break;
#endif
#ifdef INCLUDE_MINIMIZE
case DFM_MINIMIZE:
if (wnd->condition != DF_ISMINIMIZED)
MinimizeMsg(wnd);
break;
#endif
#ifdef INCLUDE_RESTORE
case DFM_RESTORE:
if (wnd->condition != DF_SRESTORED) {
#ifdef INCLUDE_MAXIMIZE
if (wnd->oldcondition == DF_ISMAXIMIZED)
DfSendMessage(wnd, DFM_MAXIMIZE, 0, 0);
else
#endif
RestoreMsg(wnd);
}
break;
#endif
case DFM_MOVE:
MoveMsg(wnd, p1, p2);
break;
case DFM_DFM_SIZE: {
SizeMsg(wnd, p1, p2);
break;
}
case DFM_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;
DfRectLeft(rc) = DfRectRight(prc) - DF_ICONWIDTH;
DfRectTop(rc) = DfRectBottom(prc) - DF_ICONHEIGHT;
DfRectRight(rc) = DfRectLeft(rc)+DF_ICONWIDTH-1;
DfRectBottom(rc) = DfRectTop(rc)+DF_ICONHEIGHT-1;
return rc;
}
/* ----- compute a position for a minimized window icon ---- */
static DFRECT PositionIcon(DFWINDOW wnd)
{
DFWINDOW pwnd = DfGetParent(wnd);
DFRECT rc;
DfRectLeft(rc) = DfGetScreenWidth()-DF_ICONWIDTH;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -