HexEdit/GridCtrl_src/GridCellBase.cpp
BOOL CGridCellBase::PrintCell(CDC* pDC, int /*nRow*/, int /*nCol*/, CRect rect)
{
#if defined(_WIN32_WCE_NO_PRINTING) || defined(GRIDCONTROL_NO_PRINTING)
    return FALSE;
#else
    COLORREF crFG, crBG;
    GV_ITEM Item;

    CGridCtrl* pGrid = GetGrid();
    if (!pGrid || !pDC)
        return FALSE;

    if( rect.Width() <= 0
        || rect.Height() <= 0)  // prevents imagelist item from drawing even
        return FALSE;           //  though cell is hidden

    int nSavedDC = pDC->SaveDC();

    pDC->SetBkMode(TRANSPARENT);

    if(pGrid->GetShadedPrintOut())
    {
        // Get the default cell implementation for this kind of cell. We use it if this cell
        // has anything marked as "default"
        CGridDefaultCell *pDefaultCell = (CGridDefaultCell*) GetDefaultCell();
        if (!pDefaultCell)
            return FALSE;

        // Use custom color if it doesn't match the default color and the
        // default grid background color.  If not, leave it alone.
        if(IsFixed())
            crBG = (GetBackClr() != CLR_DEFAULT) ? GetBackClr() : pDefaultCell->GetBackClr();
        else
            crBG = (GetBackClr() != CLR_DEFAULT && GetBackClr() != pDefaultCell->GetBackClr()) ?
                GetBackClr() : CLR_DEFAULT;

        // Use custom color if the background is different or if it doesn't
        // match the default color and the default grid text color.  If not,
        // use black to guarantee the text is visible.
        if(IsFixed())
            crFG = (GetBackClr() != CLR_DEFAULT) ? GetTextClr() : pDefaultCell->GetTextClr();
        else
            crFG = (GetBackClr() != CLR_DEFAULT ||
                (GetTextClr() != CLR_DEFAULT && GetTextClr() != pDefaultCell->GetTextClr())) ?
                    GetTextClr() : RGB(0, 0, 0);

        // If not printing on a color printer, adjust the foreground color
        // to a gray scale if the background color isn't used so that all
        // colors will be visible.  If not, some colors turn to solid black
        // or white when printed and may not show up.  This may be caused by
        // coarse dithering by the printer driver too (see image note below).
        if(pDC->GetDeviceCaps(NUMCOLORS) == 2 && crBG == CLR_DEFAULT)
            crFG = RGB(GetRValue(crFG) * 0.30, GetGValue(crFG) * 0.59,
                GetBValue(crFG) * 0.11);

        // Only erase the background if the color is not the default
        // grid background color.
        if(crBG != CLR_DEFAULT)
        {
            CBrush brush(crBG);
            rect.right++; rect.bottom++;
            pDC->FillRect(rect, &brush);
            rect.right--; rect.bottom--;
        }
    }
    else
    {
        crBG = CLR_DEFAULT;
        crFG = RGB(0, 0, 0);
    }

    pDC->SetTextColor(crFG);

    CFont *pFont = GetFontObject();
    if (pFont)
        pDC->SelectObject(pFont);

    /*
    // ***************************************************
    // Disabled - if you need this functionality then you'll need to rewrite.
    // Create the appropriate font and select into DC.
    CFont Font;
    // Bold the fixed cells if not shading the print out.  Use italic
    // font it it is enabled.
    const LOGFONT* plfFont = GetFont();
    if(IsFixed() && !pGrid->GetShadedPrintOut())
    {
        Font.CreateFont(plfFont->lfHeight, 0, 0, 0, FW_BOLD, plfFont->lfItalic, 0, 0,
            ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
#ifndef _WIN32_WCE
            PROOF_QUALITY,
#else
            DEFAULT_QUALITY,
#endif
            VARIABLE_PITCH | FF_SWISS, plfFont->lfFaceName);
    }
    else
        Font.CreateFontIndirect(plfFont);

    pDC->SelectObject(&Font);
    // ***************************************************
    */

    // Draw lines only when wanted on fixed cells.  Normal cell grid lines
    // are handled in OnPrint.
    if(pGrid->GetGridLines() != GVL_NONE && IsFixed())
    {
        CPen lightpen(PS_SOLID, 1,  ::GetSysColor(COLOR_3DHIGHLIGHT)),
             darkpen(PS_SOLID,  1, ::GetSysColor(COLOR_3DDKSHADOW)),
            *pOldPen = pDC->GetCurrentPen();

        pDC->SelectObject(&lightpen);
        pDC->MoveTo(rect.right, rect.top);
        pDC->LineTo(rect.left, rect.top);
        pDC->LineTo(rect.left, rect.bottom);

        pDC->SelectObject(&darkpen);
        pDC->MoveTo(rect.right, rect.top);
        pDC->LineTo(rect.right, rect.bottom);
        pDC->LineTo(rect.left, rect.bottom);

        rect.DeflateRect(1,1);
        pDC->SelectObject(pOldPen);
    }

    rect.DeflateRect(GetMargin(), 0);

    if(pGrid->GetImageList() && GetImage() >= 0)
    {
        // NOTE: If your printed images look like fuzzy garbage, check the
        //       settings on your printer driver.  If it's using coarse
        //       dithering and/or vector graphics, they may print wrong.
        //       Changing to fine dithering and raster graphics makes them
        //       print properly.  My HP 4L had that problem.

        IMAGEINFO Info;
        if(pGrid->GetImageList()->GetImageInfo(GetImage(), &Info))
        {
            int nImageWidth = Info.rcImage.right-Info.rcImage.left;
            pGrid->GetImageList()->Draw(pDC, GetImage(), rect.TopLeft(), ILD_NORMAL);
            rect.left += nImageWidth+GetMargin();
        }
    }

    // Draw without clipping so as not to lose text when printed for real
	// DT_NOCLIP removed 01.01.01. Slower, but who cares - we are printing!
#if _MSC_VER >= 1300
		::DrawTextW(pDC->m_hDC, GetText(), -1, rect, GetFormat() | /*DT_NOCLIP | */ DT_NOPREFIX);
#else
		DrawText(pDC->m_hDC, GetText(), -1, rect,
			GetFormat() | /*DT_NOCLIP | */ DT_NOPREFIX);
#endif

    pDC->RestoreDC(nSavedDC);

    return TRUE;
#endif
}
// EFW - Added to print cells so that grids that use different colors are
// printed correctly.

Added to print cells so that grids that use different colors are
printed correctly.
Added to print cells so that grids that use different colors are printed correctly .
BOOL CGridCellBase::PrintCell(CDC* pDC, int , int , CRect rect)
{
#if defined(_WIN32_WCE_NO_PRINTING) || defined(GRIDCONTROL_NO_PRINTING)
    return FALSE;
#else
    COLORREF crFG, crBG;
    GV_ITEM Item;
    CGridCtrl* pGrid = GetGrid();
    if (!pGrid || !pDC)
        return FALSE;
    if( rect.Width() <= 0
        || rect.Height() <= 0)  
        return FALSE;           
    int nSavedDC = pDC->SaveDC();
    pDC->SetBkMode(TRANSPARENT);
    if(pGrid->GetShadedPrintOut())
    {
        CGridDefaultCell *pDefaultCell = (CGridDefaultCell*) GetDefaultCell();
        if (!pDefaultCell)
            return FALSE;
        if(IsFixed())
            crBG = (GetBackClr() != CLR_DEFAULT) ? GetBackClr() : pDefaultCell->GetBackClr();
        else
            crBG = (GetBackClr() != CLR_DEFAULT && GetBackClr() != pDefaultCell->GetBackClr()) ?
                GetBackClr() : CLR_DEFAULT;
        if(IsFixed())
            crFG = (GetBackClr() != CLR_DEFAULT) ? GetTextClr() : pDefaultCell->GetTextClr();
        else
            crFG = (GetBackClr() != CLR_DEFAULT ||
                (GetTextClr() != CLR_DEFAULT && GetTextClr() != pDefaultCell->GetTextClr())) ?
                    GetTextClr() : RGB(0, 0, 0);
        if(pDC->GetDeviceCaps(NUMCOLORS) == 2 && crBG == CLR_DEFAULT)
            crFG = RGB(GetRValue(crFG) * 0.30, GetGValue(crFG) * 0.59,
                GetBValue(crFG) * 0.11);
        if(crBG != CLR_DEFAULT)
        {
            CBrush brush(crBG);
            rect.right++; rect.bottom++;
            pDC->FillRect(rect, &brush);
            rect.right--; rect.bottom--;
        }
    }
    else
    {
        crBG = CLR_DEFAULT;
        crFG = RGB(0, 0, 0);
    }
    pDC->SetTextColor(crFG);
    CFont *pFont = GetFontObject();
    if (pFont)
        pDC->SelectObject(pFont);
    if(pGrid->GetGridLines() != GVL_NONE && IsFixed())
    {
        CPen lightpen(PS_SOLID, 1,  ::GetSysColor(COLOR_3DHIGHLIGHT)),
             darkpen(PS_SOLID,  1, ::GetSysColor(COLOR_3DDKSHADOW)),
            *pOldPen = pDC->GetCurrentPen();
        pDC->SelectObject(&lightpen);
        pDC->MoveTo(rect.right, rect.top);
        pDC->LineTo(rect.left, rect.top);
        pDC->LineTo(rect.left, rect.bottom);
        pDC->SelectObject(&darkpen);
        pDC->MoveTo(rect.right, rect.top);
        pDC->LineTo(rect.right, rect.bottom);
        pDC->LineTo(rect.left, rect.bottom);
        rect.DeflateRect(1,1);
        pDC->SelectObject(pOldPen);
    }
    rect.DeflateRect(GetMargin(), 0);
    if(pGrid->GetImageList() && GetImage() >= 0)
    {
        IMAGEINFO Info;
        if(pGrid->GetImageList()->GetImageInfo(GetImage(), &Info))
        {
            int nImageWidth = Info.rcImage.right-Info.rcImage.left;
            pGrid->GetImageList()->Draw(pDC, GetImage(), rect.TopLeft(), ILD_NORMAL);
            rect.left += nImageWidth+GetMargin();
        }
    }
#if _MSC_VER >= 1300
		::DrawTextW(pDC->m_hDC, GetText(), -1, rect, GetFormat() |  DT_NOPREFIX);
#else
		DrawText(pDC->m_hDC, GetText(), -1, rect,
			GetFormat() |  DT_NOPREFIX);
#endif
    pDC->RestoreDC(nSavedDC);
    return TRUE;
#endif
}
BOOL CGridCellBase :: PrintCell ( CDC * pDC , int , int , CRect rect ) { #if defined ( _WIN32_WCE_NO_PRINTING ) || defined ( GRIDCONTROL_NO_PRINTING ) return FALSE ; #else COLORREF crFG , crBG ; GV_ITEM Item ; CGridCtrl * pGrid = GetGrid ( ) ; if ( ! pGrid || ! pDC ) return FALSE ; if ( rect . Width ( ) <= 0 || rect . Height ( ) <= 0 ) return FALSE ; int nSavedDC = pDC -> SaveDC ( ) ; pDC -> SetBkMode ( TRANSPARENT ) ; if ( pGrid -> GetShadedPrintOut ( ) ) { CGridDefaultCell * pDefaultCell = ( CGridDefaultCell * ) GetDefaultCell ( ) ; if ( ! pDefaultCell ) return FALSE ; if ( IsFixed ( ) ) crBG = ( GetBackClr ( ) != CLR_DEFAULT ) ? GetBackClr ( ) : pDefaultCell -> GetBackClr ( ) ; else crBG = ( GetBackClr ( ) != CLR_DEFAULT && GetBackClr ( ) != pDefaultCell -> GetBackClr ( ) ) ? GetBackClr ( ) : CLR_DEFAULT ; if ( IsFixed ( ) ) crFG = ( GetBackClr ( ) != CLR_DEFAULT ) ? GetTextClr ( ) : pDefaultCell -> GetTextClr ( ) ; else crFG = ( GetBackClr ( ) != CLR_DEFAULT || ( GetTextClr ( ) != CLR_DEFAULT && GetTextClr ( ) != pDefaultCell -> GetTextClr ( ) ) ) ? GetTextClr ( ) : RGB ( 0 , 0 , 0 ) ; if ( pDC -> GetDeviceCaps ( NUMCOLORS ) == 2 && crBG == CLR_DEFAULT ) crFG = RGB ( GetRValue ( crFG ) * 0.30 , GetGValue ( crFG ) * 0.59 , GetBValue ( crFG ) * 0.11 ) ; if ( crBG != CLR_DEFAULT ) { CBrush brush ( crBG ) ; rect . right ++ ; rect . bottom ++ ; pDC -> FillRect ( rect , & brush ) ; rect . right -- ; rect . bottom -- ; } } else { crBG = CLR_DEFAULT ; crFG = RGB ( 0 , 0 , 0 ) ; } pDC -> SetTextColor ( crFG ) ; CFont * pFont = GetFontObject ( ) ; if ( pFont ) pDC -> SelectObject ( pFont ) ; if ( pGrid -> GetGridLines ( ) != GVL_NONE && IsFixed ( ) ) { CPen lightpen ( PS_SOLID , 1 , :: GetSysColor ( COLOR_3DHIGHLIGHT ) ) , darkpen ( PS_SOLID , 1 , :: GetSysColor ( COLOR_3DDKSHADOW ) ) , * pOldPen = pDC -> GetCurrentPen ( ) ; pDC -> SelectObject ( & lightpen ) ; pDC -> MoveTo ( rect . right , rect . top ) ; pDC -> LineTo ( rect . left , rect . top ) ; pDC -> LineTo ( rect . left , rect . bottom ) ; pDC -> SelectObject ( & darkpen ) ; pDC -> MoveTo ( rect . right , rect . top ) ; pDC -> LineTo ( rect . right , rect . bottom ) ; pDC -> LineTo ( rect . left , rect . bottom ) ; rect . DeflateRect ( 1 , 1 ) ; pDC -> SelectObject ( pOldPen ) ; } rect . DeflateRect ( GetMargin ( ) , 0 ) ; if ( pGrid -> GetImageList ( ) && GetImage ( ) >= 0 ) { IMAGEINFO Info ; if ( pGrid -> GetImageList ( ) -> GetImageInfo ( GetImage ( ) , & Info ) ) { int nImageWidth = Info . rcImage . right - Info . rcImage . left ; pGrid -> GetImageList ( ) -> Draw ( pDC , GetImage ( ) , rect . TopLeft ( ) , ILD_NORMAL ) ; rect . left += nImageWidth + GetMargin ( ) ; } } #if _MSC_VER >= 1300 :: DrawTextW ( pDC -> m_hDC , GetText ( ) , -1 , rect , GetFormat ( ) | DT_NOPREFIX ) ; #else DrawText ( pDC -> m_hDC , GetText ( ) , -1 , rect , GetFormat ( ) | DT_NOPREFIX ) ; #endif pDC -> RestoreDC ( nSavedDC ) ; return TRUE ; #endif }
EFW - Added to print cells so that grids that use different colors are
printed correctly.
EFW - Added to print cells so that grids that use different colors are printed correctly .
/*nRow*/ /*nCol*/ // prevents imagelist item from drawing even
 //  though cell is hidden
 // Get the default cell implementation for this kind of cell. We use it if this cell
 // has anything marked as "default"
 // Use custom color if it doesn't match the default color and the
 // default grid background color.  If not, leave it alone.
 // Use custom color if the background is different or if it doesn't
 // match the default color and the default grid text color.  If not,
 // use black to guarantee the text is visible.
 // If not printing on a color printer, adjust the foreground color
 // to a gray scale if the background color isn't used so that all
 // colors will be visible.  If not, some colors turn to solid black
 // or white when printed and may not show up.  This may be caused by
 // coarse dithering by the printer driver too (see image note below).
 // Only erase the background if the color is not the default
 // grid background color.
 /*
    // ***************************************************
    // Disabled - if you need this functionality then you'll need to rewrite.
    // Create the appropriate font and select into DC.
    CFont Font;
    // Bold the fixed cells if not shading the print out.  Use italic
    // font it it is enabled.
    const LOGFONT* plfFont = GetFont();
    if(IsFixed() && !pGrid->GetShadedPrintOut())
    {
        Font.CreateFont(plfFont->lfHeight, 0, 0, 0, FW_BOLD, plfFont->lfItalic, 0, 0,
            ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
#ifndef _WIN32_WCE
            PROOF_QUALITY,
#else
            DEFAULT_QUALITY,
#endif
            VARIABLE_PITCH | FF_SWISS, plfFont->lfFaceName);
    }
    else
        Font.CreateFontIndirect(plfFont);

    pDC->SelectObject(&Font);
    // ***************************************************
    */ // Draw lines only when wanted on fixed cells.  Normal cell grid lines
 // are handled in OnPrint.
 // NOTE: If your printed images look like fuzzy garbage, check the
 //       settings on your printer driver.  If it's using coarse
 //       dithering and/or vector graphics, they may print wrong.
 //       Changing to fine dithering and raster graphics makes them
 //       print properly.  My HP 4L had that problem.
 // Draw without clipping so as not to lose text when printed for real
 // DT_NOCLIP removed 01.01.01. Slower, but who cares - we are printing!
 /*DT_NOCLIP | */ /*DT_NOCLIP | */