HexEdit/GridCtrl_src/GridCtrl.cpp
void CGridCtrl::AutoSize(UINT nAutoSizeStyle /*=GVS_DEFAULT*/)
{
    CDC* pDC = GetDC();
    if (!pDC)
        return;

    int nNumColumns = GetColumnCount();

    int nCol, nRow;

    ASSERT(GVS_DEFAULT <= nAutoSizeStyle && nAutoSizeStyle <= GVS_BOTH);
    if (nAutoSizeStyle == GVS_DEFAULT)
        nAutoSizeStyle = GetAutoSizeStyle();

    int nStartRow = (nAutoSizeStyle & GVS_HEADER)? 0 : GetFixedRowCount();
    int nEndRow   = (nAutoSizeStyle & GVS_DATA)? GetRowCount()-1 : GetFixedRowCount()-1;

    if (GetVirtualMode())
        SendCacheHintToParent(CCellRange(nStartRow, 0, nEndRow, nNumColumns));

    // Row initialisation - only work on rows whose height is > 0
    for (nRow = nStartRow; nRow <= nEndRow; nRow++)
    {
        if( GetRowHeight( nRow) > 0 )
            m_arRowHeights[nRow] = 1;
    }

    CSize size;
    for (nCol = 0; nCol < nNumColumns; nCol++)
    {
        //  Don't size hidden columns or rows
        if( GetColumnWidth( nCol) > 0 )
        {
            // Skip columns that are hidden, but now initialize
            m_arColWidths[nCol] = 0;
            for (nRow = nStartRow; nRow <= nEndRow; nRow++)
            {
                if( GetRowHeight( nRow) > 0 )
                {
                    CGridCellBase* pCell = GetCell(nRow, nCol);
                    if (pCell)
                        size = pCell->GetCellExtent(pDC);
                    if (nRow == 0 && GetSortColumn() == nCol)
                    {
                        // Add width of sort indicator (= min of text height and row height)
                        CRect rect_cell, rect_text;
                        GetCellRect(nRow, nCol, &rect_cell);
                        GetTextRect(nRow, nCol, &rect_text);
                        size.cx += __min(rect_cell.Height(), rect_text.Height());
                    }
                    if (size.cx >(int) m_arColWidths[nCol] && OnResizeColumn(nCol, size.cx))
                        m_arColWidths[nCol] = size.cx;
                    if (size.cy >(int) m_arRowHeights[nRow])
                        m_arRowHeights[nRow] = size.cy;
                }
            }
        }
    }

    if (GetVirtualMode())
        SendCacheHintToParent(CCellRange(-1,-1,-1,-1));

    ReleaseDC(pDC);

    ResetScrollBars();
    Refresh();
}
// sizes all rows and columns
// faster than calling both AutoSizeColumns() and AutoSizeRows()

sizes all rows and columns
faster than calling both AutoSizeColumns() and AutoSizeRows()
sizes all rows and columns faster than calling both AutoSizeColumns () and AutoSizeRows ()
void CGridCtrl::AutoSize(UINT nAutoSizeStyle )
{
    CDC* pDC = GetDC();
    if (!pDC)
        return;
    int nNumColumns = GetColumnCount();
    int nCol, nRow;
    ASSERT(GVS_DEFAULT <= nAutoSizeStyle && nAutoSizeStyle <= GVS_BOTH);
    if (nAutoSizeStyle == GVS_DEFAULT)
        nAutoSizeStyle = GetAutoSizeStyle();
    int nStartRow = (nAutoSizeStyle & GVS_HEADER)? 0 : GetFixedRowCount();
    int nEndRow   = (nAutoSizeStyle & GVS_DATA)? GetRowCount()-1 : GetFixedRowCount()-1;
    if (GetVirtualMode())
        SendCacheHintToParent(CCellRange(nStartRow, 0, nEndRow, nNumColumns));
    for (nRow = nStartRow; nRow <= nEndRow; nRow++)
    {
        if( GetRowHeight( nRow) > 0 )
            m_arRowHeights[nRow] = 1;
    }
    CSize size;
    for (nCol = 0; nCol < nNumColumns; nCol++)
    {
        if( GetColumnWidth( nCol) > 0 )
        {
            m_arColWidths[nCol] = 0;
            for (nRow = nStartRow; nRow <= nEndRow; nRow++)
            {
                if( GetRowHeight( nRow) > 0 )
                {
                    CGridCellBase* pCell = GetCell(nRow, nCol);
                    if (pCell)
                        size = pCell->GetCellExtent(pDC);
                    if (nRow == 0 && GetSortColumn() == nCol)
                    {
                        CRect rect_cell, rect_text;
                        GetCellRect(nRow, nCol, &rect_cell);
                        GetTextRect(nRow, nCol, &rect_text);
                        size.cx += __min(rect_cell.Height(), rect_text.Height());
                    }
                    if (size.cx >(int) m_arColWidths[nCol] && OnResizeColumn(nCol, size.cx))
                        m_arColWidths[nCol] = size.cx;
                    if (size.cy >(int) m_arRowHeights[nRow])
                        m_arRowHeights[nRow] = size.cy;
                }
            }
        }
    }
    if (GetVirtualMode())
        SendCacheHintToParent(CCellRange(-1,-1,-1,-1));
    ReleaseDC(pDC);
    ResetScrollBars();
    Refresh();
}
void CGridCtrl :: AutoSize ( UINT nAutoSizeStyle ) { CDC * pDC = GetDC ( ) ; if ( ! pDC ) return ; int nNumColumns = GetColumnCount ( ) ; int nCol , nRow ; ASSERT ( GVS_DEFAULT <= nAutoSizeStyle && nAutoSizeStyle <= GVS_BOTH ) ; if ( nAutoSizeStyle == GVS_DEFAULT ) nAutoSizeStyle = GetAutoSizeStyle ( ) ; int nStartRow = ( nAutoSizeStyle & GVS_HEADER ) ? 0 : GetFixedRowCount ( ) ; int nEndRow = ( nAutoSizeStyle & GVS_DATA ) ? GetRowCount ( ) - 1 : GetFixedRowCount ( ) - 1 ; if ( GetVirtualMode ( ) ) SendCacheHintToParent ( CCellRange ( nStartRow , 0 , nEndRow , nNumColumns ) ) ; for ( nRow = nStartRow ; nRow <= nEndRow ; nRow ++ ) { if ( GetRowHeight ( nRow ) > 0 ) m_arRowHeights [ nRow ] = 1 ; } CSize size ; for ( nCol = 0 ; nCol < nNumColumns ; nCol ++ ) { if ( GetColumnWidth ( nCol ) > 0 ) { m_arColWidths [ nCol ] = 0 ; for ( nRow = nStartRow ; nRow <= nEndRow ; nRow ++ ) { if ( GetRowHeight ( nRow ) > 0 ) { CGridCellBase * pCell = GetCell ( nRow , nCol ) ; if ( pCell ) size = pCell -> GetCellExtent ( pDC ) ; if ( nRow == 0 && GetSortColumn ( ) == nCol ) { CRect rect_cell , rect_text ; GetCellRect ( nRow , nCol , & rect_cell ) ; GetTextRect ( nRow , nCol , & rect_text ) ; size . cx += __min ( rect_cell . Height ( ) , rect_text . Height ( ) ) ; } if ( size . cx > ( int ) m_arColWidths [ nCol ] && OnResizeColumn ( nCol , size . cx ) ) m_arColWidths [ nCol ] = size . cx ; if ( size . cy > ( int ) m_arRowHeights [ nRow ] ) m_arRowHeights [ nRow ] = size . cy ; } } } } if ( GetVirtualMode ( ) ) SendCacheHintToParent ( CCellRange ( -1 , -1 , -1 , -1 ) ) ; ReleaseDC ( pDC ) ; ResetScrollBars ( ) ; Refresh ( ) ; }
sizes all rows and columns
faster than calling both AutoSizeColumns() and AutoSizeRows()
sizes all rows and columns faster than calling both AutoSizeColumns () and AutoSizeRows ()
/*=GVS_DEFAULT*/ // Row initialisation - only work on rows whose height is > 0
 //  Don't size hidden columns or rows
 // Skip columns that are hidden, but now initialize
 // Add width of sort indicator (= min of text height and row height)
