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

📄 gridbtncellbase.cpp

📁 是一个GridTree的控件
💻 CPP
📖 第 1 页 / 共 3 页
字号:
                                | DFCS_SCROLLRIGHT
                                | DFCS_SCROLLSIZEGRIP)  )  )  // checking for DFCS_SCROLLUP
                                    // but it is not a bit, it is 0x0!
            {
                if( i1 + 1 < iCtlNbr)
                {
                    // at least 1 more -- see if we got spin box match
                    if( GetDrawCtlType( i1 + 1) == DFC_SCROLL
                        && ( GetDrawCtlState( i1 + 1) & DFCS_SCROLLDOWN)  )
                    {
                        // it's a spin box
                        i1++;   // skip looking at next control
                        iSpinBoxDownIdx = i1;
                    }

                }
            }
        }

    }

    int iSizeToFitWidth = 0;
    int iFitWidthsTotal = arRectCell.Width() - iFixedSum;
    if( iSizeToFitCount > 0)
    {
        iSizeToFitWidth = iFitWidthsTotal / iSizeToFitCount;
    }


    int iSizeToFitCountWrk = iSizeToFitCount;
    int iWidthSoFar = 0;
    for( i1=0; i1 < iCtlNbr; i1++)
    {
        if( iSpinBoxDownIdx == i1)
        {
            // skip down arrow of spin box for calculations
            apRect++;
            continue;
        }

        apRect->operator=( arRectCell); // copy initial rectangle
        apRect->left += iWidthSoFar;
        apRect->right = apRect->left;

        iWidth = GetDrawCtlWidth( i1);
        if( iWidth > 0)
            iWidthSoFar += iWidth; // fixed width
        else
        {
            iSizeToFitCountWrk--;   // found another one

            // may shrink width if control is square -- saves screen real-estate
            uiType = GetDrawCtlType( i1);
            uiState = GetDrawCtlState( i1);
            BOOL bIsRectangle = (   uiType == DFC_BUTTON
                                    && (uiState & DFCS_BUTTONPUSH) == DFCS_BUTTONPUSH);
                                        // all other buttons are square

            if( !bIsRectangle
                && arRectCell.Height() < iSizeToFitWidth)
            {
                // it is square -- make width the cell height
                iWidthSoFar += arRectCell.Height();

                // recalulate size to fit
                iFitWidthsTotal -= arRectCell.Height();

                if( iSizeToFitCountWrk > 0)
                    iSizeToFitWidth = iFitWidthsTotal / iSizeToFitCountWrk;
            }
            else
            {
                iWidthSoFar += iSizeToFitWidth;
                iFitWidthsTotal -= iSizeToFitWidth;
            }
        }

        apRect->right = iWidthSoFar + arRectCell.left;
        apRect++;
    }

    if( iFitWidthsTotal < (int)GetMargin() )
    {
        // no leftover rectangle available
        apRect->SetRectEmpty();
    }
    else
    {
        // calc leftover rectangle
        apRect->operator=( arRectCell);
        apRect->left += iWidthSoFar;
    }

    // I've been assuming that all controls are left-aligned.  Programmer
    //  may have defined controls as right-aligned, too.  Note that left
    //  and right controls can be declared in the array in any order

    // Ok, here's the kludge.  Since I know that the heights of each control
    //  are the same, use these unused height values in the CRect array to
    //  help me calculate the proper order of the widths
    apRect = pRectSav;
    int iSavedTop = arRectCell.left;  // seed first result

    for( i1=0; i1 < iCtlNbr; i1++)
    {
        if( iSpinBoxDownIdx == i1)
        {
            // skip down arrow of spin box for calculations
            apRect++;
            continue;
        }

        // analyzing just Left-aligned controls
        CtlAlign = GetDrawCtlAlign( i1);
        ASSERT( CtlAlign != CTL_ALIGN_CENTER);  // should've taken care of

        if( CtlAlign == CTL_ALIGN_LEFT)
        {
            apRect->top = iSavedTop;
            iSavedTop += apRect->Width();
            apRect->bottom = iSavedTop;
        }
        apRect++;

    }

    // text rectangle appears between left and right aligned controls
    //  and width has been saved in last rectangle
    apRect = pRectSav + iCtlNbr;

    apRect->top = iSavedTop + GetMargin();        // put some margin so doesn't overwrite
    iSavedTop += apRect->Width();
    apRect->bottom = iSavedTop;
    iSavedTop += GetMargin();         // some more margin...

    apRect = pRectSav;
    for( i1=0; i1 < iCtlNbr; i1++)
    {
        if( iSpinBoxDownIdx == i1)
        {
            // skip down arrow of spin box for calculations
            apRect++;
            continue;
        }

        // finally, look at right-aligned controls
        CtlAlign = GetDrawCtlAlign( i1);
        if( CtlAlign == CTL_ALIGN_RIGHT)
        {
            apRect->top = iSavedTop;
            iSavedTop += apRect->Width();
            apRect->bottom = iSavedTop;
        }
        apRect++;
    }


    // flip everything back and we're done
    apRect = pRectSav;
    for( i1=0; i1 <= iCtlNbr; i1++)     // note that I'll get leftover rect, too
    {
        apRect->left = apRect->top;
        if( apRect->left < arRectCell.left )
            apRect->left = arRectCell.left;   // can't go beyond cell
        if( apRect->left > arRectCell.right )
            apRect->left = arRectCell.right;

        apRect->right = apRect->bottom;
        if( apRect->right > arRectCell.right)
            apRect->right = arRectCell.right;
        if( apRect->right < arRectCell.left)
            apRect->right = arRectCell.left;

        apRect->bottom = arRectCell.bottom;
        apRect->top = arRectCell.top;

        apRect++;
    }


    // but wait -- special calculations for the spin box
    if( iSpinBoxDownIdx >= 0)
    {
        CRect* pRectSpinUp = pRectSav + iSpinBoxDownIdx - 1;
        apRect = pRectSav + iSpinBoxDownIdx;

        apRect->left = pRectSpinUp->left;
        apRect->right = pRectSpinUp->right;
        apRect->bottom = pRectSpinUp->bottom;

        int iHalf = apRect->top + ( (apRect->bottom - apRect->top) / 2);
        apRect->top = iHalf;
        pRectSpinUp->bottom = iHalf;
    }

    return TRUE;
}

/*****************************************************************************
Override default title tips so that I'll get a title tip for a cell
filled only with buttons

*****************************************************************************/
LPCTSTR CGridBtnCellBase::GetTipText()
{
    if( HasCellText() )
        return GetText();

    // no string text... maybe there's btns with text
    const int iCtlNbr = GetDrawCtlNbr();
    if( iCtlNbr <= 0)
        return NULL;

    char szTip[ 256];
    int iNbrChars = 0;

    int i1;
    for( i1=0; i1 < iCtlNbr; i1++)
    {
        // remove any '&' chars
        const char* pszCtlBtnText = GetDrawCtlBtnText( i1);
        if( pszCtlBtnText != NULL)
        {
            if( i1 > 0)
            {
                szTip[ iNbrChars] = ' ';
                iNbrChars++;
            }

            BOOL bJustGotAmp = FALSE;
            while( iNbrChars < sizeof( szTip) - 2)
            {
                if( *pszCtlBtnText == '\0')
                    break;

                if( *pszCtlBtnText == '&' )
                {
                    if( bJustGotAmp)
                    {
                        bJustGotAmp = FALSE;
                        szTip[ iNbrChars] = *pszCtlBtnText;
                        iNbrChars++;
                    }
                    else
                        bJustGotAmp = TRUE;
                }
                else
                {
                    bJustGotAmp = FALSE;
                    szTip[ iNbrChars] = *pszCtlBtnText;
                    iNbrChars++;
                }
                pszCtlBtnText++;
            }
        }
    }
    szTip[ iNbrChars] = '\0';
    m_strTipText = szTip;

    return m_strTipText;
}

/*****************************************************************************
If no text in the cell, add up all the button text together and use that
as the title tip text

*****************************************************************************/
BOOL CGridBtnCellBase::GetTipTextRect( LPRECT pRect)  // i/o:  i=dims of cell rect; o=dims of text rect
{
    if( HasCellText() )
        return GetTextRect( pRect); // if any text, just use default

    // no string text... maybe there's btns with text
    const int iCtlNbr = GetDrawCtlNbr();
    if( iCtlNbr <= 0)
    {
        pRect->left = 0;
        pRect->top = 0;
        pRect->right = 0;
        pRect->bottom = 0;
    }

    // else, don't modify rect -- rect is full cell size
    return TRUE;
}

BOOL CGridBtnCellBase::HasCellText()
// returns:  F=auto-size buttons, only
{
    CGridCtrl* pGrid = GetGrid();
    ASSERT( pGrid);

    CRect RectCell;
    if( !pGrid->GetCellRect(m_iRow,
                            m_iCol,
                            &RectCell) )
        return FALSE;

    // rather than see if there is text assigned, check if any
    //  space allocated for text
    CRect RectText( RectCell);
    if( !GetTextRect( &RectText) ) // i/o:  i=dims of cell rect; o=dims of text rect
        return FALSE;

    if( RectText.Width() > 0 )
        return TRUE;

    return FALSE;
}

int CGridBtnCellBase::HotKeyBtnMatch( char acHotKey) // hot key character
// returns:  index of button or -1 if no hot key matches
{
    const char* pszWork;

    const int iCtlNbr = GetDrawCtlNbr();
    for( int i1=0; i1 < iCtlNbr; i1++)
    {
        pszWork = GetDrawCtlBtnText( i1);
        while( *pszWork != NULL)
        {
            if( *pszWork == '&')
            {
                pszWork++;
                if( *pszWork == NULL)
                    break;

                if( tolower(*pszWork) == tolower( acHotKey) )
                    return i1;
            }

            pszWork++;
        }
    }
    return -1;
}

⌨️ 快捷键说明

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