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

📄 window.c

📁 rtCell 实时微内核-具有下列功能: 1. 完全抢占的实时微内核结构
💻 C
📖 第 1 页 / 共 3 页
字号:
/*
 *******************************************************************************
 *                      The real-time kernel "rtCell"                          *
 *              Copyright 2005 taowentao, allrights reserved.                  *
 * File : Window.c                                                             *
 * By   : taowentao     2006-09-02  2007-05-20                                 *
 *******************************************************************************
 */

#if !defined(WINDOW_H)
#include "giCell\Wins\include\Window.h"
#endif  

/*
 *******************************************************************************
 *                                                                             *
 *******************************************************************************
 */

#define PAGE             (16) 
#define ACTIVE_BAR_CLR   (WindowBarColor[0])
#define INACTIVE_BAR_CLR (WindowBarColor[1])
#define ACTIVE_CLR       (0)
#define INACTIVE_CLR     (1)
#define WIN_BORDER       (2)
#define BAR_XOFF         (4)
#define BAR_YOFF         (4)

#define BAR_HEIGHT       (18)
#define VIEWSYS_XOFF     (BAR_XOFF + 3)
#define VIEWSYS_YOFF     (BAR_YOFF + 1)
#define CAPTION_XOFF     (BAR_XOFF + 22)
#define CAPTION_YOFF     (BAR_YOFF + 1)     
#define SYSBTN_WIDTH     (16)
#define SYSBTN_HEIGHT    (14)
#define BTN_DOWN         (0)
#define BTN_UP           (-1)

#define CLIENT_XOFF      (BAR_XOFF + 2)
#define CLIENT_YOFF      (BAR_YOFF + BAR_HEIGHT + 1)
#define WIN_MAX_XSIZE    (GetWidth()+(BAR_XOFF<<1))
#define WIN_MAX_YSIZE    (GetHeight()+(BAR_YOFF<<1))

#define SYSBTN_YOFF      (6)
#define SYSBTN_XOFF      (2) 

static const COLOR WindowBarColor[2] = {GD_LIGHTBLUE, GD_DARKGRAY};
static const COLOR ClientColor = GD_GRAY;
static const COLOR CaptionColor = GD_WHITE;
static const COLOR MouseEnterColor = GD_LIGHTRED;

static const BYTE  sysMin[4] = {0x07, 0xE0, 0x07, 0xE0};
static const BYTE  sysMax[18] = {0x0F, 0xF8, 0x0F, 0xF8, 0x08, 0x08,
                                 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
                                 0x08, 0x08, 0x08, 0x08, 0x0F, 0xF8
                                };
static const BYTE  sysNormal[18] = {0x03, 0xF0, 0x03, 0xF0, 0x02, 0x10,
                                    0x0F, 0xD0, 0x0F, 0xD0, 0x08, 0x70,
                                    0x08, 0x40, 0x08, 0x40, 0x0F, 0xC0
                                   };
static const BYTE  sysClose[14] = {0x06, 0x18, 0x03, 0x30, 0x01, 0xE0, 0x00,
                                   0xC0, 0x01, 0xE0, 0x03, 0x30, 0x06, 0x18
                                  };

static const BYTE  viewSYS[28] = {0xFF, 0x1F, 0x3C, 0x06, 0x1C, 0x04, 0x1C,
                                  0x0C, 0x0E, 0x08, 0x0E, 0x18, 0x07, 0x10,
                                  0x07, 0x30, 0x03, 0xA0, 0x03, 0xE0, 0x01,
                                  0xC0, 0x01, 0xC0, 0x00, 0x80, 0x00, 0x80
                                 };

/*
 *******************************************************************************
 *                                                                             *
 *******************************************************************************
 */

static void SysBtnViewPaint(VIEW *pView)
{
    SYSBTN* pBtn;
    WINDOW* pWin;
    int     Off;
    COLOR   clr;
    RECT    r;

    pBtn = OBJ_FROM_VIEW(pView);
    pWin = OBJ_FROM_VIEW(pView->pParent);
    r = pView->viewRect;
    FillRect(&r, pBtn->BottonColor);
    
    if ((pBtn->Status & SYSBTN_MOUSE_CATCH) &&
        (pBtn->Status & SYSBTN_MOUSE_ENTER)) {
        DrawDownBotton(&r);
        Off = BTN_DOWN;
    } else {
        DrawUpBotton(&r);
        Off = BTN_UP;
    }

    if (pBtn->Status & SYSBTN_MOUSE_ENTER) clr = MouseEnterColor;
    else clr = GD_BLACK;

    if (pBtn->Status & SYSBTN_MIN_BTN) {
        if (pWin->Status & WIN_MIN_SIZE)
            DrawMatrix(r.left+Off, r.top+Off+3, 16, 9, sysNormal, clr);
        else
            DrawMatrix(r.left+Off, r.top+Off+10, 16, 2, sysMin, clr);
    } else if (pBtn->Status & SYSBTN_MAX_BTN) {
        if (pWin->Status & WIN_MAX_SIZE)
            DrawMatrix(r.left+Off, r.top+Off+3, 16, 9, sysNormal, clr);
        else
            DrawMatrix(r.left+Off, r.top+Off+1+2, 16, 9, sysMax, clr);
    } else if (pBtn->Status & SYSBTN_CLOSE_BTN) {
        DrawMatrix(r.left+Off, r.top+Off+1+3, 16, 7, sysClose, clr);
    }
}

static void ResizeWindow(WINDOW* pWin, const int dx, const int dy);
void SetWindow(WINDOW* pWin, int left, int top, int xSize, int ySize);
static void SetWindowSize(WINDOW* pWin, const int xs, const int ys);
static void SetWinScrollBar(WINDOW* pWin);
static void MoveWindow(WINDOW* pWin, const int dx, const int dy);

static CBOOL _cdecl_ SysBtnViewProc(VMSG *pMsg)
{  
    SYSBTN *pBtn = OBJ_FROM_VIEW(pMsg->pView);
    WINDOW *pWin = OBJ_FROM_VIEW(pMsg->pView->pParent);
    int x, y;
    
    switch (pMsg->MsgID) {
    case VMSG_PAINT:
        SysBtnViewPaint(pMsg->pView);
        return (true);
    case TIMERM_OUT:
    case KEYM_KEY_DOWN:
        InformView(pWin->pMainView, pMsg);
        return (true);
    case VMSG_GETFOCUS:
        pBtn->Status |= (SYSBTN_FOCUSSED);
        UpdateView(pMsg->pView);
        return (true);
    case VMSG_LOSTFOCUS:
        pBtn->Status &= ~(SYSBTN_FOCUSSED|SYSBTN_MOUSE_CATCH);
        UpdateView(pMsg->pView);
        return (true);
    case MSM_MS_ENTER:  
        SetMouseCursor(ARROW);
        pBtn->Status |= SYSBTN_MOUSE_ENTER;
        UpdateView(pMsg->pView);
        return (true);
    case MSM_MS_LEAVE:
        pBtn->Status &= ~(SYSBTN_MOUSE_ENTER);
        UpdateView(pMsg->pView);
        return (true);
    case MSM_LB_DOWN:
        if (pBtn->Status & SYSBTN_FOCUSSED) {
            pBtn->Status |= (SYSBTN_MOUSE_CATCH|SYSBTN_MOUSE_ENTER);
            UpdateView(pMsg->pView);
        }
        return (true);
    case MSM_LB_UP:
        if ((pBtn->Status & SYSBTN_MOUSE_CATCH) == 0) return (true);
        pBtn->Status &= ~(SYSBTN_MOUSE_CATCH);
        if ((pBtn->Status & SYSBTN_FOCUSSED) &&
            (pBtn->Status & SYSBTN_MOUSE_ENTER)) {
            pBtn->Status &= ~(SYSBTN_MOUSE_ENTER);           
            if (pBtn->Status & SYSBTN_CLOSE_BTN) { /* close botton */
                HideView(pWin->pMainView);
                return (true);  
            } else if (pBtn->Status & SYSBTN_MIN_BTN) {/* min botton */
                if (pWin->Status & WIN_MIN_SIZE) {
                    pWin->Status &= ~WIN_MIN_SIZE;
                    goto _set_normal_size_win;
                } else {
                    if (pWin->Status & WIN_MAX_SIZE)
                        pWin->Status &= ~WIN_MAX_SIZE;
                    pWin->Status |= WIN_MIN_SIZE;
                    x = pWin->pMainView->viewRect.left;
                    y = pWin->pMainView->viewRect.top;
                    if (x < 0) x = 0;
                    if (y < 0) y = 0;
                    SetWindow(pWin, x, y, FORM_MIN_XSIZE, FORM_MIN_YSIZE);
                }
            } else if (pBtn->Status & SYSBTN_MAX_BTN) { /* max botton */
                if (pWin->Status & WIN_MAX_SIZE) {
                    pWin->Status &= ~WIN_MAX_SIZE;
_set_normal_size_win:
                    SetWindow(pWin, pWin->WinRect.left, pWin->WinRect.top,
                              GetRectXSize(&(pWin->WinRect)),
                              GetRectYSize(&(pWin->WinRect))); 
                } else {
                    if (pWin->Status & WIN_MIN_SIZE)
                        pWin->Status &= ~WIN_MIN_SIZE;
                    pWin->Status |= WIN_MAX_SIZE;
                    SetWindow(pWin, -BAR_XOFF, -BAR_YOFF, WIN_MAX_XSIZE, WIN_MAX_YSIZE);
                }
            }
        } 
        return (true);  
    default:
        return (false);
    }
}

static SYSBTN* CreateSysBtn(int left, int top, int width, int height, VIEW* pParent)
{
    VIEW   *pView;
    SYSBTN *pBtn;

    if (pParent == NULL) 
        return (NULL);

    pView = CreateControl(left, top, width, height, pParent, VS_MOVABLE,
                          SysBtnViewProc, sizeof(SYSBTN));
    if (pView == NULL) return (NULL);
    
    pBtn = OBJ_FROM_VIEW(pView);
    pBtn->pView = pView;
    pBtn->BottonColor = ClientColor; 
    pBtn->Status = 0;  
    ShowView(pView);
    return (pBtn);
}

/*
 *******************************************************************************
 *                                                                             *
 *******************************************************************************
 */

static void SetWinScrollBar(WINDOW* pWin); 

static void _cdecl_ OnWinScroll(VIEW *pView, const int Off)
{
    WINDOW *pWin;
    VIEW *pClient;
    SCROLLBAR *pScrollbar = OBJ_FROM_VIEW(pView);

    if (Off == 0) return;
    pWin = OBJ_FROM_VIEW(pView->pParent);
    pClient = pWin->pClientView;
    if (pScrollbar->Align == CTRL_ALIGN_VCENTER)
        MoveAllChildViews(pClient, 0, Off);
    else
        MoveAllChildViews(pClient, Off, 0);
    UpdateView(pWin->pClientView);
} 

static void SetWinScrollBar(WINDOW* pWin)
{ 
    int xSize, ySize;
    CWORD flag = 0;
    RECT save, rect, *r;

    if ((pWin->Styles & WIN_SCROLL) == 0) return;

    save = pWin->pClientView->viewRect;
    r = &(pWin->pClientView->viewRect);
    MergeAllChildViewsRect(pWin->pClientView, &rect);
    
    xSize = GetRectXSize(&rect);
    ySize = GetRectYSize(&rect);
    if (GetRectYSize(r) < ySize) {
        flag |= 1;
        r->right -= BOX_W;
        MergeAllChildViewsRect(pWin->pClientView, &rect);
        xSize = GetRectXSize(&rect);  
    }
    if (GetRectXSize(r) < xSize) {
        flag |= 2;
        r->bottom -= BOX_W;
        MergeAllChildViewsRect(pWin->pClientView, &rect); 
        ySize = GetRectYSize(&rect);
    }
    if (GetRectYSize(r) < ySize) {
        if ((flag & 1) == 0) {
            flag |= 1;
            r->right -= BOX_W;
            MergeAllChildViewsRect(pWin->pClientView, &rect);
            xSize = GetRectXSize(&rect);  
        }
    }     
    if (GetRectXSize(r) < xSize) {
        if ((flag & 2) == 0) {
            flag |= 2;
            r->bottom -= BOX_W;
        }
    }

    pWin->MaxRect = rect;
    rect = (*r);
    pWin->pClientView->viewRect = save;

    if (flag == 3) {
        SetScrolbar(pWin->pVScrolbar, PAGE, &save, &rect, &(pWin->MaxRect), true);
        SetScrolbar(pWin->pHScrolbar, PAGE, &save, &rect, &(pWin->MaxRect), true);
    } else if (flag == 1) {
        SetScrolbar(pWin->pVScrolbar, PAGE, &save, &rect, &(pWin->MaxRect), false);
    } else if (flag == 2) {
        SetScrolbar(pWin->pHScrolbar, PAGE, &save, &rect, &(pWin->MaxRect), false);
    } 

⌨️ 快捷键说明

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