Ver código fonte

show a richedit control to edit the display text

git-svn-id: svn://svn.code.sf.net/p/ditto-cp/code/trunk@126 595ec19a-5cb4-439b-94a8-42fb3063c22c
sabrogden 21 anos atrás
pai
commit
23ccb7a44b
7 arquivos alterados com 531 adições e 13 exclusões
  1. 1 0
      CP_Main.cpp
  2. 3 3
      CP_Main.rc
  3. 7 8
      CopyProperties.cpp
  4. 2 1
      CopyProperties.h
  5. 2 1
      Resource.h
  6. 427 0
      RichEditCtrlEx.cpp
  7. 89 0
      RichEditCtrlEx.h

+ 1 - 0
CP_Main.cpp

@@ -96,6 +96,7 @@ BOOL CCP_MainApp::InitInstance()
 	}
 	
 	AfxOleInit();
+	AfxInitRichEdit();
 
 	m_cfIgnoreClipboard = ::RegisterClipboardFormat("Clipboard Viewer Ignore");
 

+ 3 - 3
CP_Main.rc

@@ -591,9 +591,6 @@ BEGIN
     PUSHBUTTON      "Parse",IDC_PARSE_BUTTON,212,23,25,12
     COMBOBOX        IDC_COMBO1,63,39,174,128,CBS_DROPDOWNLIST | WS_VSCROLL | 
                     WS_TABSTOP
-    EDITTEXT        IDC_EDIT_DISPLAY_TEXT,7,58,230,56,ES_MULTILINE | 
-                    ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN | 
-                    WS_VSCROLL
     LISTBOX         IDC_COPY_DATA,7,125,230,75,LBS_SORT | 
                     LBS_NOINTEGRALHEIGHT | LBS_EXTENDEDSEL | WS_VSCROLL | 
                     WS_TABSTOP
@@ -605,6 +602,9 @@ BEGIN
     LTEXT           "Hot Key",IDC_STATIC,7,7,28,13,SS_CENTERIMAGE
     LTEXT           "Copy Formats",IDC_STATIC,7,116,46,8
     LTEXT           "Move To Group",IDC_STATIC,8,40,56,9
+    CONTROL         "",IDC_RICHEDIT1,"RICHEDIT",ES_MULTILINE | 
+                    ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN | 
+                    WS_BORDER | WS_VSCROLL | WS_TABSTOP,7,58,230,57
 END
 
 IDD_ABOUT DIALOG DISCARDABLE  0, 0, 292, 124

+ 7 - 8
CopyProperties.cpp

@@ -26,7 +26,6 @@ CCopyProperties::CCopyProperties(long lCopyID, CWnd* pParent /*=NULL*/)
 	m_bHideOnKillFocus = false;
 	m_lGroupChangedTo = -1;
 	//{{AFX_DATA_INIT(CCopyProperties)
-	m_eDisplayText = _T("");
 	m_eDate = _T("");
 	m_bNeverAutoDelete = FALSE;
 	//}}AFX_DATA_INIT
@@ -37,17 +36,15 @@ void CCopyProperties::DoDataExchange(CDataExchange* pDX)
 {
 	CDialog::DoDataExchange(pDX);
 	//{{AFX_DATA_MAP(CCopyProperties)
+	DDX_Control(pDX, IDC_RICHEDIT1, m_RichEdit);
 	DDX_Control(pDX, IDC_COMBO1, m_GroupCombo);
 	DDX_Control(pDX, IDC_HOTKEY, m_HotKey);
 	DDX_Control(pDX, IDC_COPY_DATA, m_lCopyData);
-	DDX_Text(pDX, IDC_EDIT_DISPLAY_TEXT, m_eDisplayText);
-	DDV_MaxChars(pDX, m_eDisplayText, 250);
 	DDX_Text(pDX, IDC_DATE, m_eDate);
 	DDX_Check(pDX, IDC_NEVER_AUTO_DELETE, m_bNeverAutoDelete);
 	//}}AFX_DATA_MAP
 	DDX_Control(pDX, IDC_PARSE_EDIT, m_ParseEdit);
 	DDX_Control(pDX, IDC_PARSE_BUTTON, m_ParseButton);
-	DDX_Control(pDX, IDC_EDIT_DISPLAY_TEXT, m_DisplayTextEdit);
 }
 
 
@@ -75,7 +72,7 @@ BOOL CCopyProperties::OnInitDialog()
 		CTime time(m_MainTable.m_lDate);
 		m_eDate = time.Format("%m/%d/%Y %I:%M %p");
 
-		m_eDisplayText = m_MainTable.m_strText;
+		m_RichEdit.SetText(m_MainTable.m_strText);
 
 		if(m_MainTable.m_lDontAutoDelete)
 		{
@@ -118,7 +115,7 @@ BOOL CCopyProperties::OnInitDialog()
 	if( theApp.m_bShowCopyProperties )
 		m_HotKey.SetFocus();
 	else
-		m_DisplayTextEdit.SetFocus();
+		m_RichEdit.SetFocus();
 
 	return FALSE;
 }
@@ -181,14 +178,16 @@ void CCopyProperties::OnOK()
 		bUpdate = true;
 	}
 
-	if(m_eDisplayText != m_MainTable.m_strText)
+	CString csDisplayText;
+	csDisplayText = m_RichEdit.GetText();
+	if(csDisplayText != m_MainTable.m_strText)
 	{
 		if(!bUpdate)
 			m_MainTable.Edit();
 
 		m_bChangedText = true;
 
-		m_MainTable.m_strText = m_eDisplayText;
+		m_MainTable.m_strText = csDisplayText;
 
 		bUpdate = true;
 	}

+ 2 - 1
CopyProperties.h

@@ -9,6 +9,7 @@
 //
 
 #include "GroupCombo.h"
+#include "RichEditCtrlEx.h"
 
 /////////////////////////////////////////////////////////////////////////////
 // CCopyProperties dialog
@@ -22,10 +23,10 @@ public:
 // Dialog Data
 	//{{AFX_DATA(CCopyProperties)
 	enum { IDD = IDD_COPY_PROPERTIES };
+	CRichEditCtrlEx	m_RichEdit;
 	CGroupCombo	m_GroupCombo;
 	CHotKeyCtrl	m_HotKey;
 	CListBox	m_lCopyData;
-	CString	m_eDisplayText;
 	CString	m_eDate;
 	BOOL	m_bNeverAutoDelete;
 	//}}AFX_DATA

+ 2 - 1
Resource.h

@@ -122,6 +122,7 @@
 #define IDC_HOTKEY4                     2027
 #define IDC_TREE                        2027
 #define IDC_HOTKEY5                     2028
+#define IDC_RICHEDIT1                   2028
 #define IDC_HOTKEY6                     2029
 #define IDC_HOTKEY7                     2030
 #define IDC_HOTKEY8                     2031
@@ -204,7 +205,7 @@
 #define _APS_3D_CONTROLS                     1
 #define _APS_NEXT_RESOURCE_VALUE        157
 #define _APS_NEXT_COMMAND_VALUE         32844
-#define _APS_NEXT_CONTROL_VALUE         2028
+#define _APS_NEXT_CONTROL_VALUE         2029
 #define _APS_NEXT_SYMED_VALUE           101
 #endif
 #endif

+ 427 - 0
RichEditCtrlEx.cpp

@@ -0,0 +1,427 @@
+// AutoRichEditCtrl.cpp : implementation file
+//
+
+#include "stdafx.h"
+#include "RichEditCtrlEx.h"
+
+#ifdef _DEBUG
+#define new DEBUG_NEW
+#undef THIS_FILE
+static char THIS_FILE[] = __FILE__;
+#endif
+
+/////////////////////////////////////////////////////////////////////////////
+// CAutoRichEditCtrl
+
+CRichEditCtrlEx::CRichEditCtrlEx()
+{
+}
+
+CRichEditCtrlEx::~CRichEditCtrlEx()
+{
+}
+
+
+BEGIN_MESSAGE_MAP(CRichEditCtrlEx, CRichEditCtrl)
+	//{{AFX_MSG_MAP(CRichEditCtrlEx)
+		// NOTE - the ClassWizard will add and remove mapping macros here.
+	//}}AFX_MSG_MAP
+END_MESSAGE_MAP()
+
+/////////////////////////////////////////////////////////////////////////////
+// CRichEditCtrlEx message handlers
+
+CString CRichEditCtrlEx::GetRTF()
+{
+	// Return the RTF string of the text in the control.
+	
+	// Stream out here.
+	EDITSTREAM es;
+	es.dwError = 0;
+	es.pfnCallback = CBStreamOut;		// Set the callback
+
+	CString sRTF = "";
+
+	es.dwCookie = (DWORD) &sRTF;	// so sRTF receives the string
+	
+	StreamOut(SF_RTF, es);			// Call CRichEditCtrl::StreamOut to get the string.
+	///
+
+	return sRTF;
+
+}
+
+void CRichEditCtrlEx::SetRTF(CString sRTF)
+{
+	// Put the RTF string sRTF into the rich edit control.
+
+	// Read the text in
+	EDITSTREAM es;
+	es.dwError = 0;
+	es.pfnCallback = CBStreamIn;
+	es.dwCookie = (DWORD) &sRTF;
+	StreamIn(SF_RTF, es);	// Do it.
+	
+}
+
+CString CRichEditCtrlEx::GetText()
+{
+	// Return the RTF string of the text in the control.
+	
+	// Stream out here.
+	EDITSTREAM es;
+	es.dwError = 0;
+	es.pfnCallback = CBStreamOut;		// Set the callback
+
+	CString sText = "";
+
+	es.dwCookie = (DWORD) &sText;	// so sRTF receives the string
+	
+	StreamOut(SF_TEXT, es);			// Call CRichEditCtrl::StreamOut to get the string.
+
+	return sText;
+
+}
+
+void CRichEditCtrlEx::SetText(CString sText)
+{
+	// Put the RTF string sRTF into the rich edit control.
+
+	// Read the text in
+	EDITSTREAM es;
+	es.dwError = 0;
+	es.pfnCallback = CBStreamIn;
+	es.dwCookie = (DWORD) &sText;
+	StreamIn(SF_TEXT, es);	// Do it.
+}
+
+/*
+	Callback function to stream an RTF string into the rich edit control.
+*/
+DWORD CALLBACK CRichEditCtrlEx::CBStreamIn(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
+{
+	// We insert the rich text here.
+
+/*	
+	This function taken from CodeGuru.com
+	http://www.codeguru.com/richedit/rtf_string_streamin.shtml
+	Zafir Anjum
+*/
+
+	CString *pstr = (CString *) dwCookie;
+
+	if (pstr->GetLength() < cb)
+	{
+		*pcb = pstr->GetLength();
+		memcpy(pbBuff, (LPCSTR) *pstr, *pcb);
+		pstr->Empty();
+	}
+	else
+	{
+		*pcb = cb;
+		memcpy(pbBuff, (LPCSTR) *pstr, *pcb);
+		*pstr = pstr->Right(pstr->GetLength() - cb);
+	}
+	///
+
+	return 0;
+}
+
+/*
+	Callback function to stream the RTF string out of the rich edit control.
+*/
+DWORD CALLBACK CRichEditCtrlEx::CBStreamOut(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
+{
+	// Address of our string var is in psEntry
+	CString *psEntry = (CString*) dwCookie;
+	
+
+	CString tmpEntry = "";
+	tmpEntry = (CString) pbBuff;
+
+	// And write it!!!
+	*psEntry += tmpEntry.Left(cb);
+
+	return 0;
+}
+
+bool CRichEditCtrlEx::SelectionIsBold()
+{
+	CHARFORMAT cf = GetCharFormat();	
+	
+	if (cf.dwEffects & CFM_BOLD)
+		return true;
+	else
+		return false;
+}
+
+bool CRichEditCtrlEx::SelectionIsItalic()
+{
+	CHARFORMAT cf = GetCharFormat();	
+	
+	if (cf.dwEffects & CFM_ITALIC)
+		return true;
+	else
+		return false;
+}
+
+bool CRichEditCtrlEx::SelectionIsUnderlined()
+{
+	CHARFORMAT cf = GetCharFormat();	
+	
+	if (cf.dwEffects & CFM_UNDERLINE)
+		return true;
+	else
+		return false;
+}
+
+CHARFORMAT CRichEditCtrlEx::GetCharFormat(DWORD dwMask)
+{
+	CHARFORMAT cf;
+	cf.cbSize = sizeof(CHARFORMAT);
+
+	cf.dwMask = dwMask;
+
+	GetSelectionCharFormat(cf);
+
+	return cf;
+}
+
+void CRichEditCtrlEx::SetCharStyle(int MASK, int STYLE, int nStart, int nEnd)
+{
+	CHARFORMAT cf;
+	cf.cbSize = sizeof(CHARFORMAT);
+	//cf.dwMask = MASK;
+	
+	GetSelectionCharFormat(cf);
+	
+	if (cf.dwMask & MASK)	// selection is all the same
+	{
+		cf.dwEffects ^= STYLE; 
+	}
+	else
+	{
+		cf.dwEffects |= STYLE;
+	}
+	
+	cf.dwMask = MASK;
+
+	SetSelectionCharFormat(cf);
+
+}
+
+void CRichEditCtrlEx::SetSelectionBold()
+{
+	long start=0, end=0;
+	GetSel(start, end);		// Get the current selection
+
+	SetCharStyle(CFM_BOLD, CFE_BOLD, start, end);	// Make it bold
+}
+
+void CRichEditCtrlEx::SetSelectionItalic()
+{
+	long start=0, end=0;
+	GetSel(start, end);
+
+	SetCharStyle(CFM_ITALIC, CFE_ITALIC, start, end);
+}
+
+void CRichEditCtrlEx::SetSelectionUnderlined()
+{
+	long start=0, end=0;
+	GetSel(start, end);
+
+	SetCharStyle(CFM_UNDERLINE, CFE_UNDERLINE, start, end);
+}
+
+void CRichEditCtrlEx::SetParagraphCenter()
+{
+	PARAFORMAT paraFormat;    
+	paraFormat.cbSize = sizeof(PARAFORMAT);
+	paraFormat.dwMask = PFM_ALIGNMENT;    
+	paraFormat.wAlignment = PFA_CENTER;
+	
+	SetParaFormat(paraFormat);	// Set the paragraph.
+}
+
+void CRichEditCtrlEx::SetParagraphLeft()
+{
+	PARAFORMAT paraFormat;
+	paraFormat.cbSize = sizeof(PARAFORMAT);
+	paraFormat.dwMask = PFM_ALIGNMENT;    
+	paraFormat.wAlignment = PFA_LEFT;
+	
+	SetParaFormat(paraFormat);
+}
+
+void CRichEditCtrlEx::SetParagraphRight()
+{
+	PARAFORMAT paraFormat;
+	paraFormat.cbSize = sizeof(PARAFORMAT);
+	paraFormat.dwMask = PFM_ALIGNMENT;    
+	paraFormat.wAlignment = PFA_RIGHT;
+	
+	SetParaFormat(paraFormat);
+}
+
+bool CRichEditCtrlEx::ParagraphIsCentered()
+{
+	PARAFORMAT pf = GetParagraphFormat();
+
+	if (pf.wAlignment == PFA_CENTER)
+		return true;
+	else
+		return false;
+}
+
+bool CRichEditCtrlEx::ParagraphIsLeft()
+{
+	PARAFORMAT pf = GetParagraphFormat();
+
+	if (pf.wAlignment == PFA_LEFT)
+		return true;
+	else
+		return false;
+}
+
+bool CRichEditCtrlEx::ParagraphIsRight()
+{
+	PARAFORMAT pf = GetParagraphFormat();
+
+	if (pf.wAlignment == PFA_RIGHT)
+		return true;
+	else
+		return false;
+}
+
+PARAFORMAT CRichEditCtrlEx::GetParagraphFormat()
+{
+	PARAFORMAT pf;
+	pf.cbSize = sizeof(PARAFORMAT);
+
+	pf.dwMask = PFM_ALIGNMENT | PFM_NUMBERING;    	
+
+	GetParaFormat(pf);
+
+	return pf;
+}
+
+void CRichEditCtrlEx::SetParagraphBulleted()
+{
+	PARAFORMAT paraformat = GetParagraphFormat();
+
+	if ( (paraformat.dwMask & PFM_NUMBERING) && (paraformat.wNumbering == PFN_BULLET) )
+	{
+		paraformat.wNumbering = 0;
+		paraformat.dxOffset = 0;
+		paraformat.dxStartIndent = 0;
+		paraformat.dwMask = PFM_NUMBERING | PFM_STARTINDENT | PFM_OFFSET;
+	}
+	else
+	{
+		paraformat.wNumbering = PFN_BULLET;
+		paraformat.dwMask = PFM_NUMBERING;
+		if (paraformat.dxOffset == 0)
+		{
+			paraformat.dxOffset = 4;
+			paraformat.dwMask = PFM_NUMBERING | PFM_STARTINDENT | PFM_OFFSET;
+		}
+	}
+	
+	SetParaFormat(paraformat);
+
+}
+
+bool CRichEditCtrlEx::ParagraphIsBulleted()
+{
+	PARAFORMAT pf = GetParagraphFormat();
+
+	if (pf.wNumbering == PFN_BULLET)
+		return true;
+	else
+		return false;
+}
+
+void CRichEditCtrlEx::SelectColor()
+{
+	CColorDialog dlg;
+
+	CHARFORMAT cf = GetCharFormat();
+
+	if (cf.dwEffects & CFE_AUTOCOLOR) cf.dwEffects -= CFE_AUTOCOLOR;
+
+	// Get a color from the common color dialog.
+	if( dlg.DoModal() == IDOK )
+	{	
+		cf.crTextColor = dlg.GetColor();
+	}
+
+	cf.dwMask = CFM_COLOR;
+
+	SetSelectionCharFormat(cf);
+}
+
+void CRichEditCtrlEx::SetFontName(CString sFontName)
+{
+	CHARFORMAT cf = GetCharFormat();
+
+	// Set the font name.
+	for (int i = 0; i <= sFontName.GetLength()-1; i++)
+		cf.szFaceName[i] = sFontName[i];
+
+
+	cf.dwMask = CFM_FACE;
+
+	SetSelectionCharFormat(cf);
+}
+
+void CRichEditCtrlEx::SetFontSize(int nPointSize)
+{
+	CHARFORMAT cf = GetCharFormat();
+
+	nPointSize *= 20;	// convert from to twips
+	cf.yHeight = nPointSize;
+	
+	cf.dwMask = CFM_SIZE;
+
+	SetSelectionCharFormat(cf);
+}
+
+void CRichEditCtrlEx::GetSystemFonts(CStringArray &saFontList)
+{
+	CDC *pDC = GetDC ();
+
+	EnumFonts (pDC->GetSafeHdc(),NULL,(FONTENUMPROC) CBEnumFonts,(LPARAM)&saFontList);//Enumerate
+
+}
+
+BOOL CALLBACK CRichEditCtrlEx::CBEnumFonts(LPLOGFONT lplf, LPTEXTMETRIC lptm, DWORD dwType, LPARAM lpData)
+{
+	// This function was written with the help of CCustComboBox, by Girish Bharadwaj.
+	// Available from Codeguru.
+
+	if (dwType == TRUETYPE_FONTTYPE) 
+	{
+		((CStringArray *) lpData)->Add( lplf->lfFaceName );
+	}
+
+	return true;
+}
+
+CString CRichEditCtrlEx::GetSelectionFontName()
+{
+	CHARFORMAT cf = GetCharFormat();
+
+	CString sName = cf.szFaceName;
+
+	return sName;
+}
+
+long CRichEditCtrlEx::GetSelectionFontSize()
+{
+	CHARFORMAT cf = GetCharFormat();
+
+	long nSize = cf.yHeight/20;
+
+	return nSize;
+}

+ 89 - 0
RichEditCtrlEx.h

@@ -0,0 +1,89 @@
+#if !defined(AFX_AUTORICHEDITCTRL_H__C26D1E0E_DD32_11D2_B39F_000092914562__INCLUDED_)
+#define AFX_AUTORICHEDITCTRL_H__C26D1E0E_DD32_11D2_B39F_000092914562__INCLUDED_
+
+#if _MSC_VER > 1000
+#pragma once
+#endif // _MSC_VER > 1000
+// AutoRichEditCtrl.h : header file
+//
+
+/////////////////////////////////////////////////////////////////////////////
+// CRichEditCtrlEx window
+
+class CRichEditCtrlEx : public CRichEditCtrl
+{
+// Construction
+public:
+	CRichEditCtrlEx();
+
+// Attributes
+public:
+
+// Operations
+public:
+
+// Overrides
+	// ClassWizard generated virtual function overrides
+	//{{AFX_VIRTUAL(CRichEditCtrlEx)
+	//}}AFX_VIRTUAL
+
+// Implementation
+public:
+	long GetSelectionFontSize();
+	CString GetSelectionFontName();
+	CStringArray m_saFontList;
+	void GetSystemFonts(CStringArray &saFontList);
+	void SetFontSize(int nPointSize);
+	void SetFontName(CString sFontName);
+	void SelectColor();
+	bool ParagraphIsBulleted();
+	void SetParagraphBulleted();
+	
+	PARAFORMAT GetParagraphFormat();
+	
+	bool ParagraphIsRight();
+	bool ParagraphIsLeft();
+	bool ParagraphIsCentered();
+	
+	void SetParagraphRight();
+	void SetParagraphLeft();
+	void SetParagraphCenter();
+	
+	CHARFORMAT GetCharFormat(DWORD dwMask = CFM_COLOR | CFM_FACE | CFM_SIZE | CFM_BOLD | CFM_ITALIC | CFM_UNDERLINE);
+	
+	bool SelectionIsBold();
+	bool SelectionIsItalic();
+	bool SelectionIsUnderlined();
+
+	void SetSelectionBold();
+	void SetSelectionItalic();
+	void SetSelectionUnderlined();
+
+	void SetRTF(CString sRTF);
+	CString GetRTF();
+
+	void SetText(CString sText);
+	CString GetText();
+
+	virtual ~CRichEditCtrlEx();
+
+	// Generated message map functions
+protected:
+	//{{AFX_MSG(CRichEditCtrlEx)
+		// NOTE - the ClassWizard will add and remove member functions here.
+	//}}AFX_MSG
+
+	DECLARE_MESSAGE_MAP()
+private:
+		void SetCharStyle(int MASK, int STYLE, int nStart, int nEnd);
+		static DWORD CALLBACK CBStreamIn(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb);
+		static DWORD CALLBACK CBStreamOut(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG* pcb);
+		static BOOL CALLBACK CBEnumFonts(LPLOGFONT lplf, LPTEXTMETRIC lptm, DWORD dwType, LPARAM lpData);
+};
+
+/////////////////////////////////////////////////////////////////////////////
+
+//{{AFX_INSERT_LOCATION}}
+// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
+
+#endif // !defined(AFX_AUTORICHEDITCTRL_H__C26D1E0E_DD32_11D2_B39F_000092914562__INCLUDED_)