HexEdit/GridCtrl_src/GridCtrl.cpp
COleDataSource* CGridCtrl::CopyTextFromGrid()
{
    USES_CONVERSION;

    CCellRange Selection = GetSelectedCellRange();
    if (!IsValid(Selection))
        return NULL;

    if (GetVirtualMode())
        SendCacheHintToParent(Selection);

    // Write to shared file (REMEBER: CF_TEXT is ANSI, not UNICODE, so we need to convert)
    CSharedFile sf(GMEM_MOVEABLE | GMEM_DDESHARE | GMEM_ZEROINIT);

    // Get a tab delimited string to copy to cache
    CString str;
    CGridCellBase *pCell;
    for (int row = Selection.GetMinRow(); row <= Selection.GetMaxRow(); row++)
    {
        // don't copy hidden cells
        if( m_arRowHeights[row] <= 0 )
            continue;

        str.Empty();
        for (int col = Selection.GetMinCol(); col <= Selection.GetMaxCol(); col++)
        {
            // don't copy hidden cells
            if( m_arColWidths[col] <= 0 )
                continue;

            pCell = GetCell(row, col);
            if (pCell &&(pCell->GetState() & GVIS_SELECTED))
            {
                // if (!pCell->GetText())
                //    str += _T(" ");
                // else 
                str += pCell->GetText();
            }
            if (col != Selection.GetMaxCol()) 
                str += _T("\t");
        }
        if (row != Selection.GetMaxRow()) 
            str += _T("\n");

        sf.Write(T2A(str.GetBuffer(1)), str.GetLength());
        str.ReleaseBuffer();
    }

    char c = '\0';
    sf.Write(&c, 1);

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

    DWORD dwLen = (DWORD) sf.GetLength();
    HGLOBAL hMem = sf.Detach();
    if (!hMem)
        return NULL;

    hMem = ::GlobalReAlloc(hMem, dwLen, GMEM_MOVEABLE | GMEM_DDESHARE | GMEM_ZEROINIT);
    if (!hMem)
        return NULL;

    // Cache data
    COleDataSource* pSource = new COleDataSource();
    pSource->CacheGlobalData(CF_TEXT, hMem);

    return pSource;
}
// Copies text from the selected cells to the clipboard

Copies text from the selected cells to the clipboard
Copies text from the selected cells to the clipboard
COleDataSource* CGridCtrl::CopyTextFromGrid()
{
    USES_CONVERSION;
    CCellRange Selection = GetSelectedCellRange();
    if (!IsValid(Selection))
        return NULL;
    if (GetVirtualMode())
        SendCacheHintToParent(Selection);
    CSharedFile sf(GMEM_MOVEABLE | GMEM_DDESHARE | GMEM_ZEROINIT);
    CString str;
    CGridCellBase *pCell;
    for (int row = Selection.GetMinRow(); row <= Selection.GetMaxRow(); row++)
    {
        if( m_arRowHeights[row] <= 0 )
            continue;
        str.Empty();
        for (int col = Selection.GetMinCol(); col <= Selection.GetMaxCol(); col++)
        {
            if( m_arColWidths[col] <= 0 )
                continue;
            pCell = GetCell(row, col);
            if (pCell &&(pCell->GetState() & GVIS_SELECTED))
            {
                str += pCell->GetText();
            }
            if (col != Selection.GetMaxCol()) 
                str += _T("\t");
        }
        if (row != Selection.GetMaxRow()) 
            str += _T("\n");
        sf.Write(T2A(str.GetBuffer(1)), str.GetLength());
        str.ReleaseBuffer();
    }
    char c = '\0';
    sf.Write(&c, 1);
    if (GetVirtualMode())
        SendCacheHintToParent(CCellRange(-1,-1,-1,-1));
    DWORD dwLen = (DWORD) sf.GetLength();
    HGLOBAL hMem = sf.Detach();
    if (!hMem)
        return NULL;
    hMem = ::GlobalReAlloc(hMem, dwLen, GMEM_MOVEABLE | GMEM_DDESHARE | GMEM_ZEROINIT);
    if (!hMem)
        return NULL;
    COleDataSource* pSource = new COleDataSource();
    pSource->CacheGlobalData(CF_TEXT, hMem);
    return pSource;
}
COleDataSource * CGridCtrl :: CopyTextFromGrid ( ) { USES_CONVERSION ; CCellRange Selection = GetSelectedCellRange ( ) ; if ( ! IsValid ( Selection ) ) return NULL ; if ( GetVirtualMode ( ) ) SendCacheHintToParent ( Selection ) ; CSharedFile sf ( GMEM_MOVEABLE | GMEM_DDESHARE | GMEM_ZEROINIT ) ; CString str ; CGridCellBase * pCell ; for ( int row = Selection . GetMinRow ( ) ; row <= Selection . GetMaxRow ( ) ; row ++ ) { if ( m_arRowHeights [ row ] <= 0 ) continue ; str . Empty ( ) ; for ( int col = Selection . GetMinCol ( ) ; col <= Selection . GetMaxCol ( ) ; col ++ ) { if ( m_arColWidths [ col ] <= 0 ) continue ; pCell = GetCell ( row , col ) ; if ( pCell && ( pCell -> GetState ( ) & GVIS_SELECTED ) ) { str += pCell -> GetText ( ) ; } if ( col != Selection . GetMaxCol ( ) ) str += _T ( " \t " ) ; } if ( row != Selection . GetMaxRow ( ) ) str += _T ( " \n " ) ; sf . Write ( T2A ( str . GetBuffer ( 1 ) ) , str . GetLength ( ) ) ; str . ReleaseBuffer ( ) ; } char c = ' \0 ' ; sf . Write ( & c , 1 ) ; if ( GetVirtualMode ( ) ) SendCacheHintToParent ( CCellRange ( -1 , -1 , -1 , -1 ) ) ; DWORD dwLen = ( DWORD ) sf . GetLength ( ) ; HGLOBAL hMem = sf . Detach ( ) ; if ( ! hMem ) return NULL ; hMem = :: GlobalReAlloc ( hMem , dwLen , GMEM_MOVEABLE | GMEM_DDESHARE | GMEM_ZEROINIT ) ; if ( ! hMem ) return NULL ; COleDataSource * pSource = new COleDataSource ( ) ; pSource -> CacheGlobalData ( CF_TEXT , hMem ) ; return pSource ; }
Copies text from the selected cells to the clipboard
Copies text from the selected cells to the clipboard
// Write to shared file (REMEBER: CF_TEXT is ANSI, not UNICODE, so we need to convert)
 // Get a tab delimited string to copy to cache
 // don't copy hidden cells
 // don't copy hidden cells
 // if (!pCell->GetText())
 //    str += _T(" ");
 // else 
 // Cache data
