/***************************************************************************** Override default title tips so that I'll get a title tip for a cell filled only with buttons *****************************************************************************/ LPCTSTR CGridBtnCellBase::GetTipText() { if( HasCellText() ) return CString(GetText()); // no string text... maybe there's btns with text const int iCtlNbr = GetDrawCtlNbr(); if( iCtlNbr <= 0) return NULL; char szTip[ 256]; int iNbrChars = 0; int i1; for( i1=0; i1 < iCtlNbr; i1++) { // remove any '&' chars const char* pszCtlBtnText = GetDrawCtlBtnText( i1); if( pszCtlBtnText != NULL) { if( i1 > 0) { szTip[ iNbrChars] = ' '; iNbrChars++; } BOOL bJustGotAmp = FALSE; while( iNbrChars < sizeof( szTip) - 2) { if( *pszCtlBtnText == '\0') break; if( *pszCtlBtnText == '&' ) { if( bJustGotAmp) { bJustGotAmp = FALSE; szTip[ iNbrChars] = *pszCtlBtnText; iNbrChars++; } else bJustGotAmp = TRUE; } else { bJustGotAmp = FALSE; szTip[ iNbrChars] = *pszCtlBtnText; iNbrChars++; } pszCtlBtnText++; } } } szTip[ iNbrChars] = '\0'; m_strTipText = szTip; return m_strTipText; }
/***************************************************************************** May mean end of a button click sequence or to edit text *****************************************************************************/ BOOL CGridBtnCellCombo::Edit(int nRow, int nCol, CRect rect, CPoint point, UINT nID, UINT nChar) { int iCtlHit = RelPointInCtl( point); // Relative point coords // returns: Index of control that this point is within bounds of or -1 if no control matches BOOL bShowDropDownNow = 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); bShowDropDownNow = ( uiType == DFC_SCROLL) && uiState & DFCS_SCROLLDOWN; } BOOL bHitNonComboButton = ( iCtlHit >= 0) && !bShowDropDownNow; if( HasCellText() && !bHitNonComboButton ) { m_ucEditing = TRUE; // InPlaceList auto-deletes itself CGridCtrl* pGrid = GetGrid(); CInPlaceList* pInPlaceList = new CInPlaceList( pGrid, rect, m_dwComboStyle, nID, nRow, nCol, GetTextClr(), GetBackClr(), m_StringArrayCombo, GetText(), nChar); if( bShowDropDownNow) { if( m_dwComboStyle & CBS_DROPDOWN || m_dwComboStyle & CBS_DROPDOWNLIST) { pInPlaceList->ShowDropDown( TRUE); } } m_pBtnDataBase->SetEditWnd( pInPlaceList); return TRUE; } // call base class, otherwise return CGridBtnCell::Edit( nRow, nCol, rect, point, nID, nChar); }
/***************************************************************************** If no text in the cell, add up all the button text together and use that as the title tip text *****************************************************************************/ BOOL CGridBtnCellBase::GetTipTextRect( LPRECT pRect) // i/o: i=dims of cell rect; o=dims of text rect { if( HasCellText() ) return GetTextRect( pRect); // if any text, just use default // no string text... maybe there's btns with text const int iCtlNbr = GetDrawCtlNbr(); if( iCtlNbr <= 0) { pRect->left = 0; pRect->top = 0; pRect->right = 0; pRect->bottom = 0; } // else, don't modify rect -- rect is full cell size return TRUE; }
/***************************************************************************** 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; }