void CSelection::MakeEmpty( BOOL bDamage, BOOL bAtEnd ) { if ( !IsEmpty() ) { EnableColumnSel( FALSE ); if ( bDamage ) { Damage(); } if ( bAtEnd ) { m_nStartCol = m_nEndCol; m_nStartViewCol = m_nEndViewCol; m_nStartRow = m_nEndRow; } else { m_nEndCol = m_nStartCol; m_nEndViewCol = m_nStartViewCol; m_nEndRow = m_nStartRow; } UpdateCaretPosition(); } }
void VDUIHotKeyExControlW32::SetAccelerator(const VDUIAccelerator& accel) { if (mAccel == accel) return; mAccel = accel; UpdateText(); UpdateCaretPosition(); }
void VDUIHotKeyExControlW32::UpdateText() { if (!mAccel.mVirtKey && !(mAccel.mModifiers & (VDUIAccelerator::kModAlt | VDUIAccelerator::kModShift | VDUIAccelerator::kModCtrl))) mBuffer = L"-"; else VDUIGetAcceleratorString(mAccel, mBuffer); InvalidateRect(mhwnd, NULL, TRUE); UpdateCaretPosition(); }
void CSelection::SetExtendedSelection( int nStartCol, int nStartRow, int nEndCol, int nEndRow, BOOL bEnsureVisible, BOOL bAllowDamage ) { ASSERT( nStartRow >= 0 ); int nOldStartRow = m_nStartRow; int nOldEndRow = m_nEndRow; CBuffer *pBuffer = m_pCtrl->GetBuffer(); int nMaxLine = pBuffer->GetLineCount() - 1; nMaxLine = max( 0, nMaxLine ); m_nStartRow = min( nMaxLine, nStartRow ); m_nEndRow = min( nMaxLine, nEndRow ); m_nStartCol = nStartCol; m_nEndCol = nEndCol; // keep selection over text, if requested to if ( BoundSelection() ) { BOOL bKeepEmpty = ( nStartCol == nEndCol && nStartRow == nEndRow ); EnforceSelBounds(); if ( bKeepEmpty ) { m_nStartCol = m_nEndCol; } } m_nEndViewCol = pBuffer->ConvertBufferColToViewCol( m_nEndRow, m_nEndCol ); m_nStartViewCol = pBuffer->ConvertBufferColToViewCol( m_nStartRow, m_nStartCol ); m_nEndViewColPreferred = m_nEndViewCol; // damage old selection and new selection to clear it if ( bAllowDamage ) { int nStartDamage = min( nOldStartRow, nOldEndRow ); nStartDamage = min( nStartDamage, nStartRow ); nStartDamage = min( nStartDamage, nEndRow ); int nEndDamage = max( nOldStartRow, nOldEndRow ); nEndDamage = max( nEndDamage, nStartRow ); nEndDamage = max( nEndDamage, nEndRow ); m_pView->DamageView( nStartDamage, nEndDamage ); } if ( bEnsureVisible ) { EnsureVisible( TRUE ); } if ( ::IsWindow( m_hWnd ) && GetFocus() == m_hWnd ) { UpdateCaretPosition(); } }
void CSelection::OnFocusChange( BOOL bSetFocus ) { if ( bSetFocus ) { VERIFY( CreateCaret( m_hWnd, NULL, m_cxCaret, m_cyCaret ) ); UpdateCaretPosition(); ShowCaret(); } else { HideCaret(); DestroyCaret(); } }
void CSelection::SetView( CEditView *pView, BOOL bSilent ) { if ( m_pView != pView ) { CBuffer *pBuffer = m_pCtrl->GetBuffer(); int nRow = pView->GetTopIndex(); int nCol = pBuffer->ConvertViewColToBufferCol( nRow, pView->GetLeftIndex() ); nCol = pBuffer->ConvertBufferColToViewCol( nRow, nCol ); if ( !bSilent ) { SetEmptySelection( nCol, nRow ); } m_pView = pView; UpdateCaretPosition(); } }
void CSelection::OnFocusChange( BOOL bSetFocus ) { if ( bSetFocus ) { ASSERT( IsWindow( m_hWnd ) ); ASSERT( GetFocus() == m_hWnd ); VERIFY( CreateCaret( m_hWnd, NULL, m_cxCaret, m_cyCaret ) ); UpdateCaretPosition(); ShowCaret(); } else { HideCaret(); ASSERT( IsWindow( m_hWnd ) ); DestroyCaret(); } }
void CSelection::ExtendTo( int nCol, int nRow ) { CBuffer *pBuffer = m_pCtrl->GetBuffer(); int nOldRow = m_nEndRow; int nTemp = pBuffer->GetLineCount() - 1; nTemp = min( nRow, nTemp ); m_nEndRow = max( 0, nTemp ); int nMinRow = min( nOldRow, m_nEndRow ); int nMaxRow = max( nOldRow, m_nEndRow ); int nOldViewCol = m_nEndViewCol; m_nEndCol = max( 0, nCol ); // keep selection over text is requested to if ( BoundSelection() ) { EnforceSelBounds(); } m_nStartViewCol = pBuffer->ConvertBufferColToViewCol( m_nStartRow, m_nStartCol ); m_nEndViewCol = pBuffer->ConvertBufferColToViewCol( m_nEndRow, m_nEndCol ); if ( m_bColumnSel && ( m_nEndViewCol != nOldViewCol ) ) { // column sel width changed nMinRow = min( nMinRow, m_nStartRow ); nMaxRow = max( nMaxRow, m_nStartRow ); } // if user changed lines, notify the control so it can normalize the text case in the // line that was just left. if ( nOldRow != nRow ) { m_pCtrl->OnChangeLineSelection(); } m_pView->DamageView( nMinRow, nMaxRow ); UpdateCaretPosition(); }
LRESULT VDUIHotKeyExControlW32::WndProc(UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_NCCREATE: SetFont(NULL); break; case WM_GETDLGCODE: if (lParam) return DLGC_WANTMESSAGE; return DLGC_WANTALLKEYS; case WM_ERASEBKGND: return FALSE; case WM_PAINT: OnPaint(); return 0; case WM_GETFONT: return (LRESULT)wParam; case WM_SETFONT: SetFont((HFONT)wParam); if (LOWORD(lParam)) InvalidateRect(mhwnd, NULL, TRUE); return 0; case WM_LBUTTONDOWN: SetFocus(mhwnd); return 0; case WM_SETFOCUS: CreateCaret(mhwnd, NULL, 0, mFontHeight); UpdateCaretPosition(); ShowCaret(mhwnd); break; case WM_KILLFOCUS: HideCaret(mhwnd); DestroyCaret(); break; case WM_KEYDOWN: case WM_SYSKEYDOWN: mAccel.mVirtKey = 0; mAccel.mModifiers = 0; if (wParam == VK_CONTROL) mCurrentMods |= VDUIAccelerator::kModCtrl; else if (wParam == VK_SHIFT) mCurrentMods |= VDUIAccelerator::kModShift; else if (wParam == VK_MENU) mCurrentMods |= VDUIAccelerator::kModAlt; else { mAccel.mVirtKey = wParam; if (lParam & (1 << 24)) mAccel.mModifiers |= VDUIAccelerator::kModExtended; } mAccel.mModifiers |= mCurrentMods; UpdateText(); UpdateCaretPosition(); mEventOnChange.Raise(this, mAccel); return 0; case WM_SYSKEYUP: case WM_KEYUP: if (wParam == VK_CONTROL) mCurrentMods &= ~VDUIAccelerator::kModCtrl; else if (wParam == VK_SHIFT) mCurrentMods &= ~VDUIAccelerator::kModShift; else if (wParam == VK_MENU) mCurrentMods &= ~VDUIAccelerator::kModAlt; else break; UpdateText(); UpdateCaretPosition(); mEventOnChange.Raise(this, mAccel); return 0; } return DefWindowProc(mhwnd, msg, wParam, lParam); }
void CSelection::EnsureVisible( BOOL bScrollIfNeccessary, BOOL bCanCenter, BOOL bPreserveSelIfPossible ) { int nTopIndex = m_pView->GetTopIndex(); int nBottomIndex = m_pView->GetBottomIndex( TRUE ); int nLeftIndex = m_pView->GetLeftIndex(); int nRightIndex = m_pView->GetRightIndex( TRUE ); if ( bScrollIfNeccessary ) { int nViewWidth = nRightIndex - nLeftIndex; BOOL bNeedToScroll = FALSE; if ( bCanCenter && ( m_nStartRow == m_nEndRow ) && !IsEmpty() ) { // entire selection is on one line -- if can fit within entire view, do so. int nSelWidth = m_nEndViewCol - m_nStartViewCol; if ( nSelWidth < 0 ) { nSelWidth = -nSelWidth; } if ( nSelWidth < nViewWidth ) { nLeftIndex = ( m_nEndViewCol < nViewWidth ) ? 0 : m_nStartViewCol - ( nViewWidth - nSelWidth ) / 2; bNeedToScroll = TRUE; } } if ( !bNeedToScroll ) { if ( m_nEndViewCol < nLeftIndex ) { // try to scroll all the way back to col 0 nLeftIndex = ( m_nEndViewCol < nViewWidth ) ? 0 : m_nEndViewCol; bNeedToScroll = TRUE; } else if ( m_nEndViewCol > nRightIndex ) { int nTemp = m_nEndViewCol - MulDiv( nViewWidth, 3, 4 ); nLeftIndex = max( 0, nTemp ); bNeedToScroll = TRUE; } } if ( m_nEndRow < nTopIndex ) { nTopIndex = m_nEndRow; bNeedToScroll = TRUE; } else if ( m_nEndRow > nBottomIndex ) { int nTemp = m_nEndRow - ( nBottomIndex - nTopIndex ); nTopIndex = max( 0, nTemp ); bNeedToScroll = TRUE; } if ( bNeedToScroll ) { // if one-char increment, do smooth scrolling int nLeft = m_pView->GetLeftIndex(); int nTop = m_pView->GetTopIndex(); BOOL bSmooth = ( ( nLeftIndex == nLeft && ( nTop - nTopIndex ) * ( nTop - nTopIndex ) == 1 ) || ( nTopIndex == nTop && ( nLeft - nLeftIndex ) * ( nLeft - nLeftIndex ) == 1 ) ); m_pView->ScrollTo( nLeftIndex, nTopIndex, bSmooth ); } } else { BOOL bWasEmpty = IsEmpty(); BOOL bSelChanged = FALSE; if ( m_nEndViewCol < nLeftIndex ) { m_nEndViewCol = nLeftIndex; bSelChanged = TRUE; } else if ( m_nEndViewCol > nRightIndex ) { m_nEndViewCol = nRightIndex; bSelChanged = TRUE; } if ( m_nEndRow < nTopIndex ) { m_nEndRow = nTopIndex; bSelChanged = TRUE; } else if ( m_nEndRow > nBottomIndex ) { m_nEndRow = nBottomIndex; bSelChanged = TRUE; } // update the buffer position, regardless of the selection bounding setting. m_nEndCol = m_pCtrl->GetBuffer()->ConvertViewColToBufferCol( m_nEndRow, m_nEndViewCol ); if ( bSelChanged || !bPreserveSelIfPossible ) { MakeEmpty( !bWasEmpty ); } } UpdateCaretPosition(); }