📄 window.c
字号:
/* ** $Id: window.c,v 1.145 2003/09/04 03:15:07 weiym Exp $**** window.c: The Window module.**** Copyright (C) 2003 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"#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 receivedstatic 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 int DefaultMouseMsgHandler (PMAINWIN pWin, int message, WPARAM flags, int x, int y){ static PMAINWIN pCapturedWin = NULL; static PCONTROL pCaptured = NULL; PCONTROL pUnderPointer; int CapHitCode = HT_UNKNOWN; int UndHitCode = HT_UNKNOWN; int cx = 0, cy = 0; if (message == MSG_WINDOWCHANGED) { POINT mousePos; pCaptured = NULL; CapHitCode = HT_UNKNOWN; GetCursorPos (&mousePos); PostMessage (HWND_DESKTOP, MSG_MOUSEMOVE, 0, MAKELONG (mousePos.x, mousePos.y)); return 0; } if (pCaptured) { // convert to parent window's client coordinates. ScreenToClient ((HWND)pCapturedWin, &x, &y); CapHitCode = SendAsyncMessage((HWND)pCaptured, 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 (pCaptured) PostMessage((HWND)pCaptured, 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; } PostMessage ((HWND) pUnderPointer, MSG_MOUSEACTIVE, UndHitCode, 0); if (UndHitCode != HT_CLIENT) { if (UndHitCode & HT_NEEDCAPTURE) { SetCapture ((HWND)pUnderPointer); pCapturedWin = pWin; pCaptured = pUnderPointer; } else pCaptured = NULL; PostMessage ((HWND)pUnderPointer, message + MSG_NCMOUSEOFF, UndHitCode, MAKELONG (x, y)); } else { PostMessage((HWND)pUnderPointer, message, flags, MAKELONG(cx, cy)); pCaptured = NULL; } } else { if (pWin->hActiveChild) { PostMessage(pWin->hActiveChild, message + MSG_NCMOUSEOFF, HT_OUT, MAKELONG(x, y)); } } break; case MSG_LBUTTONUP: case MSG_RBUTTONUP: if (pCaptured) { PostMessage ((HWND)pCaptured, message + MSG_NCMOUSEOFF, CapHitCode, MAKELONG (x, y)); ReleaseCapture (); pCapturedWin = NULL; pCaptured = NULL; } else if (pUnderPointer) { if (pUnderPointer->dwStyle & WS_DISABLED) { break; } if (UndHitCode == HT_CLIENT) PostMessage((HWND)pUnderPointer, message, flags, MAKELONG (cx, cy)); else PostMessage((HWND)pUnderPointer, message + MSG_NCMOUSEOFF, UndHitCode, MAKELONG (x, y)); } else { if (pWin->hActiveChild) { PostMessage(pWin->hActiveChild, message + MSG_NCMOUSEOFF, HT_OUT, MAKELONG(x, y)); } } break; case MSG_LBUTTONDBLCLK: case MSG_RBUTTONDBLCLK: if (pUnderPointer) { if (pUnderPointer->dwStyle & WS_DISABLED) { Ping (); break; } if (UndHitCode == HT_CLIENT) PostMessage((HWND)pUnderPointer, message, flags, MAKELONG(cx, cy)); else PostMessage((HWND)pUnderPointer, message + MSG_NCMOUSEOFF, UndHitCode, MAKELONG (x, y)); } else { if (pWin->hActiveChild) { PostMessage(pWin->hActiveChild, message + MSG_NCMOUSEOFF, HT_OUT, MAKELONG(x, y)); } } break; } return 0;}static inline int wndGetBorder (const MAINWIN* pWin){ if (pWin->dwStyle & WS_BORDER) return GetMainWinMetrics(MWM_BORDER); else if (pWin->dwStyle & WS_THICKFRAME) return GetMainWinMetrics(MWM_THICKFRAME); else if (pWin->dwStyle & WS_THINFRAME) return GetMainWinMetrics (MWM_THINFRAME); return 0;}static BOOL wndGetVScrollBarRect (const MAINWIN* pWin, RECT* rcVBar){ if (pWin->dwStyle & WS_VSCROLL) { int iBorder = wndGetBorder (pWin); rcVBar->left = pWin->right - GetMainWinMetrics (MWM_CXVSCROLL) - iBorder; rcVBar->right = pWin->right - iBorder;#ifdef _FLAT_WINDOW_STYLE rcVBar->top = pWin->ct - 1;#else rcVBar->top = pWin->ct;#endif rcVBar->bottom = pWin->bottom - iBorder; if (pWin->dwStyle & WS_HSCROLL && !(pWin->hscroll.status & SBS_HIDE)) rcVBar->bottom -= GetMainWinMetrics (MWM_CYHSCROLL); #ifdef _FLAT_WINDOW_STYLE if (iBorder > 0) OffsetRect (rcVBar, 1, 0);#endif return TRUE; } return FALSE;}static BOOL wndGetHScrollBarRect (const MAINWIN* pWin, RECT* rcHBar){ if (pWin->dwStyle & WS_HSCROLL) { int iBorder = wndGetBorder (pWin); rcHBar->top = pWin->bottom - GetMainWinMetrics (MWM_CYHSCROLL) - iBorder; rcHBar->bottom = pWin->bottom - iBorder;#ifdef _FLAT_WINDOW_STYLE rcHBar->left = pWin->cl - 1;#else rcHBar->left = pWin->cl;#endif rcHBar->right = pWin->right - iBorder; if (pWin->dwStyle & WS_VSCROLL && !(pWin->vscroll.status & SBS_HIDE)) rcHBar->right -= GetMainWinMetrics (MWM_CXVSCROLL);#ifdef _FLAT_WINDOW_STYLE if (iBorder > 0) OffsetRect (rcHBar, 0, 1);#endif return TRUE; } return FALSE; }static int wndGetHScrollBarPos (PMAINWIN pWin, int x, int y){ RECT rcBar; RECT rcArea; if (pWin->hscroll.status & SBS_DISABLED) return SBPOS_UNKNOWN; wndGetHScrollBarRect (pWin, &rcBar); if (!PtInRect (&rcBar, x, y)) return SBPOS_UNKNOWN; rcArea.top = rcBar.top; rcArea.bottom = rcBar.bottom; // Left arrow area rcArea.left = rcBar.left; rcArea.right = rcArea.left + GetMainWinMetrics (MWM_CXHSCROLL); if (PtInRect (&rcArea, x, y)) return SBPOS_LEFTARROW; // Right arrow area rcArea.left = rcBar.right - GetMainWinMetrics (MWM_CXHSCROLL); rcArea.right = rcBar.right; if (PtInRect (&rcArea, x, y)) return SBPOS_RIGHTARROW; if (x < (rcBar.left + pWin->hscroll.barStart + GetMainWinMetrics (MWM_CXHSCROLL))) return SBPOS_LEFTSPACE; if (x > (rcBar.left + pWin->hscroll.barStart + pWin->hscroll.barLen + GetMainWinMetrics (MWM_CXHSCROLL)))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -