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

📄 maingui.c

📁 MiniGUI源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
        iIndex = GetNextNormalMenuItem(pNormalMenuItem, iIndex);

    return iIndex;
}

/*
 * Function: static int GetPreviousNormalMenuItem(PNORMALMENUITEM pNormalMenuItem, int iIndex)
 * Parameters:
 * Return:
 *      None;
 *
 * 1995.8.9.AM.
 *
 */
static int GetPreviousNormalMenuItem(PNORMALMENUITEM pNormalMenuItem, int iIndex)
{
    int iNum;
    iNum = GetNumOfNormalMenuItem(pNormalMenuItem);
    
    if(iIndex == 0)
        iIndex = iNum;

    iIndex--;
    
    if((pNormalMenuItem + iIndex)->fItemFlags & MF_MENUBREAK)
        iIndex = GetPreviousNormalMenuItem(pNormalMenuItem, iIndex);

    return iIndex;
}

/*
 * Function: static int GetNumOfNormalMenuItem(PNORMALMENUITEM pNormalMenuItem);
 * Parameters:
 * Return:
 *      None;
 *
 * 1995.8.9.AM.
 *
 */
static int GetNumOfNormalMenuItem(PNORMALMENUITEM pNormalMenuItem)
{
    int iNum = 0;
    PNORMALMENUITEM pBuffer = pNormalMenuItem;
    
    do
    {
        iNum++;
        if(pBuffer->fItemFlags & MF_END)
            break;
            
        pBuffer++;
    }while(TRUE);
    
    return iNum;
}

/*
 * Function: void GUIAPI DrawPopupMenu( PPOPUPMENUITEM pPopupMenuItem, int x, int y )
 * Parameters:
 * Return:
 *      None;
 *
 * 1995.8.9.AM.
 *
 */
void GUIAPI DrawPopupMenu( PPOPUPMENUITEM pPopupMenuItem, int x, int y )
{
    int iWidth, iHeight;
    PNORMALMENUITEM pBuffer = pPopupMenuItem->pNormalMenuItem;
    
    iWidth = GetPopupMenuWidth(pPopupMenuItem);
    iHeight = GetPopupMenuHeight(pPopupMenuItem);

    SetPtrVis(HIDE);

    // Fill background and draw the border.
    _setcolor(MN_BKCOLOR);
    _rectangle(_GFILLINTERIOR, x, y, x + iWidth, y + iHeight);
    _setcolor(0);
    _rectangle(_GBORDER, x - 1, y - 1, x + iWidth + 1, y + iHeight + 1);
    _moveto(x, y + iHeight + 2);
    _lineto(x + iWidth + 2, y + iHeight + 2);
    _lineto(x + iWidth + 2, y);
    
    do
    {
        if(pBuffer->fItemFlags & MF_MENUBREAK)
        {
            _setcolor(0);
            _moveto(x, y + MB_HEIGHT);
            _lineto(x + iWidth, y + MB_HEIGHT);
            y += MB_HEIGHT*2 + 1;
        }
        else
        {
            DrawMenuItem(pBuffer->spItemText, FALSE, pBuffer->fItemFlags, x, y, iWidth);
            y += MN_HEIGHT;
        }

        if(pBuffer->fItemFlags & MF_END)
            break;
            
        pBuffer++;
    }while(TRUE);
    
    SetPtrVis(SHOW);
}

/*
 * Function: int GUIAPI GetPopupMenuWidth( PPOPUPMENUITEM pPopupMenuItem )
 * Parameters:
 * Return:
 *      None.
 *
 * 1995.8.9.AM.
 *
 */
int GUIAPI GetPopupMenuWidth( PPOPUPMENUITEM pPopupMenuItem )
{
    int iWidth = 0;
    int x;
    PNORMALMENUITEM pBuffer = pPopupMenuItem->pNormalMenuItem;
    
    do
    {
        if(pBuffer->fItemFlags & MF_MENUBREAK)
        {
            pBuffer++;
            continue;
        }
            
        x = GetOutWidth(pBuffer->spItemText);
        if(iWidth < x)
            iWidth = x;
        if(pBuffer->fItemFlags & MF_END)
            break;
        
        pBuffer++;
    }while(TRUE);
    
    return iWidth + MN_START_WIDTH + MN_END_WIDTH;
}

/*
 * Function: int GUIAPI GetPopupMenuHeight( PPOPUPMENUITEM pPopupMenuItem )
 * Parameters:
 * Return:
 *      None;
 *
 * 1995.8.9.AM.
 *
 */
int GUIAPI GetPopupMenuHeight( PPOPUPMENUITEM pPopupMenuItem )
{
    int iHeight = 0;
    PNORMALMENUITEM pBuffer = pPopupMenuItem->pNormalMenuItem;
    
    do
    {
        if(pBuffer->fItemFlags & MF_MENUBREAK)
            iHeight += MB_HEIGHT*2 + 1;
        else
            iHeight += MN_HEIGHT;

        if(pBuffer->fItemFlags & MF_END)
            break;
        
        pBuffer++;
    }while(TRUE);
    
    return iHeight;
}

/*
 * Function: void GUIAPI DrawMenuItem( PSTR pStr, WORD fFlags, int x, int y, int iWidth)
 *      This function draw the menu item in the specified position with
 *  the specified flags.
 * Parameters:
 *      pStr:   pointer to the item text;
 *      fFlags: menu item's flags;
 *      x, y:   specified the position;
 *      iWidth: the width of menu item.
 * Return:
 *      None;
 *
 * 1995.8.9.AM.
 *
 */
void GUIAPI DrawMenuItem( PSTR pStr, BOOL fHilite, WORD fFlags, int x, int y, int iWidth )
{
    char buffer[5];
    
    if((fFlags & MF_MENUBARBREAK) || (fFlags & MF_MENUBREAK))
        return;
        
    if(fHilite)
    {
        // Fill actived menu item's background.
        _setcolor(MA_BKCOLOR);
        _rectangle(_GFILLINTERIOR, x, y, x + iWidth, y + MN_HEIGHT);
    }
    else
    {
        _setcolor(MN_BKCOLOR);
        _rectangle(_GFILLINTERIOR, x, y, x + iWidth, y + MN_HEIGHT);
    }
    
    
    if(fFlags & MF_DISABLED)
        set_color(MD_FGCOLOR);
    else if(fHilite)
        set_color(MA_FGCOLOR);
    else
        set_color(MN_FGCOLOR);
    
    if(fFlags & MF_POPUP)
        x += MP_START_WIDTH;
    else
        x += MN_START_WIDTH;
        
    if(fFlags & MF_DISABLED)
        SetGrayTextMask();
    cc_printf(pStr, x, y);
    if(fFlags & MF_DISABLED)
        RemoveDisplayMask();
    
    if(!(fFlags & MF_POPUP))
        if(fFlags & MF_CHECKED)
        {
            strcpy(buffer, "√");
            cc_wt16(buffer, x - MN_START_WIDTH, y);
        }
    
}

/*
 * Function: int GUIAPI CanActiveMenuByAltKey(PPOPUPMENUITEM pPopupMenuItem, UINT uKey)
 *      This function determines whether the specified Alt + x Key can 
 *  active the menu.
 * Parameters:
 *      pPopupMenuItem: the pionter to the POPUPMENUITEM structure;
 *      uKey:           the specified key ;
 * Return:
 *      < 0: can not;
 *      >= 0: can active menu and give the index of the popup menu item.
 *
 * 19956.12.5.pM.
 *
 */
int GUIAPI CanActiveMenuByAltKey(PPOPUPMENUITEM pPopupMenuItem, UINT uKey)
{
    char  achHilite[MAXITEM];
    char* pchT;
    char  zChar;
    BYTE  bScanCode;
    int   i, iIndex;
    BYTE  bAllScanCode[] ={ 0x1E, 0x30, 0x2E, 0x20, 0x12, 0x21, 0x22, 0x23, 0x17, 0x24,
                            0x25, 0x26, 0x32, 0x31, 0x18, 0x19, 0x10, 0x13, 0x1F, 0x14,
                            0x16, 0x2F, 0x11, 0x2D, 0x15, 0x2C
                          };
    
    CreateHiliteStringOfMenuBar(pPopupMenuItem, achHilite);
    
    // Convete scan code to ASCII code.
    bScanCode = LOBYTE(uKey);
    iIndex = -1;
    for(i=0; i<26; i++)
    {
        if(bScanCode == bAllScanCode[i])
        {
            iIndex = i;
            break;
        }
    }
    
    if(iIndex == -1)
        return -1;
    
    zChar = (char)('a' + iIndex);
    pchT = strchr( achHilite, zChar);
    if( pchT != NULL )  // If in highlight string, evaluate
    {
        return (pchT - achHilite);
    }
    
    return -1;
}

/*
 * Function: int GUIAPI CanActiveMenu( PPOPUPMENUITEM pPopupMenuItem, PPOINT pPt )
 *      This function determines weather the specified ponit pt can 
 *  active the menu.
 * Parameters:
 *      pPopupMenuItem: the pionter to the POPUPMENUITEM structure;
 *      :       specified the point.
 * Return:
 *      < 0: can not;
 *      >= 0: can active menu and give the index of the popup menu item.
 *
 * 1995.8.9.AM.
 *
 */
int GUIAPI CanActiveMenu( PPOPUPMENUITEM pPopupMenuItem, PPOINT pPt )
{
    int left = 0, right = 0;
    int i = 0;
    PPOPUPMENUITEM pBuffer = pPopupMenuItem;
    
    do
    {
        if(pBuffer->fItemFlags & MF_MENUBARBREAK)
            right += MB_WIDTH;
        else
        {
            right += MP_START_WIDTH;
            right += GetOutWidth(pBuffer->spItemText);
            right += MP_END_WIDTH;
        }
            
        if( (pPt->y > CP_HEIGHT) 
            && (pPt->y <= CP_HEIGHT + MN_HEIGHT)
            && (pPt->x > left)
            && (pPt->x <= right))
        {
            if(pBuffer->fItemFlags & MF_MENUBARBREAK)
                return FAILURE;
            return i;
        }

        if(pBuffer->fItemFlags & MF_END)
            break;
        
        left = right;
        
        pBuffer++;
        i++;
    }while(TRUE);
    
    return FAILURE;
}

/*
 * Function: static int WhichItemMouseIn(PNORMALMENUITEM pNormalMenuItem, int top, int y)
 * Parameters:
 * Return:
 *      None;
 *
 * 1995.8.9.AM.
 *
 */
static int WhichItemMouseIn(PNORMALMENUITEM pNormalMenuItem, int top, int y)
{
    int bottom = top;
    int i = 0;
    PNORMALMENUITEM pBuffer = pNormalMenuItem;
    
    do
    {
        if(pBuffer->fItemFlags & MF_MENUBREAK)
            bottom += MB_HEIGHT*2 + 1;
        else
            bottom += MN_HEIGHT;
        
        if((y > top) && (y <= bottom))
        {
            if(pBuffer->fItemFlags & MF_MENUBREAK)
                return FAILURE;
            return i;
        }

        if(pBuffer->fItemFlags & MF_END)
            break;
        
        top = bottom;
        
        pBuffer++;
        i++;
    }while(TRUE);
    
    return FAILURE;
}

static PNORMALMENUITEM GetNormalMenuItem(PGUIINFO pGUIInfo, WORD wID)
{
    PPOPUPMENUITEM pPopupMenuItem;
    PNORMALMENUITEM pNormalMenuItem;
    
    pPopupMenuItem = pGUIInfo->pPopupMenuItem;
    while(!(pPopupMenuItem->fItemFlags & MF_END))
    {
        pNormalMenuItem = pPopupMenuItem->pNormalMenuItem;
        while(!(pPopupMenuItem->fItemFlags & MF_END))
        {
            if((WORD)(pNormalMenuItem->iMenuID) == wID)
                return pNormalMenuItem;
            pNormalMenuItem++;
        }
        pPopupMenuItem++;
    }
    
    return NULL;
}

WORD GUIAPI GetPopupMenuItemFlags(PGUIINFO pGUIInfo, int iIndex)
{
    PPOPUPMENUITEM pPopupMenuItem;
    
    pPopupMenuItem = pGUIInfo->pPopupMenuItem + iIndex;
    
    return pPopupMenuItem->fItemFlags;
}

WORD GUIAPI GetNormalMenuItemFlags(PGUIINFO pGUIInfo, int iPopupIndex, int iIndex)
{
    PPOPUPMENUITEM pPopupMenuItem;
    PNORMALMENUITEM pNormalMenuItem;
    
    pPopupMenuItem = pGUIInfo->pPopupMenuItem + iPopupIndex;
    pNormalMenuItem = pPopupMenuItem->pNormalMenuItem + iIndex;

    return pNormalMenuItem->fItemFlags;
}

void GUIAPI EnablePopupMenuItem(PGUIINFO pGUIInfo, int iIndex, BOOL fEnable)
{
    PPOPUPMENUITEM pPopupMenuItem;
    
    pPopupMenuItem = pGUIInfo->pPopupMenuItem + iIndex;
    
    if(fEnable)
        pPopupMenuItem->fItemFlags &= ~MF_DISABLED;
    else
        pPopupMenuItem->fItemFlags |= MF_DISABLED;
}

void GUIAPI EnableNormalMenuItem(PGUIINFO pGUIInfo, int iPopupIndex, int iIndex, BOOL fEnable)
{
    PPOPUPMENUITEM pPopupMenuItem;
    PNORMALMENUITEM pNormalMenuItem;
    
    pPopupMenuItem = pGUIInfo->pPopupMenuItem + iPopupIndex;
    pNormalMenuItem = pPopupMenuItem->pNormalMenuItem + iIndex;

    if(fEnable)
        pNormalMenuItem->fItemFlags &= ~MF_DISABLED;
    else
        pNormalMenuItem->fItemFlags |= MF_DISABLED;
}

void GUIAPI CheckNormalMenuItem(PGUIINFO pGUIInfo, int iPopupIndex, int iIndex, BOOL fCheck)
{
    PPOPUPMENUITEM pPopupMenuItem;
    PNORMALMENUITEM pNormalMenuItem;
    
    pPopupMenuItem = pGUIInfo->pPopupMenuItem + iPopupIndex;
    pNormalMenuItem = pPopupMenuItem->pNormalMenuItem + iIndex;

    if(!fCheck)
        pNormalMenuItem->fItemFlags &= ~MF_CHECKED;
    else
        pNormalMenuItem->fItemFlags |= MF_CHECKED;
}

/*
 * Function: void GUIAPI BeginPaint(PDC pDC);
 * Parameters:
 * Return:
 *      None;
 *
 * 1995.8.10.AM.
 *
 */
void GUIAPI BeginPaint(PDC pDC)
{
    SetPtrVis(HIDE);
    set_cliprgn(pDC->cliprect.left, 
        pDC->cliprect.top,
        pDC->cliprect.right,
        pDC->cliprect.bottom);
}

/*
 * Function: void GUIAPI EndPaint(PDC pDC);
 * Parameters:
 * Return:
 *      None;
 *
 * 1995.8.10.AM.
 *
 */
void GUIAPI EndPaint(PDC pDC)
{
    set_cliprgn(pDC->clientrect.left, 
        pDC->clientrect.top,
        pDC->clientrect.right,
        pDC->clientrect.bottom);
    SetPtrVis(SHOW);
}

⌨️ 快捷键说明

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