Esempio n. 1
0
void ScrollViewUp( LPCLASSDATA lpcd )
{
	int	nLines = ArrayGetSize( lpcd->lpLines ) - 1;

	/*
	 *	Are we there already?
	 */
	if (( lpcd->ptViewPos.y + lpcd->szViewSize.cy - 1 ) < nLines )
	{
		/*
		 *	Go down one.
		 */
		lpcd->ptViewPos.y++;
		VScroll( lpcd, -1 );

		/*
		 *	Setup the scroller.
		 */
		SetupVScroller( lpcd );

		/*
		 *	Caret OK?
		 */
		if ( lpcd->ptCaretPos.y < lpcd->ptViewPos.y )
		{
			/*
			 *	Make it visible.
			 */
			lpcd->ptCaretPos.y = lpcd->ptViewPos.y;
			lpcd->ptCaretPos.x = lpcd->nLastColumnPos = 0;
			UpdateCaret( lpcd );
		}
	}
}
Esempio n. 2
0
void ScrollViewDown( LPCLASSDATA lpcd )
{
	/*
	 *	Are we there already?
	 */
	if ( lpcd->ptViewPos.y > 0 )
	{
		/*
		 *	Go up one.
		 */
		lpcd->ptViewPos.y--;
		VScroll( lpcd, 1 );

		/*
		 *	Setup the scroller.
		 */
		SetupVScroller( lpcd );

		/*
		 *	Caret OK?
		 */
		if ( lpcd->ptCaretPos.y > ( lpcd->ptViewPos.y + lpcd->szViewSize.cy - 1 ))
		{
			/*
			 *	Make it visible.
			 */
			lpcd->ptCaretPos.y = lpcd->ptViewPos.y + lpcd->szViewSize.cy - 1;
			lpcd->ptCaretPos.x = lpcd->nLastColumnPos = 0;
			UpdateCaret( lpcd );
		}
	}
}
Esempio n. 3
0
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;
}
Esempio n. 4
0
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 );
}
Esempio n. 5
0
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;
}
Esempio n. 6
0
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 );
			}
		}
	}
}