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

📄 window.c

📁 在ADS环境下MiniGUI的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
    int iBorder = 0;
    int iCaptionY = 0;
    int iIconX = 0;
    int iIconY = 0;
    int iMenuY = 0;

    iBorder = wndGetBorder (pWin);

    if( pWin->dwStyle & WS_CAPTION )
    {
        iCaptionY = GetMainWinMetrics(MWM_CAPTIONY);

        if (pWin->WinType == TYPE_MAINWIN && pWin->hIcon) {
            iIconX = GetMainWinMetrics(MWM_ICONX);
            iIconY = GetMainWinMetrics(MWM_ICONY);
        }
    }

    if (pWin->WinType == TYPE_MAINWIN && pWin->hMenu) {
        iMenuY = GetMainWinMetrics (MWM_MENUBARY);
        iMenuY += GetMainWinMetrics (MWM_MENUBAROFFY)<<1;
    }

    if (pDestRect) {
        int minWidth = 0, minHeight = 0;

        memcpy(&pWin->left, pDestRect, sizeof(RECT));

        minHeight = iMenuY + (iCaptionY<<1);
        if (pWin->dwStyle & WS_VSCROLL) {
            minWidth += GetMainWinMetrics (MWM_CXVSCROLL);
            minHeight += (GetMainWinMetrics (MWM_CYVSCROLL)<<1) +
                         (GetMainWinMetrics (MWM_MINBARLEN)<<1);
        }
        
        if (pWin->WinType == TYPE_MAINWIN)
            minWidth += GetMainWinMetrics (MWM_MINWIDTH);

        if (pWin->dwStyle & WS_HSCROLL) {
            minHeight += GetMainWinMetrics (MWM_CYHSCROLL);
            minWidth += (GetMainWinMetrics (MWM_CXHSCROLL)<<1) +
                        (GetMainWinMetrics (MWM_MINBARLEN)<<1);
        }

        if(minHeight > (pWin->bottom - pWin->top))
            pWin->bottom = pWin->top + minHeight;

        if(pWin->right < (pWin->left + minWidth))
            pWin->right = pWin->left + minWidth;

        if( pResultRect )
             memcpy(pResultRect, &pWin->left, sizeof(RECT));
    }

    memcpy(&pWin->cl, &pWin->left, sizeof(RECT));

    pWin->cl += iBorder;
    pWin->ct += iBorder;
    pWin->cr -= iBorder;
    pWin->cb -= iBorder;
    pWin->ct += iCaptionY;
    pWin->ct += iMenuY;
    
    if (pWin->dwStyle & WS_HSCROLL && !(pWin->hscroll.status & SBS_HIDE)) {
    
        RECT rcBar;
        wndGetHScrollBarRect (pWin, &rcBar);
        wndScrollBarPos (pWin, TRUE, &rcBar);

        pWin->cb -= GetMainWinMetrics (MWM_CYHSCROLL);
    }
        
    if (pWin->dwStyle & WS_VSCROLL && !(pWin->vscroll.status & SBS_HIDE)) {
    
        RECT rcBar;
        wndGetVScrollBarRect (pWin, &rcBar);
        wndScrollBarPos (pWin, FALSE, &rcBar);

        pWin->cr -= GetMainWinMetrics (MWM_CXVSCROLL);
    }
}

static void OnQueryNCRect(PMAINWIN pWin, PRECT pRC)
{
    memcpy(pRC, &pWin->left, sizeof(RECT));
}

static void OnQueryClientArea(PMAINWIN pWin, PRECT pRC)
{
    memcpy(pRC, &pWin->cl, sizeof(RECT));
}

int ClientWidthToWindowWidth (DWORD dwStyle, int cw)
{
    int iBorder = 0;
    int iScroll = 0;

    if (dwStyle & WS_BORDER) 
        iBorder = GetMainWinMetrics(MWM_BORDER);
    else if (dwStyle & WS_THICKFRAME)
        iBorder = GetMainWinMetrics(MWM_THICKFRAME);
    else if (dwStyle & WS_THINFRAME)
        iBorder = GetMainWinMetrics (MWM_THINFRAME);

    if (dwStyle & WS_VSCROLL)
        iScroll = GetMainWinMetrics (MWM_CXVSCROLL);
        
    return cw + (iBorder<<1) + iScroll;
}

int ClientHeightToWindowHeight (DWORD dwStyle, int ch, BOOL hasMenu)
{
    int iBorder  = 0;
    int iCaption = 0;
    int iScroll  = 0;
    int iMenu    = 0;

    if (dwStyle & WS_BORDER) 
        iBorder = GetMainWinMetrics(MWM_BORDER);
    else if (dwStyle & WS_THICKFRAME)
        iBorder = GetMainWinMetrics(MWM_THICKFRAME);
    else if (dwStyle & WS_THINFRAME)
        iBorder = GetMainWinMetrics (MWM_THINFRAME);

    if (dwStyle & WS_HSCROLL)
        iScroll = GetMainWinMetrics (MWM_CYHSCROLL);
        
    if (dwStyle & WS_CAPTION)
        iCaption = GetMainWinMetrics(MWM_CAPTIONY);

    if (hasMenu) {
        iMenu = GetMainWinMetrics (MWM_MENUBARY);
        iMenu += GetMainWinMetrics (MWM_MENUBAROFFY)<<1;
    }
    
    return ch + (iBorder<<1) + iCaption + iScroll + iMenu;
}

// this function is CONTROL safe.
static int HittestOnNClient (PMAINWIN pWin, int x, int y)
{
    RECT rcCaption, rcIcon, rcButton, rcMenuBar;
    int iBorder = wndGetBorder (pWin);
    int iCaption = 0;
    int iIconX = 0;
    int iIconY = 0;

    if (pWin->dwStyle & WS_HSCROLL && !(pWin->hscroll.status & SBS_HIDE)) {
    
        RECT rcBar;
        wndGetHScrollBarRect (pWin, &rcBar);

        if (PtInRect (&rcBar, x, y))
            return HT_HSCROLL;
    }
        
    if (pWin->dwStyle & WS_VSCROLL && !(pWin->vscroll.status & SBS_HIDE)) {
    
        RECT rcBar;
        wndGetVScrollBarRect (pWin, &rcBar);

        if (PtInRect (&rcBar, x, y)) {
            return HT_VSCROLL;
        }
    }
    
    if (pWin->dwStyle & WS_CAPTION) {
        iCaption = GetMainWinMetrics(MWM_CAPTIONY);

        if (pWin->WinType == TYPE_MAINWIN && pWin->hIcon) {
            iIconX = GetMainWinMetrics(MWM_ICONX);
            iIconY = GetMainWinMetrics(MWM_ICONY);
        }

        // Caption rect;
        rcCaption.left = pWin->left + iBorder;
        rcCaption.top = pWin->top + iBorder;
        rcCaption.right = pWin->right - iBorder;
        rcCaption.bottom = rcCaption.top + iCaption;
                        
        if (pWin->WinType == TYPE_MAINWIN && pWin->hIcon)
        { 
            rcIcon.left = rcCaption.left;
            rcIcon.top = rcCaption.top;
            rcIcon.right = rcIcon.left + iIconX;
            rcIcon.bottom = rcIcon.top + iIconY;
    
            if (PtInRect (&rcIcon, x, y))
                return HT_ICON;
        }
    
        rcButton.left = rcCaption.right - GetMainWinMetrics (MWM_SB_WIDTH);
        rcButton.top = rcCaption.top;
        rcButton.right = rcCaption.right;
        rcButton.bottom = rcCaption.top + GetMainWinMetrics (MWM_SB_HEIGHT);

        if (!(pWin->dwExStyle & WS_EX_NOCLOSEBOX)) {
            if (PtInRect (&rcButton, x, y))
                return HT_CLOSEBUTTON;

            rcButton.left -= GetMainWinMetrics (MWM_SB_WIDTH);
            rcButton.left -= GetMainWinMetrics (MWM_SB_INTERX)<<1;
        }
    
        if (pWin->dwStyle & WS_MAXIMIZEBOX) {
            rcButton.right = rcButton.left + GetMainWinMetrics (MWM_SB_WIDTH);
            if (PtInRect (&rcButton, x, y))
                return HT_MAXBUTTON;
    
            rcButton.left -= GetMainWinMetrics (MWM_SB_WIDTH);
            rcButton.left -= GetMainWinMetrics (MWM_SB_INTERX);
        }
    
        if (pWin->dwStyle & WS_MINIMIZEBOX) {
            rcButton.right = rcButton.left + GetMainWinMetrics (MWM_SB_WIDTH);
            if (PtInRect (&rcButton, x, y))
                return HT_MINBUTTON;
        }
    
        if (pWin->WinType == TYPE_MAINWIN && pWin->hMenu) {
            rcMenuBar.left = rcCaption.left;
            rcMenuBar.top = rcCaption.bottom + 1;
            rcMenuBar.right = rcCaption.right;
            rcMenuBar.bottom = rcMenuBar.top + GetMainWinMetrics (MWM_MENUBARY);
            rcMenuBar.bottom += GetMainWinMetrics (MWM_MENUBAROFFY)<<1;
                    
            if (PtInRect (&rcMenuBar, x, y))
                return HT_MENUBAR;
        }

        if (PtInRect (&rcCaption, x, y))
            return HT_CAPTION;
    }
    else {
        // Caption rect;
        rcCaption.left = pWin->left + iBorder;
        rcCaption.top = pWin->top + iBorder;
        rcCaption.right = pWin->right - iBorder;
        rcCaption.bottom = rcCaption.top;

        if (pWin->WinType == TYPE_MAINWIN && pWin->hMenu) {
            rcMenuBar.left = rcCaption.left;
            rcMenuBar.top = rcCaption.bottom + 1;
            rcMenuBar.right = rcCaption.right;
            rcMenuBar.bottom = rcMenuBar.top + GetMainWinMetrics (MWM_MENUBARY);
            rcMenuBar.bottom += GetMainWinMetrics (MWM_MENUBAROFFY)<<1;
                    
            if (PtInRect (&rcMenuBar, x, y))
                return HT_MENUBAR;
        }
    }

    return HT_BORDER;
}

extern HWND __mg_ime_wnd;
static void open_ime_window (PMAINWIN pWin, BOOL open_close, HWND rev_hwnd)
{
#ifndef _LITE_VERSION
    if (__mg_ime_wnd && pWin) {
        BOOL is_edit = SendAsyncMessage ((HWND)pWin, MSG_DOESNEEDIME, 0, 0L);

        if (pWin->pMainWin && ((pWin->pMainWin->dwExStyle & WS_EX_TOOLWINDOW)
                           || ((HWND)(pWin->pMainWin) == __mg_ime_wnd)))
            return;

        //if (open_close) {
            if (is_edit)
                SendNotifyMessage (__mg_ime_wnd, MSG_IME_OPEN, 0, 0);
            else
                SendNotifyMessage (__mg_ime_wnd, MSG_IME_CLOSE, 0, 0);
/*
        }
        else if (!open_close) {
            BOOL other_is_edit 
                = rev_hwnd && SendAsyncMessage (rev_hwnd, MSG_DOESNEEDIME, 0, 0L);
            if (!other_is_edit)
                SendNotifyMessage (__mg_ime_wnd, MSG_IME_CLOSE, 0, 0);
        }
*/
    }
#elif !defined(_STAND_ALONE)
    if (!mgIsServer && pWin) {
        BOOL is_edit = SendAsyncMessage ((HWND)pWin, MSG_DOESNEEDIME, 0, 0L);
        REQUEST req;
        BOOL open = FALSE;

        if (pWin->pMainWin && (pWin->pMainWin->dwExStyle & WS_EX_TOOLWINDOW))
            return;

        req.id = REQID_OPENIMEWND;
        req.data = &open;
        req.len_data = sizeof (BOOL);
        if (open_close) {
            if (is_edit)
                open = TRUE;
            cli_request (&req, NULL, 0);
        }
        else if (!open_close && is_edit) {
            BOOL other_is_edit 
                = rev_hwnd && SendAsyncMessage (rev_hwnd, MSG_DOESNEEDIME, 0, 0L);
            if (!other_is_edit) {
                cli_request (&req, NULL, 0);
            }
        }
    }
#endif
}

static int DefaultPostMsgHandler(PMAINWIN pWin, int message,
                           WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
        case MSG_SETCURSOR:
//
// NOTE:
// this message is only implemented for main window.
// for CONTROL, must handle this message and should NOT 
// call default window procedure
// when handle MSG_SETCURSOR.
//
            if (wndMouseInWhichControl (pWin, LOSWORD(lParam), HISWORD(lParam), 
                    NULL))
                break;

            if (pWin->hCursor)
                SetCursor(pWin->hCursor);
        break;

        case MSG_NCSETCURSOR:
//
// NOTE:
// this message is only implemented for main window.
// for CONTROL, must handle this message and should NOT 
// call default window procedure
// when handle MSG_SETCURSOR.
//
            SetCursor (GetSystemCursor (IDC_ARROW));
        break;
        
        case MSG_HITTEST:
            if (PtInRect((PRECT)(&(pWin->cl)), (int)wParam, (int)lParam) )
                return HT_CLIENT;
            else
                return HittestOnNClient (pWin, 
                            (int)wParam, (int)lParam);
        break;

        case MSG_CHANGESIZE:
            OnChangeSize (pWin, (PRECT)wParam, (PRECT)lParam);
            RecalcClientArea ((HWND)pWin);
        break;

        case MSG_SIZECHANGING:
            memcpy ((PRECT)lParam, (PRECT)wParam, sizeof (RECT));
        break;
        
        case MSG_QUERYNCRECT:
            OnQueryNCRect(pWin, (PRECT)lParam);
        break;

        case MSG_QUERYCLIENTAREA:
            OnQueryClientArea(pWin, (PRECT)lParam);
        break;

        case MSG_SETFOCUS:
        case MSG_KILLFOCUS:
            if (pWin->hActiveChild)
                SendNotifyMessage (pWin->hActiveChild, message, 0, lParam);
            if (!pWin->hActiveChild && lParam == 0) {
                open_ime_window (pWin, message == MSG_SETFOCUS, (HWND)wParam);
            }
        break;
        
        case MSG_MOUSEACTIVE:
            if (pWin->WinType == TYPE_CONTROL 
                    && !(pWin->dwStyle & WS_DISABLED)) {

                if (wParam != HT_OUT) {
                    PCONTROL pCtrl = (PCONTROL)pWin;
                    PCONTROL old_active = pCtrl->pParent->active;
               
                    if (old_active != (PCONTROL)pWin) {
                        if (old_active) {
                            SendNotifyMessage ((HWND)old_active, MSG_ACTIVE, FALSE, wParam);
                            SendNotifyMessage ((HWND)old_active, MSG_KILLFOCUS, (WPARAM)pWin, 1);
                        }

                        pCtrl->pParent->active = (PCONTROL)pWin;

                        SendNotifyMessage ((HWND)pWin, MSG_ACTIVE, TRUE, 0);
                        SendNotifyMessage ((HWND)pWin, MSG_SETFOCUS, (WPARAM)old_active, 1);
                    }

                    if (!pWin->hActiveChild && wParam == HT_CLIENT) {
                        open_ime_window (pWin, TRUE, HWND_DESKTOP);
                    }
                    else {
                        open_ime_window (pWin, FALSE, HWND_DESKTOP);

⌨️ 快捷键说明

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