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 ); }
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; }
static void MakeVisible( LPCLASSDATA lpcd, BOOL bRedraw ) { int nDiffY = lpcd->ptViewPos.y; BOOL bRender = FALSE; /* * Is the caret visible? */ if ( CaretInView( lpcd ) == FALSE ) { /* * Get "real" caret position. */ int nXPos = GetCaretOffset( lpcd, lpcd->ptCaretPos.x ); /* * Is it in the view horizontally? */ if (( nXPos < lpcd->ptViewPos.x ) || ( nXPos > lpcd->ptViewPos.x + ( lpcd->szViewSize.cx - 1 ))) { lpcd->ptViewPos.x = max( 0, nXPos - ( lpcd->szViewSize.cx ) / 2 ); bRender = TRUE; } /* * Is it in the view vertically? */ if ( lpcd->ptCaretPos.y < lpcd->ptViewPos.y ) { lpcd->ptViewPos.y = lpcd->ptCaretPos.y; } else if ( lpcd->ptCaretPos.y > lpcd->ptViewPos.y + ( lpcd->szViewSize.cy - 1 )) { lpcd->ptViewPos.y = max( 0, lpcd->ptCaretPos.y - ( lpcd->szViewSize.cy - 1 )); } /* * Redraw? */ if ( bRedraw ) { /* * Compute difference in Y direction. */ nDiffY = nDiffY - lpcd->ptViewPos.y; /* * View moved? */ if ( nDiffY != 0 && bRender == FALSE ) { /* * Scroll view. */ VScroll( lpcd, nDiffY ); /* * Setup vertical scroller. */ SetupVScroller( lpcd ); } else if ( bRender == TRUE ) { /* * Setup scrollers. */ SetupHScroller( lpcd ); SetupVScroller( lpcd ); /* * Re-render. */ InvalidateRect( lpcd->hWnd, NULL, TRUE ); } } } }