/*
** $Id: window.c,v 1.179.10.1 2005/02/15 08:31:35 weiym Exp $
**
** window.c: The Window module.
**
** Copyright (C) 2003 ~ 2004 Feynman Software.
** Copyright (C) 1999 ~ 2002 Wei Yongming.
**
** Current maintainer: Wei Yongming.
**
** Create date: 1999.04.19
*/
/*
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
** TODO:
*/
#include <stdlib.h>
#include <string.h>
#include "common.h"
#include "minigui.h"
#include "gdi.h"
#include "window.h"
#include "control.h"
#include "cliprect.h"
#include "gal.h"
#include "internals.h"
#include "menu.h"
#include "ctrlclass.h"
#include "element.h"
#if defined(_LITE_VERSION) && !defined(_STAND_ALONE)
#include "client.h"
#endif
// function defined in menu module.
void DrawMenuBarHelper (const MAINWIN *pWin, HDC hdc, const RECT* pClipRect);
// functions defined in caret module.
BOOL BlinkCaret (HWND hWnd);
void GetCaretBitmaps (PCARETINFO pCaretInfo);
// this message will auto-repeat when MSG_IDLE received
static MSG sg_repeat_msg = {HWND_DESKTOP, 0, 0, 0};
void GUIAPI SetAutoRepeatMessage (HWND hwnd, int msg, WPARAM wParam, LPARAM lParam)
{
sg_repeat_msg.hwnd = hwnd;
sg_repeat_msg.message = msg;
sg_repeat_msg.wParam = wParam;
sg_repeat_msg.lParam = lParam;
}
static void RecalcClientArea (HWND hWnd)
{
PMAINWIN pWin = (PMAINWIN)hWnd;
RECT rcWin, rcClient;
memcpy (&rcWin, &pWin->left, sizeof (RECT));
memcpy (&rcClient, &pWin->cl, sizeof (RECT));
if (SendAsyncMessage (hWnd, MSG_SIZECHANGED,
(WPARAM)&rcWin, (LPARAM)&rcClient))
memcpy (&pWin->cl, &rcClient, sizeof(RECT));
}
static PCONTROL wndMouseInWhichControl (PMAINWIN pWin, int x, int y,
int* UndHitCode)
{
PCONTROL pCtrl;
int hitcode;
pCtrl = (PCONTROL)pWin->hPrimitive;
if (pCtrl) {
if (pCtrl->primitive) {
if (UndHitCode)
*UndHitCode = HT_CLIENT;
return pCtrl;
}
else {
hitcode = SendAsyncMessage ((HWND)pCtrl, MSG_HITTEST,
(WPARAM)x, (LPARAM)y);
if (hitcode != HT_OUT && hitcode != HT_TRANSPARENT) {
if (UndHitCode)
*UndHitCode = hitcode;
return pCtrl;
}
}
}
pCtrl = (PCONTROL)(pWin->hFirstChild);
while (pCtrl) {
if ((pCtrl->dwStyle & WS_VISIBLE)
&& PtInRect ((PRECT)(&pCtrl->left), x, y)) {
hitcode = SendAsyncMessage((HWND)pCtrl, MSG_HITTEST,
(WPARAM)x, (LPARAM)y);
if (hitcode != HT_OUT && hitcode != HT_TRANSPARENT) {
if (UndHitCode) {
*UndHitCode = hitcode;
}
return pCtrl;
}
}
pCtrl = pCtrl->next;
}
return NULL;
}
// NOTE:
// this function is CONTROL mouse messages handler,
// can automaticly capture mouse depend on HITTEST code.
//
static PCONTROL __mgs_captured_ctrl = NULL;
void __mg_reset_mainwin_capture_info (PCONTROL ctrl)
{
if ((ctrl == NULL || ctrl == __mgs_captured_ctrl)
|| (__mgs_captured_ctrl && __mgs_captured_ctrl->pMainWin == (PMAINWIN)ctrl)) {
POINT mousePos;
ReleaseCapture ();
__mgs_captured_ctrl = NULL;
GetCursorPos (&mousePos);
PostMessage (HWND_DESKTOP, MSG_MOUSEMOVE, 0, MAKELONG (mousePos.x, mousePos.y));
}
}
static int DefaultMouseMsgHandler (PMAINWIN pWin, int message,
WPARAM flags, int x, int y)
{
static PMAINWIN __mgs_captured_win = NULL;
PCONTROL pUnderPointer;
int CapHitCode = HT_UNKNOWN;
int UndHitCode = HT_UNKNOWN;
int cx = 0, cy = 0;
if (__mgs_captured_ctrl) {
// convert to parent window's client coordinates.
ScreenToClient ((HWND)__mgs_captured_win, &x, &y);
CapHitCode = SendAsyncMessage((HWND)__mgs_captured_ctrl, MSG_HITTEST,
(WPARAM)x, (LPARAM)y);
pUnderPointer = NULL;
}
else {
pUnderPointer = wndMouseInWhichControl (pWin, x, y, &UndHitCode);
if (pUnderPointer && (pUnderPointer->dwStyle & WS_DISABLED))
pUnderPointer = NULL;
if (pUnderPointer) {
cx = x - pUnderPointer->cl;
cy = y - pUnderPointer->ct;
}
}
switch (message) {
case MSG_MOUSEMOVE:
if (__mgs_captured_ctrl)
PostMessage((HWND)__mgs_captured_ctrl, MSG_NCMOUSEMOVE,
CapHitCode, MAKELONG (x, y));
else {
if (pWin->hOldUnderPointer != (HWND)pUnderPointer) {
if (pWin->hOldUnderPointer) {
PostMessage ((HWND)pWin->hOldUnderPointer,
MSG_MOUSEMOVEIN, FALSE, (LPARAM)pUnderPointer);
PostMessage ((HWND)pWin->hOldUnderPointer,
MSG_NCMOUSEMOVE, HT_OUT, MAKELONG (x, y));
}
if (pUnderPointer)
PostMessage ((HWND)pUnderPointer,
MSG_MOUSEMOVEIN, TRUE, (LPARAM)pWin->hOldUnderPointer);
pWin->hOldUnderPointer = (HWND)pUnderPointer;
}
if (pUnderPointer == NULL) {
pWin->hOldUnderPointer = 0;
break;
}
if (pUnderPointer->dwStyle & WS_DISABLED) {
SetCursor (GetSystemCursor (IDC_ARROW));
break;
}
if (UndHitCode == HT_CLIENT) {
PostMessage ((HWND)pUnderPointer,
MSG_SETCURSOR, 0, MAKELONG (cx, cy));
PostMessage((HWND)pUnderPointer, MSG_NCMOUSEMOVE,
UndHitCode, MAKELONG (x, y));
PostMessage((HWND)pUnderPointer, MSG_MOUSEMOVE,
flags, MAKELONG (cx, cy));
}
else
{
PostMessage((HWND)pUnderPointer, MSG_NCSETCURSOR,
UndHitCode, MAKELONG (x, y));
PostMessage((HWND)pUnderPointer, MSG_NCMOUSEMOVE,
UndHitCode, MAKELONG (x, y));
}
}
break;
case MSG_LBUTTONDOWN:
case MSG_RBUTTONDOWN:
if (pUnderPointer) {
if (pUnderPointer->dwStyle & WS_DISABLED) {
Ping ();
break;
}
SendNotifyMessage ((HWND) pUnderPointer, MSG_MOUSEACTIVE, UndHitCode, 0);
if (UndHitCode != HT_CLIENT) {
if (UndHitCode & HT_NEEDCAPTURE) {
SetCapture ((HWND)pUnderPointer);
__mgs_captured_win = pWin;
__mgs_captured_ctrl = pUnderPointer;
}
else
__mgs_captured_ctrl = NULL;
PostMessage ((HWND)pUnderPointer, message + MSG_NCMOUSEOFF,
UndHitCode, MAKELONG (x, y));
}
else {
PostMessage(
- 1
- 2
前往页