The CDataEdit class is a standalone MFC edit control derived directly from CWnd using a Unicode UTF-8 or UTF-16 text string that can be over a gigabyte. It provides editing of text in fixed or variable width fonts and supports undo/redo and printing. See CDataEdit specific notes in the firstobject XML Editor release notes.

Advanced CMarkup Developer License

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. Also you will likely need to add imm32.lib to your Project Settings -> Link -> General -> Object/Library modules due to Windows IME support.

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 necessarily support CEdit methods. Here are some of the CDataEdit public methods:

BOOL Create( CWnd* pParentWnd, UINT nID, HFONT hFont = NULL );
BOOL CreateEditBox( CWnd* pParentWnd, UINT nID, HFONT hFont = NULL );
void SetSel( int nStartChar, int nEndChar, BOOL bNoScroll = FALSE );
void GetSel( int& nStartChar, int& nEndChar ) const; 
CString GetSelText();
int GetSelLength();
BOOL LocateWord( int& nStart, int& nEnd );
BOOL GoToLine( int nLine, int nCharPos = 0 );
BOOL FindOccurrence( CString csFindWhat, int& nStart, int& nEnd, int nFlags = 0 );
void ReplaceSel( CString csNewText, BOOL bRedraw = TRUE );
CString GetText() const;
void SetText( CString& csText );
void ModifyText( CString& csText, BOOL bCanUndo = TRUE );
BOOL IsModified();
void SetUnmodified();
int Print( CDC* pDC, int nPage, CString csTitle = "" );
void GetLogFont( LOGFONT* pLF );
void SetLogFont( LOGFONT* pLF );
int GetTextHeight();
static void GetDefaultLogFont( LOGFONT* pLF );
BOOL CopyUTF8( CString csCopy );
void SetReadOnly( BOOL bReadOnly );
void SetMultiLine( BOOL bMultiLine );
BOOL IsReadOnly();
void SetGutter( BOOL nGutter );
void SetWordWrap( BOOL bWordWrap );
BOOL IsWordWrap();
void SetHorizontalTextOffset( int nOffset );
void SetVerticalTextOffset( int nOffset );
void SetBgColor( COLORREF clr );
void SetNormalTextColor( COLORREF clr );
void SetIndentStyle( int nIndentStyle );
BOOL CanCut();
BOOL CanCopy();
BOOL CanPaste();
BOOL CanUndo();
BOOL CanRedo();

When a document is loaded, the carriage return and linefeed characters are not modified to conform to any standard. CRLF (0x0d 0x0a) 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).

 

comment posted Ask for the full code of CDataEdit

Li 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.