void CGridBtnCellCombo::OnEndEdit() { ASSERT( m_pBtnDataBase != NULL); m_ucEditing = FALSE; m_pBtnDataBase->SetEditWnd( NULL); // make sure that all pushbuttons appear in "up" state const int iCtlNbr = GetDrawCtlNbr(); for( int i1=0; i1 < iCtlNbr; i1++) { UINT uiType = GetDrawCtlType( i1); UINT uiState = GetDrawCtlState( i1); BOOL bIsScrollDown = ( uiType == DFC_SCROLL) && uiState & DFCS_SCROLLDOWN; BOOL bIsPushButton = ( uiType == DFC_BUTTON) && uiState & DFCS_BUTTONPUSH; if( bIsScrollDown || bIsPushButton) { ClickedCellCtl( WM_LBUTTONUP, // Command that invoked. e.g. WM_LBUTTONDOWN i1); // zero-based index of image to draw } } }
/***************************************************************************** 3/2001: Fix: Pops button back up if mouse clicked on a button, then moved away from button rectangle before release *****************************************************************************/ void CGridBtnCellBase::OnClick( CPoint /* PointCellRelative */) { if( m_sLastCtlClicked < 0) return; ClickedCellCtl( WM_LBUTTONUP,// Command that invoked. e.g. WM_LBUTTONDOWN m_sLastCtlClicked); // zero-based index of image to draw }
/***************************************************************************** Processes mouse clicks that potentially hit an embedded cell control *****************************************************************************/ BOOL CGridBtnCellBase::ProcessCtlClick(UINT uMsg, // Command that invoked. e.g. WM_LBUTTONDOWN const CPoint& arPoint) // point to check for hit // returns: T=hit a control / F=no control hit { int iCtlHit = RelPointInCtl( arPoint); // Relative point coords // returns: Index of control that this point is within bounds of or -1 if no control matches if( iCtlHit >= 0) { ClickedCellCtl( uMsg, // Command that invoked. e.g. WM_LBUTTONDOWN iCtlHit); // zero-based index of image to draw return TRUE; } m_sLastCtlClicked = -1; return FALSE; }
/***************************************************************************** May mean end of a button click sequence or to edit text *****************************************************************************/ BOOL CGridBtnCellBase::Edit(int nRow, int nCol, CRect rect, CPoint point, UINT nID, UINT nChar) { ASSERT( m_pBtnDataBase != NULL); if( ProcessCtlClick(WM_LBUTTONUP, // Command that invoked. e.g. WM_LBUTTONDOWN point) ) // point to check for hit { SendMessageToParent( m_iRow, m_iCol, NM_CLICK); // tell parent about it return FALSE; // clicked a control rather than edited a value } const int iCtlNbr = GetDrawCtlNbr(); if( iCtlNbr > 0 ) { // if there's at least one left-aligned control and user pressed // space bar, activate that control if( GetDrawCtlAlign( 0) == CTL_ALIGN_LEFT || iCtlNbr == 1) { if( nChar == ' ' ) { // user hit space bar -- just like clicking a button ClickedCellCtl( WM_LBUTTONDOWN, // Command that invoked. e.g. WM_LBUTTONDOWN 0); // zero-based index of image to draw Sleep( 200); ClickedCellCtl( WM_LBUTTONUP, // Command that invoked. e.g. WM_LBUTTONDOWN 0); // zero-based index of image to draw SendMessageToParent( m_iRow, m_iCol, NM_CLICK); // tell parent about it return FALSE; // clicked a control rather than edited a value } } } // if no string text to edit, then typing a character may invoke a button if( HasCellText() ) { DWORD dwStyle = ES_LEFT; if (GetFormat() & DT_RIGHT) dwStyle = ES_RIGHT; else if (GetFormat() & DT_CENTER) dwStyle = ES_CENTER; m_ucEditing = TRUE; // InPlaceEdit auto-deletes itself CGridCtrl* pGrid = GetGrid(); CWnd* pWnd = new CInPlaceEdit(pGrid, rect, dwStyle, nID, nRow, nCol, GetText(), nChar); m_pBtnDataBase->SetEditWnd( pWnd); } else { // since no text to edit, maybe press a button -- check for hot keys int iCtl = HotKeyBtnMatch( (char)nChar); // hot key character if( iCtl >= 0 ) { // returns: index of button or -1 if no hot key matches ClickedCellCtl( WM_LBUTTONDOWN, // Command that invoked. e.g. WM_LBUTTONDOWN iCtl); // zero-based index of image to draw Sleep( 200); ClickedCellCtl( WM_LBUTTONUP, // Command that invoked. e.g. WM_LBUTTONDOWN iCtl); // zero-based index of image to draw SendMessageToParent( m_iRow, m_iCol, NM_CLICK); // tell parent about it return FALSE; // clicked a control rather than edited a value } } return TRUE; }