/* * Toggle overwrite mode. */ void ToggleOverwrite( LPCLASSDATA lpcd ) { /* * Toggle overwrite mode. */ lpcd->bOverwrite = ! lpcd->bOverwrite; /* * Destroy the caret if we have focus and * the caret type is not fixed at a block cursor. */ if ( Parser->nCaretType != CARET_BLOCK && lpcd->bHasFocus ) { /* * Destroy... */ DisplayCaret( lpcd, FALSE ); DestroyCaret(); } /* * Update status. */ SendStatusMessage( lpcd ); /* * Create the caret if we have focus and * the caret type is not fixed at a block cursor. */ if ( Parser->nCaretType != CARET_BLOCK && lpcd->bHasFocus ) /* * Create the caret. */ CreateTheCaret( lpcd ); }
void UpdateCaret( LPCLASSDATA lpcd ) { /* * Do we have the focus? */ if ( lpcd->bHasFocus == TRUE || lpcd->bDragOver == TRUE ) { /* * Caret inside the view? */ if ( CaretInView( lpcd )) { /* * Already visible? */ if ( lpcd->bCaretVisible == FALSE ) /* * No make it visible. */ DisplayCaret( lpcd, TRUE ); else { /* * Re-position. */ int cy = ( Parser->nCaretType == CARET_HORIZONTAL && ! lpcd->bOverwrite ) ? Parser->szCharSize.cy - ( 2 * GetSystemMetrics( SM_CYBORDER )) : 0; SetCaretPos( GetMarginWidth( lpcd ) + GetLineMarginWidth( lpcd ) + (( GetCaretOffset( lpcd, lpcd->ptCaretPos.x ) - lpcd->ptViewPos.x ) * Parser->szCharSize.cx ), ( lpcd->ptCaretPos.y - lpcd->ptViewPos.y ) * Parser->szCharSize.cy + cy ); } } else if ( lpcd->bCaretVisible == TRUE ) /* * Hide the caret. */ DisplayCaret( lpcd, FALSE ); } /* * Send caret position message. */ SendCaretMessage( lpcd ); }
static void MoveViewDown( LPCLASSDATA lpcd ) { int nLines = ArrayGetSize( lpcd->lpLines ) - 1; /* * Are we already at the end? */ if ( lpcd->ptCaretPos.y < nLines ) { /* * Hide the caret. */ DisplayCaret( lpcd, FALSE ); /* * Are we on the bottom of the view? */ if ( lpcd->ptCaretPos.y == ( lpcd->ptViewPos.y + lpcd->szViewSize.cy - 1 )) /* * Move down a page. */ lpcd->ptCaretPos.y = min( lpcd->ptCaretPos.y + lpcd->szViewSize.cy - 1, nLines ); else /* * Move to the bottom of the page. */ lpcd->ptCaretPos.y = min( lpcd->ptViewPos.y + lpcd->szViewSize.cy - 1, nLines ); /* * Make sure the caret is visible. */ MakeCaretVisible( lpcd ); /* * Show the caret. */ DisplayCaret( lpcd, TRUE ); } }
static void MoveViewUp( LPCLASSDATA lpcd ) { /* * Are we on the top? */ if ( lpcd->ptCaretPos.y > 0 ) { /* * Hide the caret. */ DisplayCaret( lpcd, FALSE ); /* * Are we on the top of the view? */ if ( lpcd->ptCaretPos.y == lpcd->ptViewPos.y ) /* * Move up a view. */ lpcd->ptCaretPos.y = max( 0, lpcd->ptCaretPos.y - lpcd->szViewSize.cy ); else /* * Go to the top of the view. */ lpcd->ptCaretPos.y = lpcd->ptViewPos.y; /* * Make sure the caret is visible. */ MakeCaretVisible( lpcd ); /* * Show the caret. */ DisplayCaret( lpcd, TRUE ); } }
void CScrView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { switch(nChar) { case VK_LEFT: case VK_RIGHT: case VK_UP: case VK_DOWN: case VK_HOME: case VK_END: case VK_PRIOR: case VK_NEXT: if (MovePos(nChar, nRepCnt, control_down(), shift_down(), caret_mode_)) { DisplayCaret(); return; } break; } CView::OnKeyDown(nChar, nRepCnt, nFlags); }
BOOL Delete( LPCLASSDATA lpcd ) { /* * Read only? */ if ( ISREADONLY ) return TRUE; /* * Do we have a mark and * is it valid? */ if ( HasMark( lpcd )) { /* * Remove the text. */ DeleteText( lpcd, &lpcd->ptSelStart, &lpcd->ptSelEnd, TRUE ); /* * We _must_ have atleast one * empty line. */ if ( ArrayGetSize( lpcd->lpLines ) == 0 ) { if ( InsertLine( lpcd, NULL, 0, -1, TRUE ) == FALSE ) return FALSE; } /* * Hide the caret. */ DisplayCaret( lpcd, FALSE ); /* * Move to the start position. */ lpcd->ptCaretPos = lpcd->ptSelStart; /* * Update column position. */ lpcd->nLastColumnPos = GetCaretOffset( lpcd, lpcd->ptCaretPos.x ); /* * Invalidate marks. */ lpcd->ptSelStart.x = lpcd->ptSelStart.y = -1; lpcd->ptSelEnd.x = lpcd->ptSelEnd.y = -1; /* * Is the caret inside * the view? */ if ( CaretInView( lpcd ) == FALSE ) /* * No. Move the view to * make it visible. */ MakeCaretVisibleNoRedraw( lpcd ); /* * Re-render. */ InvalidateRect( lpcd->hWnd, NULL, FALSE ); /* * Setup scrollers. */ SetupHScroller( lpcd ); SetupVScroller( lpcd ); /* * We are modified. */ SetModified( lpcd, TRUE ); /* * Send status message. */ SendStatusMessage( lpcd ); /* * Show the caret. */ DisplayCaret( lpcd, TRUE ); } return TRUE; }
void Paste( LPCLASSDATA lpcd ) { HANDLE hData; LPCTSTR lpszText; BOOL bDeleted = FALSE; /* * Are we read-only? */ if ( ISREADONLY ) return; /* * Valid format on the clipboard? */ if ( IsClipboardFormatAvailable( CF_TEXT ) == FALSE ) return; /* * Any marks set? */ if ( HasMark( lpcd )) bDeleted = Delete( lpcd ); /* * Hide the caret. */ DisplayCaret( lpcd, FALSE ); /* * Open the clipboard. */ if ( OpenClipboard( lpcd->hWnd )) { /* * Get data handle. */ if (( hData = GetClipboardData( CF_TEXT )) != NULL ) { /* * Lock the data. */ if (( lpszText = GlobalLock( hData )) != NULL ) { /* * Insert the clipboard contents * into the text. */ InsertText( lpcd, lpcd->ptCaretPos.y, lpcd->ptCaretPos.x, lpszText, &lpcd->ptCaretPos, ! bDeleted ); /* * Unlock the data handle. */ GlobalUnlock( hData ); } } /* * Close the clipboard. */ CloseClipboard(); } /* * Update column position. */ lpcd->nLastColumnPos = GetCaretOffset( lpcd, lpcd->ptCaretPos.x ); /* * Is the caret inside * the view? */ if ( CaretInView( lpcd ) == FALSE ) /* * No. Move the view to * make it visible. */ MakeCaretVisibleNoRedraw( lpcd ); /* * Re-render. */ InvalidateRect( lpcd->hWnd, NULL, FALSE ); /* * Setup scrollers. */ SetupHScroller( lpcd ); SetupVScroller( lpcd ); /* * We are modified. */ SetModified( lpcd, TRUE ); /* * Show the caret. */ DisplayCaret( lpcd, TRUE ); }
LRESULT OnReplaceSelection( HWND hWnd, WPARAM wParam, LPARAM lParam, LPCLASSDATA lpcd ) { LPCTSTR lpszText = ( LPCTSTR )lParam; BOOL bDeleted = FALSE; /* * Are we read-only? */ if ( ISREADONLY ) return FALSE; /* * Any text? */ if ( lpszText == NULL || *lpszText == _T( '\0' )) return FALSE; /* * Any marks set? If not return FALSE since we need * to replace a text selection. */ if ( HasMark( lpcd ) == FALSE ) return FALSE; /* * Delete the current selection from the text. */ bDeleted = Delete( lpcd ); /* * Hide the caret. */ DisplayCaret( lpcd, FALSE ); /* * Insert the clipboard contents * into the text. */ InsertText( lpcd, lpcd->ptCaretPos.y, lpcd->ptCaretPos.x, lpszText, &lpcd->ptCaretPos, ! bDeleted ); /* * Update column position. */ lpcd->nLastColumnPos = GetCaretOffset( lpcd, lpcd->ptCaretPos.x ); /* * Is the caret inside * the view? */ if ( CaretInView( lpcd ) == FALSE ) /* * No. Move the view to * make it visible. */ MakeCaretVisibleNoRedraw( lpcd ); /* * Re-render. */ InvalidateRect( lpcd->hWnd, NULL, FALSE ); /* * Setup scrollers. */ SetupHScroller( lpcd ); SetupVScroller( lpcd ); /* * We are modified. */ SetModified( lpcd, TRUE ); /* * Show the caret. */ DisplayCaret( lpcd, TRUE ); return TRUE; }