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

📄 window.c

📁 在ADS环境下MiniGUI的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
/* 
** $Id: window.c,v 1.179 2004/10/09 04:50:01 snig 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((HWND)pUnderPointer, message, 
                        flags, MAKELONG(cx, cy));
                    __mgs_captured_ctrl = NULL;
                }
            }
            else if (pWin->hActiveChild) {
                SendNotifyMessage (pWin->hActiveChild, MSG_MOUSEACTIVE, HT_OUT, 0);
                PostMessage (pWin->hActiveChild, message + MSG_NCMOUSEOFF, 
                        HT_OUT, MAKELONG(x, y));
            }
        break;

        case MSG_LBUTTONUP:
        case MSG_RBUTTONUP:
            if (__mgs_captured_ctrl) {
                PostMessage ((HWND)__mgs_captured_ctrl, message + MSG_NCMOUSEOFF,
                        CapHitCode, MAKELONG (x, y));
                ReleaseCapture ();
                __mgs_captured_win = NULL;
                __mgs_captured_ctrl = 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;

        rcVBar->top  = pWin->ct;
        rcVBar->bottom = pWin->bottom - iBorder;

        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) {
        int iBorder = wndGetBorder (pWin);

        rcHBar->top = pWin->bottom - GetMainWinMetrics (MWM_CYHSCROLL)
                        - iBorder;
        rcHBar->bottom = pWin->bottom - iBorder;

        rcHBar->left  = pWin->cl;
        rcHBar->right = pWin->right - iBorder;

        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);

⌨️ 快捷键说明

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