message.c
来自「DOS下Editor的源代码」· C语言 代码 · 共 648 行 · 第 1/2 页
C
648 行
break;
case RIGHT_BUTTON:
case LEFT_BUTTON:
case DOUBLE_CLICK:
case BUTTON_RELEASED:
/* --- don't send these messages unless the
window is visible or has captured the mouse -- */
if (isVisible(wnd) || wnd == CaptureMouse)
rtn = (*wnd->wndproc)(wnd, msg, p1, p2);
break;
case KEYBOARD:
case SHIFT_CHANGED:
/* ------- don't send these messages unless the
window is visible or has captured the keyboard -- */
if (!(isVisible(wnd) || wnd == CaptureKeyboard))
break;
default:
rtn = (*wnd->wndproc)(wnd, msg, p1, p2);
break;
}
/* ----- window processor returned true or the message was sent
to no window at all (NULL) ----- */
if (rtn != FALSE) {
/* --------- process messages that a window sends to the
system itself ---------- */
switch (msg) {
case STOP:
StopMsg();
break;
/* ------- clock messages --------- */
case CAPTURE_CLOCK:
if (Cwnd == NULL)
set_timer(clocktimer, 0);
wnd->PrevClock = Cwnd;
Cwnd = wnd;
break;
case RELEASE_CLOCK:
Cwnd = wnd->PrevClock;
if (Cwnd == NULL)
disable_timer(clocktimer);
break;
/* -------- keyboard messages ------- */
case KEYBOARD_CURSOR:
if (wnd == NULL)
cursor((int)p1, (int)p2);
else if (wnd == inFocus)
cursor(GetClientLeft(wnd)+(int)p1,
GetClientTop(wnd)+(int)p2);
break;
case CAPTURE_KEYBOARD:
if (p2)
((WINDOW)p2)->PrevKeyboard=CaptureKeyboard;
else
wnd->PrevKeyboard = CaptureKeyboard;
CaptureKeyboard = wnd;
NoChildCaptureKeyboard = (int)p1;
break;
case RELEASE_KEYBOARD:
if (wnd != NULL) {
if (CaptureKeyboard == wnd || (int)p1)
CaptureKeyboard = wnd->PrevKeyboard;
else {
WINDOW twnd = CaptureKeyboard;
while (twnd != NULL) {
if (twnd->PrevKeyboard == wnd) {
twnd->PrevKeyboard = wnd->PrevKeyboard;
break;
}
twnd = twnd->PrevKeyboard;
}
if (twnd == NULL)
CaptureKeyboard = NULL;
}
wnd->PrevKeyboard = NULL;
}
else
CaptureKeyboard = NULL;
NoChildCaptureKeyboard = FALSE;
break;
case CURRENT_KEYBOARD_CURSOR:
curr_cursor(&x, &y);
*(int*)p1 = x;
*(int*)p2 = y;
break;
case SAVE_CURSOR:
savecursor();
break;
case RESTORE_CURSOR:
restorecursor();
break;
case HIDE_CURSOR:
normalcursor();
hidecursor();
break;
case SHOW_CURSOR:
if (p1)
set_cursor_type(0x0106);
else
set_cursor_type(0x0607);
unhidecursor();
break;
case WAITKEYBOARD:
waitforkeyboard();
break;
/* -------- mouse messages -------- */
case RESET_MOUSE:
resetmouse();
set_mousetravel(0, SCREENWIDTH-1, 0, SCREENHEIGHT-1);
break;
case MOUSE_INSTALLED:
rtn = mouse_installed();
break;
case MOUSE_TRAVEL: {
RECT rc;
if (!p1) {
rc.lf = rc.tp = 0;
rc.rt = SCREENWIDTH-1;
rc.bt = SCREENHEIGHT-1;
}
else
rc = *(RECT *)p1;
set_mousetravel(rc.lf, rc.rt, rc.tp, rc.bt);
break;
}
case SHOW_MOUSE:
show_mousecursor();
break;
case HIDE_MOUSE:
hide_mousecursor();
break;
case MOUSE_CURSOR:
set_mouseposition((int)p1, (int)p2);
break;
case CURRENT_MOUSE_CURSOR:
get_mouseposition((int*)p1,(int*)p2);
break;
case WAITMOUSE:
waitformouse();
break;
case TESTMOUSE:
rtn = mousebuttons();
break;
case CAPTURE_MOUSE:
if (p2)
((WINDOW)p2)->PrevMouse = CaptureMouse;
else
wnd->PrevMouse = CaptureMouse;
CaptureMouse = wnd;
NoChildCaptureMouse = (int)p1;
break;
case RELEASE_MOUSE:
if (wnd != NULL) {
if (CaptureMouse == wnd || (int)p1)
CaptureMouse = wnd->PrevMouse;
else {
WINDOW twnd = CaptureMouse;
while (twnd != NULL) {
if (twnd->PrevMouse == wnd) {
twnd->PrevMouse = wnd->PrevMouse;
break;
}
twnd = twnd->PrevMouse;
}
if (twnd == NULL)
CaptureMouse = NULL;
}
wnd->PrevMouse = NULL;
}
else
CaptureMouse = NULL;
NoChildCaptureMouse = FALSE;
break;
default:
break;
}
}
return rtn;
}
static RECT VisibleRect(WINDOW wnd)
{
RECT rc = WindowRect(wnd);
if (!TestAttribute(wnd, NOCLIP)) {
WINDOW pwnd = GetParent(wnd);
RECT prc;
prc = ClientRect(pwnd);
while (pwnd != NULL) {
if (TestAttribute(pwnd, NOCLIP))
break;
rc = subRectangle(rc, prc);
if (!ValidRect(rc))
break;
if ((pwnd = GetParent(pwnd)) != NULL)
prc = ClientRect(pwnd);
}
}
return rc;
}
/* ----- find window that mouse coordinates are in --- */
static WINDOW inWindow(WINDOW wnd, int x, int y)
{
WINDOW Hit = NULL;
while (wnd != NULL) {
if (isVisible(wnd)) {
WINDOW wnd1;
RECT rc = VisibleRect(wnd);
if (InsideRect(x, y, rc))
Hit = wnd;
if ((wnd1 = inWindow(LastWindow(wnd), x, y)) != NULL)
Hit = wnd1;
if (Hit != NULL)
break;
}
wnd = PrevWindow(wnd);
}
return Hit;
}
static WINDOW MouseWindow(int x, int y)
{
/* ------ get the window in which a
mouse event occurred ------ */
WINDOW Mwnd = inWindow(ApplicationWindow, x, y);
/* ---- process mouse captures ----- */
if (CaptureMouse != NULL) {
if (NoChildCaptureMouse ||
Mwnd == NULL ||
!isAncestor(Mwnd, CaptureMouse))
Mwnd = CaptureMouse;
}
return Mwnd;
}
void handshake(void)
{
handshaking++;
dispatch_message();
--handshaking;
}
/* ---- dispatch messages to the message proc function ---- */
BOOL dispatch_message(void)
{
WINDOW Mwnd, Kwnd;
/* -------- collect mouse and keyboard events ------- */
collect_events();
/* --------- dequeue and process events -------- */
while (EventQueueCtr > 0) {
struct events ev;
ev = EventQueue[EventQueueOffCtr];
if (++EventQueueOffCtr == MAXMESSAGES)
EventQueueOffCtr = 0;
--EventQueueCtr;
/* ------ get the window in which a
keyboard event occurred ------ */
Kwnd = inFocus;
/* ---- process keyboard captures ----- */
if (CaptureKeyboard != NULL)
if (Kwnd == NULL ||
NoChildCaptureKeyboard ||
!isAncestor(Kwnd, CaptureKeyboard))
Kwnd = CaptureKeyboard;
/* -------- send mouse and keyboard messages to the
window that should get them -------- */
switch (ev.event) {
case SHIFT_CHANGED:
case KEYBOARD:
if (!handshaking)
SendMessage(Kwnd, ev.event, ev.mx, ev.my);
break;
case LEFT_BUTTON:
if (!handshaking) {
Mwnd = MouseWindow(ev.mx, ev.my);
if (!CaptureMouse ||
(!NoChildCaptureMouse &&
isAncestor(Mwnd, CaptureMouse)))
if (Mwnd != inFocus)
SendMessage(Mwnd, SETFOCUS, TRUE, 0);
SendMessage(Mwnd, LEFT_BUTTON, ev.mx, ev.my);
}
break;
case BUTTON_RELEASED:
case DOUBLE_CLICK:
case RIGHT_BUTTON:
if (handshaking)
break;
case MOUSE_MOVED:
Mwnd = MouseWindow(ev.mx, ev.my);
SendMessage(Mwnd, ev.event, ev.mx, ev.my);
break;
case CLOCKTICK:
SendMessage(Cwnd, ev.event,
(PARAM) MK_FP(ev.mx, ev.my), 0);
break;
default:
break;
}
}
/* ------ dequeue and process messages ----- */
while (MsgQueueCtr > 0) {
struct msgs mq;
mq = MsgQueue[MsgQueueOffCtr];
if (++MsgQueueOffCtr == MAXMESSAGES)
MsgQueueOffCtr = 0;
--MsgQueueCtr;
SendMessage(mq.wnd, mq.msg, mq.p1, mq.p2);
if (mq.msg == ENDDIALOG)
return FALSE;
if (mq.msg == STOP) {
PostMessage(NULL, STOP, 0, 0);
return FALSE;
}
}
return TRUE;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?