int CGridBtnCellBase::RelPointInCtl( const CPoint& arPoint) // Relative point coords // returns: Index of control that this point is within bounds of or -1 if no control matches { CGridCtrl* pGrid = GetGrid(); ASSERT( pGrid); CRect RectCell; if( pGrid->GetCellRect( m_iRow, m_iCol, &RectCell) ) { ASSERT( MAX_NBR_CTLS_INCELL > GetDrawCtlNbrMax() ); // whoa! CRect RectAry[ MAX_NBR_CTLS_INCELL]; if( CalcDrawCtlRects( RectAry, // returns: CRects with coordinates // last entry has optional leftover rect // available for text, etc. MAX_NBR_CTLS_INCELL,// nbr of Rects in above array RectCell) ) // cell rectangle to work with { const int iCtlNbr = GetDrawCtlNbr(); // make point absolute coord CPoint pointAbs; pointAbs.x = arPoint.x + RectCell.left; pointAbs.y = arPoint.y + RectCell.top; for( int i1=0; i1 < iCtlNbr; i1++) { if( pointAbs.x >= RectAry[i1].left && pointAbs.x <= RectAry[i1].right && pointAbs.y >= RectAry[i1].top && pointAbs.y <= RectAry[i1].bottom) { return i1; // found it } } } } return -1; }
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; }
void CGridBtnCellCombo::OnClick( CPoint PointCellRelative) { // immediately edit if user clicked on scroll down button picture int iCtlHit = RelPointInCtl( PointCellRelative); // Relative point coords // returns: Index of control that this point is within bounds of or -1 if no control matches BOOL bHitScrollDown = FALSE; if( iCtlHit >= 0) { // if user clicked on scroll down button picture, then show // the drop-down, too UINT uiType = GetDrawCtlType( iCtlHit); UINT uiState = GetDrawCtlState( iCtlHit); bHitScrollDown = ( uiType == DFC_SCROLL) && uiState & DFCS_SCROLLDOWN; } if( bHitScrollDown) { // invoke the edit, now -- similar to CGridCtl::OnEditCell() logic CGridCtrl* pGrid = GetGrid(); ASSERT( pGrid != NULL); CRect rect; if (!pGrid->GetCellRect( m_iRow, m_iCol, rect)) return; SendMessageToParent(m_iRow, m_iCol, GVN_BEGINLABELEDIT); Edit( m_iRow, m_iCol, rect, PointCellRelative, IDC_INPLACE_CONTROL, VK_LBUTTON); return; } CGridBtnCell::OnClick( PointCellRelative); }