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

📄 window.c

📁 rtCell 实时微内核-具有下列功能: 1. 完全抢占的实时微内核结构
💻 C
📖 第 1 页 / 共 3 页
字号:

    if (flag & 1) {
        if (GetRectXSize(&(pWin->pHScrolbar->pView->viewRect)) >= BOX_H)
            if (GetRectYSize(&(pWin->pVScrolbar->pView->viewRect)) >= BOX_H) {
                if (IsViewVisible(pWin->pVScrolbar->pView) == false) 
                    ShowView(pWin->pVScrolbar->pView);
                goto set_hscroll_bar;
            }
    }      
    HideView(pWin->pVScrolbar->pView);
    
set_hscroll_bar:
    if (flag & 2) {
        if (GetRectYSize(&(pWin->pVScrolbar->pView->viewRect)) >= BOX_H) {
            if (IsViewVisible(pWin->pHScrolbar->pView) == false) 
                ShowView(pWin->pHScrolbar->pView);
            return;
        }
    }
    HideView(pWin->pHScrolbar->pView);
}

static void ScrollParentWin(WINDOW* pWin)
{
    WINDOW* pParent = GetParentWin(pWin->pMainView);
    
    if (pParent != NULL) {
        VMSG msg;
        RECT r;
        
        MergeAllChildViewsRect(pParent->pClientView, &r);
        if (pParent->MaxRect.left != r.left ||
            pParent->MaxRect.right != r.right ||
            pParent->MaxRect.top != r.top ||
            pParent->MaxRect.bottom != r.bottom) {
            pParent->MaxRect = r;
            msg.MsgID = WINM_SCROLL;
            InformView(pParent->pMainView, &msg);
        }
    }
}

static void SetWindowOffset(WINDOW* pWin, int dx, int dy, int dxSize, int dySize)
{
    VIEW *pView = pWin->pMainView;
    int   x, y;

    if ((pWin->pMainView->wdStatus & (VS_MOVABLE|VS_RESIZABLE)) == 0) return;
    x = (pView->viewRect.right - pView->viewRect.left + 1 + dxSize);
    y = (pView->viewRect.bottom - pView->viewRect.top + 1 + dySize);
    if (x <= FORM_MIN_XSIZE) dxSize += (FORM_MIN_XSIZE-x);
    if (y <= FORM_MIN_YSIZE) dySize += (FORM_MIN_YSIZE-y);

    SetViewVisible(pWin->pClientView, false);
    ResizeView(pWin->pClientView, dxSize, dySize);
    SetViewVisible(pWin->pClientView, true);
    SetViewRectOffset(pWin->pMainView, dx, dy, dxSize, dySize);    
    x = pView->viewRect.right+1-SYSBTN_YOFF-SYSBTN_WIDTH;
    y = pView->viewRect.top+SYSBTN_YOFF;
    if (pWin->pCloseBtn != NULL) {
        MoveViewTo(pWin->pCloseBtn->pView, x, y);
        x -= (SYSBTN_XOFF+SYSBTN_WIDTH);
    }
    if (pWin->pMaxBtn != NULL) {
        MoveViewTo(pWin->pMaxBtn->pView, x, y);
        x -= SYSBTN_WIDTH;
    }
    if (pWin->pMinBtn != NULL) {
        MoveViewTo(pWin->pMinBtn->pView, x, y);
    }
    
    if (IsValidRect(&(pWin->pClientView->viewRect)) == false)
        HideView(pWin->pClientView);
        
    SetWinScrollBar(pWin);
    ScrollParentWin(pWin);
    if (GetRectYSize(&(pWin->pVScrolbar->pView->viewRect)) < BOX_H)
        HideView(pWin->pHScrolbar->pView);
    if (GetRectXSize(&(pWin->pHScrolbar->pView->viewRect)) < BOX_H)
        HideView(pWin->pVScrolbar->pView);
}

void SetWindow(WINDOW* pWin, int left, int top, int xSize, int ySize)
{
    if (xSize < FORM_MIN_XSIZE) xSize = FORM_MIN_XSIZE;
    if (ySize < FORM_MIN_YSIZE) ySize = FORM_MIN_YSIZE;
    left -= pWin->pMainView->viewRect.left;
    top  -= pWin->pMainView->viewRect.top;
    xSize -= (pWin->pMainView->viewRect.right - pWin->pMainView->viewRect.left + 1);
    ySize -= (pWin->pMainView->viewRect.bottom - pWin->pMainView->viewRect.top + 1);
    SetWindowOffset(pWin, left, top, xSize, ySize);
}

static void MoveWindow(WINDOW* pWin, const int dx, const int dy)
{
    SetWindowOffset(pWin, dx, dy, 0, 0);
}

void MoveWindowTo(WINDOW* pWin, int x, int y)
{
    x -= pWin->pMainView->viewRect.left;
    y -= pWin->pMainView->viewRect.top;
    MoveWindow(pWin, x, y);
}

static void ResizeWindow(WINDOW* pWin, const int dx, const int dy)
{
    SetWindowOffset(pWin, 0, 0, dx, dy);
}

void SetWindowSize(WINDOW* pWin, const int xs, const int ys)
{
    int dx, dy;

    dx = (pWin->pMainView->viewRect.left-pWin->pMainView->viewRect.right+xs-1);
    dy = (pWin->pMainView->viewRect.top-pWin->pMainView->viewRect.bottom+ys-1);
    ResizeWindow(pWin, dx, dy);
}

static void MainViewPaint(VIEW *pView)
{
    WINDOW* pWin;
    COLOR   clr;
    RECT    r;

    pWin = OBJ_FROM_VIEW(pView);
    /* 3D border of the client rect */
    r = pView->viewRect;
    r.left += (WIN_BORDER+2);
    r.right -= (WIN_BORDER+2);
    r.top += (WIN_BORDER+BAR_HEIGHT+2);
    r.bottom -= (WIN_BORDER+2);
    if (pWin->Status & WIN_CLIENT_RECT) { 
        r.top ++;
        if (IsValidRect(&r) == true)
            DrawDownRect(&r);

    } else if ((pView->wdStatus & VS_HASTRANS) == 0) { 
        DrawRect(&r, pWin->ClientColor);
        r.left ++; r.right --; r.bottom --;
        DrawRect(&r, pWin->ClientColor);
    }

    /* between inside and outside border */ 
    if ((pView->wdStatus & VS_HASTRANS) == 0) {
        r = pView->viewRect;
        r.left += WIN_BORDER;
        r.right -= WIN_BORDER;
        r.top += WIN_BORDER;
        r.bottom -= WIN_BORDER;
        DrawRect(&r, pWin->ClientColor);
        r.left ++; r.right --; r.top ++; r.bottom --;
        DrawRect(&r, pWin->ClientColor);  
    }
    
    if (pWin->Status & WIN_MOUSE_ENTER) clr = MouseEnterColor;
    else if (pWin->Status & WIN_FOCUSSED) clr = pWin->BarColor[ACTIVE_CLR];
    else clr = pWin->BarColor[INACTIVE_CLR];
    
    r.left = pView->viewRect.left+BAR_XOFF; r.top = pView->viewRect.top+BAR_YOFF;
    r.right = pView->viewRect.right-BAR_XOFF; r.bottom = r.top+BAR_HEIGHT-1;
    /* title bar of the window    */
    if ((pView->wdStatus & VS_HASTRANS) == 0) { 
        FillRect(&r, clr);
        DrawHLine(pView->viewRect.top+(BAR_YOFF+BAR_HEIGHT),
                    pView->viewRect.left+WIN_BORDER,
                    pView->viewRect.right-WIN_BORDER, pWin->ClientColor);
    } else {
        DrawRect(&r, clr);
    }

    if (pWin->pCloseBtn != NULL) r.right -= (SYSBTN_YOFF+SYSBTN_WIDTH+2);
    if (pWin->pMaxBtn != NULL) r.right -= (SYSBTN_WIDTH);
    if (pWin->pMinBtn != NULL) r.right -= (SYSBTN_WIDTH);
    if (SetPartClipRect(&r) == true) {
        /* view system ico and caption of the window */
        DrawMatrix(pView->viewRect.left+VIEWSYS_XOFF, pView->viewRect.top+VIEWSYS_YOFF+1,
                     16, 14, viewSYS, GD_YELLOW);
        DrawText(pView->viewRect.left+CAPTION_XOFF,
                   pView->viewRect.top+CAPTION_YOFF,
                   pWin->pCaption, pWin->CaptionColor);
        RestoreClipRect(&r);
    }
    /* 3D border of the window rect */
    DrawUpRect(&(pView->viewRect));
}

void InformView(VIEW *pView, const VMSG *pMsg)
{
    VMSG msg = (*pMsg);

    msg.pView = pView;
    SendViewMsg(pView, &msg);
}

void * GetParentWin(VIEW *pView)
{
    VIEW *pForm = pView;

    if (pForm == NULL) return (NULL);
    if (IsFormView(pForm) == true) {
        if (pForm->pParent == NULL) return (NULL);
        pForm = pForm->pParent;
    }

    pForm = ((VIEW *)(GetFormView(pForm)));
    
    if (pForm != NULL) {
        return (WIN_FROM_MAINVIEW(pForm));
    }
    
    return (NULL);
}

void SetFocussedView(VIEW *pView)
{
    WINDOW *pWin = GetParentWin(pView);
    
    if (pWin != NULL) {  
        if ((pView != pWin->pClientView) &&
            (pView != pWin->pMainView) &&
            (pView != pWin->pFocussedView)) {
            VMSG msg;
            if (pWin->pFocussedView != NULL) {
                msg.pView = pWin->pFocussedView;
                msg.MsgID = VMSG_LOSTFOCUS;
                SendViewMsg(pWin->pFocussedView, &msg);
            }
            pWin->pFocussedView = pView; 
        }
    }
}

static void DoResizeWindow(WINDOW* pWin, POINT *pPT, int dx, int dy)
{
    CWORD Status = (pWin->Status & WIN_SIZE);
    
    pWin->ptCatch.x = pPT->x; pWin->ptCatch.y = pPT->y;
    if (Status & WIN_SIZE_LEFT) {
        if (pPT->x > (pWin->pMainView->viewRect.right-FORM_MIN_XSIZE)) {
            pWin->ptCatch.x = pWin->pMainView->viewRect.right-FORM_MIN_XSIZE;
            dx = pWin->pMainView->viewRect.right-FORM_MIN_XSIZE-pWin->pMainView->viewRect.left+1;
        }
    } else if (Status & WIN_SIZE_RIGHT) {
        if (pPT->x < (pWin->pMainView->viewRect.left+FORM_MIN_XSIZE))
            pWin->ptCatch.x = (pWin->pMainView->viewRect.left+FORM_MIN_XSIZE);
    }

    if (Status & WIN_SIZE_TOP) {
        if (pPT->y >= (pWin->pMainView->viewRect.bottom-FORM_MIN_YSIZE)) {
            pWin->ptCatch.y = pWin->pMainView->viewRect.bottom-FORM_MIN_YSIZE;
            dy = pWin->pMainView->viewRect.bottom-FORM_MIN_YSIZE-pWin->pMainView->viewRect.top+1;
        }
    } else if (Status & WIN_SIZE_BOTTOM) {
        if (pPT->y < (pWin->pMainView->viewRect.top+FORM_MIN_YSIZE))
            pWin->ptCatch.y = (pWin->pMainView->viewRect.top+FORM_MIN_YSIZE);
    }     

    if (Status == (WIN_SIZE_LEFT|WIN_SIZE_TOP)) {
        SetWindowOffset(pWin, dx, dy, -dx, -dy);
    } else if (Status == (WIN_SIZE_RIGHT|WIN_SIZE_BOTTOM)) {
        ResizeWindow(pWin, dx, dy);
    } else if (Status == (WIN_SIZE_LEFT|WIN_SIZE_BOTTOM)) {
        SetWindowOffset(pWin, dx, 0, -dx, dy);
    } else if (Status == (WIN_SIZE_RIGHT|WIN_SIZE_TOP)) {
        SetWindowOffset(pWin, 0, dy, dx, -dy);
    } else if (Status == WIN_SIZE_LEFT) {
        SetWindowOffset(pWin, dx, 0, -dx, 0);
    } else if (Status == WIN_SIZE_TOP) {
        SetWindowOffset(pWin, 0, dy, 0, -dy);
    } else if (Status == WIN_SIZE_RIGHT) {
        ResizeWindow(pWin, dx, 0);
    } else if (Status == WIN_SIZE_BOTTOM) {
        ResizeWindow(pWin, 0, dy);
    }
}

static CBOOL _cdecl_ MainViewProc(VMSG *pMsg)
{  
    WINDOW* pWin;
    RECT l, r, t, b, v;

    pWin = OBJ_FROM_VIEW(pMsg->pView);
    r.left = pMsg->pView->viewRect.left+BAR_XOFF;
    r.top = pMsg->pView->viewRect.top+BAR_YOFF;
    r.right = pMsg->pView->viewRect.right-BAR_XOFF;
    r.bottom = r.top+BAR_HEIGHT-1;
    
    switch (pMsg->MsgID) {
    case WINM_SCROLL:
        SetWinScrollBar(pWin);
        return (true);
    case TIMERM_OUT:
    case KEYM_KEY_DOWN:
        InformView(pWin->pClientView, pMsg);
        return (true);
    case VMSG_PAINT:
        MainViewPaint(pMsg->pView);
        return (true);
    case VMSG_GETFOCUS:

⌨️ 快捷键说明

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