00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00032 
00033 #include "stdafx.h"
00034 #include "../GridCtrl_src/GridCell.h"
00035 #include "../GridCtrl_src/GridCtrl.h"
00036 
00037 #include "GridCellCheck.h"
00038 
00039 
00040 #ifdef _DEBUG
00041 #define new DEBUG_NEW
00042 #undef THIS_FILE
00043 static char THIS_FILE[] = __FILE__;
00044 #endif
00045 
00046 IMPLEMENT_DYNCREATE(CGridCellCheck, CGridCell)
00047 
00048 CGridCellCheck::CGridCellCheck() : CGridCell()
00049 {
00050     m_bChecked = FALSE;
00051     
00052 }
00053 
00054 CSize CGridCellCheck::GetCellExtent(CDC* pDC)
00055 {
00056     
00057         int nWidth = GetSystemMetrics(SM_CXHSCROLL) + 2*GetMargin();
00058         return CGridCell::GetCellExtent(pDC) + CSize(nWidth, nWidth);
00059 }
00060 
00061 
00062 BOOL CGridCellCheck::GetTextRect( LPRECT pRect)
00063 {
00064     BOOL bResult = CGridCell::GetTextRect(pRect);
00065     if (bResult)
00066     {
00067         int nWidth = GetSystemMetrics(SM_CXHSCROLL) + 2*GetMargin();
00068         pRect->left += nWidth;
00069         if (pRect->left > pRect->right)
00070             pRect->left = pRect->right;
00071     }
00072     return bResult;
00073 }
00074 
00075 
00076 BOOL CGridCellCheck::Draw(CDC* pDC, int nRow, int nCol, CRect rect,  BOOL bEraseBkgnd )
00077 {
00078     BOOL bResult = CGridCell::Draw(pDC, nRow, nCol, rect,  bEraseBkgnd);
00079 
00080 #ifndef _WIN32_WCE
00081     
00082     m_Rect = rect;
00083 
00084     CRect CheckRect = GetCheckPlacement();
00085     rect.left = CheckRect.right;
00086 
00087     
00088     
00089 
00090     
00091     pDC->DrawFrameControl(GetCheckPlacement(), DFC_BUTTON, 
00092             (m_bChecked)? DFCS_BUTTONCHECK | DFCS_CHECKED : DFCS_BUTTONCHECK);
00093 
00094     
00095 #endif
00096     return bResult;
00097 }
00098 
00099 void CGridCellCheck::OnClick(CPoint PointCellRelative)
00100 {
00101         
00102         PointCellRelative += m_Rect.TopLeft();
00103 
00104         
00105         
00106         if (GetCheckPlacement().PtInRect(PointCellRelative))
00107         {
00108                 m_bChecked = !m_bChecked;
00109                 GetGrid()->InvalidateRect(m_Rect);
00110         }
00111 }
00112 
00114 
00116 
00117 BOOL CGridCellCheck::SetCheck(BOOL bChecked )
00118 {
00119         BOOL bTemp = m_bChecked;
00120         m_bChecked = bChecked;
00121         if (!m_Rect.IsRectEmpty())
00122                 GetGrid()->InvalidateRect(m_Rect);
00123 
00124         return bTemp;
00125 }
00126 
00127 BOOL CGridCellCheck::GetCheck()
00128 {
00129         return m_bChecked;
00130 }
00131 
00133 
00135 
00136 
00137 CRect CGridCellCheck::GetCheckPlacement()
00138 {
00139         int nWidth = GetSystemMetrics(SM_CXHSCROLL);
00140         CRect place = m_Rect + CSize(GetMargin(), GetMargin());
00141     place.right = place.left + nWidth;
00142     place.bottom = place.top + nWidth;
00143 
00144         
00145 
00146 
00147 
00148 
00149 
00150 
00151 
00152 
00153 
00154 
00155 
00156 
00157 
00158 
00159         return place;
00160 }