📄 normal.c
字号:
/* ------------- normal.c ------------ */
#include "dflat32/dflat.h"
#ifdef INCLUDE_MULTI_WINDOWS
static void PaintOverLappers(DFWINDOW wnd);
static void PaintUnderLappers(DFWINDOW wnd);
#endif
static BOOL InsideWindow(DFWINDOW, int, int);
static void TerminateMoveSize(void);
static void SaveBorder(DFRECT);
static void RestoreBorder(DFRECT);
static void GetVideoBuffer(DFWINDOW);
static void PutVideoBuffer(DFWINDOW);
#ifdef INCLUDE_MINIMIZE
static DFRECT PositionIcon(DFWINDOW);
#endif
static void dragborder(DFWINDOW, int, int);
static void sizeborder(DFWINDOW, int, int);
static int px = -1, py = -1;
static int diff;
static struct window dwnd = {DUMMY, NULL, NormalProc,
{-1,-1,-1,-1}};
static PCHAR_INFO Bsave;
static int Bht, Bwd;
BOOL WindowMoving;
BOOL WindowSizing;
/* -------- array of class definitions -------- */
CLASSDEFS classdefs[] = {
#undef ClassDef
#define ClassDef(c,b,p,a) {b,p,a},
#include "dflat32/classes.h"
};
DFWINDOW HiddenWindow;
/* --------- CREATE_WINDOW Message ---------- */
static void CreateWindowMsg(DFWINDOW wnd)
{
AppendWindow(wnd);
// ClearAttribute(wnd, VSCROLLBAR | HSCROLLBAR);
if (TestAttribute(wnd, SAVESELF) && isVisible(wnd))
GetVideoBuffer(wnd);
}
/* --------- SHOW_WINDOW Message ---------- */
static void ShowWindowMsg(DFWINDOW wnd, PARAM p1, PARAM p2)
{
if (GetParent(wnd) == NULL || isVisible(GetParent(wnd)))
{
DFWINDOW cwnd;
if (TestAttribute(wnd, SAVESELF) && wnd->videosave == NULL)
GetVideoBuffer(wnd);
SetVisible(wnd);
DfSendMessage(wnd, PAINT, 0, TRUE);
DfSendMessage(wnd, BORDER, 0, 0);
/* --- show the children of this window --- */
cwnd = FirstWindow(wnd);
while (cwnd != NULL)
{
if (cwnd->condition != ISCLOSING)
DfSendMessage(cwnd, SHOW_WINDOW, p1, p2);
cwnd = NextWindow(cwnd);
}
}
}
/* --------- HIDE_WINDOW Message ---------- */
static void HideWindowMsg(DFWINDOW wnd)
{
if (isVisible(wnd))
{
ClearVisible(wnd);
/* --- paint what this window covered --- */
if (TestAttribute(wnd, SAVESELF))
PutVideoBuffer(wnd);
#ifdef INCLUDE_MULTI_WINDOWS
else
PaintOverLappers(wnd);
#endif
}
}
/* --------- KEYBOARD Message ---------- */
static BOOL KeyboardMsg(DFWINDOW wnd, PARAM p1, PARAM p2)
{
if (WindowMoving || WindowSizing) {
/* -- move or size a window with keyboard -- */
int x, y;
x=WindowMoving?GetLeft(&dwnd):GetRight(&dwnd);
y=WindowMoving?GetTop(&dwnd):GetBottom(&dwnd);
switch ((int)p1) {
case ESC:
TerminateMoveSize();
return TRUE;
case UP:
if (y)
--y;
break;
case DN:
if (y < DfGetScreenHeight()-1)
y++;
break;
case FWD:
if (x < DfGetScreenWidth()-1)
x++;
break;
case BS:
if (x)
--x;
break;
case '\r':
DfSendMessage(wnd, DFM_BUTTON_RELEASED,x,y);
default:
return TRUE;
}
/* -- use the mouse functions to move/size - */
DfSendMessage(wnd, MOUSE_MOVED, x, y);
return TRUE;
}
switch ((int)p1)
{
case F1:
DfSendMessage(wnd, DFM_COMMAND, ID_HELP, 0);
return TRUE;
case ' ':
if ((int)p2 & ALTKEY)
if (TestAttribute(wnd, HASTITLEBAR))
if (TestAttribute(wnd, CONTROLBOX))
BuildSystemMenu(wnd);
return TRUE;
case CTRL_F4:
if (TestAttribute(wnd, CONTROLBOX))
{
DfSendMessage(wnd, CLOSE_WINDOW, 0, 0);
SkipApplicationControls();
return TRUE;
}
break;
default:
break;
}
return FALSE;
}
/* --------- COMMAND Message ---------- */
static void CommandMsg(DFWINDOW wnd, PARAM p1)
{
switch ((int)p1) {
case ID_HELP:
DisplayHelp(wnd,ClassNames[GetClass(wnd)]);
break;
#ifdef INCLUDE_RESTORE
case ID_SYSRESTORE:
DfSendMessage(wnd, RESTORE, 0, 0);
break;
#endif
case ID_SYSMOVE:
DfSendMessage(wnd, CAPTURE_MOUSE, TRUE,
(PARAM) &dwnd);
DfSendMessage(wnd, CAPTURE_KEYBOARD, TRUE,
(PARAM) &dwnd);
WindowMoving = TRUE;
dragborder(wnd, GetLeft(wnd), GetTop(wnd));
break;
case ID_SYSSIZE:
DfSendMessage(wnd, CAPTURE_MOUSE, TRUE,
(PARAM) &dwnd);
DfSendMessage(wnd, CAPTURE_KEYBOARD, TRUE,
(PARAM) &dwnd);
WindowSizing = TRUE;
dragborder(wnd, GetLeft(wnd), GetTop(wnd));
break;
#ifdef INCLUDE_MINIMIZE
case ID_SYSMINIMIZE:
DfSendMessage(wnd, MINIMIZE, 0, 0);
break;
#endif
#ifdef INCLUDE_MAXIMIZE
case ID_SYSMAXIMIZE:
DfSendMessage(wnd, MAXIMIZE, 0, 0);
break;
#endif
case ID_SYSCLOSE:
DfSendMessage(wnd, CLOSE_WINDOW, 0, 0);
SkipApplicationControls();
break;
default:
break;
}
}
/* --------- SETFOCUS Message ---------- */
static void SetFocusMsg(DFWINDOW wnd, PARAM p1)
{
DFRECT rc = {0,0,0,0};
if (p1 && wnd != NULL && inFocus != wnd)
{
DFWINDOW this, thispar;
DFWINDOW that = NULL, thatpar = NULL;
DFWINDOW cwnd = wnd, fwnd = GetParent(wnd);
/* ---- post focus in ancestors ---- */
while (fwnd != NULL)
{
fwnd->childfocus = cwnd;
cwnd = fwnd;
fwnd = GetParent(fwnd);
}
/* ---- de-post focus in self and children ---- */
fwnd = wnd;
while (fwnd != NULL)
{
cwnd = fwnd->childfocus;
fwnd->childfocus = NULL;
fwnd = cwnd;
}
this = wnd;
that = thatpar = inFocus;
/* ---- find common ancestor of prev focus and this window --- */
while (thatpar != NULL)
{
thispar = wnd;
while (thispar != NULL)
{
if (this == CaptureMouse || this == CaptureKeyboard)
{
/* ---- don't repaint if this window has capture ---- */
that = thatpar = NULL;
break;
}
if (thispar == thatpar)
{
/* ---- don't repaint if SAVESELF window had focus ---- */
if (this != that && TestAttribute(that, SAVESELF))
that = thatpar = NULL;
break;
}
this = thispar;
thispar = GetParent(thispar);
}
if (thispar != NULL)
break;
that = thatpar;
thatpar = GetParent(thatpar);
}
if (inFocus != NULL)
DfSendMessage(inFocus, SETFOCUS, FALSE, 0);
inFocus = wnd;
if (that != NULL && isVisible(wnd))
{
rc = subRectangle(WindowRect(that), WindowRect(this));
if (!ValidRect(rc))
{
if (ApplicationWindow != NULL)
{
DFWINDOW fwnd = FirstWindow(ApplicationWindow);
while (fwnd != NULL)
{
if (!isAncestor(wnd, fwnd))
{
rc = subRectangle(WindowRect(wnd),WindowRect(fwnd));
if (ValidRect(rc))
break;
}
fwnd = NextWindow(fwnd);
}
}
}
}
if (that != NULL && !ValidRect(rc) && isVisible(wnd))
{
DfSendMessage(wnd, BORDER, 0, 0);
this = NULL;
}
ReFocus(wnd);
if (this != NULL)
DfSendMessage(this, SHOW_WINDOW, 0, 0);
}
else if (!p1 && inFocus == wnd)
{
/* clearing focus */
inFocus = NULL;
DfSendMessage(wnd, BORDER, 0, 0);
}
}
/* --------- DOUBLE_CLICK Message ---------- */
static void DoubleClickMsg(DFWINDOW wnd, PARAM p1, PARAM p2)
{
int mx = (int) p1 - GetLeft(wnd);
int my = (int) p2 - GetTop(wnd);
if (!WindowSizing && !WindowMoving) {
if (HitControlBox(wnd, mx, my)) {
DfPostMessage(wnd, CLOSE_WINDOW, 0, 0);
SkipApplicationControls();
}
}
}
/* --------- LEFT_BUTTON Message ---------- */
static void LeftButtonMsg(DFWINDOW wnd, PARAM p1, PARAM p2)
{
int mx = (int) p1 - GetLeft(wnd);
int my = (int) p2 - GetTop(wnd);
if (WindowSizing || WindowMoving)
return;
if (HitControlBox(wnd, mx, my)) {
BuildSystemMenu(wnd);
return;
}
if (my == 0 && mx > -1 && mx < WindowWidth(wnd)) {
/* ---------- hit the top border -------- */
if (TestAttribute(wnd, MINMAXBOX) &&
TestAttribute(wnd, HASTITLEBAR)) {
if (mx == WindowWidth(wnd)-2) {
if (wnd->condition != ISRESTORED)
/* --- hit the restore box --- */
DfSendMessage(wnd, RESTORE, 0, 0);
#ifdef INCLUDE_MAXIMIZE
else
/* --- hit the maximize box --- */
DfSendMessage(wnd, MAXIMIZE, 0, 0);
#endif
return;
}
#ifdef INCLUDE_MINIMIZE
if (mx == WindowWidth(wnd)-3) {
/* --- hit the minimize box --- */
if (wnd->condition != ISMINIMIZED)
DfSendMessage(wnd, MINIMIZE, 0, 0);
return;
}
#endif
}
#ifdef INCLUDE_MAXIMIZE
if (wnd->condition == ISMAXIMIZED)
return;
#endif
if (TestAttribute(wnd, MOVEABLE)) {
WindowMoving = TRUE;
px = mx;
py = my;
diff = (int) mx;
DfSendMessage(wnd, CAPTURE_MOUSE, TRUE,
(PARAM) &dwnd);
dragborder(wnd, GetLeft(wnd), GetTop(wnd));
}
return;
}
if (mx == WindowWidth(wnd)-1 &&
my == WindowHeight(wnd)-1) {
/* ------- hit the resize corner ------- */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -