⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 window.c

📁 在ecos 下mingui 的移植开发
💻 C
📖 第 1 页 / 共 5 页
字号:
// $Id: window.c,v 1.34 2000/11/24 09:19:23 ymwei Exp $//// window.c: The Window module.//// Copyright (c) 1999, Wei Yongming.//// Current maintainer: Wei Yongming./***  This library is free software; you can redistribute it and/or**  modify it under the terms of the GNU Library General Public**  License as published by the Free Software Foundation; either**  version 2 of the License, or (at your option) any later version.****  This library 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**  Library General Public License for more details.****  You should have received a copy of the GNU Library General Public**  License along with this library; if not, write to the Free**  Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,**  MA 02111-1307, USA*/// Create date: 1999.04.19//// Modify records:////  Who             When        Where       For What                Status//-----------------------------------------------------------------------------//  WEI Yongming    1999/6/21   Tsinghua    Main window hosting     Finished//  WEI Yongming    1999/6/26   Tsinghua    Main window scroll bar  Finished//  WEI Yongming    1999/6/27   Tsinghua    Control scroll bar      Finished//  WEI Yongming    1999/9/11   Tsinghua    Disable style           Finished//// TODO:// #include <stdlib.h>#include <string.h>#include <pthread.h>#include <semaphore.h>#include "common.h"#include "minigui.h"#include "gdi.h"#include "window.h"#include "cliprect.h"#include "gal.h"#include "internals.h"#include "menu.h"#include "ctrlclass.h"#ifndef lintstatic char fileid[] = "$Id: window.c,v 1.34 2000/11/24 09:19:23 ymwei Exp $";#endif// function defined in menu module.void DrawMenuBarHelper (const MAINWIN *pWin, HDC hdc, const RECT* pClipRect);// function definde 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};inline static void SetRepeatMessage (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 PCONTROL wndMouseInWhichControl (PMAINWIN pWin, int x, int y,                         int* UndHitCode){    PCONTROL pCtrl;    int hitcode;       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 functio as a 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.        x = x - pCapturedWin->cl;        y = y - pCapturedWin->ct;        CapHitCode = SendAsyncMessage((HWND)pCaptured, MSG_HITTEST,                                        (WPARAM)x, (LPARAM)y);                pUnderPointer = NULL;    }    else {        pUnderPointer = wndMouseInWhichControl (pWin, x, y, &UndHitCode);        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) {        rcVBar->left = pWin->right - GetMainWinMetrics (MWM_CXVSCROLL)                         - wndGetBorder (pWin);        rcVBar->right = pWin->right - wndGetBorder (pWin);        rcVBar->top  = pWin->ct;        rcVBar->bottom = pWin->bottom - wndGetBorder (pWin);        if (pWin->dwStyle & WS_HSCROLL && !(pWin->hscroll.status & SBS_HIDE))            rcVBar->bottom -= GetMainWinMetrics (MWM_CYHSCROLL);                return TRUE;    }        return FALSE;}static BOOL wndGetHScrollBarRect (const MAINWIN* pWin,                 RECT* rcHBar){    if (pWin->dwStyle & WS_HSCROLL) {        rcHBar->top = pWin->bottom - GetMainWinMetrics (MWM_CYHSCROLL)                        - wndGetBorder (pWin);        rcHBar->bottom = pWin->bottom - wndGetBorder (pWin);        rcHBar->left  = pWin->cl;        rcHBar->right = pWin->right - wndGetBorder (pWin);        if (pWin->dwStyle & WS_VSCROLL && !(pWin->vscroll.status & SBS_HIDE))            rcHBar->right -= GetMainWinMetrics (MWM_CXVSCROLL);        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)))        return SBPOS_RIGHTSPACE;    return SBPOS_THUMB;}static int wndGetVScrollBarPos (PMAINWIN pWin, int x, int y){    RECT rcBar;    RECT rcArea;    if (pWin->vscroll.status & SBS_DISABLED)        return SBPOS_UNKNOWN;    wndGetVScrollBarRect (pWin, &rcBar);    if (!PtInRect (&rcBar, x, y))        return SBPOS_UNKNOWN;    rcArea.left  = rcBar.left;    rcArea.right = rcBar.right;    // Left arrow area    rcArea.top = rcBar.top;    rcArea.bottom = rcArea.top + GetMainWinMetrics (MWM_CYVSCROLL);    if (PtInRect (&rcArea, x, y))        return SBPOS_UPARROW;    // Right arrow area    rcArea.top = rcBar.bottom - GetMainWinMetrics (MWM_CYVSCROLL);    rcArea.bottom = rcBar.bottom;    if (PtInRect (&rcArea, x, y))        return SBPOS_DOWNARROW;    if (y < (rcBar.top + pWin->vscroll.barStart            + GetMainWinMetrics (MWM_CYVSCROLL)))        return SBPOS_UPSPACE;    if (y > (rcBar.top + pWin->vscroll.barStart + pWin->vscroll.barLen            + GetMainWinMetrics (MWM_CYVSCROLL)))        return SBPOS_DOWNSPACE;    return SBPOS_THUMB;}static BOOL sbGetSBarArrowPos (PMAINWIN pWin, int location,                             int* x, int* y, int* w, int* h){    RECT rcBar;    if (location < SBPOS_UPARROW)         wndGetHScrollBarRect (pWin, &rcBar);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -