Home   |   Products   |   Documentation
 

dev net revision
29 July 2008
 

 
 

CDataEdit Class

The CDataEdit class is a standalone MFC edit control derived directly from CWnd, for Unicode UTF-8 text even in a non-_UNICODE build. It provides editing of large files in fixed or variable width fonts and supports undo/redo and printing. See CDataEdit specific notes in the firstobject XML Editor release notes.

The source code for CDataEdit comes in the firstobject XML Editor with the Advanced CMarkup Developer License.

To use CDataEdit in your Visual Studio MFC project, just add DataEdit.cpp and DataEdit.h. Put a CDataEdit member variable in a parent window class such as a dialog or view. Note that CDataEdit is not derived from MFC CEdit and does not support CEdit methods. Here are some of the CDataEdit public methods:

BOOL Create( CWnd* pParentWnd, UINT nID );
void SetSel( int nStartChar, int nEndChar, BOOL bNoScroll = FALSE );
void ReplaceSel( LPCTSTR lpszNewText );
CString GetText();
void SetText( CString& csText );
void ModifyText( CString& csText );
BOOL IsModified();
int Print( CDC* pDC, int nPage, CString csTitle = "" );

When a document is loaded, the carriage return and linefeed characters are not modified to conform to any standard. CRLF (0x0d0x0a) pairs are considered to be a combined end of line code. This way, mixtures of UNIX and PC end of line styles do not cause concern.

Printing

The Print method is used for printing a particular page and for paginating (nPage=0). The following simple code can be used to support print and print preview in a CView where the CDataEdit control is m_edit.

void CMarkupEditorView::OnBeginPrinting( CDC* pDC, CPrintInfo* pInfo )
{
	// Paginate document
	CString csTitle = GetDocument()->GetPathName();
	if ( csTitle.IsEmpty() )
		csTitle = GetDocument()->GetTitle();

	int nMaxPage = m_edit.Print( pDC, 0, csTitle );
	pInfo->SetMinPage( 1 );
	pInfo->SetMaxPage( nMaxPage );
}

void CMarkupEditorView::OnPrint(CDC* pDC, CPrintInfo* pInfo) 
{
	m_edit.Print( pDC, pInfo->m_nCurPage );
}

Text Value

At any given time, the text value is a simple string in the m_csText member. Use SetText() and GetText() methods explicitly rather than GetWindowText and SetWindowText because Windows 95/98/ME place limits on text passing though WM_SETTEXT. Use ModifyText to change the value of the control such that Undo will undo the change (SetText resets the Undo history).

Ask for the full code of CDataEditLi Xiuhua 24-Sep-2006

I am very interested in your CMarkup, and I want to see your source code of CDataEdit Class. May I get it?

The CDataEdit source code comes with the Advanced CMarkup Developer product.

 
 

Question or comment about this article?

©Copyright 2008 First Objective Software, Inc. All rights reserved.